home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource3
/
169_01
/
xc.c
< prev
next >
Wrap
Text File
|
1984-07-29
|
22KB
|
928 lines
/**********************************************************
XC - A 'C' Concordance Utility
Version 1.0 January, 1982
Copyright (c) 1982 by Philip N. Hisley
Philip N. Hisley
548H Jamestown Court
Edgewood, Maryland 21040
(301) 679-4606
Released for non-commercial distribution only
Converted to IBM/PC CI/C86 by David N. Smith, May/June 1983
with enhancements and Lattice compiler support in December 1983.
David N. Smith
44 Ole Musket Lane
Danbury, CT 06810
(203) 748-5934
Changes Copyright (c) 1983 by David N. Smith
PC Enhancements include:
1) Nested #INCLUDE statements
2) Single spaced cross-reference list
3) Removal of tabbing on output device
(Since many printers don't support it)
4) #INCLUDE statements with both "--" and <-->
syntax and with a full fileid in the quotes.
5) Multiple input filenames on command line.
Abstract:
'XC' is a cross-reference utility for 'C' programs.
Its has the ability to handle nested include files
to a depth of 8 levels and properly processes nested
comments as supported by BDS C. Option flags support
the following features:
- Routing of list output to disk
- Cross-referencing of reserved words
- Processing of nested include files
- Generation of listing only
Usage: xc <filename> <flag(s)>
Flags: -i = Enable file inclusion
-l = Generate listing only
-r = Cross-ref reserved words
-o <filename> = Write output to named file
***********************************************************/
#include "e:stdio.h"
/* Compiler specific stuff */
#define Lattice
#ifdef Lattice
#include "e:ctype.h"
#endif
/* end compiler specific section */
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#define ERROR -1
#define MAX_REF 5 /* maximum refs per ref-block */
#define MAX_LEN 20 /* maximum identifier length */
#define MAX_WRD 749 /* maximum number of identifiers */
#define MAX_ALPHA 53 /* maximum alpha chain heads */
#define REFS_PER_LINE 10 /* maximum refs per line */
#define LINES_PER_PAGE 60
#define MAXCOL 78 /* default maximum column number for listing line */
#define MINCOL 30 /* minimum value for -w option */
#define FF 0x0C /* formfeed */
struct rf_blk {
int ref_item[MAX_REF];
int ref_cnt;
} onerf;
struct id_blk {
char id_name[MAX_LEN];
struct id_blk *alpha_lnk;
struct rf_blk *top_lnk;
struct rf_blk *lst_lnk;
} oneid;
struct id_blk *id_vector[MAX_WRD];
struct alpha_hdr { struct id_blk *alpha_top;
struct id_blk *alpha_lst;
};
struct alpha_hdr alpha_vector[MAX_ALPHA];
int linum; /* line number */
int edtnum; /* edit line number */
int fil_cnt; /* active file index */
int wrd_cnt; /* token count */
int pagno; /* page number */
int id_cnt; /* number of unique identifiers */
int rhsh_cnt; /* number of conflict hits */
int filevl; /* file level */
int paglin; /* page line counter */
int dummy; /* dummy integer */
int maxcol=MAXCOL; /* maximum right column for listing line */
int prt_ref;
char act_fil[MAX_LEN];
char lst_fil[MAX_LEN];
char gbl_fil[MAX_LEN];
FILE *f_lst_fil;
int i_flg,
o_flg,
r_flg,
l_flg;
long atoi();
/*************************************************************************/
main(p_argc, p_argv)
int p_argc;
char **p_argv;
{
char *arg;
int argc;
char **argv;
char c;
int i;
argc = p_argc;
argv = p_argv;
if (argc < 2) use_err();
i_flg=r_flg=o_flg=l_flg=FALSE;
while(--argc != 0)
{ if(*(arg=*++argv) == '-')
{switch(*++arg)
{
case 'i':
case 'I': i_flg++;
break;
case 'r':
case 'R': r_flg++;
break;
case 'l':
case 'L': l_flg++;
break;
case 'o':
case 'O': { o_flg++;
if(--argc == 0) use_err();
strcpy(lst_fil,*++argv);
if(lst_fil[0] == '-') use_err();
break;}
case 'w':
case 'W': { if(--argc == 0) use_err();
i = atoi(*++argv);
if( i<=MINCOL || i>=255 ) use_err();
maxcol = i;
break;
}
default: use_err();
}
}
}
if(o_flg)
{if( (f_lst_fil=fopen(lst_fil,"w")) == NULL)
{ printf("ERROR: Unable to create list file - %s\n",lst_fil);
exit(0);}
printf("XC ... 'C' Concordance Utility v1.0\n\n");
}
prt_ref = FALSE;
for(linum=0;linum < MAX_WRD;linum++) {
id_vector[linum] = NULL; }
for(linum=0;linum < MAX_ALPHA;linum++)
{
alpha_vector[linum].alpha_top =
alpha_vector[linum].alpha_lst = NULL;
}
fil_cnt = wrd_cnt = linum = 0;
filevl=paglin=pagno=edtnum=0;
id_cnt=rhsh_cnt=0;
argc = p_argc; argc--;
argv = p_argv;
while(argc--) {
strcpy(gbl_fil,*++argv);
if(*gbl_fil == '-') break;
proc_file(gbl_fil,dummy);
}
if(!l_flg) {
gbl_fil[0] = '\0';
prnt_tbl();
printf("\nAllowable Symbols: %d\n",MAX_WRD);
printf("Unique Symbols: %d\n",id_cnt);}
if(o_flg) {
nl();
/* if(fprintf(f_lst_fil,"%c",CPMEOF) == ERROR) lst_err(); */
fclose(f_lst_fil);
}
}
/*************************************************************************/
lst_err()
{ printf("\nERROR: Write error on list output file - %s\n",
lst_fil);
exit(0);
}
/*************************************************************************/
use_err()
{ printf("\nERROR: Invalid parameter specification\n\n");
printf("Usage: xc <filename>... <flag(s)>\n\n");
printf("Flags: -i = Enable file inclusion\n");
printf(" -l = Generate listing only\n");
printf(" -r = Cross-reference reserved words\n");
printf(" -o <outfile> = Write output to named file\n");
printf(" -w width = Width of output page; default=78\n");
printf("Flags must follow all input file names");
exit(0); }
/*************************************************************************/
proc_file(filnam,incnum)
char *filnam;
int incnum; /* prev. included line number (return to caller) */
{
char token[MAX_LEN]; /* token buffer */
int eof_flg; /* end-of-file indicator */
int tok_len; /* token length */
FILE *infile; /* input file */
strcpy(act_fil,filnam);
edtnum=0;
if((infile=fopen(filnam,"r")) == NULL)
{printf("\nERROR: Unable to open input file: %s\n",filnam);
return;} /* ignore error */
if(filevl++ == 0) prt_hdr();
eof_flg = FALSE;
do {
if(get_token(infile,token,&tok_len,&eof_flg,0))
if(chk_token(token))
{
if(strcmp(token,"#include") == 0)
{
get_include_fileid(token,infile);
if(!i_flg) continue;
else
{
nl();
edtnum=proc_file(token,edtnum);
strcpy(act_fil,filnam);
continue;
}
}
put_token(token,linum);
}
} while (!eof_flg);
filevl -= 1;
fclose(infile);
return( incnum );
}
/*************************************************************************/
get_include_fileid(token,infile)
char *token;
FILE *infile;
{
char c, term;
while ( (term=getc(infile)) == ' ' ) echo(term);
echo(term);
if ( term=='<' ) term='>'; /* terminator is > or " */
if ( (term!='>') && (term!='"') )
{
printf("Error scanning #INCLUDE fileid: %c\n", term);
exit(1);
}
do {
if ( (c = getc(infile)) != ' ')
{
*token++ = c;
echo(c);
}
else
echo(c);
}
while ( c!=term );
*--token = '\0';
}
/*************************************************************************/
echo(c)
char c;
{
static int col = 11;
int i;
echochar(c);
if( c == '\n' )
col = 1