/*
- * "$Id: rastertohp.c 6420 2007-03-30 20:00:59Z mike $"
+ * "$Id: rastertohp.c 7403 2008-03-26 15:23:43Z mike $"
*
* Hewlett-Packard Page Control Language filter for the Common UNIX
* Printing System (CUPS).
*
+ * Copyright 2007-2008 by Apple Inc.
* Copyright 1993-2007 by Easy Software Products.
*
* 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
+ * 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
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*
#include <cups/cups.h>
#include <cups/string.h>
#include <cups/i18n.h>
-#include "raster.h"
+#include <cups/raster.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
ColorBits, /* Number of bits per color */
Feed, /* Number of lines to skip */
Duplex, /* Current duplex mode */
- Page; /* Current page number */
+ 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 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.
- */
-
-#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...
*/
* Set graphics mode...
*/
- if (ppd->model_number == 2)
+ if (ppd && ppd->model_number == 2)
{
/*
* Figure out the number of color planes...
* Allocate memory for a line of graphics...
*/
- Planes[0] = malloc(header->cupsBytesPerLine);
+ if ((Planes[0] = malloc(header->cupsBytesPerLine)) == 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;
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
-OutputLine(cups_page_header_t *header) /* I - Page header */
+OutputLine(cups_page_header2_t *header) /* I - Page header */
{
int plane, /* Current plane */
bytes, /* Bytes to write */
* '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 */
+ int 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 */
/*
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...
*/
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);
* 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);
*/
EndPage();
+
+ if (Canceled)
+ break;
}
/*
/*
- * End of "$Id: rastertohp.c 6420 2007-03-30 20:00:59Z mike $".
+ * End of "$Id: rastertohp.c 7403 2008-03-26 15:23:43Z mike $".
*/