1.1 --- a/tools/incparser/Program.cs Fri Jul 11 06:51:21 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,183 +0,0 @@
1.4 -using System;
1.5 -using System.Collections.Generic;
1.6 -using System.Text;
1.7 -using System.IO;
1.8 -
1.9 -namespace incparser
1.10 -{
1.11 - class Program
1.12 - {
1.13 - static void Main(string[] args)
1.14 - {
1.15 - Environment.Exit(SubMain(args));
1.16 - }
1.17 -
1.18 - static int SubMain(string[] args)
1.19 - {
1.20 - string directory = ".";
1.21 - string template = "template.txt";
1.22 - string outputfile = "output.txt";
1.23 - string file = null;
1.24 -
1.25 - if (args.Length == 0 || (args.Length == 1 && args[0] == "-h"))
1.26 - {
1.27 - PrintHelp();
1.28 - return 0;
1.29 - }
1.30 -
1.31 - for (int i=0; i<args.Length-1; i++)
1.32 - {
1.33 - if (args[i] == "-d")
1.34 - {
1.35 - directory = args[i + 1];
1.36 - }
1.37 -
1.38 - if (args[i] == "-t")
1.39 - {
1.40 - template = args[i + 1];
1.41 - }
1.42 -
1.43 - if (args[i] == "-o")
1.44 - {
1.45 - outputfile = args[i + 1];
1.46 - }
1.47 -
1.48 - if (args[i] == "-f")
1.49 - {
1.50 - file = args[i + 1];
1.51 - }
1.52 -
1.53 - if (args[i] == "-h")
1.54 - {
1.55 - if (args[i + 1] == "template")
1.56 - {
1.57 - PrintTemplateHelp();
1.58 - return 0;
1.59 - }
1.60 - PrintHelp();
1.61 - return 0;
1.62 - }
1.63 - }
1.64 -
1.65 - IncParser inc = null;
1.66 -
1.67 - if (file == null)
1.68 - {
1.69 - DirectoryInfo di = new DirectoryInfo(directory);
1.70 - FileInfo[] rgFiles = di.GetFiles("*.inc");
1.71 -
1.72 - ParseWriter pwr = new ParseWriter();
1.73 -
1.74 - foreach (FileInfo fi in rgFiles)
1.75 - {
1.76 - pwr.Reset();
1.77 -
1.78 - Console.Write("Parsing file: " + fi.ToString() + "... ");
1.79 -
1.80 - try
1.81 - {
1.82 - inc = new IncParser(fi.FullName);
1.83 - }
1.84 - catch (ParseException e)
1.85 - {
1.86 - Console.WriteLine("Initial browsing failed: " + e.Message);
1.87 - continue;
1.88 - }
1.89 - catch (System.Exception e)
1.90 - {
1.91 - Console.WriteLine("Failed to read file: " + e.Message);
1.92 - continue;
1.93 - }
1.94 -
1.95 - try
1.96 - {
1.97 - inc.Parse(pwr);
1.98 - }
1.99 - catch (System.Exception e)
1.100 - {
1.101 - Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
1.102 - continue;
1.103 - }
1.104 -
1.105 - if (pwr.Level != 0)
1.106 - {
1.107 - Console.WriteLine("Fatal parse error detected; unable to complete output.");
1.108 - continue;
1.109 - }
1.110 -
1.111 - Console.WriteLine("Complete!");
1.112 - }
1.113 -
1.114 - pwr.WriteFiles(template, outputfile);
1.115 -
1.116 - Console.WriteLine("Parsing Complete!");
1.117 -
1.118 - return 0;
1.119 - }
1.120 -
1.121 - try
1.122 - {
1.123 - inc = new IncParser(file);
1.124 - }
1.125 - catch (ParseException e)
1.126 - {
1.127 - Console.WriteLine("Initial browsing failed: " + e.Message);
1.128 - return 1;
1.129 - }
1.130 - catch (System.Exception e)
1.131 - {
1.132 - Console.WriteLine("Failed to read file: " + e.Message);
1.133 - return 1;
1.134 - }
1.135 -
1.136 - ParseWriter pw = new ParseWriter();
1.137 -
1.138 - try
1.139 - {
1.140 - inc.Parse(pw);
1.141 - }
1.142 - catch (System.Exception e)
1.143 - {
1.144 - Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
1.145 - return 1;
1.146 - }
1.147 -
1.148 - if (pw.Level != 0)
1.149 - {
1.150 - Console.WriteLine("Fatal parse error detected; unable to complete output.");
1.151 - return 1;
1.152 - }
1.153 -
1.154 - Console.Write(pw.Contents);
1.155 - Console.Write("\n");
1.156 -
1.157 - return 0;
1.158 - }
1.159 -
1.160 - static void PrintHelp()
1.161 - {
1.162 - Console.WriteLine("SourcePawn include file parser by BAILOPAN (edited by pRED*)");
1.163 - Console.Write("\n");
1.164 - Console.WriteLine("This can parse a single file into SMC configuration format or an entire directory into a template file if -f is not specified (current directory is used if -d is not specified)");
1.165 - Console.Write("\n");
1.166 - Console.WriteLine("Parameters:");
1.167 - Console.Write("\n");
1.168 - Console.WriteLine("-f <filename> - Specify an input file to be used");
1.169 - Console.WriteLine("-d <path> - Specify a directory to parse (only *.inc files are used)");
1.170 - Console.WriteLine("-t <filename> - Specify a template file to be used");
1.171 - Console.WriteLine("-o <filename> - Specify an output file to be used");
1.172 - Console.WriteLine("-h - Display this help");
1.173 - Console.WriteLine("-h template - Displays help about templates");
1.174 - }
1.175 -
1.176 - static void PrintTemplateHelp()
1.177 - {
1.178 - Console.WriteLine("Template File Help:");
1.179 - Console.WriteLine("The inc parser can read a template file and replace variables with the outputs of it's parse and write into the output file");
1.180 - Console.Write("\n");
1.181 - Console.WriteLine("Variables:");
1.182 - Console.Write("\n");
1.183 - Console.WriteLine("$defines $enums $enumtypes $forwards $natives $stocks $funcenums $functags $structs");
1.184 - }
1.185 - }
1.186 -}