Adapted to use of GCIPM.

This commit is contained in:
ceriel 1986-11-11 13:44:13 +00:00
parent 3bc3818955
commit fb16148641

View file

@ -1,5 +1,3 @@
/* @cc % $LIBDIR/stoi.o -o cid@ */
/* Change IDentifiers occurring in C programs outside comment, strings
and character constants.
-Dname=text : replace all occerences of name by text
@ -10,206 +8,8 @@
Date: Oct 23, 1985
*/
/*** Generic C Identifier Processing Module ***/
/* IMPORT CheckId(char *) and DoOption(char *, int)
*/
#include <stdio.h>
extern CheckId();
extern DoOption();
#define MAX_ID_LEN 256
char *ProgName;
main(argc, argv)
char *argv[];
{
char **nargv;
int nargc = 0;
FILE *fp;
ProgName = *argv++;
nargv = argv;
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);
}
return 0;
}
DoFile(fp)
FILE *fp;
{
register c;
while ((c = getc(fp)) != EOF) {
switch (c) {
case '"':
case '\'':
SkipString(fp, c);
break;
case '/':
if ((c = getc(fp)) == '*') {
SkipComment(fp);
}
else {
putchar('/');
ungetc(c, fp);
}
break;
default:
if (StartId(c)) {
DoIdent(fp, c);
}
else
putchar(c);
break;
}
}
fclose(fp);
}
SkipString(fp, stopc)
FILE *fp;
{
register c;
putchar(stopc);
while ((c = getc(fp)) != EOF) {
if (c == stopc) {
putchar(stopc);
return;
}
if (c == '\\') {
putchar(c);
c = getc(fp);
}
putchar(c);
}
}
SkipComment(fp)
FILE *fp;
{
register c;
putchar('/');
putchar('*');
while ((c = getc(fp)) != EOF) {
if (c == '*') {
putchar('*');
if ((c = getc(fp)) == '/') {
putchar('/');
return;
}
ungetc(c, fp);
}
else
putchar(c);
}
}
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;
}
}
/*** end of GCIPM ***/
#ifndef DEF_LENGTH
#define DEF_LENGTH 8
#endif
@ -229,6 +29,8 @@ struct idf *hash_tab[HASHSIZE];
char *Malloc(), *Salloc();
struct idf *FindId();
extern char *ProgName;
DoOption(str)
char *str;
{
@ -386,3 +188,14 @@ EnHash(id)
return hash_val % (unsigned) HASHSIZE;
}
extern int GCcopy;
BeginOfProgram()
{
GCcopy = 1;
}
EndOfProgram()
{
}