home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / XRF / XRF3.C < prev    next >
C/C++ Source or Header  |  1993-12-01  |  5KB  |  124 lines

  1. /*
  2.  *                      ***************
  3.  *                      * X R F 3 . C *
  4.  *                      ***************
  5.  *
  6.  * Sorted cross reference listing routines. 'prtree' performs an
  7.  * inorder traversal of the id tree, printing the references to'
  8.  * each id while visiting that node.
  9.  *
  10.  * Version V1.3          9-May-80
  11.  * Version V1.4        10-Jul-80 MM    Bummed code, added 80 col. support
  12.  * Version V1.5          2-Dec-84 MC    Tweak for CI86 on Msdos Rainbow
  13.  *                       7-Jan-85 MC    Remove case sensitive printing order
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include "xrf.h"
  18.  
  19. /*
  20.  * Inorder tree traversal.
  21.  */
  22.  
  23. prtree(link)
  24. struct idt *link;
  25.  
  26.    {
  27.    if (link != NULL)
  28.       {
  29.       prtree(link->left);       /* Visit the left */
  30.       prtrefs(link);            /* Print refs for this one */
  31.       prtree(link->right);      /* Visit the right */
  32.       }
  33.    }
  34.  
  35. /*
  36.  * List out a line of references.
  37.  * Start new page if it gets full.
  38.  */
  39.  
  40. lstrefs()
  41.    {
  42.    if(++linpg > MAXLIN)                 /* New page if necessary */
  43.       newpage();
  44.    fputs(scanbf, lst);                 /* Write out the string */
  45.    fputs("\n", lst);
  46.    }
  47.  
  48. /*
  49.  * Print id and references.
  50.  * Share scan buffer for printout.
  51.  * Use newpag.
  52.  *
  53.  * The ref line number field width is hard-wired into the format statement.
  54.  * Trouble is, #define's don't (and shouldn't!) substitute into strings,
  55.  * like formats.
  56.  *
  57.  * Current values are 5 char field (RSIZE) and rperline ref's per line.
  58.  *
  59.  * The node is now positioned in the tree in case non-sensitive order.
  60.  * This means that in the final list mixed, upper & lower case symbols
  61.  * appear togethor instead of being separated in the collating sequence.
  62.  *
  63.  * The id (*kp) now comes as <KEYactualNNNNNNNN> from XRF0.C where:-
  64.  *                      KEY                is the symbol as lower case
  65.  *                                                  length CPS characters.
  66.  *                               actual          is the symbol as she appears
  67.  *                                                  length CPS characters.
  68.  *                           NNNNNNNN  is the program name
  69.  *                                                  length 8 chars
  70.  *
  71.  */
  72.  
  73. prtrefs(link)
  74. struct idt *link;
  75.  
  76.    {
  77.    register struct ref *r;              /* Ref chain pointer */
  78.    register char *p,*kp;                /* Fast scan buffer pointer */
  79.    register int j;                      /* Counts refs printed on a line */
  80.    register int i = 0;                  /* work counter */
  81.    char *strcpy();                      /* cpystr returns char pointer */
  82.    char keyname[9];                     /* program name for this symbol */
  83.    r = link->first;                     /* r --> head of ref chain */
  84.    p = scanbf;                          /* p --> start of scan buffer */
  85.    j = 0;                               /* Init refs-per-line */
  86.    kp = link->keyp + CPS + CPS;        /* init pname ptr */
  87.    strcpy(keyname,kp);            /* Start with the program name */
  88.    *kp = '\0';                /* then terminate ID string */
  89.    kp = link->keyp + CPS;        /* reinit id string ptr */
  90.    if(strcmp(kp,lastsym)){              /* if symbol change ... */
  91.        strcpy(p, kp);                       /* ... then the id string */
  92.        p += strlen(kp);
  93.        strcpy(lastsym,kp);                  /* save as previous */
  94.        }
  95.    while(p < &scanbf[CPS])              /* Pad with blanks */
  96.          *p++ = ' ';
  97.    *p++ = ':';                          /* Followed by a separator */
  98.    if(conflg){                /* Followed by progname    */
  99.     for(i=0;i<8;*p++=keyname[i++]);
  100.     *p++ = ' ';                          /* Followed by a space */
  101.     }
  102.    do
  103.       {                                 /* List Reference line numbers */
  104.       if(j >= rperline){                /* If this line is full */
  105.          *p = '\0';                     /* Terminate with null */
  106.          lstrefs();                     /* Write it out */
  107.          j = 0;                         /* Reset refs-on-line count */
  108.          for(p=scanbf;p<&scanbf[CPS];*p++ =' '); /*Reset buffer ptr*/
  109.          *p++ = ':';                    /* plus a separator */
  110.          if(conflg){                /* Followed by progname    */
  111.             for(i=0;i<8;*p++=keyname[i++]);
  112.             *p++ = ' ';                          /* Followed by a space */
  113.             }
  114.          }
  115.       j++;
  116.       sprintf(p,"%5d", r->lno);         /* Insert reference into buffer */
  117.       p += RSIZE;                       /* Update buffer pointer */
  118.       r = r->next;                      /* On down the chain */
  119.       }
  120.    while(r != NULL);                    /* Until the end */
  121.    *p = '\0';                           /* Terminate with null */
  122.    lstrefs();                           /* Write the line out */
  123.    }
  124.