1 /* 2 * GZIP/raw pre-filter for CUPS. 3 * 4 * Copyright 2007-2015 by Apple Inc. 5 * Copyright 1993-2007 by Easy Software Products. 6 * 7 * These coded instructions, statements, and computer programs are the 8 * property of Apple Inc. and are protected by Federal copyright 9 * law. Distribution and use rights are outlined in the file "LICENSE.txt" 10 * which should have been included with this file. If this file is 11 * missing or damaged, see the license at "http://www.cups.org/". 12 * 13 * This file is subject to the Apple OS-Developed Software exception. 14 */ 15 16 /* 17 * Include necessary headers... 18 */ 19 20 #include <cups/cups-private.h> 21 22 23 /* 24 * 'main()' - Copy (and uncompress) files to stdout. 25 */ 26 27 int /* O - Exit status */ 28 main(int argc, /* I - Number of command-line arguments */ 29 char *argv[]) /* I - Command-line arguments */ 30 { 31 cups_file_t *fp; /* File */ 32 char buffer[8192]; /* Data buffer */ 33 ssize_t bytes; /* Number of bytes read/written */ 34 int copies; /* Number of copies */ 35 36 37 /* 38 * Check command-line... 39 */ 40 41 if (argc < 6 || argc > 7) 42 { 43 _cupsLangPrintf(stderr, 44 _("Usage: %s job-id user title copies options [file]"), 45 argv[0]); 46 return (1); 47 } 48 49 /* 50 * Get the copy count; if we have no final content type, this is a 51 * raw queue or raw print file, so we need to make copies... 52 */ 53 54 if (!getenv("FINAL_CONTENT_TYPE")) 55 copies = atoi(argv[4]); 56 else 57 copies = 1; 58 59 /* 60 * Open the file... 61 */ 62 63 if (argc == 6) 64 { 65 copies = 1; 66 fp = cupsFileStdin(); 67 } 68 else if ((fp = cupsFileOpen(argv[6], "r")) == NULL) 69 { 70 fprintf(stderr, "DEBUG: Unable to open \"%s\".\n", argv[6]); 71 _cupsLangPrintError("ERROR", _("Unable to open print file")); 72 return (1); 73 } 74 75 /* 76 * Copy the file to stdout... 77 */ 78 79 while (copies > 0) 80 { 81 if (!getenv("FINAL_CONTENT_TYPE")) 82 fputs("PAGE: 1 1\n", stderr); 83 84 cupsFileRewind(fp); 85 86 while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0) 87 if (write(1, buffer, (size_t)bytes) < bytes) 88 { 89 _cupsLangPrintFilter(stderr, "ERROR", 90 _("Unable to write uncompressed print data: %s"), 91 strerror(errno)); 92 if (argc == 7) 93 cupsFileClose(fp); 94 95 return (1); 96 } 97 98 copies --; 99 } 100 101 /* 102 * Close the file and return... 103 */ 104 105 if (argc == 7) 106 cupsFileClose(fp); 107 108 return (0); 109 } 110