From: nuffer Date: Thu, 13 May 2004 03:47:52 +0000 (+0000) Subject: Added -o option to specify the output file which also will set the #line directives... X-Git-Tag: 0.13.6~702 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1b660ed881279a0784d510a4ac13230dde061f09;p=re2c Added -o option to specify the output file which also will set the #line directives to something useful. --- diff --git a/Makefile.am b/Makefile.am index 35721a09..712e7ff9 100755 --- a/Makefile.am +++ b/Makefile.am @@ -35,8 +35,8 @@ parser.cc: parser.y scanner.cc: scanner.re @if test -x ./re2c; then \ - echo "re2c $(RE2CFLAGS) $< >$@.tmp"; \ - ./re2c $(RE2CFLAGS) $< >$@.tmp && mv $@.tmp $@ && cp $@ bootstrap/; \ + echo "re2c $(RE2CFLAGS) -o $@ $<"; \ + ./re2c $(RE2CFLAGS) -o $@ $< && cp $@ bootstrap/; \ else \ echo "cp -f bootstrap/$@ $@"; \ cp -f bootstrap/$@ $@; \ diff --git a/bootstrap/scanner.cc b/bootstrap/scanner.cc index f9756f6f..b197c059 100644 --- a/bootstrap/scanner.cc +++ b/bootstrap/scanner.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.9.2 on Wed Apr 21 10:37:57 2004 */ +/* Generated by re2c 0.9.2 on Wed May 12 21:46:34 2004 */ #line 1 "scanner.re" /* $Id$ */ #include @@ -62,7 +62,7 @@ char *Scanner::fill(char *cursor){ return cursor; } -#line 73 "scanner.re" +#line 72 "scanner.re" int Scanner::echo(std::ostream &out){ @@ -75,7 +75,7 @@ int Scanner::echo(std::ostream &out){ tok = cursor; echo: -#line 7 "re2c-output.c" +#line 7 "scanner.cc" { YYCTYPE yych; unsigned int yyaccept; @@ -92,18 +92,18 @@ yy2: yyaccept = 0; if(yych == '*') goto yy7; goto yy3; yy3: -#line 92 "scanner.re" +#line 91 "scanner.re" { goto echo; } -#line 26 "re2c-output.c" +#line 26 "scanner.cc" yy4: ++YYCURSOR; goto yy5; yy5: -#line 88 "scanner.re" +#line 87 "scanner.re" { if(cursor == eof) RETURN(0); out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); tok = pos = cursor; cline++; goto echo; } -#line 35 "re2c-output.c" +#line 35 "scanner.cc" yy6: yych = *++YYCURSOR; goto yy3; yy7: yych = *++YYCURSOR; @@ -128,13 +128,13 @@ yy12: yych = *++YYCURSOR; yy13: ++YYCURSOR; goto yy14; yy14: -#line 85 "scanner.re" +#line 84 "scanner.re" { out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok)); tok = cursor; RETURN(1); } -#line 64 "re2c-output.c" +#line 64 "scanner.cc" } -#line 93 "scanner.re" +#line 92 "scanner.re" } @@ -148,7 +148,7 @@ scan: tline = cline; tok = cursor; -#line 68 "re2c-output.c" +#line 68 "scanner.cc" { YYCTYPE yych; unsigned int yyaccept; @@ -210,50 +210,50 @@ yy17: yyaccept = 0; if(yych <= '9') goto yy63; goto yy18; yy18: -#line 106 "scanner.re" +#line 105 "scanner.re" { depth = 1; goto code; } -#line 134 "re2c-output.c" +#line 134 "scanner.cc" yy19: ++YYCURSOR; if((yych = *YYCURSOR) == '*') goto yy61; goto yy20; yy20: -#line 132 "scanner.re" +#line 131 "scanner.re" { RETURN(*tok); } -#line 141 "re2c-output.c" +#line 141 "scanner.cc" yy21: ++YYCURSOR; if((yych = *YYCURSOR) == '/') goto yy59; goto yy22; yy22: -#line 134 "scanner.re" +#line 133 "scanner.re" { yylval.op = *tok; RETURN(CLOSE); } -#line 149 "re2c-output.c" +#line 149 "scanner.cc" yy23: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); if(yych != '\n') goto yy55; goto yy24; yy24: -#line 123 "scanner.re" +#line 122 "scanner.re" { fatal("unterminated string constant (missing \")"); } -#line 157 "re2c-output.c" +#line 157 "scanner.cc" yy25: yyaccept = 2; yych = *(YYMARKER = ++YYCURSOR); if(yych != '\n') goto yy50; goto yy26; yy26: -#line 124 "scanner.re" +#line 123 "scanner.re" { fatal("unterminated string constant (missing ')"); } -#line 165 "re2c-output.c" +#line 165 "scanner.cc" yy27: yyaccept = 3; yych = *(YYMARKER = ++YYCURSOR); if(yych != '\n') goto yy44; goto yy28; yy28: -#line 130 "scanner.re" +#line 129 "scanner.re" { fatal("unterminated range (missing ])"); } -#line 173 "re2c-output.c" +#line 173 "scanner.cc" yy29: yych = *++YYCURSOR; goto yy20; yy30: yych = *++YYCURSOR; @@ -262,35 +262,35 @@ yy31: ++YYCURSOR; yych = *YYCURSOR; goto yy42; yy32: -#line 149 "scanner.re" +#line 148 "scanner.re" { cur = cursor; yylval.symbol = Symbol::find(token()); return ID; } -#line 185 "re2c-output.c" +#line 185 "scanner.cc" yy33: ++YYCURSOR; yych = *YYCURSOR; goto yy40; yy34: -#line 153 "scanner.re" +#line 152 "scanner.re" { goto scan; } -#line 191 "re2c-output.c" +#line 191 "scanner.cc" yy35: ++YYCURSOR; goto yy36; yy36: -#line 155 "scanner.re" +#line 154 "scanner.re" { if(cursor == eof) RETURN(0); pos = cursor; cline++; goto scan; } -#line 200 "re2c-output.c" +#line 200 "scanner.cc" yy37: ++YYCURSOR; goto yy38; yy38: -#line 160 "scanner.re" +#line 159 "scanner.re" { std::cerr << "unexpected character: " << *tok << std::endl; goto scan; } -#line 208 "re2c-output.c" +#line 208 "scanner.cc" yy39: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; @@ -339,11 +339,11 @@ yy46: ++YYCURSOR; yy47: ++YYCURSOR; goto yy48; yy48: -#line 126 "scanner.re" +#line 125 "scanner.re" { cur = cursor; yylval.regexp = ranToRE(token()); return RANGE; } -#line 265 "re2c-output.c" +#line 265 "scanner.cc" yy49: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; @@ -364,11 +364,11 @@ yy51: ++YYCURSOR; yy52: ++YYCURSOR; goto yy53; yy53: -#line 119 "scanner.re" +#line 118 "scanner.re" { cur = cursor; yylval.regexp = strToCaseInsensitiveRE(token()); return STRING; } -#line 292 "re2c-output.c" +#line 292 "scanner.cc" yy54: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; @@ -389,25 +389,25 @@ yy56: ++YYCURSOR; yy57: ++YYCURSOR; goto yy58; yy58: -#line 115 "scanner.re" +#line 114 "scanner.re" { cur = cursor; yylval.regexp = strToRE(token()); return STRING; } -#line 319 "re2c-output.c" +#line 319 "scanner.cc" yy59: ++YYCURSOR; goto yy60; yy60: -#line 112 "scanner.re" +#line 111 "scanner.re" { tok = cursor; RETURN(0); } -#line 326 "re2c-output.c" +#line 326 "scanner.cc" yy61: ++YYCURSOR; goto yy62; yy62: -#line 109 "scanner.re" +#line 108 "scanner.re" { depth = 1; goto comment; } -#line 333 "re2c-output.c" +#line 333 "scanner.cc" yy63: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; @@ -423,22 +423,22 @@ yy64: if(yych <= '/'){ yy65: ++YYCURSOR; goto yy66; yy66: -#line 137 "scanner.re" +#line 136 "scanner.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = atoi((char *)tok+1); RETURN(CLOSESIZE); } -#line 354 "re2c-output.c" +#line 354 "scanner.cc" yy67: yych = *++YYCURSOR; if(yych != '}') goto yy71; goto yy68; yy68: ++YYCURSOR; goto yy69; yy69: -#line 145 "scanner.re" +#line 144 "scanner.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = -1; RETURN(CLOSESIZE); } -#line 365 "re2c-output.c" +#line 365 "scanner.cc" yy70: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; @@ -450,18 +450,18 @@ yy71: if(yych <= '/') goto yy45; yy72: ++YYCURSOR; goto yy73; yy73: -#line 141 "scanner.re" +#line 140 "scanner.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = MAX(yylval.extop.minsize,atoi(strchr((char *)tok, ',')+1)); RETURN(CLOSESIZE); } -#line 382 "re2c-output.c" +#line 382 "scanner.cc" } -#line 163 "scanner.re" +#line 162 "scanner.re" code: -#line 386 "re2c-output.c" +#line 386 "scanner.cc" { YYCTYPE yych; unsigned int yyaccept; @@ -491,36 +491,36 @@ yy74: yy76: ++YYCURSOR; goto yy77; yy77: -#line 167 "scanner.re" +#line 166 "scanner.re" { if(--depth == 0){ cur = cursor; yylval.token = new Token(token(), tline); return CODE; } goto code; } -#line 423 "re2c-output.c" +#line 423 "scanner.cc" yy78: ++YYCURSOR; goto yy79; yy79: -#line 173 "scanner.re" +#line 172 "scanner.re" { ++depth; goto code; } -#line 430 "re2c-output.c" +#line 430 "scanner.cc" yy80: ++YYCURSOR; goto yy81; yy81: -#line 175 "scanner.re" +#line 174 "scanner.re" { if(cursor == eof) fatal("missing '}'"); pos = cursor; cline++; goto code; } -#line 439 "re2c-output.c" +#line 439 "scanner.cc" yy82: ++YYCURSOR; goto yy83; yy83: -#line 179 "scanner.re" +#line 178 "scanner.re" { goto code; } -#line 445 "re2c-output.c" +#line 445 "scanner.cc" yy84: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if(yych == '\n') goto yy83; @@ -568,12 +568,12 @@ yy92: ++YYCURSOR; if(yych == '\n') goto yy88; goto yy90; } -#line 180 "scanner.re" +#line 179 "scanner.re" comment: -#line 499 "re2c-output.c" +#line 499 "scanner.cc" { YYCTYPE yych; unsigned int yyaccept; @@ -594,46 +594,46 @@ yy95: ++YYCURSOR; if((yych = *YYCURSOR) == '/') goto yy103; goto yy96; yy96: -#line 194 "scanner.re" +#line 193 "scanner.re" { goto comment; } -#line 522 "re2c-output.c" +#line 522 "scanner.cc" yy97: yych = *++YYCURSOR; if(yych == '*') goto yy101; goto yy96; yy98: ++YYCURSOR; goto yy99; yy99: -#line 190 "scanner.re" +#line 189 "scanner.re" { if(cursor == eof) RETURN(0); tok = pos = cursor; cline++; goto comment; } -#line 534 "re2c-output.c" +#line 534 "scanner.cc" yy100: yych = *++YYCURSOR; goto yy96; yy101: ++YYCURSOR; goto yy102; yy102: -#line 188 "scanner.re" +#line 187 "scanner.re" { ++depth; goto comment; } -#line 543 "re2c-output.c" +#line 543 "scanner.cc" yy103: ++YYCURSOR; goto yy104; yy104: -#line 184 "scanner.re" +#line 183 "scanner.re" { if(--depth == 0) goto scan; else goto comment; } -#line 552 "re2c-output.c" +#line 552 "scanner.cc" } -#line 195 "scanner.re" +#line 194 "scanner.re" } void Scanner::fatal(char *msg){ - std::cerr << "line " << tline << ", column " << (tchar + 1) << ": " + std::cerr << "line " << tline << ", column " << (tchar + 1) << ": " << msg << std::endl; exit(1); } diff --git a/code.cc b/code.cc index ad607afc..a6d08458 100644 --- a/code.cc +++ b/code.cc @@ -369,8 +369,7 @@ void Rule::emit(std::ostream &o, bool &readCh) // not sure if we need this or not. oline += std::count(rule->code->text, rule->code->text + ::strlen(rule->code->text), '\n'); o << "\n"; ++oline; - o << "#line " << ++oline << " \"re2c-output.c\"\n"; - // TODO: use this once we get an output filename: o << "#line " << ++oline << " \"" << outputFileName << "\"\n"; + o << "#line " << ++oline << " \"" << outputFileName << "\"\n"; // o << "\n#line " << rule->code->line // << "\n\t" << rule->code->text << "\n"; } @@ -930,8 +929,7 @@ void DFA::emit(std::ostream &o) delete head->action; ++oline; - o << "\n#line " << ++oline << " \"re2c-output.c\"\n"; - // TODO: Switch to use this once we have an outputFileName: o << "\n#line " << ++oline << " \"" << outputFileName << "\"\n"; + o << "\n#line " << ++oline << " \"" << outputFileName << "\"\n"; o << "{\n\tYYCTYPE yych;\n\tunsigned int yyaccept;\n"; oline += 3; diff --git a/globals.h b/globals.h index a3c2ebe3..ee1703ea 100644 --- a/globals.h +++ b/globals.h @@ -5,6 +5,7 @@ #include "basics.h" extern char *fileName; +extern char *outputFileName; extern bool sFlag; extern bool bFlag; extern unsigned int oline; diff --git a/main.cc b/main.cc index e7dd8c38..39fa3247 100644 --- a/main.cc +++ b/main.cc @@ -13,7 +13,8 @@ #include "dfa.h" #include "mbo_getopt.h" -char *fileName; +char *fileName = 0; +char *outputFileName = 0; bool sFlag = false; bool bFlag = false; unsigned int oline = 1; @@ -29,6 +30,7 @@ static const mbo_opt_struct OPTIONS[] = { {'e', 0, "ecb"}, {'h', 0, "help"}, {'s', 0, "nested-ifs"}, + {'o', 1, "output"}, {'v', 0, "version"} }; @@ -49,6 +51,8 @@ static void usage() "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n" " need this assist to generate better code.\n" "\n" + "-o --output=output Specify the output file instead of stdout\n" + "\n" "-v --version Show version information.\n"; } @@ -75,6 +79,9 @@ int main(int argc, char *argv[]) case 's': sFlag = true; break; + case 'o': + outputFileName = opt_arg; + break; case 'v': cerr << "re2c " << PACKAGE_VERSION << "\n"; return 2; @@ -96,6 +103,7 @@ int main(int argc, char *argv[]) return 2; } + // set up the input stream istream* input = 0; ifstream inputFile; if (fileName[0] == '-' && fileName[1] == '\0') @@ -113,7 +121,27 @@ int main(int argc, char *argv[]) } input = &inputFile; } - parse(*input, cout); + + // set up the output stream + ostream* output = 0; + ofstream outputFile; + if (outputFileName == 0 || (fileName[0] == '-' && fileName[1] == '\0')) + { + outputFileName = ""; + output = &cout; + } + else + { + outputFile.open(outputFileName); + if (!outputFile) + { + cerr << "can't open " << outputFileName << "\n"; + return 1; + } + output = &outputFile; + } + + parse(*input, *output); return 0; }