aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/make/parse.c
diff options
context:
space:
mode:
authorHartmut Brandt <harti@FreeBSD.org>2005-04-28 07:55:55 +0000
committerHartmut Brandt <harti@FreeBSD.org>2005-04-28 07:55:55 +0000
commit2274441da6a3a642412527fd795e1d5aeb44b6b9 (patch)
tree55eac1df47743b4f456328f864ca636a89abb33b /usr.bin/make/parse.c
parent61d596a8ff529277d32f6a0571227b06856052ab (diff)
downloadsrc-2274441da6a3a642412527fd795e1d5aeb44b6b9.tar.gz
src-2274441da6a3a642412527fd795e1d5aeb44b6b9.zip
Move the hash function for directives into its own file and add
a Makefile target to re-created this file. Note, that there is no explicite dependency to automatically re-create the file, because this is needed only when the directive table changes and it requires the (yet to come) devel/mph port. Submitted by: Max Okumoto <okumoto@ucsd.edu> (first version)
Notes
Notes: svn path=/head/; revision=145612
Diffstat (limited to 'usr.bin/make/parse.c')
-rw-r--r--usr.bin/make/parse.c68
1 files changed, 3 insertions, 65 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index 431d854a94cb..05701b599615 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -82,6 +82,7 @@ __FBSDID("$FreeBSD$");
#include "cond.h"
#include "config.h"
#include "dir.h"
+#include "directive_hash.h"
#include "for.h"
#include "globals.h"
#include "GNode.h"
@@ -231,58 +232,19 @@ static struct {
{ ".WAIT", Wait, 0 },
};
-/*
- * Directive table. We use a hash table. This hash table has been generated
- * with mph which can be found on the usual GNU mirrors. If you change the
- * directives (adding, deleting, reordering) you need to create a new table
- * and hash function (directive_hash). The command line to generate the
- * table is:
- *
- * mph -d2 -m1 <tab | emitc -l -s
- *
- * Where tab is a file containing just the directive strings, one per line.
- *
- * While inporting the result of this the following changes have been made
- * to the generated code:
- *
- * prefix the names of the g, T0 and T1 arrays with 'directive_'.
- *
- * make the type of the tables 'const [un]signed char'.
- *
- * make the hash function use the length for termination,
- * not the trailing '\0'.
- */
static void parse_include(char *, int, int);
static void parse_message(char *, int, int);
static void parse_undef(char *, int, int);
static void parse_for(char *, int, int);
static void parse_endfor(char *, int, int);
-static const signed char directive_g[] = {
- 16, 0, -1, 14, 5, 2, 2, -1, 0, 0,
- -1, -1, 16, 11, -1, 15, -1, 14, 7, -1,
- 8, 6, 1, -1, -1, 0, 4, 6, -1, 0,
- 0, 2, 0, 13, -1, 14, -1, 0,
-};
-
-static const unsigned char directive_T0[] = {
- 11, 25, 14, 30, 14, 26, 23, 15, 9, 37,
- 27, 32, 27, 1, 17, 27, 35, 13, 8, 22,
- 8, 28, 7,
-};
-
-static const unsigned char directive_T1[] = {
- 19, 20, 31, 17, 29, 2, 7, 12, 1, 31,
- 11, 18, 11, 20, 10, 2, 15, 19, 4, 10,
- 13, 36, 3,
-};
-
static const struct directive {
const char *name;
int code;
Boolean skip_flag; /* execute even when skipped */
void (*func)(char *, int, int);
} directives[] = {
+ /* DIRECTIVES-START-TAG */
{ "elif", COND_ELIF, TRUE, Cond_If },
{ "elifdef", COND_ELIFDEF, TRUE, Cond_If },
{ "elifmake", COND_ELIFMAKE, TRUE, Cond_If },
@@ -301,6 +263,7 @@ static const struct directive {
{ "include", 0, FALSE, parse_include },
{ "undef", 0, FALSE, parse_undef },
{ "warning", 0, FALSE, parse_message },
+ /* DIRECTIVES-END-TAG */
};
#define NDIRECTS (sizeof(directives) / sizeof(directives[0]))
@@ -2331,31 +2294,6 @@ parse_endfor(char *line __unused, int code __unused, int lineno __unused)
}
/**
- * directive_hash
- */
-static int
-directive_hash(const u_char *key, size_t len)
-{
- unsigned f0, f1;
- const u_char *kp = key;
-
- if (len < 2 || len > 9)
- return (-1);
-
- for (f0 = f1 = 0; kp < key + len; ++kp) {
- if (*kp < 97 || *kp > 119)
- return (-1);
- f0 += directive_T0[-97 + *kp];
- f1 += directive_T1[-97 + *kp];
- }
-
- f0 %= 38;
- f1 %= 38;
-
- return (directive_g[f0] + directive_g[f1]) % 18;
-}
-
-/**
* parse_directive
* Got a line starting with a '.'. Check if this is a directive
* and parse it.