home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 169_01 / cc.c < prev    next >
Text File  |  1984-12-26  |  6KB  |  203 lines

  1. /*
  2.  
  3.         compile flow generator v1.0 for computer innovations c86
  4.  
  5.         by Bob Lafleur and Tom Vaughan of Farm Credit Banks of Springfield
  6.  
  7.         Comments are welcome! Contact:
  8.  
  9.                 Bob Lafleur
  10.                 45 Ionia Street
  11.                 Springfield, MA  01109
  12.                 (413) 737-8503
  13.                 CompuServe: 75146,3122
  14.  
  15.         ===============================================================
  16.  
  17.         This program will accept a command line containing compiler switch(es)
  18.         and program name(s) and execute the four passes of the ci c86 compiler.
  19.         A list of files containing errors will appear at the end after all
  20.         programs have been compiled.
  21.  
  22.         Note that this program uses the ANSI sequences to turn the bold
  23.         attribute on and off - if you're not using the ANSI driver, it is
  24.         a simple matter to remove them.
  25.  
  26.         I keep my compiler in "c\exe", if yours is somewhere else, you'll
  27.         have to change the constants below.
  28.  
  29.         ===============================================================
  30.  
  31.         If you come up with any additional enhancements/features for this,
  32.         please let me know!
  33.  
  34. */
  35.  
  36.  
  37.  
  38.  
  39.  
  40. #include <stdio.h>
  41.  
  42. #define         NODEBUG 1
  43.  
  44. main (argc, argv)
  45.  
  46. int     argc;
  47. char   *argv[];
  48.  
  49. {
  50.     static char cc[4][80] =
  51.     {
  52.         {
  53.             "CC1 -i "   /* -i (long identifiers) is standard! */
  54.         },
  55.         {
  56.             "CC2 "
  57.         },
  58.         {
  59.             "CC3 "
  60.         },
  61.         {
  62.             "CC4 "
  63.         }
  64.     };
  65.     char errlst[30][80];
  66.     int errcnt = 0;
  67.     static char *ccprg[] =
  68.     {
  69.         "C:\\EXE\\CC1.EXE",     /* where the compiler is on disk */
  70.         "C:\\EXE\\CC2.EXE",
  71.         "C:\\EXE\\CC3.EXE",
  72.         "C:\\EXE\\CC4.EXE"
  73.     };
  74.  
  75.     char    fnam[30];
  76.     int     phase;              /* current phase number */
  77.     int     cnt;
  78.     struct
  79.     {
  80.         unsigned int    ax,
  81.                         bx,
  82.                         cx,
  83.                         dx,
  84.                         si,
  85.                         di,
  86.                         ds,
  87.                         es;     /* register struct */
  88.     }       srv;
  89.     struct
  90.     {                           /* param block structure */
  91.         int     env_seg;
  92.         char   *line_off,
  93.                *line_seg;
  94.         char   *fcb1_off,
  95.                *fcb1_seg;
  96.         char   *fcb2_off,
  97.                *fcb2_seg;
  98.     }       ctrl;
  99.  
  100.     unsigned char   cline[128]; /* command line */
  101.     int     status;             /* status return variable */
  102.     int     argcnt;
  103.     extern  FILE * stdout;
  104.  
  105. #ifdef DEBUG
  106.     printf ("CCSML in DEBUG mode with %d arguments\n", argc);
  107. #endif
  108.  
  109.  
  110.     if (argc < 2)
  111.     {
  112.         printf ("cc - ci c86 compile flow generator v1.0\n\n");
  113.         printf ("Usage: cc [-pa] [-pa]... [filename] [filename]...\n");
  114.         printf ("   p        - pass number (1, 2, 3, or 4)\n");
  115.         printf ("   a        - argument for pass p\n");
  116.         printf ("   filename - name of file(s) to compile\n");
  117.     }
  118.     else
  119.     {                           /* ONLY if given FILENAME */
  120.         for (argcnt = 1; argcnt < argc; argcnt++)
  121.         {
  122.             if (argv[argcnt][0] == '-')
  123.             {
  124.                 int     cl;
  125.                 sscanf (&argv[argcnt][1], "%d", &cl);
  126.                 cl--;
  127. #ifdef DEBUG
  128.                 printf ("Arg %d is %s\n", argcnt, argv[argcnt]);
  129. #endif
  130.                 strcat (cc[cl], "-");
  131.                 strcat (cc[cl], &argv[argcnt][2]);
  132.                 strcat (cc[cl], " ");
  133. #ifdef DEBUG
  134.                 printf ("cc line %d is now %s\n", cl + 1, cc[cl]);
  135. #endif
  136.             }
  137.         }
  138.         for (argcnt = 1; argcnt < argc; argcnt++)
  139.         {
  140.             if (argv[argcnt]00] != '-')
  141.             {
  142.                 sscanf (argv[argcnt], "%s", fnam);
  143.  
  144.         /* edit the following line if you're not using the ANSI driver!!! */
  145.  
  146.                 fprintf (stdout, "\033[1m...compiling %s\033[0m\n", fnam);
  147.  
  148.                 status = 0;     /* setup status */
  149.                 for (phase = 0; phase < 4 && status == 0; phase++)
  150.                 {
  151.                 /*
  152.                  *-- CREATE command line from FILENAME and COMMAND OPTIONS
  153.                  */
  154.                     cline[0] = strlen (fnam) + strlen (cc[phase]);
  155.                     cline[1] = 0;
  156.                     strcat (cline, cc[phase]);
  157.                     strcat (cline, fnam);
  158.                     strcat (cline, "\r");
  159.                 /*
  160.                  *-- INSERT into the PARAM block
  161.                  */
  162.                     segread (&srv.si);/* get segment address */
  163.                     ctrl.env_seg = 0;/* NO environment */
  164.                     ctrl.line_off = cline;/* setup command line */
  165.                     ctrl.line_seg = srv.ds;/* segment for this */
  166.  
  167. #ifdef DEBUG
  168.                     {
  169.                         char    temp[128];
  170.                         printf ("Command line length = %u\n", cline[0]);
  171.                         strncpy (temp, &cline[1], cline[0]-1);
  172.                         temp[cline[0]] = 0;
  173.                         printf ("Command line: %s\n", temp);
  174.                         printf ("Filename: %s\n", ccprg[phase]);
  175.                     }
  176. #endif
  177.  
  178.  
  179.                     status = loadexec (ccprg[phase], srv.ds, &ctrl, srv.ds, 0);
  180.                     if (status == 0)/* check REAL status */
  181.                         status = bdos (0x4d);
  182. #ifdef DEBUG
  183.                     printf ("LOADEXEC status: %d\n", status);
  184. #endif
  185.                     if (status) /* there was a compile error */
  186.                      {
  187.                        sprintf(errlst[errcnt++], "%s", fnam);
  188.                        printf("\n");
  189.                      }
  190.                 }
  191.             }
  192.         }
  193.       if (errcnt)  /* there was a compile error */
  194.          {
  195.             printf("\n\033[1mThere were errors in the file%s:\n", (errcnt != 1) ? "s" : "");
  196.             for (cnt = 0; cnt < errcnt; cnt++)
  197.                printf("%s\n", errlst[cnt]);
  198.             printf("\033[0m"); /* remove this if you're not using the ANSI driver */
  199.          }
  200.     }
  201. }
  202. /* END */
  203.