generate.c revision 1.2
1/* $OpenBSD: generate.c,v 1.2 2001/03/02 16:57:26 espie Exp $ */ 2/* Written by Marc Espie 1999. 3 * Public domain. 4 */ 5 6#include <stdio.h> 7#include <stdlib.h> 8#include <stddef.h> 9 10#include "make.h" 11#include "ohash.h" 12#include "error.h" 13 14#define M(x) x, #x 15char *table[] = { 16 M(TARGET), 17 M(OODATE), 18 M(ALLSRC), 19 M(IMPSRC), 20 M(PREFIX), 21 M(ARCHIVE), 22 M(MEMBER), 23 M(LONGTARGET), 24 M(LONGOODATE), 25 M(LONGALLSRC), 26 M(LONGIMPSRC), 27 M(LONGPREFIX), 28 M(LONGARCHIVE), 29 M(LONGMEMBER) 30}; 31 32 33int 34main(int argc, char *argv[]) 35{ 36 u_int32_t i; 37 u_int32_t v; 38 u_int32_t h; 39 u_int32_t slots; 40 const char *e; 41 char **occupied; 42 43#ifdef HAS_STATS 44 Init_Stats(); 45#endif 46 if (argc < 2) 47 exit(1); 48 49 slots = atoi(argv[1]); 50 if (!slots) 51 exit(1); 52 occupied = emalloc(sizeof(char *) * slots); 53 for (i = 0; i < slots; i++) 54 occupied[i] = NULL; 55 56 printf("/* Generated file, do not edit */\n"); 57 for (i = 0; i < sizeof(table)/sizeof(char *); i++) { 58 e = NULL; 59 v = ohash_interval(table[i], &e); 60 h = v % slots; 61 if (occupied[h]) { 62 fprintf(stderr, "Collision: %s / %s (%d)\n", occupied[h], 63 table[i], h); 64 exit(1); 65 } 66 occupied[h] = table[i++]; 67 printf("#define K_%s %u\n", table[i], v); 68 } 69 printf("#define MAGICSLOTS %u\n", slots); 70 exit(0); 71} 72 73