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

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

/*------------------------------------------------------------------------
XRF3.C

Sorted cross reference listing routines. 'prtree' performs an
inorder traversal of the id tree, printing the references to
each id while visiting that node.

Version V1.3 9-May-80
Version V1.4 10-Jul-80 MM Bummed code, added 80 col. support
Version V1.5 2-Dec-84 MC Tweak for CI86 on Msdos Rainbow
7-Jan-85 MC Remove case sensitive printing order
Version V1.6 14-Dec-89 SMB Modify for Turbo C compatibility.
23-Dec-89 Bug fixed in lstrefs
------------------------------------------------------------------------*/
#include
#include
#include "xrf.h"

/*------------------------------------------------------------------------
Function: lstrefs

Prototype In: Local to this module.

Description: List out a line of references. Start a new page
if it gets full.

Returns: void
------------------------------------------------------------------------*/
static void lstrefs(void)
{
if (linpg >= plength) /* New page if necessary */
newpage();
fputs(scanbf, lst); /* Write out the string */
fputs("\n", lst);
linpg++;
}

/*------------------------------------------------------------------------
Function: prtrefs

Prototype In: Local to this module.

Description: Print id and references. Share scan buffer for
printout. Use newpag.

The ref line number field width is hard-wired into
the format statement. Trouble is, #define's don't
(and shouldn't!) substitute into strings, like
formats.

Current values are 5 char field (RSIZE) and rperline
ref's per line.

The node is now positioned in the tree in case
non-sensitive order. This means that in the final
list mixed, upper and lowercase symbols appear
together instead of being separated in the
collating sequence.

The id (*kp) now comes as

KEYactualNNN from XRF0.C where:

KEY is the symbol as lowercase
length CPS+FFLAG characters.

actual is the symbol as she appears
length CPS+FFLAG characters.

NNN is the program name
length 12 characters.

Returns: void
------------------------------------------------------------------------*/
static void prtrefs(struct idt *link)
{
register struct ref *r; /* Ref chain pointer */
register char *p, *kp; /* Fast scan buffer pointer */
register int j; /* Counts refs printed on a line */
register int i; /* Work counter */
char keyname[13]; /* Program name for this symbol */

r = link->first; /* r --> head of ref chain */
p = scanbf; /* p --> start of scan buffer */
j = 0; /* Init refs-per-line */
kp = link->keyp + 2 * (CPS+FFLAG); /* init pname ptr */
strcpy(keyname, kp); /* Start with the program name */
*kp = '\0'; /* then terminate ID string */
kp = link->keyp + CPS + FFLAG; /* reinit id string ptr */
if (strcmp(kp, lastsym)) { /* if symbol change ... */
strcpy(p, kp); /* ... then the id string */
p += strlen(kp);
strcpy(lastsym,kp); /* save as previous */
}
while (p < scanbf + CPS + FFLAG) /* Pad with blanks */
*p++ = ' ';
*p++ = ':'; /* Followed by a separator */
if (conflag) { /* Followed by program name */
for (i = 0; i < 12; *p++ = keyname[i++])
;
*p++ = ' '; /* Followed by a space */
}
do { /* List Reference line numbers */
if (j >= rperline) { /* If this line is full */
*p = '\0'; /* Terminate with null */
lstrefs(); /* Write it out */
j = 0; /* Reset refs-on-line count */
for (p = scanbf; p < scanbf + CPS + FFLAG; *p++ = ' ')
; /*Reset buffer ptr*/
*p++ = ':'; /* plus a separator */
if (conflag) { /* Followed by program name */
for(i = 0; i < 12; *p++ = keyname[i++]);

*p++ = ' '; /* Followed by a space */
}
}
j++;
sprintf(p, "%5d", r->lno); /* Insert reference into buffer */
p += RSIZE; /* Update buffer pointer */
r = r->next; /* On down the chain */
} while (r != NULL); /* Until the end */
*p = '\0'; /* Terminate with null */
lstrefs(); /* Write the line out */
}

/*------------------------------------------------------------------------
Function: prtree

Prototype In: xrf.h

Description: Inorder tree traverse.

Usage: prtree(struct idt *link)

Returns: void
------------------------------------------------------------------------*/
void prtree(struct idt *link)
{
if (link != NULL) {
prtree(link->left); /* Visit the left */
prtrefs(link); /* Print refs for this one */
prtree(link->right); /* Visit the right */
}
}

/* End XRF3.C */