From 18cb422d37084fed768518e89da6bb7ca5e8f040 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 9 Jan 2012 17:08:55 -0700 Subject: Interface plugins are almost done. At least, the basic console interface is almost done. --- .gitignore | 2 + default.bld | 2 +- src/interface.h | 2 +- src/interfaceconsole.cpp | 222 +++++++++++++++++++++++++++++++++++++++ src/interfaceconsole.h | 22 ++++ src/interfacegats.cpp | 71 +++++++++++++ src/interfacegats.h | 15 +++ src/interfaceplugger.cpp | 15 +++ src/interfaceplugger.h | 20 ++++ src/options.cpp | 264 ++++++----------------------------------------- src/options.h | 1 + 11 files changed, 400 insertions(+), 236 deletions(-) create mode 100644 src/interfacegats.cpp create mode 100644 src/interfacegats.h create mode 100644 src/interfaceplugger.cpp create mode 100644 src/interfaceplugger.h diff --git a/.gitignore b/.gitignore index 28b0e0f..9b9c783 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ stage +stage.exe +stage*.zip .build_cache .*.swp *.o diff --git a/default.bld b/default.bld index bacbb6b..2747296 100644 --- a/default.bld +++ b/default.bld @@ -53,7 +53,7 @@ target "stage" FLEXFLAGS="-osrc/parser.yy.c --header-file=src/parser.yy.h"; BISONFLAGS="-d"; - LDFLAGS += "-lbu++"; + LDFLAGS += "-lbu++ -ldl"; } /* diff --git a/src/interface.h b/src/interface.h index 4103f93..bc4bd06 100644 --- a/src/interface.h +++ b/src/interface.h @@ -7,7 +7,7 @@ public: Interface(); virtual ~Interface(); - void display(); + virtual void display( const class SmlNode *pSml )=0; }; #endif diff --git a/src/interfaceconsole.cpp b/src/interfaceconsole.cpp index 0b1b43f..05ca56c 100644 --- a/src/interfaceconsole.cpp +++ b/src/interfaceconsole.cpp @@ -1,5 +1,16 @@ #include "interfaceconsole.h" +#include "smlnode.h" + +#include + +#include + +PluginInterface3( plugin_interface_console, console, InterfaceConsole, + Interface, "Mike Buland", 1, 0 ); + +using namespace Bu; + InterfaceConsole::InterfaceConsole() { } @@ -8,3 +19,214 @@ InterfaceConsole::~InterfaceConsole() { } +void InterfaceConsole::appendToken( Bu::String &sCurLine, + Bu::String &sNextToken, int &iLineLen, int &iNextLen ) +{ + if( iLineLen + iNextLen + 1 >= 78 ) + { + sio << sCurLine << sio.nl; + iLineLen = 0; + sCurLine = sNextToken; + } + else + { + sCurLine += sNextToken; + } + iLineLen += iNextLen + 1; + sCurLine += " "; + iNextLen = 0; + sNextToken.clear(); +} + +Bu::String InterfaceConsole::getVt100Style( const StyleStack &sStyle ) +{ + if( sStyle.isEmpty() ) + { + return "\x1B[0m"; + } + + int sCurStyle = 0; + for( StyleStack::const_iterator i = sStyle.begin(); i; i++ ) + { +// sio << "Merging in: " << Fmt::hex() << *i << sio.nl; + if( ((sCurStyle&stTypeMask) & ((*i)&stTypeMask)) == 0 ) + { + sCurStyle |= *i; +// sio << " -> curStyle = " << Fmt::hex() << *i << sio.nl; + } + } + + Bu::String sRet; + +// sio << "Color: " << Fmt::hex() << sCurStyle << sio.nl; + switch( sCurStyle&stColor ) + { + case stRed: + sRet += "\x1B[1;31m"; + break; + + case stGreen: + sRet += "\x1B[1;32m"; + break; + } + + return sRet; +} + +void InterfaceConsole::display( const SmlNode *pNode ) +{ + Bu::String sCurLine; + Bu::String sNextToken; + int iLineLen = 0; + int iNextLen = 0; + int iState = 0; + typedef Bu::List NodeStack; + NodeStack sNode; + + StyleStack sStyle; + + sNode.push( pNode->getChildren().begin() ); + + for(;;) + { + if( !sNode.peek() ) + { + sNode.pop(); + if( sNode.isEmpty() ) + break; + if( sNode.peek() ) + { + // sio << "Pop'd: " << (*sNode.peek())->getText() << sio.nl; + Bu::String sTag = (*sNode.peek())->getText(); + if( sTag == "green" || sTag == "red" ) + { + sStyle.pop(); + sNextToken += getVt100Style( sStyle ); + } + sNode.peek()++; + continue; + } + } + if( sNode.isEmpty() ) + { + break; + } + const SmlNode *pNode = (*sNode.peek()); + switch( pNode->getType() ) + { + case SmlNode::typeRoot: + throw Bu::ExceptionBase("Invalid root."); + + case SmlNode::typeText: + { + // sio << "Process text node: " << pNode->getText() << + // sio.nl; + Bu::String::const_iterator iBgn = pNode->getText().begin(); + Bu::String::const_iterator iEnd = iBgn; + int iTmpLen = 0; + for(;iBgn;) + { + switch( iState ) + { + case 0: // begining of paragraph + if( iBgn && ( *iBgn == ' ' || *iBgn == '\n' || + *iBgn == '\r' || *iBgn == '\t' ) ) + { + iBgn++; + } + else + { + // Here is where you would indent paragraphs + iEnd = iBgn; + iState = 1; + } + break; + + case 1: // non-whitespace + if( !iEnd ) + { + sNextToken.append( iBgn, iEnd ); + iBgn = iEnd; + iNextLen += iTmpLen; + iTmpLen = 0; + } + else if( *iEnd == ' ' || *iEnd == '\n' || + *iEnd == '\r' || *iEnd == '\t' ) + { + sNextToken.append( iBgn, iEnd ); + iNextLen += iTmpLen; + iTmpLen = 0; + iState = 2; + iBgn = iEnd; + } + else + { + iEnd++; + iTmpLen++; + } + break; + + case 2: // Whitespace + if( iBgn && (*iBgn == ' ' || *iBgn == '\n' || + *iBgn == '\r' || *iBgn == '\t') ) + { + iBgn++; + } + else + { + iEnd = iBgn; + iState = 1; + appendToken( sCurLine, sNextToken, + iLineLen, iNextLen ); + } + break; + } + } + } + break; + + case SmlNode::typeTag: + if( pNode->getChildren().isEmpty() ) + { + if( pNode->getText() == "break" ) + { + appendToken( sCurLine, sNextToken, iLineLen, iNextLen ); + if( !sCurLine.isEmpty() ) + sio << sCurLine << sio.nl; + sCurLine.clear(); + iLineLen = 0; + iState = 0; + } + } + else + { +// sio << "Push'd: " << pNode->getText() << sio.nl; + Bu::String sTag = pNode->getText(); + if( sTag == "green" ) + { + sStyle.push( stGreen ); + } + else if( sTag == "red" ) + { + sStyle.push( stRed ); + } + sNextToken += getVt100Style( sStyle ); + sNode.push( pNode->getChildren().begin() ); + continue; +/* for( SmlNode::SmlNodeList::const_iterator i = + pNode->getChildren().begin(); i; i++ ) + { + s + smlToConsole( *i, sCurLine, sNextToken, iLineLen, iState ); + } +*/ + } + break; + } + sNode.peek()++; + } + if( !sNextToken.isEmpty() ) + appendToken( sCurLine, sNextToken, iLineLen, iNextLen ); + sio << sCurLine << sio.nl; +} + diff --git a/src/interfaceconsole.h b/src/interfaceconsole.h index 74f88d0..9272087 100644 --- a/src/interfaceconsole.h +++ b/src/interfaceconsole.h @@ -3,11 +3,33 @@ #include "interface.h" +#include +#include + class InterfaceConsole : public Interface { public: InterfaceConsole(); virtual ~InterfaceConsole(); + + virtual void display( const class SmlNode *pSml ); + +private: + enum Style + { + stRed = 0x010001, + stGreen = 0x010002, + + stColor = 0x01000f, + + stTypeMask = 0xff0000, + }; + + typedef Bu::List