]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/rastertohp.c
Import CUPS v1.7.1
[thirdparty/cups.git] / filter / rastertohp.c
index c2feb39a90dbcf472e87b4af8125fd2c51e06d60..5efad593b09ccf9fc9b93c922a0b98d633b25004 100644 (file)
@@ -1,26 +1,16 @@
 /*
- * "$Id: rastertohp.c 6420 2007-03-30 20:00:59Z mike $"
+ * "$Id: rastertohp.c 10996 2013-05-29 11:51:34Z msweet $"
  *
- *   Hewlett-Packard Page Control Language filter for the Common UNIX
- *   Printing System (CUPS).
+ *   Hewlett-Packard Page Control Language filter for CUPS.
  *
+ *   Copyright 2007-2012 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 <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>
@@ -61,7 +51,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 +60,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,30 +91,10 @@ 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...
@@ -211,6 +182,10 @@ StartPage(ppd_file_t         *ppd, /* I - PPD file */
           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;
@@ -272,10 +247,9 @@ StartPage(ppd_file_t         *ppd, /* I - PPD file */
 
     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 */
     }
   }
@@ -286,7 +260,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 +365,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 +393,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 +414,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 +451,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 +593,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 +676,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 */
 
 
  /*
@@ -763,8 +707,9 @@ main(int  argc,             /* I - Number of command-line arguments */
     * and return.
     */
 
-    fprintf(stderr, _("Usage: %s job-id user title copies options [file]\n"),
-            argv[0]);
+    _cupsLangPrintFilter(stderr, "ERROR",
+                         _("%s job-id user title copies options [file]"),
+                        "rastertohp");
     return (1);
   }
 
@@ -776,7 +721,7 @@ main(int  argc,             /* I - Number of command-line arguments */
   {
     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);
     }
@@ -786,11 +731,44 @@ 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...
   */
 
   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();
 
@@ -800,15 +778,19 @@ 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);
+    _cupsLangPrintFilter(stderr, "INFO", _("Starting page %d."), Page);
 
    /*
     * Start the page...
@@ -826,9 +808,17 @@ 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);
+      {
+        _cupsLangPrintFilter(stderr, "INFO",
+                            _("Printing page %d, %d%% complete."),
+                            Page, 100 * y / header.cupsHeight);
+        fprintf(stderr, "ATTR: job-media-progress=%d\n",
+               100 * y / header.cupsHeight);
+      }
 
      /*
       * Read a line of graphics...
@@ -852,7 +842,12 @@ main(int  argc,            /* I - Number of command-line arguments */
     * Eject the page...
     */
 
+    _cupsLangPrintFilter(stderr, "INFO", _("Finished page %d."), Page);
+
     EndPage();
+
+    if (Canceled)
+      break;
   }
 
  /*
@@ -877,14 +872,15 @@ main(int  argc,           /* I - Number of command-line arguments */
   */
 
   if (Page == 0)
-    fputs(_("ERROR: No pages found!\n"), stderr);
+  {
+    _cupsLangPrintFilter(stderr, "ERROR", _("No pages were found."));
+    return (1);
+  }
   else
-    fputs(_("INFO: Ready to print.\n"), stderr);
-
-  return (Page == 0);
+    return (0);
 }
 
 
 /*
- * End of "$Id: rastertohp.c 6420 2007-03-30 20:00:59Z mike $".
+ * End of "$Id: rastertohp.c 10996 2013-05-29 11:51:34Z msweet $".
  */