* Help! Can't figure out how to set up print queue.
@ 1994-08-04 23:22 William Thompson
1994-08-05 14:01 ` Torbj|rn Lindgren
1994-08-05 17:30 ` William Thompson
0 siblings, 2 replies; 4+ messages in thread
From: William Thompson @ 1994-08-04 23:22 UTC (permalink / raw)
I'm trying to set up a print queue to be smart enough to figure out for itself
whether or not the file being printed is PostScript or ASCII. I've tried
different things, none of which have worked. I've also tried the following C
program that I just wrote, which works fine until it's connected to the print
queue. I've come to the conclusion that the computer is simply ignoring
whatever I tell it, possibly because it's printing through the network.
I set up the print queue using 'lprsetup'. Here's what it created for a
printcap entry.
lp4|4|test:\
:if=/usr/local/bin/psfilter:\
:lf=/usr/adm/lp4err:\
:lp=:\
:of=/usr/local/bin/psfilter:\
:rm=serts:\
:rp=lp:\
:sd=/usr/spool/lpd4:
As far as I can tell, though, a file would be simply sent to the printer
without ever passing through the filter. Am I supposed to reboot or something?
Probably I'm just missing something. I'm not exactly an expert in this stuff.
I'd appreciate any help you can give me.
Thank you,
William Thompson
===============================================================================
/* 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:
* Version 1, 4 August 1994
*/
#include <stdio.h>
#include <string.h>
void main(void)
{
char ch, firsttwo, PSfile;
char savChar[3]; /* 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') {
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);
}
/* 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 unchanged. */
} else fwrite(&ch,sizeof(char),1,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);
}
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help! Can't figure out how to set up print queue.
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
1 sibling, 1 reply; 4+ messages in thread
From: Torbj|rn Lindgren @ 1994-08-05 14:01 UTC (permalink / raw)
In article <31rt75$l7d@paperboy.gsfc.nasa.gov>,
William Thompson <thompson@orpheus.gsfc.nasa.gov> wrote:
>lp4|4|test:\
> :if=/usr/local/bin/psfilter:\
> :lf=/usr/adm/lp4err:\
> :lp=:\
> :of=/usr/local/bin/psfilter:\
> :rm=serts:\
> :rp=lp:\
> :sd=/usr/spool/lpd4:
>
>As far as I can tell, though, a file would be simply sent to the printer
>without ever passing through the filter. Am I supposed to reboot or something?
You're not supposed to use filters on remote printers! The filtering
is done on the remote machine. The file is passed to serts/lp
untouched, where it is processed.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help! Can't figure out how to set up print queue.
1994-08-05 14:01 ` Torbj|rn Lindgren
@ 1994-08-05 14:47 ` William Thompson
0 siblings, 0 replies; 4+ messages in thread
From: William Thompson @ 1994-08-05 14:47 UTC (permalink / raw)
tl@cd.chalmers.se (Torbj|rn Lindgren) writes:
>In article <31rt75$l7d@paperboy.gsfc.nasa.gov>,
>William Thompson <thompson@orpheus.gsfc.nasa.gov> wrote:
>>lp4|4|test:\
>> :if=/usr/local/bin/psfilter:\
>> :lf=/usr/adm/lp4err:\
>> :lp=:\
>> :of=/usr/local/bin/psfilter:\
>> :rm=serts:\
>> :rp=lp:\
>> :sd=/usr/spool/lpd4:
>>
>>As far as I can tell, though, a file would be simply sent to the printer
>>without ever passing through the filter. Am I supposed to reboot or something?
>You're not supposed to use filters on remote printers! The filtering
>is done on the remote machine. The file is passed to serts/lp
>untouched, where it is processed.
But that doesn't make any sense, especially since we're moving towards all
printers being directly on the network. The days of printing via serial or
parallel interfaces is over, as far as we're concerned.
I thought I was missing something. Now at least I know to take this up with
DEC and complain mightily.
Bill Thompson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help! Can't figure out how to set up print queue.
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 17:30 ` William Thompson
1 sibling, 0 replies; 4+ messages in thread
From: William Thompson @ 1994-08-05 17:30 UTC (permalink / raw)
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);
}
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1994-08-05 17:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox