diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 17:20:11 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 17:20:11 +0000 |
commit | d534a56d95bca7bdd812be024d9eacba4734e2b7 (patch) | |
tree | f9b98ee2b80e645a7b54e7934882be6c9f73c165 /c++-libbu++/src/gatsc/main.cpp | |
parent | 61ccc86fdf06f12cb72a8b7e65286f812cf62154 (diff) | |
download | libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.tar.gz libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.tar.bz2 libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.tar.xz libgats-d534a56d95bca7bdd812be024d9eacba4734e2b7.zip |
Many changes: tabconv'd the C++ code, added a license, BSD, and docs.
Diffstat (limited to '')
-rw-r--r-- | c++-libbu++/src/gatsc/main.cpp | 99 |
1 files changed, 53 insertions, 46 deletions
diff --git a/c++-libbu++/src/gatsc/main.cpp b/c++-libbu++/src/gatsc/main.cpp index 2bac3fd..e07fe82 100644 --- a/c++-libbu++/src/gatsc/main.cpp +++ b/c++-libbu++/src/gatsc/main.cpp | |||
@@ -1,3 +1,10 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libgats library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
1 | #include <bu/optparser.h> | 8 | #include <bu/optparser.h> |
2 | #include <bu/string.h> | 9 | #include <bu/string.h> |
3 | #include <bu/file.h> | 10 | #include <bu/file.h> |
@@ -11,63 +18,63 @@ using namespace Bu; | |||
11 | class Options : public OptParser | 18 | class Options : public OptParser |
12 | { | 19 | { |
13 | public: | 20 | public: |
14 | Options( int argc, char *argv[] ) : | 21 | Options( int argc, char *argv[] ) : |
15 | bCompile( true ) | 22 | bCompile( true ) |
16 | { | 23 | { |
17 | addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n"); | 24 | addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n"); |
18 | 25 | ||
19 | addOption( sInput, 'i', "input", "Specify input file."); | 26 | addOption( sInput, 'i', "input", "Specify input file."); |
20 | addOption( sOutput, 'o', "output", "Specify output file."); | 27 | addOption( sOutput, 'o', "output", "Specify output file."); |
21 | 28 | ||
22 | addOption( bCompile, 'd', "decompile", | 29 | addOption( bCompile, 'd', "decompile", |
23 | "Convert binary gats to text gats."); | 30 | "Convert binary gats to text gats."); |
24 | 31 | ||
25 | addHelpOption('h', "help", "This Help"); | 32 | addHelpOption('h', "help", "This Help"); |
26 | 33 | ||
27 | setNonOption( slot( this, &Options::setInput ) ); | 34 | setNonOption( slot( this, &Options::setInput ) ); |
28 | 35 | ||
29 | setOverride("decompile", false ); | 36 | setOverride("decompile", false ); |
30 | 37 | ||
31 | parse( argc, argv ); | 38 | parse( argc, argv ); |
32 | } | 39 | } |
33 | 40 | ||
34 | int setInput( StrArray aParam ) | 41 | int setInput( StrArray aParam ) |
35 | { | 42 | { |
36 | sInput = aParam[0]; | 43 | sInput = aParam[0]; |
37 | return 0; | 44 | return 0; |
38 | } | 45 | } |
39 | 46 | ||
40 | bool bCompile; | 47 | bool bCompile; |
41 | String sInput; | 48 | String sInput; |
42 | String sOutput; | 49 | String sOutput; |
43 | }; | 50 | }; |
44 | 51 | ||
45 | int main( int argc, char *argv[] ) | 52 | int main( int argc, char *argv[] ) |
46 | { | 53 | { |
47 | Options opt( argc, argv ); | 54 | Options opt( argc, argv ); |
48 | 55 | ||
49 | if( opt.sInput.isEmpty() ) | 56 | if( opt.sInput.isEmpty() ) |
50 | { | 57 | { |
51 | sio << "You must specify an input." << sio.nl << sio.nl; | 58 | sio << "You must specify an input." << sio.nl << sio.nl; |
52 | return 1; | 59 | return 1; |
53 | } | 60 | } |
54 | 61 | ||
55 | if( opt.sOutput.isEmpty() ) | 62 | if( opt.sOutput.isEmpty() ) |
56 | { | 63 | { |
57 | opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') ); | 64 | opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') ); |
58 | opt.sOutput += ".gats"; | 65 | opt.sOutput += ".gats"; |
59 | } | 66 | } |
60 | 67 | ||
61 | if( opt.bCompile ) | 68 | if( opt.bCompile ) |
62 | { | 69 | { |
63 | File fIn( opt.sInput, File::Read ); | 70 | File fIn( opt.sInput, File::Read ); |
64 | File fOut( opt.sOutput, File::WriteNew ); | 71 | File fOut( opt.sOutput, File::WriteNew ); |
65 | Gats::GatsStream gs( fOut ); | 72 | Gats::GatsStream gs( fOut ); |
66 | Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() ); | 73 | Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() ); |
67 | gs.writeObject( pObj ); | 74 | gs.writeObject( pObj ); |
68 | delete pObj; | 75 | delete pObj; |
69 | } | 76 | } |
70 | 77 | ||
71 | return 0; | 78 | return 0; |
72 | } | 79 | } |
73 | 80 | ||