diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-01-09 17:08:55 -0700 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-01-09 17:08:55 -0700 |
| commit | 18cb422d37084fed768518e89da6bb7ca5e8f040 (patch) | |
| tree | b71b1bf383eb1275261111fdb5501b5abddc2876 | |
| parent | 5d21388a640239cadcfbf3ee2fd296db9d0eab4a (diff) | |
| download | stage-18cb422d37084fed768518e89da6bb7ca5e8f040.tar.gz stage-18cb422d37084fed768518e89da6bb7ca5e8f040.tar.bz2 stage-18cb422d37084fed768518e89da6bb7ca5e8f040.tar.xz stage-18cb422d37084fed768518e89da6bb7ca5e8f040.zip | |
Interface plugins are almost done.
At least, the basic console interface is almost done.
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | default.bld | 2 | ||||
| -rw-r--r-- | src/interface.h | 2 | ||||
| -rw-r--r-- | src/interfaceconsole.cpp | 222 | ||||
| -rw-r--r-- | src/interfaceconsole.h | 22 | ||||
| -rw-r--r-- | src/interfacegats.cpp | 71 | ||||
| -rw-r--r-- | src/interfacegats.h | 15 | ||||
| -rw-r--r-- | src/interfaceplugger.cpp | 15 | ||||
| -rw-r--r-- | src/interfaceplugger.h | 20 | ||||
| -rw-r--r-- | src/options.cpp | 264 | ||||
| -rw-r--r-- | src/options.h | 1 |
11 files changed, 400 insertions, 236 deletions
| @@ -1,4 +1,6 @@ | |||
| 1 | stage | 1 | stage |
| 2 | stage.exe | ||
| 3 | stage*.zip | ||
| 2 | .build_cache | 4 | .build_cache |
| 3 | .*.swp | 5 | .*.swp |
| 4 | *.o | 6 | *.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" | |||
| 53 | FLEXFLAGS="-osrc/parser.yy.c --header-file=src/parser.yy.h"; | 53 | FLEXFLAGS="-osrc/parser.yy.c --header-file=src/parser.yy.h"; |
| 54 | BISONFLAGS="-d"; | 54 | BISONFLAGS="-d"; |
| 55 | 55 | ||
| 56 | LDFLAGS += "-lbu++"; | 56 | LDFLAGS += "-lbu++ -ldl"; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | /* | 59 | /* |
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: | |||
| 7 | Interface(); | 7 | Interface(); |
| 8 | virtual ~Interface(); | 8 | virtual ~Interface(); |
| 9 | 9 | ||
| 10 | void display(); | 10 | virtual void display( const class SmlNode *pSml )=0; |
| 11 | }; | 11 | }; |
| 12 | 12 | ||
| 13 | #endif | 13 | #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 @@ | |||
| 1 | #include "interfaceconsole.h" | 1 | #include "interfaceconsole.h" |
| 2 | 2 | ||
| 3 | #include "smlnode.h" | ||
| 4 | |||
| 5 | #include <bu/sio.h> | ||
| 6 | |||
| 7 | #include <bu/plugger.h> | ||
| 8 | |||
| 9 | PluginInterface3( plugin_interface_console, console, InterfaceConsole, | ||
| 10 | Interface, "Mike Buland", 1, 0 ); | ||
| 11 | |||
| 12 | using namespace Bu; | ||
| 13 | |||
| 3 | InterfaceConsole::InterfaceConsole() | 14 | InterfaceConsole::InterfaceConsole() |
| 4 | { | 15 | { |
| 5 | } | 16 | } |
| @@ -8,3 +19,214 @@ InterfaceConsole::~InterfaceConsole() | |||
| 8 | { | 19 | { |
| 9 | } | 20 | } |
| 10 | 21 | ||
| 22 | void InterfaceConsole::appendToken( Bu::String &sCurLine, | ||
| 23 | Bu::String &sNextToken, int &iLineLen, int &iNextLen ) | ||
| 24 | { | ||
| 25 | if( iLineLen + iNextLen + 1 >= 78 ) | ||
| 26 | { | ||
| 27 | sio << sCurLine << sio.nl; | ||
| 28 | iLineLen = 0; | ||
| 29 | sCurLine = sNextToken; | ||
| 30 | } | ||
| 31 | else | ||
| 32 | { | ||
| 33 | sCurLine += sNextToken; | ||
| 34 | } | ||
| 35 | iLineLen += iNextLen + 1; | ||
| 36 | sCurLine += " "; | ||
| 37 | iNextLen = 0; | ||
| 38 | sNextToken.clear(); | ||
| 39 | } | ||
| 40 | |||
| 41 | Bu::String InterfaceConsole::getVt100Style( const StyleStack &sStyle ) | ||
| 42 | { | ||
| 43 | if( sStyle.isEmpty() ) | ||
| 44 | { | ||
| 45 | return "\x1B[0m"; | ||
| 46 | } | ||
| 47 | |||
| 48 | int sCurStyle = 0; | ||
| 49 | for( StyleStack::const_iterator i = sStyle.begin(); i; i++ ) | ||
| 50 | { | ||
| 51 | // sio << "Merging in: " << Fmt::hex() << *i << sio.nl; | ||
| 52 | if( ((sCurStyle&stTypeMask) & ((*i)&stTypeMask)) == 0 ) | ||
| 53 | { | ||
| 54 | sCurStyle |= *i; | ||
| 55 | // sio << " -> curStyle = " << Fmt::hex() << *i << sio.nl; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | Bu::String sRet; | ||
| 60 | |||
| 61 | // sio << "Color: " << Fmt::hex() << sCurStyle << sio.nl; | ||
| 62 | switch( sCurStyle&stColor ) | ||
| 63 | { | ||
| 64 | case stRed: | ||
| 65 | sRet += "\x1B[1;31m"; | ||
| 66 | break; | ||
| 67 | |||
| 68 | case stGreen: | ||
| 69 | sRet += "\x1B[1;32m"; | ||
| 70 | break; | ||
| 71 | } | ||
| 72 | |||
| 73 | return sRet; | ||
| 74 | } | ||
| 75 | |||
| 76 | void InterfaceConsole::display( const SmlNode *pNode ) | ||
| 77 | { | ||
| 78 | Bu::String sCurLine; | ||
| 79 | Bu::String sNextToken; | ||
| 80 | int iLineLen = 0; | ||
| 81 | int iNextLen = 0; | ||
| 82 | int iState = 0; | ||
| 83 | typedef Bu::List<SmlNode::SmlNodeList::const_iterator> NodeStack; | ||
| 84 | NodeStack sNode; | ||
| 85 | |||
| 86 | StyleStack sStyle; | ||
| 87 | |||
| 88 | sNode.push( pNode->getChildren().begin() ); | ||
| 89 | |||
| 90 | for(;;) | ||
| 91 | { | ||
| 92 | if( !sNode.peek() ) | ||
| 93 | { | ||
| 94 | sNode.pop(); | ||
| 95 | if( sNode.isEmpty() ) | ||
| 96 | break; | ||
| 97 | if( sNode.peek() ) | ||
| 98 | { | ||
| 99 | // sio << "Pop'd: " << (*sNode.peek())->getText() << sio.nl; | ||
| 100 | Bu::String sTag = (*sNode.peek())->getText(); | ||
| 101 | if( sTag == "green" || sTag == "red" ) | ||
| 102 | { | ||
| 103 | sStyle.pop(); | ||
| 104 | sNextToken += getVt100Style( sStyle ); | ||
| 105 | } | ||
| 106 | sNode.peek()++; | ||
| 107 | continue; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | if( sNode.isEmpty() ) | ||
| 111 | { | ||
| 112 | break; | ||
| 113 | } | ||
| 114 | const SmlNode *pNode = (*sNode.peek()); | ||
| 115 | switch( pNode->getType() ) | ||
| 116 | { | ||
| 117 | case SmlNode::typeRoot: | ||
| 118 | throw Bu::ExceptionBase("Invalid root."); | ||
| 119 | |||
| 120 | case SmlNode::typeText: | ||
| 121 | { | ||
| 122 | // sio << "Process text node: " << pNode->getText() << | ||
| 123 | // sio.nl; | ||
| 124 | Bu::String::const_iterator iBgn = pNode->getText().begin(); | ||
| 125 | Bu::String::const_iterator iEnd = iBgn; | ||
| 126 | int iTmpLen = 0; | ||
| 127 | for(;iBgn;) | ||
| 128 | { | ||
| 129 | switch( iState ) | ||
| 130 | { | ||
| 131 | case 0: // begining of paragraph | ||
| 132 | if( iBgn && ( *iBgn == ' ' || *iBgn == '\n' || | ||
| 133 | *iBgn == '\r' || *iBgn == '\t' ) ) | ||
| 134 | { | ||
| 135 | iBgn++; | ||
| 136 | } | ||
| 137 | else | ||
| 138 | { | ||
| 139 | // Here is where you would indent paragraphs | ||
| 140 | iEnd = iBgn; | ||
| 141 | iState = 1; | ||
| 142 | } | ||
| 143 | break; | ||
| 144 | |||
| 145 | case 1: // non-whitespace | ||
| 146 | if( !iEnd ) | ||
| 147 | { | ||
| 148 | sNextToken.append( iBgn, iEnd ); | ||
| 149 | iBgn = iEnd; | ||
| 150 | iNextLen += iTmpLen; | ||
| 151 | iTmpLen = 0; | ||
| 152 | } | ||
| 153 | else if( *iEnd == ' ' || *iEnd == '\n' || | ||
| 154 | *iEnd == '\r' || *iEnd == '\t' ) | ||
| 155 | { | ||
| 156 | sNextToken.append( iBgn, iEnd ); | ||
| 157 | iNextLen += iTmpLen; | ||
| 158 | iTmpLen = 0; | ||
| 159 | iState = 2; | ||
| 160 | iBgn = iEnd; | ||
| 161 | } | ||
| 162 | else | ||
| 163 | { | ||
| 164 | iEnd++; | ||
| 165 | iTmpLen++; | ||
| 166 | } | ||
| 167 | break; | ||
| 168 | |||
| 169 | case 2: // Whitespace | ||
| 170 | if( iBgn && (*iBgn == ' ' || *iBgn == '\n' || | ||
| 171 | *iBgn == '\r' || *iBgn == '\t') ) | ||
| 172 | { | ||
| 173 | iBgn++; | ||
| 174 | } | ||
| 175 | else | ||
| 176 | { | ||
| 177 | iEnd = iBgn; | ||
| 178 | iState = 1; | ||
| 179 | appendToken( sCurLine, sNextToken, | ||
| 180 | iLineLen, iNextLen ); | ||
| 181 | } | ||
| 182 | break; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | } | ||
| 186 | break; | ||
| 187 | |||
| 188 | case SmlNode::typeTag: | ||
| 189 | if( pNode->getChildren().isEmpty() ) | ||
| 190 | { | ||
| 191 | if( pNode->getText() == "break" ) | ||
| 192 | { | ||
| 193 | appendToken( sCurLine, sNextToken, iLineLen, iNextLen ); | ||
| 194 | if( !sCurLine.isEmpty() ) | ||
| 195 | sio << sCurLine << sio.nl; | ||
| 196 | sCurLine.clear(); | ||
| 197 | iLineLen = 0; | ||
| 198 | iState = 0; | ||
| 199 | } | ||
| 200 | } | ||
| 201 | else | ||
| 202 | { | ||
| 203 | // sio << "Push'd: " << pNode->getText() << sio.nl; | ||
| 204 | Bu::String sTag = pNode->getText(); | ||
| 205 | if( sTag == "green" ) | ||
| 206 | { | ||
| 207 | sStyle.push( stGreen ); | ||
| 208 | } | ||
| 209 | else if( sTag == "red" ) | ||
| 210 | { | ||
| 211 | sStyle.push( stRed ); | ||
| 212 | } | ||
| 213 | sNextToken += getVt100Style( sStyle ); | ||
| 214 | sNode.push( pNode->getChildren().begin() ); | ||
| 215 | continue; | ||
| 216 | /* for( SmlNode::SmlNodeList::const_iterator i = | ||
| 217 | pNode->getChildren().begin(); i; i++ ) | ||
| 218 | { | ||
| 219 | s | ||
| 220 | smlToConsole( *i, sCurLine, sNextToken, iLineLen, iState ); | ||
| 221 | } | ||
| 222 | */ | ||
| 223 | } | ||
| 224 | break; | ||
| 225 | } | ||
| 226 | sNode.peek()++; | ||
| 227 | } | ||
| 228 | if( !sNextToken.isEmpty() ) | ||
| 229 | appendToken( sCurLine, sNextToken, iLineLen, iNextLen ); | ||
| 230 | sio << sCurLine << sio.nl; | ||
| 231 | } | ||
| 232 | |||
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 @@ | |||
| 3 | 3 | ||
| 4 | #include "interface.h" | 4 | #include "interface.h" |
| 5 | 5 | ||
| 6 | #include <bu/list.h> | ||
| 7 | #include <bu/string.h> | ||
| 8 | |||
| 6 | class InterfaceConsole : public Interface | 9 | class InterfaceConsole : public Interface |
| 7 | { | 10 | { |
| 8 | public: | 11 | public: |
| 9 | InterfaceConsole(); | 12 | InterfaceConsole(); |
| 10 | virtual ~InterfaceConsole(); | 13 | virtual ~InterfaceConsole(); |
| 14 | |||
| 15 | virtual void display( const class SmlNode *pSml ); | ||
| 16 | |||
| 17 | private: | ||
| 18 | enum Style | ||
| 19 | { | ||
| 20 | stRed = 0x010001, | ||
| 21 | stGreen = 0x010002, | ||
| 22 | |||
| 23 | stColor = 0x01000f, | ||
| 24 | |||
| 25 | stTypeMask = 0xff0000, | ||
| 26 | }; | ||
| 27 | |||
| 28 | typedef Bu::List<Style> StyleStack; | ||
| 29 | |||
| 30 | void appendToken( Bu::String &sCurLine, Bu::String &sNextToken, | ||
| 31 | int &iLineLen, int &iNextLen ); | ||
| 32 | Bu::String getVt100Style( const StyleStack &sStyle ); | ||
| 11 | }; | 33 | }; |
| 12 | 34 | ||
| 13 | #endif | 35 | #endif |
diff --git a/src/interfacegats.cpp b/src/interfacegats.cpp new file mode 100644 index 0000000..bd936c7 --- /dev/null +++ b/src/interfacegats.cpp | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | #include "interfacegats.h" | ||
| 2 | |||
| 3 | #include "smlnode.h" | ||
| 4 | |||
| 5 | #include <bu/plugger.h> | ||
| 6 | #include <bu/sio.h> | ||
| 7 | |||
| 8 | using namespace Bu; | ||
| 9 | |||
| 10 | PluginInterface3( plugin_interface_gats, gats, InterfaceGats, | ||
| 11 | Interface, "Mike Buland", 1, 0 ); | ||
| 12 | |||
| 13 | InterfaceGats::InterfaceGats() | ||
| 14 | { | ||
| 15 | } | ||
| 16 | |||
| 17 | InterfaceGats::~InterfaceGats() | ||
| 18 | { | ||
| 19 | } | ||
| 20 | |||
| 21 | void InterfaceGats::display( const SmlNode *pSml ) | ||
| 22 | { | ||
| 23 | switch( pSml->getType() ) | ||
| 24 | { | ||
| 25 | case SmlNode::typeRoot: | ||
| 26 | sio << "<p>"; | ||
| 27 | for( SmlNode::SmlNodeList::const_iterator i = | ||
| 28 | pSml->getChildren().begin(); i; i++ ) | ||
| 29 | { | ||
| 30 | display( *i ); | ||
| 31 | } | ||
| 32 | sio << "</p>"; | ||
| 33 | break; | ||
| 34 | |||
| 35 | case SmlNode::typeText: | ||
| 36 | sio << pSml->getText(); | ||
| 37 | break; | ||
| 38 | |||
| 39 | case SmlNode::typeTag: | ||
| 40 | if( pSml->getChildren().isEmpty() ) | ||
| 41 | { | ||
| 42 | if( pSml->getText() == "break" ) | ||
| 43 | sio << "</p><p>"; | ||
| 44 | } | ||
| 45 | else | ||
| 46 | { | ||
| 47 | if( pSml->getText() == "red" ) | ||
| 48 | { | ||
| 49 | sio << "<span style=\"color: red;\">"; | ||
| 50 | for( SmlNode::SmlNodeList::const_iterator i = | ||
| 51 | pSml->getChildren().begin(); i; i++ ) | ||
| 52 | { | ||
| 53 | display( *i ); | ||
| 54 | } | ||
| 55 | sio << "</span>"; | ||
| 56 | } | ||
| 57 | else if( pSml->getText() == "green" ) | ||
| 58 | { | ||
| 59 | sio << "<span style=\"color: green;\">"; | ||
| 60 | for( SmlNode::SmlNodeList::const_iterator i = | ||
| 61 | pSml->getChildren().begin(); i; i++ ) | ||
| 62 | { | ||
| 63 | display( *i ); | ||
| 64 | } | ||
| 65 | sio << "</span>"; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | break; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
diff --git a/src/interfacegats.h b/src/interfacegats.h new file mode 100644 index 0000000..b04abb3 --- /dev/null +++ b/src/interfacegats.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #ifndef INTERFACE_GATS_H | ||
| 2 | #define INETRFACE_GATS_H | ||
| 3 | |||
| 4 | #include "interface.h" | ||
| 5 | |||
| 6 | class InterfaceGats : public Interface | ||
| 7 | { | ||
| 8 | public: | ||
| 9 | InterfaceGats(); | ||
| 10 | virtual ~InterfaceGats(); | ||
| 11 | |||
| 12 | virtual void display( const class SmlNode *pSml ); | ||
| 13 | }; | ||
| 14 | |||
| 15 | #endif | ||
diff --git a/src/interfaceplugger.cpp b/src/interfaceplugger.cpp new file mode 100644 index 0000000..ddb0f9a --- /dev/null +++ b/src/interfaceplugger.cpp | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #include "interfaceplugger.h" | ||
| 2 | |||
| 3 | extern struct Bu::PluginInfo plugin_interface_console; | ||
| 4 | extern struct Bu::PluginInfo plugin_interface_gats; | ||
| 5 | |||
| 6 | InterfacePlugger::InterfacePlugger() | ||
| 7 | { | ||
| 8 | registerBuiltinPlugin( &plugin_interface_console ); | ||
| 9 | registerBuiltinPlugin( &plugin_interface_gats ); | ||
| 10 | } | ||
| 11 | |||
| 12 | InterfacePlugger::~InterfacePlugger() | ||
| 13 | { | ||
| 14 | } | ||
| 15 | |||
diff --git a/src/interfaceplugger.h b/src/interfaceplugger.h new file mode 100644 index 0000000..ee36477 --- /dev/null +++ b/src/interfaceplugger.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | #ifndef INTERFACE_PLUGGER_H | ||
| 2 | #define INETRFACE_PLUGGER_H | ||
| 3 | |||
| 4 | #include <bu/singleton.h> | ||
| 5 | #include <bu/plugger.h> | ||
| 6 | #include "interface.h" | ||
| 7 | |||
| 8 | class InterfacePlugger : public Bu::Singleton<InterfacePlugger>, | ||
| 9 | public Bu::Plugger<Interface> | ||
| 10 | { | ||
| 11 | friend class Bu::Singleton<InterfacePlugger>; | ||
| 12 | private: | ||
| 13 | InterfacePlugger(); | ||
| 14 | virtual ~InterfacePlugger(); | ||
| 15 | |||
| 16 | public: | ||
| 17 | |||
| 18 | }; | ||
| 19 | |||
| 20 | #endif | ||
diff --git a/src/options.cpp b/src/options.cpp index c2e7313..ac43dfc 100644 --- a/src/options.cpp +++ b/src/options.cpp | |||
| @@ -10,9 +10,12 @@ | |||
| 10 | #include <bu/optparser.h> | 10 | #include <bu/optparser.h> |
| 11 | #include <bu/sio.h> | 11 | #include <bu/sio.h> |
| 12 | 12 | ||
| 13 | #include "interfaceplugger.h" | ||
| 14 | |||
| 13 | using namespace Bu; | 15 | using namespace Bu; |
| 14 | 16 | ||
| 15 | Options::Options() | 17 | Options::Options() : |
| 18 | sInterface("console") | ||
| 16 | { | 19 | { |
| 17 | } | 20 | } |
| 18 | 21 | ||
| @@ -29,12 +32,27 @@ void Options::parse( int argc, char *argv[] ) | |||
| 29 | opt.addHelpBanner("usage: " + Bu::String(argv[0]) + | 32 | opt.addHelpBanner("usage: " + Bu::String(argv[0]) + |
| 30 | " [options] <filename>\n"); | 33 | " [options] <filename>\n"); |
| 31 | 34 | ||
| 35 | Bu::String sIFaces; | ||
| 36 | Bu::StringList lIFaces = InterfacePlugger::getInstance().getPluginList(); | ||
| 37 | bool bBegin = true; | ||
| 38 | for( Bu::List<Bu::String>::const_iterator i = lIFaces.begin(); i; i++ ) | ||
| 39 | { | ||
| 40 | if( bBegin ) | ||
| 41 | bBegin = false; | ||
| 42 | else | ||
| 43 | sIFaces += ", "; | ||
| 44 | sIFaces += *i; | ||
| 45 | } | ||
| 46 | |||
| 32 | opt.addOption( Bu::slot( this, &Options::smlTest ), "sml-test", | 47 | opt.addOption( Bu::slot( this, &Options::smlTest ), "sml-test", |
| 33 | "Test SML parser." ); | 48 | "Test SML parser." ); |
| 34 | opt.addOption( Bu::slot( this, &Options::version ), "version", | 49 | opt.addOption( Bu::slot( this, &Options::version ), "version", |
| 35 | "Show full version info." ); | 50 | "Show full version info." ); |
| 36 | opt.addOption( Bu::slot( this, &Options::builtins ), "builtins", | 51 | opt.addOption( Bu::slot( this, &Options::builtins ), "builtins", |
| 37 | "List available builtins." ); | 52 | "List available builtins." ); |
| 53 | opt.addOption( sInterface, 'i', "interface", | ||
| 54 | "Select interface module. Default is " + sInterface + | ||
| 55 | ". Available modules: " + sIFaces ); | ||
| 38 | 56 | ||
| 39 | opt.addHelpOption('h', "help"); | 57 | opt.addHelpOption('h', "help"); |
| 40 | opt.setNonOption( Bu::slot( this, &Options::nonOption ) ); | 58 | opt.setNonOption( Bu::slot( this, &Options::nonOption ) ); |
| @@ -67,238 +85,6 @@ int Options::builtins( Bu::StrArray aArgs ) | |||
| 67 | return 0; | 85 | return 0; |
| 68 | } | 86 | } |
| 69 | 87 | ||
| 70 | void smlToHtml( const SmlNode *pNode ) | ||
| 71 | { | ||
| 72 | switch( pNode->getType() ) | ||
| 73 | { | ||
| 74 | case SmlNode::typeRoot: | ||
| 75 | sio << "<p>"; | ||
| 76 | for( SmlNode::SmlNodeList::const_iterator i = | ||
| 77 | pNode->getChildren().begin(); i; i++ ) | ||
| 78 | { | ||
| 79 | smlToHtml( *i ); | ||
| 80 | } | ||
| 81 | sio << "</p>"; | ||
| 82 | break; | ||
| 83 | |||
| 84 | case SmlNode::typeText: | ||
| 85 | sio << pNode->getText(); | ||
| 86 | break; | ||
| 87 | |||
| 88 | case SmlNode::typeTag: | ||
| 89 | if( pNode->getChildren().isEmpty() ) | ||
| 90 | { | ||
| 91 | if( pNode->getText() == "break" ) | ||
| 92 | sio << "</p><p>"; | ||
| 93 | } | ||
| 94 | else | ||
| 95 | { | ||
| 96 | if( pNode->getText() == "red" ) | ||
| 97 | { | ||
| 98 | sio << "<span style=\"color: red;\">"; | ||
| 99 | for( SmlNode::SmlNodeList::const_iterator i = | ||
| 100 | pNode->getChildren().begin(); i; i++ ) | ||
| 101 | { | ||
| 102 | smlToHtml( *i ); | ||
| 103 | } | ||
| 104 | sio << "</span>"; | ||
| 105 | } | ||
| 106 | else if( pNode->getText() == "green" ) | ||
| 107 | { | ||
| 108 | sio << "<span style=\"color: green;\">"; | ||
| 109 | for( SmlNode::SmlNodeList::const_iterator i = | ||
| 110 | pNode->getChildren().begin(); i; i++ ) | ||
| 111 | { | ||
| 112 | smlToHtml( *i ); | ||
| 113 | } | ||
| 114 | sio << "</span>"; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | break; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | void appendToken( Bu::String &sCurLine, Bu::String &sNextToken, int &iLineLen, | ||
| 122 | int &iNextLen ) | ||
| 123 | { | ||
| 124 | if( iLineLen + iNextLen + 1 >= 78 ) | ||
| 125 | { | ||
| 126 | sio << sCurLine << sio.nl; | ||
| 127 | iLineLen = 0; | ||
| 128 | sCurLine = sNextToken; | ||
| 129 | } | ||
| 130 | else | ||
| 131 | { | ||
| 132 | sCurLine += sNextToken; | ||
| 133 | } | ||
| 134 | iLineLen += iNextLen + 1; | ||
| 135 | sCurLine += " "; | ||
| 136 | iNextLen = 0; | ||
| 137 | sNextToken.clear(); | ||
| 138 | } | ||
| 139 | |||
| 140 | void smlToConsole( const SmlNode *pNode ) | ||
| 141 | { | ||
| 142 | Bu::String sCurLine; | ||
| 143 | Bu::String sNextToken; | ||
| 144 | int iLineLen = 0; | ||
| 145 | int iNextLen = 0; | ||
| 146 | int iState = 0; | ||
| 147 | typedef Bu::List<SmlNode::SmlNodeList::const_iterator> NodeStack; | ||
| 148 | NodeStack sNode; | ||
| 149 | |||
| 150 | sNode.push( pNode->getChildren().begin() ); | ||
| 151 | |||
| 152 | for(;;) | ||
| 153 | { | ||
| 154 | if( !sNode.peek() ) | ||
| 155 | { | ||
| 156 | sNode.pop(); | ||
| 157 | if( sNode.isEmpty() ) | ||
| 158 | break; | ||
| 159 | if( sNode.peek() ) | ||
| 160 | { | ||
| 161 | // sio << "Pop'd: " << (*sNode.peek())->getText() << sio.nl; | ||
| 162 | Bu::String sTag = (*sNode.peek())->getText(); | ||
| 163 | if( sTag == "green" || sTag == "red" ) | ||
| 164 | { | ||
| 165 | sNextToken += "\x1B[0m"; | ||
| 166 | } | ||
| 167 | sNode.peek()++; | ||
| 168 | continue; | ||
| 169 | } | ||
| 170 | } | ||
| 171 | if( sNode.isEmpty() ) | ||
| 172 | { | ||
| 173 | break; | ||
| 174 | } | ||
| 175 | const SmlNode *pNode = (*sNode.peek()); | ||
| 176 | switch( pNode->getType() ) | ||
| 177 | { | ||
| 178 | case SmlNode::typeRoot: | ||
| 179 | throw Bu::ExceptionBase("Invalid root."); | ||
| 180 | |||
| 181 | case SmlNode::typeText: | ||
| 182 | { | ||
| 183 | // sio << "Process text node: " << pNode->getText() << | ||
| 184 | // sio.nl; | ||
| 185 | Bu::String::const_iterator iBgn = pNode->getText().begin(); | ||
| 186 | Bu::String::const_iterator iEnd = iBgn; | ||
| 187 | int iTmpLen = 0; | ||
| 188 | for(;iBgn;) | ||
| 189 | { | ||
| 190 | switch( iState ) | ||
| 191 | { | ||
| 192 | case 0: // begining of paragraph | ||
| 193 | if( iBgn && ( *iBgn == ' ' || *iBgn == '\n' || | ||
| 194 | *iBgn == '\r' || *iBgn == '\t' ) ) | ||
| 195 | { | ||
| 196 | iBgn++; | ||
| 197 | } | ||
| 198 | else | ||
| 199 | { | ||
| 200 | // Here is where you would indent paragraphs | ||
| 201 | iEnd = iBgn; | ||
| 202 | iState = 1; | ||
| 203 | } | ||
| 204 | break; | ||
| 205 | |||
| 206 | case 1: // non-whitespace | ||
| 207 | if( !iEnd ) | ||
| 208 | { | ||
| 209 | sNextToken.append( iBgn, iEnd ); | ||
| 210 | iBgn = iEnd; | ||
| 211 | iNextLen += iTmpLen; | ||
| 212 | iTmpLen = 0; | ||
| 213 | } | ||
| 214 | else if( *iEnd == ' ' || *iEnd == '\n' || | ||
| 215 | *iEnd == '\r' || *iEnd == '\t' ) | ||
| 216 | { | ||
| 217 | sNextToken.append( iBgn, iEnd ); | ||
| 218 | iNextLen += iTmpLen; | ||
| 219 | iTmpLen = 0; | ||
| 220 | iState = 2; | ||
| 221 | iBgn = iEnd; | ||
| 222 | } | ||
| 223 | else | ||
| 224 | { | ||
| 225 | iEnd++; | ||
| 226 | iTmpLen++; | ||
| 227 | } | ||
| 228 | break; | ||
| 229 | |||
| 230 | case 2: // Whitespace | ||
| 231 | if( iBgn && (*iBgn == ' ' || *iBgn == '\n' || | ||
| 232 | *iBgn == '\r' || *iBgn == '\t') ) | ||
| 233 | { | ||
| 234 | iBgn++; | ||
| 235 | } | ||
| 236 | else | ||
| 237 | { | ||
| 238 | iEnd = iBgn; | ||
| 239 | iState = 1; | ||
| 240 | appendToken( sCurLine, sNextToken, | ||
| 241 | iLineLen, iNextLen ); | ||
| 242 | } | ||
| 243 | break; | ||
| 244 | } | ||
| 245 | } | ||
| 246 | } | ||
| 247 | break; | ||
| 248 | |||
| 249 | case SmlNode::typeTag: | ||
| 250 | if( pNode->getChildren().isEmpty() ) | ||
| 251 | { | ||
| 252 | if( pNode->getText() == "break" ) | ||
| 253 | { | ||
| 254 | appendToken( sCurLine, sNextToken, iLineLen, iNextLen ); | ||
| 255 | if( !sCurLine.isEmpty() ) | ||
| 256 | sio << sCurLine << sio.nl; | ||
| 257 | sCurLine.clear(); | ||
| 258 | iLineLen = 0; | ||
| 259 | iState = 0; | ||
| 260 | } | ||
| 261 | } | ||
| 262 | else | ||
| 263 | { | ||
| 264 | // sio << "Push'd: " << pNode->getText() << sio.nl; | ||
| 265 | Bu::String sTag = pNode->getText(); | ||
| 266 | if( sTag == "green" ) | ||
| 267 | { | ||
| 268 | sNextToken += "\x1B[1;32m"; | ||
| 269 | } | ||
| 270 | else if( sTag == "red" ) | ||
| 271 | { | ||
| 272 | sNextToken += "\x1B[1;31m"; | ||
| 273 | } | ||
| 274 | sNode.push( pNode->getChildren().begin() ); | ||
| 275 | continue; | ||
| 276 | /* for( SmlNode::SmlNodeList::const_iterator i = | ||
| 277 | pNode->getChildren().begin(); i; i++ ) | ||
| 278 | { | ||
| 279 | s | ||
| 280 | smlToConsole( *i, sCurLine, sNextToken, iLineLen, iState ); | ||
| 281 | } | ||
| 282 | */ | ||
| 283 | } | ||
| 284 | break; | ||
| 285 | } | ||
| 286 | sNode.peek()++; | ||
| 287 | } | ||
| 288 | if( !sNextToken.isEmpty() ) | ||
| 289 | appendToken( sCurLine, sNextToken, iLineLen, iNextLen ); | ||
| 290 | sio << sCurLine << sio.nl; | ||
| 291 | } | ||
| 292 | /* | ||
| 293 | void smlToConsole( const SmlNode *pNode ) | ||
| 294 | { | ||
| 295 | Bu::String sBuf, sBuf2; | ||
| 296 | int i1 = 0, i2 = 0; | ||
| 297 | smlToConsole( pNode, sBuf, sBuf2, i1, i2 ); | ||
| 298 | appendToken( sBuf, sBuf2, i1 ); | ||
| 299 | sio << sBuf << sBuf2 << sio.nl; | ||
| 300 | }*/ | ||
| 301 | |||
| 302 | int Options::smlTest( Bu::Array<Bu::String> aArgs ) | 88 | int Options::smlTest( Bu::Array<Bu::String> aArgs ) |
| 303 | { | 89 | { |
| 304 | Bu::String sContent; | 90 | Bu::String sContent; |
| @@ -313,7 +99,17 @@ int Options::smlTest( Bu::Array<Bu::String> aArgs ) | |||
| 313 | SmlNode *pRoot = SmlNode::parse( sContent ); | 99 | SmlNode *pRoot = SmlNode::parse( sContent ); |
| 314 | sio << *pRoot << sio.nl; | 100 | sio << *pRoot << sio.nl; |
| 315 | 101 | ||
| 316 | smlToConsole( pRoot ); | 102 | try |
| 103 | { | ||
| 104 | InterfacePlugger &ip = InterfacePlugger::getInstance(); | ||
| 105 | Interface *pIface = ip.instantiate( sInterface ); | ||
| 106 | pIface->display( pRoot ); | ||
| 107 | ip.destroy( pIface ); | ||
| 108 | } | ||
| 109 | catch( Bu::HashException &e ) | ||
| 110 | { | ||
| 111 | sio << "No such interface found." << sio.nl; | ||
| 112 | } | ||
| 317 | 113 | ||
| 318 | delete pRoot; | 114 | delete pRoot; |
| 319 | 115 | ||
diff --git a/src/options.h b/src/options.h index b97285b..3012a58 100644 --- a/src/options.h +++ b/src/options.h | |||
| @@ -16,6 +16,7 @@ public: | |||
| 16 | void parse( int argc, char *argv[] ); | 16 | void parse( int argc, char *argv[] ); |
| 17 | 17 | ||
| 18 | Bu::String sFile; | 18 | Bu::String sFile; |
| 19 | Bu::String sInterface; | ||
| 19 | 20 | ||
| 20 | protected: | 21 | protected: |
| 21 | int version( Bu::Array<Bu::String> aArgs ); | 22 | int version( Bu::Array<Bu::String> aArgs ); |
