]> git.ipfire.org Git - thirdparty/cups.git/blob - driver/commandtopclx.c
Merge changes from CUPS 1.5.1-r9875.
[thirdparty/cups.git] / driver / commandtopclx.c
1 /*
2 * "$Id$"
3 *
4 * Advanced PCL command filter for CUPS.
5 *
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1993-2005 by Easy Software Products.
8 *
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/".
14 *
15 *
16 * Contents:
17 *
18 * main() - Main entry and command processing.
19 */
20
21 /*
22 * Include necessary headers...
23 */
24
25 #include <cups/cups-private.h>
26 #include "driver.h"
27 #include "data/pcl.h"
28
29
30 /*
31 * 'main()' - Main entry and processing of driver.
32 */
33
34 int /* O - Exit status */
35 main(int argc, /* I - Number of command-line arguments */
36 char *argv[]) /* I - Command-line arguments */
37 {
38 FILE *fp; /* Command file */
39 char line[1024], /* Line from file */
40 *lineptr; /* Pointer into line */
41 int feedpage; /* Feed the page */
42 ppd_file_t *ppd; /* PPD file */
43
44
45 /*
46 * Check for valid arguments...
47 */
48
49 if (argc < 6 || argc > 7)
50 {
51 /*
52 * We don't have the correct number of arguments; write an error message
53 * and return.
54 */
55
56 _cupsLangPrintf(stderr,
57 _("Usage: %s job-id user title copies options [file]"),
58 argv[0]);
59 return (1);
60 }
61
62 /*
63 * Open the PPD file...
64 */
65
66 if ((ppd = ppdOpenFile(getenv("PPD"))) == NULL)
67 {
68 fputs("ERROR: Unable to open PPD file!\n", stderr);
69 return (1);
70 }
71
72 /*
73 * Open the command file as needed...
74 */
75
76 if (argc == 7)
77 {
78 if ((fp = fopen(argv[6], "r")) == NULL)
79 {
80 perror("ERROR: Unable to open command file - ");
81 return (1);
82 }
83 }
84 else
85 fp = stdin;
86
87 /*
88 * Reset the printer...
89 */
90
91 cupsWritePrintData("\033E", 2);
92
93 /*
94 * Read the commands from the file and send the appropriate commands...
95 */
96
97 feedpage = 0;
98
99 while (fgets(line, sizeof(line), fp) != NULL)
100 {
101 /*
102 * Drop trailing newline...
103 */
104
105 lineptr = line + strlen(line) - 1;
106 if (*lineptr == '\n')
107 *lineptr = '\0';
108
109 /*
110 * Skip leading whitespace...
111 */
112
113 for (lineptr = line; isspace(*lineptr); lineptr ++);
114
115 /*
116 * Skip comments and blank lines...
117 */
118
119 if (*lineptr == '#' || !*lineptr)
120 continue;
121
122 /*
123 * Parse the command...
124 */
125
126 if (_cups_strncasecmp(lineptr, "Clean", 5) == 0 &&
127 (ppd->model_number & PCL_INKJET))
128 {
129 /*
130 * Clean heads...
131 */
132
133 cupsWritePrintData("\033&b16WPML \004\000\006\001\004\001\005\001"
134 "\001\004\001\144", 22);
135 }
136 else
137 fprintf(stderr, "ERROR: Invalid printer command \"%s\"!\n", lineptr);
138 }
139
140 /*
141 * Eject the page as needed...
142 */
143
144 if (feedpage)
145 {
146 fputs("PAGE: 1 1\n", stderr);
147
148 putchar(12);
149 }
150
151 /*
152 * Reset the printer...
153 */
154
155 cupsWritePrintData("\033E", 2);
156
157 /*
158 * Close the command file and return...
159 */
160
161 ppdClose(ppd);
162
163 if (fp != stdin)
164 fclose(fp);
165
166 return (0);
167 }
168
169
170 /*
171 * End of "$Id$".
172 */