summaryrefslogtreecommitdiff
path: root/usr.bin/make/generate.c
blob: 4fa1013f9064e17311d55c54a825d1125e178ed8 (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
/* $OpenBSD: generate.c,v 1.2 2001/03/02 16:57:26 espie Exp $ */
/* Written by Marc Espie 1999.  
 * Public domain.
 */

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>

#include "make.h"
#include "ohash.h"
#include "error.h"

#define M(x)	x, #x
char *table[] = {
	M(TARGET),
	M(OODATE),
	M(ALLSRC),
	M(IMPSRC),
	M(PREFIX),
	M(ARCHIVE),
	M(MEMBER),
	M(LONGTARGET),
	M(LONGOODATE),
	M(LONGALLSRC),
	M(LONGIMPSRC),
	M(LONGPREFIX),
	M(LONGARCHIVE),
	M(LONGMEMBER)
};


int
main(int argc, char *argv[])
{
	u_int32_t i;
	u_int32_t v;
	u_int32_t h;
	u_int32_t slots;
	const char *e;
	char **occupied;

#ifdef HAS_STATS
	Init_Stats();
#endif
	if (argc < 2)
		exit(1);

	slots = atoi(argv[1]);
	if (!slots)
		exit(1);
	occupied = emalloc(sizeof(char *) * slots);
	for (i = 0; i < slots; i++)
		occupied[i] = NULL;
	
	printf("/* Generated file, do not edit */\n");
	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);
		}
		occupied[h] = table[i++];
		printf("#define K_%s %u\n", table[i], v);
	}
	printf("#define MAGICSLOTS %u\n", slots);
	exit(0);
}