Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
* 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

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