]>
Commit | Line | Data |
---|---|---|
ac884b6a MS |
1 | /* |
2 | * "$Id$" | |
3 | * | |
4 | * Advanced EPSON ESC/P command filter for CUPS. | |
5 | * | |
88f9aafc | 6 | * Copyright 2007-2011 by Apple Inc. |
ac884b6a MS |
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 | ||
0837b7e8 | 25 | #include <cups/cups-private.h> |
ac884b6a | 26 | #include "driver.h" |
ac884b6a MS |
27 | #include "data/escp.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 | ||
0837b7e8 MS |
56 | _cupsLangPrintf(stderr, |
57 | _("Usage: %s job-id user title copies options [file]"), | |
58 | argv[0]); | |
ac884b6a MS |
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 | * Some EPSON printers need an additional command issued at the | |
89 | * beginning of each job to exit from USB "packet" mode... | |
90 | */ | |
91 | ||
92 | if (ppd->model_number & ESCP_USB) | |
93 | cupsWritePrintData("\000\000\000\033\001@EJL 1284.4\n@EJL \n\033@", 29); | |
94 | ||
95 | /* | |
96 | * Reset the printer... | |
97 | */ | |
98 | ||
99 | cupsWritePrintData("\033@", 2); | |
100 | ||
101 | /* | |
102 | * Enter remote mode... | |
103 | */ | |
104 | ||
105 | cupsWritePrintData("\033(R\010\000\000REMOTE1", 13); | |
106 | feedpage = 0; | |
107 | ||
108 | /* | |
109 | * Read the commands from the file and send the appropriate commands... | |
110 | */ | |
111 | ||
112 | while (fgets(line, sizeof(line), fp) != NULL) | |
113 | { | |
114 | /* | |
115 | * Drop trailing newline... | |
116 | */ | |
117 | ||
118 | lineptr = line + strlen(line) - 1; | |
119 | if (*lineptr == '\n') | |
120 | *lineptr = '\0'; | |
121 | ||
122 | /* | |
123 | * Skip leading whitespace... | |
124 | */ | |
125 | ||
126 | for (lineptr = line; isspace(*lineptr); lineptr ++); | |
127 | ||
128 | /* | |
129 | * Skip comments and blank lines... | |
130 | */ | |
131 | ||
132 | if (*lineptr == '#' || !*lineptr) | |
133 | continue; | |
134 | ||
135 | /* | |
136 | * Parse the command... | |
137 | */ | |
138 | ||
88f9aafc | 139 | if (_cups_strncasecmp(lineptr, "Clean", 5) == 0) |
ac884b6a MS |
140 | { |
141 | /* | |
142 | * Clean heads... | |
143 | */ | |
144 | ||
145 | cupsWritePrintData("CH\002\000\000\000", 6); | |
146 | } | |
88f9aafc | 147 | else if (_cups_strncasecmp(lineptr, "PrintAlignmentPage", 18) == 0) |
ac884b6a MS |
148 | { |
149 | /* | |
150 | * Print alignment page... | |
151 | */ | |
152 | ||
153 | int phase; | |
154 | ||
155 | phase = atoi(lineptr + 18); | |
156 | ||
157 | cupsWritePrintData("DT\003\000\000", 5); | |
158 | putchar(phase & 255); | |
159 | putchar(phase >> 8); | |
160 | feedpage = 1; | |
161 | } | |
88f9aafc | 162 | else if (_cups_strncasecmp(lineptr, "PrintSelfTestPage", 17) == 0) |
ac884b6a MS |
163 | { |
164 | /* | |
165 | * Print version info and nozzle check... | |
166 | */ | |
167 | ||
168 | cupsWritePrintData("VI\002\000\000\000", 6); | |
169 | cupsWritePrintData("NC\002\000\000\000", 6); | |
170 | feedpage = 1; | |
171 | } | |
88f9aafc | 172 | else if (_cups_strncasecmp(lineptr, "ReportLevels", 12) == 0) |
ac884b6a MS |
173 | { |
174 | /* | |
175 | * Report ink levels... | |
176 | */ | |
177 | ||
178 | cupsWritePrintData("IQ\001\000\001", 5); | |
179 | } | |
88f9aafc | 180 | else if (_cups_strncasecmp(lineptr, "SetAlignment", 12) == 0) |
ac884b6a MS |
181 | { |
182 | /* | |
183 | * Set head alignment... | |
184 | */ | |
185 | ||
186 | int phase, x; | |
187 | ||
188 | if (sscanf(lineptr + 12, "%d%d", &phase, &x) != 2) | |
189 | { | |
190 | fprintf(stderr, "ERROR: Invalid printer command \"%s\"!\n", lineptr); | |
191 | continue; | |
192 | } | |
193 | ||
194 | cupsWritePrintData("DA\004\000", 4); | |
195 | putchar(0); | |
196 | putchar(phase); | |
197 | putchar(0); | |
198 | putchar(x); | |
199 | cupsWritePrintData("SV\000\000", 4); | |
200 | } | |
201 | else | |
202 | fprintf(stderr, "ERROR: Invalid printer command \"%s\"!\n", lineptr); | |
203 | } | |
204 | ||
205 | /* | |
206 | * Exit remote mode... | |
207 | */ | |
208 | ||
209 | cupsWritePrintData("\033\000\000\000", 4); | |
210 | ||
211 | /* | |
212 | * Eject the page as needed... | |
213 | */ | |
214 | ||
215 | if (feedpage) | |
216 | { | |
217 | fputs("PAGE: 1 1\n", stderr); | |
218 | ||
219 | putchar(13); | |
220 | putchar(10); | |
221 | putchar(12); | |
222 | } | |
223 | ||
224 | /* | |
225 | * Reset the printer... | |
226 | */ | |
227 | ||
228 | cupsWritePrintData("\033@", 2); | |
229 | ||
230 | /* | |
231 | * Close the command file and return... | |
232 | */ | |
233 | ||
234 | ppdClose(ppd); | |
235 | ||
236 | if (fp != stdin) | |
237 | fclose(fp); | |
238 | ||
239 | return (0); | |
240 | } | |
241 | ||
242 | ||
243 | /* | |
244 | * End of "$Id$". | |
245 | */ |