Category : C Source Code
Archive   : CXRF.ZIP
Filename : XRFI.C

 
Output of file : XRFI.C contained in archive : CXRF.ZIP

/*------------------------------------------------------------------------
XRFI.C

Version V1.4 1-Jul-80
Version V1.5 3-Jul-80 Conditionaled date/time stuff.
Version V1.6 MM 9-Jul-80 Changed date/time stuff
Version V1.7 MM 10-Jul-80 File name changes
Version V1.8 MM 21-Jul-80 Ctime() changed
Version V1.9 MM 22-Jul-80 Redid initialization
Version V1.11 RBD 26-Dec-80 Cleanup rt11 usage message
Version V1.12 MM 22-Dec-81 Rtime isn't in vax library
Version V1.13 MM 16-Feb-82 ctime fixup
Version V1.14 MC 29-Dec-84 tailor for DEC Rainbow
4-Jan-84 add spooler to PRINT Queue if
installed.
8-Jan-85 Add date/time plus return name
Version V1.15 SMB 10-Dec-89 Rainbow code removed.
concat fixed for ANSI compatibility.
other functions fixed for Turbo C
compatibility.
13-Dec-89 Add fatal to handle errors.
15-Dec-89 Add nextinfile and nextoutfile.
------------------------------------------------------------------------*/
#include
#include
#include
#include
#include
#include "xrf.h"

static struct ffblk ff_blk; /* Search file structure */
static struct path path_in; /* Input search pathname structure */
static struct path path_out; /* Output search pathname structure */
static char ff_in [MAXPATH]; /* Full input pathname */
static char ff_out [MAXPATH]; /* Full output pathname */

/*------------------------------------------------------------------------
Function: useage

Prototype In: xrf.h

Description: Give user help on program usage.

Returns: void
------------------------------------------------------------------------*/
void useage(char *n)
{
fnsplit(n, path_in.drive, path_in.dir, path_in.name, path_in.ext);
printf("Syntax : %s [-options] infile[.ext] infile[.ext] ...\n\n",
path_in.name);
printf("Options: -s Write source (with linenumbers)\n");
printf(" -lxxx Set output page length to xxx lines\n");
printf(" -wxxx Set output page width to xxx columns\n");
printf(" -txx Expand tabs to xx spaces\n");
printf(" -f Ignore all form feeds in input file\n");
printf(" -c[fn] Concatanate file(s) and write to file \"fn\"\n\n");
printf("Wildcards may be used. The default input filetype is \".c\".\n");
printf("The default output filename is \".REF\".\n\n");
printf("Examples:\n");
printf(" %s -W80 -S THIS THAT\n", path_in.name);
printf(" will produce separate .REF files of THIS.C and THAT.C\n");
printf(" with printed C source in 80-column format.\n");
printf(" %s -CTHIS THIS* THAT\n", path_in.name);
printf(" will produce a combined cross reference file of\n");
printf(" THIS????.C and THAT.C as THIS.REF\n\n");
fatal("%s parameter error", path_in.name);
}

/*------------------------------------------------------------------------
Function: nextinfile

Prototype In: xrf.h

Description: Find and open next input file.
If parameter *in is not NULL than this function
searches for the FIRST file match; otherwise search is
dependent on information in the ff_blk structure.

Returns: TRUE if file was found, FALSE if otherwise.
------------------------------------------------------------------------*/
BOOL nextinfile(char *in)
{
int i;

if (in) {
/* Split up input filename pattern */
fnsplit(in, path_in.drive, path_in.dir, path_in.name, path_in.ext);
/* Build full filename with default extension */
if (path_in.ext[0] == '\0') /* Provide default extension */
concat(ff_in, path_in.drive, path_in.dir, path_in.name, ".c", NULL);
else /* Use specified extension */
concat(ff_in, path_in.drive, path_in.dir, path_in.name, path_in.ext, NULL);
/* Find first matching filename */
if (findfirst(ff_in, &ff_blk, 0) != 0)
fatal("Cannot find %s\n", strupr(ff_in));
/* Now build entire pathname and open file */
concat(ff_in, path_in.drive, path_in.dir, ff_blk.ff_name, NULL);
if ((src = fopen(ff_in, "r")) == NULL)
fatal("Cannot open %s\n", strupr(ff_in));
}
else {
/* Find next matching filename */
if (findnext(&ff_blk) != 0)
return (FALSE); /* No more filename matches */
/* Build entire pathname and open file */
concat(ff_in, path_in.drive, path_in.dir, ff_blk.ff_name, NULL);
if ((src = freopen(ff_in, "r", src)) == NULL)
fatal("Cannot open %s\n", strupr(ff_in));
}
printf("Processing: %s ...\n", strupr(ff_in));
/* Build program name string (filename + extension) for printout */
for (i = 0; ff_blk.ff_name[i]; progname[i] = ff_blk.ff_name[i++])
;
while (i < 12)
progname[i++] = ' ';
progname[i] = '\0';
concat(pghead, "\fXRF Source Listing: ", strupr(progname),
"\t", thedate, " ", thetime, "\tPage ", NULL);
return (TRUE);
}

/*------------------------------------------------------------------------
Function: nextoutfile

Prototype In: xrf.h

Description: Initialize output file. If no output filename is given
(NULL) then the input filename is used with a .REF
extension.

Returns: Pointer to new output file string.
------------------------------------------------------------------------*/
char *nextoutfile(char *out)
{
if (out == NULL)
out = ff_blk.ff_name;
fnsplit(out, path_out.drive, path_out.dir, path_out.name, path_out.ext);
/* Build output filename for current directory */
concat(ff_out, path_out.name, ".ref", NULL);
if ((lst = fopen(ff_out, "w")) == NULL)
fatal("Cannot open output file %s\n", strupr(ff_out));
return ff_out;
}

/*------------------------------------------------------------------------
Function: date

Prototype In: xrf.h

Description: Writes current system date into parameter string.

Usage: date(d)

Returns: void
------------------------------------------------------------------------*/
void date(char *d)
{
char *dayofweek[] = { "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday","Friday", "Saturday" };
char *monthname[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
union REGS regs;

regs.h.ah = 0x2a;
intdos(®s, ®s);
sprintf(d, "%s %2d %s %04d", dayofweek[regs.h.al], regs.h.dl,
monthname[regs.h.dh - 1], regs.x.cx);
}

/*------------------------------------------------------------------------
Function: time

Prototype In: xrf.h

Description: Writes current system time into paramter string.

Usage: time(t)

Returns: void
------------------------------------------------------------------------*/
void time(char *t)
{
union REGS regs;

regs.h.ah = 0x2c;
intdos(®s, ®s);
sprintf(t, "%02d:%02d:%02d", regs.h.ch, regs.h.cl, regs.h.dh);
}

/*------------------------------------------------------------------------
Function: concat

Prototype In: xrf.h

Description: Concatate 'n' strings to new output string.
Last parameter MUST be NULL!

Usage: concat(out, ip1, ip2, ... ipn, NULL)

Returns: Pointer to output string.
------------------------------------------------------------------------*/
unsigned char *concat(unsigned char *op, unsigned char *ip1, ...)
{
unsigned char *r = op, *cp = ip1;
va_list argp;

va_start(argp, ip1);
*op = '\0';
while (cp) {
strcat(op, cp);
op += strlen(cp);
cp = va_arg(argp, unsigned char *);
}
va_end(argp);
return r;
}

/*------------------------------------------------------------------------
Function: fatal

Prototype In: xrf.h

Description: Print error message and terminate.

Usage: fatal(char *msg)

Returns: void
------------------------------------------------------------------------*/
void fatal(char *format, ...)
{
va_list argp;

fprintf(stderr, "ERROR: ");
va_start(argp, format);
vfprintf(stderr, format, argp);
fprintf(stderr, "\n");
va_end(argp);
myfree();
exit(1);
}

/* End XRFI.C */