]>
git.ipfire.org Git - thirdparty/cups.git/blob - driver/commandtoescpx.c
4 * Advanced EPSON ESC/P command filter for CUPS.
6 * Copyright 2007 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 <cups/string.h>
28 #include "data/escp.h"
32 * 'main()' - Main entry and processing of driver.
35 int /* O - Exit status */
36 main(int argc
, /* I - Number of command-line arguments */
37 char *argv
[]) /* I - Command-line arguments */
39 FILE *fp
; /* Command file */
40 char line
[1024], /* Line from file */
41 *lineptr
; /* Pointer into line */
42 int feedpage
; /* Feed the page */
43 ppd_file_t
*ppd
; /* PPD file */
47 * Check for valid arguments...
50 if (argc
< 6 || argc
> 7)
53 * We don't have the correct number of arguments; write an error message
57 fputs("ERROR: commandtoescpx job-id user title copies options [file]\n", stderr
);
62 * Open the PPD file...
65 if ((ppd
= ppdOpenFile(getenv("PPD"))) == NULL
)
67 fputs("ERROR: Unable to open PPD file!\n", stderr
);
72 * Open the command file as needed...
77 if ((fp
= fopen(argv
[6], "r")) == NULL
)
79 perror("ERROR: Unable to open command file - ");
87 * Some EPSON printers need an additional command issued at the
88 * beginning of each job to exit from USB "packet" mode...
91 if (ppd
->model_number
& ESCP_USB
)
92 cupsWritePrintData("\000\000\000\033\001@EJL 1284.4\n@EJL \n\033@", 29);
95 * Reset the printer...
98 cupsWritePrintData("\033@", 2);
101 * Enter remote mode...
104 cupsWritePrintData("\033(R\010\000\000REMOTE1", 13);
108 * Read the commands from the file and send the appropriate commands...
111 while (fgets(line
, sizeof(line
), fp
) != NULL
)
114 * Drop trailing newline...
117 lineptr
= line
+ strlen(line
) - 1;
118 if (*lineptr
== '\n')
122 * Skip leading whitespace...
125 for (lineptr
= line
; isspace(*lineptr
); lineptr
++);
128 * Skip comments and blank lines...
131 if (*lineptr
== '#' || !*lineptr
)
135 * Parse the command...
138 if (strncasecmp(lineptr
, "Clean", 5) == 0)
144 cupsWritePrintData("CH\002\000\000\000", 6);
146 else if (strncasecmp(lineptr
, "PrintAlignmentPage", 18) == 0)
149 * Print alignment page...
154 phase
= atoi(lineptr
+ 18);
156 cupsWritePrintData("DT\003\000\000", 5);
157 putchar(phase
& 255);
161 else if (strncasecmp(lineptr
, "PrintSelfTestPage", 17) == 0)
164 * Print version info and nozzle check...
167 cupsWritePrintData("VI\002\000\000\000", 6);
168 cupsWritePrintData("NC\002\000\000\000", 6);
171 else if (strncasecmp(lineptr
, "ReportLevels", 12) == 0)
174 * Report ink levels...
177 cupsWritePrintData("IQ\001\000\001", 5);
179 else if (strncasecmp(lineptr
, "SetAlignment", 12) == 0)
182 * Set head alignment...
187 if (sscanf(lineptr
+ 12, "%d%d", &phase
, &x
) != 2)
189 fprintf(stderr
, "ERROR: Invalid printer command \"%s\"!\n", lineptr
);
193 cupsWritePrintData("DA\004\000", 4);
198 cupsWritePrintData("SV\000\000", 4);
201 fprintf(stderr
, "ERROR: Invalid printer command \"%s\"!\n", lineptr
);
205 * Exit remote mode...
208 cupsWritePrintData("\033\000\000\000", 4);
211 * Eject the page as needed...
216 fputs("PAGE: 1 1\n", stderr
);
224 * Reset the printer...
227 cupsWritePrintData("\033@", 2);
230 * Close the command file and return...