]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/rastertohp.c
Merge changes from CUPS 1.4svn-r7696.
[thirdparty/cups.git] / filter / rastertohp.c
index c2feb39a90dbcf472e87b4af8125fd2c51e06d60..48b0cfcb1dd022bfe717b24502de9124648c8f3b 100644 (file)
@@ -1,26 +1,17 @@
 /*
- * "$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.
  *
@@ -43,7 +34,7 @@
 #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>
@@ -61,7 +52,8 @@ int           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 */
+               Page,                   /* Current page number */
+               Canceled;               /* Has the current job been canceled? */
 
 
 /*
@@ -69,13 +61,13 @@ int         NumPlanes,              /* Number of color planes */
  */
 
 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);
 
 
 /*
@@ -100,31 +92,11 @@ Setup(void)
 
 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...
   */
@@ -286,7 +258,7 @@ StartPage(ppd_file_t         *ppd,  /* I - PPD file */
   * Set graphics mode...
   */
 
-  if (ppd->model_number == 2)
+  if (ppd && ppd->model_number == 2)
   {
    /*
     * Figure out the number of color planes...
@@ -391,7 +363,12 @@ StartPage(ppd_file_t         *ppd, /* I - PPD file */
   * 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;
 
@@ -414,11 +391,6 @@ StartPage(ppd_file_t         *ppd, /* I - PPD file */
 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...
   */
@@ -440,22 +412,6 @@ EndPage(void)
 
   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...
   */
@@ -493,26 +449,9 @@ Shutdown(void)
 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;
 }
 
 
@@ -652,7 +591,7 @@ CompressData(unsigned char *line,   /* I - Data to compress */
  */
 
 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 */
@@ -735,15 +674,18 @@ OutputLine(cups_page_header_t *header)    /* I - Page header */
  * '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 */
 
 
  /*
@@ -786,6 +728,25 @@ main(int  argc,            /* I - Number of command-line arguments */
 
   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...
   */
@@ -800,12 +761,15 @@ main(int  argc,           /* I - Number of command-line arguments */
 
   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);
@@ -826,6 +790,9 @@ main(int  argc,             /* I - Number of command-line arguments */
       * 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);
@@ -853,6 +820,9 @@ main(int  argc,             /* I - Number of command-line arguments */
     */
 
     EndPage();
+
+    if (Canceled)
+      break;
   }
 
  /*
@@ -886,5 +856,5 @@ main(int  argc,             /* I - Number of command-line arguments */
 
 
 /*
- * 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 $".
  */