3 * File name: ir/common/ident.c
4 * Purpose: Hash table to store names.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 1999-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
29 void id_init(int initial_n_idents)
31 id_set = new_set(memcmp, initial_n_idents);
34 void id_finish (void) {
39 INLINE ident *id_from_str (const char *str, int len)
42 return set_hinsert0(id_set, str, len, ID_HASH(str, len));
45 ident *new_id_from_str(const char *str)
48 return id_from_str(str, strlen(str));
51 INLINE const char *get_id_str(ident *id)
53 return (const char *)id->dptr;
56 INLINE int get_id_strlen(ident *id)
61 int id_is_prefix(ident *prefix, ident *id)
63 if (get_id_strlen(prefix) > get_id_strlen(id)) return 0;
64 return 0 == memcmp(prefix->dptr, id->dptr, get_id_strlen(prefix));
67 int id_is_suffix(ident *suffix, ident *id)
69 int suflen = get_id_strlen(suffix);
70 int idlen = get_id_strlen(id);
73 if (suflen > idlen) return 0;
75 part = (char *)id->dptr;
76 part = part + (idlen - suflen);
78 return 0 == memcmp(suffix->dptr, part, suflen);
81 int id_contains_char(ident *id, char c)
83 return strchr(get_id_str(id), c) != NULL;
86 int print_id (ident *id)
88 return printf("%s", get_id_str(id));
91 int fprint_id (FILE *F, ident *id)
93 return fprintf(F, "%s", get_id_str(id));