]> git.ipfire.org Git - thirdparty/cups.git/blame - filter/gziptoany.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / filter / gziptoany.c
CommitLineData
ef416fc2 1/*
7e86f2f6 2 * GZIP/raw pre-filter for CUPS.
ef416fc2 3 *
8e333c29 4 * Copyright 2007-2015 by Apple Inc.
7e86f2f6 5 * Copyright 1993-2007 by Easy Software Products.
ef416fc2 6 *
e3101897 7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
ef416fc2 8 */
9
10/*
11 * Include necessary headers...
12 */
13
71e16022 14#include <cups/cups-private.h>
ef416fc2 15
ef416fc2 16
17/*
f899b121 18 * 'main()' - Copy (and uncompress) files to stdout.
ef416fc2 19 */
20
21int /* O - Exit status */
22main(int argc, /* I - Number of command-line arguments */
23 char *argv[]) /* I - Command-line arguments */
24{
f899b121 25 cups_file_t *fp; /* File */
ef416fc2 26 char buffer[8192]; /* Data buffer */
7e86f2f6 27 ssize_t bytes; /* Number of bytes read/written */
ef416fc2 28 int copies; /* Number of copies */
ef416fc2 29
30
31 /*
32 * Check command-line...
33 */
34
8e333c29 35 if (argc < 6 || argc > 7)
ef416fc2 36 {
0837b7e8 37 _cupsLangPrintf(stderr,
f3c17241 38 _("Usage: %s job-id user title copies options [file]"),
0837b7e8 39 argv[0]);
ef416fc2 40 return (1);
41 }
42
43 /*
f899b121 44 * Get the copy count; if we have no final content type, this is a
45 * raw queue or raw print file, so we need to make copies...
ef416fc2 46 */
47
f899b121 48 if (!getenv("FINAL_CONTENT_TYPE"))
ef416fc2 49 copies = atoi(argv[4]);
50 else
51 copies = 1;
52
53 /*
f899b121 54 * Open the file...
ef416fc2 55 */
56
8e333c29 57 if (argc == 6)
ef416fc2 58 {
8e333c29
MS
59 copies = 1;
60 fp = cupsFileStdin();
61 }
62 else if ((fp = cupsFileOpen(argv[6], "r")) == NULL)
63 {
64 fprintf(stderr, "DEBUG: Unable to open \"%s\".\n", argv[6]);
0837b7e8 65 _cupsLangPrintError("ERROR", _("Unable to open print file"));
ef416fc2 66 return (1);
67 }
68
69 /*
f899b121 70 * Copy the file to stdout...
ef416fc2 71 */
72
ef416fc2 73 while (copies > 0)
74 {
f42414bf 75 if (!getenv("FINAL_CONTENT_TYPE"))
76 fputs("PAGE: 1 1\n", stderr);
77
f899b121 78 cupsFileRewind(fp);
ef416fc2 79
f899b121 80 while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
7e86f2f6 81 if (write(1, buffer, (size_t)bytes) < bytes)
ef416fc2 82 {
0837b7e8
MS
83 _cupsLangPrintFilter(stderr, "ERROR",
84 _("Unable to write uncompressed print data: %s"),
c8fef167 85 strerror(errno));
8e333c29
MS
86 if (argc == 7)
87 cupsFileClose(fp);
ef416fc2 88
89 return (1);
90 }
91
92 copies --;
93 }
94
95 /*
96 * Close the file and return...
97 */
98
8e333c29
MS
99 if (argc == 7)
100 cupsFileClose(fp);
ef416fc2 101
102 return (0);
ef416fc2 103}