5d63240034fa2d974a3ad0f21cb76275cb2e49fa
[libfirm] / ir / ident / ident.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/common/ident.c
4  * Purpose:     Hash table to store names.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1999-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16
17 #include <assert.h>
18 #include <ctype.h>
19 #include <string.h>
20 #include <stddef.h>
21 #include <stdlib.h>
22
23 #include "ident_t.h"
24
25 set *__id_set;
26
27 void id_init(int initial_n_idents)
28 {
29   __id_set = new_set(memcmp, initial_n_idents);
30 }
31
32 void id_finish (void) {
33   del_set(__id_set);
34   __id_set = NULL;
35 }
36
37 ident *(id_from_str)(const char *str, int len)
38 {
39   return __id_from_str(str, len);
40 }
41
42 ident *new_id_from_str(const char *str)
43 {
44   assert(str);
45   return id_from_str(str, strlen(str));
46 }
47
48 const char *(get_id_str)(ident *id)
49 {
50   return __get_id_str(id);
51 }
52
53 int (get_id_strlen)(ident *id)
54 {
55   return __get_id_strlen(id);
56 }
57
58 int id_is_prefix(ident *prefix, ident *id)
59 {
60   if (get_id_strlen(prefix) > get_id_strlen(id)) return 0;
61   return 0 == memcmp(prefix->dptr, id->dptr, get_id_strlen(prefix));
62 }
63
64 int id_is_suffix(ident *suffix, ident *id)
65 {
66   int suflen = get_id_strlen(suffix);
67   int idlen  = get_id_strlen(id);
68   char *part;
69
70   if (suflen > idlen) return 0;
71
72   part = (char *)id->dptr;
73   part = part + (idlen - suflen);
74
75   return 0 == memcmp(suffix->dptr, part, suflen);
76 }
77
78 int id_contains_char(ident *id, char c)
79 {
80   return strchr(get_id_str(id), c) != NULL;
81 }
82
83 int print_id (ident *id)
84 {
85   return printf("%s", get_id_str(id));
86 }
87
88 int fprint_id (FILE *F, ident *id)
89 {
90   return fprintf(F, "%s", get_id_str(id));
91 }