home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / XRF / XRFR.C < prev   
C/C++ Source or Header  |  1993-12-01  |  7KB  |  203 lines

  1. /*
  2.  *                      ***************
  3.  *                      * X R F R . C *
  4.  *                      ***************
  5.  *
  6.  * Do initialization things & special Rainbow code (was XRFI.C).
  7.  *
  8.  * Version V1.4                  1-Jul-80
  9.  * Version V1.5                  3-Jul-80  Conditionaled date/time stuff.
  10.  * Version V1.6 MM         9-Jul-80  Changed date/time stuff
  11.  * Version V1.7 MM        10-Jul-80  File name changes
  12.  * Version V1.8 MM        21-Jul-80  Ctime() changed
  13.  * Version V1.9 MM        22-Jul-80  Redid initialization
  14.  * Version V1.11 RBD        26-Dec-80  Cleanup rt11 usage message
  15.  * Version V1.12 MM        22-Dec-81  Rtime isn't in vax library
  16.  * Version V1.13 MM        16-Feb-82  ctime fixup
  17.  * Version V1.14 MC        29-Dec-84  tailor for DEC Rainbow
  18.  *                               4-Jan-84  add spooler to PRINT Queue if
  19.  *                                         installed.
  20.  *                 8-Jan-85  Add date/time plus return name
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include "xrf.h"
  25.  
  26. /*****************************************************************/
  27. /*                  RAINBOW/MSDOS TAILORING                      */
  28. /*****************************************************************/
  29. static char ff_omode[2] = " ";
  30. static int  ff_search_code = 0x4e00;
  31. static unsigned char ff_fb[13] = "";    /*search name*/
  32. static unsigned char ff_fw[13] = "";    /*def work file name*/
  33. static unsigned char ff_fa[13] = "";    /*act work file name*/
  34. static struct ff_str { 
  35.   char dummy[21];        /* reserved for dos */ 
  36.   unsigned char attribute;    /* returned attribute */ 
  37.   unsigned time; 
  38.   unsigned date; 
  39.   long size;            /* size of file */ 
  40.   unsigned char fn[13];        /* string containing the filename */ 
  41. } ff_area; 
  42.  
  43.  
  44. /*****************************************************************/
  45. /*        Give user help on program useage.                      */
  46. /*****************************************************************/
  47.  
  48. useage()
  49.    {
  50.    printf("Usage: xrf [-options] [-o outfile] infile[s]\n\n");
  51.    printf("       -s  Spool output file to PRINT queue\n");
  52.    printf("       -n  Narrow (80 column) output else wide (132)\n");
  53.    printf("       -i  Expanded Symbols (31), else 8 chars.\n");
  54.    printf("       -p  Print C source (with linenumbers) as well.\n");
  55.    printf("       -c  Concatanate input files(s)\n");
  56.    printf("       -o  Output to \"outfile\"\n\n");
  57.    printf("Input files may have wild-card names\n");
  58.    printf("Default input filetype is \".c\"\n");
  59.    printf("Default output filename is \"<first_input_file>.REF\"\n\n");
  60.    printf("E.G. XRF -NIC -O XRF XRF* SPOOL will do a combined\n");
  61.    printf("     crossreference of XRF?????.C and SPOOL.C as XRF.REF\n\n");
  62.    abort("?XRF-E-parameter error");
  63.    }
  64.  
  65.  
  66. /*****************************************************************/
  67. /*       Initialise input file system                            */
  68. /*****************************************************************/
  69.  
  70. initinfile(in)
  71. char *in;
  72.  
  73. { FILE *ffirst();
  74.   int i;
  75.   unsigned char *cs=ff_area.fn, *cd=ff_fw, *concat();
  76.   if((src = ffirst(concat(ff_fb,in,".c",0), "r")) == NULL)
  77.      abort("Cannot open %s\n", ff_fb);
  78.   for(;*cs!='.';*cd++=*cs++);            /*save name for output*/
  79.   *cd='\0';
  80. }
  81.  
  82. /*****************************************************************/
  83. /*       Initialise output file system                           */
  84. /*****************************************************************/
  85.  
  86. initoutfile(out)
  87. char    *out;
  88.    {
  89.    unsigned char *concat();
  90.    FILE *fopen();
  91.    if (out == NULL)out=ff_fw;
  92.    if((lst = fopen(concat(ff_fa,out,".ref",0), "w")) == NULL)
  93.       abort("Cannot open output reference file %s\n", ff_fa);
  94.    }
  95.  
  96. /*****************************************************************/
  97. /*       set next input file to be processed                     */
  98. /* open file & initialize page header strings                    */
  99. /*****************************************************************/
  100.  
  101.  
  102. nextinfile()
  103. {
  104.    FILE     *ffnext();
  105.    unsigned char *cp=ff_area.fn,*concat();
  106.    unsigned char datetemp[23], timetemp[9];
  107.    int i;
  108.    if ((src=ffnext(src)) == NULL)
  109.       return(0);
  110.    for(i=0;*cp!='.'&&i<8;progname[i++]=*cp++); /* set curr name */
  111.    while(i<8)progname[i++]=' ';
  112.    progname[i]='\0';
  113.    if(verbose)printf("Processing %s ...\n",progname);
  114.    concat(pghead, "\fXRF Source Listing of: ",
  115.          ff_area.fn,"\t",thedate," ",thetime,"\tPage ", 0);
  116.  
  117.    ff_search_code=0x4f00;            /*search next*/
  118.    return(1);
  119. }
  120.  
  121. /*****************************************************************/
  122. /*          RAINBOW/MSDOS support routines                       */
  123. /*****************************************************************/
  124.  
  125. FILE *ffirst(filename,mode)
  126. unsigned char *filename;
  127. unsigned char *mode;
  128. { struct {int ax,bx,cx,dx,si,di,ds,es;}srv;
  129.   FILE *fopen();
  130.   segread(&srv.si);            /* get ds value */
  131.   srv.ax=ff_search_code=0x4e00;        /* search first*/
  132.   srv.cx=0;                /* set search modes */
  133.   srv.dx=filename;
  134.   bdos(0x1a,&ff_area);            /* set the transfer address */
  135.   strcpy(ff_omode,mode);
  136.   if(!(sysint21(&srv,&srv)&1))return fopen(ff_area.fn,mode);
  137.   return NULL;
  138.  
  139. FILE *ffnext(iop)
  140. FILE *iop;
  141. { int i;
  142.   struct {int ax,bx,cx,dx,si,di,ds,es;}srv;
  143.   FILE *freopen();
  144.   segread(&srv.si);        /* get ds value */
  145.   srv.ax=ff_search_code;
  146.   srv.cx=0;            /* set search modes */
  147.   srv.dx=ff_fb;
  148.   bdos(0x1a,&ff_area);        /* set the transfer address */
  149.   if(!(sysint21(&srv,&srv)&1))return freopen(ff_area.fn,ff_omode,iop);
  150.   return NULL;
  151.  
  152. fspool(iop)            /*trigger off spool print of output file*/
  153. FILE *iop;
  154. { fclose(iop);                /*ensure file shut */
  155.   if(spool(ff_fa))printf("ERR - Can't spool print %s\n",ff_fa);
  156.    else printf("%s queued for printing...\n",ff_fa);
  157. }
  158.  
  159. delete(filename)
  160. char *filename;
  161. { return unlink(filename);}
  162.  
  163. /* get system date & time */
  164. static char *dayofweek[] = { "Sunday","Monday","Tuesday","Wednesday",
  165.                             "Thursday","Friday","Saturday" };
  166. static char *monthname[] = { "Jan","Feb","Mar","Apr","May","Jun","Jul",
  167.                             "Aug","Sep","Oct","Nov","Dec" };
  168. date(d)            /* return date into d[23] */
  169. char *d;
  170. { struct {int ax,bx,cx,dx,si,di,ds,es;}srv;
  171.   srv.ax=0x2A00;
  172.   sysint21(&srv,&srv);
  173.   sprintf(d,"%s, %2d %s %04d",dayofweek[srv.ax&0xFF],srv.dx&0xFF,
  174.                               monthname[srv.dx>>8],srv.cx);
  175. }
  176.  
  177. time(t)                /* return time into t[9] */
  178. char *t;
  179. { struct {int ax,bx,cx,dx,si,di,ds,es;}srv;
  180.   srv.ax=0x2C00;
  181.   sysint21(&srv,&srv);
  182.   sprintf(t,"%02d:%02d:%02d",srv.cx>>8,srv.cx&0xFF,srv.dx>>8);
  183. }
  184.  
  185. /* concatanate 'n' strings to new output string*/
  186. /* concat(out,ip1,ip2...ipn,0); !last parameter MUST be 0! */
  187. /* returns pointer to output string*/
  188.  
  189. unsigned char *concat(op,ip)
  190. unsigned char *op;
  191. int *ip;
  192. { unsigned char *r=op,*cp,**cpp=&ip;
  193.  
  194.   *op='\0';
  195.   while(*cpp){
  196.     strcat(op,(cp=*cpp++));
  197.     op+=strlen(cp);
  198.     }
  199.   return r;
  200. }
  201.