Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

HexReader.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Created on Thu Aug 21 22:47:07 PDT 1997 by heydon
00020 // Last modified on Fri Nov  9 14:31:15 EST 2001 by ken@xorian.net
00021 //      modified on Thu Aug 21 23:33:17 PDT 1997 by heydon
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), /*OUT*/ 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     // check for EOF
00043     if (FS::AtEOF(this->ifs)) return 0;
00044 
00045     // read next line of file
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     // convert it to a ShortId
00056     char *val = buff;
00057     if (strncmp(val, "0x", 2) == 0) val += 2;
00058     ShortId res;
00059     if (sscanf(val, "%x", /*OUT*/ &res) != 1) {
00060         throw HexReader::BadValue(this->lineNum, buff);
00061     }
00062 
00063     // success
00064     this->lineNum++;
00065     return res;
00066 }
00067 

Generated on Mon May 8 00:48:42 2006 for Vesta by  doxygen 1.4.2