Annotation of src/usr.bin/make/generate.c, Revision 1.9
1.4 espie 1: /* $OpenPackages$ */
1.9 ! espie 2: /* $OpenBSD: generate.c,v 1.8 2007/09/03 13:56:56 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>
1.6 espie 31: #include <stdint.h>
1.1 espie 32: #include <stdlib.h>
33:
1.3 espie 34: #include "stats.h"
1.1 espie 35: #include "ohash.h"
1.3 espie 36: #include "cond_int.h"
1.4 espie 37: #include "var_int.h"
1.9 ! espie 38: #include "node_int.h"
1.1 espie 39:
40: #define M(x) x, #x
1.3 espie 41: char *table_var[] = {
1.1 espie 42: M(TARGET),
43: M(OODATE),
44: M(ALLSRC),
45: M(IMPSRC),
46: M(PREFIX),
47: M(ARCHIVE),
48: M(MEMBER),
49: M(LONGTARGET),
50: M(LONGOODATE),
51: M(LONGALLSRC),
52: M(LONGIMPSRC),
53: M(LONGPREFIX),
54: M(LONGARCHIVE),
1.3 espie 55: M(LONGMEMBER),
56: M(FTARGET),
57: M(DTARGET),
58: M(FPREFIX),
59: M(DPREFIX),
60: M(FARCHIVE),
61: M(DARCHIVE),
62: M(FMEMBER),
63: M(DMEMBER),
64: NULL
1.1 espie 65: };
66:
1.3 espie 67: char *table_cond[] = {
68: M(COND_IF),
69: M(COND_IFDEF),
70: M(COND_IFNDEF),
71: M(COND_IFMAKE),
72: M(COND_IFNMAKE),
73: M(COND_ELSE),
1.5 espie 74: M(COND_ELIF),
1.3 espie 75: M(COND_ELIFDEF),
76: M(COND_ELIFNDEF),
77: M(COND_ELIFMAKE),
78: M(COND_ELIFNMAKE),
79: M(COND_ENDIF),
80: M(COND_FOR),
1.5 espie 81: M(COND_ENDFOR),
1.3 espie 82: M(COND_INCLUDE),
83: M(COND_UNDEF),
1.7 espie 84: M(COND_POISON),
1.3 espie 85: NULL
86: };
87:
1.9 ! espie 88: char *table_nodes[] = {
! 89: M(NODE_DEFAULT),
! 90: M(NODE_EXEC),
! 91: M(NODE_IGNORE),
! 92: M(NODE_INCLUDES),
! 93: M(NODE_INVISIBLE),
! 94: M(NODE_JOIN),
! 95: M(NODE_LIBS),
! 96: M(NODE_MADE),
! 97: M(NODE_MAIN),
! 98: M(NODE_MAKE),
! 99: M(NODE_MAKEFLAGS),
! 100: M(NODE_MFLAGS),
! 101: M(NODE_NOTMAIN),
! 102: M(NODE_NOTPARALLEL),
! 103: M(NODE_NO_PARALLEL),
! 104: M(NODE_NULL),
! 105: M(NODE_OPTIONAL),
! 106: M(NODE_ORDER),
! 107: M(NODE_PARALLEL),
! 108: M(NODE_PATH),
! 109: M(NODE_PHONY),
! 110: M(NODE_PRECIOUS),
! 111: M(NODE_RECURSIVE),
! 112: M(NODE_SILENT),
! 113: M(NODE_SINGLESHELL),
! 114: M(NODE_SUFFIXES),
! 115: M(NODE_USE),
! 116: M(NODE_WAIT),
! 117: M(NODE_BEGIN),
! 118: M(NODE_END),
! 119: M(NODE_INTERRUPT),
! 120: NULL
! 121: };
! 122:
1.3 espie 123:
124: char **table[] = {
125: table_var,
1.9 ! espie 126: table_cond,
! 127: table_nodes
1.3 espie 128: };
1.1 espie 129:
130: int
131: main(int argc, char *argv[])
132: {
1.6 espie 133: uint32_t i;
134: uint32_t v;
135: uint32_t h;
136: uint32_t slots;
1.1 espie 137: const char *e;
138: char **occupied;
1.3 espie 139: char **t;
140: int tn;
1.1 espie 141:
142: Init_Stats();
1.3 espie 143: if (argc != 3)
1.1 espie 144: exit(1);
145:
1.3 espie 146: tn = atoi(argv[1]);
147: if (!tn)
1.1 espie 148: exit(1);
1.3 espie 149: t = table[tn-1];
150: slots = atoi(argv[2]);
151: if (slots) {
1.8 espie 152: occupied = calloc(sizeof(char *), slots);
1.3 espie 153: if (!occupied)
154: exit(1);
155: for (i = 0; i < slots; i++)
156: occupied[i] = NULL;
157: } else
158: occupied = NULL;
159:
160: printf("/* File created by generate %d %d, do not edit */\n",
161: tn, slots);
162: for (i = 0; t[i] != NULL; i++) {
1.1 espie 163: e = NULL;
1.3 espie 164: v = ohash_interval(t[i], &e);
165: if (slots) {
166: h = v % slots;
167: if (occupied[h]) {
168: fprintf(stderr,
169: "Collision: %s / %s (%d)\n", occupied[h],
170: t[i], h);
171: exit(1);
172: }
173: occupied[h] = t[i];
1.1 espie 174: }
1.3 espie 175: i++;
176: printf("#define K_%s %u\n", t[i], v);
1.1 espie 177: }
1.3 espie 178: if (slots)
179: printf("#define MAGICSLOTS%d %u\n", tn, slots);
1.1 espie 180: exit(0);
181: }