]>
git.ipfire.org Git - thirdparty/cups.git/blob - driver/commandtoescpx.c
4 * Advanced EPSON ESC/P 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-private.h>
27 #include "data/escp.h"
31 * 'main()' - Main entry and processing of driver.
34 int /* O - Exit status */
35 main(int argc
, /* I - Number of command-line arguments */
36 char *argv
[]) /* I - Command-line arguments */
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 */
46 * Check for valid arguments...
49 if (argc
< 6 || argc
> 7)
52 * We don't have the correct number of arguments; write an error message
56 _cupsLangPrintf(stderr
,
57 _("Usage: %s job-id user title copies options [file]"),
63 * Open the PPD file...
66 if ((ppd
= ppdOpenFile(getenv("PPD"))) == NULL
)
68 fputs("ERROR: Unable to open PPD file!\n", stderr
);
73 * Open the command file as needed...
78 if ((fp
= fopen(argv
[6], "r")) == NULL
)
80 perror("ERROR: Unable to open command file - ");
88 * Some EPSON printers need an additional command issued at the
89 * beginning of each job to exit from USB "packet" mode...
92 if (ppd
->model_number
& ESCP_USB
)
93 cupsWritePrintData("\000\000\000\033\001@EJL 1284.4\n@EJL \n\033@", 29);
96 * Reset the printer...
99 cupsWritePrintData("\033@", 2);
102 * Enter remote mode...
105 cupsWritePrintData("\033(R\010\000\000REMOTE1", 13);
109 * Read the commands from the file and send the appropriate commands...
112 while (fgets(line
, sizeof(line
), fp
) != NULL
)
115 * Drop trailing newline...
118 lineptr
= line
+ strlen(line
) - 1;
119 if (*lineptr
== '\n')
123 * Skip leading whitespace...
126 for (lineptr
= line
; isspace(*lineptr
); lineptr
++);
129 * Skip comments and blank lines...
132 if (*lineptr
== '#' || !*lineptr
)
136 * Parse the command...
139 if (_cups_strncasecmp(lineptr
, "Clean", 5) == 0)
145 cupsWritePrintData("CH\002\000\000\000", 6);
147 else if (_cups_strncasecmp(lineptr
, "PrintAlignmentPage", 18) == 0)
150 * Print alignment page...
155 phase
= atoi(lineptr
+ 18);
157 cupsWritePrintData("DT\003\000\000", 5);
158 putchar(phase
& 255);
162 else if (_cups_strncasecmp(lineptr
, "PrintSelfTestPage", 17) == 0)
165 * Print version info and nozzle check...
168 cupsWritePrintData("VI\002\000\000\000", 6);
169 cupsWritePrintData("NC\002\000\000\000", 6);
172 else if (_cups_strncasecmp(lineptr
, "ReportLevels", 12) == 0)
175 * Report ink levels...
178 cupsWritePrintData("IQ\001\000\001", 5);
180 else if (_cups_strncasecmp(lineptr
, "SetAlignment", 12) == 0)
183 * Set head alignment...
188 if (sscanf(lineptr
+ 12, "%d%d", &phase
, &x
) != 2)
190 fprintf(stderr
, "ERROR: Invalid printer command \"%s\"!\n", lineptr
);
194 cupsWritePrintData("DA\004\000", 4);
199 cupsWritePrintData("SV\000\000", 4);
202 fprintf(stderr
, "ERROR: Invalid printer command \"%s\"!\n", lineptr
);
206 * Exit remote mode...
209 cupsWritePrintData("\033\000\000\000", 4);
212 * Eject the page as needed...
217 fputs("PAGE: 1 1\n", stderr
);
225 * Reset the printer...
228 cupsWritePrintData("\033@", 2);
231 * Close the command file and return...