1 /* Ident --- unique handles for identifiers
2 Copyright (C) 1995, 1996 Markus Armbruster
3 All rights reserved. */
23 #define ID_TO_STR(id) ((const char *)&(id)->dptr[0])
24 #define ID_TO_STRLEN(id) ((id)->size)
25 #define ID_TO_HASH(id) ((long)(id) + (id)->hash)
27 /* Vormals Debugunterstuetzung, entfernt (debug.h). */
28 # define ID_VRFY(id) ((void)0)
29 # define IDS_VRFY(id) ((void)0)
32 # define id_stats() set_stats (id_set)
34 # define id_stats() ((void)0)
42 id_set = new_set(memcmp, TUNE_NIDENTS);
45 INLINE ident *id_from_str (const char *str, int len)
48 return set_hinsert0(id_set, str, len, ID_HASH(str, len));
51 ident *new_id_from_str(const char *str)
54 return id_from_str(str, strlen(str));
57 INLINE const char *id_to_str(ident *id)
59 return (const char *)id->dptr;
62 INLINE int id_to_strlen(ident *id)
67 int id_is_prefix(ident *prefix, ident *id)
69 if (id_to_strlen(prefix) > id_to_strlen(id)) return 0;
70 return 0 == memcmp(prefix->dptr, id->dptr, id_to_strlen(prefix));
73 int id_is_suffix(ident *suffix, ident *id)
75 int suflen = id_to_strlen(suffix);
76 int idlen = id_to_strlen(id);
79 if (suflen > idlen) return 0;
81 part = (char *)id->dptr;
82 part = part + (idlen - suflen);
84 return 0 == memcmp(suffix->dptr, part, suflen);
87 int id_contains_char(ident *id, char c)
89 return strchr(id_to_str(id), c) != NULL;
92 int print_id (ident *id)
94 return printf("%s", id_to_str(id));
97 int fprint_id (FILE *F, ident *id)
99 return fprintf(F, "%s", id_to_str(id));