home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-3 / STRIPC.CQ / STRIPC.C
Text File  |  2000-06-30  |  2KB  |  72 lines

  1. /*
  2.     STRIPC.C
  3.     Written by Leor Zolman, 3/82
  4.  
  5.     This program takes an assembly language source file as input,
  6.     and writes out the same file stripped of comments. Everything between
  7.     a semicolon and the end of the line is stripped, plus the tabs
  8.     before the semicolon.
  9.     If a line contains an odd number of single quote (') characters before
  10.     the first semicolon, then the line is left intact.
  11. */
  12.  
  13. #include "bdscio.h"
  14. char ibuf[BUFSIZ], obuf[BUFSIZ];
  15.  
  16. main(argc,argv)
  17. char **argv;
  18. {
  19.     char iname[30], oname[30];
  20.     char linbuf[200];
  21.  
  22.     int i,j,k;
  23.  
  24.     if (argc != 3) exit(puts("usage: stripc <infile> <outfile>\n"));
  25.     if (!strcmp(argv[1],argv[2])) exit(puts("Names must be distinct\n"));
  26.  
  27.     strcpy(iname,argv[1]);
  28.     strcpy(oname,argv[2]);
  29.  
  30.     strcat(iname,".ASM");
  31.     strcat(oname,".ASM");
  32.  
  33.     if (fopen(iname,ibuf) == ERROR)
  34.         exit(puts("\7Can't open input file\n"));
  35.  
  36.     if (fcreat(oname,obuf) == ERROR)
  37.         exit(puts("\7Can't create output file\n"));
  38.  
  39.     while (fgets(linbuf,ibuf)) {
  40.         if ((i = index(linbuf,";")) != ERROR)
  41.         {
  42.            if (!i)
  43.            {
  44.             *linbuf = '\0';
  45.            }
  46.            else
  47.            {
  48.             if (index(linbuf,"'") < i)
  49.             {
  50.                 k = 0;    /* quote count */
  51.                 for (j = 0; j < i; j++)
  52.                     if (linbuf[j] == '\'')
  53.                         k++;
  54.                 if (k & 1) goto lineout;
  55.             }
  56.             while (i && isspace(linbuf[i-1]))
  57.                 i--;
  58.             linbuf[i++] = '\n';
  59.             linbuf[i] = '\0';
  60.            }
  61.         }
  62.   lineout:    if (fputs(linbuf,obuf) == ERROR)
  63.             exit(puts("\7Error writing output file"));
  64.         putchar('.');
  65.     }
  66.     putc(CPMEOF,obuf);
  67.     fflush(obuf);
  68.     fclose(obuf);
  69.     fclose(ibuf);
  70.     puts("All done.\n");
  71. }
  72.