Annotation of src/usr.bin/make/generate.c, Revision 1.5
1.4 espie 1: /* $OpenPackages$ */
1.5 ! espie 2: /* $OpenBSD: generate.c,v 1.4 2001/05/23 12:34:43 espie Exp $ */
1.1 espie 3:
1.4 espie 4: /*
5: * Copyright (c) 2001 Marc Espie.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: *
16: * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
17: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
20: * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27: */
28:
29: #include <stddef.h>
1.1 espie 30: #include <stdio.h>
31: #include <stdlib.h>
32:
1.3 espie 33: #include "stats.h"
1.1 espie 34: #include "ohash.h"
1.3 espie 35: #include "cond_int.h"
1.4 espie 36: #include "var_int.h"
1.1 espie 37:
38: #define M(x) x, #x
1.3 espie 39: char *table_var[] = {
1.1 espie 40: M(TARGET),
41: M(OODATE),
42: M(ALLSRC),
43: M(IMPSRC),
44: M(PREFIX),
45: M(ARCHIVE),
46: M(MEMBER),
47: M(LONGTARGET),
48: M(LONGOODATE),
49: M(LONGALLSRC),
50: M(LONGIMPSRC),
51: M(LONGPREFIX),
52: M(LONGARCHIVE),
1.3 espie 53: M(LONGMEMBER),
54: M(FTARGET),
55: M(DTARGET),
56: M(FPREFIX),
57: M(DPREFIX),
58: M(FARCHIVE),
59: M(DARCHIVE),
60: M(FMEMBER),
61: M(DMEMBER),
62: NULL
1.1 espie 63: };
64:
1.3 espie 65: char *table_cond[] = {
66: M(COND_IF),
67: M(COND_IFDEF),
68: M(COND_IFNDEF),
69: M(COND_IFMAKE),
70: M(COND_IFNMAKE),
71: M(COND_ELSE),
1.5 ! espie 72: M(COND_ELIF),
1.3 espie 73: M(COND_ELIFDEF),
74: M(COND_ELIFNDEF),
75: M(COND_ELIFMAKE),
76: M(COND_ELIFNMAKE),
77: M(COND_ENDIF),
78: M(COND_FOR),
1.5 ! espie 79: M(COND_ENDFOR),
1.3 espie 80: M(COND_INCLUDE),
81: M(COND_UNDEF),
82: NULL
83: };
84:
85:
86: char **table[] = {
87: table_var,
88: table_cond
89: };
1.1 espie 90:
91: int
92: main(int argc, char *argv[])
93: {
94: u_int32_t i;
95: u_int32_t v;
96: u_int32_t h;
97: u_int32_t slots;
98: const char *e;
99: char **occupied;
1.3 espie 100: char **t;
101: int tn;
1.1 espie 102:
103: Init_Stats();
1.3 espie 104: if (argc != 3)
1.1 espie 105: exit(1);
106:
1.3 espie 107: tn = atoi(argv[1]);
108: if (!tn)
1.1 espie 109: exit(1);
1.3 espie 110: t = table[tn-1];
111: slots = atoi(argv[2]);
112: if (slots) {
113: occupied = malloc(sizeof(char *) * slots);
114: if (!occupied)
115: exit(1);
116: for (i = 0; i < slots; i++)
117: occupied[i] = NULL;
118: } else
119: occupied = NULL;
120:
121: printf("/* File created by generate %d %d, do not edit */\n",
122: tn, slots);
123: for (i = 0; t[i] != NULL; i++) {
1.1 espie 124: e = NULL;
1.3 espie 125: v = ohash_interval(t[i], &e);
126: if (slots) {
127: h = v % slots;
128: if (occupied[h]) {
129: fprintf(stderr,
130: "Collision: %s / %s (%d)\n", occupied[h],
131: t[i], h);
132: exit(1);
133: }
134: occupied[h] = t[i];
1.1 espie 135: }
1.3 espie 136: i++;
137: printf("#define K_%s %u\n", t[i], v);
1.1 espie 138: }
1.3 espie 139: if (slots)
140: printf("#define MAGICSLOTS%d %u\n", tn, slots);
1.1 espie 141: exit(0);
142: }