[Cmap-cvs] mp2mp mpmerge.cpp,1.1,1.2
Status: Beta
Brought to you by:
dyp
From: Denis P. <dy...@us...> - 2005-06-12 06:58:41
|
Update of /cvsroot/cmap/mp2mp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7087 Modified Files: mpmerge.cpp Log Message: Handle file not found correctly Index: mpmerge.cpp =================================================================== RCS file: /cvsroot/cmap/mp2mp/mpmerge.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- mpmerge.cpp 24 Apr 2005 19:59:43 -0000 1.1 +++ mpmerge.cpp 12 Jun 2005 06:58:32 -0000 1.2 @@ -13,14 +13,35 @@ void process(FILE *fo, const char *filename, bool copyHeader); }; +class FileNotFoundException : public std::exception { +public: + FileNotFoundException(const char *_filename) : filename(_filename){ + } + + virtual ~FileNotFoundException() throw () { + } + + static void raise(const char *_filename) { + throw FileNotFoundException(_filename); + } + + virtual const char *name() const throw() { + return "FileNotFoundException"; + } + + virtual const char *what() const throw() { + return ("File not found: " + filename).c_str(); + } +public: + std::string filename; +}; + void Converter::process(FILE *fo, const char *filename, bool copyHeader) { fprintf(stderr, "Processing: %s\n", filename); FILE *f = fopen(filename, "rt"); - if (f == NULL) { - fprintf(stderr, "File not found: %s\n", filename); - exit(1); - } + if (f == NULL) + throw FileNotFoundException(filename); Tokenizer t(f); @@ -40,7 +61,7 @@ p.map.printHeader(fo); for (std::list<Rgn>::iterator it = p.map.rgns.begin(); it != p.map.rgns.end(); it++) { Rgn &rgn = *it; - rgn.print(fo); + rgn.print(fo, true); } fclose(f); @@ -81,12 +102,14 @@ return 1; } - try { - for (int i = firstArg; i < argc; i++) + for (int i = firstArg; i < argc; i++) + try { c.process(f, argv[i], i == firstArg); - } catch (ParserException &x) { - fprintf(stderr, "%d: %s\n", x.lineno(), x.what()); - } + } catch (ParserException &x) { + fprintf(stderr, "%d: %s\n", x.lineno(), x.what()); + } catch (FileNotFoundException &x) { + fprintf(stderr, "File not found: %s\n", x.filename.c_str()); + } fclose(f); return 0; |