home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
8bitfiles.net/archives
/
archives.tar
/
archives
/
canada-remote-systems
/
cpower
/
cref.arc
/
CREF1.C
< prev
next >
Wrap
Text File
|
2019-04-13
|
4KB
|
189 lines
/* ├╥┼╞1.├ - ├ CROSS-REFERENCE UTILITY
** (1 OF 3 SOURCE FILES)
** ┴UTHOR:╩EFF ╘AYLOR, ╘HE ╘OOLSMITH
** (C) COPYRIGHT 1982, 1985.
** ┼NVIRONMENT: ├;╒╬╔╪ 4.2 ┬╙─.
** ┴LGORITHMS:
** ═ODIFIED ALGORITHM ╘ FROM
** "╘HE ┴RT OF ├OMPUTER ╨ROGRAMMING,"
** ╓OL.1,P.317,BY ─.┼.╦NUTH USED IN
** TREEWALK().
** ╚ISTORY:
** 22 ╬OVEMBER 1982 - REMOVE RECURSION
** FROM LOOKUP().
** 16 ─ECEMBER 1982 - REMOVE RECURSION
** FROM TREEWALK().
** 26 ═ARCH 1985 - PORT TO ─┼├╒╙ ├.
** 27 ═ARCH 1985 - LINE # LIST MADE A
** CIRCULAR QUEUE: INSERT(),LISTñFIL().
** RESERVED WORD SEARCH CHANGED TO
** BINARY SEARCH: KEYWORD().
** 28 ═ARCH 1985 - PORT TO ╒╬╔╪ 4.2 ┬╙─.
**
** 01 ╩ULY 1989 - PORT TO ├ ╨OWER ├,
** ├64/├128, ┬EN ╨EDERSEN.
** ├-╨OWER ┬┬╙ 416-538-7720
*/
#INCLUDE <STDIO.H>
#INCLUDE <CREF.H>
STATIC CHAR *RESERVED[]=
█"AUTO","BREAK","CASE","CHAR","CONTINUE",
"DEFAULT","DO","DOUBLE","ELSE","EXTERN",
"FLOAT","FOR","GOTO","IF","INT","LONG",
"REGISTER","RETURN","SHORT","SIZEOF",
"STATIC","STRUCT","SWITCH","TYPEDEF",
"UNION","UNSIGNED","WHILE","VOID"▌;
INT LINEñCNT;
STRUCT NODE *SYMñROOT = ╬╒╠╠;
STRUCT NODE *FILñROOT = ╬╒╠╠;
MAIN(ARGC,ARGV)
UNSIGNED ARGC;
CHAR **ARGV;
█
UNSIGNED PRNTXREF();
╞╔╠┼ FREOPEN();
IF(ARGC<2) USEAGE();
WHILE(--ARGC>0) █
IF(FREOPEN(*(++ARGV),"R",STDIN)==╬╒╠╠ ▀▀ FERROR())
FPRINTF(STDOUT,"UNABLE TO OPEN %S\N",*ARGV);
ELSE XREF(*ARGV);
▌
FCLOSE(STDIN);
TREEWALK(SYMñROOT,PRNTXREF);
/* QUICK-'N-DIRTY WAY TO DE-ALLOCATE MEMORY */
HIGHMEM(0XD000);
▌
USEAGE()
█
PRINTF("\NUSEAGE: CREF FNAME1 <FNAME2... >\N\N");
EXIT();
▌
/* KEYWORD - IS "S" A RESERVED KEYWORD
IN ├ */
UNSIGNED KEYWORD(S)
CHAR *S;
█
INT COND; /* CONDITION CODE OF LEXCMP() */
INT MID;
INT HI,LO;
/* BINARY SEARCH;RESERVED[] MUST BE IN
ALPHABETICAL ORDER */
LO=0;
HI=SIZEOF(RESERVED)/SIZEOF(CHAR*)-1;
WHILE(LO<=HI) █
MID=(HI+LO)/2;
IF((COND=LEXCMP(S,RESERVED[MID]))==0)
RETURN(╘╥╒┼);
IF(COND<0) HI=MID-1;
ELSE LO=MID+1;
▌
RETURN(╞┴╠╙┼);
▌
/* XREF - CROSS REFERENCE */
UNSIGNED XREF(FILE)
CHAR *FILE;
█
INT ATOI();
CHAR CLASS;
STATIC CHAR *S;
STATIC CHAR TOKEN[═┴╪╠╔╬┼+1];
LINEñCNT=0;
WHILE((S=NEWñLINE())!=╬╒╠╠) █
IF((CLASS=GETOKEN(&S,TOKEN))!='#') █
WHILE(CLASS!='\N') █
IF(CLASS==╔─ && KEYWORD(TOKEN)==╞┴╠╙┼)
USE(TOKEN,FILE,LINEñCNT);
CLASS=GETOKEN(&S,TOKEN);
▌
▌
ELSE IF(GETOKEN(&S,TOKEN)==╔─) █
IF(STREQ(TOKEN,"INCLUDE")) █
GETñNAME(S,TOKEN);
USE(TOKEN,FILE,LINEñCNT);
▌
ELSE IF(STREQ(TOKEN,"DEFINE")) █
GETOKEN(&S,TOKEN);
USE(TOKEN,FILE,LINEñCNT);
▌
ELSE IF(STREQ(TOKEN,"IFDEF")▀▀STREQ(TOKEN,"IFNDEF")) █
GETOKEN(&S,TOKEN);
USE(TOKEN,FILE,LINEñCNT);
▌
ELSE IF(STREQ(TOKEN,"LINE")) █
IF(GETOKEN(&S,TOKEN)==╔╬╘┼╟┼╥)
LINEñCNT=ATOI(TOKEN);
ELSE
FPRINTF(STDOUT,"#LINE %S\N",TOKEN);
▌
ELSE
; /* IGNORE #ELSE,#ENDIF,ETC. */
▌
▌
▌
/* PUTP - OUTPUT A PARTIAL LINE
TO STDOUT */
UNSIGNED PUTP(S)
CHAR *S;
█
UNSIGNED N;
FOR(N=0;*S != ┼╧╙;++N)
FPUTC(*(S++),STDOUT);
RETURN(N);
▌
/* LISTñFIL - PRINT LINES WITHIN
A FILE */
UNSIGNED LISTñFIL(FT)
STRUCT NODE *FT;
█
CHAR *ITOA();
UNSIGNED LINLEN,NAMLEN;
STRUCT INSTANCE *IT;
CHAR BUF[5];
LINLEN=PUTP(" ");
LINLEN+=PUTP(FT->NAME);
/* PRINT LINE NUMBERS */
IT=FT->P.LINES=FT->P.LINES->NEXT; /* MOVE 'LINES' TO START */
FOR(;;) █
LINLEN+=PUTP(" ");
ITOA(IT->LINE,BUF);
LINLEN+=PUTP(BUF);
IF((IT=IT->NEXT)==FT->P.LINES) BREAK;
IF(LINLEN>╫╔─╘╚-5) █ /* LEAVE A MARGIN ON RIGHT */
PUTP("\N");
NAMLEN = STRLEN(FT->NAME);
LINLEN = ++NAMLEN;
WHILE(NAMLEN--) PUTP(" ");
▌
▌
IF(LINLEN) PUTP("\N");
▌
/* PRNTXREF - DUMP CROSS REFERENCE
TABLE TO STDOUT */
UNSIGNED PRNTXREF(NT)
STRUCT NODE *NT;
█
UNSIGNED LISTñFIL();
PUTP(NT->NAME);
PUTP("\N");
TREEWALK(NT->P.FILES,LISTñFIL);
▌