/*1* GZIP/raw pre-filter for CUPS.2*3* Copyright © 2021 by OpenPrinting.4* Copyright © 2007-2015 by Apple Inc.5* Copyright © 1993-2007 by Easy Software Products.6*7* Licensed under Apache License v2.0. See the file "LICENSE" for more8* information.9*/1011/*12* Include necessary headers...13*/1415#include <cups/cups-private.h>161718/*19* 'main()' - Copy (and uncompress) files to stdout.20*/2122int /* O - Exit status */23main(int argc, /* I - Number of command-line arguments */24char *argv[]) /* I - Command-line arguments */25{26cups_file_t *fp; /* File */27char buffer[8192]; /* Data buffer */28ssize_t bytes; /* Number of bytes read/written */29int copies; /* Number of copies */303132/*33* Check command-line...34*/3536if (argc < 6 || argc > 7)37{38_cupsLangPrintf(stderr,39_("Usage: %s job-id user title copies options [file]"),40argv[0]);41return (1);42}4344/*45* Get the copy count; if we have no final content type, this is a46* raw queue or raw print file, so we need to make copies...47*/4849if (!getenv("FINAL_CONTENT_TYPE"))50{51if ((copies = atoi(argv[4])) < 1)52copies = 1;53}54else55{56copies = 1;57}5859/*60* Open the file...61*/6263if (argc == 6)64{65copies = 1;66fp = cupsFileStdin();67}68else if ((fp = cupsFileOpen(argv[6], "r")) == NULL)69{70fprintf(stderr, "DEBUG: Unable to open \"%s\".\n", argv[6]);71_cupsLangPrintError("ERROR", _("Unable to open print file"));72return (1);73}7475/*76* Copy the file to stdout...77*/7879while (copies > 0)80{81if (!getenv("FINAL_CONTENT_TYPE"))82fputs("PAGE: 1 1\n", stderr);8384cupsFileRewind(fp);8586while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)87if (write(1, buffer, (size_t)bytes) < bytes)88{89_cupsLangPrintFilter(stderr, "ERROR",90_("Unable to write uncompressed print data: %s"),91strerror(errno));92if (argc == 7)93cupsFileClose(fp);9495return (1);96}9798copies --;99}100101/*102* Close the file and return...103*/104105if (argc == 7)106cupsFileClose(fp);107108return (0);109}110111112