@@ -51,6 +51,7 @@ static char Version[] = "$Id: foo2hbpl1.c,v 1.3 2014/03/30 05:08:32 rick Exp $";
5151/*
5252 * Command line options
5353 */
54+ int Copies = 1 ; // [1..999] Page Copies (default=1)
5455int MediaCode = -1 ; // -1=undefined (default to paper)
5556int Model = -1 ; // -1=undefined (default -z0)
5657int pagenum = 0 ; // no pages, no printer codes sent
@@ -118,8 +119,9 @@ usage(void)
118119" 19=color, 20=color (side2),\n"
119120" 21=user, 22=user (side2),\n"
120121" 23=special, 24=special (side2)\n"
121- "-J filename Filename string to send to printer [%s]\n"
122- "-U username Username string to send to printer [%s]\n"
122+ "-n copies Number of copies [%d]\n"
123+ "-J filename Filename string to send to printer [%s]\n"
124+ "-U username Username string to send to printer [%s]\n"
123125"\n"
124126"Printer Tweaking Options:\n"
125127"-u left,top,right,bottom\n"
@@ -130,6 +132,7 @@ usage(void)
130132"\n"
131133"Debugging Options:\n"
132134"-V Version %s\n"
135+ , Copies
133136 , Filename ? Filename : ""
134137 , Username ? Username : ""
135138 , Clip [0 ], Clip [1 ], Clip [2 ], Clip [3 ]
@@ -361,7 +364,7 @@ start_doc(int color)
361364 "@PJL SET JOBATTR=\"@TRAP=ON\"\n"
362365 "@PJL SET JOBATTR=\"@JOAU=%s\"\n"
363366 "@PJL SET JOBATTR=\"@CNAM=%s\"\n"
364- "@PJL SET COPIES=1 \n"
367+ "@PJL SET COPIES=%-2d \n"
365368 "@PJL SET QTY=1\n"
366369 "@PJL SET PAPERDIRECTION=SEF\n"
367370 "@PJL SET RESOLUTION=600\n"
@@ -391,7 +394,8 @@ start_doc(int color)
391394 , mname [MediaCode ]
392395 , color ? "COLOR" : "GRAYSCALE"
393396 , Username ? Username : ""
394- , cname );
397+ , cname
398+ , Copies );
395399 fwrite (reca , 1 , sizeof reca , stdout );
396400
397401 pagenum ++ ; // Now begin printing as "JOB START=1"...
@@ -491,7 +495,7 @@ encode_page(int color, int width, int height, char *image)
491495 head [21 ] = 2 ;
492496 }
493497 width = - (- width & -8 );
494- setle (head + 33 , 4 , pagenum ++ );
498+ setle (head + 33 , 4 , pagenum );
495499 setle (head + 39 , 4 , width );
496500 setle (head + 43 , 4 , height );
497501 setle (head + 70 , 4 , width );
@@ -600,6 +604,7 @@ encode_page(int color, int width, int height, char *image)
600604 }
601605 free (blank - width /8 - 1 );
602606 printf ("SD" );
607+ pagenum += Copies ;
603608}
604609#undef IP
605610#undef CP
@@ -729,10 +734,11 @@ main(int argc, char *argv[])
729734{
730735 int c , i ;
731736
732- while ( (c = getopt (argc , argv , "m:u:z:J:U:V" )) != EOF )
737+ while ( (c = getopt (argc , argv , "m:n: u:z:J:U:V" )) != EOF )
733738 switch (c )
734739 {
735740 case 'm' : MediaCode = atoi (optarg ); break ;
741+ case 'n' : Copies = atoi (optarg ); break ;
736742 case 'u' : if (sscanf (optarg , "%d,%d,%d,%d" ,
737743 Clip , Clip + 1 , Clip + 2 , Clip + 3 ) != 4 )
738744 error (1 , "Must specify four clipping margins!\n" );
@@ -758,7 +764,10 @@ main(int argc, char *argv[])
758764 else if (MediaCode == 7 ) MediaCode = 1 - 1 ;
759765 }
760766 MediaCode ++ ;
761-
767+ if (Model <= 0 && Copies != 1 )
768+ error (1 , "Illegal value for -n. Must be 1 for -z0 printers!\n" );
769+ if (Copies < 1 || Copies > 999 )
770+ error (1 , "Illegal value for -n%d. Must be a number [1..999]!\n" , Copies );
762771
763772 argc -= optind ;
764773 argv += optind ;
0 commit comments