using System; using System.IO; using System.Text.RegularExpressions; namespace gensyms_rl78 { class Program { static void Main(string[] args) { // 引数チェック if (args.Length != 1) { Console.Error.WriteLine("usage: gensyms-rl78 "); Environment.Exit(1); } /* * ファイル中でチェックするパターン */ // (パブリック・ローカル)シンボル定義開始 var regDelim = new Regex(@";FF (?.+)"); // シンボル定義 var regEntry = new Regex(@"^(?\d\d)(?[0-9a-fA-F]{5})(?.+)"); try { var sr = new StreamReader(args[0]); string line; // シンボルテーブルファイルの先頭をチェック if (!new Regex(@"#05").IsMatch(sr.ReadLine())) { throw new Exception("This file is not a symbol table file. abort."); } while ((line = sr.ReadLine()) != null) { // パブリックシンボルの開始を探す if (regDelim.Match(line).Groups["name"].Value == "PUBLIC") { // パブリックシンボル定義の終わりまで,シンボル定義を出力 while (!regDelim.IsMatch(line = sr.ReadLine())) { var m = regEntry.Match(line); Console.WriteLine("000" + m.Groups["addr"] + " T " + m.Groups["name"]); } } } } catch (Exception e) { Console.Error.WriteLine("処理に失敗しました:" + e.ToString()); Environment.Exit(1); } } } }