1 using System;
  2 using System.IO;
  3 using System.Collections;
  4 using cmsx.assembly;
  5 
  6 public nothrow const char* Version()
  7 {
  8     return "4.0.0";
  9 }
 10 
 11 public nothrow void PrintHelp()
 12 {
 13     Console.Out() << "Cmajor System X Assembler version " << Version() << endl();
 14     Console.Out() << "Usage: cmsxas [options] { <file>.s }" << endl();
 15     Console.Out() << "Options: " << endl();
 16     Console.Out() << "   --help (-h)" << endl();
 17     Console.Out() << "      print this help" << endl();
 18     Console.Out() << "   --verbose (-v)" << endl();
 19     Console.Out() << "      be verbose" << endl();
 20     Console.Out() << "   --outdir=DIR (-o=DIR)" << endl();
 21     Console.Out() << "      set output directory to DIR" << endl();
 22 }
 23 
 24 int main(int argcconst char** argv)
 25 {
 26     try
 27     {
 28         List<string> assemblyFiles;
 29         bool verbose = false;
 30         string outdir;
 31         for (int i = 1; i < argc; ++i;)
 32         {
 33             string arg = argv[i];
 34             if (arg.StartsWith("--"))
 35             {
 36                 if (arg == "--help")
 37                 {
 38                     PrintHelp();
 39                     return 1;
 40                 }
 41                 else if (arg == "--verbose")
 42                 {
 43                     verbose = true;
 44                 }
 45                 else if (arg.StartsWith("--outdir="))
 46                 {
 47                     outdir = arg.Substring(9);
 48                 }
 49                 else
 50                 {
 51                     throw Exception("unknown option '" + arg + "'");
 52                 }
 53             }
 54             else if (arg.StartsWith("-"))
 55             {
 56                 if (arg.StartsWith("-o="))
 57                 {
 58                     outdir = arg.Substring(3);
 59                 }
 60                 else
 61                 {
 62                     string options = arg.Substring(1);
 63                     if (options.IsEmpty())
 64                     {
 65                         throw Exception("unknown option '" + arg + "'");
 66                     }
 67                     else
 68                     {
 69                         for (char o : options)
 70                         {
 71                             if (o == 'h')
 72                             {
 73                                 PrintHelp();
 74                                 return 1;
 75                             }
 76                             else if (o == 'v')
 77                             {
 78                                 verbose = true;
 79                             }
 80                             else
 81                             {
 82                                 throw Exception("unknown option '-" + string(o) + "'");
 83                             }
 84                         }
 85                     }
 86                 }
 87             }
 88             else
 89             {
 90                 assemblyFiles.Add(GetFullPath(arg));
 91             }
 92         }
 93         if (verbose)
 94         {
 95             Console.Out() << "Cmajor System X Assembler version " << Version() << endl();
 96         }
 97         if (assemblyFiles.IsEmpty())
 98         {
 99             PrintHelp();
100             throw Exception("no assembly files given");
101         }
102         int n = cast<int>(assemblyFiles.Count());
103         for (int i = 0; i < n; ++i;)
104         {
105             const string& assemblyFileName = assemblyFiles[i];
106             string assemblyFilePath = GetFullPath(assemblyFileName);
107             ProcessAssemblyFile(iassemblyFilePathverboseoutdir);
108         }
109     }
110     catch (const Exception& ex)
111     {
112         Console.Error() << ex.Message() << endl();
113         return 1;
114     }
115     return 0;
116 }