/*
- * "$Id$"
+ * Hewlett-Packard Page Control Language filter for CUPS.
*
- * Hewlett-Packard Page Control Language filter for the Common UNIX
- * Printing System (CUPS).
+ * Copyright 2007-2015 by Apple Inc.
+ * Copyright 1993-2007 by Easy Software Products.
*
- * Copyright 1993-2005 by Easy Software Products.
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * missing or damaged, see the license at "http://www.cups.org/".
*
- * These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
- *
- * This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- * Setup() - Prepare the printer for printing.
- * StartPage() - Start a page of graphics.
- * EndPage() - Finish a page of graphics.
- * Shutdown() - Shutdown the printer.
- * CancelJob() - Cancel the current job...
- * CompressData() - Compress a line of graphics.
- * OutputLine() - Output a line of graphics.
- * main() - Main entry and processing of driver.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
*/
#include <cups/cups.h>
-#include <cups/string.h>
-#include "raster.h"
-#include <stdlib.h>
+#include <cups/ppd.h>
+#include <cups/string-private.h>
+#include <cups/language-private.h>
+#include <cups/raster.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
unsigned char *Planes[4], /* Output buffers */
*CompBuffer, /* Compression buffer */
*BitBuffer; /* Buffer for output bits */
-int NumPlanes, /* Number of color planes */
+unsigned NumPlanes, /* Number of color planes */
ColorBits, /* Number of bits per color */
- Feed, /* Number of lines to skip */
- Duplex, /* Current duplex mode */
- Page; /* Current page number */
+ Feed; /* Number of lines to skip */
+int Duplex, /* Current duplex mode */
+ Page, /* Current page number */
+ Canceled; /* Has the current job been canceled? */
/*
*/
void Setup(void);
-void StartPage(ppd_file_t *ppd, cups_page_header_t *header);
+void StartPage(ppd_file_t *ppd, cups_page_header2_t *header);
void EndPage(void);
void Shutdown(void);
void CancelJob(int sig);
-void CompressData(unsigned char *line, int length, int plane, int type);
-void OutputLine(cups_page_header_t *header);
+void CompressData(unsigned char *line, unsigned length, unsigned plane, unsigned type);
+void OutputLine(cups_page_header2_t *header);
/*
void
StartPage(ppd_file_t *ppd, /* I - PPD file */
- cups_page_header_t *header) /* I - Page header */
+ cups_page_header2_t *header) /* I - Page header */
{
- int plane; /* Looping var */
-#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
- struct sigaction action; /* Actions for POSIX signals */
-#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
-
-
- /*
- * Register a signal handler to eject the current page if the
- * job is cancelled.
- */
+ unsigned plane; /* Looping var */
-#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
- sigset(SIGTERM, CancelJob);
-#elif defined(HAVE_SIGACTION)
- memset(&action, 0, sizeof(action));
-
- sigemptyset(&action.sa_mask);
- action.sa_handler = CancelJob;
- sigaction(SIGTERM, &action, NULL);
-#else
- signal(SIGTERM, CancelJob);
-#endif /* HAVE_SIGSET */
/*
* Show page device dictionary...
*/
fprintf(stderr, "DEBUG: StartPage...\n");
- fprintf(stderr, "DEBUG: MediaClass = \"%s\"\n", header->MediaClass);
- fprintf(stderr, "DEBUG: MediaColor = \"%s\"\n", header->MediaColor);
- fprintf(stderr, "DEBUG: MediaType = \"%s\"\n", header->MediaType);
- fprintf(stderr, "DEBUG: OutputType = \"%s\"\n", header->OutputType);
-
- fprintf(stderr, "DEBUG: AdvanceDistance = %d\n", header->AdvanceDistance);
- fprintf(stderr, "DEBUG: AdvanceMedia = %d\n", header->AdvanceMedia);
- fprintf(stderr, "DEBUG: Collate = %d\n", header->Collate);
- fprintf(stderr, "DEBUG: CutMedia = %d\n", header->CutMedia);
fprintf(stderr, "DEBUG: Duplex = %d\n", header->Duplex);
- fprintf(stderr, "DEBUG: HWResolution = [ %d %d ]\n", header->HWResolution[0],
- header->HWResolution[1]);
- fprintf(stderr, "DEBUG: ImagingBoundingBox = [ %d %d %d %d ]\n",
- header->ImagingBoundingBox[0], header->ImagingBoundingBox[1],
- header->ImagingBoundingBox[2], header->ImagingBoundingBox[3]);
- fprintf(stderr, "DEBUG: InsertSheet = %d\n", header->InsertSheet);
- fprintf(stderr, "DEBUG: Jog = %d\n", header->Jog);
- fprintf(stderr, "DEBUG: LeadingEdge = %d\n", header->LeadingEdge);
- fprintf(stderr, "DEBUG: Margins = [ %d %d ]\n", header->Margins[0],
- header->Margins[1]);
+ fprintf(stderr, "DEBUG: HWResolution = [ %d %d ]\n", header->HWResolution[0], header->HWResolution[1]);
+ fprintf(stderr, "DEBUG: ImagingBoundingBox = [ %d %d %d %d ]\n", header->ImagingBoundingBox[0], header->ImagingBoundingBox[1], header->ImagingBoundingBox[2], header->ImagingBoundingBox[3]);
+ fprintf(stderr, "DEBUG: Margins = [ %d %d ]\n", header->Margins[0], header->Margins[1]);
fprintf(stderr, "DEBUG: ManualFeed = %d\n", header->ManualFeed);
fprintf(stderr, "DEBUG: MediaPosition = %d\n", header->MediaPosition);
- fprintf(stderr, "DEBUG: MediaWeight = %d\n", header->MediaWeight);
- fprintf(stderr, "DEBUG: MirrorPrint = %d\n", header->MirrorPrint);
- fprintf(stderr, "DEBUG: NegativePrint = %d\n", header->NegativePrint);
fprintf(stderr, "DEBUG: NumCopies = %d\n", header->NumCopies);
fprintf(stderr, "DEBUG: Orientation = %d\n", header->Orientation);
- fprintf(stderr, "DEBUG: OutputFaceUp = %d\n", header->OutputFaceUp);
- fprintf(stderr, "DEBUG: PageSize = [ %d %d ]\n", header->PageSize[0],
- header->PageSize[1]);
- fprintf(stderr, "DEBUG: Separations = %d\n", header->Separations);
- fprintf(stderr, "DEBUG: TraySwitch = %d\n", header->TraySwitch);
- fprintf(stderr, "DEBUG: Tumble = %d\n", header->Tumble);
+ fprintf(stderr, "DEBUG: PageSize = [ %d %d ]\n", header->PageSize[0], header->PageSize[1]);
fprintf(stderr, "DEBUG: cupsWidth = %d\n", header->cupsWidth);
fprintf(stderr, "DEBUG: cupsHeight = %d\n", header->cupsHeight);
fprintf(stderr, "DEBUG: cupsMediaType = %d\n", header->cupsMediaType);
printf("\033&l80A"); /* Set page size */
break;
+ case 595 : /* A5 */
+ printf("\033&l25A"); /* Set page size */
+ break;
+
case 624 : /* DL Envelope */
printf("\033&l90A"); /* Set page size */
break;
if (!ppd || ppd->model_number != 2)
{
- if (header->Duplex)
- printf("\033&l%dS", /* Set duplex mode */
- header->Duplex + header->Tumble);
+ int mode = Duplex ? 1 + header->Tumble != 0 : 0;
+ printf("\033&l%dS", mode); /* Set duplex mode */
printf("\033&l0L"); /* Turn off perforation skip */
}
}
* Set graphics mode...
*/
- if (ppd->model_number == 2)
+ if (ppd && ppd->model_number == 2)
{
/*
* Figure out the number of color planes...
printf("\033*g26W");
putchar(2); /* Format 2 */
- putchar(NumPlanes); /* Output planes */
+ putchar((int)NumPlanes); /* Output planes */
- putchar(header->HWResolution[0] >> 8); /* Black resolution */
- putchar(header->HWResolution[0]);
- putchar(header->HWResolution[1] >> 8);
- putchar(header->HWResolution[1]);
+ putchar((int)(header->HWResolution[0] >> 8));/* Black resolution */
+ putchar((int)header->HWResolution[0]);
+ putchar((int)(header->HWResolution[1] >> 8));
+ putchar((int)header->HWResolution[1]);
putchar(0);
putchar(1 << ColorBits); /* # of black levels */
- putchar(header->HWResolution[0] >> 8); /* Cyan resolution */
- putchar(header->HWResolution[0]);
- putchar(header->HWResolution[1] >> 8);
- putchar(header->HWResolution[1]);
+ putchar((int)(header->HWResolution[0] >> 8));/* Cyan resolution */
+ putchar((int)header->HWResolution[0]);
+ putchar((int)(header->HWResolution[1] >> 8));
+ putchar((int)header->HWResolution[1]);
putchar(0);
putchar(1 << ColorBits); /* # of cyan levels */
- putchar(header->HWResolution[0] >> 8); /* Magenta resolution */
- putchar(header->HWResolution[0]);
- putchar(header->HWResolution[1] >> 8);
- putchar(header->HWResolution[1]);
+ putchar((int)(header->HWResolution[0] >> 8));/* Magenta resolution */
+ putchar((int)header->HWResolution[0]);
+ putchar((int)(header->HWResolution[1] >> 8));
+ putchar((int)header->HWResolution[1]);
putchar(0);
putchar(1 << ColorBits); /* # of magenta levels */
- putchar(header->HWResolution[0] >> 8); /* Yellow resolution */
- putchar(header->HWResolution[0]);
- putchar(header->HWResolution[1] >> 8);
- putchar(header->HWResolution[1]);
+ putchar((int)(header->HWResolution[0] >> 8));/* Yellow resolution */
+ putchar((int)header->HWResolution[0]);
+ putchar((int)(header->HWResolution[1] >> 8));
+ putchar((int)header->HWResolution[1]);
putchar(0);
putchar(1 << ColorBits); /* # of yellow levels */
}
else
{
- printf("\033*t%dR", header->HWResolution[0]);
+ printf("\033*t%uR", header->HWResolution[0]);
/* Set resolution */
if (header->cupsColorSpace == CUPS_CSPACE_KCMY)
* Set size and position of graphics...
*/
- printf("\033*r%dS", header->cupsWidth); /* Set width */
- printf("\033*r%dT", header->cupsHeight); /* Set height */
+ printf("\033*r%uS", header->cupsWidth); /* Set width */
+ printf("\033*r%uT", header->cupsHeight); /* Set height */
printf("\033&a0H"); /* Set horizontal position */
printf("\033*r1A"); /* Start graphics */
if (header->cupsCompression)
- printf("\033*b%dM", /* Set compression */
+ printf("\033*b%uM", /* Set compression */
header->cupsCompression);
Feed = 0; /* No blank lines yet */
* Allocate memory for a line of graphics...
*/
- Planes[0] = malloc(header->cupsBytesPerLine);
+ if ((Planes[0] = malloc(header->cupsBytesPerLine + NumPlanes)) == NULL)
+ {
+ fputs("ERROR: Unable to allocate memory\n", stderr);
+ exit(1);
+ }
+
for (plane = 1; plane < NumPlanes; plane ++)
Planes[plane] = Planes[0] + plane * header->cupsBytesPerLine / NumPlanes;
BitBuffer = NULL;
if (header->cupsCompression)
- CompBuffer = malloc(header->cupsBytesPerLine * 2);
+ CompBuffer = malloc(header->cupsBytesPerLine * 2 + 2);
else
CompBuffer = NULL;
}
void
EndPage(void)
{
-#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
- struct sigaction action; /* Actions for POSIX signals */
-#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
-
-
/*
* Eject the current page...
*/
fflush(stdout);
- /*
- * Unregister the signal handler...
- */
-
-#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
- sigset(SIGTERM, SIG_IGN);
-#elif defined(HAVE_SIGACTION)
- memset(&action, 0, sizeof(action));
-
- sigemptyset(&action.sa_mask);
- action.sa_handler = SIG_IGN;
- sigaction(SIGTERM, &action, NULL);
-#else
- signal(SIGTERM, SIG_IGN);
-#endif /* HAVE_SIGSET */
-
/*
* Free memory...
*/
void
CancelJob(int sig) /* I - Signal */
{
- int i; /* Looping var */
-
-
(void)sig;
- /*
- * Send out lots of NUL bytes to clear out any pending raster data...
- */
-
- for (i = 0; i < 600; i ++)
- putchar(0);
-
- /*
- * End the current page and exit...
- */
-
- EndPage();
- Shutdown();
-
- exit(0);
+ Canceled = 1;
}
void
CompressData(unsigned char *line, /* I - Data to compress */
- int length, /* I - Number of bytes */
- int plane, /* I - Color plane */
- int type) /* I - Type of compression */
+ unsigned length, /* I - Number of bytes */
+ unsigned plane, /* I - Color plane */
+ unsigned type) /* I - Type of compression */
{
unsigned char *line_ptr, /* Current byte pointer */
*line_end, /* End-of-line byte pointer */
*comp_ptr, /* Pointer into compression buffer */
*start; /* Start of compression sequence */
- int count; /* Count of bytes for output */
+ unsigned count; /* Count of bytes for output */
switch (type)
count < 256;
count ++);
- comp_ptr[0] = count - 1;
+ comp_ptr[0] = (unsigned char)(count - 1);
comp_ptr[1] = line_ptr[0];
}
count ++;
}
- *comp_ptr++ = 257 - count;
+ *comp_ptr++ = (unsigned char)(257 - count);
*comp_ptr++ = *line_ptr++;
}
else
count ++;
}
- *comp_ptr++ = count - 1;
+ *comp_ptr++ = (unsigned char)(count - 1);
memcpy(comp_ptr, start, count);
comp_ptr += count;
*/
printf("\033*b%d%c", (int)(line_end - line_ptr), plane);
- fwrite(line_ptr, line_end - line_ptr, 1, stdout);
+ fwrite(line_ptr, (size_t)(line_end - line_ptr), 1, stdout);
}
*/
void
-OutputLine(cups_page_header_t *header) /* I - Page header */
+OutputLine(cups_page_header2_t *header) /* I - Page header */
{
- int plane, /* Current plane */
+ unsigned plane, /* Current plane */
bytes, /* Bytes to write */
count; /* Bytes to convert */
unsigned char bit, /* Current plane data */
{
bit = plane_ptr[0];
- bit0 = ((bit & 64) << 1) | ((bit & 16) << 2) | ((bit & 4) << 3) | ((bit & 1) << 4);
- bit1 = (bit & 128) | ((bit & 32) << 1) | ((bit & 8) << 2) | ((bit & 2) << 3);
+ bit0 = (unsigned char)(((bit & 64) << 1) | ((bit & 16) << 2) | ((bit & 4) << 3) | ((bit & 1) << 4));
+ bit1 = (unsigned char)((bit & 128) | ((bit & 32) << 1) | ((bit & 8) << 2) | ((bit & 2) << 3));
if (count > 1)
{
bit = plane_ptr[1];
- bit0 |= (bit & 1) | ((bit & 4) >> 1) | ((bit & 16) >> 2) | ((bit & 64) >> 3);
- bit1 |= ((bit & 2) >> 1) | ((bit & 8) >> 2) | ((bit & 32) >> 3) | ((bit & 128) >> 4);
+ bit0 |= (unsigned char)((bit & 1) | ((bit & 4) >> 1) | ((bit & 16) >> 2) | ((bit & 64) >> 3));
+ bit1 |= (unsigned char)(((bit & 2) >> 1) | ((bit & 8) >> 2) | ((bit & 32) >> 3) | ((bit & 128) >> 4));
}
bit_ptr[0] = bit0;
* 'main()' - Main entry and processing of driver.
*/
-int /* O - Exit status */
-main(int argc, /* I - Number of command-line arguments */
- char *argv[]) /* I - Command-line arguments */
+int /* O - Exit status */
+main(int argc, /* I - Number of command-line arguments */
+ char *argv[]) /* I - Command-line arguments */
{
- int fd; /* File descriptor */
- cups_raster_t *ras; /* Raster stream for printing */
- cups_page_header_t header; /* Page header from file */
- int y; /* Current line */
- ppd_file_t *ppd; /* PPD file */
+ int fd; /* File descriptor */
+ cups_raster_t *ras; /* Raster stream for printing */
+ cups_page_header2_t header; /* Page header from file */
+ unsigned y; /* Current line */
+ ppd_file_t *ppd; /* PPD file */
+#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
+ struct sigaction action; /* Actions for POSIX signals */
+#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
/*
* and return.
*/
- fputs("ERROR: rastertopcl job-id user title copies options [file]\n", stderr);
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("%s job-id user title copies options [file]"),
+ "rastertohp");
return (1);
}
{
if ((fd = open(argv[6], O_RDONLY)) == -1)
{
- perror("ERROR: Unable to open raster file - ");
+ _cupsLangPrintError("ERROR", _("Unable to open raster file"));
sleep(1);
return (1);
}
ras = cupsRasterOpen(fd, CUPS_RASTER_READ);
+ /*
+ * Register a signal handler to eject the current page if the
+ * job is cancelled.
+ */
+
+ Canceled = 0;
+
+#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
+ sigset(SIGTERM, CancelJob);
+#elif defined(HAVE_SIGACTION)
+ memset(&action, 0, sizeof(action));
+
+ sigemptyset(&action.sa_mask);
+ action.sa_handler = CancelJob;
+ sigaction(SIGTERM, &action, NULL);
+#else
+ signal(SIGTERM, CancelJob);
+#endif /* HAVE_SIGSET */
+
/*
* Initialize the print device...
*/
ppd = ppdOpenFile(getenv("PPD"));
+ if (!ppd)
+ {
+ ppd_status_t status; /* PPD error */
+ int linenum; /* Line number */
+
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("The PPD file could not be opened."));
+
+ status = ppdLastError(&linenum);
+
+ fprintf(stderr, "DEBUG: %s on line %d.\n", ppdErrorString(status), linenum);
+
+ return (1);
+ }
Setup();
Page = 0;
- while (cupsRasterReadHeader(ras, &header))
+ while (cupsRasterReadHeader2(ras, &header))
{
/*
* Write a status message with the page number and number of copies.
*/
+ if (Canceled)
+ break;
+
Page ++;
fprintf(stderr, "PAGE: %d %d\n", Page, header.NumCopies);
+ _cupsLangPrintFilter(stderr, "INFO", _("Starting page %d."), Page);
/*
* Start the page...
* Let the user know how far we have progressed...
*/
+ if (Canceled)
+ break;
+
if ((y & 127) == 0)
- fprintf(stderr, "INFO: Printing page %d, %d%% complete...\n", Page,
- 100 * y / header.cupsHeight);
+ {
+ _cupsLangPrintFilter(stderr, "INFO",
+ _("Printing page %d, %u%% complete."),
+ Page, 100 * y / header.cupsHeight);
+ fprintf(stderr, "ATTR: job-media-progress=%u\n",
+ 100 * y / header.cupsHeight);
+ }
/*
* Read a line of graphics...
* Eject the page...
*/
+ _cupsLangPrintFilter(stderr, "INFO", _("Finished page %d."), Page);
+
EndPage();
+
+ if (Canceled)
+ break;
}
/*
*/
if (Page == 0)
- fputs("ERROR: No pages found!\n", stderr);
+ {
+ _cupsLangPrintFilter(stderr, "ERROR", _("No pages were found."));
+ return (1);
+ }
else
- fputs("INFO: " CUPS_SVERSION " is ready to print.\n", stderr);
-
- return (Page == 0);
+ return (0);
}
-
-
-/*
- * End of "$Id$".
- */