diff options
Diffstat (limited to 'other/Kermit/lib/SymbolFingp.cpp')
| -rw-r--r-- | other/Kermit/lib/SymbolFingp.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/other/Kermit/lib/SymbolFingp.cpp b/other/Kermit/lib/SymbolFingp.cpp new file mode 100644 index 0000000..4b29bef --- /dev/null +++ b/other/Kermit/lib/SymbolFingp.cpp | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | /* | ||
| 2 | * SymbolFingp.cpp: | ||
| 3 | * written by palmers / teso | ||
| 4 | */ | ||
| 5 | #include <SymbolFingp.hpp> | ||
| 6 | #include <stoi16.hpp> | ||
| 7 | |||
| 8 | |||
| 9 | bool SymbolFingp::addFinger (struct sfp *a) | ||
| 10 | { | ||
| 11 | Fingers.insert (FingerThing::value_type (string (a->name), *a)); | ||
| 12 | return true; /* ah, well - think positiv ... */ | ||
| 13 | } | ||
| 14 | |||
| 15 | |||
| 16 | void SymbolFingp::readFingers (ifstream a) | ||
| 17 | { | ||
| 18 | int x = 0; | ||
| 19 | struct sfp *tmp_sfp = NULL; | ||
| 20 | string tmp_string; | ||
| 21 | |||
| 22 | if (!a.is_open ()) | ||
| 23 | { | ||
| 24 | cerr << "failed to open file" << endl; | ||
| 25 | abort (); | ||
| 26 | } | ||
| 27 | #ifdef DEBUG | ||
| 28 | else | ||
| 29 | { | ||
| 30 | cout << "Reading fingerprints ..." << endl; | ||
| 31 | } | ||
| 32 | #endif | ||
| 33 | |||
| 34 | a.setf (ios::skipws); | ||
| 35 | while (!a.eof ()) | ||
| 36 | { | ||
| 37 | tmp_sfp = new struct sfp; | ||
| 38 | |||
| 39 | /* get the name */ | ||
| 40 | a >> tmp_string; | ||
| 41 | tmp_sfp->name = new char[tmp_string.length () + 1]; | ||
| 42 | copy (tmp_string.begin (), tmp_string.end (), tmp_sfp->name); | ||
| 43 | |||
| 44 | /* the addresses */ | ||
| 45 | a.setf (ios::hex, ios::basefield); | ||
| 46 | a >> tmp_sfp->start_addr; | ||
| 47 | a >> tmp_sfp->stop_addr; | ||
| 48 | |||
| 49 | /* offset from fp to real address */ | ||
| 50 | a >> tmp_sfp->offset; | ||
| 51 | |||
| 52 | /* length of fp */ | ||
| 53 | a >> tmp_sfp->length; | ||
| 54 | |||
| 55 | /* the cells */ | ||
| 56 | tmp_sfp->fp = new struct cell[tmp_sfp->length]; | ||
| 57 | |||
| 58 | for (x = 0; x < tmp_sfp->length; x++) | ||
| 59 | { | ||
| 60 | a >> tmp_string; | ||
| 61 | |||
| 62 | if ((tmp_string.length () == 1) && (tmp_string[0] == '?')) | ||
| 63 | { | ||
| 64 | tmp_sfp->fp[x].type = WWCARD; | ||
| 65 | tmp_sfp->fp[x].val = 0; | ||
| 66 | } | ||
| 67 | else | ||
| 68 | { | ||
| 69 | tmp_sfp->fp[x].type = NOCARD; | ||
| 70 | tmp_sfp->fp[x].val = stoi16 (tmp_string); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | if (addFinger (tmp_sfp) != true) | ||
| 74 | { | ||
| 75 | cerr << "Could not add fingerprint" << endl; | ||
| 76 | abort (); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | a.setf (ios::dec, ios::basefield); | ||
| 80 | #ifdef DEBUG | ||
| 81 | cout << "done." << endl; | ||
| 82 | #endif | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | SymbolFingp::SymbolFingp () | ||
| 87 | { | ||
| 88 | readFingers (ifstream (DEFAULT_FILE)); | ||
| 89 | } | ||
| 90 | |||
| 91 | |||
| 92 | SymbolFingp::SymbolFingp (string a) | ||
| 93 | { | ||
| 94 | readFingers (ifstream (a.c_str ())); | ||
| 95 | } | ||
| 96 | |||
| 97 | |||
| 98 | SymbolFingp::~SymbolFingp () | ||
| 99 | { | ||
| 100 | Fingers.clear (); | ||
| 101 | } | ||
| 102 | |||
| 103 | |||
| 104 | struct sfp *SymbolFingp::getFinger (string a) | ||
| 105 | { | ||
| 106 | return &Fingers[a]; | ||
| 107 | } | ||
| 108 | |||
