-
Notifications
You must be signed in to change notification settings - Fork 452
/
ppd.c
3531 lines (2811 loc) · 82 KB
/
ppd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* PPD file routines for CUPS.
*
* Copyright © 2007-2019 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more
* information.
*
* PostScript is a trademark of Adobe Systems, Inc.
*/
/*
* Include necessary headers.
*/
#include "cups-private.h"
#include "ppd-private.h"
#include "debug-internal.h"
/*
* Definitions...
*/
#define PPD_KEYWORD 1 /* Line contained a keyword */
#define PPD_OPTION 2 /* Line contained an option name */
#define PPD_TEXT 4 /* Line contained human-readable text */
#define PPD_STRING 8 /* Line contained a string or code */
#define PPD_HASHSIZE 512 /* Size of hash */
/*
* Line buffer structure...
*/
typedef struct _ppd_line_s
{
char *buffer; /* Pointer to buffer */
size_t bufsize; /* Size of the buffer */
} _ppd_line_t;
/*
* Local globals...
*/
static _cups_threadkey_t ppd_globals_key = _CUPS_THREADKEY_INITIALIZER;
/* Thread local storage key */
#ifdef HAVE_PTHREAD_H
static pthread_once_t ppd_globals_key_once = PTHREAD_ONCE_INIT;
/* One-time initialization object */
#endif /* HAVE_PTHREAD_H */
/*
* Local functions...
*/
static ppd_attr_t *ppd_add_attr(ppd_file_t *ppd, const char *name,
const char *spec, const char *text,
const char *value);
static ppd_choice_t *ppd_add_choice(ppd_option_t *option, const char *name);
static ppd_size_t *ppd_add_size(ppd_file_t *ppd, const char *name);
static int ppd_compare_attrs(ppd_attr_t *a, ppd_attr_t *b);
static int ppd_compare_choices(ppd_choice_t *a, ppd_choice_t *b);
static int ppd_compare_coptions(ppd_coption_t *a,
ppd_coption_t *b);
static int ppd_compare_options(ppd_option_t *a, ppd_option_t *b);
static int ppd_decode(char *string);
static void ppd_free_filters(ppd_file_t *ppd);
static void ppd_free_group(ppd_group_t *group);
static void ppd_free_option(ppd_option_t *option);
static ppd_coption_t *ppd_get_coption(ppd_file_t *ppd, const char *name);
static ppd_cparam_t *ppd_get_cparam(ppd_coption_t *opt,
const char *param,
const char *text);
static ppd_group_t *ppd_get_group(ppd_file_t *ppd, const char *name,
const char *text, _ppd_globals_t *pg,
cups_encoding_t encoding);
static ppd_option_t *ppd_get_option(ppd_group_t *group, const char *name);
static _ppd_globals_t *ppd_globals_alloc(void);
#if defined(HAVE_PTHREAD_H) || defined(_WIN32)
static void ppd_globals_free(_ppd_globals_t *g);
#endif /* HAVE_PTHREAD_H || _WIN32 */
#ifdef HAVE_PTHREAD_H
static void ppd_globals_init(void);
#endif /* HAVE_PTHREAD_H */
static int ppd_hash_option(ppd_option_t *option);
static int ppd_read(cups_file_t *fp, _ppd_line_t *line,
char *keyword, char *option, char *text,
char **string, int ignoreblank,
_ppd_globals_t *pg);
static int ppd_update_filters(ppd_file_t *ppd,
_ppd_globals_t *pg);
/*
* 'ppdClose()' - Free all memory used by the PPD file.
*/
void
ppdClose(ppd_file_t *ppd) /* I - PPD file record */
{
int i; /* Looping var */
ppd_group_t *group; /* Current group */
char **font; /* Current font */
ppd_attr_t **attr; /* Current attribute */
ppd_coption_t *coption; /* Current custom option */
ppd_cparam_t *cparam; /* Current custom parameter */
/*
* Range check arguments...
*/
if (!ppd)
return;
/*
* Free all strings at the top level...
*/
free(ppd->lang_encoding);
free(ppd->nickname);
free(ppd->patches);
free(ppd->emulations);
free(ppd->jcl_begin);
free(ppd->jcl_end);
free(ppd->jcl_ps);
/*
* Free any UI groups, subgroups, and options...
*/
if (ppd->num_groups > 0)
{
for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
ppd_free_group(group);
free(ppd->groups);
}
cupsArrayDelete(ppd->options);
cupsArrayDelete(ppd->marked);
/*
* Free any page sizes...
*/
if (ppd->num_sizes > 0)
free(ppd->sizes);
/*
* Free any constraints...
*/
if (ppd->num_consts > 0)
free(ppd->consts);
/*
* Free any filters...
*/
ppd_free_filters(ppd);
/*
* Free any fonts...
*/
if (ppd->num_fonts > 0)
{
for (i = ppd->num_fonts, font = ppd->fonts; i > 0; i --, font ++)
free(*font);
free(ppd->fonts);
}
/*
* Free any profiles...
*/
if (ppd->num_profiles > 0)
free(ppd->profiles);
/*
* Free any attributes...
*/
if (ppd->num_attrs > 0)
{
for (i = ppd->num_attrs, attr = ppd->attrs; i > 0; i --, attr ++)
{
free((*attr)->value);
free(*attr);
}
free(ppd->attrs);
}
cupsArrayDelete(ppd->sorted_attrs);
/*
* Free custom options...
*/
for (coption = (ppd_coption_t *)cupsArrayFirst(ppd->coptions);
coption;
coption = (ppd_coption_t *)cupsArrayNext(ppd->coptions))
{
for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
cparam;
cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
{
switch (cparam->type)
{
case PPD_CUSTOM_PASSCODE :
case PPD_CUSTOM_PASSWORD :
case PPD_CUSTOM_STRING :
free(cparam->current.custom_string);
break;
default :
break;
}
free(cparam);
}
cupsArrayDelete(coption->params);
free(coption);
}
cupsArrayDelete(ppd->coptions);
/*
* Free constraints...
*/
if (ppd->cups_uiconstraints)
{
_ppd_cups_uiconsts_t *consts; /* Current constraints */
for (consts = (_ppd_cups_uiconsts_t *)cupsArrayFirst(ppd->cups_uiconstraints);
consts;
consts = (_ppd_cups_uiconsts_t *)cupsArrayNext(ppd->cups_uiconstraints))
{
free(consts->constraints);
free(consts);
}
cupsArrayDelete(ppd->cups_uiconstraints);
}
/*
* Free any PPD cache/mapping data...
*/
if (ppd->cache)
_ppdCacheDestroy(ppd->cache);
/*
* Free the whole record...
*/
free(ppd);
}
/*
* 'ppdErrorString()' - Returns the text associated with a status.
*
* @since CUPS 1.1.19/macOS 10.3@
*/
const char * /* O - Status string */
ppdErrorString(ppd_status_t status) /* I - PPD status */
{
static const char * const messages[] =/* Status messages */
{
_("OK"),
_("Unable to open PPD file"),
_("NULL PPD file pointer"),
_("Memory allocation error"),
_("Missing PPD-Adobe-4.x header"),
_("Missing value string"),
_("Internal error"),
_("Bad OpenGroup"),
_("OpenGroup without a CloseGroup first"),
_("Bad OpenUI/JCLOpenUI"),
_("OpenUI/JCLOpenUI without a CloseUI/JCLCloseUI first"),
_("Bad OrderDependency"),
_("Bad UIConstraints"),
_("Missing asterisk in column 1"),
_("Line longer than the maximum allowed (255 characters)"),
_("Illegal control character"),
_("Illegal main keyword string"),
_("Illegal option keyword string"),
_("Illegal translation string"),
_("Illegal whitespace character"),
_("Bad custom parameter"),
_("Missing option keyword"),
_("Bad value string"),
_("Missing CloseGroup"),
_("Bad CloseUI/JCLCloseUI"),
_("Missing CloseUI/JCLCloseUI")
};
if (status < PPD_OK || status >= PPD_MAX_STATUS)
return (_cupsLangString(cupsLangDefault(), _("Unknown")));
else
return (_cupsLangString(cupsLangDefault(), messages[status]));
}
/*
* '_ppdGetEncoding()' - Get the CUPS encoding value for the given
* LanguageEncoding.
*/
cups_encoding_t /* O - CUPS encoding value */
_ppdGetEncoding(const char *name) /* I - LanguageEncoding string */
{
if (!_cups_strcasecmp(name, "ISOLatin1"))
return (CUPS_ISO8859_1);
else if (!_cups_strcasecmp(name, "ISOLatin2"))
return (CUPS_ISO8859_2);
else if (!_cups_strcasecmp(name, "ISOLatin5"))
return (CUPS_ISO8859_5);
else if (!_cups_strcasecmp(name, "JIS83-RKSJ"))
return (CUPS_JIS_X0213);
else if (!_cups_strcasecmp(name, "MacStandard"))
return (CUPS_MAC_ROMAN);
else if (!_cups_strcasecmp(name, "WindowsANSI"))
return (CUPS_WINDOWS_1252);
else
return (CUPS_UTF8);
}
/*
* '_ppdGlobals()' - Return a pointer to thread local storage
*/
_ppd_globals_t * /* O - Pointer to global data */
_ppdGlobals(void)
{
_ppd_globals_t *pg; /* Pointer to global data */
#ifdef HAVE_PTHREAD_H
/*
* Initialize the global data exactly once...
*/
pthread_once(&ppd_globals_key_once, ppd_globals_init);
#endif /* HAVE_PTHREAD_H */
/*
* See if we have allocated the data yet...
*/
if ((pg = (_ppd_globals_t *)_cupsThreadGetData(ppd_globals_key)) == NULL)
{
/*
* No, allocate memory as set the pointer for the key...
*/
if ((pg = ppd_globals_alloc()) != NULL)
_cupsThreadSetData(ppd_globals_key, pg);
}
/*
* Return the pointer to the data...
*/
return (pg);
}
/*
* 'ppdLastError()' - Return the status from the last ppdOpen*().
*
* @since CUPS 1.1.19/macOS 10.3@
*/
ppd_status_t /* O - Status code */
ppdLastError(int *line) /* O - Line number */
{
_ppd_globals_t *pg = _ppdGlobals();
/* Global data */
if (line)
*line = pg->ppd_line;
return (pg->ppd_status);
}
/*
* '_ppdOpen()' - Read a PPD file into memory.
*
* @since CUPS 1.2/macOS 10.5@
*/
ppd_file_t * /* O - PPD file record or @code NULL@ if the PPD file could not be opened. */
_ppdOpen(
cups_file_t *fp, /* I - File to read from */
_ppd_localization_t localization) /* I - Localization to load */
{
int i, j, k; /* Looping vars */
_ppd_line_t line; /* Line buffer */
ppd_file_t *ppd; /* PPD file record */
ppd_group_t *group, /* Current group */
*subgroup; /* Current sub-group */
ppd_option_t *option; /* Current option */
ppd_choice_t *choice; /* Current choice */
ppd_const_t *constraint; /* Current constraint */
ppd_size_t *size; /* Current page size */
int mask; /* Line data mask */
char keyword[PPD_MAX_NAME],
/* Keyword from file */
name[PPD_MAX_NAME],
/* Option from file */
text[PPD_MAX_LINE],
/* Human-readable text from file */
*string, /* Code/text from file */
*sptr, /* Pointer into string */
*temp, /* Temporary string pointer */
**tempfonts; /* Temporary fonts pointer */
float order; /* Order dependency number */
ppd_section_t section; /* Order dependency section */
ppd_profile_t *profile; /* Pointer to color profile */
char **filter; /* Pointer to filter */
struct lconv *loc; /* Locale data */
int ui_keyword; /* Is this line a UI keyword? */
cups_lang_t *lang; /* Language data */
cups_encoding_t encoding; /* Encoding of PPD file */
_ppd_globals_t *pg = _ppdGlobals();
/* Global data */
char custom_name[PPD_MAX_NAME];
/* CustomFoo attribute name */
ppd_attr_t *custom_attr; /* CustomFoo attribute */
char ll[7], /* Base language + '.' */
ll_CC[7]; /* Language w/country + '.' */
size_t ll_len = 0, /* Base language length */
ll_CC_len = 0; /* Language w/country length */
static const char * const ui_keywords[] =
{
#ifdef CUPS_USE_FULL_UI_KEYWORDS_LIST
/*
* Adobe defines some 41 keywords as "UI", meaning that they are
* user interface elements and that they should be treated as such
* even if the PPD creator doesn't use Open/CloseUI around them.
*
* Since this can cause previously invisible options to appear and
* confuse users, the default is to only treat the PageSize and
* PageRegion keywords this way.
*/
/* Boolean keywords */
"BlackSubstitution",
"Booklet",
"Collate",
"ManualFeed",
"MirrorPrint",
"NegativePrint",
"Sorter",
"TraySwitch",
/* PickOne keywords */
"AdvanceMedia",
"BindColor",
"BindEdge",
"BindType",
"BindWhen",
"BitsPerPixel",
"ColorModel",
"CutMedia",
"Duplex",
"FoldType",
"FoldWhen",
"InputSlot",
"JCLFrameBufferSize",
"JCLResolution",
"Jog",
"MediaColor",
"MediaType",
"MediaWeight",
"OutputBin",
"OutputMode",
"OutputOrder",
"PageRegion",
"PageSize",
"Resolution",
"Separations",
"Signature",
"Slipsheet",
"Smoothing",
"StapleLocation",
"StapleOrientation",
"StapleWhen",
"StapleX",
"StapleY"
#else /* !CUPS_USE_FULL_UI_KEYWORDS_LIST */
"PageRegion",
"PageSize"
#endif /* CUPS_USE_FULL_UI_KEYWORDS_LIST */
};
static const char * const color_keywords[] = /* Keywords associated with color profiles */
{
".cupsICCProfile",
".ColorModel",
};
DEBUG_printf(("_ppdOpen(fp=%p)", fp));
/*
* Default to "OK" status...
*/
pg->ppd_status = PPD_OK;
pg->ppd_line = 0;
/*
* Range check input...
*/
if (fp == NULL)
{
pg->ppd_status = PPD_NULL_FILE;
return (NULL);
}
/*
* If only loading a single localization set up the strings to match...
*/
if (localization == _PPD_LOCALIZATION_DEFAULT)
{
if ((lang = cupsLangDefault()) == NULL)
return (NULL);
snprintf(ll_CC, sizeof(ll_CC), "%s.", lang->language);
/*
* <rdar:https://problem/22130168>
* <rdar:https://problem/27245567>
*
* Need to use a different base language for some locales...
*/
if (!strcmp(lang->language, "zh_HK"))
{ /* Traditional Chinese + variants */
strlcpy(ll_CC, "zh_TW.", sizeof(ll_CC));
strlcpy(ll, "zh_", sizeof(ll));
}
else if (!strncmp(lang->language, "zh", 2))
strlcpy(ll, "zh_", sizeof(ll)); /* Any Chinese variant */
else if (!strncmp(lang->language, "jp", 2))
{ /* Any Japanese variant */
strlcpy(ll_CC, "ja", sizeof(ll_CC));
strlcpy(ll, "jp", sizeof(ll));
}
else if (!strncmp(lang->language, "nb", 2) || !strncmp(lang->language, "no", 2))
{ /* Any Norwegian variant */
strlcpy(ll_CC, "nb", sizeof(ll_CC));
strlcpy(ll, "no", sizeof(ll));
}
else
snprintf(ll, sizeof(ll), "%2.2s.", lang->language);
ll_CC_len = strlen(ll_CC);
ll_len = strlen(ll);
DEBUG_printf(("2_ppdOpen: Loading localizations matching \"%s\" and \"%s\"",
ll_CC, ll));
}
/*
* Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
*/
line.buffer = NULL;
line.bufsize = 0;
mask = ppd_read(fp, &line, keyword, name, text, &string, 0, pg);
DEBUG_printf(("2_ppdOpen: mask=%x, keyword=\"%s\"...", mask, keyword));
if (mask == 0 ||
strcmp(keyword, "PPD-Adobe") ||
string == NULL || string[0] != '4')
{
/*
* Either this is not a PPD file, or it is not a 4.x PPD file.
*/
if (pg->ppd_status == PPD_OK)
pg->ppd_status = PPD_MISSING_PPDADOBE4;
free(string);
free(line.buffer);
return (NULL);
}
DEBUG_printf(("2_ppdOpen: keyword=%s, string=%p", keyword, string));
/*
* Allocate memory for the PPD file record...
*/
if ((ppd = calloc(1, sizeof(ppd_file_t))) == NULL)
{
pg->ppd_status = PPD_ALLOC_ERROR;
free(string);
free(line.buffer);
return (NULL);
}
free(string);
string = NULL;
ppd->language_level = 2;
ppd->color_device = 0;
ppd->colorspace = PPD_CS_N;
ppd->landscape = -90;
ppd->coptions = cupsArrayNew((cups_array_func_t)ppd_compare_coptions, NULL);
/*
* Read lines from the PPD file and add them to the file record...
*/
group = NULL;
subgroup = NULL;
option = NULL;
choice = NULL;
ui_keyword = 0;
encoding = CUPS_ISO8859_1;
loc = localeconv();
while ((mask = ppd_read(fp, &line, keyword, name, text, &string, 1, pg)) != 0)
{
DEBUG_printf(("2_ppdOpen: mask=%x, keyword=\"%s\", name=\"%s\", "
"text=\"%s\", string=%d chars...", mask, keyword, name, text,
string ? (int)strlen(string) : 0));
if (strncmp(keyword, "Default", 7) && !string &&
pg->ppd_conform != PPD_CONFORM_RELAXED)
{
/*
* Need a string value!
*/
pg->ppd_status = PPD_MISSING_VALUE;
goto error;
}
else if (!string)
continue;
/*
* Certain main keywords (as defined by the PPD spec) may be used
* without the usual OpenUI/CloseUI stuff. Presumably this is just
* so that Adobe wouldn't completely break compatibility with PPD
* files prior to v4.0 of the spec, but it is hopelessly
* inconsistent... Catch these main keywords and automatically
* create the corresponding option, as needed...
*/
if (ui_keyword)
{
/*
* Previous line was a UI keyword...
*/
option = NULL;
ui_keyword = 0;
}
/*
* If we are filtering out keyword localizations, see if this line needs to
* be used...
*/
if (localization != _PPD_LOCALIZATION_ALL &&
(temp = strchr(keyword, '.')) != NULL &&
((temp - keyword) == 2 || (temp - keyword) == 5) &&
_cups_isalpha(keyword[0]) &&
_cups_isalpha(keyword[1]) &&
(keyword[2] == '.' ||
(keyword[2] == '_' && _cups_isalpha(keyword[3]) &&
_cups_isalpha(keyword[4]) && keyword[5] == '.')))
{
if (localization == _PPD_LOCALIZATION_NONE ||
(localization == _PPD_LOCALIZATION_DEFAULT &&
strncmp(ll_CC, keyword, ll_CC_len) &&
strncmp(ll, keyword, ll_len)))
{
DEBUG_printf(("2_ppdOpen: Ignoring localization: \"%s\"\n", keyword));
free(string);
string = NULL;
continue;
}
else if (localization == _PPD_LOCALIZATION_ICC_PROFILES)
{
/*
* Only load localizations for the color profile related keywords...
*/
for (i = 0;
i < (int)(sizeof(color_keywords) / sizeof(color_keywords[0]));
i ++)
{
if (!_cups_strcasecmp(temp, color_keywords[i]))
break;
}
if (i >= (int)(sizeof(color_keywords) / sizeof(color_keywords[0])))
{
DEBUG_printf(("2_ppdOpen: Ignoring localization: \"%s\"\n", keyword));
free(string);
string = NULL;
continue;
}
}
}
if (option == NULL &&
(mask & (PPD_KEYWORD | PPD_OPTION | PPD_STRING)) ==
(PPD_KEYWORD | PPD_OPTION | PPD_STRING))
{
for (i = 0; i < (int)(sizeof(ui_keywords) / sizeof(ui_keywords[0])); i ++)
if (!strcmp(keyword, ui_keywords[i]))
break;
if (i < (int)(sizeof(ui_keywords) / sizeof(ui_keywords[0])))
{
/*
* Create the option in the appropriate group...
*/
ui_keyword = 1;
DEBUG_printf(("2_ppdOpen: FOUND ADOBE UI KEYWORD %s WITHOUT OPENUI!",
keyword));
if (!group)
{
if ((group = ppd_get_group(ppd, "General", _("General"), pg,
encoding)) == NULL)
goto error;
DEBUG_printf(("2_ppdOpen: Adding to group %s...", group->text));
option = ppd_get_option(group, keyword);
group = NULL;
}
else
option = ppd_get_option(group, keyword);
if (option == NULL)
{
pg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
/*
* Now fill in the initial information for the option...
*/
if (!strncmp(keyword, "JCL", 3))
option->section = PPD_ORDER_JCL;
else
option->section = PPD_ORDER_ANY;
option->order = 10.0f;
if (i < 8)
option->ui = PPD_UI_BOOLEAN;
else
option->ui = PPD_UI_PICKONE;
for (j = 0; j < ppd->num_attrs; j ++)
if (!strncmp(ppd->attrs[j]->name, "Default", 7) &&
!strcmp(ppd->attrs[j]->name + 7, keyword) &&
ppd->attrs[j]->value)
{
DEBUG_printf(("2_ppdOpen: Setting Default%s to %s via attribute...",
option->keyword, ppd->attrs[j]->value));
strlcpy(option->defchoice, ppd->attrs[j]->value,
sizeof(option->defchoice));
break;
}
if (!strcmp(keyword, "PageSize"))
strlcpy(option->text, _("Media Size"), sizeof(option->text));
else if (!strcmp(keyword, "MediaType"))
strlcpy(option->text, _("Media Type"), sizeof(option->text));
else if (!strcmp(keyword, "InputSlot"))
strlcpy(option->text, _("Media Source"), sizeof(option->text));
else if (!strcmp(keyword, "ColorModel"))
strlcpy(option->text, _("Output Mode"), sizeof(option->text));
else if (!strcmp(keyword, "Resolution"))
strlcpy(option->text, _("Resolution"), sizeof(option->text));
else
strlcpy(option->text, keyword, sizeof(option->text));
}
}
if (!strcmp(keyword, "LanguageLevel"))
ppd->language_level = atoi(string);
else if (!strcmp(keyword, "LanguageEncoding"))
{
/*
* Say all PPD files are UTF-8, since we convert to UTF-8...
*/
ppd->lang_encoding = strdup("UTF-8");
encoding = _ppdGetEncoding(string);
}
else if (!strcmp(keyword, "LanguageVersion"))
ppd->lang_version = string;
else if (!strcmp(keyword, "Manufacturer"))
ppd->manufacturer = string;
else if (!strcmp(keyword, "ModelName"))
ppd->modelname = string;
else if (!strcmp(keyword, "Protocols"))
ppd->protocols = string;
else if (!strcmp(keyword, "PCFileName"))
ppd->pcfilename = string;
else if (!strcmp(keyword, "NickName"))
{
if (encoding != CUPS_UTF8)
{
cups_utf8_t utf8[256]; /* UTF-8 version of NickName */
cupsCharsetToUTF8(utf8, string, sizeof(utf8), encoding);
ppd->nickname = strdup((char *)utf8);
}
else
ppd->nickname = strdup(string);
}
else if (!strcmp(keyword, "Product"))
ppd->product = string;
else if (!strcmp(keyword, "ShortNickName"))
ppd->shortnickname = string;
else if (!strcmp(keyword, "TTRasterizer"))
ppd->ttrasterizer = string;
else if (!strcmp(keyword, "JCLBegin"))
{
ppd->jcl_begin = strdup(string);
ppd_decode(ppd->jcl_begin); /* Decode quoted string */
}
else if (!strcmp(keyword, "JCLEnd"))
{
ppd->jcl_end = strdup(string);
ppd_decode(ppd->jcl_end); /* Decode quoted string */
}
else if (!strcmp(keyword, "JCLToPSInterpreter"))
{
ppd->jcl_ps = strdup(string);
ppd_decode(ppd->jcl_ps); /* Decode quoted string */
}
else if (!strcmp(keyword, "AccurateScreensSupport"))
ppd->accurate_screens = !strcasecmp(string, "True");
else if (!strcmp(keyword, "ColorDevice"))
ppd->color_device = !strcasecmp(string, "True");
else if (!strcmp(keyword, "ContoneOnly"))
ppd->contone_only = !strcasecmp(string, "True");
else if (!strcmp(keyword, "cupsFlipDuplex"))
ppd->flip_duplex = !strcasecmp(string, "True");
else if (!strcmp(keyword, "cupsManualCopies"))
ppd->manual_copies = !strcasecmp(string, "True");
else if (!strcmp(keyword, "cupsModelNumber"))
ppd->model_number = atoi(string);
else if (!strcmp(keyword, "cupsColorProfile"))
{
if (ppd->num_profiles == 0)
profile = malloc(sizeof(ppd_profile_t));
else
profile = realloc(ppd->profiles, sizeof(ppd_profile_t) * (size_t)(ppd->num_profiles + 1));
if (!profile)
{
pg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
ppd->profiles = profile;
profile += ppd->num_profiles;
ppd->num_profiles ++;
memset(profile, 0, sizeof(ppd_profile_t));
strlcpy(profile->resolution, name, sizeof(profile->resolution));
strlcpy(profile->media_type, text, sizeof(profile->media_type));
profile->density = (float)_cupsStrScand(string, &sptr, loc);
profile->gamma = (float)_cupsStrScand(sptr, &sptr, loc);
profile->matrix[0][0] = (float)_cupsStrScand(sptr, &sptr, loc);
profile->matrix[0][1] = (float)_cupsStrScand(sptr, &sptr, loc);
profile->matrix[0][2] = (float)_cupsStrScand(sptr, &sptr, loc);
profile->matrix[1][0] = (float)_cupsStrScand(sptr, &sptr, loc);
profile->matrix[1][1] = (float)_cupsStrScand(sptr, &sptr, loc);
profile->matrix[1][2] = (float)_cupsStrScand(sptr, &sptr, loc);
profile->matrix[2][0] = (float)_cupsStrScand(sptr, &sptr, loc);
profile->matrix[2][1] = (float)_cupsStrScand(sptr, &sptr, loc);
profile->matrix[2][2] = (float)_cupsStrScand(sptr, &sptr, loc);
}
else if (!strcmp(keyword, "cupsFilter"))
{
if (ppd->num_filters == 0)
filter = malloc(sizeof(char *));
else
filter = realloc(ppd->filters, sizeof(char *) * (size_t)(ppd->num_filters + 1));
if (filter == NULL)
{
pg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
ppd->filters = filter;
filter += ppd->num_filters;
ppd->num_filters ++;
/*
* Make a copy of the filter string...
*/
*filter = strdup(string);
}
else if (!strcmp(keyword, "Throughput"))
ppd->throughput = atoi(string);
else if (!strcmp(keyword, "Font"))
{
/*
* Add this font to the list of available fonts...
*/
if (ppd->num_fonts == 0)
tempfonts = (char **)malloc(sizeof(char *));
else
tempfonts = (char **)realloc(ppd->fonts, sizeof(char *) * (size_t)(ppd->num_fonts + 1));
if (tempfonts == NULL)
{
pg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
ppd->fonts = tempfonts;
ppd->fonts[ppd->num_fonts] = strdup(name);
ppd->num_fonts ++;
}
else if (!strncmp(keyword, "ParamCustom", 11))
{
ppd_coption_t *coption; /* Custom option */
ppd_cparam_t *cparam; /* Custom parameter */
int corder; /* Order number */
char ctype[33], /* Data type */
cminimum[65], /* Minimum value */
cmaximum[65]; /* Maximum value */
/*
* Get the custom option and parameter...
*/
if ((coption = ppd_get_coption(ppd, keyword + 11)) == NULL)
{
pg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
if ((cparam = ppd_get_cparam(coption, name, text)) == NULL)
{
pg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
if (cparam->type != PPD_CUSTOM_UNKNOWN)
{
pg->ppd_status = PPD_BAD_CUSTOM_PARAM;
goto error;