From: thompson@orpheus.gsfc.nasa.gov (William Thompson)
Subject: Re: Help! Can't figure out how to set up print queue.
Date: 5 Aug 1994 17:30:30 GMT [thread overview]
Message-ID: <31tsvm$6on@paperboy.gsfc.nasa.gov> (raw)
In-Reply-To: 31rt75$l7d@paperboy.gsfc.nasa.gov
thompson@orpheus.gsfc.nasa.gov (William Thompson) writes:
After being on the phone to DEC support, I found out how to fix my problem. As
it's been pointed out, one can't use a print filter with a remote queue.
However, there is a workaround. One sets up a regular queue to the remote
printer, and then another queue with a printcap entry such as the following:
lp4|4|test:\
:lf=/usr/adm/lp4err:\
:lp=/dev/null:\
:mx#0:\
:of=/usr/lbin/testfilter:\
:sd=/usr/spool/lpd4:\
:sh:\
:sf:
(The "sh" and "sf" fields were added by myself after some experimenting.) The
filter (here called testfilter) is a shell script that looks something like the
following:
#! /bin/csh -f
/bin/cat | /usr/local/bin/psfilter | lpr -P remoteprinter
where "remoteprinter" is the name of the remote printer queue. Sending
something to the queue "test" causes the file to be processed by the filter and
then sent on to the real printer queue.
The one drawback is that jobs disappear from the "test" queue very quickly,
and one has to check the "remoteprinter" queue to find out the true status of
the job.
Bill Thompson
P.S. The print filter I posted earlier had a bug in it related to tabs at the
beginning of the line. The corrected version is included below. I also added
some code by Robert E. Boughner of the NASA Langley Research Center, which
converts 8-bit ASCII values in PostScript files to their octal notation
equivalent. According to him, this solves a problem with printing from inside
BookReader to some PostScript printers.
Other, more standard, PostScript filters have also been suggested, namely
/usr/lbin/ln03rof
/usr/lbin/ps_level1of_isolatin1
/usr/lbin/ps_level2of_isolatin1
I've tried them in the past, but was fooled by the fact that filters are
ignored for remote printer queues, so I can't comment on how well they work.
===============================================================================
/* This small program checks to see if the file being processed is a PostScript
* file, by looking to see if the first two characters are '%!'. If they are,
* then the file will be passed straight through. Otherwise, the file is
* converted into PostScript using default formatting conventions. */
/* Written:
* William Thompson, GSFC/ARC, 4 August 1994
* Modified:
* Version 1, William Thompson, GSFC/ARC, 4 August 1994
* Version 2, William Thompson, GSFC/ARC, 5 August 1994
* Corrected bug with tabs at the beginning of the line.
* Added check for 8 bit characters based on code by Robert E.
* Boughner of the NASA Langley Research Center.
* Version:
* Version 2, 5 August 1994
*/
#include <stdio.h>
#include <string.h>
void main(void)
{
char ch, firsttwo, PSfile;
char savChar[5]; /* Space for saving characters. */
int n_char; /* Number of characters that will actually print. */
int n_lines; /* Number of lines printed so far. */
int n_tab; /* Number of spaces to replace tab with. */
int i;
int max_chars,max_lines;
max_chars = 80; /* Maximum characters/line. */
max_lines = 54; /* Maximum lines/page. */
firsttwo = PSfile = 1; /* Assume PS file, and check 1st 2 chars. */
while( (ch = getchar()) != EOF) {
if (firsttwo) {
firsttwo = 0;
savChar[0] = ch;
savChar[1] = ch = getchar();
savChar[2] = '\0';
/* If not a PostScript file, then prepend the appropriate header. */
if (strcmp(savChar,"%!")) {
PSfile = 0;
fwrite("%!PS-Adobe-3.0\n",sizeof(char),15,stdout);
fwrite("gsave\n",sizeof(char),6,stdout);
fwrite("/setlocation {72 -27 translate 0 740 moveto} def\n",
sizeof(char),49,stdout);
fwrite("/showline {show currentpoint pop neg -12 rmoveto} def\n",
sizeof(char),54,stdout);
fwrite("setlocation\n",sizeof(char),12,stdout);
fwrite("/Courier findfont 10 scalefont setfont\n",sizeof(char),39,
stdout);
fwrite("(",sizeof(char),1,stdout);
/* Initialize the various counters. */
n_char = 1;
n_lines = 0;
}
fwrite(savChar,sizeof(char),1,stdout); /* Write the first char. */
}
/* Process the character depending on whether or not the file is PostScript. */
if (! PSfile) {
/* If the input character is "\", "(" or ")", then precede the character with a
* "\" in the output. Otherwise the PostScript printer might think it was a
* control character. */
if ((ch == (char) '\134') || (ch == (char) '\050') ||
(ch == (char) '\051'))
fwrite("\\",sizeof(char),1,stdout);
/* If the character is a tab, then convert it to spaces. Print all but the
* last space. */
if (ch == (char) '\011') {
if (n_char == 0) fwrite("(",sizeof(char),1,stdout);
n_tab = 8*((n_char/8) + 1) - n_char;
ch = (char) '\040';
for (i=1; i<n_tab; ++i) {
fwrite(&ch,sizeof(char),1,stdout);
++n_char;
}
}
/* If the input character is a formfeed, then flush out the current line, and
* eject the page. */
if (ch == (char) '\014') {
if (n_char > 0)
fwrite(") showline\n",sizeof(char),11,stdout);
fwrite("showpage\n",sizeof(char),9,stdout);
fwrite("setlocation\n",sizeof(char),12,stdout);
n_char = 0;
n_lines = 0;
continue; /* Skip the rest of this loop. */
}
/* If the input character is an end-of-line, then flush out the current line.
* If necessary, eject the page. */
if (ch == (char) '\012') {
if (n_char == 0) fwrite ("(",sizeof(char),1,stdout);
fwrite(") showline\n",sizeof(char),11,stdout);
n_char = 0;
++n_lines;
if (n_lines >= max_lines) {
fwrite("showpage\n",sizeof(char),9,stdout);
fwrite("setlocation\n",sizeof(char),12,stdout);
n_lines = 0;
}
continue; /* Skip the rest of this loop. */
}
/* If the input character is a non-printing character, insert a period in its
* place. */
if (((int) ch < '\040') || ((int) ch > '\176')) ch = (char) '\056';
/* Print the character. If the maximum number of characters is reached, then
* flush out the current. If the maximum number of lines is reached, then
* eject the page. */
if (n_char == 0) fwrite ("(",sizeof(char),1,stdout);
fwrite(&ch,sizeof(char),1,stdout);
++n_char;
if (n_char >= max_chars) {
fwrite(") showline\n",sizeof(char),11,stdout);
n_char = 0;
++n_lines;
if (n_lines >= max_lines) {
fwrite("showpage\n",sizeof(char),9,stdout);
fwrite("setlocation\n",sizeof(char),12,stdout);
n_lines = 0;
}
}
/* However, if this is a PostScript file, then simply pass the character
* through, either unchanged or converted into octal notation. */
} else {
savChar[0] = ch;
savChar[1] = '\0';
if ((unsigned char)ch > 0177)
sprintf(savChar,"\\%.3o", (unsigned char)ch);
fwrite(savChar, sizeof(char), strlen(savChar), stdout);
}
}
/* Show the last page, and restore any previous printer settings. */
if (! PSfile) {
fwrite("showpage\n",sizeof(char),9,stdout);
fwrite("grestore\n",sizeof(char),9,stdout);
}
}
prev parent reply other threads:[~1994-08-05 17:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-08-04 23:22 Help! Can't figure out how to set up print queue William Thompson
1994-08-05 14:01 ` Torbj|rn Lindgren
1994-08-05 14:47 ` William Thompson
1994-08-05 17:30 ` William Thompson [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox