aboutsummaryrefslogtreecommitdiff
path: root/src/gatsc/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gatsc/main.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/gatsc/main.cpp b/src/gatsc/main.cpp
new file mode 100644
index 0000000..2bac3fd
--- /dev/null
+++ b/src/gatsc/main.cpp
@@ -0,0 +1,73 @@
1#include <bu/optparser.h>
2#include <bu/string.h>
3#include <bu/file.h>
4#include <bu/sio.h>
5
6#include "gats/types.h"
7#include "gats/gatsstream.h"
8
9using namespace Bu;
10
11class Options : public OptParser
12{
13public:
14 Options( int argc, char *argv[] ) :
15 bCompile( true )
16 {
17 addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n");
18
19 addOption( sInput, 'i', "input", "Specify input file.");
20 addOption( sOutput, 'o', "output", "Specify output file.");
21
22 addOption( bCompile, 'd', "decompile",
23 "Convert binary gats to text gats.");
24
25 addHelpOption('h', "help", "This Help");
26
27 setNonOption( slot( this, &Options::setInput ) );
28
29 setOverride("decompile", false );
30
31 parse( argc, argv );
32 }
33
34 int setInput( StrArray aParam )
35 {
36 sInput = aParam[0];
37 return 0;
38 }
39
40 bool bCompile;
41 String sInput;
42 String sOutput;
43};
44
45int main( int argc, char *argv[] )
46{
47 Options opt( argc, argv );
48
49 if( opt.sInput.isEmpty() )
50 {
51 sio << "You must specify an input." << sio.nl << sio.nl;
52 return 1;
53 }
54
55 if( opt.sOutput.isEmpty() )
56 {
57 opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') );
58 opt.sOutput += ".gats";
59 }
60
61 if( opt.bCompile )
62 {
63 File fIn( opt.sInput, File::Read );
64 File fOut( opt.sOutput, File::WriteNew );
65 Gats::GatsStream gs( fOut );
66 Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() );
67 gs.writeObject( pObj );
68 delete pObj;
69 }
70
71 return 0;
72}
73