]> git.ipfire.org Git - thirdparty/cups.git/blame - filter/gziptoany.c
Load cups into easysw/current.
[thirdparty/cups.git] / filter / gziptoany.c
CommitLineData
ef416fc2 1/*
c0e1af83 2 * "$Id: gziptoany.c 6420 2007-03-30 20:00:59Z mike $"
ef416fc2 3 *
f899b121 4 * GZIP/raw pre-filter for the Common UNIX Printing System (CUPS).
ef416fc2 5 *
f899b121 6 * Copyright 1993-2007 by Easy Software Products.
ef416fc2 7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * This file is subject to the Apple OS-Developed Software exception.
25 *
26 * Contents:
27 *
f899b121 28 * main() - Copy (and uncompress) files to stdout.
ef416fc2 29 */
30
31/*
32 * Include necessary headers...
33 */
34
f899b121 35#include <cups/file.h>
ef416fc2 36#include <cups/string.h>
c0e1af83 37#include <cups/i18n.h>
ef416fc2 38#include <stdlib.h>
39#include <errno.h>
40
ef416fc2 41
42/*
f899b121 43 * 'main()' - Copy (and uncompress) files to stdout.
ef416fc2 44 */
45
46int /* O - Exit status */
47main(int argc, /* I - Number of command-line arguments */
48 char *argv[]) /* I - Command-line arguments */
49{
f899b121 50 cups_file_t *fp; /* File */
ef416fc2 51 char buffer[8192]; /* Data buffer */
52 int bytes; /* Number of bytes read/written */
53 int copies; /* Number of copies */
ef416fc2 54
55
56 /*
57 * Check command-line...
58 */
59
60 if (argc != 7)
61 {
c0e1af83 62 fprintf(stderr, _("Usage: %s job-id user title copies options file\n"),
63 argv[0]);
ef416fc2 64 return (1);
65 }
66
67 /*
f899b121 68 * Get the copy count; if we have no final content type, this is a
69 * raw queue or raw print file, so we need to make copies...
ef416fc2 70 */
71
f899b121 72 if (!getenv("FINAL_CONTENT_TYPE"))
ef416fc2 73 copies = atoi(argv[4]);
74 else
75 copies = 1;
76
77 /*
f899b121 78 * Open the file...
ef416fc2 79 */
80
f899b121 81 if ((fp = cupsFileOpen(argv[6], "r")) == NULL)
ef416fc2 82 {
c0e1af83 83 fprintf(stderr, _("ERROR: Unable to open file \"%s\": %s\n"), argv[6],
f899b121 84 strerror(errno));
ef416fc2 85 return (1);
86 }
87
88 /*
f899b121 89 * Copy the file to stdout...
ef416fc2 90 */
91
92 setbuf(stdout, NULL);
93
94 while (copies > 0)
95 {
f42414bf 96 if (!getenv("FINAL_CONTENT_TYPE"))
97 fputs("PAGE: 1 1\n", stderr);
98
f899b121 99 cupsFileRewind(fp);
ef416fc2 100
f899b121 101 while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
ef416fc2 102 if (fwrite(buffer, 1, bytes, stdout) < bytes)
103 {
f899b121 104 fprintf(stderr,
c0e1af83 105 _("ERROR: Unable to write uncompressed document data: %s\n"),
ef416fc2 106 strerror(ferror(stdout)));
f899b121 107 cupsFileClose(fp);
ef416fc2 108
109 return (1);
110 }
111
112 copies --;
113 }
114
115 /*
116 * Close the file and return...
117 */
118
f899b121 119 cupsFileClose(fp);
ef416fc2 120
121 return (0);
ef416fc2 122}
123
124
125/*
c0e1af83 126 * End of "$Id: gziptoany.c 6420 2007-03-30 20:00:59Z mike $".
ef416fc2 127 */