• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
8  */
9 
10 /*
11  * Include necessary headers...
12  */
13 
14 #include <cups/cups-private.h>
15 
16 
17 /*
18  * 'main()' - Copy (and uncompress) files to stdout.
19  */
20 
21 int					/* O - Exit status */
main(int argc,char * argv[])22 main(int  argc,				/* I - Number of command-line arguments */
23      char *argv[])			/* I - Command-line arguments */
24 {
25   cups_file_t	*fp;			/* File */
26   char		buffer[8192];		/* Data buffer */
27   ssize_t	bytes;			/* Number of bytes read/written */
28   int		copies;			/* Number of copies */
29 
30 
31  /*
32   * Check command-line...
33   */
34 
35   if (argc < 6 || argc > 7)
36   {
37     _cupsLangPrintf(stderr,
38                     _("Usage: %s job-id user title copies options [file]"),
39                     argv[0]);
40     return (1);
41   }
42 
43  /*
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...
46   */
47 
48   if (!getenv("FINAL_CONTENT_TYPE"))
49     copies = atoi(argv[4]);
50   else
51     copies = 1;
52 
53  /*
54   * Open the file...
55   */
56 
57   if (argc == 6)
58   {
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]);
65     _cupsLangPrintError("ERROR", _("Unable to open print file"));
66     return (1);
67   }
68 
69  /*
70   * Copy the file to stdout...
71   */
72 
73   while (copies > 0)
74   {
75     if (!getenv("FINAL_CONTENT_TYPE"))
76       fputs("PAGE: 1 1\n", stderr);
77 
78     cupsFileRewind(fp);
79 
80     while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
81       if (write(1, buffer, (size_t)bytes) < bytes)
82       {
83 	_cupsLangPrintFilter(stderr, "ERROR",
84 			     _("Unable to write uncompressed print data: %s"),
85 			     strerror(errno));
86         if (argc == 7)
87 	  cupsFileClose(fp);
88 
89 	return (1);
90       }
91 
92     copies --;
93   }
94 
95  /*
96   * Close the file and return...
97   */
98 
99   if (argc == 7)
100     cupsFileClose(fp);
101 
102   return (0);
103 }
104