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