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

Annotation of src/usr.bin/make/generate.c, Revision 1.6

1.4       espie       1: /*     $OpenPackages$ */
1.6     ! espie       2: /*     $OpenBSD: generate.c,v 1.5 2002/06/11 21:12:11 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.1       espie      38:
                     39: #define M(x)   x, #x
1.3       espie      40: char *table_var[] = {
1.1       espie      41:        M(TARGET),
                     42:        M(OODATE),
                     43:        M(ALLSRC),
                     44:        M(IMPSRC),
                     45:        M(PREFIX),
                     46:        M(ARCHIVE),
                     47:        M(MEMBER),
                     48:        M(LONGTARGET),
                     49:        M(LONGOODATE),
                     50:        M(LONGALLSRC),
                     51:        M(LONGIMPSRC),
                     52:        M(LONGPREFIX),
                     53:        M(LONGARCHIVE),
1.3       espie      54:        M(LONGMEMBER),
                     55:        M(FTARGET),
                     56:        M(DTARGET),
                     57:        M(FPREFIX),
                     58:        M(DPREFIX),
                     59:        M(FARCHIVE),
                     60:        M(DARCHIVE),
                     61:        M(FMEMBER),
                     62:        M(DMEMBER),
                     63:        NULL
1.1       espie      64: };
                     65:
1.3       espie      66: char *table_cond[] = {
                     67:        M(COND_IF),
                     68:        M(COND_IFDEF),
                     69:        M(COND_IFNDEF),
                     70:        M(COND_IFMAKE),
                     71:        M(COND_IFNMAKE),
                     72:        M(COND_ELSE),
1.5       espie      73:        M(COND_ELIF),
1.3       espie      74:        M(COND_ELIFDEF),
                     75:        M(COND_ELIFNDEF),
                     76:        M(COND_ELIFMAKE),
                     77:        M(COND_ELIFNMAKE),
                     78:        M(COND_ENDIF),
                     79:        M(COND_FOR),
1.5       espie      80:        M(COND_ENDFOR),
1.3       espie      81:        M(COND_INCLUDE),
                     82:        M(COND_UNDEF),
                     83:        NULL
                     84: };
                     85:
                     86:
                     87: char **table[] = {
                     88:        table_var,
                     89:        table_cond
                     90: };
1.1       espie      91:
                     92: int
                     93: main(int argc, char *argv[])
                     94: {
1.6     ! espie      95:        uint32_t i;
        !            96:        uint32_t v;
        !            97:        uint32_t h;
        !            98:        uint32_t slots;
1.1       espie      99:        const char *e;
                    100:        char **occupied;
1.3       espie     101:        char **t;
                    102:        int tn;
1.1       espie     103:
                    104:        Init_Stats();
1.3       espie     105:        if (argc != 3)
1.1       espie     106:                exit(1);
                    107:
1.3       espie     108:        tn = atoi(argv[1]);
                    109:        if (!tn)
1.1       espie     110:                exit(1);
1.3       espie     111:        t = table[tn-1];
                    112:        slots = atoi(argv[2]);
                    113:        if (slots) {
                    114:                occupied = malloc(sizeof(char *) * slots);
                    115:                if (!occupied)
                    116:                        exit(1);
                    117:                for (i = 0; i < slots; i++)
                    118:                        occupied[i] = NULL;
                    119:        } else
                    120:                occupied = NULL;
                    121:
                    122:        printf("/* File created by generate %d %d, do not edit */\n",
                    123:            tn, slots);
                    124:        for (i = 0; t[i] != NULL; i++) {
1.1       espie     125:                e = NULL;
1.3       espie     126:                v = ohash_interval(t[i], &e);
                    127:                if (slots) {
                    128:                        h = v % slots;
                    129:                        if (occupied[h]) {
                    130:                                fprintf(stderr,
                    131:                                    "Collision: %s / %s (%d)\n", occupied[h],
                    132:                                    t[i], h);
                    133:                                exit(1);
                    134:                        }
                    135:                        occupied[h] = t[i];
1.1       espie     136:                }
1.3       espie     137:                i++;
                    138:                printf("#define K_%s %u\n", t[i], v);
1.1       espie     139:        }
1.3       espie     140:        if (slots)
                    141:                printf("#define MAGICSLOTS%d %u\n", tn, slots);
1.1       espie     142:        exit(0);
                    143: }