forked from Konamiman/Nextor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymToEqus.cs
82 lines (68 loc) · 2.49 KB
/
SymToEqus.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace Konamiman.SymToEqus
{
class Program
{
static int Main(string[] args)
{
Console.WriteLine("SymToEqus 1.0 - (c) 2008 by Nestor Soriano");
if(args.Length<2) {
Console.WriteLine(
@"
Usage: SymToEqus <input file> <output file> [<label filter regular exp>]
This program converts a .SYM file generated by M80 assembler into a
file containing an EQU and a PUBLIC label for each symbol.
The label filter regular expression selects which symbols will be
included, it should explicitly reject spaces and tabs.
Default label filter accepts all symbols, it is: [^ \t]+"
);
return 0;
}
//* Parse parameters
string inputFile=null;
try {
inputFile=File.ReadAllText(args[0]);
}
catch(Exception ex) {
Console.WriteLine("*** Error when reading input file: {0}", ex.Message);
return 1;
}
string labelPattern=@"[^ \t]+";
if(args.Length>2) {
labelPattern=args[2];
}
Regex regex = null;
try {
regex = new Regex(@"(?<value>[0-9A-Fa-f]{4})[ \t](?<label>"+labelPattern+")");
}
catch(Exception ex) {
Console.WriteLine("*** Error when parsing label filter: {0}", ex.Message);
return 1;
}
StringBuilder outputFile=new StringBuilder();
//* Process input file
try {
MatchCollection matches = regex.Matches(inputFile);
foreach(Match match in matches) {
outputFile.AppendFormat("{0} equ {1}h{2}\tpublic {0}{2}", match.Groups["label"].Value, match.Groups["value"].Value, Environment.NewLine);
}
}
catch(Exception ex) {
Console.WriteLine("*** Error when parsing input file: {0}", ex.Message);
return 1;
}
//* Generate output file
try {
File.WriteAllText(args[1], outputFile.ToString());
}
catch(Exception ex) {
Console.WriteLine("*** Error when creating output file: {0}", ex.Message);
return 1;
}
return 0;
}
}
}