From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f678f,604092d15f8f9cd,start X-Google-Attributes: gidf678f,public X-Google-ArrivalTime: 1994-08-05 04:51:37 PST Path: bga.com!news.sprintlink.net!redstone.interpath.net!ddsw1!news.kei.com!MathWorks.Com!yeshua.marcam.com!usc!elroy.jpl.nasa.gov!ames!newsfeed.gsfc.nasa.gov!orpheus.gsfc.nasa.gov!thompson From: thompson@orpheus.gsfc.nasa.gov (William Thompson) Newsgroups: comp.unix.osf.misc Subject: Help! Can't figure out how to set up print queue. Date: 4 Aug 1994 23:22:13 GMT Organization: NASA Goddard Space Flight Center -- InterNetNews site Message-ID: <31rt75$l7d@paperboy.gsfc.nasa.gov> NNTP-Posting-Host: orpheus.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Newsreader: NN version 6.5.0 #4 (NOV) 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 #include 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 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); } }