From 105aa3262bde83a33394ec57401ecf53e8d81971 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 8 Feb 2012 10:52:30 -0700 Subject: Deflate support, more colors. --- src/options.cpp | 15 ++++++++++ src/options.h | 1 + src/smlrenderervt100.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++------ src/smlrenderervt100.h | 8 ++++++ 4 files changed, 89 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/options.cpp b/src/options.cpp index f8112c4..93a29bc 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -12,6 +12,8 @@ #include #include +#include + #include "interfaceplugger.h" using namespace Bu; @@ -48,6 +50,8 @@ void Options::parse( int argc, char *argv[] ) opt.addOption( Bu::slot( this, &Options::smlTest ), "sml-test", "Test SML parser." ); + opt.addOption( Bu::slot( this, &Options::smlHelp ), "sml-help", + "Display SML help." ); opt.addOption( sCommand, "command", "Set the command to execute once the game is loaded. " "This does not work with all interfaces."); @@ -124,6 +128,17 @@ int Options::smlTest( Bu::Array aArgs ) return 0; } +int Options::smlHelp( Bu::Array aArgs ) +{ + Bu::File fIn("sml-help.sml.gz", Bu::File::Read ); + Bu::Deflate dIn( fIn ); + char buf[4096]; + buf[dIn.read( buf, 4096 )] = '\0'; + printf("%s\n", buf ); + + return 0; +} + int Options::nonOption( Bu::Array aArgs ) { sFile = aArgs[0]; diff --git a/src/options.h b/src/options.h index bf9825f..4ac030b 100644 --- a/src/options.h +++ b/src/options.h @@ -23,6 +23,7 @@ protected: int version( Bu::Array aArgs ); int builtins( Bu::Array aArgs ); int smlTest( Bu::Array aArgs ); + int smlHelp( Bu::Array aArgs ); int nonOption( Bu::Array aArgs ); int printResult( Bu::Array aArgs ); }; diff --git a/src/smlrenderervt100.cpp b/src/smlrenderervt100.cpp index 2b59d5f..5ab3d82 100644 --- a/src/smlrenderervt100.cpp +++ b/src/smlrenderervt100.cpp @@ -63,11 +63,67 @@ Bu::String SmlRendererVt100::getStyle( const StyleStack &sStyle ) case stGreen: sRet += "\x1B[1;32m"; break; + + case stYellow: + sRet += "\x1B[1;33m"; + break; + + case stBlue: + sRet += "\x1B[1;34m"; + break; + + case stMagenta: + sRet += "\x1B[1;35m"; + break; + + case stCyan: + sRet += "\x1B[1;36m"; + break; + + case stWhite: + sRet += "\x1B[1;37m"; + break; } return sRet; } +SmlRendererVt100::Style SmlRendererVt100::strToStyle( const Bu::String &sTag ) +{ + if( sTag == "green" ) + { + return stGreen; + } + else if( sTag == "red" ) + { + return stRed; + } + else if( sTag == "yellow" ) + { + return stYellow; + } + else if( sTag == "blue" ) + { + return stBlue; + } + else if( sTag == "magenta" ) + { + return stMagenta; + } + else if( sTag == "cyan" ) + { + return stCyan; + } + else if( sTag == "white" ) + { + return stWhite; + } + else + { + return stNone; + } +} + void SmlRendererVt100::render( Bu::Formatter &f, const SmlNode *pNode ) { Bu::String sCurLine; @@ -93,11 +149,16 @@ void SmlRendererVt100::render( Bu::Formatter &f, const SmlNode *pNode ) { // f << "Pop'd: " << (*sNode.peek())->getText() << f.nl; Bu::String sTag = (*sNode.peek())->getText(); - if( sTag == "green" || sTag == "red" ) + Style s = strToStyle( sTag ); + if( sStyle.peek() == s ) { sStyle.pop(); sNextToken += getStyle( sStyle ); } + else + { + throw Bu::ExceptionBase("Close tag doesn't match open tag."); + } sNode.peek()++; continue; } @@ -199,14 +260,9 @@ void SmlRendererVt100::render( Bu::Formatter &f, const SmlNode *pNode ) { // f << "Push'd: " << pNode->getText() << f.nl; Bu::String sTag = pNode->getText(); - if( sTag == "green" ) - { - sStyle.push( stGreen ); - } - else if( sTag == "red" ) - { - sStyle.push( stRed ); - } + Style s = strToStyle( sTag ); + if( s != 0 ) + sStyle.push( s ); sNextToken += getStyle( sStyle ); sNode.push( pNode->getChildren().begin() ); continue; diff --git a/src/smlrenderervt100.h b/src/smlrenderervt100.h index ed5dd42..0f82ca9 100644 --- a/src/smlrenderervt100.h +++ b/src/smlrenderervt100.h @@ -14,8 +14,15 @@ public: private: enum Style { + stNone = 0x000000, + stRed = 0x010001, stGreen = 0x010002, + stYellow = 0x010003, + stBlue = 0x010004, + stMagenta = 0x010005, + stCyan = 0x010006, + stWhite = 0x010007, stColor = 0x01000f, @@ -27,6 +34,7 @@ private: void appendToken( Bu::Formatter &f, Bu::String &sCurLine, Bu::String &sNextToken, int &iLineLen, int &iNextLen ); Bu::String getStyle( const StyleStack &sStyle ); + Style strToStyle( const Bu::String &sStyle ); }; #endif -- cgit v1.2.3