]> git.ipfire.org Git - thirdparty/cups.git/blob - filter/gziptoany.c
Load cups into easysw/current.
[thirdparty/cups.git] / filter / gziptoany.c
1 /*
2 * "$Id: gziptoany.c 6649 2007-07-11 21:46:42Z mike $"
3 *
4 * GZIP/raw pre-filter for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 2007 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 * Contents:
18 *
19 * main() - Copy (and uncompress) files to stdout.
20 */
21
22 /*
23 * Include necessary headers...
24 */
25
26 #include <cups/file.h>
27 #include <cups/string.h>
28 #include <cups/i18n.h>
29 #include <stdlib.h>
30 #include <errno.h>
31
32
33 /*
34 * 'main()' - Copy (and uncompress) files to stdout.
35 */
36
37 int /* O - Exit status */
38 main(int argc, /* I - Number of command-line arguments */
39 char *argv[]) /* I - Command-line arguments */
40 {
41 cups_file_t *fp; /* File */
42 char buffer[8192]; /* Data buffer */
43 int bytes; /* Number of bytes read/written */
44 int copies; /* Number of copies */
45
46
47 /*
48 * Check command-line...
49 */
50
51 if (argc != 7)
52 {
53 fprintf(stderr, _("Usage: %s job-id user title copies options file\n"),
54 argv[0]);
55 return (1);
56 }
57
58 /*
59 * Get the copy count; if we have no final content type, this is a
60 * raw queue or raw print file, so we need to make copies...
61 */
62
63 if (!getenv("FINAL_CONTENT_TYPE"))
64 copies = atoi(argv[4]);
65 else
66 copies = 1;
67
68 /*
69 * Open the file...
70 */
71
72 if ((fp = cupsFileOpen(argv[6], "r")) == NULL)
73 {
74 fprintf(stderr, _("ERROR: Unable to open file \"%s\": %s\n"), argv[6],
75 strerror(errno));
76 return (1);
77 }
78
79 /*
80 * Copy the file to stdout...
81 */
82
83 setbuf(stdout, NULL);
84
85 while (copies > 0)
86 {
87 if (!getenv("FINAL_CONTENT_TYPE"))
88 fputs("PAGE: 1 1\n", stderr);
89
90 cupsFileRewind(fp);
91
92 while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
93 if (fwrite(buffer, 1, bytes, stdout) < bytes)
94 {
95 fprintf(stderr,
96 _("ERROR: Unable to write uncompressed document data: %s\n"),
97 strerror(ferror(stdout)));
98 cupsFileClose(fp);
99
100 return (1);
101 }
102
103 copies --;
104 }
105
106 /*
107 * Close the file and return...
108 */
109
110 cupsFileClose(fp);
111
112 return (0);
113 }
114
115
116 /*
117 * End of "$Id: gziptoany.c 6649 2007-07-11 21:46:42Z mike $".
118 */