4 * Advanced PCL command filter for CUPS.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1993-2005 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
18 * main() - Main entry and command processing.
22 * Include necessary headers...
25 #include <cups/cups.h>
27 #include <cupsfilters/driver.h>
34 * 'main()' - Main entry and processing of driver.
37 int /* O - Exit status */
38 main(int argc, /* I - Number of command-line arguments */
39 char *argv[]) /* I - Command-line arguments */
41 FILE *fp; /* Command file */
42 char line[1024], /* Line from file */
43 *lineptr; /* Pointer into line */
44 int feedpage; /* Feed the page */
45 ppd_file_t *ppd; /* PPD file */
49 * Check for valid arguments...
52 if (argc < 6 || argc > 7)
55 * We don't have the correct number of arguments; write an error message
59 fprintf(stderr, "Usage: %s job-id user title copies options [file]\n",
65 * Open the PPD file...
68 if ((ppd = ppdOpenFile(getenv("PPD"))) == NULL)
70 fputs("ERROR: Unable to open PPD file!\n", stderr);
75 * Open the command file as needed...
80 if ((fp = fopen(argv[6], "r")) == NULL)
82 perror("ERROR: Unable to open command file - ");
90 * Reset the printer...
93 cupsWritePrintData("\033E", 2);
96 * Read the commands from the file and send the appropriate commands...
101 while (fgets(line, sizeof(line), fp) != NULL)
104 * Drop trailing newline...
107 lineptr = line + strlen(line) - 1;
108 if (*lineptr == '\n')
112 * Skip leading whitespace...
115 for (lineptr = line; isspace(*lineptr); lineptr ++);
118 * Skip comments and blank lines...
121 if (*lineptr == '#' || !*lineptr)
125 * Parse the command...
128 if (strncasecmp(lineptr, "Clean", 5) == 0 &&
129 (ppd->model_number & PCL_INKJET))
135 cupsWritePrintData("\033&b16WPML \004\000\006\001\004\001\005\001"
136 "\001\004\001\144", 22);
139 fprintf(stderr, "ERROR: Invalid printer command \"%s\"!\n", lineptr);
143 * Eject the page as needed...
148 fputs("PAGE: 1 1\n", stderr);
154 * Reset the printer...
157 cupsWritePrintData("\033E", 2);
160 * Close the command file and return...