/***********************************************************/
/* */
/* XC - A 'C' Concordance Utility */
/* */
/* Version 1.0 January, 1982 */
/* */
/* Copyright (c) 1982 by Philip N. Hisley */
/* */
/* Released for non-commercial distribution only */
/* */
/* 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 */
/* */
/* ------------------------------------------------- */
/* */
/* Compiliation Instructions - BDS C V1.42 */
/* */
/* XC.C utilizes the dynamic storage allocation */
/* scheme provided by BDS C .. the option must be */
/* enabled per the instructions in BDSCIO.H */
/* */
/* The -o and the -e options are used to maximize */
/* the execution speed of XC. */
/* */
/* cc1 xc.c -o -e3560 */
/* clink xc -o -e3560 */
/* */
/* Note: The location of the externals (-e3560) */
/* is valid for version 1.0 of XC.C .. any */
/* changes to XC which increase the size of */
/* the generated code will require that */
/* -e<xxxx> be resized .. also use of a */
/* version of BDS C other than V1.42 may */
/* alter the location of the external data */
/* .. handle with care! */
/* */
/* Resizing Procedure: */
/* */
/* 1. Compile/link XC with -o option: */
/* */
/* cc1 XC.C -o */
/* clink XC -s */
/* */
/* The link map will indicate the address at */
/* which external data starts .. in the case */
/* of XC 1.0/BDS C V1.42 this becomes 3821h */
/* */
/* 2. Recompile/link XC with the -o option and */
/* the -e option using the external data */
/* address obtained from step 1. */
/* */
/* cc1 XC.C -o -e3821 */
/* clink XC -s -e3821 */
/* */
/* 3. Use of the -e option in step 2 will cause */
/* the size of the generated code to become */
/* smaller .. recompile/link adjusting the */
/* external data address to just above the */
/* end of the code. */
/* */
/* cc1 XC.C -o -e3560 */
/* clink XC -s -e3560 */
/* */
/* ------------------------------------------------- */
/* */
/* Please report bugs/fixes/enhancements to: */
/* */
/* Philip N. Hisley */
/* 548H Jamestown Court */
/* Edgewood, Maryland 21040 */
/* (301) 679-4606 */
/* Net Addr: PNH@MIT-AI */
/* */
/* */
/***********************************************************/
#include "bdscio.h"
#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 8 /* maximum refs per line */
#define LINES_PER_PAGE 60
#define FF 0x0C /* formfeed */
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 prt_ref;
char act_fil[MAX_LEN];
char lst_fil[MAX_LEN];
char gbl_fil[MAX_LEN];
char l_buffer[BUFSIZ];
int i_flg,o_flg,r_flg,l_flg;
char *g_buffer;
char *g_token;
int *g_toklen;
int *g_eoflg;
int g_flg;
/*
'getoken' returns the next valid identifier or
reserved word from a given file along with the
character length of the token and an end-of-file
indicator
*/
{
int c;
char *h_token;
char tmpchr;
h_token = g_token;
gtk:
*g_toklen = 0;
g_token = h_token;
/*
Scan and discard any characters until an alphabetic or
'_' (underscore) character is encountered or an end-of-file
condition occurs
*/
/*
Check to see if a numeric hex or octal constant has
been encountered ... if so dump it and try again
*/
if (*h_token == '0') goto gtk;
/*
Tack a NULL character onto the end of the token
*/
*++g_token = NULL;
/*
Screen out all #token strings except #include
*/
if (*h_token == '#' && strcmp(h_token,"#include")) goto gtk;
return(TRUE);
}
fil_chr(f_buffer,f_eof)
char *f_buffer;
int *f_eof;
{ int fc;
fc=getc(f_buffer);
if(fc == ERROR) {
printf("\nERROR: Error while processing input file - %s\n",
act_fil);
exit(0);
}
if (fc == CPMEOF || fc == EOF) { *f_eof = TRUE;
fc = NULL; }
return(fc);}
rdchr(r_buffer,r_eoflg,rd_flg)
int *r_eoflg;
char *r_buffer;
int rd_flg;
/*
'rdchr' returns the next valid character in a file
and an end-of-file indicator. A valid character is
defined as any which does not appear in either a
commented or a quoted string ... 'rdchr' will correctly
handle comment tokens which appear within a quoted
string
*/
{
int c;
int q_flg; /* double quoted string flag */
int q1_flg; /* single quoted string flag */
int cs_flg; /* comment start flag */
int ce_flg; /* comment end flag */
int c_cnt; /* comment nesting level */
int t_flg; /* transparency flag */
if(c == '\\') { t_flg = TRUE;
goto rch;}
/*
If the character is not part of a quoted string
check for and process commented strings...
nested comments are handled correctly but unbalanced
comments are not ... the assumption is made that
the syntax of the program being xref'd is correct
*/