home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume32
/
lprps
/
patch01
next >
Wrap
Text File
|
1992-10-06
|
17KB
|
684 lines
Newsgroups: comp.sources.misc
From: jjc@jclark.com (James Clark)
Subject: v32i094: lprps - interface lpr to a PostScript printer, Patch01
Message-ID: <1992Oct4.165224.4203@sparky.imd.sterling.com>
X-Md4-Signature: dcbe848e0bea4e28be01e1c8910490c3
Date: Sun, 4 Oct 1992 16:52:24 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: jjc@jclark.com (James Clark)
Posting-number: Volume 32, Issue 94
Archive-name: lprps/patch01
Environment: BSD, SUNOS
Patch-To: lprps: Volume 31, Issue 77-78
This patch updates lprps version 2.3 to version 2.4. It improves
lprps's response to various error conditions that were occurring on
Ultrix systems. It also improves psof's robustness and permits it to
be used in conjunction with the `hl' capability (which specifies that
the banner page should be printed at the end of a job).
James Clark
jjc@jclark.com
Prereq: 2.3.
*** lprps-2.3/README Tue Sep 29 10:18:06 1992
--- lprps-2.4/README Tue Sep 29 10:15:48 1992
***************
*** 1,3 ****
! This is lprps version 2.3.
lprps is a collection of programs for using lpr with a PostScript
--- 1,3 ----
! This is lprps version 2.4.
lprps is a collection of programs for using lpr with a PostScript
***************
*** 58,60 ****
jjc@jclark.com
! $Id: README,v 1.12 1992/08/14 16:34:21 jjc Exp $
--- 58,60 ----
jjc@jclark.com
! $Id: README,v 1.13 1992/09/29 09:14:36 jjc Exp $
*** lprps-2.3/INSTALL Tue Sep 29 10:18:06 1992
--- lprps-2.4/INSTALL Tue Sep 29 10:15:48 1992
***************
*** 15,25 ****
This entry would be appropriate if you were using /dev/ttya and a baud
! rate of 38400. You need to create the spool directory
! (/usr/spool/pslpd), the accounting file (/usr/adm/psacct), and the log
! file (/usr/adm/pslog). The spool directory and the accounting file
! should be owned by daemon, the log file by root. You can use other
! names if you want. The `ms' capabability is a Sun extension. If you
! decide to make use of the patches in lpr.diff, you should also add the
! `ex' boolean capability (the patches also add the `ms' capability.)
If you wish to have banner printing, then you should add
--- 15,26 ----
This entry would be appropriate if you were using /dev/ttya and a baud
! rate of 38400. Note that the `sf', `rw' and `sb' capabilities are
! essential. You need to create the spool directory (/usr/spool/pslpd),
! the accounting file (/usr/adm/psacct), and the log file
! (/usr/adm/pslog). The spool directory and the accounting file should
! be owned by daemon, the log file by root. You can use other names if
! you want. The `ms' capabability is a Sun extension. If you decide to
! make use of the patches in lpr.diff, you should also add the `ex'
! boolean capability (the patches also add the `ms' capability.)
If you wish to have banner printing, then you should add
***************
*** 27,31 ****
probably also wnat to modify the banner printing code in banner.ps.
As distributed, it provides a fairly minimalist banner page. Note
! that psof requires the `sb' capability.
You can add easily add other filters. For example, suppose you want to
--- 28,35 ----
probably also wnat to modify the banner printing code in banner.ps.
As distributed, it provides a fairly minimalist banner page. Note
! that psof requires the `sb' capability. If your printer stacks face
! up and you're using the 4.3BSD (or later) lpd, then you can add an
! `hl' capability to specify that the banner page should be printed at
! the end of a job instead of at the beginning.
You can add easily add other filters. For example, suppose you want to
***************
*** 92,94 ****
again from (*).
! $Id: INSTALL,v 1.7 1992/02/01 12:51:59 jjc Exp $
--- 96,98 ----
again from (*).
! $Id: INSTALL,v 1.9 1992/08/30 10:19:57 jjc Exp $
*** lprps-2.3/TODO Tue Sep 29 10:18:06 1992
--- lprps-2.4/TODO Tue Sep 29 10:15:49 1992
***************
*** 4,5 ****
--- 4,7 ----
psif should either mail or syslog errors.
+
+ Option to psrev to force page reversal no matter what the %%PageOrder: is?
*** lprps-2.3/Makefile Tue Sep 29 10:18:06 1992
--- lprps-2.4/Makefile Tue Sep 29 10:15:47 1992
***************
*** 1,3 ****
! # $Id: Makefile,v 1.14 1992/08/14 16:41:24 jjc Exp $
# Define A4 if you use A4 rather than letter size paper.
# Define IIg to enable a workaround for a bug in the serial
--- 1,3 ----
! # $Id: Makefile,v 1.16 1992/09/29 09:13:30 jjc Exp $
# Define A4 if you use A4 rather than letter size paper.
# Define IIg to enable a workaround for a bug in the serial
***************
*** 38,41 ****
--- 38,45 ----
INSTALL_DATA=install -m 0444
+ SHELL=/bin/sh
+ # Uncomment the next line for Ultrix.
+ #SHELL=/bin/sh5
+
SHAR=shar
DIST1=README INSTALL TODO Makefile textps.man psrev.man lprps.man psif.man \
***************
*** 60,64 ****
all: psif-text psif-ps $(PROGS) textps.n psrev.n lprps.n psif.n psof.n
! install: all
-test -d $(LIBDIR) || mkdir $(LIBDIR)
-test -d $(BINDIR) || mkdir $(BINDIR)
--- 64,68 ----
all: psif-text psif-ps $(PROGS) textps.n psrev.n lprps.n psif.n psof.n
! install: all banner.ps
-test -d $(LIBDIR) || mkdir $(LIBDIR)
-test -d $(BINDIR) || mkdir $(BINDIR)
***************
*** 98,102 ****
@echo Creating $@
@-rm -f $@
! @echo "#! /bin/sh" > $@
@echo "$(TEXT_TO_PS) | $(REV_COMMAND) $(LIBDIR)/lprps \"\$$@\"" >>$@
@chmod +x $@
--- 102,106 ----
@echo Creating $@
@-rm -f $@
! @echo "#! $(SHELL)" > $@
@echo "$(TEXT_TO_PS) | $(REV_COMMAND) $(LIBDIR)/lprps \"\$$@\"" >>$@
@chmod +x $@
***************
*** 105,109 ****
@echo Creating $@
@-rm -f $@
! @echo "#! /bin/sh" > $@
@echo "$(REV_COMMAND) $(LIBDIR)/lprps \"\$$@\"" >>$@
@chmod +x $@
--- 109,113 ----
@echo Creating $@
@-rm -f $@
! @echo "#! $(SHELL)" > $@
@echo "$(REV_COMMAND) $(LIBDIR)/lprps \"\$$@\"" >>$@
@chmod +x $@
***************
*** 119,122 ****
--- 123,139 ----
$(SHAR) -n2 -e2 $(DIST2) >$@
+ tar-dist: $(DIST1) $(DIST2)
+ dir=lprps-`sed -ne '1s/.*version \([0-9.]*[0-9]\).*/\1/p' README`; \
+ rm -fr $$dir; \
+ mkdir $$dir; \
+ cd $$dir; \
+ for f in $(DIST1) $(DIST2); do \
+ ln -s ../$$f .; \
+ done; \
+ cd ..; \
+ rm -f $$dir.tar.Z; \
+ tar cfh - $$dir | compress >$$dir.tar.Z; \
+ rm -fr $$dir
+
clean:
-rm -f $(PROGS) psif-text psif-ps *.n
*** lprps-2.3/lprps.c Tue Sep 29 10:18:24 1992
--- lprps-2.4/lprps.c Tue Sep 29 10:15:52 1992
***************
*** 2,6 ****
#ifndef lint
! static char rcsid[] = "$Id: lprps.c,v 1.16 1992/03/09 16:07:05 jjc Exp $";
#endif
--- 2,6 ----
#ifndef lint
! static char rcsid[] = "$Id: lprps.c,v 1.19 1992/09/29 09:06:22 jjc Exp $";
#endif
***************
*** 18,21 ****
--- 18,25 ----
#include <errno.h>
+ #ifndef errno
+ extern int errno;
+ #endif
+
#define SENDMAIL "/usr/lib/sendmail"
***************
*** 27,30 ****
--- 31,38 ----
#define IBSIZE 1024
+ /* number of times to try to get the status from the printer at the
+ beginning of the job */
+ #define MAX_TRIES 16
+
char ctrl_d = '\004';
char ctrl_t = '\024';
***************
*** 46,49 ****
--- 54,59 ----
/* set to non-zero on timeout */
int timeout_flag = 0;
+ /* if non-zero exit on timeout */
+ int exit_on_timeout = 0;
/* descriptor of printer device */
int psfd = 1;
***************
*** 82,89 ****
INVALID,
UNKNOWN,
IDLE,
BUSY,
WAITING,
! PRINTING
} status = INVALID;
--- 92,102 ----
INVALID,
UNKNOWN,
+ WARMING_UP,
+ INITIALIZING,
IDLE,
BUSY,
WAITING,
! PRINTING,
! PRINTER_ERROR,
} status = INVALID;
***************
*** 102,105 ****
--- 115,121 ----
int message_buf_i;
+ /* last printer error message */
+ char error_buf[128];
+
static char pagecount_string[] = "(%%[ pagecount: ) print \
statusdict begin pagecount end 20 string cvs print \
***************
*** 113,116 ****
--- 129,133 ----
void write_status_file();
void restore_status_file();
+ void handle_printer_error();
char *xmalloc();
char *strsignal();
***************
*** 124,128 ****
printer_name ? printer_name : "printer");
sleep(60); /* it will take at least this long to warm up */
! do_exit(EXIT_REPRINT);
}
--- 141,146 ----
printer_name ? printer_name : "printer");
sleep(60); /* it will take at least this long to warm up */
! if (exit_on_timeout)
! do_exit(EXIT_REPRINT);
}
***************
*** 435,444 ****
printer_flushing();
else if (strcmp(key, "PrinterError") == 0) {
! syslog(LOG_ERR, "%s: %s",
! printer_name ? printer_name : "printer error",
! p);
! print_status_file("%s: %s",
! printer_name ? printer_name : "printer error",
! p);
want_status = 1;
}
--- 453,457 ----
printer_flushing();
else if (strcmp(key, "PrinterError") == 0) {
! handle_printer_error(p);
want_status = 1;
}
***************
*** 464,470 ****
else if (strcmp(p, "printing") == 0)
status = PRINTING;
! else
status = UNKNOWN;
switch (status) {
case BUSY:
case WAITING:
--- 477,497 ----
else if (strcmp(p, "printing") == 0)
status = PRINTING;
! else if (strcmp(p, "warming up") == 0) {
! status = WARMING_UP;
! handle_printer_error(p);
! }
! else if (strcmp(p, "initializing") == 0)
! status = INITIALIZING;
! else if (strncmp(p, "PrinterError: ", sizeof("PrinterError: ") - 1)
! == 0) {
! status = PRINTER_ERROR;
! handle_printer_error(p + sizeof("PrinterError: ") - 1);
! }
! else {
! syslog(LOG_ERR, "unknown printer status `%s'", p);
status = UNKNOWN;
+ }
switch (status) {
+ case IDLE:
case BUSY:
case WAITING:
***************
*** 471,474 ****
--- 498,502 ----
case PRINTING:
restore_status_file();
+ error_buf[0] = '\0';
break;
default:
***************
*** 498,501 ****
--- 526,543 ----
}
+ void handle_printer_error(s)
+ char *s;
+ {
+ if (strlen(s) + 1 > sizeof(error_buf)
+ || strcmp(s, error_buf) == 0)
+ return;
+ strcpy(error_buf, s);
+ syslog(LOG_ERR, "%s: %s",
+ printer_name ? printer_name : "printer error",
+ s);
+ print_status_file("%s: %s",
+ printer_name ? printer_name : "printer error",
+ s);
+ }
void process_input_char(c)
***************
*** 582,587 ****
if (interrupt_flag)
handle_interrupt();
! if (timeout_flag)
handle_timeout();
while (select(psfd + 1, &rfds, &wfds, (fd_set *)NULL, (struct timeval *)NULL)
< 0)
--- 624,631 ----
if (interrupt_flag)
handle_interrupt();
! if (timeout_flag) {
handle_timeout();
+ return;
+ }
while (select(psfd + 1, &rfds, &wfds, (fd_set *)NULL, (struct timeval *)NULL)
< 0)
***************
*** 591,594 ****
--- 635,639 ----
else if (interrupt_flag)
handle_interrupt();
+ return;
}
else
***************
*** 755,783 ****
void get_status()
{
! if (signal(SIGALRM, set_timeout_flag) == BADSIG)
! sys_error("signal");
! ioflush();
! (void)alarm(5);
! blocking_write(&ctrl_t, 1);
! in_job = 0;
! parse_state = NORMAL;
! ignore_input = 0;
! while (status == INVALID)
! process_some_input();
! switch (status) {
! case IDLE:
! break;
! case WAITING:
! blocking_write(&ctrl_d, 1);
! sleep(5);
! exit(EXIT_REPRINT);
! case BUSY:
! case PRINTING:
! case UNKNOWN:
! sleep(15);
! exit(EXIT_REPRINT);
}
! if (signal(SIGALRM, SIG_IGN) == BADSIG)
! sys_error("signal");
}
--- 800,844 ----
void get_status()
{
! int i;
!
! for (i = 0; i < MAX_TRIES; i++) {
! ioflush();
! if (signal(SIGALRM, set_timeout_flag) == BADSIG)
! sys_error("signal");
! (void)alarm(5);
! blocking_write(&ctrl_t, 1);
! in_job = 0;
! parse_state = NORMAL;
! ignore_input = 0;
! exit_on_timeout = 0;
! while (status == INVALID) {
! process_some_input();
! if (timeout_flag) {
! timeout_flag = 0;
! break;
! }
! }
! if (signal(SIGALRM, SIG_IGN) == BADSIG)
! sys_error("signal");
! switch (status) {
! case INVALID:
! /* we slept in handle_timeout(), so don't sleep here */
! break;
! case IDLE:
! return;
! case WAITING:
! blocking_write(&ctrl_d, 1);
! sleep(5);
! break;
! default:
! sleep(15);
! break;
! }
! status = INVALID;
}
! syslog(LOG_ERR, "%s%scouldn't make printer ready to receive job",
! printer_name ? printer_name : "",
! printer_name ? ": " : "");
! do_exit(EXIT_REPRINT);
}
***************
*** 974,977 ****
--- 1035,1039 ----
read_status_file();
get_status();
+ exit_on_timeout = 1;
get_start_pagecount();
send_file();
*** lprps-2.3/psof.c Tue Sep 29 10:18:24 1992
--- lprps-2.4/psof.c Tue Sep 29 10:15:53 1992
***************
*** 1,6 ****
/* psof.c - lprps `of' filter for banner printing */
! /* Assumes sb is set, sh is not set, and that there is also an if
! filter. */
/* TODO: parse height and width command line arguments and pass them
--- 1,6 ----
/* psof.c - lprps `of' filter for banner printing */
! /* Assumes that the `sb' capability is present, that the `sh' capability
! is not present, and that there is an `if' filter. */
/* TODO: parse height and width command line arguments and pass them
***************
*** 8,12 ****
#ifndef lint
! static char rcsid[] = "$Id: psof.c,v 1.1 1992/02/01 12:36:01 jjc Exp $";
#endif
--- 8,12 ----
#ifndef lint
! static char rcsid[] = "$Id: psof.c,v 1.4 1992/08/30 10:23:27 jjc Exp $";
#endif
***************
*** 18,21 ****
--- 18,25 ----
#include <ctype.h>
+ #ifndef errno
+ extern int errno;
+ #endif
+
#ifndef LPRPS
#define LPRPS "/usr/local/lib/lprps"
***************
*** 59,89 ****
else
prog = "psof";
openlog(prog, LOG_PID, LOG_LPR);
for (;;) {
int i = 0;
! int c = getchar();
! if (c == EOF)
! break;
! for (;;) {
! if (c == '\n')
! break;
! if (i >= LINE_MAX - 1 || c == '\0' || c == EOF || c == '\031')
error("bad banner line");
! buf[i++] = c;
c = getchar();
}
! buf[i++] = '\0';
! if (!parse_banner(buf))
! error("bad banner line");
! print_banner();
! c = getchar();
! if (c == EOF)
! break;
! if (c != '\031' || getchar() != '\001')
! error("more than one banner line");
if (kill(getpid(), SIGSTOP) < 0)
sys_error("kill");
}
- exit(0);
/*NOTREACHED*/
}
--- 63,125 ----
else
prog = "psof";
+
openlog(prog, LOG_PID, LOG_LPR);
+
+ /* lpd gets indigestion if the output filter exits unexpectedly,
+ so we press on even when errors are encountered. */
for (;;) {
int i = 0;
! int c;
! int too_long_message = 0;
! int junk_message = 0;
!
! while ((c = getchar()) != EOF && c != '\n' && c != '\031') {
! if (c != '\f') {
! if (i >= LINE_MAX - 1) {
! if (!too_long_message) {
! error("banner line too long");
! too_long_message = 1;
! }
! }
! else
! buf[i++] = c;
! }
! }
!
! if (!too_long_message && i > 0) {
! buf[i] = '\0';
! if (parse_banner(buf))
! print_banner();
! else
error("bad banner line");
! }
!
! /* Skip till Control-Y Control-A sequence or end of file. */
! for (;;) {
! if (c == '\031') {
! c = getchar();
! if (c == '\001')
! break;
! if (c != EOF)
! ungetc(c, stdin);
! c = '\031';
! }
! if (c == EOF)
! exit(0);
! if (c != '\n' && c != '\f') {
! if (!junk_message) {
! if (i > 0)
! error("junk after banner line");
! else
! error("bad banner format (missing `sb' capability?)");
! junk_message = 1;
! }
! }
c = getchar();
}
!
if (kill(getpid(), SIGSTOP) < 0)
sys_error("kill");
}
/*NOTREACHED*/
}
***************
*** 273,277 ****
{
syslog(LOG_ERR, "%s", s);
- exit(1);
}
--- 309,312 ----
*** lprps-2.3/psrev.c Tue Sep 29 10:18:23 1992
--- lprps-2.4/psrev.c Tue Sep 29 10:15:51 1992
***************
*** 2,6 ****
#ifndef lint
! static char rcsid[] = "$Id: psrev.c,v 1.3 1991/07/14 14:11:01 jjc Exp $";
#endif
--- 2,6 ----
#ifndef lint
! static char rcsid[] = "$Id: psrev.c,v 1.4 1992/08/30 10:23:27 jjc Exp $";
#endif
***************
*** 10,13 ****
--- 10,17 ----
#include <sys/stat.h>
#include <errno.h>
+
+ #ifndef errno
+ extern int errno;
+ #endif
char *malloc();
*** lprps-2.3/psof.man Tue Sep 29 10:18:07 1992
--- lprps-2.4/psof.man Tue Sep 29 10:15:50 1992
***************
*** 1,4 ****
.\" -*- nroff -*-
! .\" $Id: psof.man,v 1.1 1992/02/01 12:36:32 jjc Exp $
.TH PSOF @MAN8EXT@
.SH NAME
--- 1,4 ----
.\" -*- nroff -*-
! .\" $Id: psof.man,v 1.2 1992/08/29 10:35:09 jjc Exp $
.TH PSOF @MAN8EXT@
.SH NAME
***************
*** 34,37 ****
--- 34,41 ----
.B sh
capability.
+ Include an
+ .B hl
+ capability to print the banner page at the end of a job rather
+ than at the beginning.
The
.B lpr
***************
*** 61,67 ****
.B @BANNER@
\ \ PostScript code to print banner.
- .SH BUGS
- The banner page will be printed before the job even on printers
- that stack face up.
.SH "SEE ALSO"
.BR printcap (5),
--- 65,68 ----
exit 0 # Just in case...