home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l200 / 6.ddi / TOOL / BASUPD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-09-02  |  3.5 KB  |  171 lines

  1. /* basupd.c -- BASTOC update program
  2.  
  3.     Copyright (c) 1984 by JMI Software Consultants, Inc.
  4. */
  5. #include "upd.h"
  6. GLOBAL TEXT xeq[64] = {0};
  7.  
  8. INT main(argc, argv)
  9.     INT argc;
  10.     TEXT **argv;
  11.     {
  12.     IMPORT BITS errors;
  13.     IMPORT BOOL work_mode[];
  14.     INT mode;
  15.  
  16.     if (valid(argc, argv))
  17.         for (mode = 0; mode < NMODE; ++mode)
  18.             if (work_mode[mode])
  19.                 {
  20.                 if (!errors)
  21.                     compile(argc, argv, mode);
  22.                 if (!errors)
  23.                     archive(argc, argv, mode);
  24.                 if (!errors)
  25.                     linkedit(mode);
  26.                 }
  27.     return (errors);
  28.     }
  29.  
  30. /* Validate command - returns YES if all files on command line
  31.     exist and all required libraries also exist. Prints error
  32.     messages when files can not be found.
  33. */
  34. BOOL valid(ac, av)
  35.     INT ac;
  36.     TEXT **av;
  37.     {
  38.     IMPORT TEXT *upd_modes[], *tran_files[], *lib_files[];
  39.     IMPORT TEXT *tran_libs[], *lib_libs[], *c_libs[];
  40.     IMPORT TEXT *c_objs[], *tran_objs[];
  41.     IMPORT BITS errors;
  42.     IMPORT BOOL file_type[], work_mode[];
  43.     INT mode, n;
  44.     BOOL any_mode;
  45.  
  46.     while (--ac)
  47.         if (**++av == '+')
  48.             if (0 <= (n = lookup(*av + 1, upd_modes)))
  49.                 work_mode[n] = YES;
  50.             else
  51.                 {
  52.                 puts("Unknown flag ", *av, "\n", NULL);
  53.                 errors |= BADFLAG;
  54.                 }
  55.         else if (!exists(*av))
  56.             {
  57.             puts("Can't access input file ", *av, "\n", NULL);
  58.             errors |= BADFILE;
  59.             }
  60.         else if (0 <= (n = lookup(*av, tran_files)))
  61.             file_type[0] = YES;
  62.         else if (0 <= (n = lookup(*av, lib_files)))
  63.             file_type[1] = YES;
  64.         else
  65.             file_type[2] = YES;
  66.     any_mode = 0;
  67.     for (mode = 0; mode < NMODE; ++mode)
  68.         any_mode += work_mode[mode];
  69.     for (mode = 0; mode < NMODE; ++mode)
  70.         {
  71.         if (!any_mode)
  72.             work_mode[mode] = YES;
  73.         if (work_mode[mode])
  74.             {
  75.             if (file_type[0] || file_type[1])
  76.                 {
  77.                 if (!exists(tran_libs[mode]))
  78.                     {
  79.                     puts("Can't access library file ", tran_libs[mode], "\n", NULL);
  80.                     errors |= BADLIBR;
  81.                     }
  82.                 if (!exists(tran_objs[mode]))
  83.                     {
  84.                     puts("Can't access object file ", tran_objs[mode], "\n", NULL);
  85.                     errors |= BADLIBR;
  86.                     }
  87.                 if (!exists(c_objs[mode]))
  88.                     {
  89.                     puts("Can't access object file ", c_objs[mode], "\n", NULL);
  90.                     errors |= BADLIBR;
  91.                     }
  92.                 }
  93.             if (!exists(lib_libs[mode]))
  94.                 {
  95.                 puts("Can't access library file ", lib_libs[mode], "\n", NULL);
  96.                 errors |= BADLIBR;
  97.                 }
  98.             if (!exists(c_libs[mode]))
  99.                 {
  100.                 puts("Can't access library file ", c_libs[mode], "\n", NULL);
  101.                 errors |= BADLIBR;
  102.                 }
  103.             }
  104.         }
  105.     return (!errors);
  106.     }
  107.  
  108. /* write a series of strings to standard out
  109. */
  110. /*VARARGS1*/
  111. LOCAL VOID puts(s)
  112.     TEXT *s;
  113.     {
  114.     TEXT **ss;
  115.  
  116.     for (ss = &s; *ss; ++ss)
  117.         write(1, *ss, strlen(*ss));
  118.     }
  119.  
  120. /* put object files into appropriate libraries
  121. */
  122. VOID archive(ac, av, mode)
  123.     INT ac, mode;
  124.     TEXT **av;
  125.     {
  126.     IMPORT TEXT *tran_files[], *tran_libs[], *lib_libs[], *tran_pgms[];
  127.  
  128.     while (--ac)
  129.         if ( (**++av != '+') && (**av != '-') )
  130.             {
  131.             if (0 <= lookup(*av, tran_files))
  132.                 {
  133.                 if (tran_pgms[mode])
  134.                     arch(*av, tran_libs[mode]);
  135.                 }
  136.             else
  137.                 arch(*av, lib_libs[mode]);
  138.             }
  139.     }
  140.  
  141. /* compile files using the indicated mode
  142. */
  143. VOID compile(ac, av, mode)
  144.     INT ac, mode;
  145.     TEXT **av;
  146.     {
  147.     IMPORT TEXT *tran_files[], *tran_pgms[];
  148.  
  149.     while (--ac)
  150.         if ( (**++av != '+') && (**av != '-') )
  151.             {
  152.             if (lookup(*av, tran_files) < 0 || tran_pgms[mode])
  153.                 cc(*av, mode);
  154.             }
  155.     }
  156.  
  157. /* rebuild BASTOC translator
  158. */
  159. VOID linkedit(mode)
  160.     INT mode;
  161.     {
  162.     IMPORT TEXT *tran_pgms[];
  163.     IMPORT BOOL file_type[];
  164.  
  165.     if (!(file_type[0] || file_type[1]))
  166.         return;
  167.     if (!tran_pgms[mode])
  168.         return;
  169.     ld(mode);
  170.     }
  171.