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