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

  1. /*
  2.  *              ***************
  3.  *              * X R F 0 . C *
  4.  *              ***************
  5.  *
  6.  * This is the mainline program for the C cross referencer and lister.
  7.  * It handles the following tasks:
  8.  *
  9.  *      - Scans the command line
  10.  *      - Opens the appropriate files
  11.  *      - Calls some initialization functions
  12.  *      - Invokes line by line processing
  13.  *      - Prints the cross-reference index
  14.  *      - Finishes up processing as appropriate
  15.  *
  16.  *
  17.  * Usage:
  18.  *
  19.  *    xrf [-s] [-n] [-o out_file] in_files
  20.  *
  21.  *    Flags:
  22.  *        -s    Spool out_file to printer QUEUE
  23.  *        -n    Narrow (80 column) output, normal is 132 column.
  24.  *        -i    Maximum size Symbols, else truncated to minimum size.
  25.  *        -p    Print C source (with linenumbers) as well.
  26.  *        -c    Concatanate C source files (treat as one).
  27.  *        -v    Verbose mode (get chatty)
  28.  *
  29.  *        -o file    Write output to the indicated file.  If -o is not
  30.  *            specified, output will be to the first in_file
  31.  *            with the filetype set to ".x"
  32.  *
  33.  * Written By:
  34.  *              Bob Denny
  35.  *              Creative System Design Co.
  36.  *              3452 E. Foothill Blvd. << Suite 601 >>
  37.  *              Pasadena, Ca.  91107
  38.  *              (213) 355-6836
  39.  * Modified for MSDOS By:
  40.  *
  41.  *        Mike Cole
  42.  *        Digital Equipment Co.
  43.  *        PC Customer Information & Support Centre,
  44.  *        Jays Close,
  45.  *        Basingstoke,
  46.  *        Hampshire  RG22 4DE,
  47.  *        ENGLAND.        (44) 256-59200
  48.  *
  49.  *
  50.  * Experimental Version         X1.0             5-May-80
  51.  * Split off initialization     X1.1             7-May-80
  52.  * Prototype.                   Y1.2             9-May-80
  53.  * Release.                     V1.3             9-May-80
  54.  * Chg. for DECUS OTS. & Cmplr. V1.4             1-Jul-80
  55.  * Add support for RT-11        V1.5             3-Jul-80
  56.  * Conditionalized spool call    V1.6 MM         9-Jul-80
  57.  * Added narrow, outfile, etc.    V1.7 MM        10-Jul-80
  58.  * Added multiple infiles    V1.8 MM        22-Jul-80
  59.  * Fspool now in the library    V1.9 MM         2-Aug-80
  60.  * Modify for CI86 under MSDOS  V1.10MC         3-Dec-84
  61.  * add Print spooler (-s opt)   V1.11MC         4-Jan-85
  62.  * add -i, -p options           V1.12MC         4-Jan-85
  63.  * add -c option                V1.13MC         8-Jan-85
  64.  * add -v option                         8-Jan-85
  65.  * allow for mixed case keys    V1.14MC        12-Jan-85
  66.  * & flag functions with '()'           12-Jan-85
  67.  *
  68.  *****************************************************************************
  69.  */
  70.  
  71. #include <stdio.h>                              /* RSX-11M Std. I/O Def's */
  72. #include "xrf.h"                                /* Global definitions */
  73.  
  74. int pageno;                                     /* Current listing page no. */
  75.  
  76.  
  77. main ( argc, argv )
  78. char *argv[];
  79.    {                                            /* Start the main prog. */
  80.    register int i;                      /* Arg count */
  81.    register int c;                      /* Switch character code */
  82.    register int f;            /* fnd -i sw */
  83.    register char *p;                    /* Fast arg pointer */
  84.    char *in_file;                       /* Source file name string */
  85.    char *out_file;            /* Cref file name string */
  86.    int splflg = 0;                      /* Spool file flag */
  87.    int nofiles;                /* Flag "got a file" */
  88.    char *klower();            /* make a max len lower case key*/
  89.    char keystr[8+NCPS+NCPS+1];        /* constructed key hold */
  90.  
  91.    fprintf(stderr, "C program Cross Referencer from DECUSC\n");
  92.  
  93.    out_file = NULL;                /* No output file yet */
  94.    lastsym[0]='\0';                             /* no prev symbol [XRF3] */
  95.    date(thedate);                /* get date & time */
  96.    time(thetime);
  97.  
  98.    for( i=1; i<argc; ++i )                      /* For each token */
  99.       {
  100.       p = argv[i];                              /* p --> i'th arg token */
  101.       if( *p++ == '-' )                         /* if it's a switch token */
  102.          {
  103.          while( c = *p++ )                      /* Each char is a switch */
  104.             switch(tolower(c))                  /* Process 'em */
  105.                {
  106.            case 'o':            /* Output file */
  107.           argv[i] = 0;
  108.           if (++i >= argc)
  109.             useage();
  110.           out_file = argv[i];
  111.           argv[i] = 0;
  112.           goto nextarg;
  113.  
  114.            case 'n':            /* Narrow output */
  115.           linewidth=80;
  116.           break;
  117.  
  118.            case 'i':            /* Large symbol size */
  119.           symbolsize=LCPS;
  120.           break;
  121.  
  122.                case 'p':                        /* Print source listing */
  123.                   prnflg++;
  124.                   break;
  125.  
  126.                case 'c':                       /* Concatanate source file(s) */
  127.                   conflg++;
  128.                   break;
  129.  
  130.                case 's':                        /* Spool listing */
  131.                   splflg++;
  132.                   break;
  133.  
  134.                case 'v':                        /* Verbose mode */
  135.                   verbose++;
  136.                   break;
  137.  
  138.                default :                        /* Bad switch, give help */
  139.                   useage();
  140.                }
  141.      argv[i] = 0;                /* Drop this one */
  142.          }
  143. nextarg:;
  144.       }                                         /* Done with cmd string */
  145.    if(conflg)                    /* Set references */
  146.       rperline=(linewidth-symbolsize-10-FFLAG)/RSIZE; /* with pname */
  147.     else
  148.       rperline=(linewidth-symbolsize-1-FFLAG)/RSIZE;  /* w/out pname */
  149.    nofiles = 1;
  150.    myfree();                                    /* Clear out storage */
  151.    root = NULL;                                 /* No tree yet */
  152.  
  153.    for( i = 1; i < argc; i++){
  154.       if ((in_file = argv[i]) == 0)continue;   /* no more filenames */
  155.       initinfile(in_file);
  156.       while (nextinfile()){
  157.          if (nofiles){
  158.         initoutfile(out_file);
  159.            nofiles = 0;
  160.        }
  161.          lineno = pageno = 0;                   /* Init. page & line number */
  162.      if(!conflg){                           /* if NO concatanation ... /*
  163.            myfree();                               /* Clear out storage */
  164.            root = NULL;                            /* No tree yet */
  165.            lastsym[0]='\0';                        /* no prev symbol [XRF3] */
  166.            }
  167.          if(prnflg)newpage();                   /* Start first page */
  168.          while(fgets(scanbf, LWIDTH, src) != NULL) /* Get a line of source */
  169.             {
  170.             ++lineno;                           /* Increment line number */
  171.             scanp = scanbf;                     /* Reset scan pointer */
  172.             while(getid()){                      /* scanp --> id or NULL */
  173.                concat(keystr,klower(idbuf),idbuf,progname,0);/*construct key*/
  174.                root = search(keystr, root);      /* Process identifier */
  175.                }                                /* Till done with this line */
  176.             if(prnflg)lstline();                /* List this line */
  177.             }                                   /* Till end of source file */
  178.          if(conflg) strcpy(scanbf, "listing: ");
  179.              else   concat(scanbf, "list of: ",progname," ",0);
  180.          concat(pghead, "\fCross Reference ",scanbf,
  181.                            "\t",thedate," ",thetime,"\tPage ", 0);
  182.          if(!conflg){                        /* process if NOT concat */
  183.              newpage();                         /* Start index on new page */
  184.              prtree(root);                      /* Print the index */
  185.              }
  186.           }
  187.       }
  188.    if(conflg){                                /* process now if concat */
  189.          newpage();                             /* Start index on new page */
  190.          prtree(root);                          /* Print the index */
  191.          }
  192.    if (nofiles)useage();
  193.       else if(splflg)fspool(lst);               /* If we're to spool, */
  194.    exit();                                      /* Exit closing files */
  195.    }                                            /***** END MAIN *****/
  196.  
  197.  
  198.  
  199. /* make a fixed length [CPS] lower case key from .. */
  200. /* ... mixed case variable length  key*/
  201. /* lose function marker */
  202. static char ktemp[NCPS+1];
  203.  
  204. char *klower(c1)
  205. char *c1;
  206. {  int i=0;
  207.    while(*c1)
  208.      if(*c1!='('&&*c1!=')')ktemp[i++]=tolower(*c1++); /* move in key as LC */
  209.       else c1++;                /* unless procid    */
  210.    while(i<CPS)ktemp[i++]=' ';            /* add trail spaces */
  211.    ktemp[i]='\0';                /* add terminator */
  212.    return ktemp;
  213. }
  214.  
  215.  
  216. /*********************************************************/
  217. /* Listing control routines. Newpage also used by prtree.*/
  218. /*********************************************************/
  219.  
  220. newpage()                                       /* Start new page */
  221.    {
  222.    ++pageno;                                    /* Increment page number */
  223.    linpg = 0;                                   /* Reset line-in-page count */
  224.    fprintf(lst,"%s%d\n\n", pghead, pageno);     /* Output page heading */
  225.    }
  226.  
  227. lstline()                                       /* Write listing line out */
  228.    {
  229.    if(++linpg > MAXLIN)
  230.       newpage();
  231.    fprintf(lst, "%4d:\t%s", lineno, scanbf);
  232.    }
  233.