home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / croutes.zip / XC.C < prev    next >
Text File  |  1984-07-29  |  22KB  |  928 lines

  1. /**********************************************************
  2.  
  3.       XC  -  A 'C' Concordance Utility
  4.  
  5.       Version 1.0   January, 1982
  6.  
  7.       Copyright (c) 1982 by Philip N. Hisley
  8.  
  9.           Philip N. Hisley
  10.           548H Jamestown Court
  11.           Edgewood, Maryland 21040
  12.           (301) 679-4606
  13.  
  14.       Released for non-commercial distribution only
  15.  
  16.  
  17.  
  18.  
  19.       Converted to IBM/PC CI/C86 by David N. Smith, May/June 1983
  20.       with enhancements and Lattice compiler support in December 1983.
  21.  
  22.           David N. Smith
  23.           44 Ole Musket Lane
  24.           Danbury, CT 06810
  25.           (203) 748-5934
  26.  
  27.       Changes Copyright (c) 1983 by David N. Smith
  28.  
  29.       PC Enhancements include:
  30.  
  31.        1)  Nested #INCLUDE statements
  32.        2)  Single spaced cross-reference list
  33.        3)  Removal of tabbing on output device
  34.            (Since many printers don't support it)
  35.        4)  #INCLUDE statements with both "--" and <-->
  36.            syntax and with a full fileid in the quotes.
  37.        5)  Multiple input filenames on command line.
  38.  
  39.  
  40.  
  41.       Abstract:
  42.  
  43.       'XC' is a cross-reference utility for 'C' programs.
  44.       Its has the ability to handle nested include files
  45.       to a depth of 8 levels and properly processes nested
  46.       comments as supported by BDS C. Option flags support
  47.       the following features:
  48.  
  49.       - Routing of list output to disk
  50.       - Cross-referencing of reserved words
  51.       - Processing of nested include files
  52.       - Generation of listing only
  53.  
  54.       Usage: xc <filename> <flag(s)>
  55.  
  56.       Flags: -i        = Enable file inclusion
  57.          -l        = Generate listing only
  58.          -r        = Cross-ref reserved words
  59.          -o <filename> = Write output to named file
  60.  
  61.  
  62. ***********************************************************/
  63.  
  64. #include "e:stdio.h"
  65.  
  66. /* Compiler specific stuff */
  67. #define Lattice
  68.  
  69. #ifdef Lattice
  70. #include "e:ctype.h"
  71. #endif
  72. /* end compiler specific section */
  73.  
  74. #ifndef  TRUE
  75. #define  TRUE         1
  76. #define  FALSE         0
  77. #endif
  78.  
  79. #define  ERROR        -1
  80. #define  MAX_REF     5        /* maximum refs per ref-block */
  81. #define  MAX_LEN    20        /* maximum identifier length  */
  82. #define  MAX_WRD   749        /* maximum number of identifiers */
  83. #define  MAX_ALPHA  53        /* maximum alpha chain heads */
  84. #define  REFS_PER_LINE    10    /* maximum refs per line */
  85. #define  LINES_PER_PAGE 60
  86. #define  MAXCOL     78        /* default maximum column number for listing line */
  87. #define  MINCOL     30        /* minimum value for -w option */
  88. #define  FF 0x0C        /* formfeed */
  89.  
  90. struct    rf_blk {
  91.          int  ref_item[MAX_REF];
  92.          int  ref_cnt;
  93.            } onerf;
  94.  
  95. struct    id_blk {
  96.          char  id_name[MAX_LEN];
  97.          struct id_blk *alpha_lnk;
  98.          struct rf_blk *top_lnk;
  99.          struct rf_blk *lst_lnk;
  100.            } oneid;
  101.  
  102. struct id_blk *id_vector[MAX_WRD];
  103.  
  104. struct alpha_hdr { struct id_blk *alpha_top;
  105.            struct id_blk *alpha_lst;
  106.          };
  107.  
  108. struct alpha_hdr alpha_vector[MAX_ALPHA];
  109.  
  110. int    linum;        /* line number */
  111. int    edtnum;     /* edit line number */
  112. int    fil_cnt;    /* active file index */
  113. int    wrd_cnt;    /* token count */
  114. int    pagno;        /* page number */
  115. int    id_cnt;     /* number of unique identifiers */
  116. int    rhsh_cnt;    /* number of conflict hits */
  117. int    filevl;     /* file level  */
  118. int    paglin;     /* page line counter */
  119. int    dummy;        /* dummy integer */
  120. int    maxcol=MAXCOL;    /* maximum right column for listing line */
  121. int    prt_ref;
  122. char    act_fil[MAX_LEN];
  123. char    lst_fil[MAX_LEN];
  124. char    gbl_fil[MAX_LEN];
  125. FILE    *f_lst_fil;
  126. int    i_flg,
  127.     o_flg,
  128.     r_flg,
  129.     l_flg;
  130.  
  131. long atoi();
  132.  
  133.  
  134. /*************************************************************************/
  135.  
  136. main(p_argc, p_argv)
  137. int    p_argc;
  138. char    **p_argv;
  139.  
  140. {
  141.     char  *arg;
  142.     int argc;
  143.     char **argv;
  144.     char c;
  145.     int i;
  146.  
  147.     argc = p_argc;
  148.     argv = p_argv;
  149.     if (argc < 2) use_err();
  150.     i_flg=r_flg=o_flg=l_flg=FALSE;
  151.     while(--argc != 0)
  152.      { if(*(arg=*++argv) == '-')
  153.     {switch(*++arg)
  154.      {
  155.        case 'i':
  156.        case 'I': i_flg++;
  157.              break;
  158.        case 'r':
  159.        case 'R': r_flg++;
  160.              break;
  161.        case 'l':
  162.        case 'L':  l_flg++;
  163.               break;
  164.        case 'o':
  165.        case 'O': { o_flg++;
  166.                if(--argc == 0) use_err();
  167.                strcpy(lst_fil,*++argv);
  168.                if(lst_fil[0] == '-') use_err();
  169.             break;}
  170.        case 'w':
  171.        case 'W': { if(--argc == 0) use_err();
  172.                i = atoi(*++argv);
  173.                if( i<=MINCOL || i>=255 ) use_err();
  174.                maxcol = i;
  175.                break;
  176.                }
  177.        default: use_err();
  178.      }
  179.        }
  180.      }
  181.  
  182.      if(o_flg)
  183.        {if( (f_lst_fil=fopen(lst_fil,"w")) == NULL)
  184.     { printf("ERROR: Unable to create list file - %s\n",lst_fil);
  185.       exit(0);}
  186.        printf("XC ... 'C' Concordance Utility  v1.0\n\n");
  187.     }
  188.  
  189.     prt_ref = FALSE;
  190.     for(linum=0;linum < MAX_WRD;linum++) {
  191.        id_vector[linum] = NULL; }
  192.     for(linum=0;linum < MAX_ALPHA;linum++)
  193.      {
  194.        alpha_vector[linum].alpha_top =
  195.        alpha_vector[linum].alpha_lst = NULL;
  196.      }
  197.     fil_cnt = wrd_cnt = linum = 0;
  198.     filevl=paglin=pagno=edtnum=0;
  199.     id_cnt=rhsh_cnt=0;
  200.  
  201.     argc = p_argc;  argc--;
  202.     argv = p_argv;
  203.     while(argc--) {
  204.        strcpy(gbl_fil,*++argv);
  205.        if(*gbl_fil == '-')  break;
  206.        proc_file(gbl_fil,dummy);
  207.        }
  208.     if(!l_flg) {
  209.       gbl_fil[0] = '\0';
  210.       prnt_tbl();
  211.       printf("\nAllowable Symbols: %d\n",MAX_WRD);
  212.       printf("Unique    Symbols: %d\n",id_cnt);}
  213.     if(o_flg) {
  214.      nl();
  215.      /* if(fprintf(f_lst_fil,"%c",CPMEOF) == ERROR) lst_err(); */
  216.      fclose(f_lst_fil);
  217.     }
  218. }
  219.  
  220. /*************************************************************************/
  221.  
  222. lst_err()
  223.  
  224. { printf("\nERROR: Write error on list output file - %s\n",
  225.    lst_fil);
  226.   exit(0);
  227. }
  228.  
  229. /*************************************************************************/
  230.  
  231. use_err()
  232.  
  233.        { printf("\nERROR: Invalid parameter specification\n\n");
  234.        printf("Usage: xc <filename>... <flag(s)>\n\n");
  235.        printf("Flags: -i            = Enable file inclusion\n");
  236.        printf("       -l            = Generate listing only\n");
  237.        printf("       -r            = Cross-reference reserved words\n");
  238.        printf("       -o <outfile>  = Write output to named file\n");
  239.        printf("       -w width      = Width of output page; default=78\n");
  240.        printf("Flags must follow all input file names");
  241.        exit(0); }
  242.  
  243. /*************************************************************************/
  244.  
  245. proc_file(filnam,incnum)
  246. char    *filnam;
  247. int     incnum;    /* prev. included line number (return to caller) */
  248.  
  249. {
  250.   char    token[MAX_LEN]; /* token buffer */
  251.   int    eof_flg;    /* end-of-file indicator */
  252.   int    tok_len;    /* token length */
  253.   FILE    *infile;    /* input file */
  254.  
  255.  
  256.   strcpy(act_fil,filnam);
  257.   edtnum=0;
  258.  
  259.   if((infile=fopen(filnam,"r")) == NULL)
  260.       {printf("\nERROR: Unable to open input file: %s\n",filnam);
  261.     return;}  /* ignore error */
  262.   if(filevl++ == 0) prt_hdr();
  263.   eof_flg = FALSE;
  264.   do {
  265.        if(get_token(infile,token,&tok_len,&eof_flg,0))
  266.       if(chk_token(token))
  267.          {
  268.          if(strcmp(token,"#include") == 0)
  269.         {
  270.         get_include_fileid(token,infile);
  271.         if(!i_flg) continue;
  272.         else
  273.            {
  274.            nl();
  275.            edtnum=proc_file(token,edtnum);
  276.            strcpy(act_fil,filnam);
  277.            continue;
  278.            }
  279.         }
  280.         put_token(token,linum);
  281.         }
  282.      } while (!eof_flg);
  283.  
  284.      filevl -= 1;
  285.      fclose(infile);
  286.  
  287.      return( incnum );
  288. }
  289.  
  290. /*************************************************************************/
  291.  
  292. get_include_fileid(token,infile)
  293. char *token;
  294. FILE *infile;
  295. {
  296.  
  297.    char c, term;
  298.  
  299.    while ( (term=getc(infile)) == ' ' )  echo(term);
  300.    echo(term);
  301.    if ( term=='<' ) term='>';   /* terminator is > or " */
  302.    if ( (term!='>') && (term!='"') )
  303.       {
  304.       printf("Error scanning #INCLUDE fileid: %c\n", term);
  305.       exit(1);
  306.       }
  307.  
  308.    do {
  309.       if ( (c = getc(infile)) != ' ')
  310.      {
  311.      *token++ = c;
  312.      echo(c);
  313.      }
  314.       else
  315.      echo(c);
  316.       }
  317.       while ( c!=term );
  318.  
  319.    *--token = '\0';
  320.  
  321. }
  322.  
  323. /*************************************************************************/
  324.  
  325. echo(c)
  326. char c;
  327. {
  328.    static int col = 11;
  329.    int i;
  330.    echochar(c);
  331.    if( c == '\n' )
  332.       col = 11;
  333.    else if( ++col > maxcol )  {
  334.       col = 11;
  335.       paglin++;
  336.       echochar('\n');
  337.       for( i=1; i<=11; i++ )  echochar(' ');
  338.       }
  339. }
  340.  
  341. echochar(c)
  342. char c;
  343. {
  344.    if(o_flg)  {
  345.       if(fprintf(f_lst_fil,"%c",c) == ERROR)  lst_err();
  346.       }
  347.    else
  348.       printf("%c",c);
  349. }
  350. /*************************************************************************/
  351.  
  352. get_token(infile,g_token,g_toklen,g_eoflg,g_flg)
  353.  
  354. FILE    *infile;
  355. char    *g_token;
  356. int    *g_toklen;
  357. int    *g_eoflg;
  358. int    g_flg;
  359.  
  360. /*
  361.     'getoken' returns the next valid identifier or
  362.     reserved word from a given file along with the
  363.     character length of the token and an end-of-file
  364.     indicator
  365. */
  366.  
  367. {
  368. int    c;
  369. char    *h_token;
  370. char    tmpchr;
  371.  
  372. h_token = g_token;
  373.  
  374. gtk:
  375. *g_toklen = 0;
  376. g_token = h_token;
  377.  
  378. /*
  379.     Scan and discard any characters until an alphabetic or
  380.     '_' (underscore) character is encountered or an end-of-file
  381.     condition occurs
  382. */
  383.  
  384. while( (!isalpha(*g_token = rdchr(infile,g_eoflg,g_flg)))
  385.   && !*g_eoflg
  386.   && *g_token != '_'
  387.   && *g_token != '0'
  388.   && *g_token != '#');
  389. if(*g_eoflg) return(FALSE);
  390. *g_toklen += 1;
  391.  
  392. /*
  393.     Scan and collect identified alpanumeric token until
  394.     a non-alphanumeric character is encountered or and
  395.     end-of-file condition occurs
  396. */
  397.  
  398. if(g_flg) tmpchr = '.';
  399.      else tmpchr = '_';
  400. while( (isalpha(c=rdchr(infile,g_eoflg,g_flg))
  401.     || isdigit(c)
  402.     || c == '_'
  403.     || c == tmpchr)
  404.      && !*g_eoflg)
  405.     {
  406.      if(*g_toklen < MAX_LEN)
  407.       { *++g_token = c;
  408.       *g_toklen += 1; }
  409.     }
  410.  
  411. /*
  412.     Check to see if a numeric hex or octal constant has
  413.     been encountered ... if so dump it and try again
  414. */
  415.  
  416.     if (*h_token == '0') goto gtk;
  417.  
  418.  
  419. /*
  420.     Tack a NULL character onto the end of the token
  421. */
  422.  
  423.  *++g_token = NULL;
  424.  
  425. /*
  426.     Screen out all #token strings except #include
  427. */
  428.  
  429. if (*h_token == '#' && strcmp(h_token,"#include")) goto gtk;
  430.  
  431.  return(TRUE);
  432. }
  433.  
  434. /*************************************************************************/
  435.  
  436.  fil_chr(infile,f_eof)
  437.    FILE *infile;
  438.    int *f_eof;
  439.    { int fc;
  440.    fc=getc(infile);
  441. /* if(fc == ERROR) {  /* omit since ERROR and EOF have save value for GETC  */
  442. /*   printf("\nERROR: Error while processing input file - %s\n",            */
  443. /*   act_fil);                                    */
  444. /*   exit(0);                                    */
  445. /*   }                                        */
  446.     if (fc == EOF) { *f_eof = TRUE;
  447.                      fc = NULL; }
  448.     return(fc);
  449. }
  450.  
  451. /*************************************************************************/
  452.  
  453. rdchr(infile,r_eoflg,rd_flg)
  454.  
  455. int    *r_eoflg;
  456. FILE    *infile;
  457. int    rd_flg;
  458.  
  459. /*
  460.     'rdchr' returns the next valid character in a file
  461.     and an end-of-file indicator. A valid character is
  462.     defined as any which does not appear in either a
  463.     commented or a quoted string ... 'rdchr' will correctly
  464.     handle comment tokens which appear within a quoted
  465.     string
  466. */
  467.  
  468. {
  469. int    c;
  470. int    q_flg;        /* double quoted string flag */
  471. int    q1_flg;     /* single quoted string flag */
  472. int    cs_flg;     /* comment start flag */
  473. int    ce_flg;     /* comment end flag */
  474. int    c_cnt;        /* comment nesting level */
  475. int    t_flg;        /* transparency flag */
  476.  
  477. q_flg = FALSE;
  478. q1_flg = FALSE;
  479. cs_flg = FALSE;
  480. ce_flg = FALSE;
  481. t_flg = FALSE;
  482. c_cnt  = 0;
  483.  
  484. rch:
  485.  
  486. /*
  487.     Fetch character from file
  488. */
  489.  
  490. c=fil_chr(infile,r_eoflg);
  491. if(*r_eoflg) return(c);   /* EOF encountered */
  492. if(c == '\n')
  493.         nl();
  494.          else
  495.         echo(c);
  496.  
  497. if(rd_flg) return(c);
  498.  
  499. if(t_flg) { t_flg = !t_flg;
  500.         goto rch;}
  501.  
  502. if(c == '\\') { t_flg = TRUE;
  503.         goto rch;}
  504. /*
  505.     If the character is not part of a quoted string
  506.     check for and process commented strings...
  507.     nested comments are handled correctly but unbalanced
  508.     comments are not ... the assumption is made that
  509.     the syntax of the program being xref'd is correct
  510. */
  511.  
  512. if (!q_flg && !q1_flg) {
  513.      if (c == '*' && c_cnt && !cs_flg) { ce_flg = TRUE;
  514.               goto rch;}
  515.      if (c == '/' && ce_flg) { c_cnt -= 1;
  516.               ce_flg = FALSE;
  517.               goto rch; }
  518.      ce_flg = FALSE;
  519.      if (c == '/') { cs_flg = TRUE;
  520.         goto rch; }
  521.      if (c == '*' && cs_flg) { c_cnt += 1;
  522.               cs_flg = FALSE;
  523.               goto rch; }
  524.      cs_flg = FALSE;
  525.      if (c_cnt) goto rch;
  526. }
  527.  
  528. /*
  529.     Check for and process quoted strings
  530. */
  531.  
  532. if ( c == '"' && !q1_flg) { q_flg =  !q_flg; /* toggle quote flag */
  533.             goto rch;}
  534. if (q_flg) goto rch;
  535.  
  536. if (c == '\'') { q1_flg = !q1_flg; /* toggle quote flag */
  537.         goto rch; }
  538. if (q1_flg) goto rch;
  539.  
  540. /*
  541.     Valid character ... return to caller
  542. */
  543.  
  544. return(c);
  545. }
  546.  
  547. /*************************************************************************/
  548.  
  549. chk_token(c_token)
  550. char    *c_token;
  551.  
  552. {
  553.   char    u_token[MAX_LEN];
  554.   int    i;
  555.  
  556.     {
  557.       if(r_flg) return(TRUE);
  558.       i = 0;
  559.       do { u_token[i] = toupper(c_token[i]); }
  560.      while (c_token[i++] != NULL);
  561.  
  562.       switch(u_token[0]) {
  563.     case 'A': if (strcmp(u_token,"AUTO") == 0) return(FALSE);
  564.           break;
  565.     case 'B': if (strcmp(u_token,"BREAK") == 0) return(FALSE);
  566.           break;
  567.     case 'C': if (strcmp(u_token,"CHAR") == 0) return (FALSE);
  568.           if (strcmp(u_token,"CONTINUE") == 0) return (FALSE);
  569.           if (strcmp(u_token,"CASE") == 0) return (FALSE);
  570.           break;
  571.     case 'D': if(strcmp(u_token,"DOUBLE") == 0) return(FALSE);
  572.           if(strcmp(u_token,"DO") == 0) return(FALSE);
  573.           if(strcmp(u_token,"DEFAULT") == 0) return(FALSE);
  574.           break;
  575.     case 'E': if(strcmp(u_token,"EXTERN") == 0) return(FALSE);
  576.           if(strcmp(u_token,"ELSE") == 0) return(FALSE);
  577.           if(strcmp(u_token,"ENTRY") == 0) return(FALSE);
  578.           break;
  579.     case 'F': if(strcmp(u_token,"FLOAT") == 0) return(FALSE);
  580.           if(strcmp(u_token,"FOR") == 0) return(FALSE);
  581.           break;
  582.     case 'G': if(strcmp(u_token,"GOTO") == 0) return(FALSE);
  583.           break;
  584.     case 'I': if(strcmp(u_token,"INT") == 0) return(FALSE);
  585.           if(strcmp(u_token,"IF") == 0) return(FALSE);
  586.           break;
  587.     case 'L': if(strcmp(u_token,"LONG") == 0) return(FALSE);
  588.           break;
  589.     case 'R': if(strcmp(u_token,"RETURN") == 0) return(FALSE);
  590.           if(strcmp(u_token,"REGISTER") == 0) return(FALSE);
  591.           break;
  592.     case 'S': if(strcmp(u_token,"STRUCT") == 0) return(FALSE);
  593.           if(strcmp(u_token,"SHORT") == 0) return(FALSE);
  594.           if(strcmp(u_token,"STATIC") == 0) return(FALSE);
  595.           if(strcmp(u_token,"SIZEOF") == 0) return(FALSE);
  596.           if(strcmp(u_token,"SWITCH") == 0) return(FALSE);
  597.           break;
  598.     case 'T': if(strcmp(u_token,"TYPEDEF") == 0) return(FALSE);
  599.           break;
  600.     case 'U': if(strcmp(u_token,"UNION") == 0) return(FALSE);
  601.           if(strcmp(u_token,"UNSIGNED") == 0) return(FALSE);
  602.           break;
  603.     case 'W': if(strcmp(u_token,"WHILE") == 0) return(FALSE);
  604.           break; }
  605.     }
  606.   return(TRUE);
  607. }
  608.  
  609. /*************************************************************************/
  610.  
  611. /*
  612.    Install parsed token and line reference in linked structure
  613. */
  614.  
  615. put_token(p_token,p_ref)
  616.  
  617. char *p_token;
  618. int  p_ref;
  619.  
  620. {
  621.   int  hsh_index;
  622.   int  i;
  623.   int  j;
  624.   int  d;
  625.   int  found;
  626.   struct id_blk *idptr;
  627.   struct rf_blk *rfptr;
  628.   struct id_blk *alloc_id();
  629.   struct rf_blk *alloc_rf();
  630.   struct rf_blk *add_rf();
  631.  
  632.   if(l_flg) return;
  633.   j=0;
  634.   for (i=0; p_token[i] != NULL; i++)  /* Hashing algorithm is far from */
  635.   {                      /* optimal but is adequate for a */
  636.       j = j * 10 + p_token[i];          /* memory-bound index vector!    */
  637.    }
  638.   hsh_index = abs(j) % MAX_WRD;
  639.   found = FALSE;
  640.   d = 1;
  641.   do {
  642.        idptr = id_vector[hsh_index];
  643.        if(idptr == NULL) {
  644.      id_cnt++;
  645.      idptr = id_vector[hsh_index] = alloc_id(p_token);
  646.      chain_alpha(idptr,p_token);
  647.      idptr->top_lnk = idptr->lst_lnk = alloc_rf(p_ref);
  648.      found = TRUE;
  649.        }
  650.        else
  651.        if(strcmp(p_token,idptr->id_name) == 0) {
  652.      idptr->lst_lnk = add_rf(idptr->lst_lnk,p_ref);
  653.        found = TRUE;
  654.      }
  655.        else
  656.        { hsh_index += d;
  657.      d += 2;
  658.      rhsh_cnt++;
  659.      if (hsh_index >= MAX_WRD)
  660.         hsh_index -= MAX_WRD;
  661.      if (d == MAX_WRD) {
  662.         printf("\nERROR: Symbol table overflow\n");
  663.         exit(0);
  664.      }
  665.        }
  666.       } while (!found);
  667. }
  668.  
  669. /*************************************************************************/
  670.  
  671. chain_alpha(ca_ptr,ca_token)
  672.  
  673. struct id_blk *ca_ptr;
  674. char  *ca_token;
  675.  
  676. {
  677.   char    c;
  678.   int    f;
  679.   struct id_blk *cur_ptr;
  680.   struct id_blk *lst_ptr;
  681.  
  682.   c = ca_token[0];
  683.   if(c == '_') c = 0;
  684.     else
  685.       if (isupper(c))  c=1+((c-'A')*2);
  686.       else           c=2+((c-'a')*2);
  687.  
  688.   if(alpha_vector[c].alpha_top == NULL)
  689.     { alpha_vector[c].alpha_top =
  690.       alpha_vector[c].alpha_lst = ca_ptr;
  691.       ca_ptr->alpha_lnk = NULL;
  692.       return;
  693.     }
  694.  
  695. /* check to see if new id_blk should be inserted between
  696.    the alpha_vector header block and the first id_blk in
  697.    the current alpha chain
  698. */
  699.  
  700.  if(strcmp(alpha_vector[c].alpha_top->id_name,ca_token) >0)
  701.   {
  702.     ca_ptr->alpha_lnk=alpha_vector[c].alpha_top;
  703.     alpha_vector[c].alpha_top=ca_ptr;
  704.     return;
  705.   }
  706.  
  707.   if(strcmp(alpha_vector[c].alpha_lst->id_name,ca_token) < 0)
  708.     { alpha_vector[c].alpha_lst->alpha_lnk = ca_ptr;
  709.       ca_ptr->alpha_lnk = NULL;
  710.       alpha_vector[c].alpha_lst=ca_ptr;
  711.       return;
  712.     }
  713.  
  714.   cur_ptr = alpha_vector[c].alpha_top;
  715.   while(strcmp(cur_ptr->id_name,ca_token) < 0)
  716.    { lst_ptr = cur_ptr;
  717.      cur_ptr = lst_ptr->alpha_lnk;
  718.    }
  719.  
  720.   lst_ptr->alpha_lnk = ca_ptr;
  721.   ca_ptr->alpha_lnk = cur_ptr;
  722.   return;
  723. }
  724.  
  725. /*************************************************************************/
  726.  
  727. struct id_blk *alloc_id(aid_token)
  728.   char    *aid_token;
  729.  
  730.   {
  731.     int  ai;
  732.     struct id_blk *aid_ptr;
  733.  
  734.      if((aid_ptr = alloc(sizeof(struct id_blk))) == 0) {
  735.        printf("\nERROR: Unable to allocate identifier block\n");
  736.        exit(0);
  737.      }
  738.      ai=0;
  739.      do {
  740.       aid_ptr->id_name[ai] = aid_token[ai];
  741.     } while (aid_token[ai++] != NULL);
  742.      return (aid_ptr);
  743. }
  744.  
  745. /*************************************************************************/
  746.  
  747. struct rf_blk *alloc_rf(arf_ref)
  748.  
  749.   int  arf_ref;
  750.  
  751.   {
  752.     int ri;
  753.     struct rf_blk *arf_ptr;
  754.  
  755.     if((arf_ptr = alloc(sizeof(struct rf_blk))) == 0) {
  756.       printf("\nERROR: Unable to allocate reference block\n");
  757.       exit(0);
  758.     }
  759.     arf_ptr->ref_item[0] = arf_ref;
  760.     arf_ptr->ref_cnt = 1;
  761.     for(ri=1;ri<MAX_REF;ri++)
  762.       arf_ptr->ref_item[ri] = NULL;
  763.     return (arf_ptr);
  764.   }
  765.  
  766. /*************************************************************************/
  767.  
  768. struct rf_blk *add_rf(adr_ptr,adr_ref)
  769.  
  770.   struct rf_blk *adr_ptr;
  771.   int adr_ref;
  772.  
  773.   {
  774.     struct rf_blk *tmp_ptr;
  775.  
  776.     tmp_ptr = adr_ptr;
  777.     if(adr_ptr->ref_cnt == MAX_REF) {
  778.       tmp_ptr = adr_ptr->ref_cnt = alloc_rf(adr_ref);
  779.     }
  780.     else
  781.     { adr_ptr->ref_item[adr_ptr->ref_cnt++] = adr_ref;
  782.     }
  783.     return (tmp_ptr);
  784.   }
  785.  
  786. /*************************************************************************/
  787.  
  788. prnt_tbl()
  789. {  int prf_cnt;
  790.    int pti;
  791.    int pref;
  792.    int lin_cnt;
  793.    struct id_blk *pid_ptr;
  794.    struct rf_blk *ptb_ptr;
  795.  
  796.   prt_ref = TRUE;
  797.   prt_hdr();
  798.   for (pti=0;pti<MAX_ALPHA;pti++)
  799.   { if ((pid_ptr = alpha_vector[pti].alpha_top) != NULL)
  800.       { do
  801.      { if(o_flg)
  802.      {if(fprintf(f_lst_fil,"%-20.19s: ",pid_ptr->id_name) == ERROR)
  803.         lst_err();}
  804.        else
  805.       printf("%-20.19s: ",pid_ptr->id_name);
  806.        ptb_ptr=pid_ptr->top_lnk;
  807.        lin_cnt=prf_cnt=0;
  808.        do { if(prf_cnt == MAX_REF)
  809.           { prf_cnt=0;
  810.         ptb_ptr = ptb_ptr->ref_cnt;
  811.           }
  812.        if(ptb_ptr > MAX_REF)
  813.         {
  814.          if((pref=ptb_ptr->ref_item[prf_cnt++]) != 0)
  815.         { if(o_flg)
  816.          {if(fprintf(f_lst_fil,"%4d ",pref) == ERROR) lst_err();}
  817.         else
  818.         printf("%4d ",pref);
  819.         if (++lin_cnt == REFS_PER_LINE)
  820.             { nl();
  821.               if(o_flg)
  822.              {if(fprintf(f_lst_fil,"                      ") == ERROR) lst_err();}
  823.               else
  824.              printf("                      ");
  825.               lin_cnt=0;
  826.             }
  827.         }
  828.           } else pref=0;
  829.        } while (pref);
  830.     nl();
  831.     } while ((pid_ptr=pid_ptr->alpha_lnk) != NULL);
  832.       }
  833.    }/*for*/
  834.  
  835.    echo( '\n' );
  836.  
  837. }
  838.  
  839. /*************************************************************************/
  840.  
  841. prt_hdr()
  842.  
  843. {
  844.   if (pagno++ != 0)    { echo( '\n' ); echo( FF ); }
  845.   if (o_flg)
  846.    {if(fprintf(f_lst_fil,
  847.       "XC ... 'C' Concordance Utility   %-20s       Page %d",
  848.      gbl_fil,pagno) == ERROR) lst_err();}
  849.   else
  850.    printf("XC ... 'C' Concordance Utility   %-20s       Page %d",
  851.      gbl_fil,pagno);
  852.   echo('\n');
  853.   paglin = 3;
  854.   nl();
  855. }
  856.  
  857. /*************************************************************************/
  858.  
  859. nl()
  860.  
  861. {
  862.   echo('\n');
  863.   if(++paglin >= LINES_PER_PAGE) prt_hdr();
  864.     else
  865.   if(!prt_ref) {
  866.     if(o_flg) {
  867.        if(fprintf(f_lst_fil,"%-4d %4d: ",    ++linum,++edtnum) == ERROR)
  868.        lst_err();
  869.        }
  870.     else
  871.        printf("%-4d %4d: ",    ++linum,++edtnum);
  872.     if(o_flg)
  873.        if(linum % 60 == 1)
  874.       printf("\n<%d> ",linum);
  875.        else {
  876.       printf(".");
  877. #if Lattice
  878.       fflush(stdout);
  879. #endif
  880.       }
  881.  
  882.     }
  883.  return;
  884. }
  885.  
  886. /*************************************************************************/
  887.  
  888. #ifndef Lattice
  889. abs(i)
  890. int i;
  891. {
  892.    if (i<0) return(-i);
  893.    else     return( i);
  894. }
  895. #endif
  896.  
  897. /*************************************************************************/
  898.  
  899. #ifdef Lattice
  900. /*    cvt ascii to int or long     */
  901.  
  902. long atoi(s)
  903. char *s;
  904. {
  905.    long n;
  906.    int sign = 0;
  907.  
  908.    while(*s==' ' || *s=='\t')  ++s;   /* move over blanks & tabs */
  909.    if (*s=='-')
  910.       sign=1;
  911.    else
  912.       if (*s!='+')  --s;
  913.    ++s;                   /* skip sign */
  914.    for( n=0; *s>='0' && *s<='9'; )
  915.       n = n * 10 + (*s++ - '0');
  916.    if (sign)   n = -n;
  917.    return n;
  918. }
  919. #endif
  920.  
  921. /*************************************************************************/
  922.  
  923. alloc(i)
  924. int i;
  925. {
  926.    return malloc(i);
  927. }
  928.