1 /*
2 
3 IMASM Macro Precompiler
4 
5 Copyright (C) 2003  Joe Fisher, Shiny Technologies, LLC
6 http://www.shinytechnologies.com
7 Portions Copyright (C) 2003  Joseph Zbiciak.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 
23 */
24 
25 #include "includes.h"
26 
27 const char *const license_string =
28     "IMASM Macro Precompiler\n"
29     "imasm -help for help\n"
30     "\n"
31     "Copyright (C) 2003  Joe Fisher, Shiny Technologies, LLC\n"
32     "Portions Copyright (C) 2003  Joseph Zbiciak\n"
33     "\n"
34     "http://www.shinytechnologies.com\n"
35     "\n"
36     "This program is free software; you can redistribute it and/or\n"
37     "modify it under the terms of the GNU General Public License\n"
38     "as published by the Free Software Foundation; either version 2\n"
39     "of the License, or (at your option) any later version.\n"
40     "\n"
41     "This program is distributed in the hope that it will be useful,\n"
42     "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
43     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
44     "GNU General Public License for more details.\n"
45     "\n"
46     "You should have received a copy of the GNU General Public License\n"
47     "along with this program; if not, write to the Free Software\n"
48     "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, "
49     "USA.\n";
50 
main(int argc,char * argv[])51 int main(int argc, char *argv[])
52 {
53     if (argc <= 1)
54     {
55         OutputLicense();
56         exit(0);
57     } else if (argc != 3)
58     {
59         // For now, always output help if the user doesn't specify
60         // correct argument set.
61         OutputHelp();
62         exit(0);
63     }
64 
65     try
66     {
67         StringFIFO_fromFile iFIFO(argv[1]);
68         StringFIFO_toFile   oFIFO(argv[2]);
69         Parser              p(&iFIFO, &oFIFO);
70 
71         p.ParseSourceFile();
72     } catch(FileNotFound &f)
73     {
74         cerr << "ERROR: " << f.msg << endl;
75         exit(1);
76     } catch(InternalError &ie)
77     {
78         cerr << ie.msg << endl;
79         exit(1);
80     } catch(StringFIFO::BufferOverflow &bo)
81     {
82         cerr << "ERROR:  Line too large. " << endl
83              << "    Maximum line length: " << bo.buffer_size << endl
84              << "  Attempted line length: " << bo.string_length << endl;
85 
86         // todo: output StringFIFO_fromFile location.
87 
88         exit(1);
89     } catch(Parser::ParseError &p)
90     {
91         cerr << "ERROR: " << endl  << p.msg << endl;
92         exit(1);
93     } catch(...) // catch all
94     {
95         cerr << "INTERNAL ERROR: UNHANDLED EXCEPTION! "
96              << __FILE__ ":" << __LINE__ << endl;
97     }
98 
99 
100 
101     return 0;
102 }
103 
OutputLicense()104 void OutputLicense()
105 {
106     cout << license_string << endl;
107 }
108 
OutputHelp()109 void OutputHelp()
110 {
111     cout << "IMASM Macro Precompiler"                        << endl
112          << "Copyright (C) 2003  Joe Fisher, Joseph Zbiciak" << endl << endl
113          << "IMASM usage:"                                   << endl << endl
114          << "  Preprocess file:  imasm inputfile outputfile" << endl
115          << "  This help:        imasm -help"                << endl
116          << "  Show license:     imasm"                      << endl;
117 }
118 
119