home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1988, The Trustees of the University of California.
- * Edward Moy, Workstation Software Support Group, Workstation Support Serices,
- * Information Systems and Technology.
- *
- * Permission is granted to any individual or institution to use, copy,
- * or redistribute this software so long as it is not sold for profit,
- * provided that this notice and the original copyright notices are
- * retained. The University of California makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- */
-
- #ifndef lint
- static char *SCCSid = "@(#)macps.c 1.1 9/19/88";
- #endif lint
-
- #include <ctype.h>
- #include <stdio.h>
- #include <strings.h>
- #include "ucbwhich.h"
-
- #define CONFIG "macps.config"
- #define LINELEN 256
-
- char *Fgets();
- char *myname;
- int ucbalternate;
- char ucbpath[UCBMAXPATHLEN];
- char ucblib[UCBMAXPATHLEN];
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- register char *cp, *pp;
- register FILE *fp, *lp;
- register int i, libend;
- char buf[BUFSIZ], line[LINELEN];
-
- ucbwhich(*argv);
- if(myname = rindex(*argv, '/'))
- myname++;
- else
- myname = *argv;
- if(argc > 2) {
- fprintf(stderr, "Usage: %s [file]\n", myname);
- exit(1);
- }
- if(argc == 2 && freopen(*++argv, "r", stdin) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", myname, *argv);
- exit(1);
- }
- if(Fgets(buf, BUFSIZ, stdin) == NULL) {
- fprintf(stderr, "%s: Null input\n", myname);
- exit(1);
- }
- strcat(ucblib, "/");
- libend = strlen(ucblib);
- strcat(ucblib, CONFIG);
- if((fp = fopen(ucblib, "r")) == NULL) {
- fprintf(stderr, "%s: Can't open %s\n", myname, ucblib);
- exit(1);
- }
- fputs("%!\n", stdout);
- do {
- Fputs(buf, stdout);
- if(strncmp(buf, "%%IncludeProcSet:", 17) == 0) {
- for(cp = &buf[17] ; ; cp++) {
- if(!*cp) {
- fprintf(stderr,
- "%s: Syntax error on IncludeProcSet line\n",
- myname);
- exit(1);
- }
- if(!isspace(*cp))
- break;
- }
- pp = cp + strlen(cp);
- for( ; ; ) {
- --pp;
- if(!isspace(*pp))
- break;
- *pp = 0;
- }
- fseek(fp, 0L, 0);
- for( ; ; ) {
- if(!fgets(line, LINELEN, fp)) {
- fprintf(stderr,
- "%s: Unknown IncludeProcSet (%s)\n",
- myname, cp);
- exit(1);
- }
- if(*line == '#')
- continue;
- if(pp = index(line, '\n')) {
- if(pp == line)
- continue;
- *pp = 0;
- }
- if(!(pp = index(line, '\t'))) {
- fprintf(stderr,
- "%s: Syntax error in %s\n",
- myname, ucblib);
- exit(1);
- }
- *pp++ = 0;
- if(strcmp(line, cp) == 0)
- break;
- }
- if(*pp == '/')
- strcpy(ucblib, pp);
- else {
- ucblib[libend] = 0;
- strcat(ucblib, pp);
- }
- if((lp = fopen(ucblib, "r")) == NULL) {
- fprintf(stderr, "%s: Can't open %s\n", myname,
- ucblib);
- exit(1);
- }
- while((i = fread(buf, 1, BUFSIZ, lp)) > 0)
- fwrite(buf, 1, i, stdout);
- fclose(lp);
- }
- } while(Fgets(buf, BUFSIZ, stdin));
- exit(0);
- }
-