]> 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/*
f899b121 2 * "$Id: gziptoany.c 6378 2007-03-21 07:18:18Z 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>
37#include <stdlib.h>
38#include <errno.h>
39
ef416fc2 40
41/*
f899b121 42 * 'main()' - Copy (and uncompress) files to stdout.
ef416fc2 43 */
44
45int /* O - Exit status */
46main(int argc, /* I - Number of command-line arguments */
47 char *argv[]) /* I - Command-line arguments */
48{
f899b121 49 cups_file_t *fp; /* File */
ef416fc2 50 char buffer[8192]; /* Data buffer */
51 int bytes; /* Number of bytes read/written */
52 int copies; /* Number of copies */
ef416fc2 53
54
55 /*
56 * Check command-line...
57 */
58
59 if (argc != 7)
60 {
61 fputs("ERROR: gziptoany job-id user title copies options file\n", stderr);
62 return (1);
63 }
64
65 /*
f899b121 66 * Get the copy count; if we have no final content type, this is a
67 * raw queue or raw print file, so we need to make copies...
ef416fc2 68 */
69
f899b121 70 if (!getenv("FINAL_CONTENT_TYPE"))
ef416fc2 71 copies = atoi(argv[4]);
72 else
73 copies = 1;
74
75 /*
f899b121 76 * Open the file...
ef416fc2 77 */
78
f899b121 79 if ((fp = cupsFileOpen(argv[6], "r")) == NULL)
ef416fc2 80 {
f899b121 81 fprintf(stderr, "ERROR: Unable to open file \"%s\": %s\n", argv[6],
82 strerror(errno));
ef416fc2 83 return (1);
84 }
85
86 /*
f899b121 87 * Copy the file to stdout...
ef416fc2 88 */
89
90 setbuf(stdout, NULL);
91
92 while (copies > 0)
93 {
f899b121 94 cupsFileRewind(fp);
ef416fc2 95
f899b121 96 while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
ef416fc2 97 if (fwrite(buffer, 1, bytes, stdout) < bytes)
98 {
f899b121 99 fprintf(stderr,
100 "ERROR: Unable to write uncompressed document data: %s\n",
ef416fc2 101 strerror(ferror(stdout)));
f899b121 102 cupsFileClose(fp);
ef416fc2 103
104 return (1);
105 }
106
107 copies --;
108 }
109
110 /*
111 * Close the file and return...
112 */
113
f899b121 114 cupsFileClose(fp);
ef416fc2 115
116 return (0);
ef416fc2 117}
118
119
120/*
f899b121 121 * End of "$Id: gziptoany.c 6378 2007-03-21 07:18:18Z mike $".
ef416fc2 122 */