load.c
changeset 5 c87681fff7d3
parent 2 57a1fcb0c75c
child 6 bc41369f4587
equal deleted inserted replaced
4:b2dfe3374454 5:c87681fff7d3
    12 struct Def defs[MAX];
    12 struct Def defs[MAX];
    13 int ndefs;
    13 int ndefs;
    14 int dont_touch[20];
    14 int dont_touch[20];
    15 int ndont_touch;
    15 int ndont_touch;
    16 
    16 
    17 void load_init()
    17 void init_load()
    18 {
    18 {
    19     ndefs = 0;
    19     ndefs = 0;
    20     nwords = 0;
    20     nwords = 0;
    21     ndont_touch = 0;
    21     ndont_touch = 0;
    22 }
    22 }
    67 
    67 
    68 void load_dictionary(FILE *index, FILE *fdefs)
    68 void load_dictionary(FILE *index, FILE *fdefs)
    69 {
    69 {
    70     struct Word w;
    70     struct Word w;
    71     int last_offset = 0;
    71     int last_offset = 0;
       
    72     int def_avoided = 0;
    72 
    73 
    73     do {
    74     do {
    74         int offset, length;
    75         int offset, length;
    75         char *defstr;
    76         char *defstr;
    76         w.w = get_word(index);
    77         w.w = get_word(index);
    77         if (w.w == 0)
    78         if (w.w == 0)
    78             break;
    79             break;
       
    80         /*printf("Word: %s\n", w.w);*/
    79         offset = get_int(index);
    81         offset = get_int(index);
    80         length = get_int(index);
    82         length = get_int(index);
    81         if (offset > last_offset)
    83         if (offset > last_offset)
    82         {
    84         {
    83             w.def = -1;
    85             w.def = -1;
    84             last_offset = offset;
    86             last_offset = offset;
    85         }
    87         }
    86         else
    88         else
    87             w.def = search_def(offset, length);
    89             w.def = search_def(offset, length);
    88         if (w.def == -1)
    90         if (w.def == -1) 
    89         {
    91         {
       
    92             /* New definition */
       
    93             int newindex, repindex;
    90             defstr = get_def(fdefs, offset, length);
    94             defstr = get_def(fdefs, offset, length);
    91             w.def = new_def(defstr, offset, length);
    95             newindex = new_def(defstr, offset, length);
       
    96             
       
    97             /* Store it in the hash for repeated defs */
       
    98             repindex = def_repeated(&defs[newindex]);
       
    99             if (repindex != -1) 
       
   100             {
       
   101                 def_avoided += 1;
       
   102                 printf("Repeated def avoided %i (word %s)\n", def_avoided, w.w);
       
   103                 remove_def(newindex);
       
   104                 newindex = repindex;
       
   105             } else
       
   106                 new_hashdef(&defs[newindex], newindex);
       
   107 
       
   108             /* Store the final index */
       
   109             w.def = newindex;
    92         }
   110         }
    93         /* sizeof -1  instead of strlen() */
   111         /* sizeof -1  instead of strlen() */
    94         if (strncmp(w.w, "00database", sizeof("00database") - 1) == 0)
   112         if (strncmp(w.w, "00database", sizeof("00database") - 1) == 0)
    95                 new_dont_touch(w.def);
   113                 new_dont_touch(w.def);
    96         new_word(&w);
   114         new_word(&w);