1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * originally written by: Kirk Reiser.
5 ** Copyright (C) 2002 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski.
24 struct st_key key_table
[MAXKEYS
];
25 struct st_key
*extra_keys
= key_table
+HASHSIZE
;
26 char *def_name
, *def_val
;
32 static inline void open_input(const char *dir_name
, const char *name
)
35 snprintf(filename
, sizeof(filename
), "%s/%s", dir_name
, name
);
37 snprintf(filename
, sizeof(filename
), "%s", name
);
38 infile
= fopen(filename
, "r");
40 fprintf(stderr
, "can't open %s\n", filename
);
46 static inline int oops(const char *msg
, const char *info
)
50 fprintf(stderr
, "error: file %s line %d\n", filename
, lc
);
51 fprintf(stderr
, "%s %s\n", msg
, info
);
55 static inline struct st_key
*hash_name(char *name
)
57 unsigned char *pn
= (unsigned char *)name
;
61 hash
= (hash
* 17) & 0xfffffff;
68 return &key_table
[hash
];
71 static inline struct st_key
*find_key(char *name
)
73 struct st_key
*this = hash_name(name
);
76 if (this->name
&& !strcmp(name
, this->name
))
83 static inline struct st_key
*add_key(char *name
, int value
, int shift
)
85 struct st_key
*this = hash_name(name
);
87 if (extra_keys
-key_table
>= MAXKEYS
)
88 oops("out of key table space, enlarge MAXKEYS", NULL
);
89 if (this->name
!= NULL
) {
91 if (!strcmp(name
, this->name
))
92 oops("attempt to add duplicate key", name
);
95 this->next
= extra_keys
++;
98 this->name
= strdup(name
);