]> git.ipfire.org Git - thirdparty/cups.git/blob - filter/gziptoany.c
9adc376fabb1f3911c9f9cab90d90f24f6cf4d89
[thirdparty/cups.git] / filter / gziptoany.c
1 /*
2 * "$Id$"
3 *
4 * GZIP/raw pre-filter for CUPS.
5 *
6 * Copyright 2007-2015 by Apple Inc.
7 * Copyright 1993-2007 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 */
17
18 /*
19 * Include necessary headers...
20 */
21
22 #include <cups/cups-private.h>
23
24
25 /*
26 * 'main()' - Copy (and uncompress) files to stdout.
27 */
28
29 int /* O - Exit status */
30 main(int argc, /* I - Number of command-line arguments */
31 char *argv[]) /* I - Command-line arguments */
32 {
33 cups_file_t *fp; /* File */
34 char buffer[8192]; /* Data buffer */
35 ssize_t bytes; /* Number of bytes read/written */
36 int copies; /* Number of copies */
37
38
39 /*
40 * Check command-line...
41 */
42
43 if (argc < 6 || argc > 7)
44 {
45 _cupsLangPrintf(stderr,
46 _("Usage: %s job-id user title copies options [file]"),
47 argv[0]);
48 return (1);
49 }
50
51 /*
52 * Get the copy count; if we have no final content type, this is a
53 * raw queue or raw print file, so we need to make copies...
54 */
55
56 if (!getenv("FINAL_CONTENT_TYPE"))
57 copies = atoi(argv[4]);
58 else
59 copies = 1;
60
61 /*
62 * Open the file...
63 */
64
65 if (argc == 6)
66 {
67 copies = 1;
68 fp = cupsFileStdin();
69 }
70 else if ((fp = cupsFileOpen(argv[6], "r")) == NULL)
71 {
72 fprintf(stderr, "DEBUG: Unable to open \"%s\".\n", argv[6]);
73 _cupsLangPrintError("ERROR", _("Unable to open print file"));
74 return (1);
75 }
76
77 /*
78 * Copy the file to stdout...
79 */
80
81 while (copies > 0)
82 {
83 if (!getenv("FINAL_CONTENT_TYPE"))
84 fputs("PAGE: 1 1\n", stderr);
85
86 cupsFileRewind(fp);
87
88 while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
89 if (write(1, buffer, (size_t)bytes) < bytes)
90 {
91 _cupsLangPrintFilter(stderr, "ERROR",
92 _("Unable to write uncompressed print data: %s"),
93 strerror(errno));
94 if (argc == 7)
95 cupsFileClose(fp);
96
97 return (1);
98 }
99
100 copies --;
101 }
102
103 /*
104 * Close the file and return...
105 */
106
107 if (argc == 7)
108 cupsFileClose(fp);
109
110 return (0);
111 }
112
113
114 /*
115 * End of "$Id$".
116 */