From 3af6cc33ff246d31513b9a645403a9ece58983a0 Mon Sep 17 00:00:00 2001
From: Mike Buland ";
+ for( SmlNode::SmlNodeList::const_iterator i =
+ pNode->getChildren().begin(); i; i++ )
+ {
+ smlToHtml( *i );
+ }
+ sio << "
";
+ }
+ else
+ {
+ if( pNode->getText() == "red" )
+ {
+ sio << "";
+ for( SmlNode::SmlNodeList::const_iterator i =
+ pNode->getChildren().begin(); i; i++ )
+ {
+ smlToHtml( *i );
+ }
+ sio << "";
+ }
+ else if( pNode->getText() == "green" )
+ {
+ sio << "";
+ for( SmlNode::SmlNodeList::const_iterator i =
+ pNode->getChildren().begin(); i; i++ )
+ {
+ smlToHtml( *i );
+ }
+ sio << "";
+ }
+ }
+ break;
+ }
+}
+
+void appendToken( Bu::String &sCurLine, Bu::String &sNextToken, int &iLineLen )
+{
+ if( iLineLen + sNextToken.getSize() + 1 >= 78 )
+ {
+ sio << sCurLine << sio.nl;
+ iLineLen = 0;
+ sCurLine = sNextToken;
+
+ }
+ else
+ {
+ sCurLine += sNextToken;
+ }
+ iLineLen += sNextToken.getSize() + 1;
+ sCurLine += " ";
+ sNextToken.clear();
+}
+
+void smlToConsole( const SmlNode *pNode, Bu::String &sCurLine,
+ Bu::String &sNextToken, int &iLineLen, int &iState )
+{
+// sio << "Begin: iState = " << iState << sio.nl;
+ switch( pNode->getType() )
+ {
+ case SmlNode::typeRoot:
+ for( SmlNode::SmlNodeList::const_iterator i =
+ pNode->getChildren().begin(); i; i++ )
+ {
+ smlToConsole( *i, sCurLine, sNextToken, iLineLen, iState );
+ }
+ break;
+
+ case SmlNode::typeText:
+ {
+ Bu::String::const_iterator iBgn = pNode->getText().begin();
+ Bu::String::const_iterator iEnd = iBgn;
+ for(;iBgn;)
+ {
+// sio << iState << ": [" << (iBgn?*iBgn:'-') << ":"
+// << (iEnd?*iEnd:'-') << "]"
+// << sio.nl;
+ int iTmpLen = 0;
+ 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;
+ }
+ else if( *iEnd == ' ' || *iEnd == '\n' ||
+ *iEnd == '\r' || *iEnd == '\t' )
+ {
+ sNextToken.append( iBgn, iEnd );
+ 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 );
+ }
+ break;
+ }
+ }
+ }
+ break;
+
+ case SmlNode::typeTag:
+ if( pNode->getChildren().isEmpty() )
+ {
+ if( pNode->getText() == "break" )
+ {
+ appendToken( sCurLine, sNextToken, iLineLen );
+ if( !sCurLine.isEmpty() )
+ sio << sCurLine << sio.nl;
+ sCurLine.clear();
+ iLineLen = 0;
+ iState = 0;
+ }
+ }
+ else
+ {
+ for( SmlNode::SmlNodeList::const_iterator i =
+ pNode->getChildren().begin(); i; i++ )
+ {
+ smlToConsole( *i, sCurLine, sNextToken, iLineLen, iState );
+ }
+ }
+ break;
+ }
+
+// sio << "Green? \x1b[1mhello\x1b[0m huh" << sio.nl;
+}
+
+void smlToConsole( const SmlNode *pNode )
+{
+ Bu::String sBuf, sBuf2;
+ int i1 = 0, i2 = 0;
+ smlToConsole( pNode, sBuf, sBuf2, i1, i2 );
+ appendToken( sBuf, sBuf2, i1 );
+ sio << sBuf << sBuf2 << sio.nl;
+}
+
int Options::smlTest( Bu::Array