From: Ulya Trofimovich Date: Thu, 26 Feb 2015 12:32:55 +0000 (+0000) Subject: Now input stream is simple 'FILE *'. X-Git-Tag: 0.15~378 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=44dd876e6b908d64147c839e21b4c9f7ca04650c;p=re2c Now input stream is simple 'FILE *'. This is first part of campaign to remove 'stream_lc.h'. --- diff --git a/re2c/code.cc b/re2c/code.cc index d76dcb9d..2414f7bd 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -2418,10 +2418,11 @@ ScannerState::ScannerState() { } -Scanner::Scanner(std::istream& i, OutputFile & o) - : ScannerState(), in(i), out(o) -{ -} +Scanner::Scanner (FILE * i, OutputFile & o) + : ScannerState () + , in (i) + , out (o) +{} char *Scanner::fill(char *cursor, uint need) { @@ -2470,8 +2471,8 @@ char *Scanner::fill(char *cursor, uint need) bot = buf; } /* Append to buffer. */ - in.read(lim, need); - if ((cnt = in.gcount()) != need) + cnt = fread (lim, 1, need, in); + if (cnt != need) { eof = &lim[cnt]; *eof++ = '\0'; diff --git a/re2c/main.cc b/re2c/main.cc index 8d0e6650..89b0d069 100644 --- a/re2c/main.cc +++ b/re2c/main.cc @@ -428,8 +428,7 @@ int main(int argc, char *argv[]) } // set up the source stream - re2c::ifstream_lc source; - + FILE * source = NULL; if (sourceFileName[0] == '-' && sourceFileName[1] == '\0') { if (fFlag) @@ -438,9 +437,13 @@ int main(int argc, char *argv[]) return 1; } sourceFileName = ""; - source.open(stdin); + source = stdin; + } + else + { + source = fopen (sourceFileName, "rb"); } - else if (!source.open(sourceFileName).is_open()) + if (source == NULL) { cerr << "re2c: error: cannot open " << sourceFileName << "\n"; return 1; @@ -470,5 +473,6 @@ int main(int argc, char *argv[]) // output generated code output.emit (); + fclose (source); return 0; } diff --git a/re2c/scanner.h b/re2c/scanner.h index 5c1674bb..1327e5f8 100644 --- a/re2c/scanner.h +++ b/re2c/scanner.h @@ -2,7 +2,6 @@ #ifndef _scanner_h #define _scanner_h -#include #include #include "globals.h" @@ -27,7 +26,7 @@ class Scanner: public line_number, private ScannerState { private: - std::istream& in; + FILE * in; OutputFile & out; private: @@ -37,7 +36,7 @@ private: void set_sourceline(char *& cursor); public: - Scanner(std::istream&, OutputFile &); + Scanner(FILE *, OutputFile &); ~Scanner(); enum ParseMode {