Patch #: 42 Type: operational change Priority: none Modification: make macps usable as a transcript filter Submitted: Saul Jaffe Archived: munnari.OZ.AU mac/cap.patches/cap60.patch042 Application: 'cd cap60; patch -p < cap60.patches/cap60.patch042' Summary: add necessary code (enable with -DADOBE) File: cap60/contrib/MacPS/macps.c *** contrib/MacPS/macps.c.orig Thu Feb 28 23:45:16 1991 --- contrib/MacPS/macps.c Sun Jul 28 22:43:09 1991 *************** *** 13,18 **** --- 13,21 ---- #ifndef lint static char *SCCSid = "@(#)macps.c 2.2 10/25/89"; + #ifdef ADOBE + static char *SCCSid2 = "Modified 6/27/89 by jaffe@rutgers to include support for Transcript"; + #endif ADOBE #endif lint #include *************** *** 26,31 **** --- 29,37 ---- #include #include "str.h" #include "ucbwhich.h" + #ifdef ADOBE + #include + #endif ADOBE #define CONFIG "macps.config" #ifdef SYSV *************** *** 33,38 **** --- 39,47 ---- #define rindex strrchr #endif SYSV + #ifdef ADOBE + #define debugp(x) {fprintf x ; (void) fflush(stderr);} + #endif ADOBE #ifdef SAVE char *finale = "clear countdictstack 2 sub{end}repeat macps restore\n"; char intro[] = "\ *************** *** 54,59 **** --- 63,79 ---- char ucblib[UCBMAXPATHLEN]; #endif CONFIGDIR + #ifdef ADOBE + extern char *envget(); + extern char *getenv(); + FILE *jobout; /* for debugging and logging */ + int Debugging = 0; /* debugging boolean */ + int verboselog = 0; /* do we want messages dumped to a log */ + int havejobout = 0; + long starttime; /* for time in messages to log */ + char *outname; + #endif ADOBE + main(argc, argv) int argc; char **argv; *************** *** 66,71 **** --- 86,95 ---- char path[UCBMAXPATHLEN]; long ltime; char *ctime(); + #ifdef ADOBE + char *Debug; + char *Verbose; + #endif ADOBE #ifndef CONFIGDIR ucbwhich(*argv); *************** *** 75,80 **** --- 99,137 ---- else myname = *argv; cp = NULL; + + #ifdef ADOBE + /* set up for debugging */ + Debug = envget("DEBUG"); + if (Debug != NULL) + Debugging = atoi(Debug); + + /* set up stderr to go to the right place ala transcript */ + + setjobout(); + + /* identify myself like most of the postscript filters do */ + + Verbose = envget("VERBOSELOG"); + if (Verbose != NULL) + verboselog = atoi(Verbose); + + if (verboselog) + { + (void) time(&starttime); + if (havejobout) + { + fprintf(jobout, "%s: Started at %s\n", myname, ctime(&starttime)); + (void) fflush(jobout); + } + else + { + fprintf(stderr, "%s: Started at %s\n", myname, ctime(&starttime)); + (void) fflush(stderr); + } + } + #endif ADOBE + for(argc--, argv++ ; argc > 0 && **argv == '-' ; argc--, argv++) { switch((*argv)[1]) { case 'c': /* multiple copies */ *************** *** 110,129 **** if(argc > 1) Usage(); /* never returns */ if(argc == 1 && freopen(*argv, "r", stdin) == NULL) { fprintf(stderr, "%s: can't open %s\n", myname, *argv); ! exit(1); } str = STRalloc(); if(!STRgets(str, stdin)) { fprintf(stderr, "%s: Null input\n", myname); ! exit(1); } strcat(ucblib, "/"); strcpy(path, ucblib); strcat(path, CONFIG); if((fp = fopen(path, "r")) == NULL) { fprintf(stderr, "%s: Can't open %s\n", myname, path); ! exit(1); } time(<ime); printf(intro, ctime(<ime)); --- 167,198 ---- if(argc > 1) Usage(); /* never returns */ if(argc == 1 && freopen(*argv, "r", stdin) == NULL) { + #ifdef ADOBE + debugp((jobout, "%s: can't open %s\n", myname, *argv)); + #else ADOBE fprintf(stderr, "%s: can't open %s\n", myname, *argv); ! #endif ADOBE ! exit(2); } str = STRalloc(); if(!STRgets(str, stdin)) { + #ifdef ADOBE + debugp((jobout, "%s: Null input\n", myname)); + #else ADOBE fprintf(stderr, "%s: Null input\n", myname); ! #endif ADOBE ! exit(2); } strcat(ucblib, "/"); strcpy(path, ucblib); strcat(path, CONFIG); if((fp = fopen(path, "r")) == NULL) { + #ifdef ADOBE + debugp((jobout, "%s: Can't open %s\n", myname, path)); + #else ADOBE fprintf(stderr, "%s: Can't open %s\n", myname, path); ! #endif ADOBE ! exit(2); } time(<ime); printf(intro, ctime(<ime)); *************** *** 144,153 **** if(STRheadcompare(str, "%%IncludeProcSet:") == 0) { for(cp = (char *)&str->bufptr[17] ; ; cp++) { if(!*cp) { fprintf(stderr, "%s: Syntax error on IncludeProcSet line\n", myname); ! exit(1); } if(!isascii(*cp) || !isspace(*cp)) break; --- 213,228 ---- if(STRheadcompare(str, "%%IncludeProcSet:") == 0) { for(cp = (char *)&str->bufptr[17] ; ; cp++) { if(!*cp) { + #ifdef ADOBE + debugp((jobout, + "%s: Syntax error on IncludeProcSet line\n", + myname)); + #else ADOBE fprintf(stderr, "%s: Syntax error on IncludeProcSet line\n", myname); ! #endif ADOBE ! exit(2); } if(!isascii(*cp) || !isspace(*cp)) break; *************** *** 162,171 **** fseek(fp, 0L, 0); for( ; ; ) { if(!fgets(line, BUFSIZ, fp)) { fprintf(stderr, "%s: Unknown IncludeProcSet %s\n", myname, cp); ! exit(1); } if(*line == '#') continue; --- 237,252 ---- fseek(fp, 0L, 0); for( ; ; ) { if(!fgets(line, BUFSIZ, fp)) { + #ifdef ADOBE + debugp((jobout, + "%s: Unknown IncludeProcSet %s\n", + myname, cp)); + #else ADOBE fprintf(stderr, "%s: Unknown IncludeProcSet %s\n", myname, cp); ! #endif ADOBE ! exit(2); } if(*line == '#') continue; *************** *** 175,184 **** *pp = 0; } if(!(pp = index(line, '\t'))) { fprintf(stderr, "%s: Syntax error in macps.config\n", myname); ! exit(1); } *pp++ = 0; if(STRcompareptr(str, cp, line) == 0) --- 256,271 ---- *pp = 0; } if(!(pp = index(line, '\t'))) { + #ifdef ADOBE + debugp((jobout, + "%s: Syntax error in macps.config\n", + myname)); + #else ADOBE fprintf(stderr, "%s: Syntax error in macps.config\n", myname); ! #endif ADOBE ! exit(2); } *pp++ = 0; if(STRcompareptr(str, cp, line) == 0) *************** *** 192,200 **** } fflush(stdout); if((fd = open(path, O_RDONLY, 0)) < 0) { fprintf(stderr, "%s: Can't open %s\n", myname, path); ! exit(1); } while((i = read(fd, line, BUFSIZ)) > 0) write(1, line, i); --- 279,292 ---- } fflush(stdout); if((fd = open(path, O_RDONLY, 0)) < 0) { + #ifdef ADOBE + debugp((jobout, "%s: Can't open %s\n", myname, + path)); + #else ADOBE fprintf(stderr, "%s: Can't open %s\n", myname, path); ! #endif ADOBE ! exit(2); } while((i = read(fd, line, BUFSIZ)) > 0) write(1, line, i); *************** *** 225,229 **** Usage() { fputs("Usage: macps [-c #] [-d directory] [-r] [file]\n", stderr); ! exit(1); } --- 317,354 ---- Usage() { fputs("Usage: macps [-c #] [-d directory] [-r] [file]\n", stderr); ! exit(2); } + + #ifdef ADOBE + setjobout() + { + /* So that all messages will go to someplace that is permanent. This is to + defeat Sun 4.0's lpd that uses a temporary file for error messages + (stderr) that disappears as soon as the printjob stops */ + + /* get jobout from environment if there, otherwise use stderr */ + if (((outname = envget("JOBOUTPUT")) == NULL) + || ((jobout = fopen(outname,"a")) == NULL)) { + debugp((stderr,"%s: Failure opening log file (%s)\n", myname, outname)); + jobout = stderr; + } + else havejobout = 1; + } + + + /* envget is a getenv + * if the variable is not present in the environment or + * it has the null string as value envget returns NULL + * otherwise it returns the value from the environment + */ + + char *envget(var) + char *var; + { + register char *val; + if (((val = getenv(var)) == NULL) || (*val == '\0')) + return ((char *) NULL); + else return (val); + } + #endif ADOBE *** README.orig Sun Jul 28 22:40:38 1991 --- README Sun Jul 28 22:40:49 1991 *************** *** 3,9 **** (For use with AppleTalk/Ethernet bridge) o RELEASE NOTES ! o CAP Distribution 6.0, Patch Level 41, July 1991 Introduction ------------ --- 3,9 ---- (For use with AppleTalk/Ethernet bridge) o RELEASE NOTES ! o CAP Distribution 6.0, Patch Level 42, July 1991 Introduction ------------