1 /* $Id: prid.c,v 1.5 1994/06/24 10:16:45 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 /* Print IDentifiers occurring in C programs outside comment, strings
7 and character constants.
9 -l<num> : print identifiers of <num> or more characters
12 Author: Erik Baalbergen
18 extern char *ProgName;
24 int maxlen = DEF_LENGTH;
34 if ((maxlen = atoi(&str[2])) <= 0) {
35 fprintf(stderr, "%s: option \"-l%s\" ignored\n",
42 fprintf(stderr, "%s: bad option \"%s\"\n", ProgName, str);
62 struct idf *hash_tab[HASHSIZE];
64 char *Malloc(), *Salloc();
69 int hash_val = EnHash(id);
70 register struct idf *idp = hash_tab[hash_val];
71 register struct idf *p = 0;
73 while (idp && strcmp(idp->id_name, id)) {
79 idp = (struct idf *) Malloc(sizeof(struct idf));
81 if (!p) hash_tab[hash_val] = idp;
82 else p->id_next = idp;
83 idp->id_name = Salloc(id);
93 if ((mem = malloc(n)) == 0) {
94 fprintf(stderr, "%s: out of memory\n", ProgName);
109 return strcpy(Malloc((unsigned)strlen(str) + 1), str);
115 register unsigned hash_val = 0;
119 hash_val = 31 * hash_val + *id++;
121 return hash_val % (unsigned) HASHSIZE;
126 register struct idf *idp;
129 for (i = 0; i < HASHSIZE; i++) {
130 for (idp = hash_tab[i]; idp; idp = idp->id_next) {
131 printf("%s\n", idp->id_name);