]>
Commit | Line | Data |
---|---|---|
898749d4 | 1 | /* |
c9d3f842 | 2 | * "$Id$" |
898749d4 | 3 | * |
58ec2a95 | 4 | * HP-GL/2 input processing for the Common UNIX Printing System (CUPS). |
898749d4 | 5 | * |
c9d3f842 | 6 | * Copyright 1993-2005 by Easy Software Products. |
898749d4 | 7 | * |
58ec2a95 | 8 | * These coded instructions, statements, and computer programs are the |
9 | * property of Easy Software Products and are protected by Federal | |
10 | * copyright law. Distribution and use rights are outlined in the file | |
11 | * "LICENSE.txt" which should have been included with this file. If this | |
12 | * file is missing or damaged please contact Easy Software Products | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
a43656fb | 18 | * Hollywood, Maryland 20636 USA |
58ec2a95 | 19 | * |
9639c4de | 20 | * Voice: (301) 373-9600 |
58ec2a95 | 21 | * EMail: cups-info@cups.org |
22 | * WWW: http://www.cups.org | |
898749d4 | 23 | * |
dab1a4d8 | 24 | * This file is subject to the Apple OS-Developed Software exception. |
25 | * | |
898749d4 | 26 | * Contents: |
27 | * | |
28 | * ParseCommand() - Parse an HPGL/2 command. | |
29 | * FreeParameters() - Free all string parameter values. | |
898749d4 | 30 | */ |
31 | ||
32 | /* | |
33 | * Include necessary headers... | |
34 | */ | |
35 | ||
58ec2a95 | 36 | #include "hpgltops.h" |
898749d4 | 37 | #include <ctype.h> |
38 | ||
124b1852 | 39 | #define MAX_PARAMS 16384 |
898749d4 | 40 | |
41 | ||
42 | /* | |
43 | * 'ParseCommand()' - Parse an HPGL/2 command. | |
44 | * | |
98dd54b9 | 45 | * Returns the number of parameters seen or -1 on EOF. |
898749d4 | 46 | */ |
47 | ||
98dd54b9 | 48 | int /* O - -1 on EOF, # params otherwise */ |
49 | ParseCommand(FILE *fp, /* I - File to read from */ | |
50 | char *name, /* O - Name of command */ | |
898749d4 | 51 | param_t **params) /* O - Parameter list */ |
52 | { | |
98dd54b9 | 53 | int num_params, /* Number of parameters seen */ |
54 | ch, /* Current char */ | |
55 | done, /* Non-zero when the current command is read */ | |
56 | i; /* Looping var */ | |
a43656fb | 57 | char buf[262144], /* String buffer */ |
58 | *bufptr; /* Pointer into buffer */ | |
98dd54b9 | 59 | static param_t p[MAX_PARAMS]; /* Parameter buffer */ |
898749d4 | 60 | |
61 | ||
62 | num_params = 0; | |
63 | done = 0; | |
64 | ||
65 | do | |
66 | { | |
98dd54b9 | 67 | while ((ch = getc(fp)) != EOF) |
898749d4 | 68 | if (strchr(" \t\r\n,;", ch) == NULL) |
69 | break; | |
70 | ||
71 | if (ch == EOF) | |
c79d1143 | 72 | { |
898749d4 | 73 | return (-1); |
c79d1143 | 74 | } |
898749d4 | 75 | |
76 | if (ch == 0x1b) | |
98dd54b9 | 77 | switch (getc(fp)) |
898749d4 | 78 | { |
98dd54b9 | 79 | case '.' : /* HP-GL/2 job control */ |
80 | i = getc(fp); | |
81 | ||
898749d4 | 82 | if (strchr(")Z", i) != NULL) |
83 | { | |
84 | /* | |
85 | * 'Printer Off' command - look for next 'Printer On' command... | |
86 | */ | |
98dd54b9 | 87 | |
f6bdbd14 | 88 | for (;;) |
898749d4 | 89 | { |
98dd54b9 | 90 | while ((i = getc(fp)) != EOF && i != 0x1b); |
91 | ||
898749d4 | 92 | if (i == EOF) |
93 | return (-1); | |
94 | ||
98dd54b9 | 95 | if (getc(fp) != '.') |
898749d4 | 96 | continue; |
98dd54b9 | 97 | |
98 | if ((i = getc(fp)) == '(' || | |
898749d4 | 99 | i == 'Y') |
100 | break; | |
98dd54b9 | 101 | } |
898749d4 | 102 | } |
103 | else if (strchr("@HIMNTI\003", i) != NULL) | |
104 | { | |
98dd54b9 | 105 | while ((i = getc(fp)) != EOF && i != ':'); |
106 | } | |
898749d4 | 107 | break; |
108 | ||
6d7dedd5 | 109 | case '%' : /* PJL command? */ |
c79d1143 | 110 | if ((i = getc(fp)) == '-') |
111 | if ((i = getc(fp)) == '1') | |
112 | if ((i = getc(fp)) == '2') | |
113 | { | |
114 | /* | |
115 | * Yes, dump everything up to the "ENTER LANGUAGE" line... | |
116 | */ | |
117 | ||
118 | while (fgets(buf, sizeof(buf), fp) != NULL) | |
119 | if (strstr(buf, "ENTER") && strstr(buf, "LANGUAGE")) | |
120 | break; | |
6d7dedd5 | 121 | break; |
c79d1143 | 122 | } |
123 | ||
124 | ungetc(i, fp); | |
6d7dedd5 | 125 | |
898749d4 | 126 | default : /* HP RTL/PCL control */ |
da275f55 | 127 | while ((i = getc(fp)) != EOF && !isupper(i & 255)); |
898749d4 | 128 | break; |
98dd54b9 | 129 | } |
6d7dedd5 | 130 | } while (ch < ' '); |
898749d4 | 131 | |
132 | name[0] = ch; | |
98dd54b9 | 133 | name[1] = getc(fp); |
898749d4 | 134 | name[2] = '\0'; |
135 | ||
136 | if (strcasecmp(name, "LB") == 0) | |
137 | { | |
a43656fb | 138 | bufptr = buf; |
139 | while ((ch = getc(fp)) != StringTerminator) | |
140 | if (bufptr < (buf + sizeof(buf) - 1)) | |
141 | *bufptr++ = ch; | |
142 | *bufptr = '\0'; | |
143 | ||
98dd54b9 | 144 | p[num_params].type = PARAM_STRING; |
898749d4 | 145 | p[num_params].value.string = strdup(buf); |
146 | num_params ++; | |
147 | } | |
148 | else if (strcasecmp(name, "SM") == 0) | |
149 | { | |
98dd54b9 | 150 | buf[0] = getc(fp); |
898749d4 | 151 | buf[1] = '\0'; |
98dd54b9 | 152 | p[num_params].type = PARAM_STRING; |
898749d4 | 153 | p[num_params].value.string = strdup(buf); |
154 | num_params ++; | |
155 | } | |
156 | else if (strcasecmp(name, "DT") == 0) | |
157 | { | |
98dd54b9 | 158 | if ((buf[0] = getc(fp)) != ';') |
898749d4 | 159 | { |
160 | buf[1] = '\0'; | |
98dd54b9 | 161 | p[num_params].type = PARAM_STRING; |
898749d4 | 162 | p[num_params].value.string = strdup(buf); |
163 | num_params ++; | |
98dd54b9 | 164 | } |
c839cbc9 | 165 | } |
166 | else if (strcasecmp(name, "PE") == 0) | |
167 | { | |
a43656fb | 168 | bufptr = buf; |
169 | while ((ch = getc(fp)) != ';') | |
170 | if (bufptr < (buf + sizeof(buf) - 1)) | |
171 | *bufptr++ = ch; | |
172 | *bufptr = '\0'; | |
c839cbc9 | 173 | |
98dd54b9 | 174 | p[num_params].type = PARAM_STRING; |
c839cbc9 | 175 | p[num_params].value.string = strdup(buf); |
176 | num_params ++; | |
98dd54b9 | 177 | } |
898749d4 | 178 | |
179 | while (!done) | |
98dd54b9 | 180 | switch (ch = getc(fp)) |
898749d4 | 181 | { |
182 | case ',' : | |
183 | case ' ' : | |
184 | case '\n' : | |
185 | case '\r' : | |
186 | case '\t' : | |
187 | break; | |
c839cbc9 | 188 | |
189 | case '\"' : | |
970017a4 | 190 | fscanf(fp, "%262143[^\"]\"", buf); |
124b1852 | 191 | if (num_params < MAX_PARAMS) |
192 | { | |
98dd54b9 | 193 | p[num_params].type = PARAM_STRING; |
124b1852 | 194 | p[num_params].value.string = strdup(buf); |
195 | num_params ++; | |
196 | }; | |
c839cbc9 | 197 | break; |
198 | ||
898749d4 | 199 | case '-' : |
200 | case '+' : | |
98dd54b9 | 201 | ungetc(ch, fp); |
202 | fscanf(fp, "%f", &(p[num_params].value.number)); | |
124b1852 | 203 | if (num_params < MAX_PARAMS) |
204 | { | |
205 | p[num_params].type = PARAM_RELATIVE; | |
206 | num_params ++; | |
98dd54b9 | 207 | } |
898749d4 | 208 | break; |
209 | case '0' : | |
210 | case '1' : | |
211 | case '2' : | |
212 | case '3' : | |
213 | case '4' : | |
214 | case '5' : | |
215 | case '6' : | |
216 | case '7' : | |
217 | case '8' : | |
218 | case '9' : | |
219 | case '.' : | |
98dd54b9 | 220 | ungetc(ch, fp); |
221 | fscanf(fp, "%f", &(p[num_params].value.number)); | |
124b1852 | 222 | if (num_params < MAX_PARAMS) |
223 | { | |
224 | p[num_params].type = PARAM_ABSOLUTE; | |
225 | num_params ++; | |
98dd54b9 | 226 | } |
898749d4 | 227 | break; |
228 | default : | |
98dd54b9 | 229 | ungetc(ch, fp); |
898749d4 | 230 | done = 1; |
231 | break; | |
98dd54b9 | 232 | } |
898749d4 | 233 | |
234 | *params = p; | |
235 | return (num_params); | |
236 | } | |
237 | ||
238 | ||
239 | /* | |
240 | * 'FreeParameters()' - Free all string parameter values. | |
241 | */ | |
242 | ||
243 | void | |
98dd54b9 | 244 | FreeParameters(int num_params, /* I - Number of parameters */ |
245 | param_t *params) /* I - Parameter values */ | |
898749d4 | 246 | { |
98dd54b9 | 247 | int i; /* Looping var */ |
898749d4 | 248 | |
249 | ||
250 | for (i = 0; i < num_params; i ++) | |
251 | if (params[i].type == PARAM_STRING) | |
252 | free(params[i].value.string); | |
253 | } | |
254 | ||
255 | ||
256 | /* | |
c9d3f842 | 257 | * End of "$Id$". |
898749d4 | 258 | */ |