Article 14004 of alt.sources:
Here's the source code for a filter which sets the NumCopies parameter in
output generated by the Windows device driver for a DEC Laser 5100.  This
program will only work for DEC's device driver and will not work for the
Windows generic postscript driver.  It should be easy to modify it for other
postscript drivers though (look at the switch statement in main()).

It also does a simple PCL (text) to PostScript conversion.  It understands
tabs (every 8 columns), form-feeds, carriage-return, line-feed,
'ESC & a nnn C' (move column relative by +/-nnn) and 'ESC ( s nnn P'
(if nnn=0, set fixed font or if nnn=1, set proportional font).

It is suitable for use as an output filter in a UNIX printcap entry (of=). 
It finds the number of copies to print (and the point size for the PCL to
PostScript conversion) in a file /usr/local/lib/lpfsetup, which should look
like:
	size=12
	copies=100


/* Convert PCL to Postscript, or pass Postscript right through */

#include <stdio.h>

/* Set-up file parameters */
int fontsize=12;	/* Font size */
int ncopies=1;

/* Current PCL state */
int res=720;		/* Resolution (dots per inch) */
int pres=72;		/* Post-script units */
int state=0;		/* Input state */
int num=0;		/* Input number */
int rel=0;
int cursor_y;		/* Cursor y position */
int cursor_x;		/* Cursor x position */
int height;		/* Character height */
int width;		/* Character width */
int lmargin;
int tmargin;

/* Initialize PCL */
izpcl()
 {
 printf("%%!PS-Adobe-2.0\n");
 printf("/#copies %d def\n",ncopies);
 printf("/Courier-Bold findfont %d scalefont setfont\n",fontsize);
 lmargin=res/4;
 tmargin=res/2+res/6;
 cursor_x=0;
 cursor_y=0;
 height=res/6;
 width=res/10;
 }

char line[1024];
int linep=0;

quoteout(s)
char *s;
 {
 int c;
 while(c=*s++)
  if(c=='\\') putchar('\\'), putchar('\\');
  else if(c=='(') putchar('\\'), putchar('(');
  else if(c==')') putchar('\\'), putchar(')');
  else putchar(c);
 }

flshline()
 {
 line[linep]=0;
 if(linep)
  {
  printf("%d %d moveto ",
         (cursor_x+lmargin)*pres/res,
         (res*11-tmargin-cursor_y)*pres/res);
  printf("("); quoteout(line); printf(") show\n");
  }
 cursor_x+=width*linep;
 linep=0;
 }

flshpage()
 {
 flshline();
 printf("showpage\n");
 cursor_y=0;
 }

nextline()
 {
 flshline();
 cursor_y+=height;
 cursor_x=0;
 if(cursor_y>=10*res) flshpage();
 }

pcl(c)
 {
 switch(state)
  {
  case 0:
   if(c>=' ' && c<='~') line[linep++]=c;
   else if(c=='\t') do line[linep++]=' '; while(linep&7);
   else if(c=='\n') nextline();
   else if(c=='\r') { flshline(); cursor_x=0; }
   else if(c=='\f') flshpage();
   else if(c=='\033') state=1;
   break;

  case 1: /* ESC */
   if(c=='&') state=2;
   else if(c=='(') state=3;
   else if(c==')') state=4;
   else if(c=='*') state=5;
   else if(c==27) state=1;
   else state=0;
   break;

  case 2: /* ESC & */
   if(c=='a') state=6, num=0, rel=0;
   else if(c==27) state=1;
   else state=0;
   break;

  case 3: /* ESC ( */
   if(c=='s') state=7, num=0, rel=0;
   else if(c==27) state=1;
   else state=0;
   break;

  case 4: /* ESC ) */

  case 5: /* ESC * */
  
  case 6: /* ESC & a */
   if(c>='0' && c<='9') num=num*10+c-'0';
   else if(c=='C')
    {
    flshline();
    if(rel==0) cursor_x=width*num;
    else if(rel==1) cursor_x+=width*num;
    else if(rel== -1) cursor_x-=width*num;
    state=0;
    }
   else if(c==27) state=1;
   else if(c=='-') rel= -1;
   else if(c=='+') rel=1;
   else state=0;
   break;

  case 7: /* ESC ( s */
   if(c>='0' && c<='9') num=num*10+c-'0';
   else if(c=='-') rel= -1;
   else if(c=='+') rel= 1;
   else if(c==27) state=1;
   else if(c=='P')
    {
    flshline();
    if(num==0) printf("/Courier-Bold findfont %d scalefont setfont\n",fontsize);
    else if(num==1) printf("/Times-Roman findfont %d scalefont setfont\n",fontsize-fontsize/6);
    state=0;
    }
   else state=0;
   break;
  }
 }

pclflsh()
 {
 if(cursor_y) flshpage();
 }

main()
 {
 FILE *f;
 int a, b;
 /* Load configuration */
 f=fopen("/usr/local/lib/lpfsetup","r");
 if(f)
  {
  fscanf(f,"size=%d copies=%d",&fontsize,&ncopies);
  fclose(f);
  }

 a=getchar();
 if(a==4) a=getchar();	/* Windows outputs ^D for some reason */
 b=getchar();
 if(a=='%' && b=='!' || a=='\033' && b=='%')
  { /* Input is postscript.  Pass is right through */
  int state=0;
  putchar(a); putchar(b);
  if(ncopies==1) while((a=getchar())!= -1) putchar(a);
   /* If copies is not 1, look for the sequence 'NumCopies ..... put' and
      replace it with 'NumCopies nnn put' */
  else while((a=getchar())!= -1)
   switch(state)
    {
    case 0: if(a=='N') ++state;
            else putchar(a);
            break;

    case 1: if(a=='u') ++state;
            else fputs("N",stdout), putchar(a), state=0;
            break;

    case 2: if(a=='m') ++state;
            else fputs("Nu",stdout), putchar(a), state=0;
            break;

    case 3: if(a=='C') ++state;
            else fputs("Num",stdout), putchar(a), state=0;
            break;

    case 4: if(a=='o') ++state;
            else fputs("NumC",stdout), putchar(a), state=0;
            break;

    case 5: if(a=='p') ++state;
            else fputs("NumCo",stdout), putchar(a), state=0;
            break;
            
    case 6: if(a=='i') ++state;
            else fputs("NumCop",stdout), putchar(a), state=0;
            break;

    case 7: if(a=='e') ++state;
            else fputs("NumCopi",stdout), putchar(a), state=0;
            break;

    case 8: if(a=='s')
             {
             while((a=getchar())!=-1) if(a=='p') break;
             if(a!=-1) printf("NumCopies %d p",ncopies);
             state=0;
             }
            else fputs("NumCopie",stdout), putchar(a), state=0;
            break;
    }
  }
 else
  { /* Input is PCL.  Give it to PCL interpreter */
  izpcl();
  pcl(a);
  pcl(b);
  while((a=getchar())!= -1) pcl(a);
  pclflsh();
  }
 return 0;
 }
-- 
/*  jhallen@world.std.com (192.74.137.5) */               /* Joseph H. Allen */
int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0)
+r*57)/7,q=q?q-1?q-2?1-p%79?-1:0:p%79-77?1:0:p<1659?79:0:p>158?-79:0,q?!a[p+q*2
]?a[p+=a[p+=q]=q]=q:0:0;for(;q++-1817;)printf(q%79?"%c":"%c\n"," #"[!a[q-1]]);}


