[BACK]Return to generate.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / make

Diff for /src/usr.bin/make/generate.c between version 1.2 and 1.3

version 1.2, 2001/03/02 16:57:26 version 1.3, 2001/05/03 13:41:05
Line 1 
Line 1 
 /* $OpenBSD$ */  
 /* Written by Marc Espie 1999.  
  * Public domain.  
  */  
   
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <stddef.h>  #include <stddef.h>
   
 #include "make.h"  #include "make.h"
   #include "stats.h"
 #include "ohash.h"  #include "ohash.h"
 #include "error.h"  #include "cond_int.h"
   
 #define M(x)    x, #x  #define M(x)    x, #x
 char *table[] = {  char *table_var[] = {
         M(TARGET),          M(TARGET),
         M(OODATE),          M(OODATE),
         M(ALLSRC),          M(ALLSRC),
Line 26 
Line 23 
         M(LONGIMPSRC),          M(LONGIMPSRC),
         M(LONGPREFIX),          M(LONGPREFIX),
         M(LONGARCHIVE),          M(LONGARCHIVE),
         M(LONGMEMBER)          M(LONGMEMBER),
           M(FTARGET),
           M(DTARGET),
           M(FPREFIX),
           M(DPREFIX),
           M(FARCHIVE),
           M(DARCHIVE),
           M(FMEMBER),
           M(DMEMBER),
           NULL
 };  };
   
   char *table_cond[] = {
           M(COND_IF),
           M(COND_IFDEF),
           M(COND_IFNDEF),
           M(COND_IFMAKE),
           M(COND_IFNMAKE),
           M(COND_ELSE),
           M(COND_ELIFDEF),
           M(COND_ELIFNDEF),
           M(COND_ELIFMAKE),
           M(COND_ELIFNMAKE),
           M(COND_ENDIF),
           M(COND_FOR),
           M(COND_INCLUDE),
           M(COND_UNDEF),
           NULL
   };
   
   
   char **table[] = {
           table_var,
           table_cond
   };
   
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
 {  {
Line 39 
Line 68 
         u_int32_t slots;          u_int32_t slots;
         const char *e;          const char *e;
         char **occupied;          char **occupied;
           char **t;
           int tn;
   
 #ifdef HAS_STATS  #ifdef HAS_STATS
         Init_Stats();          Init_Stats();
 #endif  #endif
         if (argc < 2)          if (argc != 3)
                 exit(1);                  exit(1);
   
         slots = atoi(argv[1]);          tn = atoi(argv[1]);
         if (!slots)          if (!tn)
                 exit(1);                  exit(1);
         occupied = emalloc(sizeof(char *) * slots);          t = table[tn-1];
         for (i = 0; i < slots; i++)          slots = atoi(argv[2]);
                 occupied[i] = NULL;          if (slots) {
                   occupied = malloc(sizeof(char *) * slots);
         printf("/* Generated file, do not edit */\n");                  if (!occupied)
         for (i = 0; i < sizeof(table)/sizeof(char *); i++) {  
                 e = NULL;  
                 v = ohash_interval(table[i], &e);  
                 h = v % slots;  
                 if (occupied[h]) {  
                         fprintf(stderr, "Collision: %s / %s (%d)\n", occupied[h],  
                                 table[i], h);  
                         exit(1);                          exit(1);
                   for (i = 0; i < slots; i++)
                           occupied[i] = NULL;
           } else
                   occupied = NULL;
   
           printf("/* File created by generate %d %d, do not edit */\n",
               tn, slots);
           for (i = 0; t[i] != NULL; i++) {
                   e = NULL;
                   v = ohash_interval(t[i], &e);
                   if (slots) {
                           h = v % slots;
                           if (occupied[h]) {
                                   fprintf(stderr,
                                       "Collision: %s / %s (%d)\n", occupied[h],
                                       t[i], h);
                                   exit(1);
                           }
                           occupied[h] = t[i];
                 }                  }
                 occupied[h] = table[i++];                  i++;
                 printf("#define K_%s %u\n", table[i], v);                  printf("#define K_%s %u\n", t[i], v);
         }          }
         printf("#define MAGICSLOTS %u\n", slots);          if (slots)
                   printf("#define MAGICSLOTS%d %u\n", tn, slots);
         exit(0);          exit(0);
 }  }
   

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3