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.
27 void init_ident(int initial_n_idents)
29 __id_set = new_set(memcmp, initial_n_idents);
32 void finish_ident (void) {
37 ident *(new_id_from_chars)(const char *str, int len)
39 return __id_from_str(str, len);
42 ident *new_id_from_str(const char *str)
45 return new_id_from_chars(str, strlen(str));
48 const char *(get_id_str)(ident *id)
50 return __get_id_str(id);
53 int (get_id_strlen)(ident *id)
55 return __get_id_strlen(id);
58 int id_is_prefix(ident *prefix, ident *id)
60 if (get_id_strlen(prefix) > get_id_strlen(id)) return 0;
61 return 0 == memcmp(prefix->dptr, id->dptr, get_id_strlen(prefix));
64 int id_is_suffix(ident *suffix, ident *id)
66 int suflen = get_id_strlen(suffix);
67 int idlen = get_id_strlen(id);
70 if (suflen > idlen) return 0;
72 part = (char *)id->dptr;
73 part = part + (idlen - suflen);
75 return 0 == memcmp(suffix->dptr, part, suflen);
78 int id_contains_char(ident *id, char c)
80 return strchr(get_id_str(id), c) != NULL;
83 int print_id (ident *id)
85 return printf("%s", get_id_str(id));
88 int fprint_id (FILE *F, ident *id)
90 return fprintf(F, "%s", get_id_str(id));