2 *------------------------------------------------------------------
3 * Copyright (c) 2006-2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 static char *sxerox (char *s);
29 typedef struct prop_ {
35 static prop_t *buckets [NBUCKETS];
36 static int hash_shifts[4] = {24, 16, 8, 0};
42 char *getprop (char *name)
49 for (cp = (unsigned char *) name; *cp; cp++)
50 hash ^= (*cp)<<(hash_shifts[(i++)&0x3]);
52 bp = buckets [hash%NBUCKETS];
54 while (bp && strcmp(bp->name, name)) {
68 char *getprop_default (char *name, char *def)
82 void addprop (char *name, char *value)
90 bp = (prop_t *)malloc (sizeof (prop_t));
93 bp->name = sxerox (name);
94 bp->value = sxerox (value);
96 for (cp = (unsigned char *)name; *cp; cp++)
97 hash ^= (*cp)<<(hash_shifts[(i++)&0x3]);
99 bpp = &buckets [hash%NBUCKETS];
113 static char *sxerox (char *s)
115 char *rv = (char *) malloc (strlen (s) + 1);
128 #define CPP_COMMENT 4
130 int readprops (char *filename)
140 ifp = fopen (filename, "r");
158 if (c == ' ' || c == '\t')
165 if (isalpha (c) || (c == '_')) {
174 } else if (c == '*') {
178 fprintf (stderr, "unknown token '/' line %d\n",
183 fprintf (stderr, "unknown token '%c' line %d\n",
205 fprintf (stderr, "unterminated comment, line %d\n",
228 fprintf (stderr, "EOF while reading a name, line %d\n",
232 if ((!isalnum (c)) && (c != '_')) {
243 while ((c == ' ') || (c == '\t') || (c == '=')) {
246 fprintf (stderr, "EOF while reading a value, line %d\n",
259 fprintf (stderr, "EOF after '\\', line %d\n",
268 while (valbuf [i-1] == ' ' || valbuf[i-1] == '\t')
271 addprop (namebuf, valbuf);