fixup commit for tag 'oct-1'

This commit is contained in:
cvs2hg
1994-12-06 09:12:22 +00:00
parent 7393f8923c
commit dc2a339e09
8241 changed files with 0 additions and 694108 deletions

View File

@@ -1,12 +0,0 @@
GCIPM.c
proto.make
cclash.1
cclash.c
cid.1
cid.c
mkdep.1
mkdep.c
prid.1
prid.c
tabgen.1
tabgen.c

View File

@@ -1,250 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/*** Generic C Identifier Processing Module ***/
/* IMPORT CheckId(char *, int), DoOption(char *), BeginOfProgram(), and
EndOfProgram().
*/
#include <stdio.h>
extern CheckId();
extern DoOption();
extern BeginOfProgram(), EndOfProgram();
#define MAX_ID_LEN 256
char *ProgName;
int GCcopy;
main(argc, argv)
char *argv[];
{
char **nargv;
int nargc = 0;
FILE *fp;
ProgName = *argv++;
nargv = argv;
BeginOfProgram();
while (--argc > 0) {
if ((*argv)[0] == '-') {
DoOption(*argv++);
}
else {
nargv[nargc++] = *argv++;
}
}
if (nargc > 0) {
while (nargc-- > 0) {
if ((fp = fopen(*nargv, "r")) == NULL) {
fprintf(stderr, "%s: cannot read file \"%s\"\n",
ProgName, *nargv);
}
else {
DoFile(fp);
}
nargv++;
}
}
else {
DoFile(stdin);
}
EndOfProgram();
exit(0);
}
DoFile(fp)
FILE *fp;
{
register c;
while ((c = getc(fp)) != EOF) {
switch (c) {
case '"':
case '\'':
if (GCcopy) putchar(c);
SkipString(fp, c);
break;
case '/':
if (GCcopy) putchar(c);
if ((c = getc(fp)) == '*') {
if (GCcopy) putchar(c);
SkipComment(fp);
}
else {
ungetc(c, fp);
}
break;
default:
if (StartId(c)) {
DoIdent(fp, c);
}
else if (StartNum(c)) {
if (GCcopy) putchar(c);
DoNum(fp, c);
}
else if (GCcopy) putchar(c);
break;
}
}
fclose(fp);
}
SkipString(fp, stopc)
FILE *fp;
{
register c;
while ((c = getc(fp)) != EOF) {
if (GCcopy) putchar(c);
if (c == stopc) {
return;
}
if (c == '\\') {
c = getc(fp);
if (GCcopy) putchar(c);
}
}
}
SkipComment(fp)
FILE *fp;
{
register c;
while ((c = getc(fp)) != EOF) {
if (GCcopy) putchar(c);
if (c == '*') {
if ((c = getc(fp)) == '/') {
if (GCcopy) putchar(c);
return;
}
ungetc(c, fp);
}
}
}
DoIdent(fp, s)
FILE *fp;
{
char id_buf[MAX_ID_LEN];
register cnt = 1;
register c;
id_buf[0] = s;
while ((c = getc(fp)) != EOF) {
if (InId(c)) {
id_buf[cnt++] = c;
}
else {
ungetc(c, fp);
id_buf[cnt] = '\0';
CheckId(id_buf, cnt);
return;
}
}
}
StartId(c)
{
switch (c) {
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y':
case 'z':
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'I': case 'J':
case 'K': case 'L': case 'M': case 'N': case 'O':
case 'P': case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X': case 'Y':
case 'Z':
case '_':
return 1;
default:
return 0;
}
}
InId(c)
{
switch (c) {
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y':
case 'z':
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'I': case 'J':
case 'K': case 'L': case 'M': case 'N': case 'O':
case 'P': case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X': case 'Y':
case 'Z':
case '_':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
return 1;
default:
return 0;
}
}
StartNum(c)
{
switch(c) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
return 1;
}
return 0;
}
#define inrange(c, l, u) ((unsigned)((c) - (l)) <= ((u) - (l)))
#define isdec(c) inrange(c, '0', '9')
#define isoct(c) inrange(c, '0', '7')
#define ishex(c) (isdec(c) || inrange(c, 'a', 'f') || inrange(c, 'A', 'F'))
#define getdec(c, fp) do { c = getc((fp)); if (GCcopy) putchar(c);} while (isdec(c))
#define getoct(c, fp) do { c = getc((fp)); if (GCcopy) putchar(c);} while (isoct(c))
#define gethex(c, fp) do { c = getc((fp)); if (GCcopy) putchar(c);} while (ishex(c))
DoNum(fp, c)
register FILE *fp;
{
if (c != '0') {
getdec(c, fp);
if (c == '.')
getdec(c, fp);
if (c == 'e') {
c = getc(fp);
if (c == '+' || c == '-')
c = getc(fp);
if (isdec(c))
getdec(c, fp);
}
}
else {
c = getc(fp);
if (GCcopy) putchar(c);
if (c == 'x' || c == 'X')
gethex(c, fp);
else
if (isoct(c))
getoct(c, fp);
}
}

View File

@@ -1,52 +0,0 @@
EM = ../..
EMBIN = $(EM)/bin
EMMAN = $(EM)/man
CFLAGS = -O
LDFLAGS =
all: mkdep cid cclash prid tabgen
install: all
rm -f $(EMBIN)/mkdep $(EMBIN)/cid $(EMBIN)/cclash $(EMBIN)/prid \
$(EMBIN)/tabgen
cp mkdep cid cclash prid tabgen $(EMBIN)
rm -f $(EMMAN)/mkdep.1 $(EMMAN)/cid.1 $(EMMAN)/cclash.1 \
$(EMMAN)/prid.1 $(EMMAN)/tabgen.1
cp mkdep.1 cid.1 cclash.1 prid.1 tabgen.1 $(EMMAN)
cmp: all
-cmp mkdep $(EMBIN)/mkdep
-cmp cid $(EMBIN)/cid
-cmp cclash $(EMBIN)/cclash
-cmp prid $(EMBIN)/prid
-cmp tabgen $(EMBIN)/tabgen
-cmp mkdep.1 $(EMMAN)/mkdep.1
-cmp cid.1 $(EMMAN)/cid.1
-cmp cclash.1 $(EMMAN)/cclash.1
-cmp prid.1 $(EMMAN)/prid.1
-cmp tabgen.1 $(EMMAN)/tabgen.1
clean:
rm -f *.o mkdep cid cclash prid tabgen
pr:
@pr `pwd`/Makefile `pwd`/mkdep.c `pwd`/cclash.c `pwd`/cid.c \
`pwd`/prid.c `pwd`/GCIPM.c `pwd`/tabgen.c
opr:
make pr | opr
mkdep: mkdep.o
$(CC) $(LDFLAGS) -o mkdep mkdep.o
tabgen: tabgen.o
$(CC) $(LDFLAGS) -o tabgen tabgen.o
cid: cid.o GCIPM.o
$(CC) $(LDFLAGS) -o cid cid.o GCIPM.o
cclash: cclash.o GCIPM.o
$(CC) $(LDFLAGS) -o cclash cclash.o GCIPM.o
prid: prid.o GCIPM.o
$(CC) $(LDFLAGS) -o prid prid.o GCIPM.o

View File

@@ -1,26 +0,0 @@
.TH CCLASH 1 "$Revision$"
.ad
.SH NAME
cclash \- report clashing identifiers in C-programs
.SH SYNOPSIS
.B cclash
[ -l<length> ] [ -c | -m ]
[ file ... ]
.SH DESCRIPTION
.I Cclash
prints all identifiers that don't differ in the first <length> characters.
The default value for <length> is 8.
.PP
The
.B -m
option indicates that #define's must be generated for clashing identifiers.
This is of course only useful if your preprocessor can distinguish between
them.
.PP
The
.B -c
option indicates that a oldname=newname line must be generated for each
clashing identifier. This is useful input for
.IR cid (1).
.SH "SEE ALSO"
cid(1)

View File

@@ -1,304 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/*
cclash: find clashing names within C programs
Flags:
-c : produce oldname=newname line for each clashing id
(useful input for cid)
-l<num> : check identifiers of <num> or more characters
(default <num> = 8)
-m : output a #define for each clashing id
Author: Erik Baalbergen
Date: Nov 8, 1985
Revised: Dec 10, 1985
C keywords are not listed
Revised: Aug 27, 1986
Skip C numeric constants
Revised: Wed Jul 23 13:27:16 MDT 1986
by Ceriel Jacobs,
replaced "stoi" by "atoi"
Revised: Tue Nov 11 13:32:31 MET 1986
by Ceriel Jacobs,
to produce lists for "cid" or preprocessor in
alphabetical order.
*/
#include <stdio.h>
#define DEF_LENGTH 8
struct idf {
struct idf *id_next;
char *id_name;
struct idf *id_same;
char id_key;
};
#define ACT_LISTONLY 0
#define ACT_MAPFILE 1
#define ACT_CID 2
int maxlen = DEF_LENGTH;
int action = ACT_LISTONLY;
extern char *ProgName;
char * keywords[] = {
"asm",
"auto",
"break",
"case",
"char",
"continue",
"default",
"do",
"double",
"else",
"entry",
"extern",
"float",
"for",
"fortran",
"goto",
"if",
"int",
"long",
"register",
"return",
"short",
"sizeof",
"static",
"struct",
"switch",
"typedef",
"union",
"unsigned",
"while",
0
};
struct idf *maplist = 0;
DefineKeys()
{
register char **pkey = &keywords[0];
register char *id;
while (id = *pkey++)
if (strlen(id) >= maxlen)
InsertId(id, 1);
}
DoOption(str)
char *str;
{
switch (str[1]) {
case 'c':
action = ACT_CID;
break;
case 'l':
if ((maxlen = atoi(&str[2])) <= 0) {
fprintf(stderr, "%s: option \"-l%s\" ignored\n",
ProgName, &str[2]);
maxlen = DEF_LENGTH;
}
break;
case 'm':
action = ACT_MAPFILE;
break;
default:
fprintf(stderr, "%s: bad option \"%s\"\n", ProgName, str);
break;
}
}
#define HASHSIZE 257
struct idf *hash_tab[HASHSIZE];
char *Malloc(), *Salloc();
InsertId(id, key)
char *id;
{
int hash_val = EnHash(id);
register struct idf *idp = hash_tab[hash_val];
register struct idf *p = 0;
while (idp && strncmp(idp->id_name, id, maxlen)) {
p = idp;
idp = idp->id_next;
}
if (idp == 0) {
idp = (struct idf *) Malloc(sizeof(struct idf));
idp->id_next = 0;
if (!p) hash_tab[hash_val] = idp;
else p->id_next = idp;
idp->id_name = Salloc(id);
idp->id_same = 0;
}
p = idp;
while (p && strcmp(p->id_name, id)) {
idp = p;
p = p->id_same;
}
if (p == 0) {
p = (struct idf *) Malloc(sizeof(struct idf));
p->id_next = 0;
p->id_same = 0;
p->id_name = Salloc(id);
idp->id_same = p;
}
p->id_key = key;
}
char *
Malloc(n)
unsigned n;
{
char *mem, *malloc();
if ((mem = malloc(n)) == 0) {
fprintf(stderr, "%s: out of memory\n", ProgName);
exit(1);
}
return mem;
}
char *
Salloc(str)
char *str;
{
char *strcpy();
if (str == 0)
str = "";
return strcpy(Malloc((unsigned)strlen(str) + 1), str);
}
EnHash(id)
char *id;
{
register unsigned hash_val = 0;
register n = maxlen;
while (n-- && *id)
hash_val = 31 * hash_val + *id++;
return hash_val % (unsigned) HASHSIZE;
}
BeginOfProgram() { DefineKeys(); }
EndOfProgram()
{
register int i;
register struct idf *idp, *p;
for (i = 0; i < HASHSIZE; i++) {
for (idp = hash_tab[i]; idp; idp = idp->id_next) {
if (idp->id_same == 0)
continue;
switch (action) {
register n;
case ACT_LISTONLY:
n = 0;
if (idp->id_key == 0) {
printf(idp->id_name);
n++;
}
for (p = idp->id_same; p; p = p->id_same)
if (p->id_key == 0) {
printf("%s%s",
n ? " " : "",
p->id_name
);
n++;
}
if (n)
printf("\n");
break;
case ACT_CID:
case ACT_MAPFILE:
for (p = idp->id_same; p;) {
register struct idf *q = p->id_same;
if (p->id_key == 0)
saveline(p);
p = q;
}
if (idp->id_key == 0)
saveline(idp);
break;
}
}
}
switch(action) {
case ACT_CID:
case ACT_MAPFILE:
for (idp = maplist; idp; idp = idp->id_same) {
mapline(idp->id_name);
}
}
}
saveline(p)
register struct idf *p;
{
register struct idf *idp = maplist, *idp1 = 0;
while (idp && strcmp(idp->id_name, p->id_name) < 0) {
idp1 = idp;
idp = idp->id_same;
}
p->id_same = idp;
if (idp1 == 0) {
maplist = p;
}
else {
idp1->id_same = p;
}
}
mapline(nm)
char *nm;
{
static map_count = 0;
switch (action) {
case ACT_MAPFILE:
printf("#define %s _%d_%s\n", nm, ++map_count, nm);
break;
case ACT_CID:
printf("%s=_%d_%s\n", nm, ++map_count, nm);
break;
}
}
CheckId(id, s)
char *id;
{
if (s >= maxlen)
InsertId(id, 0);
}

View File

@@ -1,34 +0,0 @@
.TH CID 1 "$Revision$"
.ad
.SH NAME
cid \- change identifiers not occurring in C comment, strings and
character constants.
.SH SYNOPSIS
.B cid
[options] [file ..]
.SH DESCRIPTION
.I Cid
copies the files, or standard input if no files are specified, to
standard output replacing the specified identifiers
by some text, defined by the caller in an option or on a file.
.br
.I Options
is a list of one or more of the following options:
.IP \fB\-D\fP\fIname\fP=\fItext\fP
.br
replace each occurence of \fIname\fP by \fItext\fP.
.I Text
may be empty, in which case the identifier is deleted.
.IP \fB\-D\fP\fIname\fP
.br
Delete all occurences of \fIname\fP.
.IP \fB\-F\fP\fIfile\fP
.br
Read substitute commands of the form "\fIname\fP=\fItext\fP", each on
a single line, from file \fIfile\fP.
.SH SEE ALSO
prid(1), cclash(1)
.SH DIAGNOSTICS
Supposed to be self explanatory.
.SH BUGS
The syntax of the substitute definitions is not (well) checked.

View File

@@ -1,207 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* Change IDentifiers occurring in C programs outside comment, strings
and character constants.
-Dname=text : replace all occerences of name by text
-Dname : same as -Dname=
-Ffile : read sentences of the from name=text from file
Author: Erik Baalbergen
Date: Oct 23, 1985
*/
#include <stdio.h>
#ifndef DEF_LENGTH
#define DEF_LENGTH 8
#endif
#define LINE_LEN 1024
#define HASHSIZE 257
struct idf {
struct idf *id_next;
char *id_name;
char *id_text;
};
struct idf *hash_tab[HASHSIZE];
char *Malloc(), *Salloc();
struct idf *FindId();
extern char *ProgName;
DoOption(str)
char *str;
{
switch (str[1]) {
case 'D':
DoMacro(&str[2]);
break;
case 'F':
GetMacros(&str[2]);
break;
default:
fprintf(stderr, "%s: bad option \"%s\"\n", ProgName, str);
break;
}
}
/*ARGSUSED*/
CheckId(id, len)
char *id;
{
struct idf *idp = FindId(id);
if (idp) {
printf("%s", idp->id_text);
}
else {
printf("%s", id);
}
}
DoMacro(str)
char *str;
{
char *id, *text;
id = str++;
while (*str != '\0' && *str != '=') {
str++;
}
if (*str == '=') {
*str++ = '\0';
text = str;
}
else {
text = "";
}
InsertMacro(id, text);
}
GetMacros(fn)
char *fn;
{
FILE *fp;
register c;
char buf[LINE_LEN];
char *bufp = &buf[0];
if ((fp = fopen(fn, "r")) == NULL) {
fprintf(stderr, "%s: cannot read file \"%s\"\n", ProgName, fn);
return;
}
while ((c = getc(fp)) != EOF) {
if (c == '\n' && bufp != &buf[0]) {
*bufp = '\0';
DoMacro(&buf[0]);
bufp = &buf[0];
}
else {
*bufp++ = c;
}
}
fclose(fp);
}
InsertMacro(id, text)
char *id, *text;
{
int hash_val = EnHash(id);
struct idf *idp = hash_tab[hash_val];
while (idp) {
if (strcmp(idp->id_name, id) == 0) {
fprintf(stderr, "%s: (warning) redefinition of %s\n",
ProgName, id);
break;
}
idp = idp->id_next;
}
if (idp == 0) {
idp = (struct idf *) Malloc(sizeof(struct idf));
}
idp->id_next = hash_tab[hash_val];
idp->id_name = Salloc(id);
idp->id_text = Salloc(text);
hash_tab[hash_val] = idp;
}
char *
Malloc(n)
unsigned n;
{
char *mem, *malloc();
if ((mem = malloc(n)) == 0) {
fprintf(stderr, "%s: out of memory\n", ProgName);
exit(1);
}
return mem;
}
char *
Salloc(str)
char *str;
{
char *strcpy();
if (str == 0) {
str = "";
}
return strcpy(Malloc((unsigned)strlen(str) + 1), str);
}
struct idf *
FindId(id)
char *id;
{
register hash_val = EnHash(id);
register struct idf *idp = hash_tab[hash_val];
while (idp) {
if (strcmp(idp->id_name, id) == 0) {
return idp;
}
idp = idp->id_next;
}
return 0;
}
EnHash(id)
char *id;
{
register unsigned hash_val = 0;
while (*id) {
hash_val = 31 * hash_val + *id++;
}
return hash_val % (unsigned) HASHSIZE;
}
extern int GCcopy;
BeginOfProgram()
{
GCcopy = 1;
}
EndOfProgram()
{
}

View File

@@ -1,29 +0,0 @@
.TH MKDEP 1 "$Revision$"
.ad
.SH NAME
mkdep \- dependency generator for C-programs
.SH SYNOPSYS
.B mkdep
[ -d ] file ...
.SH DESCRIPTION
.I Mkdep
scans the files in the argument list for C-preprocessor lines of the form
.nf
#include "\fIfile1\fP"
.fi
and produces for each file \fIarg\fR in the argument list lines of the form
.nf
\fIarg\fR: \fIfile1\fR
\fIarg\fR: \fIfile2\fR
...
.fi
where \fIfile1\fR, \fIfile2\fR, etc. are filenames included by \fIarg\fR, or
by a file included by \fIarg\fR, etc.
.PP
The \fB-d\fP suppresses the \fIarg\fR: part.
.PP
Only files in the current directory are scanned.
.SH "SEE ALSO"
make(1)
.SH BUGS
Should be able to handle files from other directories

View File

@@ -1,201 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* make dependencies; Date: jan 07, 1986; Author: Erik Baalbergen */
/* Log:
[Thu Oct 6 09:56:30 MET 1988; erikb]
Added option '-d' which suppresses "file.c :" be printed
*/
#include <stdio.h>
#define BSIZ 1024
char *prog;
int dflag = 0; /* suppress "file.c :" */
struct namelist {
struct namelist *next;
char *name;
};
struct namelist *freelist;
struct namelist *new_namelist();
struct namelist *nl = 0;
char *Malloc(u)
unsigned u;
{
char *sp, *malloc();
if ((sp = malloc(u)) == 0) {
fprintf(stderr, "%s: out of space\n");
exit(1);
}
return sp;
}
struct namelist *
new_namelist()
{
register struct namelist *nlp = freelist;
if (nlp) {
freelist = nlp->next;
return nlp;
}
return (struct namelist *) Malloc(sizeof(struct namelist));
}
free_namelist(nlp)
struct namelist *nlp;
{
if (nlp) {
free_namelist(nlp->next);
nlp->next = freelist;
freelist = nlp;
}
}
add_name(nm)
char *nm;
{
struct namelist *nlp = nl, *lnlp = 0, *nnlp;
char *strcpy();
while (nlp) {
register i = strcmp(nm, nlp->name);
if (i < 0)
break;
if (i == 0) /* already present */
return;
lnlp = nlp;
nlp = nlp->next;
}
(nnlp = new_namelist())->name = strcpy(Malloc((unsigned)strlen(nm) + 1), nm);
if (lnlp) {
nnlp->next = lnlp->next;
lnlp->next = nnlp;
}
else {
nnlp->next = nl;
nl = nnlp;
}
}
print_namelist(nm, nlp)
char *nm;
struct namelist *nlp;
{
while (nlp) {
if (!dflag)
printf("%s: ", nm);
printf("%s\n", nlp->name);
nlp = nlp->next;
}
}
/*ARGSUSED*/
main(argc, argv)
char *argv[];
{
int err = 0;
prog = *argv++;
if (*argv && **argv == '-') {
char *opt = &(*argv++)[1];
if (*opt++ != 'd' || *opt) {
fprintf(stderr, "use: %s [-d] [file ...]\n", prog);
exit(1);
}
dflag = 1;
}
while (*argv) {
free_namelist(nl);
nl = 0;
if (dofile(*argv) == 0)
++err;
print_namelist(*argv++, nl);
}
exit(err ? 1 : 0);
}
int
contains_slash(s)
register char *s;
{
while (*s)
if (*s++ == '/') return 1;
return 0;
}
extern char *fgets();
dofile(fn)
char *fn;
{
char buf[BSIZ];
FILE *fp;
char *nm, *include_line();
if ((fp = fopen(fn, "r")) == 0) {
fprintf(stderr, "%s: cannot read %s\n", prog, fn);
return 0;
}
if (contains_slash(fn)) {
fprintf(stderr, "%s: (warning) %s not in current directory; not checked\n", prog, fn);
fclose(fp);
return 1;
}
while (fgets(buf, BSIZ, fp) != NULL)
if (nm = include_line(buf)) {
add_name(nm);
if (dofile(nm)) ;
}
fclose(fp);
return 1;
}
char *
include_line(s)
char *s;
{
while ((*s == '\t') || (*s == ' '))
s++;
if (*s++ == '#') {
while ((*s == '\t') || (*s == ' '))
s++;
if (
(*s++ == 'i') &&
(*s++ == 'n') &&
(*s++ == 'c') &&
(*s++ == 'l') &&
(*s++ == 'u') &&
(*s++ == 'd') &&
(*s++ == 'e')
) {
while ((*s == '\t') || (*s == ' '))
s++;
if (*s++ == '"') {
char *nm = s;
while (*s != 0 && *s != '"')
s++;
*s = '\0';
return nm;
}
}
}
return (char *) 0;
}

View File

@@ -1,13 +0,0 @@
.TH PRID 1 "$Revision$"
.ad
.SH NAME
prid \- print identifiers in C-programs longer than a certain length
.SH SYNOPSIS
.B prid
[ -l<length> ] [ file ... ]
.SH DESCRIPTION
.I Prid
prints all identifiers with length >= <length>.
The default value for <length> is 8.
.SH "SEE ALSO"
cclash(1), cid(1)

View File

@@ -1,134 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* Print IDentifiers occurring in C programs outside comment, strings
and character constants.
Flags:
-l<num> : print identifiers of <num> or more characters
(default <num> = 8)
Author: Erik Baalbergen
Date: Oct 23, 1985
*/
#include <stdio.h>
extern char *ProgName;
#ifndef DEF_LENGTH
#define DEF_LENGTH 8
#endif
int maxlen = DEF_LENGTH;
BeginOfProgram() {}
DoOption(str)
char *str;
{
switch (str[1]) {
case 'l':
if ((maxlen = atoi(&str[2])) <= 0) {
fprintf(stderr, "%s: option \"-l%s\" ignored\n",
ProgName, &str[2]);
maxlen = DEF_LENGTH;
}
break;
default:
fprintf(stderr, "%s: bad option \"%s\"\n", ProgName, str);
break;
}
}
CheckId(id, len)
char *id;
{
if (len >= maxlen) {
InsertId(id);
}
}
#define HASHSIZE 257
struct idf {
char *id_name;
struct idf *id_next;
};
struct idf *hash_tab[HASHSIZE];
char *Malloc(), *Salloc();
InsertId(id)
char *id;
{
int hash_val = EnHash(id);
register struct idf *idp = hash_tab[hash_val];
register struct idf *p = 0;
while (idp && strcmp(idp->id_name, id)) {
p = idp;
idp = idp->id_next;
}
if (idp == 0) {
idp = (struct idf *) Malloc(sizeof(struct idf));
idp->id_next = 0;
if (!p) hash_tab[hash_val] = idp;
else p->id_next = idp;
idp->id_name = Salloc(id);
}
}
char *
Malloc(n)
unsigned n;
{
char *mem, *malloc();
if ((mem = malloc(n)) == 0) {
fprintf(stderr, "%s: out of memory\n", ProgName);
exit(1);
}
return mem;
}
char *
Salloc(str)
char *str;
{
char *strcpy();
if (str == 0)
str = "";
return strcpy(Malloc((unsigned)strlen(str) + 1), str);
}
EnHash(id)
char *id;
{
register unsigned hash_val = 0;
register n = maxlen;
while (n-- && *id)
hash_val = 31 * hash_val + *id++;
return hash_val % (unsigned) HASHSIZE;
}
EndOfProgram()
{
register struct idf *idp;
register int i;
for (i = 0; i < HASHSIZE; i++) {
for (idp = hash_tab[i]; idp; idp = idp->id_next) {
printf("%s\n", idp->id_name);
}
}
}

View File

@@ -1,69 +0,0 @@
# $Id$
#PARAMS do not remove this line!
SRC_DIR = $(SRC_HOME)/util/cmisc
TARGET_BIN = $(TARGET_HOME)/bin
CFLAGS = $(COPTIONS)
LDFLAGS = $(LDOPTIONS)
LINTFLAGS = $(LINTOPTIONS)
all: cid cclash prid tabgen
install: all
cp cid cclash prid tabgen $(TARGET_BIN)
if [ $(DO_MACHINE_INDEP) = y ] ; \
then mk_manpage $(SRC_DIR)/cid.1 $(TARGET_HOME) ; \
mk_manpage $(SRC_DIR)/cclash.1 $(TARGET_HOME) ; \
mk_manpage $(SRC_DIR)/prid.1 $(TARGET_HOME) ; \
mk_manpage $(SRC_DIR)/tabgen.1 $(TARGET_HOME) ; \
fi
cmp: all
-cmp cid $(TARGET_BIN)/cid
-cmp cclash $(TARGET_BIN)/cclash
-cmp prid $(TARGET_BIN)/prid
-cmp tabgen $(TARGET_BIN)/tabgen
clean:
rm -f *.$(SUF) cid cclash prid tabgen
pr:
@pr $(SRC_DIR)/proto.make $(SRC_DIR)/cclash.c $(SRC_DIR)/cid.c \
$(SRC_DIR)/prid.c $(SRC_DIR)/GCIPM.c $(SRC_DIR)/tabgen.c
opr:
make pr | opr
tabgen: tabgen.$(SUF)
$(CC) $(LDFLAGS) -o tabgen tabgen.$(SUF)
cid: cid.$(SUF) GCIPM.$(SUF)
$(CC) $(LDFLAGS) -o cid cid.$(SUF) GCIPM.$(SUF)
cclash: cclash.$(SUF) GCIPM.$(SUF)
$(CC) $(LDFLAGS) -o cclash cclash.$(SUF) GCIPM.$(SUF)
prid: prid.$(SUF) GCIPM.$(SUF)
$(CC) $(LDFLAGS) -o prid prid.$(SUF) GCIPM.$(SUF)
lint:
$(LINT) $(LINTFLAGS) $(SRC_DIR)/cid.c $(SRC_DIR)/GCIPM.c
$(LINT) $(LINTFLAGS) $(SRC_DIR)/prid.c $(SRC_DIR)/GCIPM.c
$(LINT) $(LINTFLAGS) $(SRC_DIR)/cclash.c $(SRC_DIR)/GCIPM.c
$(LINT) $(LINTFLAGS) $(SRC_DIR)/tabgen.c
tabgen.$(SUF): $(SRC_DIR)/tabgen.c
$(CC) -c $(CFLAGS) $(SRC_DIR)/tabgen.c
cid.$(SUF): $(SRC_DIR)/cid.c
$(CC) -c $(CFLAGS) $(SRC_DIR)/cid.c
prid.$(SUF): $(SRC_DIR)/prid.c
$(CC) -c $(CFLAGS) $(SRC_DIR)/prid.c
cclash.$(SUF): $(SRC_DIR)/cclash.c
$(CC) -c $(CFLAGS) $(SRC_DIR)/cclash.c
GCIPM.$(SUF): $(SRC_DIR)/GCIPM.c
$(CC) -c $(CFLAGS) $(SRC_DIR)/GCIPM.c

View File

@@ -1,110 +0,0 @@
.TH TABGEN 1 "$Revision$"
.ad
.SH NAME
tabgen \- table generator for C-programs
.SH SYNOPSYS
.B tabgen
\fIarguments\fP
.SH DESCRIPTION
.I Tabgen
is a handy tool for generating tables for C-programs from a compact
description. The current version is only suitable for generating character
tables. The output is produced on standard output.
It works by maintaining an internal table of values, printing this table
when this is requested.
.PP
Each argument given to
.I tabgen
is either a command or a description. Descriptions are discussed first.
.PP
A description consists of a value (a string), directly followed by a semicolon,
directly followed by a list of indices for which the table to be generated
has this value. This list of indices must be in a certain \fBinputformat\fP,
characterized by a charactet.
Currently, there is only one inputformat, "c". In this format, the indices
are characters. There are two special characters: '\e' and '-'. The '\e'
behaves like in a C-string, and the '-' describes a range, unless
it starts the list of indices.
.PP
Some examples of descriptions:
.nf
STIDF:a-zA-Z_
STSKIP:\er \et\e013\ef
.fi
.PP
These descriptions have the effect that the internal table values for
'a' through 'z', 'A' through 'Z', and '_' are set to STIDF, and that the
internal table values for carriage-return, space, tab, vertical-tab, and
form-feed are set to STSKIP.
.PP
A command is introduced by a special character. On the command line,
a command is introduced by a '-'. The following commands are
recognized:
.IP I\fIchar\fP
switch to a different input format. This command is only there for future
extensions.
.IP f\fIfile\fP
read input from the file \fIfile\fP. In a file, each line is an argument
to \fItabgen\fP. Each line is either a command or a description. In a file,
commands are introduced by a '%'.
.IP F\fIformat\fP
Values are printed in a printf format. The default value for this format
is \fB"%s,\en"\fP. This can be changed with this command.
.IP T\fItext\fP
Print \fItext\fP literally at this point.
.IP p
Print the table as it is built at this point.
.IP C
Clear the table. This sets all internal table values to 0.
.IP i\fIstr\fP
Initialize all internal table values to \fIstr\fP. if \fIstr\fP is not
given, this command is equivalent to the C command.
.IP S\fInum\fP
Set the table size to \fInum\fP entries. The default size is 128.
.SH "AN EXAMPLE"
.PP
The next example is a part of the \fItabgen\fP description of the
character tables used by the lexical analyser of the ACK Modula-2 compiler.
This description resides in a file called char.tab.
.I
Tabgen
is called as follows:
.nf
tabgen -fchar.tab > char.c
.fi
.PP
The description as given here generates 2 tables: one indicating a class
according to which token a character can be a start of, and one indicating
whether a character may occur in an identifier.
.nf
% Comments are introduced with space or tab after the %
%S129
%F %s,
% CHARACTER CLASSES
%iSTGARB
STSKIP: \et\e013\e014\e015
STNL:\e012
STSIMP:-#&()*+,/;=[]^{|}~
STCOMP:.:<>
STIDF:a-zA-Z
STSTR:"'
STNUM:0-9
STEOI:\e200
%T#include "class.h"
% class.h contains #defines for STSKIP, STNL, ...
%Tchar tkclass[] = {
%p
%T};
% INIDF
%C
1:a-zA-Z0-9
%Tchar inidf[] = {
%F %s,
%p
%T};
.fi
.SH BUGS
.PP
.I Tabgen
assumes that characters are 8 bits wide.