From: nuffer Date: Thu, 13 May 2004 02:58:18 +0000 (+0000) Subject: Modified code to use portable c++ streams instead of POSIX open/read/close. Changed... X-Git-Tag: 0.13.6~706 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=997000a554c7cb7a75db9ba5316b83d92ad31cec;p=re2c Modified code to use portable c++ streams instead of POSIX open/read/close. Changed iostream.h to iostream. Added std:: qualifications where necessary. --- diff --git a/actions.cc b/actions.cc index f344b5b8..1ea4be78 100644 --- a/actions.cc +++ b/actions.cc @@ -1,8 +1,8 @@ /* $Id$ */ #include #include -#include -#include +#include +#include #include "globals.h" #include "parser.h" @@ -20,7 +20,7 @@ Symbol *Symbol::find(const SubStr &str){ return new Symbol(str); } -void showIns(ostream &o, const Ins &i, const Ins &base){ +void showIns(std::ostream &o, const Ins &i, const Ins &base){ o.width(3); o << &i - &base << ": "; switch(i.i.tag){ @@ -67,7 +67,7 @@ void NullOp::split(CharSet&){ ; } -ostream& operator<<(ostream &o, const Range &r){ +std::ostream& operator<<(std::ostream &o, const Range &r){ if((r.ub - r.lb) == 1){ prtCh(o, r.lb); } else { @@ -154,7 +154,7 @@ MatchOp *merge(MatchOp *m1, MatchOp *m2){ char *MatchOp::type = "MatchOp"; -void MatchOp::display(ostream &o) const{ +void MatchOp::display(std::ostream &o) const{ o << match; } @@ -487,7 +487,7 @@ void RuleOp::split(CharSet &s){ ctx->split(s); } -extern void printSpan(ostream&, uint, uint); +extern void printSpan(std::ostream&, uint, uint); void optimize(Ins *i){ while(!isMarked(i)){ @@ -516,7 +516,7 @@ void optimize(Ins *i){ } } -void genCode(ostream& o, RegExp *re){ +void genCode(std::ostream& o, RegExp *re){ CharSet cs; uint j; memset(&cs, 0, sizeof(cs)); diff --git a/bootstrap/scanner.cc b/bootstrap/scanner.cc index 783f4671..f9756f6f 100644 --- a/bootstrap/scanner.cc +++ b/bootstrap/scanner.cc @@ -3,8 +3,7 @@ /* $Id$ */ #include #include -#include -#include +#include #include "scanner.h" #include "parser.h" #include "y.tab.h" @@ -26,7 +25,7 @@ extern YYSTYPE yylval; #define RETURN(i) {cur = cursor; return i;} -Scanner::Scanner(int i) : in(i), +Scanner::Scanner(std::istream& i) : in(i), bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL), top(NULL), eof(NULL), tchar(0), tline(0), cline(1) { ; @@ -55,7 +54,7 @@ char *Scanner::fill(char *cursor){ delete [] bot; bot = buf; } - if((cnt = read(in, (char*) lim, BSIZE)) != BSIZE){ + if((cnt = in.rdbuf()->sgetn((char*) lim, BSIZE)) != BSIZE){ eof = &lim[cnt]; *eof++ = '\n'; } lim += cnt; @@ -66,7 +65,7 @@ char *Scanner::fill(char *cursor){ #line 73 "scanner.re" -int Scanner::echo(ostream &out){ +int Scanner::echo(std::ostream &out){ char *cursor = cur; // Catch EOF @@ -288,7 +287,7 @@ yy37: ++YYCURSOR; goto yy38; yy38: #line 160 "scanner.re" -{ cerr << "unexpected character: " << *tok << endl; +{ std::cerr << "unexpected character: " << *tok << std::endl; goto scan; } #line 208 "re2c-output.c" @@ -634,7 +633,7 @@ yy104: } void Scanner::fatal(char *msg){ - cerr << "line " << tline << ", column " << (tchar + 1) << ": " - << msg << endl; + std::cerr << "line " << tline << ", column " << (tchar + 1) << ": " + << msg << std::endl; exit(1); } diff --git a/code.cc b/code.cc index 5b139c27..ad607afc 100644 --- a/code.cc +++ b/code.cc @@ -2,7 +2,8 @@ #include #include #include -#include +#include +#include #include "substr.h" #include "globals.h" #include "dfa.h" @@ -73,7 +74,7 @@ void doGen(Go *g, State *s, uchar *bm, uchar m) } } -void prt(ostream& o, Go *g, State *s) +void prt(std::ostream& o, Go *g, State *s) { Span *b = g->span, *e = &b[g->nSpans]; uint lb = 0; @@ -129,7 +130,7 @@ public: public: static BitMap *find(Go*, State*); static BitMap *find(State*); - static void gen(ostream&, uint, uint); + static void gen(std::ostream&, uint, uint); static void stats(); BitMap(Go*, State*); }; @@ -165,7 +166,7 @@ BitMap *BitMap::find(State *x) return NULL; } -void BitMap::gen(ostream &o, uint lb, uint ub) +void BitMap::gen(std::ostream &o, uint lb, uint ub) { BitMap *b = first; if(b) @@ -187,7 +188,7 @@ void BitMap::gen(ostream &o, uint lb, uint ub) { o << "\n\t"; ++oline; } - o << setw(3) << (uint) bm[j] << ", "; + o << std::setw(3) << (uint) bm[j] << ", "; } } o << "\n\t};\n"; @@ -200,14 +201,14 @@ void BitMap::stats() uint n = 0; for(BitMap *b = first; b; b = b->next) { - prt(cerr, b->go, b->on); cerr << endl; + prt(std::cerr, b->go, b->on); std::cerr << std::endl; ++n; } - cerr << n << " bitmaps\n"; + std::cerr << n << " bitmaps\n"; first = NULL; } -void genGoTo(ostream &o, State *from, State *to, bool & readCh) +void genGoTo(std::ostream &o, State *from, State *to, bool & readCh) { if (readCh && from->label + 1 != to->label) { @@ -218,7 +219,7 @@ void genGoTo(ostream &o, State *from, State *to, bool & readCh) ++oline; } -void genIf(ostream &o, char *cmp, uint v, bool &readCh) +void genIf(std::ostream &o, char *cmp, uint v, bool &readCh) { if (readCh) { @@ -234,7 +235,7 @@ void genIf(ostream &o, char *cmp, uint v, bool &readCh) o << "')"; } -void indent(ostream &o, uint i) +void indent(std::ostream &o, uint i) { while(i-- > 0) { @@ -242,7 +243,7 @@ void indent(ostream &o, uint i) } } -static void need(ostream &o, uint n, bool & readCh) +static void need(std::ostream &o, uint n, bool & readCh) { if(n == 1) { @@ -259,7 +260,7 @@ static void need(ostream &o, uint n, bool & readCh) ++oline; } -void Match::emit(ostream &o, bool &readCh) +void Match::emit(std::ostream &o, bool &readCh) { if (state->link) { @@ -284,7 +285,7 @@ void Match::emit(ostream &o, bool &readCh) } } -void Enter::emit(ostream &o, bool &readCh) +void Enter::emit(std::ostream &o, bool &readCh) { if(state->link){ o << "\t++YYCURSOR;\n"; @@ -300,7 +301,7 @@ void Enter::emit(ostream &o, bool &readCh) } } -void Save::emit(ostream &o, bool &readCh) +void Save::emit(std::ostream &o, bool &readCh) { o << "\tyyaccept = " << selector << ";\n"; ++oline; @@ -319,7 +320,7 @@ Move::Move(State *s) : Action(s) { ; } -void Move::emit(ostream &o, bool &readCh){ +void Move::emit(std::ostream &o, bool &readCh){ ; } @@ -328,7 +329,7 @@ Accept::Accept(State *x, uint n, uint *s, State **r) ; } -void Accept::emit(ostream &o, bool &readCh) +void Accept::emit(std::ostream &o, bool &readCh) { bool first = true; for(uint i = 0; i < nRules; ++i) @@ -355,7 +356,7 @@ Rule::Rule(State *s, RuleOp *r) : Action(s), rule(r) { ; } -void Rule::emit(ostream &o, bool &readCh) +void Rule::emit(std::ostream &o, bool &readCh) { uint back = rule->ctx->fixedLength(); if(back != ~0u && back > 0u) { @@ -374,7 +375,7 @@ void Rule::emit(ostream &o, bool &readCh) // << "\n\t" << rule->code->text << "\n"; } -void doLinear(ostream &o, uint i, Span *s, uint n, State *from, State *next, bool &readCh) +void doLinear(std::ostream &o, uint i, Span *s, uint n, State *from, State *next, bool &readCh) { for(;;) { @@ -415,12 +416,12 @@ void doLinear(ostream &o, uint i, Span *s, uint n, State *from, State *next, boo indent(o, i); genGoTo(o, from, next, readCh); } -void Go::genLinear(ostream &o, State *from, State *next, bool &readCh) +void Go::genLinear(std::ostream &o, State *from, State *next, bool &readCh) { doLinear(o, 0, span, nSpans, from, next, readCh); } -void genCases(ostream &o, uint lb, Span *s) +void genCases(std::ostream &o, uint lb, Span *s) { if(lb < s->ub) { @@ -437,7 +438,7 @@ void genCases(ostream &o, uint lb, Span *s) } } -void Go::genSwitch(ostream &o, State *from, State *next, bool &readCh) +void Go::genSwitch(std::ostream &o, State *from, State *next, bool &readCh) { if(nSpans <= 2){ genLinear(o, from, next, readCh); @@ -497,7 +498,7 @@ void Go::genSwitch(ostream &o, State *from, State *next, bool &readCh) } } -void doBinary(ostream &o, uint i, Span *s, uint n, State *from, State *next, bool &readCh) +void doBinary(std::ostream &o, uint i, Span *s, uint n, State *from, State *next, bool &readCh) { if(n <= 4) { @@ -517,12 +518,12 @@ void doBinary(ostream &o, uint i, Span *s, uint n, State *from, State *next, boo } } -void Go::genBinary(ostream &o, State *from, State *next, bool &readCh) +void Go::genBinary(std::ostream &o, State *from, State *next, bool &readCh) { doBinary(o, 0, span, nSpans, from, next, readCh); } -void Go::genBase(ostream &o, State *from, State *next, bool &readCh) +void Go::genBase(std::ostream &o, State *from, State *next, bool &readCh) { if(nSpans == 0) { @@ -568,7 +569,7 @@ void Go::genBase(ostream &o, State *from, State *next, bool &readCh) } } -void Go::genGoto(ostream &o, State *from, State *next, bool &readCh) +void Go::genGoto(std::ostream &o, State *from, State *next, bool &readCh) { if(bFlag) { @@ -604,7 +605,7 @@ void Go::genGoto(ostream &o, State *from, State *next, bool &readCh) genBase(o, from, next, readCh); } -void State::emit(ostream &o, bool &readCh){ +void State::emit(std::ostream &o, bool &readCh){ o << "yy" << label << ":"; /* o << "\nfprintf(stderr, \"<" << label << ">\");\n";*/ action->emit(o, readCh); @@ -797,7 +798,7 @@ void DFA::split(State *s) s->go.span[0].to = move; } -void DFA::emit(ostream &o) +void DFA::emit(std::ostream &o) { static uint label = 0; State *s; diff --git a/dfa.cc b/dfa.cc index fbdf0ffb..b3e1e618 100644 --- a/dfa.cc +++ b/dfa.cc @@ -9,7 +9,7 @@ inline char octCh(uint c){ return '0' + c%8; } -void prtCh(ostream &o, uchar c){ +void prtCh(std::ostream &o, uchar c){ uchar oc = talx[c]; switch(oc){ case '\'': o << "\\'"; break; @@ -29,7 +29,7 @@ void prtCh(ostream &o, uchar c){ } } -void printSpan(ostream &o, uint lb, uint ub){ +void printSpan(std::ostream &o, uint lb, uint ub){ if(lb > ub) o << "*"; o << "["; @@ -43,7 +43,7 @@ void printSpan(ostream &o, uint lb, uint ub){ o << "]"; } -uint Span::show(ostream &o, uint lb){ +uint Span::show(std::ostream &o, uint lb){ if(to){ printSpan(o, lb, ub); o << " " << to->label << "; "; @@ -51,7 +51,7 @@ uint Span::show(ostream &o, uint lb){ return ub; } -ostream& operator<<(ostream &o, const State &s){ +std::ostream& operator<<(std::ostream &o, const State &s){ o << "state " << s.label; if(s.rule) o << " accepts " << s.rule->accept; @@ -63,7 +63,7 @@ ostream& operator<<(ostream &o, const State &s){ return o; } -ostream& operator<<(ostream &o, const DFA &dfa){ +std::ostream& operator<<(std::ostream &o, const DFA &dfa){ for(State *s = dfa.head; s; s = s->next) { o << s << "\n\n"; diff --git a/dfa.h b/dfa.h index 9761e4e4..c7ddfabf 100644 --- a/dfa.h +++ b/dfa.h @@ -2,11 +2,11 @@ #ifndef _dfa_h #define _dfa_h -#include +#include #include "re.h" -extern void prtCh(ostream&, uchar); -extern void printSpan(ostream&, uint, uint); +extern void prtCh(std::ostream&, uchar); +extern void printSpan(std::ostream&, uint, uint); class DFA; class State; @@ -16,7 +16,7 @@ public: State *state; public: Action(State*); - virtual void emit(ostream&, bool&) = 0; + virtual void emit(std::ostream&, bool&) = 0; virtual bool isRule() const; virtual bool isMatch() const; virtual bool readAhead() const; @@ -25,7 +25,7 @@ public: class Match: public Action { public: Match(State*); - void emit(ostream&, bool&); + void emit(std::ostream&, bool&); bool isMatch() const; }; @@ -34,7 +34,7 @@ public: uint label; public: Enter(State*, uint); - void emit(ostream&, bool&); + void emit(std::ostream&, bool&); }; class Save: public Match { @@ -42,14 +42,14 @@ public: uint selector; public: Save(State*, uint); - void emit(ostream&, bool&); + void emit(std::ostream&, bool&); bool isMatch() const; }; class Move: public Action { public: Move(State*); - void emit(ostream&, bool&); + void emit(std::ostream&, bool&); }; class Accept: public Action { @@ -59,7 +59,7 @@ public: State **rules; public: Accept(State*, uint, uint*, State**); - void emit(ostream&, bool&); + void emit(std::ostream&, bool&); }; class Rule: public Action { @@ -67,7 +67,7 @@ public: RuleOp *rule; public: Rule(State*, RuleOp*); - void emit(ostream&, bool&); + void emit(std::ostream&, bool&); bool isRule() const; }; @@ -76,7 +76,7 @@ public: uint ub; State *to; public: - uint show(ostream&, uint); + uint show(std::ostream&, uint); }; class Go { @@ -84,11 +84,11 @@ public: uint nSpans; Span *span; public: - void genGoto(ostream&, State *from, State*, bool &readCh); - void genBase(ostream&, State *from, State*, bool &readCh); - void genLinear(ostream&, State *from, State*, bool &readCh); - void genBinary(ostream&, State *from, State*, bool &readCh); - void genSwitch(ostream&, State *from, State*, bool &readCh); + void genGoto(std::ostream&, State *from, State*, bool &readCh); + void genBase(std::ostream&, State *from, State*, bool &readCh); + void genLinear(std::ostream&, State *from, State*, bool &readCh); + void genBinary(std::ostream&, State *from, State*, bool &readCh); + void genSwitch(std::ostream&, State *from, State*, bool &readCh); void compact(); void unmap(Go*, State*); }; @@ -108,9 +108,9 @@ public: public: State(); ~State(); - void emit(ostream&, bool&); - friend ostream& operator<<(ostream&, const State&); - friend ostream& operator<<(ostream&, const State*); + void emit(std::ostream&, bool&); + friend std::ostream& operator<<(std::ostream&, const State&); + friend std::ostream& operator<<(std::ostream&, const State*); }; class DFA { @@ -128,10 +128,10 @@ public: void split(State*); void findSCCs(); - void emit(ostream&); + void emit(std::ostream&); - friend ostream& operator<<(ostream&, const DFA&); - friend ostream& operator<<(ostream&, const DFA*); + friend std::ostream& operator<<(std::ostream&, const DFA&); + friend std::ostream& operator<<(std::ostream&, const DFA*); }; inline Action::Action(State *s) : state(s) { @@ -165,10 +165,10 @@ inline bool Save::isMatch() const inline bool Rule::isRule() const { return true; } -inline ostream& operator<<(ostream &o, const State *s) +inline std::ostream& operator<<(std::ostream &o, const State *s) { return o << *s; } -inline ostream& operator<<(ostream &o, const DFA *dfa) +inline std::ostream& operator<<(std::ostream &o, const DFA *dfa) { return o << *dfa; } #endif diff --git a/ins.h b/ins.h index 146bef67..0781ab2f 100644 --- a/ins.h +++ b/ins.h @@ -2,7 +2,6 @@ #ifndef _ins_h #define _ins_h -#include #include "basics.h" const uint nChars = 256; diff --git a/main.cc b/main.cc index e9f7f0fa..e7dd8c38 100644 --- a/main.cc +++ b/main.cc @@ -4,9 +4,8 @@ #endif #include +#include #include -#include -#include #include #include "globals.h" @@ -33,36 +32,57 @@ static const mbo_opt_struct OPTIONS[] = { {'v', 0, "version"} }; +static void usage() +{ + cerr << "usage: re2c [-esbvh] file\n" + "\n" + "-? -h --help Display this info.\n" + "\n" + "-b --bit-vectors Implies -s. Use bit vectors as well in the attempt to\n" + " coax better code out of the compiler. Most useful for\n" + " specifications with more than a few keywords (e.g. for\n" + " most programming languages).\n" + "\n" + "-e --ecb Cross-compile from an ASCII platform to\n" + " an EBCDIC one.\n" + "\n" + "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n" + " need this assist to generate better code.\n" + "\n" + "-v --version Show version information.\n"; +} + int main(int argc, char *argv[]) { int c; - fileName = NULL; + fileName = NULL; - if (argc == 1) { - goto usage; + if (argc == 1) { + usage(); + return 2; } while ((c = mbo_getopt(argc, argv, OPTIONS, &opt_arg, &opt_ind, 0))!=-1) { switch (c) { - case '?': - goto usage; - case 'b': - sFlag = true; - bFlag = true; - break; - case 'e': - xlat = asc2ebc; - talx = ebc2asc; - break; - case 'h': - goto usage; - case 's': - sFlag = true; - break; - case 'v': - goto version; - default: - goto usage; + case 'b': + sFlag = true; + bFlag = true; + break; + case 'e': + xlat = asc2ebc; + talx = ebc2asc; + break; + case 's': + sFlag = true; + break; + case 'v': + cerr << "re2c " << PACKAGE_VERSION << "\n"; + return 2; + case 'h': + case '?': + default: + usage(); + return 2; } } @@ -72,46 +92,28 @@ int main(int argc, char *argv[]) } else { - goto usage; + usage(); + return 2; } - int fd; - if (fileName[0] == '-' && fileName[1] == '\0') - { + istream* input = 0; + ifstream inputFile; + if (fileName[0] == '-' && fileName[1] == '\0') + { fileName = ""; - fd = 0; - } - else - { - if ((fd = open(fileName, O_RDONLY)) < 0) + input = &cin; + } + else + { + inputFile.open(fileName); + if (!inputFile) { - cerr << "can't open " << fileName << "\n"; - return 1; + cerr << "can't open " << fileName << "\n"; + return 1; } - } - parse(fd, cout); - return 0; - -usage: - cerr << "usage: re2c [-esbvh] file\n" - "\n" - "-? -h --help Display this info.\n" - "\n" - "-b --bit-vectors Implies -s. Use bit vectors as well in the attempt to\n" - " coax better code out of the compiler. Most useful for\n" - " specifications with more than a few keywords (e.g. for\n" - " most programming languages).\n" - "\n" - "-e --ecb Cross-compile from an ASCII platform to\n" - " an EBCDIC one.\n" - "\n" - "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n" - " need this assist to generate better code.\n" - "\n" - "-v --version Show version information.\n"; - return 2; + input = &inputFile; + } + parse(*input, cout); + return 0; -version: - cerr << "re2c " << PACKAGE_VERSION << "\n"; - return 2; } diff --git a/parser.h b/parser.h index 34eae0e8..f7b3fe60 100644 --- a/parser.h +++ b/parser.h @@ -4,6 +4,7 @@ #include "scanner.h" #include "re.h" +#include class Symbol { public: @@ -16,7 +17,7 @@ public: static Symbol *find(const SubStr&); }; -void line_source(unsigned int, ostream&); -void parse(int, ostream&); +void line_source(unsigned int, std::ostream&); +void parse(std::istream&, std::ostream&); #endif diff --git a/parser.y b/parser.y index e33fa902..9ecf0039 100644 --- a/parser.y +++ b/parser.y @@ -172,7 +172,7 @@ int yylex(){ } } // end extern "C" -void line_source(unsigned int line, ostream& o) +void line_source(unsigned int line, std::ostream& o) { char * fnamebuf; char * token; @@ -195,7 +195,7 @@ void line_source(unsigned int line, ostream& o) free( fnamebuf ); } -void parse(int i, ostream &o){ +void parse(std::istream& i, std::ostream &o){ o << "/* Generated by re2c " PACKAGE_VERSION " on "; time_t now = time(&now); diff --git a/re.h b/re.h index 6e6124c2..2319bb75 100644 --- a/re.h +++ b/re.h @@ -2,7 +2,7 @@ #ifndef _re_h #define _re_h -#include +#include #include "token.h" #include "ins.h" @@ -34,11 +34,11 @@ public: { } Range(Range &r) : next(NULL), lb(r.lb), ub(r.ub) { } - friend ostream& operator<<(ostream&, const Range&); - friend ostream& operator<<(ostream&, const Range*); + friend std::ostream& operator<<(std::ostream&, const Range&); + friend std::ostream& operator<<(std::ostream&, const Range*); }; -inline ostream& operator<<(ostream &o, const Range *r){ +inline std::ostream& operator<<(std::ostream &o, const Range *r){ return r? o << *r : o; } @@ -53,17 +53,17 @@ public: virtual void calcSize(Char*) = 0; virtual uint fixedLength(); virtual void compile(Char*, Ins*) = 0; - virtual void display(ostream&) const = 0; - friend ostream& operator<<(ostream&, const RegExp&); - friend ostream& operator<<(ostream&, const RegExp*); + virtual void display(std::ostream&) const = 0; + friend std::ostream& operator<<(std::ostream&, const RegExp&); + friend std::ostream& operator<<(std::ostream&, const RegExp*); }; -inline ostream& operator<<(ostream &o, const RegExp &re){ +inline std::ostream& operator<<(std::ostream &o, const RegExp &re){ re.display(o); return o; } -inline ostream& operator<<(ostream &o, const RegExp *re){ +inline std::ostream& operator<<(std::ostream &o, const RegExp *re){ return o << *re; } @@ -77,7 +77,7 @@ public: void calcSize(Char*); uint fixedLength(); void compile(Char*, Ins*); - void display(ostream &o) const { + void display(std::ostream &o) const { o << "_"; } }; @@ -95,7 +95,7 @@ public: void calcSize(Char*); uint fixedLength(); void compile(Char*, Ins*); - void display(ostream&) const; + void display(std::ostream&) const; }; class RuleOp: public RegExp { @@ -115,7 +115,7 @@ public: void split(CharSet&); void calcSize(Char*); void compile(Char*, Ins*); - void display(ostream &o) const { + void display(std::ostream &o) const { o << exp << "/" << ctx << ";"; } }; @@ -134,7 +134,7 @@ public: void calcSize(Char*); uint fixedLength(); void compile(Char*, Ins*); - void display(ostream &o) const { + void display(std::ostream &o) const { o << exp1 << "|" << exp2; } friend RegExp *mkAlt(RegExp*, RegExp*); @@ -154,7 +154,7 @@ public: void calcSize(Char*); uint fixedLength(); void compile(Char*, Ins*); - void display(ostream &o) const { + void display(std::ostream &o) const { o << exp1 << exp2; } }; @@ -172,7 +172,7 @@ public: void split(CharSet&); void calcSize(Char*); void compile(Char*, Ins*); - void display(ostream &o) const { + void display(std::ostream &o) const { o << exp << "+"; } }; @@ -192,12 +192,12 @@ public: void split(CharSet&); void calcSize(Char*); void compile(Char*, Ins*); - void display(ostream &o) const { + void display(std::ostream &o) const { o << exp << "+"; } }; -extern void genCode(ostream&, RegExp*); +extern void genCode(std::ostream&, RegExp*); extern RegExp *mkDiff(RegExp*, RegExp*); extern RegExp *strToRE(SubStr); extern RegExp *ranToRE(SubStr); diff --git a/scanner.h b/scanner.h index fa1b7ee1..3a43a656 100644 --- a/scanner.h +++ b/scanner.h @@ -2,18 +2,21 @@ #ifndef _scanner_h #define _scanner_h +#include #include "token.h" class Scanner { private: - int in; + std::istream& in; char *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof; uint tchar, tline, cline; private: char *fill(char*); + Scanner(const Scanner&); //unimplemented + Scanner& operator=(const Scanner&); //unimplemented public: - Scanner(int); - int echo(ostream&); + Scanner(std::istream&); + int echo(std::ostream&); int scan(); void fatal(char*); SubStr token(); diff --git a/scanner.re b/scanner.re index c2fecd48..88a9bb8a 100644 --- a/scanner.re +++ b/scanner.re @@ -1,8 +1,7 @@ /* $Id$ */ #include #include -#include -#include +#include #include "scanner.h" #include "parser.h" #include "y.tab.h" @@ -24,7 +23,7 @@ extern YYSTYPE yylval; #define RETURN(i) {cur = cursor; return i;} -Scanner::Scanner(int i) : in(i), +Scanner::Scanner(std::istream& i) : in(i), bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL), top(NULL), eof(NULL), tchar(0), tline(0), cline(1) { ; @@ -53,7 +52,7 @@ char *Scanner::fill(char *cursor){ delete [] bot; bot = buf; } - if((cnt = read(in, (char*) lim, BSIZE)) != BSIZE){ + if((cnt = in.rdbuf()->sgetn((char*) lim, BSIZE)) != BSIZE){ eof = &lim[cnt]; *eof++ = '\n'; } lim += cnt; @@ -72,7 +71,7 @@ letter = [a-zA-Z]; digit = [0-9]; */ -int Scanner::echo(ostream &out){ +int Scanner::echo(std::ostream &out){ char *cursor = cur; // Catch EOF @@ -157,7 +156,7 @@ scan: goto scan; } - any { cerr << "unexpected character: " << *tok << endl; + any { std::cerr << "unexpected character: " << *tok << std::endl; goto scan; } */ @@ -196,7 +195,7 @@ comment: } void Scanner::fatal(char *msg){ - cerr << "line " << tline << ", column " << (tchar + 1) << ": " - << msg << endl; + std::cerr << "line " << tline << ", column " << (tchar + 1) << ": " + << msg << std::endl; exit(1); } diff --git a/substr.cc b/substr.cc index 44d529b8..20adfcd0 100644 --- a/substr.cc +++ b/substr.cc @@ -3,7 +3,7 @@ #include "substr.h" #include "globals.h" -void SubStr::out(ostream& o) const { +void SubStr::out(std::ostream& o) const { o.write(str, len); for (size_t i = 0; i < (size_t)len; ++i) { diff --git a/substr.h b/substr.h index bb441ea0..cd0afb89 100644 --- a/substr.h +++ b/substr.h @@ -2,7 +2,7 @@ #ifndef _substr_h #define _substr_h -#include +#include #include "basics.h" class SubStr { @@ -14,7 +14,7 @@ public: SubStr(uchar*, uint); SubStr(char*, uint); SubStr(const SubStr&); - void out(ostream&) const; + void out(std::ostream&) const; }; class Str: public SubStr { @@ -25,12 +25,12 @@ public: ~Str(); }; -inline ostream& operator<<(ostream& o, const SubStr &s){ +inline std::ostream& operator<<(std::ostream& o, const SubStr &s){ s.out(o); return o; } -inline ostream& operator<<(ostream& o, const SubStr* s){ +inline std::ostream& operator<<(std::ostream& o, const SubStr* s){ return o << *s; }