From a78b3af9f8b7b039144938b9833a8efea9db36ea Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 6 Apr 2010 20:03:30 -0400 Subject: [PATCH] gutted parse_input() to fix compilation --- imbecile.cc | 17 +++-- parse-input.cc | 173 +------------------------------------------------ parse-input.h | 3 +- 3 files changed, 10 insertions(+), 183 deletions(-) diff --git a/imbecile.cc b/imbecile.cc index 4dcc24c..3da448c 100644 --- a/imbecile.cc +++ b/imbecile.cc @@ -4,8 +4,6 @@ #include #include #include "refptr/refptr.h" -#include "serialize.h" -#include "unicode.h" #include "parse-input.h" using namespace std; @@ -38,14 +36,15 @@ int main(int argc, char * argv[]) cerr << "Error opening input file: '" << argv[optind] << "'"; return 2; } - refptr< vector > ucs = deserialize(encoding, ifs); - if (ucs.isNull()) - { - cerr << "Error deserializing input file." << endl; - return 1; - } + ifs.seekg(0, ios_base::end); + int size = ifs.tellg(); + ifs.seekg(0, ios_base::beg); + char * buff = new char[size]; + ifs.read(buff, size); - parse_input(ucs); + parse_input(buff, size); + ifs.close(); + delete[] buff; return 0; } diff --git a/parse-input.cc b/parse-input.cc index 30bf38c..ecce14e 100644 --- a/parse-input.cc +++ b/parse-input.cc @@ -1,5 +1,4 @@ -#include #include #include /* isspace() */ #include "parse-input.h" @@ -11,176 +10,6 @@ using namespace std; sprintf(errstr, err " at line %d, column %d", ##args, lineno, colno); \ } while(0) -void parse_input(refptr< vector > ucs) +void parse_input(char * buff, int size) { - enum State { INITIAL, SECTION_NAME, RULES, RULE_NAME, - RULE_EQUALS, RULE_RHS, TOKENS, TOKEN_NAME, TOKEN_EQUALS, TOKEN_RHS }; - State state = INITIAL; - int lineno = 1; - int colno = 1; - bool error = false; - char errstr[200]; - unistring build_str; - struct { unistring name; unistring rhs; } rule; - struct { unistring name; unistring rhs; } token; - - for (int i = 0, sz = ucs->size(); i < sz; i++) - { - unichar_t c = (*ucs)[i]; - switch (state) - { - case INITIAL: - if (c == '[') - { - state = SECTION_NAME; - build_str = ""; - } - else if (isspace(c)) - { - } - else - { - SET_ERROR("Unexpected character 0x%x (%c) in input file", - c, c); - } - break; - case SECTION_NAME: - switch (c) - { - case ']': - if (build_str == "rules") - { - state = RULES; - } - else if (build_str == "tokens") - { - state = TOKENS; - } - else - { - SET_ERROR("Unknown section name"); - } - break; - case '\n': - SET_ERROR("Unterminated section header"); - break; - default: - build_str += c; - break; - } - break; - case RULES: - if (c == '[') - { - state = SECTION_NAME; - build_str = ""; - } - else if (isspace(c)) - { - } - else - { - build_str = ""; - build_str += c; - state = RULE_NAME; - } - break; - case RULE_NAME: - if (c == ':') - { - rule.name = build_str; - build_str = ""; - state = RULE_EQUALS; - } - else - { - build_str += c; - } - break; - case RULE_EQUALS: - if (c == '=') - { - state = RULE_RHS; - } - else - { - SET_ERROR("Expected '='"); - } - break; - case RULE_RHS: - if (c == '\n') - { - rule.rhs = build_str; - state = RULES; - } - else - { - build_str += c; - } - break; - case TOKENS: - if (c == '[') - { - state = SECTION_NAME; - build_str = ""; - } - else - { - build_str = ""; - build_str += c; - state = TOKEN_NAME; - } - break; - case TOKEN_NAME: - if (c == ':') - { - state = TOKEN_EQUALS; - } - else - { - build_str += c; - } - break; - case TOKEN_EQUALS: - if (c == '=') - { - token.name = build_str; - build_str = ""; - state = TOKEN_RHS; - } - else - { - SET_ERROR("Expected '='"); - } - break; - case TOKEN_RHS: - if (c == '\n') - { - token.rhs = build_str; - state = RULES; - } - else - { - build_str += c; - } - break; - } - - /* update line and column position information */ - if (c == '\n') - { - lineno++; - colno = 1; - } - else - { - colno++; - } - - if (error) - { - cerr << errstr << endl; - break; - } - } } diff --git a/parse-input.h b/parse-input.h index 227df57..ede8a9e 100644 --- a/parse-input.h +++ b/parse-input.h @@ -4,8 +4,7 @@ #include #include "refptr/refptr.h" -#include "unicode.h" -void parse_input(refptr< std::vector > ucs); +void parse_input(char * buff, int size); #endif