]> git.ipfire.org Git - thirdparty/cups.git/blob - filter/gziptoany.c
Merge changes from CUPS 1.5svn-r9385.
[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 CUPS.
5 *
6 * Copyright 2007-2010 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/cups-private.h>
27
28
29 /*
30 * 'main()' - Copy (and uncompress) files to stdout.
31 */
32
33 int /* O - Exit status */
34 main(int argc, /* I - Number of command-line arguments */
35 char *argv[]) /* I - Command-line arguments */
36 {
37 cups_file_t *fp; /* File */
38 char buffer[8192]; /* Data buffer */
39 int bytes; /* Number of bytes read/written */
40 int copies; /* Number of copies */
41
42
43 /*
44 * Check command-line...
45 */
46
47 if (argc != 7)
48 {
49 _cupsLangPrintf(stderr,
50 _("Usage: %s job-id user title copies options file"),
51 argv[0]);
52 return (1);
53 }
54
55 /*
56 * Get the copy count; if we have no final content type, this is a
57 * raw queue or raw print file, so we need to make copies...
58 */
59
60 if (!getenv("FINAL_CONTENT_TYPE"))
61 copies = atoi(argv[4]);
62 else
63 copies = 1;
64
65 /*
66 * Open the file...
67 */
68
69 if ((fp = cupsFileOpen(argv[6], "r")) == NULL)
70 {
71 _cupsLangPrintError("ERROR", _("Unable to open print file"));
72 return (1);
73 }
74
75 /*
76 * Copy the file to stdout...
77 */
78
79 setbuf(stdout, NULL);
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 (fwrite(buffer, 1, bytes, stdout) < bytes)
90 {
91 _cupsLangPrintFilter(stderr, "ERROR",
92 _("Unable to write uncompressed print data: %s"),
93 strerror(ferror(stdout)));
94 cupsFileClose(fp);
95
96 return (1);
97 }
98
99 copies --;
100 }
101
102 /*
103 * Close the file and return...
104 */
105
106 cupsFileClose(fp);
107
108 return (0);
109 }
110
111
112 /*
113 * End of "$Id: gziptoany.c 6649 2007-07-11 21:46:42Z mike $".
114 */