home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / unix / macps_pr.hqx / macps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-22  |  2.9 KB  |  129 lines

  1. /*
  2.  * Copyright (c) 1988, The Trustees of the University of California.
  3.  * Edward Moy, Workstation Software Support Group, Workstation Support Serices,
  4.  * Information Systems and Technology.
  5.  *
  6.  * Permission is granted to any individual or institution to use, copy,
  7.  * or redistribute this software so long as it is not sold for profit,
  8.  * provided that this notice and the original copyright notices are
  9.  * retained.  The University of California makes no representations about the
  10.  * suitability of this software for any purpose.  It is provided "as is"
  11.  * without express or implied warranty.
  12.  */
  13.  
  14. #ifndef lint
  15. static char *SCCSid = "@(#)macps.c    1.1 9/19/88";
  16. #endif lint
  17.  
  18. #include <ctype.h>
  19. #include <stdio.h>
  20. #include <strings.h>
  21. #include "ucbwhich.h"
  22.  
  23. #define    CONFIG        "macps.config"
  24. #define LINELEN        256
  25.  
  26. char *Fgets();
  27. char *myname;
  28. int ucbalternate;
  29. char ucbpath[UCBMAXPATHLEN];
  30. char ucblib[UCBMAXPATHLEN];
  31.  
  32. main(argc, argv)
  33. int argc;
  34. char **argv;
  35. {
  36.     register char *cp, *pp;
  37.     register FILE *fp, *lp;
  38.     register int i, libend;
  39.     char buf[BUFSIZ], line[LINELEN];
  40.  
  41.     ucbwhich(*argv);
  42.     if(myname = rindex(*argv, '/'))
  43.         myname++;
  44.     else
  45.         myname = *argv;
  46.     if(argc > 2) {
  47.         fprintf(stderr, "Usage: %s [file]\n", myname);
  48.         exit(1);
  49.     }
  50.     if(argc == 2 && freopen(*++argv, "r", stdin) == NULL) {
  51.         fprintf(stderr, "%s: can't open %s\n", myname, *argv);
  52.         exit(1);
  53.     }
  54.     if(Fgets(buf, BUFSIZ, stdin) == NULL) {
  55.         fprintf(stderr, "%s: Null input\n", myname);
  56.         exit(1);
  57.     }
  58.     strcat(ucblib, "/");
  59.     libend = strlen(ucblib);
  60.     strcat(ucblib, CONFIG);
  61.     if((fp = fopen(ucblib, "r")) == NULL) {
  62.         fprintf(stderr, "%s: Can't open %s\n", myname, ucblib);
  63.         exit(1);
  64.     }
  65.     fputs("%!\n", stdout);
  66.     do {
  67.         Fputs(buf, stdout);
  68.         if(strncmp(buf, "%%IncludeProcSet:", 17) == 0) {
  69.             for(cp = &buf[17] ; ; cp++) {
  70.                 if(!*cp) {
  71.                     fprintf(stderr,
  72.                  "%s: Syntax error on IncludeProcSet line\n",
  73.                      myname);
  74.                     exit(1);
  75.                 }
  76.                 if(!isspace(*cp))
  77.                     break;
  78.             }
  79.             pp = cp + strlen(cp);
  80.             for( ; ; ) {
  81.                 --pp;
  82.                 if(!isspace(*pp))
  83.                     break;
  84.                 *pp = 0;
  85.             }
  86.             fseek(fp, 0L, 0);
  87.             for( ; ; ) {
  88.                 if(!fgets(line, LINELEN, fp)) {
  89.                     fprintf(stderr,
  90.                      "%s: Unknown IncludeProcSet (%s)\n",
  91.                      myname, cp);
  92.                     exit(1);
  93.                 }
  94.                 if(*line == '#')
  95.                     continue;
  96.                 if(pp = index(line, '\n')) {
  97.                     if(pp == line)
  98.                         continue;
  99.                     *pp = 0;
  100.                 }
  101.                 if(!(pp = index(line, '\t'))) {
  102.                     fprintf(stderr,
  103.                      "%s: Syntax error in %s\n",
  104.                      myname, ucblib);
  105.                     exit(1);
  106.                 }
  107.                 *pp++ = 0;
  108.                 if(strcmp(line, cp) == 0)
  109.                     break;
  110.             }
  111.             if(*pp == '/')
  112.                 strcpy(ucblib, pp);
  113.             else {
  114.                 ucblib[libend] = 0;
  115.                 strcat(ucblib, pp);
  116.             }
  117.             if((lp = fopen(ucblib, "r")) == NULL) {
  118.                 fprintf(stderr, "%s: Can't open %s\n", myname,
  119.                  ucblib);
  120.                 exit(1);
  121.             }
  122.             while((i = fread(buf, 1, BUFSIZ, lp)) > 0)
  123.                 fwrite(buf, 1, i, stdout);
  124.             fclose(lp);
  125.         }
  126.     } while(Fgets(buf, BUFSIZ, stdin));
  127.     exit(0);
  128. }
  129.