From be41caa5ca6756c7809cabaf6d8bee321928c45a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 21 Feb 2007 09:43:36 +0000 Subject: Added a new key in the lexer that converts any string contained in `` to a command and captures the output. This nicely solves many of my problems for now. Is it a hack? You be the judge... --- src/build.l | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/build.l b/src/build.l index 49275c8..15c4003 100644 --- a/src/build.l +++ b/src/build.l @@ -9,6 +9,7 @@ std::string strbuf; %x strsq %x strdq +%x cmdstr %x comment %option noyywrap nounput batch debug @@ -78,6 +79,10 @@ std::string strbuf; BEGIN( strsq ); strbuf = ""; } +\` { + BEGIN( cmdstr ); + strbuf = ""; +} [^\\\n\"]+ { strbuf += yytext; @@ -87,15 +92,20 @@ std::string strbuf; strbuf += yytext; } -\\n strbuf += "\n"; -\\t strbuf += "\t"; -\\r strbuf += "\r"; -\\b strbuf += "\b"; -\\f strbuf += "\f"; -\\\\ strbuf += "\\"; -\\\" strbuf += "\""; -\\\' strbuf += "\'"; -\\. bld.error( yylloc, "Invalid escape sequence."); +[^\\\n\`]+ { + strbuf += yytext; +} + +\\n strbuf += "\n"; +\\t strbuf += "\t"; +\\r strbuf += "\r"; +\\b strbuf += "\b"; +\\f strbuf += "\f"; +\\\\ strbuf += "\\"; +\\\" strbuf += "\""; +\\\' strbuf += "\'"; +\\\` strbuf += "`"; +\\. bld.error( yylloc, "Invalid escape sequence."); \" { BEGIN( INITIAL ); @@ -109,6 +119,28 @@ std::string strbuf; return STRING; } +\` { + BEGIN( INITIAL ); + FILE *fpg = popen( strbuf.c_str(), "r" ); + strbuf = ""; + for(;;) + { + char buf[1024]; + int nRead = fread( buf, 1, 1024, fpg ); + if( nRead == 0 ) break; + for( int j = 0; j < nRead; j++ ) + { + if( buf[j] == '\n' || buf[j] == '\r' ) + buf[j] = ' '; + } + strbuf.append( buf, nRead ); + if( nRead < 1024 ) break; + } + yylval->strval = stringdup( strbuf.c_str() ); + pclose( fpg ); + return STRING; +} + . { char buf[] = {"Character x is out of place"}; buf[10] = yytext[0]; -- cgit v1.2.3