Example #1
0
        //ソース内の 存在確認後利用する部分を展開する
        private static string convert_partsifexist(string st, string tmpstr)
        {
            var output = string.Empty;
            var lines  = tmpstr.Split('\n');

            for (var n = 0; n < lines.Length; n++)
            {
                var l     = lines[n].TrimEnd();
                int index = 0;
                var e     = EditUtil.Extract(l, out index);
                if (!string.IsNullOrWhiteSpace(e))
                {
                    var namecmt     = e + "-cmt";
                    var indentspace = (new string(' ', index));
                    if (!string.IsNullOrWhiteSpace(_getvalue(st, namecmt))) //コメント行あり
                    {
                        output += indentspace + "/*" + "\n";
                        output += indentspace + string.Format("  [[{0}]]", namecmt) + "\n";
                        output += indentspace + "*/" + "\n";
                    }
                }
                output += l + "\n";
            }
            return(output);
        }
Example #2
0
        //ソース内のname部分を値に変換する
        private static string convert_names(string st, string tmpstr)
        {
            var output = string.Empty;
            var lines  = tmpstr.Split('\n');

            for (var n = 0; n < lines.Length; n++)
            {
                var l      = lines[n].TrimEnd();
                var oindex = l.IndexOf("[[");
                var cindex = l.IndexOf("]]");
                if (oindex >= 0 && cindex >= 0 && oindex < cindex)
                {
                    var name = l.Substring(oindex + 2, cindex - oindex - 2);
                    var val  = _getvalue(st, name).Trim();

                    var result = EditUtil.Insert(l, "[[" + name + "]]", val).TrimEnd();
                    if (!string.IsNullOrWhiteSpace(result))
                    {
                        output += result + "\n";
                    }
                }
                else
                {
                    output += l + "\n";
                }
            }
            return(output);
        }
Example #3
0
        //出力ソース名を取得
        public string GetInitalSource(out string filename)
        {
            string mark = ":output=";

            filename = string.Empty;
            var output = string.Empty;

            foreach (var i in EditUtil.Split(m_template_source))
            {
                if (string.IsNullOrEmpty(i) || string.IsNullOrEmpty(i.TrimEnd()))
                {
                    continue;
                }
                var l = i.TrimEnd();
                if (l.StartsWith(mark))
                {
                    filename = l.Substring(mark.Length);
                    continue;
                }
                if (l[0] == ':')
                {
                    continue;
                }

                output += l + "\n";
            }
            return(output);
        }
Example #4
0
        //ファンクション用ファイル取得
        public string GetInitialFuncSource(string tempfunc = null)
        {
            if (string.IsNullOrEmpty(tempfunc))
            {
                tempfunc = m_template_statefunc;
            }

            var output = string.Empty;

            foreach (var i in EditUtil.Split(tempfunc))
            {
                if (string.IsNullOrEmpty(i) || string.IsNullOrEmpty(i.TrimEnd()))
                {
                    continue;
                }
                var l = i.TrimEnd();
                if (l[0] == ':')
                {
                    continue;
                }

                output += l + "\n";
            }
            return(output);
        }
Example #5
0
        //プログラムランゲージ指定を取得
        public string GetInitalSource(out string filename, out string lang, out string enc, out string tempfunc)
        {
            string mark_output   = ":output=";
            string mark_lang     = ":lang=";
            string mark_enc      = ":enc=";
            string mark_tempfunc = ":templatefunc=";

            filename = string.Empty;
            lang     = string.Empty;
            enc      = string.Empty;
            tempfunc = string.Empty;
            var output = string.Empty;

            foreach (var i in EditUtil.Split(m_template_source))
            {
                if (string.IsNullOrEmpty(i) || string.IsNullOrEmpty(i.TrimEnd()))
                {
                    continue;
                }
                var l = i.TrimEnd();
                if (l.StartsWith(mark_output))
                {
                    filename = l.Substring(mark_output.Length);
                    continue;
                }
                if (l.StartsWith(mark_lang))
                {
                    lang = l.Substring(mark_lang.Length);
                }
                if (l.StartsWith(mark_enc))
                {
                    enc = l.Substring(mark_enc.Length);
                }
                if (l.StartsWith(mark_tempfunc))
                {
                    tempfunc = l.Substring(mark_tempfunc.Length);
                }

                if (l[0] == ':')
                {
                    continue;
                }

                output += l + "\n";
            }
            return(output);
        }
Example #6
0
        static void Main(string[] args)  // 0 --- excel file, 1 --- output dir
        {
            //System.Diagnostics.Debugger.Break();

            m_ld      = new LoadTemplateAndValues(args[0]);
            m_curpath = Path.GetDirectoryName(Path.GetFullPath(args[0]));

            string filename, lang, enc, tempfunc;
            var    outpusrc = m_ld.GetInitalSource(out filename, out lang, out enc, out tempfunc);

            if (!string.IsNullOrEmpty(enc))
            {
                m_enc = enc;
            }
            if (!string.IsNullOrEmpty(tempfunc))
            {
                m_overwride_tempfunc = File.ReadAllText(Path.Combine(m_curpath, tempfunc), Encoding.GetEncoding(enc));
            }


            //stateを収集
            var state_str  = string.Empty;
            var state_list = new List <string>();
            {
                for (var c = START_COL; c < m_ld.GetMaxCol(); c++)
                {
                    var s = m_ld.GetValue(STATE_ROW, c);
                    if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(s.Trim()))
                    {
                        continue;
                    }
                    state_list.Add(s.Trim());
                }

                //
                state_list.ForEach(s => {
                    if (!string.IsNullOrEmpty(state_str))
                    {
                        state_str += ",";
                    }
                    state_str += s + "\n";
                });
            }

            // func_str作成
            var func_str = string.Empty;

            foreach (var st in state_list)
            {
                var tmpstr = m_ld.GetInitialFuncSource(m_overwride_tempfunc);
                tmpstr = convert_partsifexist_obs(st, tmpstr);
                tmpstr = convert_names(st, tmpstr);

                func_str += EditUtil.TrimLines(tmpstr);
            }

            //outputsrc作成
            outpusrc = EditUtil.Insert(outpusrc, "$contents1$", state_str);
            outpusrc = EditUtil.Insert(outpusrc, "$contents2$", func_str);

            if (lang.ToLower() == "vba")
            {
                var select_str = string.Empty;
                foreach (var st in state_list)
                {
                    select_str += "Case \"" + st + "\"\n\t" + st + "(bFirst)\n";
                }
                outpusrc = EditUtil.Insert(outpusrc, "$contents3$", select_str);
            }

            //
            outpusrc = "//This source is created by ExcelStateChartConverter.exe. Source : " + args[0] + "\n" + outpusrc;


            File.WriteAllText(Path.Combine(args[1], filename), outpusrc, Encoding.UTF8);
        }