home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OS9000 / APPS / rcs.lzh / rcs1 / mani.c < prev    next >
C/C++ Source or Header  |  1996-04-20  |  4KB  |  135 lines

  1. /*-----------------------------------------------------------------------
  2. !                                                                       !
  3. ! Name: mani                                                            !
  4. !                                                                       !
  5. ! Function: MANIFEST file processor                                     !
  6. !                                                                       !
  7. ! Revision History:                                                     !
  8. !   #    Reason for Change                             By   Date        !
  9. ! ---- ----------------------------------------------- ---- --------    !
  10. !   1   Created                                        hiro  3/24/93    !
  11. -----------------------------------------------------------------------*/
  12. #ifdef _UCC
  13. _asm("_sysedit: equ 1");
  14. #define environ    _environ
  15. #else
  16. @_sysedit: equ 1
  17. #endif
  18.  
  19. #ifdef _OS9000
  20. #include <io.h>
  21. #define environ    _environ
  22. #else
  23. #include <sysio.h>
  24. #endif
  25.  
  26. #include <stdio.h>
  27. #include <ctype.h>
  28. #include <strings.h>
  29. #include <errno.h>
  30. #ifndef _types
  31. #include <types.h>
  32. #endif
  33.  
  34. #define  MAXARGC 256
  35.  
  36. FILE *namefile;
  37. char *filename = "MANIFEST";
  38. char *files[MAXARGC + 1];
  39. extern   char *_prgname(), **environ;
  40. extern   void *malloc();
  41. extern   int  os9forkc();
  42.  
  43. int  vopt;
  44.  
  45. main(argc, argv)
  46. int  argc;
  47. char *argv[];
  48. {
  49. FILE *file;
  50. register char *p, **fpp;
  51. register int  ch, waseq = 0;
  52. char buf[256];
  53. u_int status;
  54.  
  55.      while (--argc > 0 && *(p = *++argv) == '-')
  56.      {
  57.           ++p;
  58.           while (ch = *p++)
  59.           {
  60.                waseq = *p == '=';
  61.                if (waseq)
  62.                     ++p;
  63.                switch (ch)
  64.                {
  65.                case 'v':
  66.                        vopt = 1; continue;
  67.                case 'z':
  68.                     filename = p;
  69.                     break;
  70.                default:
  71.                     prtuse(_errmsg(1,"unknown option '%c'.\n\n",ch));
  72.                case '?':
  73.                     prtuse(0);
  74.                }
  75.                break;
  76.           }
  77.      }
  78.  
  79.      if (!argc)
  80.           prtuse(1);
  81.      for (ch = 0; argc > 0 && ch < MAXARGC; argc--)
  82.           files[ch++] = *argv++;
  83.  
  84.      if ((namefile = fopen(filename,"r")) == NULL)
  85.           exit(_errmsg(errno,"can't open \"%s\" ",filename));
  86.      while (p = fgets(buf, sizeof(buf), namefile))
  87.      {
  88.           p[strlen(p) - 1] = '\0';
  89.           while (isspace(*p))
  90.                p++;
  91.           if (!*p || *p == '#' || *p == '*')
  92.                continue;
  93.           else if (ch >= MAXARGC - 1)
  94.                _errmsg(1, "too many lines; \"%s\" discarded.\n", p);
  95.           else if (!(files[ch] = malloc(strlen(p)+1)))
  96.                _errmsg(1, "memory allocation error; \"%s\" discarded.\n", p);
  97.           strcpy(files[ch++], p);
  98.      }
  99.  
  100.      if (vopt)
  101.           for (fpp = files; *fpp; fpp++)
  102.                fprintf(stderr, "%s%c", *fpp, fpp[1] ? ' ' : '\n');
  103.      if ((ch = os9exec(os9forkc, *files, files, environ, 0, 0, 3)) == -1)
  104.           exit(_errmsg(errno, "can't fork \"%s\". ", *files));
  105.      while (wait(&status) != ch)
  106.           ;
  107.      exit(status);
  108. }
  109.  
  110.  
  111. /**--------------------------------------------------------------
  112. !    cmds[] - array of pointers to strings of help text
  113. !*/
  114. static char *cmds[] = {
  115.        "Function: appliy manifest file contents to <command>\n",
  116.        "Options:\n",
  117.        "    -v    verbose mode\n",
  118.        "    -z[=<file>]   override default manifest file \"MANIFEST\"\n"
  119. };
  120.  
  121. /**--------------------------------------------------------------
  122. !    printuse - print the help text to standard error.
  123. !*/
  124. static prtuse(stat)
  125.      int stat;
  126. {
  127. register char **p = cmds,
  128.               **e = cmds + sizeof cmds / sizeof (char *);
  129.  
  130.      fprintf(stderr,"Syntax: %s {<opts>} <command> {<params>}\n", _prgname());
  131.      while (p < e)
  132.           fputs(*p++,stderr);
  133.      exit(stat);
  134. }
  135.