00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <Basics.H>
00024 #include <FS.H>
00025 #include <SourceOrDerived.H>
00026
00027 #include "HexReader.H"
00028
00029 HexReader::HexReader(char *path) throw (FS::DoesNotExist, FS::Failure)
00030 : lineNum(1)
00031 {
00032 FS::OpenReadOnly(Text(path), this->ifs);
00033 }
00034
00035 HexReader::~HexReader() throw (FS::Failure)
00036 {
00037 FS::Close(this->ifs);
00038 }
00039
00040 ShortId HexReader::Next() throw (FS::Failure, HexReader::BadValue)
00041 {
00042
00043 if (FS::AtEOF(this->ifs)) return 0;
00044
00045
00046 const int BuffSz = 60;
00047 char buff[BuffSz];
00048 ifs.getline(buff, BuffSz);
00049 if (!ifs) {
00050 char lnbuff[10]; sprintf(lnbuff, "%d", this->lineNum);
00051 Text arg("line "); arg += lnbuff;
00052 throw FS::Failure("ifstream.getline", arg);
00053 }
00054
00055
00056 char *val = buff;
00057 if (strncmp(val, "0x", 2) == 0) val += 2;
00058 ShortId res;
00059 if (sscanf(val, "%x", &res) != 1) {
00060 throw HexReader::BadValue(this->lineNum, buff);
00061 }
00062
00063
00064 this->lineNum++;
00065 return res;
00066 }
00067