Patch #: 37 Type: operational change Priority: none Modification: add "-u " option to tlw Submitted: John J. Chew Archived: munnari.OZ.AU mac/cap.patches/cap60.patch037 Application: 'cd cap60; patch -p < cap60.patches/cap60.patch037' Summary: add GETOPT handling and code to read cap.printers File: cap60/samples/Makefile.m4 File: cap60/samples/tlw.c File: cap60/man/atprint.1 *** samples/tlw.c.orig Thu Feb 28 23:44:09 1991 --- samples/tlw.c Sat Jul 27 05:56:01 1991 *************** *** 1,6 **** ! static char rcsid[] = "$Author: djh $ $Date: 91/02/15 23:04:25 $"; ! static char rcsident[] = "$Header: tlw.c,v 2.1 91/02/15 23:04:25 djh Rel $"; ! static char revision[] = "$Revision: 2.1 $"; /* * tlw - UNIX AppleTalk test program - talk to laserwriter --- 1,6 ---- ! static char rcsid[] = "$Author: djh $ $Date: 1991/07/26 19:55:39 $"; ! static char rcsident[] = "$Header: /mac/src/cap60/samples/RCS/tlw.c,v 2.2 1991/07/26 19:55:39 djh Rel djh $"; ! static char revision[] = "$Revision: 2.2 $"; /* * tlw - UNIX AppleTalk test program - talk to laserwriter *************** *** 18,23 **** --- 18,25 ---- * June 30, 1986 CCKim Convert to TLW from lwpr * July 2, 1986 Schilit Make work with new stuff * July 5, 1986 CCKim Really make work with new stuff + * July 5, 1991 jjchew + * Lookup names in cap.printers */ char copyright[] = "Copyright (c) 1986, 1988 by The Trustees of Columbia University in the City of New York"; *************** *** 35,40 **** --- 37,46 ---- #include /* include appletalk definitions */ #include /* overrides for non-4.3 systems */ + #ifndef CAPPRINTERS + #define CAPPRINTERS "/etc/cap.printers" + #endif CAPPRINTERS + int cno; #define RFLOWQ 8 #ifndef SFLOWQ *************** *** 44,49 **** --- 50,56 ---- #define SBUFMAX 512*SFLOWQ char buf[SBUFMAX+10]; char rbuf[BUFMAX+10]; + boolean useunixname = FALSE; main(argc,argv) int argc; *************** *** 54,87 **** void stopall(); int hangup(); int pstatus(); ! char *s; ! abInit(TRUE); /* initialize appletalk driver */ ! PAPInit(); /* init pap */ ! nbpInit(); /* init nbp */ ! switch (argc) { ! case 1: ! LWNAME = "LaserWriter Plus:LaserWriter@*"; /* default */ ! break; ! case 2: ! LWNAME = argv[1]; ! break; ! case 3: ! LWNAME = argv[1]; ! s = argv[2]; ! if (*s++ == '-' && *s++ == 'd') ! dbugarg(s); ! break; ! default: ! printf("Usage: %s \n",argv[0]); exit(1); - break; } ! if (index(LWNAME,':') == NULL) { (void)sprintf(tbuf,"%s:LaserWriter@*", LWNAME); LWNAME = tbuf; } printf("Starting session with %s\n",LWNAME); setbuf(stdin, (char *)NULL); --- 61,114 ---- void stopall(); int hangup(); int pstatus(); ! char *getlwname(); ! char *index(); ! char c; ! extern char *optarg; ! extern int optind; ! boolean errflag = FALSE; ! while ((c = getopt(argc, argv, "ad:u")) != EOF) { ! switch (c) { ! case 'a': ! useunixname=FALSE; ! break; ! case 'd': ! dbugarg(optarg); ! break; ! case 'u': ! useunixname=TRUE; ! break; ! case '?': ! errflag = TRUE; ! break; ! } ! } ! if (errflag || argc-optind > 1) { ! fprintf(stderr, "Usage: %s [-d flags] [-a|-u] \n",argv[0]); exit(1); } ! ! LWNAME = argc==optind ? "LaserWriter Plus:LaserWriter@*" : argv[optind]; ! if (useunixname) { ! char *s; ! s = getlwname(LWNAME); ! if (s == NULL) { ! fprintf(stderr, "Cannot find printer %s in %s\n", LWNAME, CAPPRINTERS); ! exit(2); ! } ! LWNAME = s; ! } ! else if (index(LWNAME,':') == NULL) { (void)sprintf(tbuf,"%s:LaserWriter@*", LWNAME); LWNAME = tbuf; } + + abInit(TRUE); /* initialize appletalk driver */ + PAPInit(); /* init pap */ + nbpInit(); /* init nbp */ + printf("Starting session with %s\n",LWNAME); setbuf(stdin, (char *)NULL); *************** *** 94,100 **** --- 121,167 ---- exit(0); /* exit okay */ } + /* + * get the laserwriter name of the unix spooled printer + * (stolen from lwpr.c, also found in papif.c) + * + * returns NULL if nothing found + * returns 'LaserWriter Plus' if printer is null + */ + char * + getlwname(printer) + char *printer; + { + FILE *fd; + static char buf[256]; + char *ep; + if (printer == NULL || printer[0] == '\0') + return("LaserWriter Plus:LaserWriter@*"); + if ((fd = fopen(CAPPRINTERS,"r")) == NULL) { + perror("fopen"); + return(NULL); + } + do { + if (fgets(buf, 256, fd) == NULL) + break; + buf[strlen(buf)-1] = '\0'; /* get rid of the lf */ + if (buf[0] == '#' || buf[0] == '\0') + continue; + if ((ep=index(buf,'=')) == NULL) /* find first = */ + continue; /* no = in string */ + *ep = '\0'; /* set = to null now */ + if (strcmp(buf,printer) == 0) { + if (strlen(ep+1) == 0) /* no name */ + continue; + fclose(fd); + return(ep+1); /* return pointer to value */ + } + } while (1); + fclose(fd); + return(NULL); + } + /* * open laserwriter connection * log errors every 5 minutes to stderr *************** *** 143,149 **** int cno; { int eof, rlen, rcomp, wcomp, paperr, err; ! int tcomp, teof; char *getusername(); printf("\nOkay\n"); --- 210,216 ---- int cno; { int eof, rlen, rcomp, wcomp, paperr, err; ! int tcomp; char *getusername(); printf("\nOkay\n"); *** samples/Makefile.m4.orig Thu Feb 28 23:44:03 1991 --- samples/Makefile.m4 Sat Jul 27 05:57:32 1991 *************** *** 59,69 **** isrv.o: isrv.c ${CC} ${CFLAGS} -c isrv.c ! tlw: tlw.o $(O) ! ${CC} ${LFLAGS} -o tlw tlw.o $(O) $(CAPLIB) ${SLIB} tlw.o: tlw.c ! ${CC} ${CFLAGS} ${LWFLAGS} -c tlw.c # # atlook, atlooklw, and atpinger all have a common source --- 59,69 ---- isrv.o: isrv.c ${CC} ${CFLAGS} -c isrv.c ! tlw: tlw.o $(O) ${GETOPT} ! ${CC} ${LFLAGS} -o tlw tlw.o $(O) ${GETOPT} $(CAPLIB) ${SLIB} tlw.o: tlw.c ! ${CC} ${CFLAGS} ${LWFLAGS} ${CAPPRINTERS} -c tlw.c # # atlook, atlooklw, and atpinger all have a common source *** man/atprint.1.orig Wed May 8 21:23:03 1991 --- man/atprint.1 Sat Jul 27 05:58:55 1991 *************** *** 46,54 **** .PP .I tlw allows you to communicate with the interactive executive on a networked ! LaserWriter. To invoke tlw, simply type "tlw ", ! where the LaserWriter name is specified as for ! .I lwpr. You can terminate the conversation with an EOF signal (normally CTRL-D). .PP .I isrv --- 46,59 ---- .PP .I tlw allows you to communicate with the interactive executive on a networked ! PostScript device. ! You can specify the device in one of three ways (-a is the default). ! "tlw -u " maps a Unix short printer name to an Appletalk ! entity name via the cap.printers file (often found in /etc). ! "tlw -a " specifies a device of type "LaserWriter" in the current ! zone "*". ! "tlw -a " lets you choose an arbitrary object, type and zone, ! e.g. "tlw -a frobozz:LaserShare@zork". You can terminate the conversation with an EOF signal (normally CTRL-D). .PP .I isrv *** README.orig Sat Jul 27 05:53:54 1991 --- README Sat Jul 27 05:54:31 1991 *************** *** 3,9 **** (For use with AppleTalk/Ethernet bridge) o RELEASE NOTES ! o CAP Distribution 6.0, Patch Level 36, July 1991 Introduction ------------ --- 3,9 ---- (For use with AppleTalk/Ethernet bridge) o RELEASE NOTES ! o CAP Distribution 6.0, Patch Level 37, July 1991 Introduction ------------