diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-07-06 20:30:50 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-07-06 20:30:50 +0000 |
| commit | dbd7082d205410deecfacb5a7cd5336fc360c242 (patch) | |
| tree | 40747585594a98a29f7b35866b7876d8c723039d /src/gatsc | |
| parent | 2d58f0bae4d1e0b69cb0106acbd4b4a48831bbb6 (diff) | |
| download | libgats-dbd7082d205410deecfacb5a7cd5336fc360c242.tar.gz libgats-dbd7082d205410deecfacb5a7cd5336fc360c242.tar.bz2 libgats-dbd7082d205410deecfacb5a7cd5336fc360c242.tar.xz libgats-dbd7082d205410deecfacb5a7cd5336fc360c242.zip | |
Added the gats compiler. It can only compile from gats-text to gats-binary
right now.
Diffstat (limited to '')
| -rw-r--r-- | src/gatsc/main.cpp | 73 |
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 | |||
| 9 | using namespace Bu; | ||
| 10 | |||
| 11 | class Options : public OptParser | ||
| 12 | { | ||
| 13 | public: | ||
| 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 | |||
| 45 | int 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 | |||
