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 INLINE ident *id_from_str (const char *str, int len)
37 return set_hinsert0(id_set, str, len, ID_HASH(str, len));
40 ident *new_id_from_str(const char *str)
43 return id_from_str(str, strlen(str));
46 INLINE const char *get_id_str(ident *id)
48 return (const char *)id->dptr;
51 INLINE int get_id_strlen(ident *id)
56 int id_is_prefix(ident *prefix, ident *id)
58 if (get_id_strlen(prefix) > get_id_strlen(id)) return 0;
59 return 0 == memcmp(prefix->dptr, id->dptr, get_id_strlen(prefix));
62 int id_is_suffix(ident *suffix, ident *id)
64 int suflen = get_id_strlen(suffix);
65 int idlen = get_id_strlen(id);
68 if (suflen > idlen) return 0;
70 part = (char *)id->dptr;
71 part = part + (idlen - suflen);
73 return 0 == memcmp(suffix->dptr, part, suflen);
76 int id_contains_char(ident *id, char c)
78 return strchr(get_id_str(id), c) != NULL;
81 int print_id (ident *id)
83 return printf("%s", get_id_str(id));
86 int fprint_id (FILE *F, ident *id)
88 return fprintf(F, "%s", get_id_str(id));