1 /* $Id: cclash.c,v 0.7 1994/06/24 10:16:36 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
7 cclash: find clashing names within C programs
10 -c : produce oldname=newname line for each clashing id
11 (useful input for cid)
12 -l<num> : check identifiers of <num> or more characters
14 -m : output a #define for each clashing id
16 Author: Erik Baalbergen
20 C keywords are not listed
22 Skip C numeric constants
23 Revised: Wed Jul 23 13:27:16 MDT 1986
25 replaced "stoi" by "atoi"
26 Revised: Tue Nov 11 13:32:31 MET 1986
28 to produce lists for "cid" or preprocessor in
43 #define ACT_LISTONLY 0
47 int maxlen = DEF_LENGTH;
48 int action = ACT_LISTONLY;
50 extern char *ProgName;
86 struct idf *maplist = 0;
90 register char **pkey = &keywords[0];
94 if (strlen(id) >= maxlen)
108 if ((maxlen = atoi(&str[2])) <= 0) {
109 fprintf(stderr, "%s: option \"-l%s\" ignored\n",
116 action = ACT_MAPFILE;
120 fprintf(stderr, "%s: bad option \"%s\"\n", ProgName, str);
127 struct idf *hash_tab[HASHSIZE];
129 char *Malloc(), *Salloc();
134 int hash_val = EnHash(id);
135 register struct idf *idp = hash_tab[hash_val];
136 register struct idf *p = 0;
138 while (idp && strncmp(idp->id_name, id, maxlen)) {
144 idp = (struct idf *) Malloc(sizeof(struct idf));
146 if (!p) hash_tab[hash_val] = idp;
147 else p->id_next = idp;
148 idp->id_name = Salloc(id);
154 while (p && strcmp(p->id_name, id)) {
160 p = (struct idf *) Malloc(sizeof(struct idf));
163 p->id_name = Salloc(id);
174 char *mem, *malloc();
176 if ((mem = malloc(n)) == 0) {
177 fprintf(stderr, "%s: out of memory\n", ProgName);
192 return strcpy(Malloc((unsigned)strlen(str) + 1), str);
198 register unsigned hash_val = 0;
202 hash_val = 31 * hash_val + *id++;
204 return hash_val % (unsigned) HASHSIZE;
207 BeginOfProgram() { DefineKeys(); }
212 register struct idf *idp, *p;
214 for (i = 0; i < HASHSIZE; i++) {
215 for (idp = hash_tab[i]; idp; idp = idp->id_next) {
216 if (idp->id_same == 0)
224 if (idp->id_key == 0) {
225 printf(idp->id_name);
228 for (p = idp->id_same; p; p = p->id_same)
229 if (p->id_key == 0) {
242 for (p = idp->id_same; p;) {
243 register struct idf *q = p->id_same;
249 if (idp->id_key == 0)
258 for (idp = maplist; idp; idp = idp->id_same) {
259 mapline(idp->id_name);
265 register struct idf *p;
267 register struct idf *idp = maplist, *idp1 = 0;
269 while (idp && strcmp(idp->id_name, p->id_name) < 0) {
285 static map_count = 0;
290 printf("#define %s _%d_%s\n", nm, ++map_count, nm);
294 printf("%s=_%d_%s\n", nm, ++map_count, nm);