summaryrefslogtreecommitdiff
path: root/other/Kermit/lib/SymbolFingp.cpp
blob: 4b29bef825edbd90904bab0287fd3c4133b29cfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * SymbolFingp.cpp:
 * written by palmers / teso
 */
#include <SymbolFingp.hpp>
#include <stoi16.hpp>


bool SymbolFingp::addFinger (struct sfp *a)
{
  Fingers.insert (FingerThing::value_type (string (a->name), *a));
  return true; /* ah, well - think positiv ... */
}


void SymbolFingp::readFingers (ifstream a)
{
  int			x = 0;
  struct sfp		*tmp_sfp = NULL;
  string		tmp_string;

  if (!a.is_open ())
    {
      cerr << "failed to open file" << endl;
      abort ();
    }
#ifdef DEBUG
  else
    {
      cout << "Reading fingerprints ..." << endl;
    }
#endif

  a.setf (ios::skipws);
  while (!a.eof ())
    {
      tmp_sfp = new struct sfp;

/* get the name */
      a >> tmp_string;
      tmp_sfp->name = new char[tmp_string.length () + 1];
      copy (tmp_string.begin (), tmp_string.end (), tmp_sfp->name);

/* the addresses */
      a.setf (ios::hex, ios::basefield);
      a >> tmp_sfp->start_addr;
      a >> tmp_sfp->stop_addr;

/* offset from fp to real address */
      a >> tmp_sfp->offset;

/* length of fp */
      a >> tmp_sfp->length;

/* the cells */
      tmp_sfp->fp = new struct cell[tmp_sfp->length];

      for (x = 0; x < tmp_sfp->length; x++)
      {
        a >> tmp_string;

        if ((tmp_string.length () == 1) && (tmp_string[0] == '?'))
	  {
	    tmp_sfp->fp[x].type = WWCARD;
	    tmp_sfp->fp[x].val = 0;
	  }
        else
	  {
	    tmp_sfp->fp[x].type = NOCARD;
            tmp_sfp->fp[x].val = stoi16 (tmp_string);
	  }
      }
      if (addFinger (tmp_sfp) != true)
        {
	  cerr << "Could not add fingerprint" << endl;
          abort ();
        }
    }
      a.setf (ios::dec, ios::basefield);
#ifdef DEBUG
 cout << "done." << endl;
#endif
}


SymbolFingp::SymbolFingp ()
{
  readFingers (ifstream (DEFAULT_FILE));
}


SymbolFingp::SymbolFingp (string a)
{
  readFingers (ifstream (a.c_str ()));
}


SymbolFingp::~SymbolFingp ()
{
  Fingers.clear ();
}


struct sfp *SymbolFingp::getFinger (string a)
{
  return &Fingers[a];
}