[Cmap-cvs] cmap topo.conf,NONE,1.1 plan.conf,NONE,1.1 parser.h,NONE,1.1 parser.cpp,NONE,1.1 cmap.dsp
Status: Beta
Brought to you by:
dyp
From: Denis P. <dy...@us...> - 2004-05-15 17:49:43
|
Update of /cvsroot/cmap/cmap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4505 Modified Files: cmap.dsp cmap.cpp Added Files: topo.conf plan.conf parser.h parser.cpp Log Message: Implement a parser with the same functionality as DBF files. At least text files are smaller and easier to merge with CVS. More to follow. --- NEW FILE: parser.cpp --- #include <stdio.h> #include "dbf.h" #include "common.h" #include "tokenizer.h" #include "parser.h" ParserException::ParserException(const char *_msg) : msg(_msg) { } ParserException::~ParserException() throw () { } void ParserException::raise(const char *_msg) { throw ParserException(_msg); } const char *ParserException::name() const throw() { return "ParserException"; } const char *ParserException::what() const throw() { return msg; } static void printToken(const Tokenizer &t) { switch (t.ttype) { case TT_EOF: printf("eof\n"); return; case TT_EOL: printf("eol\n"); break; case TT_NUMBER: printf("num: %d\n", t.nval); break; case TT_WORD: printf("word: %s\n", t.sval.c_str()); break; default: printf("char: %c\n", (unsigned char)t.ttype); break; } } void setValue(const std::string &varName, Tokenizer &t) { if (t.nextToken() != TT_NUMBER) throw ParserException("Expected number"); if (varName == "export") file_cod1[recnum].do_export = t.nval; else if (varName == "index") switch (t.nval) { case 0: file_cod1[recnum].RGN_point = 0x10; break; case 1: file_cod1[recnum].RGN_point = 0x20; break; default: throw ParserException("Invalid index value"); } else if (varName == "point") file_cod1[recnum].TYPE_point = t.nval; else if (varName == "line") file_cod1[recnum].TYPE_line = t.nval; else if (varName == "polygon") file_cod1[recnum].TYPE_poly = t.nval; else if (varName == "layer_min") file_cod1[recnum].img_layer_min = t.nval; else if (varName == "layer_max") file_cod1[recnum].img_layer_max = t.nval; else throw ParserException("Invalid variable name"); } bool readObject(Tokenizer &t) { switch (t.nextToken()) { case TT_EOF: return false; case TT_WORD: break; default: throw ParserException("Expected 'object'"); } if (t.sval != "object") throw ParserException("Expected 'object'"); if (t.nextToken() != TT_WORD) throw ParserException("Expected object code"); strcpy(file_cod1[recnum].object_cod, t.sval.c_str()); if (t.nextToken() != '{') throw ParserException("Expected '{'"); std::string varName; for (;;) { if (t.nextToken() == '}') break; if (t.ttype != TT_WORD) throw ParserException("Expected variable name or '}'"); varName = t.sval; if (t.nextToken() != '=') throw ParserException("Expected '='"); setValue(varName, t); if (t.nextToken() != ';') throw ParserException("Expected ';'"); } recnum++; return true; } void readConfig(const char *filename) { FILE *f = fopen(filename, "rt"); if (f == NULL) { printf("File not found: %s\n", filename); exit(1); } Tokenizer t(f); t.lowerCaseMode(true); t.quoteChar('"'); t.wordChars('a', 'z'); t.wordChars('A', 'Z'); t.wordChar('_'); t.parseNumbers(); t.whitespaceChar(' '); t.whitespaceChar('\n'); t.whitespaceChar('\r'); t.whitespaceChar('\t'); t.slashSlashComments(true); file_cod1 = (topo_cod1 *)s_malloc(sizeof(topo_cod1) * 65536); try { while (readObject(t)) ; } catch (ParserException &x) { printf("%s\n", x.what()); printToken(t); exit(0); } fclose(f); /* for (;;) { switch (t.nextToken()) { case TT_EOF: fclose(f); return; case TT_EOL: printf("eol\n"); break; case TT_NUMBER: printf("num: %d\n", t.nval); break; case TT_WORD: printf("word: %s\n", t.sval.c_str()); break; default: printf("char: %c\n", (unsigned char)t.ttype); break; } } */ } --- NEW FILE: topo.conf --- (This appears to be a binary file; contents omitted.) --- NEW FILE: plan.conf --- (This appears to be a binary file; contents omitted.) --- NEW FILE: parser.h --- #ifndef __CMAP_PARSER_H__ #define __CMAP_PARSER_H__ #include <exception> class ParserException : public exception { public: ParserException(const char *_msg); virtual ~ParserException() throw (); static void raise(const char *_msg); virtual const char *name() const throw(); virtual const char *what() const throw(); private: const char *msg; }; void readConfig(const char *filename); #endif // __CMAP_PARSER_H__ Index: cmap.dsp =================================================================== RCS file: /cvsroot/cmap/cmap/cmap.dsp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- cmap.dsp 4 May 2004 02:01:56 -0000 1.4 +++ cmap.dsp 15 May 2004 17:49:33 -0000 1.5 @@ -113,8 +113,16 @@ # End Source File # Begin Source File +SOURCE=.\parser.cpp +# End Source File +# Begin Source File + SOURCE=.\PolishFormat.cpp # End Source File +# Begin Source File + +SOURCE=.\tokenizer.cpp +# End Source File # End Group # Begin Group "Header Files" @@ -149,8 +157,16 @@ # End Source File # Begin Source File +SOURCE=.\parser.h +# End Source File +# Begin Source File + SOURCE=.\PolishFormat.h # End Source File +# Begin Source File + +SOURCE=.\tokenizer.h +# End Source File # End Group # Begin Group "Resource Files" Index: cmap.cpp =================================================================== RCS file: /cvsroot/cmap/cmap/cmap.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- cmap.cpp 11 May 2004 19:38:19 -0000 1.32 +++ cmap.cpp 15 May 2004 17:49:33 -0000 1.33 @@ -18,6 +18,7 @@ #endif #include "common.h" +#include "parser.h" #include "dbf.h" #include "IngitFile.h" #include "PolishFormat.h" @@ -537,10 +538,10 @@ ReadTableOBJ(); if (Len_code == 8) - Read_DBF("topo.dbf"); + readConfig("topo.conf"); if (Len_code == 2) - Read_DBF("plan.dbf"); + readConfig("plan.conf"); if (Len_code == 6) { printf("Marine maps are not supported"); |