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