1 /* C code produced by gperf version 2.1p1 (K&R C version, modified by Pavel) */
2 /* Command-line: pgperf -aCIptT -k1,3,$ keywords.gperf  */
3 
4 #include "my-ctype.h"
5 
6 	/* -*- C -*- */
7 
8 /******************************************************************************
9   Copyright (c) 1992, 1995, 1996 Xerox Corporation.  All rights reserved.
10   Portions of this code were written by Stephen White, aka ghond.
11   Use and copying of this software and preparation of derivative works based
12   upon this software are permitted.  Any distribution of this software or
13   derivative works must comply with all applicable United States export
14   control laws.  This software is made available AS IS, and Xerox Corporation
15   makes no warranty about the software, its performance or its conformity to
16   any specification.  Any person obtaining a copy of this software is requested
17   to send their name and post office or electronic mail address to:
18     Pavel Curtis
19     Xerox PARC
20     3333 Coyote Hill Rd.
21     Palo Alto, CA 94304
22     Pavel@Xerox.Com
23  *****************************************************************************/
24 
25 #include "my-string.h"
26 
27 #include "config.h"
28 #include "keywords.h"
29 #include "tokens.h"
30 #include "utils.h"
31 
32 
33 #define MIN_WORD_LENGTH 2
34 #define MAX_WORD_LENGTH 9
35 #define MIN_HASH_VALUE 3
36 #define MAX_HASH_VALUE 106
37 /*
38    35 keywords
39    104 is the maximum key range
40  */
41 
42 static int
hash(register const char * str,register int len)43 hash(register const char *str, register int len)
44 {
45     static const unsigned char hash_table[] =
46     {
47 	106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
48 	106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
49 	106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
50 	106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
51 	106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
52 	106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
53 	106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
54 	106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
55 	106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
56 	106, 106, 106, 106, 106, 106, 106, 10, 0, 45,
57 	0, 0, 0, 10, 106, 45, 106, 10, 106, 35,
58 	5, 106, 5, 10, 0, 25, 55, 106, 35, 5,
59 	106, 10, 106, 106, 106, 106, 106, 106,
60     };
61     register int hval = len;
62 
63     switch (hval) {
64     default:
65     case 3:
66 	hval += hash_table[tolower((unsigned char) str[2])];
67     case 2:
68     case 1:
69 	hval += hash_table[tolower((unsigned char) str[0])];
70     }
71     return hval + hash_table[tolower((unsigned char) str[len - 1])];
72 }
73 
74 static int
case_strcmp(register const char * str,register const char * key)75 case_strcmp(register const char *str, register const char *key)
76 {
77     int ans = 0;
78 
79     while (!(ans = tolower(*str) - (int) *key) && *str)
80 	str++, key++;
81 
82     return ans;
83 }
84 
85 const struct keyword *
in_word_set(register const char * str,register int len)86 in_word_set(register const char *str, register int len)
87 {
88 
89     static const struct keyword wordlist[] =
90     {
91 	{"",},
92 	{"",},
93 	{"",},
94 	{"for", DBV_Prehistory, tFOR},
95 	{"",},
96 	{"endif", DBV_Prehistory, tENDIF},
97 	{"endfor", DBV_Prehistory, tENDFOR},
98 	{"e_range", DBV_Prehistory, tERROR, E_RANGE},
99 	{"endwhile", DBV_Prehistory, tENDWHILE},
100 	{"e_recmove", DBV_Prehistory, tERROR, E_RECMOVE},
101 	{"",},
102 	{"e_none", DBV_Prehistory, tERROR, E_NONE},
103 	{"",},
104 	{"e_propnf", DBV_Prehistory, tERROR, E_PROPNF},
105 	{"fork", DBV_Prehistory, tFORK},
106 	{"break", DBV_BreakCont, tBREAK},
107 	{"endtry", DBV_Exceptions, tENDTRY},
108 	{"endfork", DBV_Prehistory, tENDFORK},
109 	{"",},
110 	{"",},
111 	{"",},
112 	{"",},
113 	{"finally", DBV_Exceptions, tFINALLY},
114 	{"",},
115 	{"",},
116 	{"",},
117 	{"",},
118 	{"e_quota", DBV_Prehistory, tERROR, E_QUOTA},
119 	{"",},
120 	{"else", DBV_Prehistory, tELSE},
121 	{"",},
122 	{"elseif", DBV_Prehistory, tELSEIF},
123 	{"",},
124 	{"any", DBV_Exceptions, tANY},
125 	{"",},
126 	{"",},
127 	{"",},
128 	{"",},
129 	{"",},
130 	{"",},
131 	{"e_div", DBV_Prehistory, tERROR, E_DIV},
132 	{"e_args", DBV_Prehistory, tERROR, E_ARGS},
133 	{"e_varnf", DBV_Prehistory, tERROR, E_VARNF},
134 	{"e_verbnf", DBV_Prehistory, tERROR, E_VERBNF},
135 	{"",},
136 	{"",},
137 	{"e_perm", DBV_Prehistory, tERROR, E_PERM},
138 	{"if", DBV_Prehistory, tIF},
139 	{"",},
140 	{"",},
141 	{"",},
142 	{"",},
143 	{"in", DBV_Prehistory, tIN},
144 	{"e_invind", DBV_Prehistory, tERROR, E_INVIND},
145 	{"",},
146 	{"while", DBV_Prehistory, tWHILE},
147 	{"e_nacc", DBV_Prehistory, tERROR, E_NACC},
148 	{"",},
149 	{"continue", DBV_BreakCont, tCONTINUE},
150 	{"",},
151 	{"",},
152 	{"e_type", DBV_Prehistory, tERROR, E_TYPE},
153 	{"e_float", DBV_Float, tERROR, E_FLOAT},
154 	{"e_invarg", DBV_Prehistory, tERROR, E_INVARG},
155 	{"",},
156 	{"",},
157 	{"return", DBV_Prehistory, tRETURN},
158 	{"",},
159 	{"",},
160 	{"",},
161 	{"",},
162 	{"",},
163 	{"",},
164 	{"",},
165 	{"",},
166 	{"",},
167 	{"",},
168 	{"",},
169 	{"try", DBV_Exceptions, tTRY},
170 	{"",},
171 	{"",},
172 	{"",},
173 	{"",},
174 	{"",},
175 	{"",},
176 	{"",},
177 	{"",},
178 	{"",},
179 	{"e_maxrec", DBV_Prehistory, tERROR, E_MAXREC},
180 	{"",},
181 	{"",},
182 	{"",},
183 	{"",},
184 	{"",},
185 	{"",},
186 	{"",},
187 	{"",},
188 	{"",},
189 	{"",},
190 	{"",},
191 	{"",},
192 	{"",},
193 	{"",},
194 	{"",},
195 	{"",},
196 	{"",},
197 	{"except", DBV_Exceptions, tEXCEPT},
198     };
199 
200     if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) {
201 	register int key = hash(str, len);
202 
203 	if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE) {
204 	    register const char *s = wordlist[key].name;
205 
206 	    if (*s == tolower(*str) && !case_strcmp(str + 1, s + 1))
207 		return &wordlist[key];
208 	}
209     }
210     return 0;
211 }
212 
213 const struct keyword *
find_keyword(const char * word)214 find_keyword(const char *word)
215 {
216     return in_word_set(word, strlen(word));
217 }
218 
219 char rcsid_keywords[] = "$Id: keywords.c,v 1.3 1998/12/14 13:17:55 nop Exp $";
220 
221 /*
222  * $Log: keywords.c,v $
223  * Revision 1.3  1998/12/14 13:17:55  nop
224  * Merge UNSAFE_OPTS (ref fixups); fix Log tag placement to fit CVS whims
225  *
226  * Revision 1.2  1997/03/03 04:18:45  nop
227  * GNU Indent normalization
228  *
229  * Revision 1.1.1.1  1997/03/03 03:45:00  nop
230  * LambdaMOO 1.8.0p5
231  *
232  * Revision 2.2  1996/02/08  06:33:21  pavel
233  * Added `break', `continue', and E_FLOAT.  Updated copyright notice for 1996.
234  * Release 1.8.0beta1.
235  *
236  * Revision 2.1  1995/12/11  08:15:42  pavel
237  * Added #include "tokens.h" removed from keywords.h.  Release 1.8.0alpha2.
238  *
239  * Revision 2.0  1995/11/30  05:02:56  pavel
240  * New baseline version, corresponding to release 1.8.0alpha1.
241  *
242  * Revision 1.1  1995/11/30  05:01:47  pavel
243  * Initial revision
244  */
245