]>
Commit | Line | Data |
---|---|---|
ac884b6a MS |
1 | // |
2 | // "$Id$" | |
3 | // | |
4 | // PPD file compiler definitions for the CUPS PPD Compiler. | |
5 | // | |
d2354e63 | 6 | // Copyright 2007-2009 by Apple Inc. |
ac884b6a MS |
7 | // Copyright 2002-2006 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 | // Contents: | |
16 | // | |
94da7e34 MS |
17 | // ppdcDriver::ppdcDriver() - Create a new printer driver. |
18 | // ppdcDriver::~ppdcDriver() - Destroy a printer driver. | |
19 | // ppdcDriver::find_attr() - Find an attribute. | |
20 | // ppdcDriver::find_group() - Find a group. | |
21 | // ppdcDriver::find_option() - Find an option. | |
97c9a8d7 | 22 | // ppdcDriver::find_option_group() - Find an option and its group. |
94da7e34 MS |
23 | // ppdcDriver::set_custom_size_code() - Set the custom page size code. |
24 | // ppdcDriver::set_default_font() - Set the default font name. | |
25 | // ppdcDriver::set_default_size() - Set the default size name. | |
26 | // ppdcDriver::set_file_name() - Set the full filename. | |
27 | // ppdcDriver::set_manufacturer() - Set the manufacturer name. | |
28 | // ppdcDriver::set_model_name() - Set the model name. | |
29 | // ppdcDriver::set_pc_file_name() - Set the PC filename. | |
30 | // ppdcDriver::set_version() - Set the version string. | |
31 | // ppdcDriver::write_ppd_file() - Write a PPD file... | |
ac884b6a MS |
32 | // |
33 | ||
34 | // | |
35 | // Include necessary headers... | |
36 | // | |
37 | ||
38e73f87 | 38 | #include "ppdc-private.h" |
61cf44e2 | 39 | #include <cups/globals.h> |
ac884b6a MS |
40 | |
41 | ||
42 | // | |
43 | // 'ppdcDriver::ppdcDriver()' - Create a new printer driver. | |
44 | // | |
45 | ||
46 | ppdcDriver::ppdcDriver(ppdcDriver *d) // I - Printer driver template | |
94da7e34 | 47 | : ppdcShared() |
ac884b6a MS |
48 | { |
49 | ppdcGroup *g; // Current group | |
50 | ||
51 | ||
94da7e34 MS |
52 | PPDC_NEW; |
53 | ||
ac884b6a MS |
54 | if (d) |
55 | { | |
56 | // Bump the use count of any strings we inherit... | |
57 | if (d->manufacturer) | |
e4572d57 | 58 | d->manufacturer->retain(); |
ac884b6a | 59 | if (d->version) |
e4572d57 | 60 | d->version->retain(); |
ac884b6a | 61 | if (d->default_font) |
e4572d57 | 62 | d->default_font->retain(); |
ac884b6a | 63 | if (d->default_size) |
e4572d57 | 64 | d->default_size->retain(); |
ac884b6a | 65 | if (d->custom_size_code) |
e4572d57 | 66 | d->custom_size_code->retain(); |
ac884b6a MS |
67 | |
68 | // Copy all of the data from the driver template... | |
69 | copyright = new ppdcArray(d->copyright); | |
70 | manufacturer = d->manufacturer; | |
71 | model_name = 0; | |
bdd6c45b | 72 | file_name = 0; |
ac884b6a MS |
73 | pc_file_name = 0; |
74 | type = d->type; | |
75 | version = d->version; | |
76 | model_number = d->model_number; | |
77 | manual_copies = d->manual_copies; | |
78 | color_device = d->color_device; | |
79 | throughput = d->throughput; | |
80 | attrs = new ppdcArray(d->attrs); | |
81 | constraints = new ppdcArray(d->constraints); | |
82 | filters = new ppdcArray(d->filters); | |
83 | fonts = new ppdcArray(d->fonts); | |
84 | profiles = new ppdcArray(d->profiles); | |
85 | sizes = new ppdcArray(d->sizes); | |
86 | default_font = d->default_font; | |
87 | default_size = d->default_size; | |
88 | variable_paper_size = d->variable_paper_size; | |
89 | custom_size_code = d->custom_size_code; | |
90 | left_margin = d->left_margin; | |
91 | bottom_margin = d->bottom_margin; | |
92 | right_margin = d->right_margin; | |
93 | top_margin = d->top_margin; | |
94 | max_width = d->max_width; | |
95 | max_length = d->max_length; | |
96 | min_width = d->min_width; | |
97 | min_length = d->min_length; | |
98 | ||
99 | // Then copy the groups manually, since we want separate copies | |
100 | // of the groups and options... | |
101 | groups = new ppdcArray(); | |
102 | ||
103 | for (g = (ppdcGroup *)d->groups->first(); g; g = (ppdcGroup *)d->groups->next()) | |
104 | groups->add(new ppdcGroup(g)); | |
105 | } | |
106 | else | |
107 | { | |
108 | // Zero all of the data in the driver... | |
109 | copyright = new ppdcArray(); | |
110 | manufacturer = 0; | |
111 | model_name = 0; | |
bdd6c45b | 112 | file_name = 0; |
ac884b6a MS |
113 | pc_file_name = 0; |
114 | version = 0; | |
115 | type = PPDC_DRIVER_CUSTOM; | |
116 | model_number = 0; | |
117 | manual_copies = 0; | |
118 | color_device = 0; | |
119 | throughput = 1; | |
120 | attrs = new ppdcArray(); | |
121 | constraints = new ppdcArray(); | |
122 | fonts = new ppdcArray(); | |
123 | filters = new ppdcArray(); | |
124 | groups = new ppdcArray(); | |
125 | profiles = new ppdcArray(); | |
126 | sizes = new ppdcArray(); | |
127 | default_font = 0; | |
128 | default_size = 0; | |
129 | variable_paper_size = 0; | |
130 | custom_size_code = 0; | |
131 | left_margin = 0; | |
132 | bottom_margin = 0; | |
133 | right_margin = 0; | |
134 | top_margin = 0; | |
135 | max_width = 0; | |
136 | max_length = 0; | |
137 | min_width = 0; | |
138 | min_length = 0; | |
139 | } | |
140 | } | |
141 | ||
142 | ||
143 | // | |
144 | // 'ppdcDriver::~ppdcDriver()' - Destroy a printer driver. | |
145 | // | |
146 | ||
147 | ppdcDriver::~ppdcDriver() | |
148 | { | |
94da7e34 MS |
149 | PPDC_DELETE; |
150 | ||
e4572d57 | 151 | copyright->release(); |
ac884b6a MS |
152 | |
153 | if (manufacturer) | |
154 | manufacturer->release(); | |
155 | if (model_name) | |
156 | model_name->release(); | |
bdd6c45b MS |
157 | if (file_name) |
158 | file_name->release(); | |
ac884b6a MS |
159 | if (pc_file_name) |
160 | pc_file_name->release(); | |
161 | if (version) | |
162 | version->release(); | |
163 | if (default_font) | |
164 | default_font->release(); | |
165 | if (default_size) | |
166 | default_size->release(); | |
167 | if (custom_size_code) | |
168 | custom_size_code->release(); | |
169 | ||
e4572d57 MS |
170 | attrs->release(); |
171 | constraints->release(); | |
172 | filters->release(); | |
173 | fonts->release(); | |
174 | groups->release(); | |
175 | profiles->release(); | |
176 | sizes->release(); | |
ac884b6a MS |
177 | } |
178 | ||
179 | ||
180 | // | |
181 | // 'ppdcDriver::find_attr()' - Find an attribute. | |
182 | // | |
183 | ||
184 | ppdcAttr * // O - Attribute or NULL | |
185 | ppdcDriver::find_attr(const char *k, // I - Keyword string | |
186 | const char *s) // I - Spec string | |
187 | { | |
188 | ppdcAttr *a; // Current attribute | |
189 | ||
190 | ||
191 | for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next()) | |
192 | if (!strcmp(a->name->value, k) && | |
193 | ((!s && (!a->selector->value || !a->selector->value[0])) || | |
f11a948a | 194 | (s && a->selector->value && !strcmp(a->selector->value, s)))) |
ac884b6a MS |
195 | return (a); |
196 | ||
197 | return (NULL); | |
198 | } | |
199 | ||
200 | ||
201 | // | |
202 | // 'ppdcDriver::find_group()' - Find a group. | |
203 | // | |
204 | ||
205 | ppdcGroup * // O - Matching group or NULL | |
206 | ppdcDriver::find_group(const char *n) // I - Group name | |
207 | { | |
208 | ppdcGroup *g; // Current group | |
209 | ||
210 | ||
211 | for (g = (ppdcGroup *)groups->first(); g; g = (ppdcGroup *)groups->next()) | |
212 | if (!strcasecmp(n, g->name->value)) | |
213 | return (g); | |
214 | ||
215 | return (0); | |
216 | } | |
217 | ||
218 | ||
219 | // | |
220 | // 'ppdcDriver::find_option()' - Find an option. | |
221 | // | |
222 | ||
223 | ppdcOption * // O - Matching option or NULL | |
224 | ppdcDriver::find_option(const char *n) // I - Option name | |
97c9a8d7 MS |
225 | { |
226 | return (find_option_group(n, (ppdcGroup **)0)); | |
227 | } | |
228 | ||
229 | ||
230 | // | |
231 | // 'ppdcDriver::find_option_group()' - Find an option and its group. | |
232 | // | |
233 | ||
234 | ppdcOption * // O - Matching option or NULL | |
235 | ppdcDriver::find_option_group( | |
236 | const char *n, // I - Option name | |
237 | ppdcGroup **mg) // O - Matching group or NULL | |
ac884b6a MS |
238 | { |
239 | ppdcGroup *g; // Current group | |
240 | ppdcOption *o; // Current option | |
241 | ||
242 | ||
243 | for (g = (ppdcGroup *)groups->first(); g; g = (ppdcGroup *)groups->next()) | |
244 | for (o = (ppdcOption *)g->options->first(); o; o = (ppdcOption *)g->options->next()) | |
245 | if (!strcasecmp(n, o->name->value)) | |
97c9a8d7 MS |
246 | { |
247 | if (mg) | |
248 | *mg = g; | |
249 | ||
ac884b6a | 250 | return (o); |
97c9a8d7 MS |
251 | } |
252 | ||
253 | if (mg) | |
254 | *mg = (ppdcGroup *)0; | |
ac884b6a MS |
255 | |
256 | return (0); | |
257 | } | |
258 | ||
259 | ||
260 | // | |
261 | // 'ppdcDriver::set_custom_size_code()' - Set the custom page size code. | |
262 | // | |
263 | ||
264 | void | |
bdd6c45b MS |
265 | ppdcDriver::set_custom_size_code( |
266 | const char *c) // I - CustomPageSize code | |
ac884b6a MS |
267 | { |
268 | if (custom_size_code) | |
269 | custom_size_code->release(); | |
270 | ||
271 | custom_size_code = new ppdcString(c); | |
272 | } | |
273 | ||
274 | ||
275 | // | |
276 | // 'ppdcDriver::set_default_font()' - Set the default font name. | |
277 | // | |
278 | ||
279 | void | |
bdd6c45b MS |
280 | ppdcDriver::set_default_font( |
281 | ppdcFont *f) // I - Font | |
ac884b6a MS |
282 | { |
283 | if (default_font) | |
284 | default_font->release(); | |
285 | ||
286 | if (f) | |
287 | { | |
e4572d57 | 288 | f->name->retain(); |
ac884b6a MS |
289 | default_font = f->name; |
290 | } | |
291 | else | |
292 | default_font = 0; | |
293 | } | |
294 | ||
295 | ||
296 | // | |
297 | // 'ppdcDriver::set_default_size()' - Set the default size name. | |
298 | // | |
299 | ||
300 | void | |
bdd6c45b MS |
301 | ppdcDriver::set_default_size( |
302 | ppdcMediaSize *m) // I - Media size | |
ac884b6a MS |
303 | { |
304 | if (default_size) | |
305 | default_size->release(); | |
306 | ||
307 | if (m) | |
308 | { | |
e4572d57 | 309 | m->name->retain(); |
ac884b6a MS |
310 | default_size = m->name; |
311 | } | |
312 | else | |
313 | default_size = 0; | |
314 | } | |
315 | ||
316 | ||
bdd6c45b MS |
317 | // |
318 | // 'ppdcDriver::set_file_name()' - Set the full filename. | |
319 | // | |
320 | ||
321 | void | |
322 | ppdcDriver::set_file_name(const char *f)// I - Filename | |
323 | { | |
324 | if (file_name) | |
325 | file_name->release(); | |
326 | ||
327 | file_name = new ppdcString(f); | |
328 | } | |
329 | ||
330 | ||
ac884b6a MS |
331 | // |
332 | // 'ppdcDriver::set_manufacturer()' - Set the manufacturer name. | |
333 | // | |
334 | ||
335 | void | |
bdd6c45b MS |
336 | ppdcDriver::set_manufacturer( |
337 | const char *m) // I - Model name | |
ac884b6a MS |
338 | { |
339 | if (manufacturer) | |
340 | manufacturer->release(); | |
341 | ||
342 | manufacturer = new ppdcString(m); | |
343 | } | |
344 | ||
345 | ||
346 | // | |
347 | // 'ppdcDriver::set_model_name()' - Set the model name. | |
348 | // | |
349 | ||
350 | void | |
bdd6c45b MS |
351 | ppdcDriver::set_model_name( |
352 | const char *m) // I - Model name | |
ac884b6a MS |
353 | { |
354 | if (model_name) | |
355 | model_name->release(); | |
356 | ||
357 | model_name = new ppdcString(m); | |
358 | } | |
359 | ||
360 | ||
361 | // | |
362 | // 'ppdcDriver::set_pc_file_name()' - Set the PC filename. | |
363 | // | |
364 | ||
365 | void | |
bdd6c45b MS |
366 | ppdcDriver::set_pc_file_name( |
367 | const char *f) // I - Filename | |
ac884b6a MS |
368 | { |
369 | if (pc_file_name) | |
370 | pc_file_name->release(); | |
371 | ||
372 | pc_file_name = new ppdcString(f); | |
373 | } | |
374 | ||
375 | ||
376 | // | |
377 | // 'ppdcDriver::set_version()' - Set the version string. | |
378 | // | |
379 | ||
380 | void | |
381 | ppdcDriver::set_version(const char *v) // I - Version | |
382 | { | |
383 | if (version) | |
384 | version->release(); | |
385 | ||
386 | version = new ppdcString(v); | |
387 | } | |
388 | ||
389 | ||
390 | // | |
391 | // 'ppdcDriver::write_ppd_file()' - Write a PPD file... | |
392 | // | |
393 | ||
394 | int // O - 0 on success, -1 on failure | |
395 | ppdcDriver::write_ppd_file( | |
396 | cups_file_t *fp, // I - PPD file | |
397 | ppdcCatalog *catalog, // I - Message catalog | |
398 | ppdcArray *locales, // I - Additional languages to add | |
399 | ppdcSource *src, // I - Driver source | |
400 | ppdcLineEnding le) // I - Line endings to use | |
401 | { | |
402 | bool delete_cat; // Delete the catalog when we are done? | |
f11a948a MS |
403 | char query[42], // Query attribute |
404 | custom[42]; // Custom attribute | |
ac884b6a MS |
405 | ppdcString *s; // Copyright string |
406 | ppdcGroup *g; // Current group | |
407 | ppdcOption *o; // Current option | |
408 | ppdcChoice *c; // Current choice | |
409 | ppdcMediaSize *m; // Current media size | |
410 | ppdcProfile *p; // Current color profile | |
411 | ppdcFilter *f; // Current filter | |
412 | ppdcFont *fn, // Current font | |
413 | *bfn; // Current base font | |
414 | ppdcConstraint *cn; // Current constraint | |
415 | ppdcAttr *a; // Current attribute | |
416 | const char *lf; // Linefeed character to use | |
417 | ||
418 | ||
419 | // If we don't have a message catalog, use an empty (English) one... | |
420 | if (!catalog) | |
421 | { | |
422 | catalog = new ppdcCatalog("en"); | |
423 | delete_cat = true; | |
424 | } | |
425 | else | |
426 | delete_cat = false; | |
427 | ||
428 | // Figure out the end-of-line string... | |
429 | if (le == PPDC_LFONLY) | |
430 | lf = "\n"; | |
431 | else if (le == PPDC_CRONLY) | |
432 | lf = "\r"; | |
433 | else | |
434 | lf = "\r\n"; | |
435 | ||
436 | // Write the standard header stuff... | |
437 | cupsFilePrintf(fp, "*PPD-Adobe: \"4.3\"%s", lf); | |
f11a948a MS |
438 | cupsFilePrintf(fp, "*%%%%%%%% PPD file for %s with CUPS.%s", |
439 | model_name->value, lf); | |
ac884b6a | 440 | cupsFilePrintf(fp, |
f11a948a MS |
441 | "*%%%%%%%% Created by the CUPS PPD Compiler " CUPS_SVERSION |
442 | ".%s", lf); | |
ac884b6a MS |
443 | for (s = (ppdcString *)copyright->first(); |
444 | s; | |
445 | s = (ppdcString *)copyright->next()) | |
446 | cupsFilePrintf(fp, "*%% %s%s", catalog->find_message(s->value), lf); | |
447 | cupsFilePrintf(fp, "*FormatVersion: \"4.3\"%s", lf); | |
448 | cupsFilePrintf(fp, "*FileVersion: \"%s\"%s", version->value, lf); | |
449 | ||
450 | a = find_attr("LanguageVersion", NULL); | |
451 | cupsFilePrintf(fp, "*LanguageVersion: %s%s", | |
452 | catalog->find_message(a ? a->value->value : "English"), lf); | |
453 | ||
454 | a = find_attr("LanguageEncoding", NULL); | |
455 | cupsFilePrintf(fp, "*LanguageEncoding: %s%s", | |
456 | catalog->find_message(a ? a->value->value : "ISOLatin1"), lf); | |
457 | ||
458 | cupsFilePrintf(fp, "*PCFileName: \"%s\"%s", pc_file_name->value, lf); | |
459 | ||
460 | for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next()) | |
461 | if (!strcmp(a->name->value, "Product")) | |
462 | break; | |
463 | ||
464 | if (a) | |
465 | { | |
466 | for (; a; a = (ppdcAttr *)attrs->next()) | |
467 | if (!strcmp(a->name->value, "Product")) | |
468 | cupsFilePrintf(fp, "*Product: \"%s\"%s", a->value->value, lf); | |
469 | } | |
470 | else | |
bdd6c45b | 471 | cupsFilePrintf(fp, "*Product: \"(%s)\"%s", model_name->value, lf); |
ac884b6a MS |
472 | |
473 | cupsFilePrintf(fp, "*Manufacturer: \"%s\"%s", | |
474 | catalog->find_message(manufacturer->value), lf); | |
475 | ||
476 | if ((a = find_attr("ModelName", NULL)) != NULL) | |
477 | cupsFilePrintf(fp, "*ModelName: \"%s\"%s", | |
478 | catalog->find_message(a->value->value), lf); | |
479 | else if (strncasecmp(model_name->value, manufacturer->value, | |
480 | strlen(manufacturer->value))) | |
481 | cupsFilePrintf(fp, "*ModelName: \"%s %s\"%s", | |
482 | catalog->find_message(manufacturer->value), | |
483 | catalog->find_message(model_name->value), lf); | |
484 | else | |
485 | cupsFilePrintf(fp, "*ModelName: \"%s\"%s", | |
486 | catalog->find_message(model_name->value), lf); | |
487 | ||
488 | if ((a = find_attr("ShortNickName", NULL)) != NULL) | |
489 | cupsFilePrintf(fp, "*ShortNickName: \"%s\"%s", | |
490 | catalog->find_message(a->value->value), lf); | |
491 | else if (strncasecmp(model_name->value, manufacturer->value, | |
492 | strlen(manufacturer->value))) | |
493 | cupsFilePrintf(fp, "*ShortNickName: \"%s %s\"%s", | |
494 | catalog->find_message(manufacturer->value), | |
495 | catalog->find_message(model_name->value), lf); | |
496 | else | |
497 | cupsFilePrintf(fp, "*ShortNickName: \"%s\"%s", | |
498 | catalog->find_message(model_name->value), lf); | |
499 | ||
500 | if ((a = find_attr("NickName", NULL)) != NULL) | |
501 | cupsFilePrintf(fp, "*NickName: \"%s\"%s", | |
502 | catalog->find_message(a->value->value), lf); | |
503 | else if (strncasecmp(model_name->value, manufacturer->value, | |
504 | strlen(manufacturer->value))) | |
505 | cupsFilePrintf(fp, "*NickName: \"%s %s, %s\"%s", | |
506 | catalog->find_message(manufacturer->value), | |
507 | catalog->find_message(model_name->value), version->value, | |
508 | lf); | |
509 | else | |
510 | cupsFilePrintf(fp, "*NickName: \"%s, %s\"%s", | |
511 | catalog->find_message(model_name->value), version->value, | |
512 | lf); | |
513 | ||
514 | for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next()) | |
515 | if (!strcmp(a->name->value, "PSVersion")) | |
516 | break; | |
517 | ||
518 | if (a) | |
519 | { | |
520 | for (; a; a = (ppdcAttr *)attrs->next()) | |
521 | if (!strcmp(a->name->value, "PSVersion")) | |
522 | cupsFilePrintf(fp, "*PSVersion: \"%s\"%s", a->value->value, lf); | |
523 | } | |
524 | else | |
bdd6c45b | 525 | cupsFilePrintf(fp, "*PSVersion: \"(3010.000) 0\"%s", lf); |
ac884b6a MS |
526 | |
527 | if ((a = find_attr("LanguageLevel", NULL)) != NULL) | |
528 | cupsFilePrintf(fp, "*LanguageLevel: \"%s\"%s", a->value->value, lf); | |
529 | else | |
530 | cupsFilePrintf(fp, "*LanguageLevel: \"3\"%s", lf); | |
531 | ||
532 | cupsFilePrintf(fp, "*ColorDevice: %s%s", color_device ? "True" : "False", lf); | |
533 | ||
534 | if ((a = find_attr("DefaultColorSpace", NULL)) != NULL) | |
535 | cupsFilePrintf(fp, "*DefaultColorSpace: %s%s", a->value->value, lf); | |
536 | else | |
537 | cupsFilePrintf(fp, "*DefaultColorSpace: %s%s", | |
538 | color_device ? "RGB" : "Gray", lf); | |
539 | ||
540 | if ((a = find_attr("FileSystem", NULL)) != NULL) | |
541 | cupsFilePrintf(fp, "*FileSystem: %s%s", a->value->value, lf); | |
542 | else | |
543 | cupsFilePrintf(fp, "*FileSystem: False%s", lf); | |
544 | ||
545 | cupsFilePrintf(fp, "*Throughput: \"%d\"%s", throughput, lf); | |
546 | ||
547 | if ((a = find_attr("LandscapeOrientation", NULL)) != NULL) | |
548 | cupsFilePrintf(fp, "*LandscapeOrientation: %s%s", a->value->value, lf); | |
549 | else | |
550 | cupsFilePrintf(fp, "*LandscapeOrientation: Plus90%s", lf); | |
551 | ||
552 | if ((a = find_attr("TTRasterizer", NULL)) != NULL) | |
553 | cupsFilePrintf(fp, "*TTRasterizer: %s%s", a->value->value, lf); | |
554 | else if (type != PPDC_DRIVER_PS) | |
555 | cupsFilePrintf(fp, "*TTRasterizer: Type42%s", lf); | |
556 | ||
557 | if (attrs->count) | |
558 | { | |
559 | // Write driver-defined attributes... | |
560 | cupsFilePrintf(fp, "*%% Driver-defined attributes...%s", lf); | |
561 | for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next()) | |
562 | { | |
563 | if (!strcmp(a->name->value, "Product") || | |
564 | !strcmp(a->name->value, "PSVersion") || | |
565 | !strcmp(a->name->value, "LanguageLevel") || | |
566 | !strcmp(a->name->value, "DefaultColorSpace") || | |
567 | !strcmp(a->name->value, "FileSystem") || | |
568 | !strcmp(a->name->value, "LandscapeOrientation") || | |
569 | !strcmp(a->name->value, "TTRasterizer") || | |
570 | !strcmp(a->name->value, "LanguageVersion") || | |
571 | !strcmp(a->name->value, "LanguageEncoding") || | |
572 | !strcmp(a->name->value, "ModelName") || | |
573 | !strcmp(a->name->value, "NickName") || | |
574 | !strcmp(a->name->value, "ShortNickName") || | |
4509bb49 | 575 | !strcmp(a->name->value, "cupsVersion")) |
ac884b6a MS |
576 | continue; |
577 | ||
4509bb49 MS |
578 | if (a->name->value[0] == '?' && |
579 | (find_option(a->name->value + 1) || | |
580 | !strcmp(a->name->value, "?ImageableArea") || | |
581 | !strcmp(a->name->value, "?PageRegion") || | |
582 | !strcmp(a->name->value, "?PageSize") || | |
583 | !strcmp(a->name->value, "?PaperDimension"))) | |
584 | continue; | |
585 | ||
f11a948a MS |
586 | if (!strncmp(a->name->value, "Custom", 6) && |
587 | find_option(a->name->value + 6)) | |
588 | continue; | |
589 | ||
590 | if (!strncmp(a->name->value, "ParamCustom", 11) && | |
591 | find_option(a->name->value + 11)) | |
592 | continue; | |
593 | ||
ac884b6a MS |
594 | if (!a->selector->value || !a->selector->value[0]) |
595 | cupsFilePrintf(fp, "*%s", a->name->value); | |
596 | else if (!a->text->value || !a->text->value[0]) | |
597 | cupsFilePrintf(fp, "*%s %s", a->name->value, a->selector->value); | |
598 | else | |
599 | cupsFilePrintf(fp, "*%s %s/%s", a->name->value, a->selector->value, | |
600 | a->text->value); | |
601 | ||
602 | if (strcmp(a->value->value, "False") && | |
603 | strcmp(a->value->value, "True") && | |
604 | strcmp(a->name->value, "1284Modes") && | |
605 | strcmp(a->name->value, "InkName") && | |
606 | strcmp(a->name->value, "PageStackOrder") && | |
607 | strncmp(a->name->value, "ParamCustom", 11) && | |
608 | strcmp(a->name->value, "Protocols") && | |
609 | strcmp(a->name->value, "ReferencePunch") && | |
610 | strncmp(a->name->value, "Default", 7)) | |
611 | { | |
612 | cupsFilePrintf(fp, ": \"%s\"%s", a->value->value, lf); | |
613 | ||
f11a948a | 614 | if (strchr(a->value->value, '\n') || strchr(a->value->value, '\r')) |
ac884b6a MS |
615 | cupsFilePrintf(fp, "*End%s", lf); |
616 | } | |
617 | else | |
618 | cupsFilePrintf(fp, ": %s%s", a->value->value, lf); | |
619 | } | |
620 | } | |
621 | ||
622 | if (type != PPDC_DRIVER_PS || filters->count) | |
623 | { | |
624 | if ((a = find_attr("cupsVersion", NULL)) != NULL) | |
625 | cupsFilePrintf(fp, "*cupsVersion: %s%s", a->value->value, lf); | |
626 | else | |
627 | cupsFilePrintf(fp, "*cupsVersion: %d.%d%s", CUPS_VERSION_MAJOR, | |
628 | CUPS_VERSION_MINOR, lf); | |
629 | cupsFilePrintf(fp, "*cupsModelNumber: %d%s", model_number, lf); | |
630 | cupsFilePrintf(fp, "*cupsManualCopies: %s%s", | |
631 | manual_copies ? "True" : "False", lf); | |
632 | ||
633 | if (filters->count) | |
634 | { | |
635 | for (f = (ppdcFilter *)filters->first(); | |
636 | f; | |
637 | f = (ppdcFilter *)filters->next()) | |
638 | cupsFilePrintf(fp, "*cupsFilter: \"%s %d %s\"%s", f->mime_type->value, | |
639 | f->cost, f->program->value, lf); | |
640 | } | |
641 | else | |
642 | { | |
643 | switch (type) | |
644 | { | |
645 | case PPDC_DRIVER_LABEL : | |
646 | cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-raster 50 " | |
647 | "rastertolabel\"%s", lf); | |
648 | break; | |
649 | ||
650 | case PPDC_DRIVER_EPSON : | |
651 | cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-raster 50 " | |
652 | "rastertoepson\"%s", lf); | |
653 | break; | |
654 | ||
655 | case PPDC_DRIVER_ESCP : | |
656 | cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-command 50 " | |
657 | "commandtoescpx\"%s", lf); | |
658 | cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-raster 50 " | |
659 | "rastertoescpx\"%s", lf); | |
660 | break; | |
661 | ||
662 | case PPDC_DRIVER_HP : | |
663 | cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-raster 50 " | |
664 | "rastertohp\"%s", lf); | |
665 | break; | |
666 | ||
667 | case PPDC_DRIVER_PCL : | |
668 | cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-command 50 " | |
669 | "commandtopclx\"%s", lf); | |
670 | cupsFilePrintf(fp, "*cupsFilter: \"application/vnd.cups-raster 50 " | |
671 | "rastertopclx\"%s", lf); | |
672 | break; | |
673 | ||
674 | default : | |
675 | break; | |
676 | } | |
677 | } | |
678 | ||
679 | for (p = (ppdcProfile *)profiles->first(); | |
680 | p; | |
681 | p = (ppdcProfile *)profiles->next()) | |
682 | cupsFilePrintf(fp, | |
683 | "*cupsColorProfile %s/%s: \"%.3f %.3f %.3f %.3f %.3f %.3f " | |
684 | "%.3f %.3f %.3f %.3f %.3f\"%s", | |
685 | p->resolution->value, p->media_type->value, | |
686 | p->density, p->gamma, | |
687 | p->profile[0], p->profile[1], | |
688 | p->profile[2], p->profile[3], | |
689 | p->profile[4], p->profile[5], | |
690 | p->profile[6], p->profile[7], | |
691 | p->profile[8], lf); | |
692 | } | |
693 | ||
694 | if (locales) | |
695 | { | |
696 | // Add localizations for additional languages... | |
697 | ppdcString *locale; // Locale name | |
698 | ppdcCatalog *locatalog; // Message catalog for locale | |
699 | ||
700 | ||
701 | // Write the list of languages... | |
702 | cupsFilePrintf(fp, "*cupsLanguages: \"en"); | |
703 | ||
704 | for (locale = (ppdcString *)locales->first(); | |
705 | locale; | |
706 | locale = (ppdcString *)locales->next()) | |
707 | { | |
708 | // Skip (US) English... | |
709 | if (!strcmp(locale->value, "en") || !strcmp(locale->value, "en_US")) | |
710 | continue; | |
711 | ||
712 | // See if we have a po file for this language... | |
713 | if (!src->find_po(locale->value)) | |
714 | { | |
715 | // No, see if we can use the base file? | |
716 | locatalog = new ppdcCatalog(locale->value); | |
717 | ||
718 | if (locatalog->messages->count == 0) | |
719 | { | |
720 | // No, skip this one... | |
61cf44e2 MS |
721 | _cupsLangPrintf(stderr, |
722 | _("ppdc: No message catalog provided for locale " | |
723 | "%s!\n"), locale->value); | |
ac884b6a MS |
724 | continue; |
725 | } | |
726 | ||
727 | // Add the base file to the list... | |
728 | src->po_files->add(locatalog); | |
729 | } | |
730 | ||
731 | cupsFilePrintf(fp, " %s", locale->value); | |
732 | } | |
733 | ||
734 | cupsFilePrintf(fp, "\"%s", lf); | |
735 | } | |
736 | ||
737 | for (cn = (ppdcConstraint *)constraints->first(); | |
738 | cn; | |
739 | cn = (ppdcConstraint *)constraints->next()) | |
740 | { | |
741 | // First constrain 1 against 2... | |
742 | if (!strncmp(cn->option1->value, "*Custom", 7) || | |
743 | !strncmp(cn->option2->value, "*Custom", 7)) | |
61cf44e2 | 744 | cupsFilePuts(fp, "*NonUIConstraints: "); |
ac884b6a | 745 | else |
61cf44e2 | 746 | cupsFilePuts(fp, "*UIConstraints: "); |
ac884b6a MS |
747 | |
748 | if (cn->option1->value[0] != '*') | |
749 | cupsFilePutChar(fp, '*'); | |
750 | ||
61cf44e2 | 751 | cupsFilePuts(fp, cn->option1->value); |
ac884b6a MS |
752 | |
753 | if (cn->choice1->value) | |
754 | cupsFilePrintf(fp, " %s", cn->choice1->value); | |
755 | ||
756 | cupsFilePutChar(fp, ' '); | |
757 | ||
758 | if (cn->option2->value[0] != '*') | |
759 | cupsFilePutChar(fp, '*'); | |
760 | ||
61cf44e2 | 761 | cupsFilePuts(fp, cn->option2->value); |
ac884b6a MS |
762 | |
763 | if (cn->choice2->value) | |
764 | cupsFilePrintf(fp, " %s", cn->choice2->value); | |
765 | ||
61cf44e2 | 766 | cupsFilePuts(fp, lf); |
ac884b6a MS |
767 | |
768 | // Then constrain 2 against 1... | |
769 | if (!strncmp(cn->option1->value, "*Custom", 7) || | |
770 | !strncmp(cn->option2->value, "*Custom", 7)) | |
61cf44e2 | 771 | cupsFilePuts(fp, "*NonUIConstraints: "); |
ac884b6a | 772 | else |
61cf44e2 | 773 | cupsFilePuts(fp, "*UIConstraints: "); |
ac884b6a MS |
774 | |
775 | if (cn->option2->value[0] != '*') | |
776 | cupsFilePutChar(fp, '*'); | |
777 | ||
61cf44e2 | 778 | cupsFilePuts(fp, cn->option2->value); |
ac884b6a MS |
779 | |
780 | if (cn->choice2->value) | |
781 | cupsFilePrintf(fp, " %s", cn->choice2->value); | |
782 | ||
783 | cupsFilePutChar(fp, ' '); | |
784 | ||
785 | if (cn->option1->value[0] != '*') | |
786 | cupsFilePutChar(fp, '*'); | |
787 | ||
61cf44e2 | 788 | cupsFilePuts(fp, cn->option1->value); |
ac884b6a MS |
789 | |
790 | if (cn->choice1->value) | |
791 | cupsFilePrintf(fp, " %s", cn->choice1->value); | |
792 | ||
793 | cupsFilePuts(fp, lf); | |
794 | } | |
795 | ||
796 | // PageSize option... | |
797 | cupsFilePrintf(fp, "*OpenUI *PageSize/Media Size: PickOne%s", lf); | |
798 | cupsFilePrintf(fp, "*OrderDependency: 10 AnySetup *PageSize%s", lf); | |
799 | cupsFilePrintf(fp, "*DefaultPageSize: %s%s", | |
800 | default_size ? default_size->value : "Letter", lf); | |
801 | ||
802 | for (m = (ppdcMediaSize *)sizes->first(); | |
803 | m; | |
804 | m = (ppdcMediaSize *)sizes->next()) | |
805 | if (m->size_code->value) | |
806 | { | |
807 | cupsFilePrintf(fp, "*PageSize %s/%s: \"%s\"%s", | |
808 | m->name->value, catalog->find_message(m->text->value), | |
809 | m->size_code->value, lf); | |
810 | ||
811 | if (strchr(m->size_code->value, '\n') || | |
812 | strchr(m->size_code->value, '\r')) | |
813 | cupsFilePrintf(fp, "*End%s", lf); | |
814 | } | |
815 | else | |
816 | cupsFilePrintf(fp, | |
817 | "*PageSize %s/%s: \"<</PageSize[%.0f %.0f]" | |
818 | "/ImagingBBox null>>setpagedevice\"%s", | |
819 | m->name->value, catalog->find_message(m->text->value), | |
820 | m->width, m->length, lf); | |
821 | ||
822 | if ((a = find_attr("?PageSize", NULL)) != NULL) | |
823 | { | |
824 | cupsFilePrintf(fp, "*?PageSize: \"%s\"%s", a->value->value, lf); | |
825 | ||
826 | if (strchr(a->value->value, '\n') || | |
827 | strchr(a->value->value, '\r')) | |
828 | cupsFilePrintf(fp, "*End%s", lf); | |
829 | } | |
830 | ||
831 | cupsFilePrintf(fp, "*CloseUI: *PageSize%s", lf); | |
832 | ||
833 | // PageRegion option... | |
834 | cupsFilePrintf(fp, "*OpenUI *PageRegion/Media Size: PickOne%s", lf); | |
835 | cupsFilePrintf(fp, "*OrderDependency: 10 AnySetup *PageRegion%s", lf); | |
836 | cupsFilePrintf(fp, "*DefaultPageRegion: %s%s", | |
837 | default_size ? default_size->value : "Letter", lf); | |
838 | ||
839 | for (m = (ppdcMediaSize *)sizes->first(); | |
840 | m; | |
841 | m = (ppdcMediaSize *)sizes->next()) | |
842 | if (m->region_code->value) | |
843 | { | |
844 | cupsFilePrintf(fp, "*PageRegion %s/%s: \"%s\"%s", | |
845 | m->name->value, catalog->find_message(m->text->value), | |
846 | m->region_code->value, lf); | |
847 | ||
848 | if (strchr(m->region_code->value, '\n') || | |
849 | strchr(m->region_code->value, '\r')) | |
850 | cupsFilePrintf(fp, "*End%s", lf); | |
851 | } | |
852 | else | |
853 | cupsFilePrintf(fp, | |
854 | "*PageRegion %s/%s: \"<</PageSize[%.0f %.0f]" | |
855 | "/ImagingBBox null>>setpagedevice\"%s", | |
856 | m->name->value, catalog->find_message(m->text->value), | |
857 | m->width, m->length, lf); | |
858 | ||
859 | if ((a = find_attr("?PageRegion", NULL)) != NULL) | |
860 | { | |
861 | cupsFilePrintf(fp, "*?PageRegion: \"%s\"%s", a->value->value, lf); | |
862 | ||
863 | if (strchr(a->value->value, '\n') || | |
864 | strchr(a->value->value, '\r')) | |
865 | cupsFilePrintf(fp, "*End%s", lf); | |
866 | } | |
867 | ||
868 | cupsFilePrintf(fp, "*CloseUI: *PageRegion%s", lf); | |
869 | ||
870 | // ImageableArea info... | |
871 | cupsFilePrintf(fp, "*DefaultImageableArea: %s%s", | |
872 | default_size ? default_size->value : "Letter", lf); | |
873 | ||
874 | for (m = (ppdcMediaSize *)sizes->first(); | |
875 | m; | |
876 | m = (ppdcMediaSize *)sizes->next()) | |
877 | cupsFilePrintf(fp, "*ImageableArea %s/%s: \"%.2f %.2f %.2f %.2f\"%s", | |
878 | m->name->value, catalog->find_message(m->text->value), | |
879 | m->left, m->bottom, m->width - m->right, m->length - m->top, | |
880 | lf); | |
881 | ||
882 | if ((a = find_attr("?ImageableArea", NULL)) != NULL) | |
883 | { | |
884 | cupsFilePrintf(fp, "*?ImageableArea: \"%s\"%s", a->value->value, lf); | |
885 | ||
886 | if (strchr(a->value->value, '\n') || | |
887 | strchr(a->value->value, '\r')) | |
888 | cupsFilePrintf(fp, "*End%s", lf); | |
889 | } | |
890 | ||
891 | // PaperDimension info... | |
892 | cupsFilePrintf(fp, "*DefaultPaperDimension: %s%s", | |
893 | default_size ? default_size->value : "Letter", lf); | |
894 | ||
895 | for (m = (ppdcMediaSize *)sizes->first(); | |
896 | m; | |
897 | m = (ppdcMediaSize *)sizes->next()) | |
898 | cupsFilePrintf(fp, "*PaperDimension %s/%s: \"%.2f %.2f\"%s", | |
899 | m->name->value, catalog->find_message(m->text->value), | |
900 | m->width, m->length, lf); | |
901 | ||
902 | if ((a = find_attr("?PaperDimension", NULL)) != NULL) | |
903 | { | |
904 | cupsFilePrintf(fp, "*?PaperDimension: \"%s\"%s", a->value->value, lf); | |
905 | ||
906 | if (strchr(a->value->value, '\n') || | |
907 | strchr(a->value->value, '\r')) | |
908 | cupsFilePrintf(fp, "*End%s", lf); | |
909 | } | |
910 | ||
911 | // Custom size support... | |
912 | if (variable_paper_size) | |
913 | { | |
914 | cupsFilePrintf(fp, "*MaxMediaWidth: \"%.2f\"%s", max_width, lf); | |
915 | cupsFilePrintf(fp, "*MaxMediaHeight: \"%.2f\"%s", max_length, lf); | |
916 | cupsFilePrintf(fp, "*HWMargins: %.2f %.2f %.2f %.2f\n", | |
917 | left_margin, bottom_margin, right_margin, top_margin); | |
918 | ||
919 | if (custom_size_code && custom_size_code->value) | |
920 | { | |
921 | cupsFilePrintf(fp, "*CustomPageSize True: \"%s\"%s", | |
922 | custom_size_code->value, lf); | |
923 | ||
924 | if (strchr(custom_size_code->value, '\n') || | |
925 | strchr(custom_size_code->value, '\r')) | |
926 | cupsFilePrintf(fp, "*End%s", lf); | |
927 | } | |
928 | else | |
929 | cupsFilePrintf(fp, | |
930 | "*CustomPageSize True: \"pop pop pop <</PageSize[5 -2 roll]" | |
931 | "/ImagingBBox null>>setpagedevice\"%s", lf); | |
932 | ||
933 | if ((a = find_attr("ParamCustomPageSize", "Width")) != NULL) | |
934 | cupsFilePrintf(fp, "*ParamCustomPageSize Width: %s%s", a->value->value, | |
935 | lf); | |
936 | else | |
937 | cupsFilePrintf(fp, "*ParamCustomPageSize Width: 1 points %.2f %.2f%s", | |
938 | min_width, max_width, lf); | |
939 | ||
940 | if ((a = find_attr("ParamCustomPageSize", "Height")) != NULL) | |
941 | cupsFilePrintf(fp, "*ParamCustomPageSize Height: %s%s", a->value->value, | |
942 | lf); | |
943 | else | |
944 | cupsFilePrintf(fp, "*ParamCustomPageSize Height: 2 points %.2f %.2f%s", | |
945 | min_length, max_length, lf); | |
946 | ||
947 | if ((a = find_attr("ParamCustomPageSize", "WidthOffset")) != NULL) | |
948 | cupsFilePrintf(fp, "*ParamCustomPageSize WidthOffset: %s%s", | |
949 | a->value->value, lf); | |
950 | else | |
951 | cupsFilePrintf(fp, "*ParamCustomPageSize WidthOffset: 3 points 0 0%s", lf); | |
952 | ||
953 | if ((a = find_attr("ParamCustomPageSize", "HeightOffset")) != NULL) | |
954 | cupsFilePrintf(fp, "*ParamCustomPageSize HeightOffset: %s%s", | |
955 | a->value->value, lf); | |
956 | else | |
957 | cupsFilePrintf(fp, "*ParamCustomPageSize HeightOffset: 4 points 0 0%s", lf); | |
958 | ||
959 | if ((a = find_attr("ParamCustomPageSize", "Orientation")) != NULL) | |
960 | cupsFilePrintf(fp, "*ParamCustomPageSize Orientation: %s%s", | |
961 | a->value->value, lf); | |
962 | else | |
963 | cupsFilePrintf(fp, "*ParamCustomPageSize Orientation: 5 int 0 0%s", lf); | |
964 | } | |
965 | ||
ac884b6a MS |
966 | // All other options... |
967 | for (g = (ppdcGroup *)groups->first(); g; g = (ppdcGroup *)groups->next()) | |
968 | { | |
969 | if (!g->options->count) | |
970 | continue; | |
971 | ||
972 | if (strcasecmp(g->name->value, "General")) | |
973 | cupsFilePrintf(fp, "*OpenGroup: %s/%s%s", g->name->value, | |
974 | catalog->find_message(g->text->value), lf); | |
975 | ||
976 | for (o = (ppdcOption *)g->options->first(); | |
977 | o; | |
978 | o = (ppdcOption *)g->options->next()) | |
979 | { | |
980 | if (!o->choices->count) | |
981 | continue; | |
982 | ||
983 | if (!o->text->value || !strcmp(o->name->value, o->text->value)) | |
d1c13e16 | 984 | cupsFilePrintf(fp, "*OpenUI *%s/%s: ", o->name->value, |
d2354e63 | 985 | catalog->find_message(o->name->value)); |
ac884b6a MS |
986 | else |
987 | cupsFilePrintf(fp, "*OpenUI *%s/%s: ", o->name->value, | |
988 | catalog->find_message(o->text->value)); | |
989 | ||
990 | switch (o->type) | |
991 | { | |
992 | case PPDC_BOOLEAN : | |
993 | cupsFilePrintf(fp, "Boolean%s", lf); | |
994 | break; | |
995 | default : | |
996 | cupsFilePrintf(fp, "PickOne%s", lf); | |
997 | break; | |
998 | case PPDC_PICKMANY : | |
999 | cupsFilePrintf(fp, "PickMany%s", lf); | |
1000 | break; | |
1001 | } | |
1002 | ||
1003 | cupsFilePrintf(fp, "*OrderDependency: %.1f ", o->order); | |
1004 | switch (o->section) | |
1005 | { | |
1006 | default : | |
1007 | cupsFilePrintf(fp, "AnySetup"); | |
1008 | break; | |
1009 | case PPDC_SECTION_DOCUMENT : | |
1010 | cupsFilePrintf(fp, "DocumentSetup"); | |
1011 | break; | |
1012 | case PPDC_SECTION_EXIT : | |
1013 | cupsFilePrintf(fp, "ExitServer"); | |
1014 | break; | |
1015 | case PPDC_SECTION_JCL : | |
1016 | cupsFilePrintf(fp, "JCLSetup"); | |
1017 | break; | |
1018 | case PPDC_SECTION_PAGE : | |
1019 | cupsFilePrintf(fp, "PageSetup"); | |
1020 | break; | |
1021 | case PPDC_SECTION_PROLOG : | |
1022 | cupsFilePrintf(fp, "Prolog"); | |
1023 | break; | |
1024 | } | |
1025 | ||
1026 | cupsFilePrintf(fp, " *%s%s", o->name->value, lf); | |
1027 | ||
1028 | if (o->defchoice) | |
1029 | { | |
1030 | // Use the programmer-supplied default... | |
1031 | cupsFilePrintf(fp, "*Default%s: %s%s", o->name->value, | |
1032 | o->defchoice->value, lf); | |
1033 | } | |
1034 | else | |
1035 | { | |
1036 | // Make the first choice the default... | |
1037 | c = (ppdcChoice *)o->choices->first(); | |
1038 | cupsFilePrintf(fp, "*Default%s: %s%s", o->name->value, c->name->value, | |
1039 | lf); | |
1040 | } | |
1041 | ||
1042 | for (c = (ppdcChoice *)o->choices->first(); | |
1043 | c; | |
1044 | c = (ppdcChoice *)o->choices->next()) | |
1045 | { | |
1046 | // Write this choice... | |
1047 | if (!c->text->value || !strcmp(c->name->value, c->text->value)) | |
d2354e63 MS |
1048 | cupsFilePrintf(fp, "*%s %s: \"%s\"%s", o->name->value, |
1049 | catalog->find_message(c->name->value), | |
ac884b6a MS |
1050 | c->code->value, lf); |
1051 | else | |
1052 | cupsFilePrintf(fp, "*%s %s/%s: \"%s\"%s", o->name->value, | |
1053 | c->name->value, catalog->find_message(c->text->value), | |
1054 | c->code->value, lf); | |
1055 | ||
1056 | // Multi-line commands need a *End line to terminate them. | |
1057 | if (strchr(c->code->value, '\n') || | |
1058 | strchr(c->code->value, '\r')) | |
1059 | cupsFilePrintf(fp, "*End%s", lf); | |
1060 | } | |
1061 | ||
1062 | snprintf(query, sizeof(query), "?%s", o->name->value); | |
1063 | ||
1064 | if ((a = find_attr(query, NULL)) != NULL) | |
1065 | { | |
f11a948a | 1066 | cupsFilePrintf(fp, "*%s: \"%s\"%s", query, a->value->value, lf); |
ac884b6a MS |
1067 | |
1068 | if (strchr(a->value->value, '\n') || | |
1069 | strchr(a->value->value, '\r')) | |
1070 | cupsFilePrintf(fp, "*End%s", lf); | |
1071 | } | |
1072 | ||
1073 | cupsFilePrintf(fp, "*CloseUI: *%s%s", o->name->value, lf); | |
f11a948a MS |
1074 | |
1075 | snprintf(custom, sizeof(custom), "Custom%s", o->name->value); | |
1076 | if ((a = find_attr(custom, "True")) != NULL) | |
1077 | { | |
1078 | // Output custom option information... | |
1079 | cupsFilePrintf(fp, "*%s True: \"%s\"%s", custom, a->value->value, lf); | |
1080 | if (strchr(a->value->value, '\n') || strchr(a->value->value, '\r')) | |
1081 | cupsFilePrintf(fp, "*End%s", lf); | |
1082 | ||
1083 | snprintf(custom, sizeof(custom), "ParamCustom%s", o->name->value); | |
1084 | for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next()) | |
1085 | { | |
1086 | if (strcmp(a->name->value, custom)) | |
1087 | continue; | |
1088 | ||
1089 | if (!a->selector->value || !a->selector->value[0]) | |
1090 | cupsFilePrintf(fp, "*%s", a->name->value); | |
1091 | else if (!a->text->value || !a->text->value[0]) | |
1092 | cupsFilePrintf(fp, "*%s %s", a->name->value, a->selector->value); | |
1093 | else | |
1094 | cupsFilePrintf(fp, "*%s %s/%s", a->name->value, a->selector->value, | |
1095 | a->text->value); | |
1096 | ||
1097 | cupsFilePrintf(fp, ": %s%s", a->value->value, lf); | |
1098 | } | |
1099 | } | |
ac884b6a MS |
1100 | } |
1101 | ||
1102 | if (strcasecmp(g->name->value, "General")) | |
1103 | cupsFilePrintf(fp, "*CloseGroup: %s%s", g->name->value, lf); | |
1104 | } | |
1105 | ||
1106 | if (locales) | |
1107 | { | |
1108 | // Add localizations for additional languages... | |
1109 | ppdcString *locale; // Locale name | |
1110 | ppdcCatalog *locatalog; // Message catalog for locale | |
1111 | ||
1112 | ||
1113 | // Write the translation strings for each language... | |
1114 | for (locale = (ppdcString *)locales->first(); | |
1115 | locale; | |
1116 | locale = (ppdcString *)locales->next()) | |
1117 | { | |
1118 | // Skip (US) English... | |
1119 | if (!strcmp(locale->value, "en") || !strcmp(locale->value, "en_US")) | |
1120 | continue; | |
1121 | ||
1122 | // Skip missing languages... | |
1123 | if ((locatalog = src->find_po(locale->value)) == NULL) | |
1124 | continue; | |
1125 | ||
1126 | // Do the core stuff first... | |
1127 | cupsFilePrintf(fp, "*%s.Translation Manufacturer/%s: \"\"%s", | |
1128 | locale->value, | |
1129 | locatalog->find_message(manufacturer->value), lf); | |
1130 | ||
1131 | if ((a = find_attr("ModelName", NULL)) != NULL) | |
1132 | cupsFilePrintf(fp, "*%s.Translation ModelName/%s: \"\"%s", | |
1133 | locale->value, | |
1134 | locatalog->find_message(a->value->value), lf); | |
1135 | else if (strncasecmp(model_name->value, manufacturer->value, | |
1136 | strlen(manufacturer->value))) | |
1137 | cupsFilePrintf(fp, "*%s.Translation ModelName/%s %s: \"\"%s", | |
1138 | locale->value, | |
1139 | locatalog->find_message(manufacturer->value), | |
1140 | locatalog->find_message(model_name->value), lf); | |
1141 | else | |
1142 | cupsFilePrintf(fp, "*%s.Translation ModelName/%s: \"\"%s", | |
1143 | locale->value, | |
1144 | locatalog->find_message(model_name->value), lf); | |
1145 | ||
1146 | if ((a = find_attr("ShortNickName", NULL)) != NULL) | |
1147 | cupsFilePrintf(fp, "*%s.Translation ShortNickName/%s: \"\"%s", | |
1148 | locale->value, | |
1149 | locatalog->find_message(a->value->value), lf); | |
1150 | else if (strncasecmp(model_name->value, manufacturer->value, | |
1151 | strlen(manufacturer->value))) | |
1152 | cupsFilePrintf(fp, "*%s.Translation ShortNickName/%s %s: \"\"%s", | |
1153 | locale->value, | |
1154 | locatalog->find_message(manufacturer->value), | |
1155 | locatalog->find_message(model_name->value), lf); | |
1156 | else | |
1157 | cupsFilePrintf(fp, "*%s.Translation ShortNickName/%s: \"\"%s", | |
1158 | locale->value, | |
1159 | locatalog->find_message(model_name->value), lf); | |
1160 | ||
1161 | if ((a = find_attr("NickName", NULL)) != NULL) | |
1162 | cupsFilePrintf(fp, "*%s.Translation NickName/%s: \"\"%s", | |
1163 | locale->value, | |
1164 | locatalog->find_message(a->value->value), lf); | |
1165 | else if (strncasecmp(model_name->value, manufacturer->value, | |
1166 | strlen(manufacturer->value))) | |
1167 | cupsFilePrintf(fp, "*%s.Translation NickName/%s %s, %s: \"\"%s", | |
1168 | locale->value, | |
1169 | locatalog->find_message(manufacturer->value), | |
1170 | locatalog->find_message(model_name->value), | |
1171 | version->value, lf); | |
1172 | else | |
1173 | cupsFilePrintf(fp, "*%s.Translation NickName/%s, %s: \"\"%s", | |
1174 | locale->value, | |
1175 | locatalog->find_message(model_name->value), | |
1176 | version->value, lf); | |
1177 | ||
1178 | // Then the page sizes... | |
1179 | cupsFilePrintf(fp, "*%s.Translation PageSize/%s: \"\"%s", locale->value, | |
1180 | locatalog->find_message("Media Size"), lf); | |
1181 | ||
1182 | for (m = (ppdcMediaSize *)sizes->first(); | |
1183 | m; | |
1184 | m = (ppdcMediaSize *)sizes->next()) | |
1185 | { | |
1186 | cupsFilePrintf(fp, "*%s.PageSize %s/%s: \"\"%s", locale->value, | |
1187 | m->name->value, locatalog->find_message(m->text->value), | |
1188 | lf); | |
1189 | } | |
1190 | ||
1191 | // Next the groups and options... | |
1192 | for (g = (ppdcGroup *)groups->first(); g; g = (ppdcGroup *)groups->next()) | |
1193 | { | |
1194 | if (!g->options->count) | |
1195 | continue; | |
1196 | ||
1197 | if (strcasecmp(g->name->value, "General")) | |
1198 | cupsFilePrintf(fp, "*%s.Translation %s/%s: \"\"%s", locale->value, | |
1199 | g->name->value, | |
1200 | locatalog->find_message(g->text->value), lf); | |
1201 | ||
1202 | for (o = (ppdcOption *)g->options->first(); | |
1203 | o; | |
1204 | o = (ppdcOption *)g->options->next()) | |
1205 | { | |
1206 | if (!o->choices->count) | |
1207 | continue; | |
1208 | ||
1209 | cupsFilePrintf(fp, "*%s.Translation %s/%s: \"\"%s", locale->value, | |
1210 | o->name->value, | |
1211 | locatalog->find_message(o->text->value ? | |
1212 | o->text->value : | |
1213 | o->name->value), lf); | |
1214 | ||
1215 | for (c = (ppdcChoice *)o->choices->first(); | |
1216 | c; | |
1217 | c = (ppdcChoice *)o->choices->next()) | |
1218 | { | |
1219 | // Write this choice... | |
1220 | cupsFilePrintf(fp, "*%s.%s %s/%s: \"\"%s", locale->value, | |
1221 | o->name->value, c->name->value, | |
1222 | locatalog->find_message(c->text->value ? | |
1223 | c->text->value : | |
1224 | c->name->value), lf); | |
1225 | } | |
1226 | } | |
1227 | } | |
1228 | ||
1229 | // Finally the localizable attributes... | |
1230 | for (a = (ppdcAttr *)attrs->first(); a; a = (ppdcAttr *)attrs->next()) | |
1231 | { | |
1232 | if ((!a->text || !a->text->value || !a->text->value[0]) && | |
1233 | strncmp(a->name->value, "Custom", 6) && | |
1234 | strncmp(a->name->value, "ParamCustom", 11)) | |
1235 | continue; | |
1236 | ||
bdd6c45b MS |
1237 | if (!a->localizable && |
1238 | strcmp(a->name->value, "APCustomColorMatchingName") && | |
ac884b6a MS |
1239 | strcmp(a->name->value, "APPrinterPreset") && |
1240 | strcmp(a->name->value, "cupsICCProfile") && | |
1241 | strcmp(a->name->value, "cupsIPPReason") && | |
bdd6c45b | 1242 | strcmp(a->name->value, "cupsMarkerName") && |
ac884b6a MS |
1243 | strncmp(a->name->value, "Custom", 6) && |
1244 | strncmp(a->name->value, "ParamCustom", 11)) | |
1245 | continue; | |
1246 | ||
1247 | cupsFilePrintf(fp, "*%s.%s %s/%s: \"%s\"%s", locale->value, | |
1248 | a->name->value, a->selector->value, | |
1249 | locatalog->find_message(a->text && a->text->value ? | |
1250 | a->text->value : a->name->value), | |
bdd6c45b MS |
1251 | ((a->localizable && a->value->value[0]) || |
1252 | !strcmp(a->name->value, "cupsIPPReason")) ? | |
ac884b6a MS |
1253 | locatalog->find_message(a->value->value) : "", |
1254 | lf); | |
1255 | } | |
1256 | } | |
1257 | } | |
1258 | ||
1259 | if (default_font && default_font->value) | |
1260 | cupsFilePrintf(fp, "*DefaultFont: %s%s", default_font->value, lf); | |
1261 | else | |
1262 | cupsFilePrintf(fp, "*DefaultFont: Courier%s", lf); | |
1263 | ||
1264 | for (fn = (ppdcFont *)fonts->first(); fn; fn = (ppdcFont *)fonts->next()) | |
1265 | if (!strcmp(fn->name->value, "*")) | |
1266 | { | |
1267 | for (bfn = (ppdcFont *)src->base_fonts->first(); | |
1268 | bfn; | |
1269 | bfn = (ppdcFont *)src->base_fonts->next()) | |
1270 | cupsFilePrintf(fp, "*Font %s: %s \"%s\" %s %s%s", | |
1271 | bfn->name->value, bfn->encoding->value, | |
1272 | bfn->version->value, bfn->charset->value, | |
1273 | bfn->status == PPDC_FONT_ROM ? "ROM" : "Disk", lf); | |
1274 | } | |
1275 | else | |
1276 | cupsFilePrintf(fp, "*Font %s: %s \"%s\" %s %s%s", | |
1277 | fn->name->value, fn->encoding->value, fn->version->value, | |
1278 | fn->charset->value, | |
1279 | fn->status == PPDC_FONT_ROM ? "ROM" : "Disk", lf); | |
1280 | ||
1281 | cupsFilePrintf(fp, "*%% End of %s, %05d bytes.%s", pc_file_name->value, | |
1282 | (int)(cupsFileTell(fp) + 25 + strlen(pc_file_name->value)), | |
1283 | lf); | |
1284 | ||
1285 | if (delete_cat) | |
e4572d57 | 1286 | catalog->release(); |
ac884b6a MS |
1287 | |
1288 | return (0); | |
1289 | } | |
1290 | ||
1291 | ||
1292 | // | |
1293 | // End of "$Id$". | |
1294 | // |