/
ppdc-source.cxx
3800 lines (3208 loc) · 89 KB
/
ppdc-source.cxx
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
//
// Source class for the CUPS PPD Compiler.
//
// Copyright 2007-2020 by Apple Inc.
// Copyright 2002-2007 by Easy Software Products.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
//
//
// Include necessary headers...
//
#include "ppdc-private.h"
#include <limits.h>
#include <math.h>
#include <unistd.h>
#include <cups/raster.h>
#include "data/epson.h"
#include "data/hp.h"
#include "data/label.h"
#ifndef _WIN32
# include <sys/utsname.h>
#endif // !_WIN32
//
// Class globals...
//
ppdcArray *ppdcSource::includes = 0;
const char *ppdcSource::driver_types[] =
{
"custom",
"ps",
"escp",
"pcl",
"label",
"epson",
"hp"
};
//
// 'ppdcSource::ppdcSource()' - Load a driver source file.
//
ppdcSource::ppdcSource(const char *f, // I - File to read
cups_file_t *ffp)// I - File pointer to use
: ppdcShared()
{
PPDC_NEW;
filename = new ppdcString(f);
base_fonts = new ppdcArray();
drivers = new ppdcArray();
po_files = new ppdcArray();
sizes = new ppdcArray();
vars = new ppdcArray();
cond_state = PPDC_COND_NORMAL;
cond_current = cond_stack;
cond_stack[0] = PPDC_COND_NORMAL;
// Add standard #define variables...
#define MAKE_STRING(x) #x
vars->add(new ppdcVariable("CUPS_VERSION", MAKE_STRING(CUPS_VERSION)));
vars->add(new ppdcVariable("CUPS_VERSION_MAJOR", MAKE_STRING(CUPS_VERSION_MAJOR)));
vars->add(new ppdcVariable("CUPS_VERSION_MINOR", MAKE_STRING(CUPS_VERSION_MINOR)));
vars->add(new ppdcVariable("CUPS_VERSION_PATCH", MAKE_STRING(CUPS_VERSION_PATCH)));
#ifdef _WIN32
vars->add(new ppdcVariable("PLATFORM_NAME", "Windows"));
vars->add(new ppdcVariable("PLATFORM_ARCH", "X86"));
#else
struct utsname name; // uname information
if (!uname(&name))
{
vars->add(new ppdcVariable("PLATFORM_NAME", name.sysname));
vars->add(new ppdcVariable("PLATFORM_ARCH", name.machine));
}
else
{
vars->add(new ppdcVariable("PLATFORM_NAME", "unknown"));
vars->add(new ppdcVariable("PLATFORM_ARCH", "unknown"));
}
#endif // _WIN32
if (f)
read_file(f, ffp);
}
//
// 'ppdcSource::~ppdcSource()' - Free a driver source file.
//
ppdcSource::~ppdcSource()
{
PPDC_DELETE;
filename->release();
base_fonts->release();
drivers->release();
po_files->release();
sizes->release();
vars->release();
}
//
// 'ppdcSource::add_include()' - Add an include directory.
//
void
ppdcSource::add_include(const char *d) // I - Include directory
{
if (!d)
return;
if (!includes)
includes = new ppdcArray();
includes->add(new ppdcString(d));
}
//
// 'ppdcSource::find_driver()' - Find a driver.
//
ppdcDriver * // O - Driver
ppdcSource::find_driver(const char *f) // I - Driver file name
{
ppdcDriver *d; // Current driver
for (d = (ppdcDriver *)drivers->first(); d; d = (ppdcDriver *)drivers->next())
if (!_cups_strcasecmp(f, d->pc_file_name->value))
return (d);
return (NULL);
}
//
// 'ppdcSource::find_include()' - Find an include file.
//
char * // O - Found path or NULL
ppdcSource::find_include(
const char *f, // I - Include filename
const char *base, // I - Current directory
char *n, // I - Path buffer
int nlen) // I - Path buffer length
{
ppdcString *dir; // Include directory
char temp[1024], // Temporary path
*ptr; // Pointer to end of path
// Range check input...
if (!f || !*f || !n || nlen < 2)
return (0);
// Check the first character to see if we have <name> or "name"...
if (*f == '<')
{
// Remove the surrounding <> from the name...
strlcpy(temp, f + 1, sizeof(temp));
ptr = temp + strlen(temp) - 1;
if (*ptr != '>')
{
_cupsLangPrintf(stderr,
_("ppdc: Invalid #include/#po filename \"%s\"."), n);
return (0);
}
*ptr = '\0';
f = temp;
}
else
{
// Check for the local file relative to the current directory...
if (base && *base && f[0] != '/')
snprintf(n, (size_t)nlen, "%s/%s", base, f);
else
strlcpy(n, f, (size_t)nlen);
if (!access(n, 0))
return (n);
else if (*f == '/')
{
// Absolute path that doesn't exist...
return (0);
}
}
// Search the include directories, if any...
if (includes)
{
for (dir = (ppdcString *)includes->first(); dir; dir = (ppdcString *)includes->next())
{
snprintf(n, (size_t)nlen, "%s/%s", dir->value, f);
if (!access(n, 0))
return (n);
}
}
// Search the standard include directories...
_cups_globals_t *cg = _cupsGlobals(); // Global data
snprintf(n, (size_t)nlen, "%s/ppdc/%s", cg->cups_datadir, f);
if (!access(n, 0))
return (n);
snprintf(n, (size_t)nlen, "%s/po/%s", cg->cups_datadir, f);
if (!access(n, 0))
return (n);
else
return (0);
}
//
// 'ppdcSource::find_po()' - Find a message catalog for the given locale.
//
ppdcCatalog * // O - Message catalog or NULL
ppdcSource::find_po(const char *l) // I - Locale name
{
ppdcCatalog *cat; // Current message catalog
for (cat = (ppdcCatalog *)po_files->first();
cat;
cat = (ppdcCatalog *)po_files->next())
if (!_cups_strcasecmp(l, cat->locale->value))
return (cat);
return (NULL);
}
//
// 'ppdcSource::find_size()' - Find a media size.
//
ppdcMediaSize * // O - Size
ppdcSource::find_size(const char *s) // I - Size name
{
ppdcMediaSize *m; // Current media size
for (m = (ppdcMediaSize *)sizes->first(); m; m = (ppdcMediaSize *)sizes->next())
if (!_cups_strcasecmp(s, m->name->value))
return (m);
return (NULL);
}
//
// 'ppdcSource::find_variable()' - Find a variable.
//
ppdcVariable * // O - Variable
ppdcSource::find_variable(const char *n)// I - Variable name
{
ppdcVariable *v; // Current variable
for (v = (ppdcVariable *)vars->first(); v; v = (ppdcVariable *)vars->next())
if (!_cups_strcasecmp(n, v->name->value))
return (v);
return (NULL);
}
//
// 'ppdcSource::get_attr()' - Get an attribute.
//
ppdcAttr * // O - Attribute
ppdcSource::get_attr(ppdcFile *fp, // I - File to read
bool loc) // I - Localize this attribute?
{
char name[1024], // Name string
selector[1024], // Selector string
*text, // Text string
value[1024]; // Value string
// Get the attribute parameters:
//
// Attribute name selector value
if (!get_token(fp, name, sizeof(name)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected name after %s on line %d of %s."),
loc ? "LocAttribute" : "Attribute", fp->line, fp->filename);
return (0);
}
if (!get_token(fp, selector, sizeof(selector)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected selector after %s on line %d of %s."),
loc ? "LocAttribute" : "Attribute", fp->line, fp->filename);
return (0);
}
if ((text = strchr(selector, '/')) != NULL)
*text++ = '\0';
if (!get_token(fp, value, sizeof(value)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected value after %s on line %d of %s."),
loc ? "LocAttribute" : "Attribute", fp->line, fp->filename);
return (0);
}
return (new ppdcAttr(name, selector, text, value, loc));
}
//
// 'ppdcSource::get_boolean()' - Get a boolean value.
//
int // O - Boolean value
ppdcSource::get_boolean(ppdcFile *fp) // I - File to read
{
char buffer[256]; // String buffer
if (!get_token(fp, buffer, sizeof(buffer)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected boolean value on line %d of %s."),
fp->line, fp->filename);
return (-1);
}
if (!_cups_strcasecmp(buffer, "on") ||
!_cups_strcasecmp(buffer, "yes") ||
!_cups_strcasecmp(buffer, "true"))
return (1);
else if (!_cups_strcasecmp(buffer, "off") ||
!_cups_strcasecmp(buffer, "no") ||
!_cups_strcasecmp(buffer, "false"))
return (0);
else
{
_cupsLangPrintf(stderr,
_("ppdc: Bad boolean value (%s) on line %d of %s."),
buffer, fp->line, fp->filename);
return (-1);
}
}
//
// 'ppdcSource::get_choice()' - Get a choice.
//
ppdcChoice * // O - Choice data
ppdcSource::get_choice(ppdcFile *fp) // I - File to read
{
char name[1024], // Name
*text, // Text
code[10240]; // Code
// Read a choice from the file:
//
// Choice name/text code
if (!get_token(fp, name, sizeof(name)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected choice name/text on line %d of %s."),
fp->line, fp->filename);
return (NULL);
}
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
if (!get_token(fp, code, sizeof(code)))
{
_cupsLangPrintf(stderr, _("ppdc: Expected choice code on line %d of %s."),
fp->line, fp->filename);
return (NULL);
}
// Return the new choice
return (new ppdcChoice(name, text, code));
}
//
// 'ppdcSource::get_color_model()' - Get an old-style color model option.
//
ppdcChoice * // O - Choice data
ppdcSource::get_color_model(ppdcFile *fp)
// I - File to read
{
char name[1024], // Option name
*text, // Text option
temp[256]; // Temporary string
int color_space, // Colorspace
color_order, // Color order
compression; // Compression mode
// Get the ColorModel parameters:
//
// ColorModel name/text colorspace colororder compression
if (!get_token(fp, name, sizeof(name)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected name/text combination for ColorModel on "
"line %d of %s."), fp->line, fp->filename);
return (NULL);
}
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
if (!get_token(fp, temp, sizeof(temp)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected colorspace for ColorModel on line %d of "
"%s."), fp->line, fp->filename);
return (NULL);
}
if ((color_space = get_color_space(temp)) < 0)
color_space = get_integer(temp);
if (!get_token(fp, temp, sizeof(temp)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected color order for ColorModel on line %d of "
"%s."), fp->line, fp->filename);
return (NULL);
}
if ((color_order = get_color_order(temp)) < 0)
color_order = get_integer(temp);
if (!get_token(fp, temp, sizeof(temp)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected compression for ColorModel on line %d of "
"%s."), fp->line, fp->filename);
return (NULL);
}
compression = get_integer(temp);
snprintf(temp, sizeof(temp),
"<</cupsColorSpace %d/cupsColorOrder %d/cupsCompression %d>>"
"setpagedevice",
color_space, color_order, compression);
return (new ppdcChoice(name, text, temp));
}
//
// 'ppdcSource::get_color_order()' - Get an old-style color order value.
//
int // O - Color order value
ppdcSource::get_color_order(
const char *co) // I - Color order string
{
if (!_cups_strcasecmp(co, "chunked") ||
!_cups_strcasecmp(co, "chunky"))
return (CUPS_ORDER_CHUNKED);
else if (!_cups_strcasecmp(co, "banded"))
return (CUPS_ORDER_BANDED);
else if (!_cups_strcasecmp(co, "planar"))
return (CUPS_ORDER_PLANAR);
else
return (-1);
}
//
// 'ppdcSource::get_color_profile()' - Get a color profile definition.
//
ppdcProfile * // O - Color profile
ppdcSource::get_color_profile(
ppdcFile *fp) // I - File to read
{
char resolution[1024], // Resolution/media type
*media_type; // Media type
int i; // Looping var
float g, // Gamma value
d, // Density value
m[9]; // Transform matrix
// Get the ColorProfile parameters:
//
// ColorProfile resolution/mediatype gamma density m00 m01 m02 ... m22
if (!get_token(fp, resolution, sizeof(resolution)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected resolution/mediatype following "
"ColorProfile on line %d of %s."),
fp->line, fp->filename);
return (NULL);
}
if ((media_type = strchr(resolution, '/')) != NULL)
*media_type++ = '\0';
else
media_type = resolution;
g = get_float(fp);
d = get_float(fp);
for (i = 0; i < 9; i ++)
m[i] = get_float(fp);
return (new ppdcProfile(resolution, media_type, d, g, m));
}
//
// 'ppdcSource::get_color_space()' - Get an old-style colorspace value.
//
int // O - Colorspace value
ppdcSource::get_color_space(
const char *cs) // I - Colorspace string
{
if (!_cups_strcasecmp(cs, "w"))
return (CUPS_CSPACE_W);
else if (!_cups_strcasecmp(cs, "rgb"))
return (CUPS_CSPACE_RGB);
else if (!_cups_strcasecmp(cs, "rgba"))
return (CUPS_CSPACE_RGBA);
else if (!_cups_strcasecmp(cs, "k"))
return (CUPS_CSPACE_K);
else if (!_cups_strcasecmp(cs, "cmy"))
return (CUPS_CSPACE_CMY);
else if (!_cups_strcasecmp(cs, "ymc"))
return (CUPS_CSPACE_YMC);
else if (!_cups_strcasecmp(cs, "cmyk"))
return (CUPS_CSPACE_CMYK);
else if (!_cups_strcasecmp(cs, "ymck"))
return (CUPS_CSPACE_YMCK);
else if (!_cups_strcasecmp(cs, "kcmy"))
return (CUPS_CSPACE_KCMY);
else if (!_cups_strcasecmp(cs, "kcmycm"))
return (CUPS_CSPACE_KCMYcm);
else if (!_cups_strcasecmp(cs, "gmck"))
return (CUPS_CSPACE_GMCK);
else if (!_cups_strcasecmp(cs, "gmcs"))
return (CUPS_CSPACE_GMCS);
else if (!_cups_strcasecmp(cs, "white"))
return (CUPS_CSPACE_WHITE);
else if (!_cups_strcasecmp(cs, "gold"))
return (CUPS_CSPACE_GOLD);
else if (!_cups_strcasecmp(cs, "silver"))
return (CUPS_CSPACE_SILVER);
else if (!_cups_strcasecmp(cs, "CIEXYZ"))
return (CUPS_CSPACE_CIEXYZ);
else if (!_cups_strcasecmp(cs, "CIELab"))
return (CUPS_CSPACE_CIELab);
else if (!_cups_strcasecmp(cs, "RGBW"))
return (CUPS_CSPACE_RGBW);
else if (!_cups_strcasecmp(cs, "ICC1"))
return (CUPS_CSPACE_ICC1);
else if (!_cups_strcasecmp(cs, "ICC2"))
return (CUPS_CSPACE_ICC2);
else if (!_cups_strcasecmp(cs, "ICC3"))
return (CUPS_CSPACE_ICC3);
else if (!_cups_strcasecmp(cs, "ICC4"))
return (CUPS_CSPACE_ICC4);
else if (!_cups_strcasecmp(cs, "ICC5"))
return (CUPS_CSPACE_ICC5);
else if (!_cups_strcasecmp(cs, "ICC6"))
return (CUPS_CSPACE_ICC6);
else if (!_cups_strcasecmp(cs, "ICC7"))
return (CUPS_CSPACE_ICC7);
else if (!_cups_strcasecmp(cs, "ICC8"))
return (CUPS_CSPACE_ICC8);
else if (!_cups_strcasecmp(cs, "ICC9"))
return (CUPS_CSPACE_ICC9);
else if (!_cups_strcasecmp(cs, "ICCA"))
return (CUPS_CSPACE_ICCA);
else if (!_cups_strcasecmp(cs, "ICCB"))
return (CUPS_CSPACE_ICCB);
else if (!_cups_strcasecmp(cs, "ICCC"))
return (CUPS_CSPACE_ICCC);
else if (!_cups_strcasecmp(cs, "ICCD"))
return (CUPS_CSPACE_ICCD);
else if (!_cups_strcasecmp(cs, "ICCE"))
return (CUPS_CSPACE_ICCE);
else if (!_cups_strcasecmp(cs, "ICCF"))
return (CUPS_CSPACE_ICCF);
else
return (-1);
}
//
// 'ppdcSource::get_constraint()' - Get a constraint.
//
ppdcConstraint * // O - Constraint
ppdcSource::get_constraint(ppdcFile *fp)// I - File to read
{
char temp[1024], // One string to rule them all
*ptr, // Pointer into string
*option1, // Constraint option 1
*choice1, // Constraint choice 1
*option2, // Constraint option 2
*choice2; // Constraint choice 2
// Read the UIConstaints parameter in one of the following forms:
//
// UIConstraints "*Option1 *Option2"
// UIConstraints "*Option1 Choice1 *Option2"
// UIConstraints "*Option1 *Option2 Choice2"
// UIConstraints "*Option1 Choice1 *Option2 Choice2"
if (!get_token(fp, temp, sizeof(temp)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected constraints string for UIConstraints on "
"line %d of %s."), fp->line, fp->filename);
return (NULL);
}
for (ptr = temp; isspace(*ptr); ptr ++);
if (*ptr != '*')
{
_cupsLangPrintf(stderr,
_("ppdc: Option constraint must *name on line %d of %s."),
fp->line, fp->filename);
return (NULL);
}
option1 = ptr;
for (; *ptr && !isspace(*ptr); ptr ++);
for (; isspace(*ptr); *ptr++ = '\0');
if (*ptr != '*')
{
choice1 = ptr;
for (; *ptr && !isspace(*ptr); ptr ++);
for (; isspace(*ptr); *ptr++ = '\0');
}
else
choice1 = NULL;
if (*ptr != '*')
{
_cupsLangPrintf(stderr,
_("ppdc: Expected two option names on line %d of %s."),
fp->line, fp->filename);
return (NULL);
}
option2 = ptr;
for (; *ptr && !isspace(*ptr); ptr ++);
for (; isspace(*ptr); *ptr++ = '\0');
if (*ptr)
choice2 = ptr;
else
choice2 = NULL;
return (new ppdcConstraint(option1, choice1, option2, choice2));
}
//
// 'ppdcSource::get_custom_size()' - Get a custom media size definition from a file.
//
ppdcMediaSize * // O - Media size
ppdcSource::get_custom_size(ppdcFile *fp)
// I - File to read
{
char name[1024], // Name
*text, // Text
size_code[10240], // PageSize code
region_code[10240]; // PageRegion
float width, // Width
length, // Length
left, // Left margin
bottom, // Bottom margin
right, // Right margin
top; // Top margin
// Get the name, text, width, length, margins, and code:
//
// CustomMedia name/text width length left bottom right top size-code region-code
if (!get_token(fp, name, sizeof(name)))
return (NULL);
if ((text = strchr(name, '/')) != NULL)
*text++ = '\0';
else
text = name;
if ((width = get_measurement(fp)) < 0.0f)
return (NULL);
if ((length = get_measurement(fp)) < 0.0f)
return (NULL);
if ((left = get_measurement(fp)) < 0.0f)
return (NULL);
if ((bottom = get_measurement(fp)) < 0.0f)
return (NULL);
if ((right = get_measurement(fp)) < 0.0f)
return (NULL);
if ((top = get_measurement(fp)) < 0.0f)
return (NULL);
if (!get_token(fp, size_code, sizeof(size_code)))
return (NULL);
if (!get_token(fp, region_code, sizeof(region_code)))
return (NULL);
// Return the new media size...
return (new ppdcMediaSize(name, text, width, length, left, bottom,
right, top, size_code, region_code));
}
//
// 'ppdcSource::get_duplex()' - Get a duplex option.
//
void
ppdcSource::get_duplex(ppdcFile *fp, // I - File to read from
ppdcDriver *d) // I - Current driver
{
char temp[256]; // Duplex keyword
ppdcAttr *attr; // cupsFlipDuplex attribute
ppdcGroup *g; // Current group
ppdcOption *o; // Duplex option
// Duplex {boolean|none|normal|flip}
if (!get_token(fp, temp, sizeof(temp)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected duplex type after Duplex on line %d of "
"%s."), fp->line, fp->filename);
return;
}
if (cond_state)
return;
if (!_cups_strcasecmp(temp, "none") || !_cups_strcasecmp(temp, "false") ||
!_cups_strcasecmp(temp, "no") || !_cups_strcasecmp(temp, "off"))
{
g = d->find_group("General");
if ((o = g->find_option("Duplex")) != NULL)
g->options->remove(o);
for (attr = (ppdcAttr *)d->attrs->first();
attr;
attr = (ppdcAttr *)d->attrs->next())
if (!strcmp(attr->name->value, "cupsFlipDuplex"))
{
d->attrs->remove(attr);
break;
}
}
else if (!_cups_strcasecmp(temp, "normal") || !_cups_strcasecmp(temp, "true") ||
!_cups_strcasecmp(temp, "yes") || !_cups_strcasecmp(temp, "on") ||
!_cups_strcasecmp(temp, "flip") || !_cups_strcasecmp(temp, "rotated") ||
!_cups_strcasecmp(temp, "manualtumble"))
{
g = d->find_group("General");
o = g->find_option("Duplex");
if (!o)
{
o = new ppdcOption(PPDC_PICKONE, "Duplex", "2-Sided Printing",
!_cups_strcasecmp(temp, "flip") ? PPDC_SECTION_PAGE :
PPDC_SECTION_ANY, 10.0f);
o->add_choice(new ppdcChoice("None", "Off (1-Sided)",
"<</Duplex false>>setpagedevice"));
o->add_choice(new ppdcChoice("DuplexNoTumble", "Long-Edge (Portrait)",
"<</Duplex true/Tumble false>>setpagedevice"));
o->add_choice(new ppdcChoice("DuplexTumble", "Short-Edge (Landscape)",
"<</Duplex true/Tumble true>>setpagedevice"));
g->add_option(o);
}
for (attr = (ppdcAttr *)d->attrs->first();
attr;
attr = (ppdcAttr *)d->attrs->next())
if (!strcmp(attr->name->value, "cupsFlipDuplex"))
{
if (_cups_strcasecmp(temp, "flip"))
d->attrs->remove(attr);
break;
}
if (!_cups_strcasecmp(temp, "flip") && !attr)
d->add_attr(new ppdcAttr("cupsFlipDuplex", NULL, NULL, "true"));
for (attr = (ppdcAttr *)d->attrs->first();
attr;
attr = (ppdcAttr *)d->attrs->next())
if (!strcmp(attr->name->value, "cupsBackSide"))
{
d->attrs->remove(attr);
break;
}
if (!_cups_strcasecmp(temp, "flip"))
d->add_attr(new ppdcAttr("cupsBackSide", NULL, NULL, "Flipped"));
else if (!_cups_strcasecmp(temp, "rotated"))
d->add_attr(new ppdcAttr("cupsBackSide", NULL, NULL, "Rotated"));
else if (!_cups_strcasecmp(temp, "manualtumble"))
d->add_attr(new ppdcAttr("cupsBackSide", NULL, NULL, "ManualTumble"));
else
d->add_attr(new ppdcAttr("cupsBackSide", NULL, NULL, "Normal"));
}
else
_cupsLangPrintf(stderr,
_("ppdc: Unknown duplex type \"%s\" on line %d of %s."),
temp, fp->line, fp->filename);
}
//
// 'ppdcSource::get_filter()' - Get a filter.
//
ppdcFilter * // O - Filter
ppdcSource::get_filter(ppdcFile *fp) // I - File to read
{
char type[1024], // MIME type
program[1024], // Filter program
*ptr; // Pointer into MIME type
int cost; // Relative cost
// Read filter parameters in one of the following formats:
//
// Filter "type cost program"
// Filter type cost program
if (!get_token(fp, type, sizeof(type)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected a filter definition on line %d of %s."),
fp->line, fp->filename);
return (NULL);
}
if ((ptr = strchr(type, ' ')) != NULL)
{
// Old-style filter definition in one string...
*ptr++ = '\0';
cost = strtol(ptr, &ptr, 10);
while (isspace(*ptr))
ptr ++;
strlcpy(program, ptr, sizeof(program));
}
else
{
cost = get_integer(fp);
if (!get_token(fp, program, sizeof(program)))
{
_cupsLangPrintf(stderr,
_("ppdc: Expected a program name on line %d of %s."),
fp->line, fp->filename);
return (NULL);
}
}
if (!type[0])
{
_cupsLangPrintf(stderr,
_("ppdc: Invalid empty MIME type for filter on line %d of "
"%s."), fp->line, fp->filename);
return (NULL);
}
if (cost < 0 || cost > 200)
{
_cupsLangPrintf(stderr,
_("ppdc: Invalid cost for filter on line %d of %s."),
fp->line, fp->filename);
return (NULL);
}
if (!program[0])
{
_cupsLangPrintf(stderr,
_("ppdc: Invalid empty program name for filter on line %d "
"of %s."), fp->line, fp->filename);
return (NULL);
}
return (new ppdcFilter(type, program, cost));
}
//
// 'ppdcSource::get_float()' - Get a single floating-point number.
//
float // O - Number
ppdcSource::get_float(ppdcFile *fp) // I - File to read
{
char temp[256], // String buffer
*ptr; // Pointer into buffer
float val; // Floating point value
// Get the number from the file and range-check...
if (!get_token(fp, temp, sizeof(temp)))
{
_cupsLangPrintf(stderr, _("ppdc: Expected real number on line %d of %s."),
fp->line, fp->filename);
return (-1.0f);
}
val = (float)strtod(temp, &ptr);
if (*ptr)
{
_cupsLangPrintf(stderr,
_("ppdc: Unknown trailing characters in real number \"%s\" "
"on line %d of %s."), temp, fp->line, fp->filename);
return (-1.0f);
}
else
return (val);
}
//
// 'ppdcSource::get_font()' - Get a font definition.
//
ppdcFont * // O - Font data
ppdcSource::get_font(ppdcFile *fp) // I - File to read
{
char name[256], // Font name
encoding[256], // Font encoding
version[256], // Font version
charset[256], // Font charset
temp[256]; // Font status string
ppdcFontStatus status; // Font status enumeration
// Read font parameters as follows:
//
// Font *
// Font name encoding version charset status
// %font name encoding version charset status
//
// "Name" is the PostScript font name.
//
// "Encoding" is the default encoding of the font: Standard, ISOLatin1,
// Special, Expert, ExpertSubset, etc.
//