1 /* $Id: cid.c,v 0.6 1994/06/24 10:16:39 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".
6 /* Change IDentifiers occurring in C programs outside comment, strings
7 and character constants.
8 -Dname=text : replace all occerences of name by text
9 -Dname : same as -Dname=
10 -Ffile : read sentences of the from name=text from file
12 Author: Erik Baalbergen
32 struct idf *hash_tab[HASHSIZE];
34 char *Malloc(), *Salloc();
37 extern char *ProgName;
53 fprintf(stderr, "%s: bad option \"%s\"\n", ProgName, str);
62 struct idf *idp = FindId(id);
65 printf("%s", idp->id_text);
79 while (*str != '\0' && *str != '=') {
91 InsertMacro(id, text);
100 char *bufp = &buf[0];
102 if ((fp = fopen(fn, "r")) == NULL) {
103 fprintf(stderr, "%s: cannot read file \"%s\"\n", ProgName, fn);
107 while ((c = getc(fp)) != EOF) {
108 if (c == '\n' && bufp != &buf[0]) {
120 InsertMacro(id, text)
123 int hash_val = EnHash(id);
124 struct idf *idp = hash_tab[hash_val];
127 if (strcmp(idp->id_name, id) == 0) {
128 fprintf(stderr, "%s: (warning) redefinition of %s\n",
136 idp = (struct idf *) Malloc(sizeof(struct idf));
139 idp->id_next = hash_tab[hash_val];
140 idp->id_name = Salloc(id);
141 idp->id_text = Salloc(text);
142 hash_tab[hash_val] = idp;
149 char *mem, *malloc();
151 if ((mem = malloc(n)) == 0) {
152 fprintf(stderr, "%s: out of memory\n", ProgName);
167 return strcpy(Malloc((unsigned)strlen(str) + 1), str);
174 register hash_val = EnHash(id);
175 register struct idf *idp = hash_tab[hash_val];
178 if (strcmp(idp->id_name, id) == 0) {
189 register unsigned hash_val = 0;
192 hash_val = 31 * hash_val + *id++;
195 return hash_val % (unsigned) HASHSIZE;