aboutsummaryrefslogtreecommitdiff
path: root/c++-libbu++/src
diff options
context:
space:
mode:
Diffstat (limited to 'c++-libbu++/src')
-rw-r--r--c++-libbu++/src/gatsc/main.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/c++-libbu++/src/gatsc/main.cpp b/c++-libbu++/src/gatsc/main.cpp
index e07fe82..339e9f4 100644
--- a/c++-libbu++/src/gatsc/main.cpp
+++ b/c++-libbu++/src/gatsc/main.cpp
@@ -9,6 +9,8 @@
9#include <bu/string.h> 9#include <bu/string.h>
10#include <bu/file.h> 10#include <bu/file.h>
11#include <bu/sio.h> 11#include <bu/sio.h>
12#include <bu/streamstack.h>
13#include <bu/deflate.h>
12 14
13#include "gats/types.h" 15#include "gats/types.h"
14#include "gats/gatsstream.h" 16#include "gats/gatsstream.h"
@@ -19,7 +21,8 @@ class Options : public OptParser
19{ 21{
20public: 22public:
21 Options( int argc, char *argv[] ) : 23 Options( int argc, char *argv[] ) :
22 bCompile( true ) 24 bCompile( true ),
25 bCompress( false )
23 { 26 {
24 addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n"); 27 addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n");
25 28
@@ -29,11 +32,14 @@ public:
29 addOption( bCompile, 'd', "decompile", 32 addOption( bCompile, 'd', "decompile",
30 "Convert binary gats to text gats."); 33 "Convert binary gats to text gats.");
31 34
35 addOption( bCompress, 'z', "compress", "Compress with deflate.");
36
32 addHelpOption('h', "help", "This Help"); 37 addHelpOption('h', "help", "This Help");
33 38
34 setNonOption( slot( this, &Options::setInput ) ); 39 setNonOption( slot( this, &Options::setInput ) );
35 40
36 setOverride("decompile", false ); 41 setOverride("decompile", false );
42 setOverride("compress", true );
37 43
38 parse( argc, argv ); 44 parse( argc, argv );
39 } 45 }
@@ -45,6 +51,7 @@ public:
45 } 51 }
46 52
47 bool bCompile; 53 bool bCompile;
54 bool bCompress;
48 String sInput; 55 String sInput;
49 String sOutput; 56 String sOutput;
50}; 57};
@@ -62,14 +69,21 @@ int main( int argc, char *argv[] )
62 if( opt.sOutput.isEmpty() ) 69 if( opt.sOutput.isEmpty() )
63 { 70 {
64 opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') ); 71 opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') );
65 opt.sOutput += ".gats"; 72 if( opt.bCompress )
73 opt.sOutput += ".gatz";
74 else
75 opt.sOutput += ".gats";
66 } 76 }
67 77
68 if( opt.bCompile ) 78 if( opt.bCompile )
69 { 79 {
70 File fIn( opt.sInput, File::Read ); 80 File fIn( opt.sInput, File::Read );
71 File fOut( opt.sOutput, File::WriteNew ); 81 StreamStack ssOut( new File( opt.sOutput, File::WriteNew ) );
72 Gats::GatsStream gs( fOut ); 82 if( opt.bCompress )
83 {
84 ssOut.pushFilter<Deflate>();
85 }
86 Gats::GatsStream gs( ssOut );
73 Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() ); 87 Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() );
74 gs.writeObject( pObj ); 88 gs.writeObject( pObj );
75 delete pObj; 89 delete pObj;