00001
00002
00003 #include <stdio.h>
00004 #include <string.h>
00005
00006
00007 class pstatus
00008 {
00009 public:
00010 long p;
00011 char n[30];
00012 char a;
00013 class pstatus *next;
00014
00015 pstatus (long np, char *nn, char na = (char) 1)
00016 {
00017 p = np;
00018 strcpy(n,nn);
00019 a = na;
00020 next = NULL;
00021 }
00022 ~pstatus () {if (next != NULL) delete next;}
00023 };
00024
00025 class phash
00026 {
00027 public:
00028 pstatus **table;
00029 int size;
00030
00031 phash (int sz)
00032 {
00033 size = sz;
00034 if (size != 0)
00035 {
00036 table = new (pstatus *) [size];
00037 for (int i = 0; i < size; i++)
00038 table[i] = NULL;
00039 }
00040 else
00041 table = NULL;
00042 }
00043 ~phash()
00044 {
00045 for (int i = 0; i < size; i++)
00046 delete table[i];
00047 delete[] table;
00048 }
00049
00050 int hashfunc (long p) {return (((p ^ (p << 3)) % size));}
00051
00052 int Allocate (long p, char *n)
00053 {
00054 int index;
00055 pstatus *check, *cprev;
00056
00057 index = hashfunc (p);
00058 if (table[index] != NULL)
00059 {
00060 for (cprev = check = table[index];
00061 check != NULL;
00062 cprev = check, check = check->next)
00063 {
00064 if (check->p == p)
00065 {
00066 if (check->a == (char) 1)
00067 printf ("Duplicate allocation for %x.\n", p);
00068 else
00069 check->a = (char) 1;
00070 strcpy (check->n, n);
00071
00072 break;
00073 }
00074 }
00075 if (check == NULL)
00076 {
00077 check = new pstatus (p, n);
00078 cprev->next = check;
00079
00080 }
00081 }
00082 else
00083 {
00084 table[index] = new pstatus (p, n);
00085
00086 }
00087
00088 return 1;
00089 }
00090
00091 int Free (long p, char *n)
00092 {
00093 int index;
00094 pstatus *check, *cprev;
00095
00096 index = hashfunc (p);
00097 if (table[index] != NULL)
00098 {
00099 for (cprev = check = table[index];
00100 check != NULL;
00101 cprev = check, check = check->next)
00102 {
00103 if (check->p == p)
00104 {
00105 if (check->a == (char) 1 && strcmp (check->n, n) != 0)
00106 {
00107 printf ("Object confusion for %x.\n", p);
00108 strcpy (check->n, n);
00109 }
00110 if (check->a == (char) 0)
00111 printf ("Duplicate deallocation for %x.\n", p);
00112 else
00113 check->a = (char) 0;
00114
00115 break;
00116 }
00117 }
00118 if (check == NULL)
00119 {
00120 printf ("Deletion of never-allocated %x.\n", p);
00121
00122 }
00123 }
00124 else
00125 {
00126 printf ("Deletion of never-allocated %x.\n", p);
00127
00128 }
00129
00130 return 1;
00131 }
00132
00133 };
00134
00135 int main()
00136 {
00137 FILE *sflog;
00138 char line[60], obj[30];
00139 phash *h;
00140 long p;
00141
00142 h = new phash (256);
00143 sflog = fopen ("sf.log", "rt");
00144 if (sflog == NULL)
00145 {
00146 printf ("sf.log not found\n");
00147 return 1;
00148 }
00149 while (fgets (line, 50, sflog) != NULL)
00150 {
00151 if (strncmp (line, "Creating", 8) != 0 &&
00152 strncmp (line, "Deleting", 8) != 0 &&
00153 strncmp (line, "Assigning", 9) != 0)
00154 continue;
00155 sscanf (line, "%*s %s %lx", obj, &p);
00156 if (strcmp (obj, "LEGOPSET") == 0 ||
00157 strcmp (obj, "LEGOREGION") == 0 ||
00158 strcmp (obj, "LEGOPARR") == 0)
00159 continue;
00160
00161 if (line[0] == 'C' || line[0] == 'A')
00162 h->Allocate (p, obj);
00163 else
00164 h->Free (p, obj);
00165 }
00166 fclose (sflog);
00167 delete h;
00168 return 0;
00169 }