From 603cb0f890db0d0acd407fcd0e3dfc7aaaf876d4 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 10 Feb 2013 22:25:26 +0000 Subject: Added a cute option to compress gats with deflate in gatsc. --- c++-libbu++/default.bld | 2 +- c++-libbu++/src/gatsc/main.cpp | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/c++-libbu++/default.bld b/c++-libbu++/default.bld index e6d1380..f67b59b 100644 --- a/c++-libbu++/default.bld +++ b/c++-libbu++/default.bld @@ -54,7 +54,7 @@ target "gatsc" input files("src/gatsc/*.cpp"); requires "libgats.a"; CXXFLAGS += "-I. -Ilibbu++"; - LDFLAGS += "-L. -lgats -lbu++"; + LDFLAGS += "-L. -lgats -lbu++ -lz"; } target files("src/tests/*.cpp").replace("src/","").replace(".cpp","") 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 @@ #include #include #include +#include +#include #include "gats/types.h" #include "gats/gatsstream.h" @@ -19,7 +21,8 @@ class Options : public OptParser { public: Options( int argc, char *argv[] ) : - bCompile( true ) + bCompile( true ), + bCompress( false ) { addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n"); @@ -29,11 +32,14 @@ public: addOption( bCompile, 'd', "decompile", "Convert binary gats to text gats."); + addOption( bCompress, 'z', "compress", "Compress with deflate."); + addHelpOption('h', "help", "This Help"); setNonOption( slot( this, &Options::setInput ) ); setOverride("decompile", false ); + setOverride("compress", true ); parse( argc, argv ); } @@ -45,6 +51,7 @@ public: } bool bCompile; + bool bCompress; String sInput; String sOutput; }; @@ -62,14 +69,21 @@ int main( int argc, char *argv[] ) if( opt.sOutput.isEmpty() ) { opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') ); - opt.sOutput += ".gats"; + if( opt.bCompress ) + opt.sOutput += ".gatz"; + else + opt.sOutput += ".gats"; } if( opt.bCompile ) { File fIn( opt.sInput, File::Read ); - File fOut( opt.sOutput, File::WriteNew ); - Gats::GatsStream gs( fOut ); + StreamStack ssOut( new File( opt.sOutput, File::WriteNew ) ); + if( opt.bCompress ) + { + ssOut.pushFilter(); + } + Gats::GatsStream gs( ssOut ); Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() ); gs.writeObject( pObj ); delete pObj; -- cgit v1.2.3