]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/gziptoany.c
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / filter / gziptoany.c
index 9f246bd111ce1f54b7c69b0e904191c12ee3f6de..0eae85ec95ffe0dc9258911b149d2d96137cf9bc 100644 (file)
@@ -1,41 +1,23 @@
 /*
- * "$Id: gziptoany.c 6378 2007-03-21 07:18:18Z mike $"
+ * GZIP/raw pre-filter for CUPS.
  *
- *   GZIP/raw pre-filter for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2015 by Apple Inc.
+ * Copyright 1993-2007 by Easy Software Products.
  *
- *   Copyright 1993-2007 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:
- *
- *   main() - Copy (and uncompress) files to stdout.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <cups/file.h>
-#include <cups/string.h>
-#include <stdlib.h>
-#include <errno.h>
+#include <cups/cups-private.h>
 
 
 /*
@@ -48,7 +30,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
 {
   cups_file_t  *fp;                    /* File */
   char         buffer[8192];           /* Data buffer */
-  int          bytes;                  /* Number of bytes read/written */
+  ssize_t      bytes;                  /* Number of bytes read/written */
   int          copies;                 /* Number of copies */
 
 
@@ -56,9 +38,11 @@ main(int  argc,                              /* I - Number of command-line arguments */
   * Check command-line...
   */
 
-  if (argc != 7)
+  if (argc < 6 || argc > 7)
   {
-    fputs("ERROR: gziptoany job-id user title copies options file\n", stderr);
+    _cupsLangPrintf(stderr,
+                    _("Usage: %s job-id user title copies options [file]"),
+                    argv[0]);
     return (1);
   }
 
@@ -76,10 +60,15 @@ main(int  argc,                             /* I - Number of command-line arguments */
   * Open the file...
   */
 
-  if ((fp = cupsFileOpen(argv[6], "r")) == NULL)
+  if (argc == 6)
+  {
+    copies = 1;
+    fp     = cupsFileStdin();
+  }
+  else if ((fp = cupsFileOpen(argv[6], "r")) == NULL)
   {
-    fprintf(stderr, "ERROR: Unable to open file \"%s\": %s\n", argv[6],
-            strerror(errno));
+    fprintf(stderr, "DEBUG: Unable to open \"%s\".\n", argv[6]);
+    _cupsLangPrintError("ERROR", _("Unable to open print file"));
     return (1);
   }
 
@@ -87,19 +76,21 @@ main(int  argc,                             /* I - Number of command-line arguments */
   * Copy the file to stdout...
   */
 
-  setbuf(stdout, NULL);
-
   while (copies > 0)
   {
+    if (!getenv("FINAL_CONTENT_TYPE"))
+      fputs("PAGE: 1 1\n", stderr);
+
     cupsFileRewind(fp);
 
     while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
-      if (fwrite(buffer, 1, bytes, stdout) < bytes)
+      if (write(1, buffer, (size_t)bytes) < bytes)
       {
-       fprintf(stderr,
-               "ERROR: Unable to write uncompressed document data: %s\n",
-               strerror(ferror(stdout)));
-       cupsFileClose(fp);
+       _cupsLangPrintFilter(stderr, "ERROR",
+                            _("Unable to write uncompressed print data: %s"),
+                            strerror(errno));
+        if (argc == 7)
+         cupsFileClose(fp);
 
        return (1);
       }
@@ -111,12 +102,8 @@ main(int  argc,                            /* I - Number of command-line arguments */
   * Close the file and return...
   */
 
-  cupsFileClose(fp);
+  if (argc == 7)
+    cupsFileClose(fp);
 
   return (0);
 }
-
-
-/*
- * End of "$Id: gziptoany.c 6378 2007-03-21 07:18:18Z mike $".
- */