2 *------------------------------------------------------------------
3 * Copyright (c) 1997-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.
23 static char *sxerox (char *s);
28 typedef struct prop_ {
34 static prop_t *buckets [NBUCKETS];
35 static int hash_shifts[4] = {24, 16, 8, 0};
41 char *getprop (char *name)
48 for (cp = (unsigned char *) name; *cp; cp++)
49 hash ^= (*cp)<<(hash_shifts[(i++)&0x3]);
51 bp = buckets [hash%NBUCKETS];
53 while (bp && strcmp (bp->name, name)) {
67 char *getprop_default (char *name, char *def)
81 void addprop (char *name, char *value)
89 bp = (prop_t *)g_malloc (sizeof (prop_t));
92 bp->name = sxerox (name);
93 bp->value = sxerox (value);
95 for (cp = (unsigned char *)name; *cp; cp++)
96 hash ^= (*cp)<<(hash_shifts[(i++)&0x3]);
98 bpp = &buckets [hash%NBUCKETS];
112 static char *sxerox (char *s)
114 char *rv = (char *) g_malloc (strlen (s) + 1);
127 #define CPP_COMMENT 4
129 int readprops (char *filename)
139 ifp = fopen (filename, "r");
157 if (c == ' ' || c == '\t')
164 if (isalpha (c) || (c == '_')) {
173 } else if (c == '*') {
177 fprintf (stderr, "unknown token '/' line %d\n",
182 fprintf (stderr, "unknown token '%c' line %d\n",
204 fprintf (stderr, "unterminated comment, line %d\n",
227 fprintf (stderr, "EOF while reading a name, line %d\n",
231 if ((!isalnum (c)) && (c != '_')) {
242 while ((c == ' ') || (c == '\t') || (c == '=')) {
245 fprintf (stderr, "EOF while reading a value, line %d\n",
258 fprintf (stderr, "EOF after '\\', line %d\n",
267 while (valbuf [i-1] == ' ' || valbuf[i-1] == '\t')
270 addprop (namebuf, valbuf);