00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <Basics.H>
00025 #include <FS.H>
00026 #include <Generics.H>
00027 #include <SourceOrDerived.H>
00028
00029 #include "HexReader.H"
00030
00031 using std::ios;
00032 using std::ostream;
00033 using std::cout;
00034 using std::cerr;
00035 using std::endl;
00036
00037 static void Syntax(char *msg, char *arg = NULL) throw ()
00038 {
00039 cerr << "Error: " << msg;
00040 if (arg != NULL) cerr << ": '" << arg << "'";
00041 cerr << endl;
00042 cerr << "Syntax: ShortIdSetDiff file1 file2" << endl;
00043 exit(1);
00044 }
00045
00046 static char *FileName(char *name) throw ()
00047 {
00048 char *res = name;
00049 if (strncmp(name, "0x", 2) == 0) {
00050
00051 char *arg = name + 2;
00052
00053
00054 ShortId sid;
00055 if (sscanf(arg, "%x", &sid) != 1) {
00056 Syntax("bad 'shortId' argument", name);
00057 }
00058
00059
00060 res = SourceOrDerived::shortIdToName(sid, false);
00061 }
00062 return res;
00063 }
00064
00065 static void ReadFile2(char *path, IntIntTbl &elts)
00066 throw (FS::DoesNotExist, FS::Failure, HexReader::BadValue)
00067 {
00068 ShortId sid, totalCnt = 0, uniqCnt = 0;
00069 HexReader hexrd(path);
00070 while ((sid = hexrd.Next()) != 0) {
00071 int dummy;
00072 totalCnt++;
00073 if (!elts.Get(sid, dummy)) {
00074 uniqCnt++;
00075 bool inTbl = elts.Put(sid, 0); assert(!inTbl);
00076 }
00077 }
00078 cerr << " Total lines = " << totalCnt;
00079 cerr << "; unique lines = " << uniqCnt << endl;
00080 }
00081
00082 static void ProcessFile1(char *path, ostream &os, const IntIntTbl &elts)
00083 throw (FS::DoesNotExist, FS::Failure, HexReader::BadValue)
00084 {
00085
00086 os.setf(ios::hex,ios::basefield);
00087
00088
00089 HexReader hexrd(path);
00090 ShortId sid, totalCnt = 0, uniqCnt = 0, writtenCnt = 0;
00091 IntIntTbl myElts( 5000);
00092 while ((sid = hexrd.Next()) != 0) {
00093 totalCnt++;
00094 int dummy;
00095 if (!myElts.Get(sid, dummy)) {
00096 uniqCnt++;
00097 bool inTbl = myElts.Put(sid, 0); assert(!inTbl);
00098 if (!elts.Get(sid, dummy)) {
00099 writtenCnt++;
00100 os.width(8); os << sid << endl;
00101 }
00102 }
00103 }
00104 cerr << " Total lines = " << totalCnt;
00105 cerr << "; unique lines = " << uniqCnt;
00106 cerr << "; written lines = " << writtenCnt << endl;
00107 }
00108
00109 int main(int argc, char *argv[])
00110 {
00111 if (argc != 3) Syntax("incorrect number of arguments");
00112 try {
00113 char *file2 = FileName(argv[2]);
00114 cerr << "Reading " << file2 << "..." << endl;
00115 IntIntTbl elts( 5000);
00116 ReadFile2(file2, elts);
00117
00118 char *file1 = FileName(argv[1]);
00119 cerr << "Reading " << file1 << "..." << endl;
00120 ProcessFile1(file1, cout, elts);
00121 } catch (const FS::DoesNotExist) {
00122 cerr << "Fatal error: file does not exist" << endl;
00123 } catch (const FS::Failure &f) {
00124 cerr << "Fatal error: " << f << endl;
00125 } catch (const HexReader::BadValue &v) {
00126 cerr << "Fatal error: bad value '" << v.str
00127 << "', line " << v.lineNum << endl;
00128 }
00129 return 0;
00130 }