]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/pstops.c
Load cups into easysw/current.
[thirdparty/cups.git] / filter / pstops.c
index f81fcdda3576709a7698e8371e62f2fc0e3afcd8..e887d381bef5edeaa879733bfe860b152c0732ed 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: pstops.c 6247 2007-02-07 20:54:37Z mike $"
+ * "$Id: pstops.c 6649 2007-07-11 21:46:42Z mike $"
  *
  *   PostScript filter for the Common UNIX Printing System (CUPS).
  *
+ *   Copyright 2007 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.
  *
@@ -61,6 +52,7 @@
 #include <math.h>
 #include <cups/file.h>
 #include <cups/array.h>
+#include <cups/i18n.h>
 
 
 /*
@@ -240,7 +232,8 @@ main(int  argc,                             /* I - Number of command-line args */
 
   if (argc < 6 || argc > 7)
   {
-    fputs("ERROR: pstops job-id user title copies options [file]\n", stderr);
+    fprintf(stderr, _("Usage: %s job-id user title copies options [file]\n"),
+            argv[0]);
     return (1);
   }
 
@@ -259,7 +252,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
     if ((fp = cupsFileOpen(argv[6], "r")) == NULL)
     {
-      fprintf(stderr, "ERROR: Unable to open print file \"%s\" - %s\n",
+      fprintf(stderr, _("ERROR: Unable to open file \"%s\" - %s\n"),
               argv[6], strerror(errno));
       return (1);
     }
@@ -271,7 +264,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
   if ((len = cupsFileGetLine(fp, line, sizeof(line))) == 0)
   {
-    fputs("ERROR: Empty print file!\n", stderr);
+    fputs(_("ERROR: Empty print file!\n"), stderr);
     return (1);
   }
 
@@ -405,14 +398,14 @@ add_page(pstops_doc_t *doc,               /* I - Document information */
 
   if (!doc->pages)
   {
-    fprintf(stderr, "EMERG: Unable to allocate memory for pages array: %s\n",
+    fprintf(stderr, _("EMERG: Unable to allocate memory for pages array: %s\n"),
             strerror(errno));
     exit(1);
   }
 
   if ((pageinfo = calloc(1, sizeof(pstops_page_t))) == NULL)
   {
-    fprintf(stderr, "EMERG: Unable to allocate memory for page info: %s\n",
+    fprintf(stderr, _("EMERG: Unable to allocate memory for page info: %s\n"),
             strerror(errno));
     exit(1);
   }
@@ -512,8 +505,12 @@ copy_bytes(cups_file_t *fp,                /* I - File to read from */
 
   if (cupsFileSeek(fp, offset) < 0)
   {
-    fprintf(stderr, "ERROR: Unable to seek to offset " CUPS_LLFMT
-                    " in file - %s\n",
+    fprintf(stderr,
+#ifdef HAVE_LONG_LONG
+            _("ERROR: Unable to seek to offset %lld in file - %s\n"),
+#else
+            _("ERROR: Unable to seek to offset %ld in file - %s\n"),
+#endif /* HAVE_LONG_LONG */
             CUPS_LLCAST offset, strerror(errno));
     return;
   }
@@ -597,7 +594,7 @@ copy_comments(cups_file_t  *fp,             /* I - File to read from */
 
 
       if (saw_pages)
-        fputs("ERROR: Duplicate %%Pages: comment seen!\n", stderr);
+        fputs(_("ERROR: Duplicate %%Pages: comment seen!\n"), stderr);
 
       saw_pages = 1;
 
@@ -644,7 +641,7 @@ copy_comments(cups_file_t  *fp,             /* I - File to read from */
     else if (!strncmp(line, "%%BoundingBox:", 14))
     {
       if (saw_bounding_box)
-        fputs("ERROR: Duplicate %%BoundingBox: comment seen!\n", stderr);
+        fputs(_("ERROR: Duplicate %%BoundingBox: comment seen!\n"), stderr);
       else if (strstr(line + 14, "(atend)"))
       {
        /*
@@ -655,7 +652,7 @@ copy_comments(cups_file_t  *fp,             /* I - File to read from */
                      doc->bounding_box + 1, doc->bounding_box + 2,
                      doc->bounding_box + 3) != 4)
       {
-       fputs("ERROR: Bad %%BoundingBox: comment seen!\n", stderr);
+       fputs(_("ERROR: Bad %%BoundingBox: comment seen!\n"), stderr);
 
        doc->bounding_box[0] = (int)PageLeft;
        doc->bounding_box[1] = (int)PageBottom;
@@ -707,10 +704,10 @@ copy_comments(cups_file_t  *fp,           /* I - File to read from */
   }
 
   if (!saw_bounding_box)
-    fputs("ERROR: No %%BoundingBox: comment in header!\n", stderr);
+    fputs(_("ERROR: No %%BoundingBox: comment in header!\n"), stderr);
 
   if (!saw_pages)
-    fputs("ERROR: No %%Pages: comment in header!\n", stderr);
+    fputs(_("ERROR: No %%Pages: comment in header!\n"), stderr);
 
   if (!saw_for)
     WriteTextComment("For", doc->user);
@@ -937,13 +934,20 @@ copy_dsc(cups_file_t  *fp,                /* I - File to read from */
         ppdEmitJCL(ppd, stdout, doc->job_id, doc->user, doc->title);
 
        puts("%!PS-Adobe-3.0");
-       
-        pageinfo = (pstops_page_t *)cupsArrayFirst(doc->pages);
-       copy_bytes(doc->temp, 0, pageinfo->offset);
 
        number = 0;
       }
 
+     /*
+      * Copy the prolog as needed...
+      */
+
+      if (!number)
+      {
+        pageinfo = (pstops_page_t *)cupsArrayFirst(doc->pages);
+       copy_bytes(doc->temp, 0, pageinfo->offset);
+      }
+
      /*
       * Then copy all of the pages...
       */
@@ -1019,8 +1023,8 @@ copy_non_dsc(cups_file_t  *fp,            /* I - File to read from */
   * that may not print correctly...
   */
 
-  fputs("WARNING: This document does not conform to the Adobe Document "
-        "Structuring Conventions and may not print correctly!\n", stderr);
+  fputs(_("WARNING: This document does not conform to the Adobe Document "
+          "Structuring Conventions and may not print correctly!\n"), stderr);
 
  /*
   * Then write a standard DSC comment section...
@@ -1204,13 +1208,13 @@ copy_page(cups_file_t  *fp,             /* I - File to read from */
 
   if (!parse_text(line + 7, &ptr, label, sizeof(label)))
   {
-    fputs("ERROR: Bad %%Page: comment in file!\n", stderr);
+    fputs(_("ERROR: Bad %%Page: comment in file!\n"), stderr);
     label[0] = '\0';
     number   = doc->page;
   }
   else if (strtol(ptr, &ptr, 10) == LONG_MAX || !isspace(*ptr & 255))
   {
-    fputs("ERROR: Bad %%Page: comment in file!\n", stderr);
+    fputs(_("ERROR: Bad %%Page: comment in file!\n"), stderr);
     number = doc->page;
   }
 
@@ -1238,7 +1242,9 @@ copy_page(cups_file_t  *fp,               /* I - File to read from */
       pageinfo->num_options = cupsAddOption("InputSlot", doc->ap_input_slot,
                                             pageinfo->num_options,
                                            &(pageinfo->options));
-      pageinfo->num_options = cupsAddOption("ManualFeed", doc->ap_manual_feed,
+      pageinfo->num_options = cupsAddOption("ManualFeed",
+                                            doc->ap_input_slot ? "False" :
+                                               doc->ap_manual_feed,
                                             pageinfo->num_options,
                                            &(pageinfo->options));
     }
@@ -1251,7 +1257,9 @@ copy_page(cups_file_t  *fp,               /* I - File to read from */
       pageinfo->num_options = cupsAddOption("InputSlot", doc->input_slot,
                                             pageinfo->num_options,
                                            &(pageinfo->options));
-      pageinfo->num_options = cupsAddOption("ManualFeed", doc->manual_feed,
+      pageinfo->num_options = cupsAddOption("ManualFeed",
+                                            doc->input_slot ? "False" :
+                                               doc->manual_feed,
                                             pageinfo->num_options,
                                            &(pageinfo->options));
     }
@@ -1276,7 +1284,7 @@ copy_page(cups_file_t  *fp,               /* I - File to read from */
                  bounding_box + 1, bounding_box + 2,
                 bounding_box + 3) != 4)
       {
-        fputs("ERROR: Bad %%PageBoundingBox: comment in file!\n", stderr);
+        fputs(_("ERROR: Bad %%PageBoundingBox: comment in file!\n"), stderr);
         memcpy(bounding_box, doc->bounding_box,
               sizeof(bounding_box));
       }
@@ -1530,7 +1538,7 @@ copy_page(cups_file_t  *fp,               /* I - File to read from */
        if (doc->number_up > 1 || doc->fitplot)
          continue;
       }
-      else if (!strncmp(line, "%%EndFeature:", 13))
+      else if (!strncmp(line, "%%EndFeature", 12))
       {
         feature = 0;
 
@@ -1682,7 +1690,7 @@ copy_prolog(cups_file_t  *fp,             /* I - File to read from */
     if (!strncmp(line, "%%EndProlog", 11))
       linelen = cupsFileGetLine(fp, line, linesize);
     else
-      fputs("ERROR: Missing %%EndProlog!\n", stderr);
+      fputs(_("ERROR: Missing %%EndProlog!\n"), stderr);
   }
 
   doc_puts(doc, "%%EndProlog\n");
@@ -1747,7 +1755,7 @@ copy_setup(cups_file_t  *fp,              /* I - File to read from */
     if (!strncmp(line, "%%EndSetup", 10))
       linelen = cupsFileGetLine(fp, line, linesize);
     else
-      fputs("ERROR: Missing %%EndSetup!\n", stderr);
+      fputs(_("ERROR: Missing %%EndSetup!\n"), stderr);
   }
 
   doc_puts(doc, "%%EndSetup\n");
@@ -1986,7 +1994,7 @@ doc_printf(pstops_doc_t *doc,             /* I - Document information */
   if (bytes > sizeof(buffer))
   {
     fprintf(stderr,
-            "ERROR: doc_printf overflow (%d bytes) detected, aborting!\n",
+            _("ERROR: doc_printf overflow (%d bytes) detected, aborting!\n"),
             (int)bytes);
     exit(1);
   }
@@ -2117,7 +2125,7 @@ include_feature(
 
   if (sscanf(line + 17, "%254s%254s", name, value) != 2)
   {
-    fputs("ERROR: Bad %%IncludeFeature: comment!\n", stderr);
+    fputs(_("ERROR: Bad %%IncludeFeature: comment!\n"), stderr);
     return (num_options);
   }
 
@@ -2127,21 +2135,21 @@ include_feature(
 
   if ((option = ppdFindOption(ppd, name + 1)) == NULL)
   {
-    fprintf(stderr, "WARNING: Unknown option \"%s\"!\n", name + 1);
+    fprintf(stderr, _("WARNING: Unknown option \"%s\"!\n"), name + 1);
     return (num_options);
   }
 
   if (option->section == PPD_ORDER_EXIT ||
       option->section == PPD_ORDER_JCL)
   {
-    fprintf(stderr, "WARNING: Option \"%s\" cannot be included via "
-                    "IncludeFeature!\n", name + 1);
+    fprintf(stderr, _("WARNING: Option \"%s\" cannot be included via "
+                      "IncludeFeature!\n"), name + 1);
     return (num_options);
   }
 
   if ((choice = ppdFindChoice(option, value)) == NULL)
   {
-    fprintf(stderr, "WARNING: Unknown choice \"%s\" for option \"%s\"!\n",
+    fprintf(stderr, _("WARNING: Unknown choice \"%s\" for option \"%s\"!\n"),
             value, name + 1);
     return (num_options);
   }
@@ -2314,8 +2322,8 @@ set_pstops_options(
 
     if (intval < 10 || intval > 1000)
     {
-      fprintf(stderr, "ERROR: Unsupported brightness value %s, using "
-                      "brightness=100!\n", val);
+      fprintf(stderr, _("ERROR: Unsupported brightness value %s, using "
+                        "brightness=100!\n"), val);
       doc->brightness = 1.0f;
     }
     else
@@ -2381,8 +2389,8 @@ set_pstops_options(
 
     if (intval < 1 || intval > 10000)
     {
-      fprintf(stderr, "ERROR: Unsupported gamma value %s, using "
-                      "gamma=1000!\n", val);
+      fprintf(stderr, _("ERROR: Unsupported gamma value %s, using "
+                        "gamma=1000!\n"), val);
       doc->gamma = 1.0f;
     }
     else
@@ -2405,9 +2413,16 @@ set_pstops_options(
   if ((choice = ppdFindMarkedChoice(ppd, "ManualFeed")) != NULL)
     doc->manual_feed = choice->choice;
 
-  if ((val = cupsGetOption("mirror", num_options, options)) != NULL &&
-      (!strcasecmp(val, "true") || !strcasecmp(val, "on") ||
-       !strcasecmp(val, "yes")))
+  if ((choice = ppdFindMarkedChoice(ppd, "MirrorPrint")) != NULL)
+  {
+    val = choice->choice;
+    choice->marked = 0;
+  }
+  else
+    val = cupsGetOption("mirror", num_options, options);
+
+  if (val && (!strcasecmp(val, "true") || !strcasecmp(val, "on") ||
+              !strcasecmp(val, "yes")))
     doc->mirror = 1;
 
  /*
@@ -2428,8 +2443,8 @@ set_pstops_options(
          break;
       default :
           fprintf(stderr,
-                 "ERROR: Unsupported number-up value %d, using number-up=1!\n",
-                 intval);
+                 _("ERROR: Unsupported number-up value %d, using "
+                   "number-up=1!\n"), intval);
           doc->number_up = 1;
          break;
     }
@@ -2461,8 +2476,8 @@ set_pstops_options(
       doc->number_up_layout = PSTOPS_LAYOUT_BTRL;
     else
     {
-      fprintf(stderr, "ERROR: Unsupported number-up-layout value %s, using "
-                      "number-up-layout=lrtb!\n", val);
+      fprintf(stderr, _("ERROR: Unsupported number-up-layout value %s, using "
+                        "number-up-layout=lrtb!\n"), val);
       doc->number_up_layout = PSTOPS_LAYOUT_LRTB;
     }
   }
@@ -2511,8 +2526,8 @@ set_pstops_options(
       doc->page_border = PSTOPS_BORDERDOUBLE2;
     else
     {
-      fprintf(stderr, "ERROR: Unsupported page-border value %s, using "
-                      "page-border=none!\n", val);
+      fprintf(stderr, _("ERROR: Unsupported page-border value %s, using "
+                        "page-border=none!\n"), val);
       doc->page_border = PSTOPS_BORDERNONE;
     }
   }
@@ -2606,7 +2621,7 @@ set_pstops_options(
     if ((doc->temp = cupsTempFile2(doc->tempfile,
                                    sizeof(doc->tempfile))) == NULL)
     {
-      fprintf(stderr, "ERROR: Unable to create temporary file: %s\n",
+      fprintf(stderr, _("ERROR: Unable to create temporary file: %s\n"),
               strerror(errno));
       exit(1);
     }
@@ -3281,5 +3296,5 @@ write_labels(pstops_doc_t *doc,           /* I - Document information */
 
 
 /*
- * End of "$Id: pstops.c 6247 2007-02-07 20:54:37Z mike $".
+ * End of "$Id: pstops.c 6649 2007-07-11 21:46:42Z mike $".
  */