]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc-source.cxx
2 // Source class for the CUPS PPD Compiler.
4 // Copyright 2007-2018 by Apple Inc.
5 // Copyright 2002-2007 by Easy Software Products.
7 // Licensed under Apache License v2.0. See the file "LICENSE" for more
12 // Include necessary headers...
15 #include "ppdc-private.h"
19 #include <cups/raster.h>
20 #include "data/epson.h"
22 #include "data/label.h"
24 # include <sys/utsname.h>
32 ppdcArray
*ppdcSource::includes
= 0;
33 const char *ppdcSource::driver_types
[] =
46 // 'ppdcSource::ppdcSource()' - Load a driver source file.
49 ppdcSource::ppdcSource(const char *f
, // I - File to read
50 cups_file_t
*ffp
)// I - File pointer to use
55 filename
= new ppdcString(f
);
56 base_fonts
= new ppdcArray();
57 drivers
= new ppdcArray();
58 po_files
= new ppdcArray();
59 sizes
= new ppdcArray();
60 vars
= new ppdcArray();
61 cond_state
= PPDC_COND_NORMAL
;
62 cond_current
= cond_stack
;
63 cond_stack
[0] = PPDC_COND_NORMAL
;
65 // Add standard #define variables...
66 #define MAKE_STRING(x) #x
68 vars
->add(new ppdcVariable("CUPS_VERSION", MAKE_STRING(CUPS_VERSION
)));
69 vars
->add(new ppdcVariable("CUPS_VERSION_MAJOR", MAKE_STRING(CUPS_VERSION_MAJOR
)));
70 vars
->add(new ppdcVariable("CUPS_VERSION_MINOR", MAKE_STRING(CUPS_VERSION_MINOR
)));
71 vars
->add(new ppdcVariable("CUPS_VERSION_PATCH", MAKE_STRING(CUPS_VERSION_PATCH
)));
74 vars
->add(new ppdcVariable("PLATFORM_NAME", "Windows"));
75 vars
->add(new ppdcVariable("PLATFORM_ARCH", "X86"));
78 struct utsname name
; // uname information
82 vars
->add(new ppdcVariable("PLATFORM_NAME", name
.sysname
));
83 vars
->add(new ppdcVariable("PLATFORM_ARCH", name
.machine
));
87 vars
->add(new ppdcVariable("PLATFORM_NAME", "unknown"));
88 vars
->add(new ppdcVariable("PLATFORM_ARCH", "unknown"));
98 // 'ppdcSource::~ppdcSource()' - Free a driver source file.
101 ppdcSource::~ppdcSource()
106 base_fonts
->release();
115 // 'ppdcSource::add_include()' - Add an include directory.
119 ppdcSource::add_include(const char *d
) // I - Include directory
125 includes
= new ppdcArray();
127 includes
->add(new ppdcString(d
));
132 // 'ppdcSource::find_driver()' - Find a driver.
135 ppdcDriver
* // O - Driver
136 ppdcSource::find_driver(const char *f
) // I - Driver file name
138 ppdcDriver
*d
; // Current driver
141 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
142 if (!_cups_strcasecmp(f
, d
->pc_file_name
->value
))
150 // 'ppdcSource::find_include()' - Find an include file.
153 char * // O - Found path or NULL
154 ppdcSource::find_include(
155 const char *f
, // I - Include filename
156 const char *base
, // I - Current directory
157 char *n
, // I - Path buffer
158 int nlen
) // I - Path buffer length
160 ppdcString
*dir
; // Include directory
161 char temp
[1024], // Temporary path
162 *ptr
; // Pointer to end of path
165 // Range check input...
166 if (!f
|| !*f
|| !n
|| nlen
< 2)
169 // Check the first character to see if we have <name> or "name"...
172 // Remove the surrounding <> from the name...
173 strlcpy(temp
, f
+ 1, sizeof(temp
));
174 ptr
= temp
+ strlen(temp
) - 1;
178 _cupsLangPrintf(stderr
,
179 _("ppdc: Invalid #include/#po filename \"%s\"."), n
);
188 // Check for the local file relative to the current directory...
189 if (base
&& *base
&& f
[0] != '/')
190 snprintf(n
, (size_t)nlen
, "%s/%s", base
, f
);
192 strlcpy(n
, f
, (size_t)nlen
);
198 // Absolute path that doesn't exist...
203 // Search the include directories, if any...
206 for (dir
= (ppdcString
*)includes
->first(); dir
; dir
= (ppdcString
*)includes
->next())
208 snprintf(n
, (size_t)nlen
, "%s/%s", dir
->value
, f
);
214 // Search the standard include directories...
215 _cups_globals_t
*cg
= _cupsGlobals(); // Global data
217 snprintf(n
, (size_t)nlen
, "%s/ppdc/%s", cg
->cups_datadir
, f
);
221 snprintf(n
, (size_t)nlen
, "%s/po/%s", cg
->cups_datadir
, f
);
230 // 'ppdcSource::find_po()' - Find a message catalog for the given locale.
233 ppdcCatalog
* // O - Message catalog or NULL
234 ppdcSource::find_po(const char *l
) // I - Locale name
236 ppdcCatalog
*cat
; // Current message catalog
239 for (cat
= (ppdcCatalog
*)po_files
->first();
241 cat
= (ppdcCatalog
*)po_files
->next())
242 if (!_cups_strcasecmp(l
, cat
->locale
->value
))
250 // 'ppdcSource::find_size()' - Find a media size.
253 ppdcMediaSize
* // O - Size
254 ppdcSource::find_size(const char *s
) // I - Size name
256 ppdcMediaSize
*m
; // Current media size
259 for (m
= (ppdcMediaSize
*)sizes
->first(); m
; m
= (ppdcMediaSize
*)sizes
->next())
260 if (!_cups_strcasecmp(s
, m
->name
->value
))
268 // 'ppdcSource::find_variable()' - Find a variable.
271 ppdcVariable
* // O - Variable
272 ppdcSource::find_variable(const char *n
)// I - Variable name
274 ppdcVariable
*v
; // Current variable
277 for (v
= (ppdcVariable
*)vars
->first(); v
; v
= (ppdcVariable
*)vars
->next())
278 if (!_cups_strcasecmp(n
, v
->name
->value
))
286 // 'ppdcSource::get_attr()' - Get an attribute.
289 ppdcAttr
* // O - Attribute
290 ppdcSource::get_attr(ppdcFile
*fp
, // I - File to read
291 bool loc
) // I - Localize this attribute?
293 char name
[1024], // Name string
294 selector
[1024], // Selector string
295 *text
, // Text string
296 value
[1024]; // Value string
299 // Get the attribute parameters:
301 // Attribute name selector value
302 if (!get_token(fp
, name
, sizeof(name
)))
304 _cupsLangPrintf(stderr
,
305 _("ppdc: Expected name after %s on line %d of %s."),
306 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
310 if (!get_token(fp
, selector
, sizeof(selector
)))
312 _cupsLangPrintf(stderr
,
313 _("ppdc: Expected selector after %s on line %d of %s."),
314 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
318 if ((text
= strchr(selector
, '/')) != NULL
)
321 if (!get_token(fp
, value
, sizeof(value
)))
323 _cupsLangPrintf(stderr
,
324 _("ppdc: Expected value after %s on line %d of %s."),
325 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
329 return (new ppdcAttr(name
, selector
, text
, value
, loc
));
334 // 'ppdcSource::get_boolean()' - Get a boolean value.
337 int // O - Boolean value
338 ppdcSource::get_boolean(ppdcFile
*fp
) // I - File to read
340 char buffer
[256]; // String buffer
343 if (!get_token(fp
, buffer
, sizeof(buffer
)))
345 _cupsLangPrintf(stderr
,
346 _("ppdc: Expected boolean value on line %d of %s."),
347 fp
->line
, fp
->filename
);
351 if (!_cups_strcasecmp(buffer
, "on") ||
352 !_cups_strcasecmp(buffer
, "yes") ||
353 !_cups_strcasecmp(buffer
, "true"))
355 else if (!_cups_strcasecmp(buffer
, "off") ||
356 !_cups_strcasecmp(buffer
, "no") ||
357 !_cups_strcasecmp(buffer
, "false"))
361 _cupsLangPrintf(stderr
,
362 _("ppdc: Bad boolean value (%s) on line %d of %s."),
363 buffer
, fp
->line
, fp
->filename
);
370 // 'ppdcSource::get_choice()' - Get a choice.
373 ppdcChoice
* // O - Choice data
374 ppdcSource::get_choice(ppdcFile
*fp
) // I - File to read
376 char name
[1024], // Name
381 // Read a choice from the file:
383 // Choice name/text code
384 if (!get_token(fp
, name
, sizeof(name
)))
386 _cupsLangPrintf(stderr
,
387 _("ppdc: Expected choice name/text on line %d of %s."),
388 fp
->line
, fp
->filename
);
392 if ((text
= strchr(name
, '/')) != NULL
)
397 if (!get_token(fp
, code
, sizeof(code
)))
399 _cupsLangPrintf(stderr
, _("ppdc: Expected choice code on line %d of %s."),
400 fp
->line
, fp
->filename
);
404 // Return the new choice
405 return (new ppdcChoice(name
, text
, code
));
410 // 'ppdcSource::get_color_model()' - Get an old-style color model option.
413 ppdcChoice
* // O - Choice data
414 ppdcSource::get_color_model(ppdcFile
*fp
)
417 char name
[1024], // Option name
418 *text
, // Text option
419 temp
[256]; // Temporary string
420 int color_space
, // Colorspace
421 color_order
, // Color order
422 compression
; // Compression mode
425 // Get the ColorModel parameters:
427 // ColorModel name/text colorspace colororder compression
428 if (!get_token(fp
, name
, sizeof(name
)))
430 _cupsLangPrintf(stderr
,
431 _("ppdc: Expected name/text combination for ColorModel on "
432 "line %d of %s."), fp
->line
, fp
->filename
);
436 if ((text
= strchr(name
, '/')) != NULL
)
441 if (!get_token(fp
, temp
, sizeof(temp
)))
443 _cupsLangPrintf(stderr
,
444 _("ppdc: Expected colorspace for ColorModel on line %d of "
445 "%s."), fp
->line
, fp
->filename
);
449 if ((color_space
= get_color_space(temp
)) < 0)
450 color_space
= get_integer(temp
);
452 if (!get_token(fp
, temp
, sizeof(temp
)))
454 _cupsLangPrintf(stderr
,
455 _("ppdc: Expected color order for ColorModel on line %d of "
456 "%s."), fp
->line
, fp
->filename
);
460 if ((color_order
= get_color_order(temp
)) < 0)
461 color_order
= get_integer(temp
);
463 if (!get_token(fp
, temp
, sizeof(temp
)))
465 _cupsLangPrintf(stderr
,
466 _("ppdc: Expected compression for ColorModel on line %d of "
467 "%s."), fp
->line
, fp
->filename
);
471 compression
= get_integer(temp
);
473 snprintf(temp
, sizeof(temp
),
474 "<</cupsColorSpace %d/cupsColorOrder %d/cupsCompression %d>>"
476 color_space
, color_order
, compression
);
478 return (new ppdcChoice(name
, text
, temp
));
483 // 'ppdcSource::get_color_order()' - Get an old-style color order value.
486 int // O - Color order value
487 ppdcSource::get_color_order(
488 const char *co
) // I - Color order string
490 if (!_cups_strcasecmp(co
, "chunked") ||
491 !_cups_strcasecmp(co
, "chunky"))
492 return (CUPS_ORDER_CHUNKED
);
493 else if (!_cups_strcasecmp(co
, "banded"))
494 return (CUPS_ORDER_BANDED
);
495 else if (!_cups_strcasecmp(co
, "planar"))
496 return (CUPS_ORDER_PLANAR
);
503 // 'ppdcSource::get_color_profile()' - Get a color profile definition.
506 ppdcProfile
* // O - Color profile
507 ppdcSource::get_color_profile(
508 ppdcFile
*fp
) // I - File to read
510 char resolution
[1024], // Resolution/media type
511 *media_type
; // Media type
512 int i
; // Looping var
513 float g
, // Gamma value
515 m
[9]; // Transform matrix
518 // Get the ColorProfile parameters:
520 // ColorProfile resolution/mediatype gamma density m00 m01 m02 ... m22
521 if (!get_token(fp
, resolution
, sizeof(resolution
)))
523 _cupsLangPrintf(stderr
,
524 _("ppdc: Expected resolution/mediatype following "
525 "ColorProfile on line %d of %s."),
526 fp
->line
, fp
->filename
);
530 if ((media_type
= strchr(resolution
, '/')) != NULL
)
531 *media_type
++ = '\0';
533 media_type
= resolution
;
537 for (i
= 0; i
< 9; i
++)
538 m
[i
] = get_float(fp
);
540 return (new ppdcProfile(resolution
, media_type
, g
, d
, m
));
545 // 'ppdcSource::get_color_space()' - Get an old-style colorspace value.
548 int // O - Colorspace value
549 ppdcSource::get_color_space(
550 const char *cs
) // I - Colorspace string
552 if (!_cups_strcasecmp(cs
, "w"))
553 return (CUPS_CSPACE_W
);
554 else if (!_cups_strcasecmp(cs
, "rgb"))
555 return (CUPS_CSPACE_RGB
);
556 else if (!_cups_strcasecmp(cs
, "rgba"))
557 return (CUPS_CSPACE_RGBA
);
558 else if (!_cups_strcasecmp(cs
, "k"))
559 return (CUPS_CSPACE_K
);
560 else if (!_cups_strcasecmp(cs
, "cmy"))
561 return (CUPS_CSPACE_CMY
);
562 else if (!_cups_strcasecmp(cs
, "ymc"))
563 return (CUPS_CSPACE_YMC
);
564 else if (!_cups_strcasecmp(cs
, "cmyk"))
565 return (CUPS_CSPACE_CMYK
);
566 else if (!_cups_strcasecmp(cs
, "ymck"))
567 return (CUPS_CSPACE_YMCK
);
568 else if (!_cups_strcasecmp(cs
, "kcmy"))
569 return (CUPS_CSPACE_KCMY
);
570 else if (!_cups_strcasecmp(cs
, "kcmycm"))
571 return (CUPS_CSPACE_KCMYcm
);
572 else if (!_cups_strcasecmp(cs
, "gmck"))
573 return (CUPS_CSPACE_GMCK
);
574 else if (!_cups_strcasecmp(cs
, "gmcs"))
575 return (CUPS_CSPACE_GMCS
);
576 else if (!_cups_strcasecmp(cs
, "white"))
577 return (CUPS_CSPACE_WHITE
);
578 else if (!_cups_strcasecmp(cs
, "gold"))
579 return (CUPS_CSPACE_GOLD
);
580 else if (!_cups_strcasecmp(cs
, "silver"))
581 return (CUPS_CSPACE_SILVER
);
582 else if (!_cups_strcasecmp(cs
, "CIEXYZ"))
583 return (CUPS_CSPACE_CIEXYZ
);
584 else if (!_cups_strcasecmp(cs
, "CIELab"))
585 return (CUPS_CSPACE_CIELab
);
586 else if (!_cups_strcasecmp(cs
, "RGBW"))
587 return (CUPS_CSPACE_RGBW
);
588 else if (!_cups_strcasecmp(cs
, "ICC1"))
589 return (CUPS_CSPACE_ICC1
);
590 else if (!_cups_strcasecmp(cs
, "ICC2"))
591 return (CUPS_CSPACE_ICC2
);
592 else if (!_cups_strcasecmp(cs
, "ICC3"))
593 return (CUPS_CSPACE_ICC3
);
594 else if (!_cups_strcasecmp(cs
, "ICC4"))
595 return (CUPS_CSPACE_ICC4
);
596 else if (!_cups_strcasecmp(cs
, "ICC5"))
597 return (CUPS_CSPACE_ICC5
);
598 else if (!_cups_strcasecmp(cs
, "ICC6"))
599 return (CUPS_CSPACE_ICC6
);
600 else if (!_cups_strcasecmp(cs
, "ICC7"))
601 return (CUPS_CSPACE_ICC7
);
602 else if (!_cups_strcasecmp(cs
, "ICC8"))
603 return (CUPS_CSPACE_ICC8
);
604 else if (!_cups_strcasecmp(cs
, "ICC9"))
605 return (CUPS_CSPACE_ICC9
);
606 else if (!_cups_strcasecmp(cs
, "ICCA"))
607 return (CUPS_CSPACE_ICCA
);
608 else if (!_cups_strcasecmp(cs
, "ICCB"))
609 return (CUPS_CSPACE_ICCB
);
610 else if (!_cups_strcasecmp(cs
, "ICCC"))
611 return (CUPS_CSPACE_ICCC
);
612 else if (!_cups_strcasecmp(cs
, "ICCD"))
613 return (CUPS_CSPACE_ICCD
);
614 else if (!_cups_strcasecmp(cs
, "ICCE"))
615 return (CUPS_CSPACE_ICCE
);
616 else if (!_cups_strcasecmp(cs
, "ICCF"))
617 return (CUPS_CSPACE_ICCF
);
624 // 'ppdcSource::get_constraint()' - Get a constraint.
627 ppdcConstraint
* // O - Constraint
628 ppdcSource::get_constraint(ppdcFile
*fp
)// I - File to read
630 char temp
[1024], // One string to rule them all
631 *ptr
, // Pointer into string
632 *option1
, // Constraint option 1
633 *choice1
, // Constraint choice 1
634 *option2
, // Constraint option 2
635 *choice2
; // Constraint choice 2
638 // Read the UIConstaints parameter in one of the following forms:
640 // UIConstraints "*Option1 *Option2"
641 // UIConstraints "*Option1 Choice1 *Option2"
642 // UIConstraints "*Option1 *Option2 Choice2"
643 // UIConstraints "*Option1 Choice1 *Option2 Choice2"
644 if (!get_token(fp
, temp
, sizeof(temp
)))
646 _cupsLangPrintf(stderr
,
647 _("ppdc: Expected constraints string for UIConstraints on "
648 "line %d of %s."), fp
->line
, fp
->filename
);
652 for (ptr
= temp
; isspace(*ptr
); ptr
++);
656 _cupsLangPrintf(stderr
,
657 _("ppdc: Option constraint must *name on line %d of %s."),
658 fp
->line
, fp
->filename
);
664 for (; *ptr
&& !isspace(*ptr
); ptr
++);
665 for (; isspace(*ptr
); *ptr
++ = '\0');
671 for (; *ptr
&& !isspace(*ptr
); ptr
++);
672 for (; isspace(*ptr
); *ptr
++ = '\0');
679 _cupsLangPrintf(stderr
,
680 _("ppdc: Expected two option names on line %d of %s."),
681 fp
->line
, fp
->filename
);
687 for (; *ptr
&& !isspace(*ptr
); ptr
++);
688 for (; isspace(*ptr
); *ptr
++ = '\0');
695 return (new ppdcConstraint(option1
, choice1
, option2
, choice2
));
700 // 'ppdcSource::get_custom_size()' - Get a custom media size definition from a file.
703 ppdcMediaSize
* // O - Media size
704 ppdcSource::get_custom_size(ppdcFile
*fp
)
707 char name
[1024], // Name
709 size_code
[10240], // PageSize code
710 region_code
[10240]; // PageRegion
711 float width
, // Width
714 bottom
, // Bottom margin
715 right
, // Right margin
719 // Get the name, text, width, length, margins, and code:
721 // CustomMedia name/text width length left bottom right top size-code region-code
722 if (!get_token(fp
, name
, sizeof(name
)))
725 if ((text
= strchr(name
, '/')) != NULL
)
730 if ((width
= get_measurement(fp
)) < 0.0f
)
733 if ((length
= get_measurement(fp
)) < 0.0f
)
736 if ((left
= get_measurement(fp
)) < 0.0f
)
739 if ((bottom
= get_measurement(fp
)) < 0.0f
)
742 if ((right
= get_measurement(fp
)) < 0.0f
)
745 if ((top
= get_measurement(fp
)) < 0.0f
)
748 if (!get_token(fp
, size_code
, sizeof(size_code
)))
751 if (!get_token(fp
, region_code
, sizeof(region_code
)))
754 // Return the new media size...
755 return (new ppdcMediaSize(name
, text
, width
, length
, left
, bottom
,
756 right
, top
, size_code
, region_code
));
761 // 'ppdcSource::get_duplex()' - Get a duplex option.
765 ppdcSource::get_duplex(ppdcFile
*fp
, // I - File to read from
766 ppdcDriver
*d
) // I - Current driver
768 char temp
[256]; // Duplex keyword
769 ppdcAttr
*attr
; // cupsFlipDuplex attribute
770 ppdcGroup
*g
; // Current group
771 ppdcOption
*o
; // Duplex option
774 // Duplex {boolean|none|normal|flip}
775 if (!get_token(fp
, temp
, sizeof(temp
)))
777 _cupsLangPrintf(stderr
,
778 _("ppdc: Expected duplex type after Duplex on line %d of "
779 "%s."), fp
->line
, fp
->filename
);
786 if (!_cups_strcasecmp(temp
, "none") || !_cups_strcasecmp(temp
, "false") ||
787 !_cups_strcasecmp(temp
, "no") || !_cups_strcasecmp(temp
, "off"))
789 g
= d
->find_group("General");
790 if ((o
= g
->find_option("Duplex")) != NULL
)
791 g
->options
->remove(o
);
793 for (attr
= (ppdcAttr
*)d
->attrs
->first();
795 attr
= (ppdcAttr
*)d
->attrs
->next())
796 if (!strcmp(attr
->name
->value
, "cupsFlipDuplex"))
798 d
->attrs
->remove(attr
);
802 else if (!_cups_strcasecmp(temp
, "normal") || !_cups_strcasecmp(temp
, "true") ||
803 !_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "on") ||
804 !_cups_strcasecmp(temp
, "flip") || !_cups_strcasecmp(temp
, "rotated") ||
805 !_cups_strcasecmp(temp
, "manualtumble"))
807 g
= d
->find_group("General");
808 o
= g
->find_option("Duplex");
812 o
= new ppdcOption(PPDC_PICKONE
, "Duplex", "2-Sided Printing",
813 !_cups_strcasecmp(temp
, "flip") ? PPDC_SECTION_PAGE
:
814 PPDC_SECTION_ANY
, 10.0f
);
815 o
->add_choice(new ppdcChoice("None", "Off (1-Sided)",
816 "<</Duplex false>>setpagedevice"));
817 o
->add_choice(new ppdcChoice("DuplexNoTumble", "Long-Edge (Portrait)",
818 "<</Duplex true/Tumble false>>setpagedevice"));
819 o
->add_choice(new ppdcChoice("DuplexTumble", "Short-Edge (Landscape)",
820 "<</Duplex true/Tumble true>>setpagedevice"));
825 for (attr
= (ppdcAttr
*)d
->attrs
->first();
827 attr
= (ppdcAttr
*)d
->attrs
->next())
828 if (!strcmp(attr
->name
->value
, "cupsFlipDuplex"))
830 if (_cups_strcasecmp(temp
, "flip"))
831 d
->attrs
->remove(attr
);
835 if (!_cups_strcasecmp(temp
, "flip") && !attr
)
836 d
->add_attr(new ppdcAttr("cupsFlipDuplex", NULL
, NULL
, "true"));
838 for (attr
= (ppdcAttr
*)d
->attrs
->first();
840 attr
= (ppdcAttr
*)d
->attrs
->next())
841 if (!strcmp(attr
->name
->value
, "cupsBackSide"))
843 d
->attrs
->remove(attr
);
847 if (!_cups_strcasecmp(temp
, "flip"))
848 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Flipped"));
849 else if (!_cups_strcasecmp(temp
, "rotated"))
850 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Rotated"));
851 else if (!_cups_strcasecmp(temp
, "manualtumble"))
852 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "ManualTumble"));
854 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Normal"));
857 _cupsLangPrintf(stderr
,
858 _("ppdc: Unknown duplex type \"%s\" on line %d of %s."),
859 temp
, fp
->line
, fp
->filename
);
864 // 'ppdcSource::get_filter()' - Get a filter.
867 ppdcFilter
* // O - Filter
868 ppdcSource::get_filter(ppdcFile
*fp
) // I - File to read
870 char type
[1024], // MIME type
871 program
[1024], // Filter program
872 *ptr
; // Pointer into MIME type
873 int cost
; // Relative cost
876 // Read filter parameters in one of the following formats:
878 // Filter "type cost program"
879 // Filter type cost program
881 if (!get_token(fp
, type
, sizeof(type
)))
883 _cupsLangPrintf(stderr
,
884 _("ppdc: Expected a filter definition on line %d of %s."),
885 fp
->line
, fp
->filename
);
889 if ((ptr
= strchr(type
, ' ')) != NULL
)
891 // Old-style filter definition in one string...
893 cost
= strtol(ptr
, &ptr
, 10);
895 while (isspace(*ptr
))
898 strlcpy(program
, ptr
, sizeof(program
));
902 cost
= get_integer(fp
);
904 if (!get_token(fp
, program
, sizeof(program
)))
906 _cupsLangPrintf(stderr
,
907 _("ppdc: Expected a program name on line %d of %s."),
908 fp
->line
, fp
->filename
);
915 _cupsLangPrintf(stderr
,
916 _("ppdc: Invalid empty MIME type for filter on line %d of "
917 "%s."), fp
->line
, fp
->filename
);
921 if (cost
< 0 || cost
> 200)
923 _cupsLangPrintf(stderr
,
924 _("ppdc: Invalid cost for filter on line %d of %s."),
925 fp
->line
, fp
->filename
);
931 _cupsLangPrintf(stderr
,
932 _("ppdc: Invalid empty program name for filter on line %d "
933 "of %s."), fp
->line
, fp
->filename
);
937 return (new ppdcFilter(type
, program
, cost
));
942 // 'ppdcSource::get_float()' - Get a single floating-point number.
946 ppdcSource::get_float(ppdcFile
*fp
) // I - File to read
948 char temp
[256], // String buffer
949 *ptr
; // Pointer into buffer
950 float val
; // Floating point value
953 // Get the number from the file and range-check...
954 if (!get_token(fp
, temp
, sizeof(temp
)))
956 _cupsLangPrintf(stderr
, _("ppdc: Expected real number on line %d of %s."),
957 fp
->line
, fp
->filename
);
961 val
= (float)strtod(temp
, &ptr
);
965 _cupsLangPrintf(stderr
,
966 _("ppdc: Unknown trailing characters in real number \"%s\" "
967 "on line %d of %s."), temp
, fp
->line
, fp
->filename
);
976 // 'ppdcSource::get_font()' - Get a font definition.
979 ppdcFont
* // O - Font data
980 ppdcSource::get_font(ppdcFile
*fp
) // I - File to read
982 char name
[256], // Font name
983 encoding
[256], // Font encoding
984 version
[256], // Font version
985 charset
[256], // Font charset
986 temp
[256]; // Font status string
987 ppdcFontStatus status
; // Font status enumeration
990 // Read font parameters as follows:
993 // Font name encoding version charset status
994 // %font name encoding version charset status
996 // "Name" is the PostScript font name.
998 // "Encoding" is the default encoding of the font: Standard, ISOLatin1,
999 // Special, Expert, ExpertSubset, etc.
1001 // "Version" is the version number string.
1003 // "Charset" specifies the characters that are included in the font:
1004 // Standard, Special, Expert, Adobe-Identity, etc.
1006 // "Status" is the keyword ROM or Disk.
1007 if (!get_token(fp
, name
, sizeof(name
)))
1009 _cupsLangPrintf(stderr
,
1010 _("ppdc: Expected name after Font on line %d of %s."),
1011 fp
->line
, fp
->filename
);
1015 if (!strcmp(name
, "*"))
1017 // Include all base fonts...
1021 status
= PPDC_FONT_ROM
;
1025 // Load a full font definition...
1026 if (!get_token(fp
, encoding
, sizeof(encoding
)))
1028 _cupsLangPrintf(stderr
,
1029 _("ppdc: Expected encoding after Font on line %d of "
1030 "%s."), fp
->line
, fp
->filename
);
1034 if (!get_token(fp
, version
, sizeof(version
)))
1036 _cupsLangPrintf(stderr
,
1037 _("ppdc: Expected version after Font on line %d of "
1038 "%s."), fp
->line
, fp
->filename
);
1042 if (!get_token(fp
, charset
, sizeof(charset
)))
1044 _cupsLangPrintf(stderr
,
1045 _("ppdc: Expected charset after Font on line %d of "
1046 "%s."), fp
->line
, fp
->filename
);
1050 if (!get_token(fp
, temp
, sizeof(temp
)))
1052 _cupsLangPrintf(stderr
,
1053 _("ppdc: Expected status after Font on line %d of %s."),
1054 fp
->line
, fp
->filename
);
1058 if (!_cups_strcasecmp(temp
, "ROM"))
1059 status
= PPDC_FONT_ROM
;
1060 else if (!_cups_strcasecmp(temp
, "Disk"))
1061 status
= PPDC_FONT_DISK
;
1064 _cupsLangPrintf(stderr
,
1065 _("ppdc: Bad status keyword %s on line %d of %s."),
1066 temp
, fp
->line
, fp
->filename
);
1071 // printf("Font %s %s %s %s %s\n", name, encoding, version, charset, temp);
1073 return (new ppdcFont(name
, encoding
, version
, charset
, status
));
1078 // 'ppdcSource::get_generic()' - Get a generic old-style option.
1081 ppdcChoice
* // O - Choice data
1082 ppdcSource::get_generic(ppdcFile
*fp
, // I - File to read
1083 const char *keyword
,
1086 // I - Text attribute
1088 // I - Numeric attribute
1090 char name
[1024], // Name
1092 command
[256]; // Command string
1093 int val
; // Numeric value
1096 // Read one of the following parameters:
1099 // Foo integer name/text
1101 val
= get_integer(fp
);
1105 if (!get_token(fp
, name
, sizeof(name
)))
1107 _cupsLangPrintf(stderr
,
1108 _("ppdc: Expected name/text after %s on line %d of %s."),
1109 keyword
, fp
->line
, fp
->filename
);
1113 if ((text
= strchr(name
, '/')) != NULL
)
1121 snprintf(command
, sizeof(command
),
1122 "<</%s(%s)/%s %d>>setpagedevice",
1123 tattr
, name
, nattr
, val
);
1125 snprintf(command
, sizeof(command
),
1126 "<</%s %d>>setpagedevice",
1130 snprintf(command
, sizeof(command
),
1131 "<</%s(%s)>>setpagedevice",
1134 return (new ppdcChoice(name
, text
, command
));
1139 // 'ppdcSource::get_group()' - Get an option group.
1142 ppdcGroup
* // O - Group
1143 ppdcSource::get_group(ppdcFile
*fp
, // I - File to read
1144 ppdcDriver
*d
) // I - Printer driver
1146 char name
[1024], // UI name
1148 ppdcGroup
*g
; // Group
1151 // Read the Group parameters:
1154 if (!get_token(fp
, name
, sizeof(name
)))
1156 _cupsLangPrintf(stderr
,
1157 _("ppdc: Expected group name/text on line %d of %s."),
1158 fp
->line
, fp
->filename
);
1162 if ((text
= strchr(name
, '/')) != NULL
)
1167 // See if the group already exists...
1168 if ((g
= d
->find_group(name
)) == NULL
)
1170 // Nope, add a new one...
1171 g
= new ppdcGroup(name
, text
);
1179 // 'ppdcSource::get_installable()' - Get an installable option.
1182 ppdcOption
* // O - Option
1183 ppdcSource::get_installable(ppdcFile
*fp
)
1186 char name
[1024], // Name for installable option
1187 *text
; // Text for installable option
1188 ppdcOption
*o
; // Option
1191 // Read the parameter for an installable option:
1193 // Installable name/text
1194 if (!get_token(fp
, name
, sizeof(name
)))
1196 _cupsLangPrintf(stderr
,
1197 _("ppdc: Expected name/text after Installable on line %d "
1198 "of %s."), fp
->line
, fp
->filename
);
1202 if ((text
= strchr(name
, '/')) != NULL
)
1207 // Create the option...
1208 o
= new ppdcOption(PPDC_BOOLEAN
, name
, text
, PPDC_SECTION_ANY
, 10.0f
);
1210 // Add the false and true choices...
1211 o
->add_choice(new ppdcChoice("False", "Not Installed", ""));
1212 o
->add_choice(new ppdcChoice("True", "Installed", ""));
1219 // 'ppdcSource::get_integer()' - Get an integer value from a string.
1222 #define PPDC_XX -1 // Bad
1223 #define PPDC_EQ 0 // ==
1224 #define PPDC_NE 1 // !=
1225 #define PPDC_LT 2 // <
1226 #define PPDC_LE 3 // <=
1227 #define PPDC_GT 4 // >
1228 #define PPDC_GE 5 // >=
1230 int // O - Integer value
1231 ppdcSource::get_integer(const char *v
) // I - Value string
1234 long temp
, // Temporary value
1235 temp2
; // Second temporary value
1236 char *newv
, // New value string pointer
1237 ch
; // Temporary character
1238 ppdcVariable
*var
; // #define variable
1239 int compop
; // Comparison operator
1242 // Parse the value string...
1246 if (isdigit(*v
& 255) || *v
== '-' || *v
== '+')
1248 // Return a simple integer value
1249 val
= strtol(v
, (char **)&v
, 0);
1250 if (*v
|| val
== LONG_MIN
)
1257 // Evaluate and expression in any of the following formats:
1259 // (number number ... number) Bitwise OR of all numbers
1260 // (NAME == value) 1 if equal, 0 otherwise
1261 // (NAME != value) 1 if not equal, 0 otherwise
1262 // (NAME < value) 1 if less than, 0 otherwise
1263 // (NAME <= value) 1 if less than or equal, 0 otherwise
1264 // (NAME > value) 1 if greater than, 0 otherwise
1265 // (NAME >= value) 1 if greater than or equal, 0 otherwise
1270 while (*v
&& *v
!= ')')
1272 // Skip leading whitespace...
1273 while (*v
&& isspace(*v
& 255))
1276 if (!*v
|| *v
== ')')
1279 if (isdigit(*v
& 255) || *v
== '-' || *v
== '+')
1281 // Bitwise OR a number...
1282 temp
= strtol(v
, &newv
, 0);
1284 if (!*newv
|| newv
== v
|| !(isspace(*newv
) || *newv
== ')') ||
1290 // NAME logicop value
1291 for (newv
= (char *)v
+ 1;
1292 *newv
&& (isalnum(*newv
& 255) || *newv
== '_');
1299 if ((var
= find_variable(v
)) != NULL
)
1301 if (!var
->value
|| !var
->value
->value
|| !var
->value
->value
[0])
1303 else if (isdigit(var
->value
->value
[0] & 255) ||
1304 var
->value
->value
[0] == '-' ||
1305 var
->value
->value
[0] == '+')
1306 temp
= strtol(var
->value
->value
, NULL
, 0);
1314 while (isspace(*newv
& 255))
1317 if (!strncmp(newv
, "==", 2))
1322 else if (!strncmp(newv
, "!=", 2))
1327 else if (!strncmp(newv
, "<=", 2))
1332 else if (*newv
== '<')
1337 else if (!strncmp(newv
, ">=", 2))
1342 else if (*newv
== '>')
1350 if (compop
!= PPDC_XX
)
1352 while (isspace(*newv
& 255))
1355 if (*newv
== ')' || !*newv
)
1358 if (isdigit(*newv
& 255) || *newv
== '-' || *newv
== '+')
1360 // Get the second number...
1361 temp2
= strtol(newv
, &newv
, 0);
1362 if (!*newv
|| newv
== v
|| !(isspace(*newv
) || *newv
== ')') ||
1368 // Lookup the second name...
1369 for (v
= newv
, newv
++;
1370 *newv
&& (isalnum(*newv
& 255) || *newv
== '_');
1376 if ((var
= find_variable(v
)) != NULL
)
1378 if (!var
->value
|| !var
->value
->value
|| !var
->value
->value
[0])
1380 else if (isdigit(var
->value
->value
[0] & 255) ||
1381 var
->value
->value
[0] == '-' ||
1382 var
->value
->value
[0] == '+')
1383 temp2
= strtol(var
->value
->value
, NULL
, 0);
1393 // Do the comparison...
1397 temp
= temp
== temp2
;
1400 temp
= temp
!= temp2
;
1403 temp
= temp
< temp2
;
1406 temp
= temp
<= temp2
;
1409 temp
= temp
> temp2
;
1412 temp
= temp
>= temp2
;
1422 if (*v
== ')' && !v
[1])
1427 else if ((var
= find_variable(v
)) != NULL
)
1429 // NAME by itself returns 1 if the #define variable is not blank and
1431 return (var
->value
->value
&& var
->value
->value
[0] &&
1432 strcmp(var
->value
->value
, "0"));
1436 // Anything else is an error...
1443 // 'ppdcSource::get_integer()' - Get an integer value from a file.
1446 int // O - Integer value
1447 ppdcSource::get_integer(ppdcFile
*fp
) // I - File to read
1449 char temp
[1024]; // String buffer
1452 if (!get_token(fp
, temp
, sizeof(temp
)))
1454 _cupsLangPrintf(stderr
, _("ppdc: Expected integer on line %d of %s."),
1455 fp
->line
, fp
->filename
);
1459 return (get_integer(temp
));
1464 // 'ppdcSource::get_measurement()' - Get a measurement value.
1467 float // O - Measurement value in points
1468 ppdcSource::get_measurement(ppdcFile
*fp
)
1471 char buffer
[256], // Number buffer
1472 *ptr
; // Pointer into buffer
1473 float val
; // Measurement value
1476 // Grab a token from the file...
1477 if (!get_token(fp
, buffer
, sizeof(buffer
)))
1480 // Get the floating point value of "s" and skip all digits and decimal points.
1481 val
= (float)strtod(buffer
, &ptr
);
1483 // Check for a trailing unit specifier...
1484 if (!_cups_strcasecmp(ptr
, "mm"))
1485 val
*= 72.0f
/ 25.4f
;
1486 else if (!_cups_strcasecmp(ptr
, "cm"))
1487 val
*= 72.0f
/ 2.54f
;
1488 else if (!_cups_strcasecmp(ptr
, "m"))
1489 val
*= 72.0f
/ 0.0254f
;
1490 else if (!_cups_strcasecmp(ptr
, "in"))
1492 else if (!_cups_strcasecmp(ptr
, "ft"))
1493 val
*= 72.0f
* 12.0f
;
1494 else if (_cups_strcasecmp(ptr
, "pt") && *ptr
)
1502 // 'ppdcSource::get_option()' - Get an option definition.
1505 ppdcOption
* // O - Option
1506 ppdcSource::get_option(ppdcFile
*fp
, // I - File to read
1507 ppdcDriver
*d
, // I - Printer driver
1508 ppdcGroup
*g
) // I - Current group
1510 char name
[1024], // UI name
1512 type
[256]; // UI type string
1513 ppdcOptType ot
; // Option type value
1514 ppdcOptSection section
; // Option section
1515 float order
; // Option order
1516 ppdcOption
*o
; // Option
1517 ppdcGroup
*mg
; // Matching group, if any
1520 // Read the Option parameters:
1522 // Option name/text type section order
1523 if (!get_token(fp
, name
, sizeof(name
)))
1525 _cupsLangPrintf(stderr
,
1526 _("ppdc: Expected option name/text on line %d of %s."),
1527 fp
->line
, fp
->filename
);
1531 if ((text
= strchr(name
, '/')) != NULL
)
1536 if (!get_token(fp
, type
, sizeof(type
)))
1538 _cupsLangPrintf(stderr
, _("ppdc: Expected option type on line %d of %s."),
1539 fp
->line
, fp
->filename
);
1543 if (!_cups_strcasecmp(type
, "boolean"))
1545 else if (!_cups_strcasecmp(type
, "pickone"))
1547 else if (!_cups_strcasecmp(type
, "pickmany"))
1551 _cupsLangPrintf(stderr
,
1552 _("ppdc: Invalid option type \"%s\" on line %d of %s."),
1553 type
, fp
->line
, fp
->filename
);
1557 if (!get_token(fp
, type
, sizeof(type
)))
1559 _cupsLangPrintf(stderr
,
1560 _("ppdc: Expected option section on line %d of %s."),
1561 fp
->line
, fp
->filename
);
1565 if (!_cups_strcasecmp(type
, "AnySetup"))
1566 section
= PPDC_SECTION_ANY
;
1567 else if (!_cups_strcasecmp(type
, "DocumentSetup"))
1568 section
= PPDC_SECTION_DOCUMENT
;
1569 else if (!_cups_strcasecmp(type
, "ExitServer"))
1570 section
= PPDC_SECTION_EXIT
;
1571 else if (!_cups_strcasecmp(type
, "JCLSetup"))
1572 section
= PPDC_SECTION_JCL
;
1573 else if (!_cups_strcasecmp(type
, "PageSetup"))
1574 section
= PPDC_SECTION_PAGE
;
1575 else if (!_cups_strcasecmp(type
, "Prolog"))
1576 section
= PPDC_SECTION_PROLOG
;
1579 _cupsLangPrintf(stderr
,
1580 _("ppdc: Invalid option section \"%s\" on line %d of "
1581 "%s."), type
, fp
->line
, fp
->filename
);
1585 order
= get_float(fp
);
1587 // See if the option already exists...
1588 if ((o
= d
->find_option_group(name
, &mg
)) == NULL
)
1590 // Nope, add a new one...
1591 o
= new ppdcOption(ot
, name
, text
, section
, order
);
1593 else if (o
->type
!= ot
)
1595 _cupsLangPrintf(stderr
,
1596 _("ppdc: Option %s redefined with a different type on line "
1597 "%d of %s."), name
, fp
->line
, fp
->filename
);
1602 _cupsLangPrintf(stderr
,
1603 _("ppdc: Option %s defined in two different groups on line "
1604 "%d of %s."), name
, fp
->line
, fp
->filename
);
1613 // 'ppdcSource::get_po()' - Get a message catalog.
1616 ppdcCatalog
* // O - Message catalog
1617 ppdcSource::get_po(ppdcFile
*fp
) // I - File to read
1619 char locale
[32], // Locale name
1620 poname
[1024], // Message catalog filename
1621 basedir
[1024], // Base directory
1622 *baseptr
, // Pointer into directory
1623 pofilename
[1024]; // Full filename of message catalog
1624 ppdcCatalog
*cat
; // Message catalog
1627 // Read the #po parameters:
1629 // #po locale "filename.po"
1630 if (!get_token(fp
, locale
, sizeof(locale
)))
1632 _cupsLangPrintf(stderr
,
1633 _("ppdc: Expected locale after #po on line %d of %s."),
1634 fp
->line
, fp
->filename
);
1638 if (!get_token(fp
, poname
, sizeof(poname
)))
1640 _cupsLangPrintf(stderr
,
1641 _("ppdc: Expected filename after #po %s on line %d of "
1642 "%s."), locale
, fp
->line
, fp
->filename
);
1646 // See if the locale is already loaded...
1647 if (find_po(locale
))
1649 _cupsLangPrintf(stderr
,
1650 _("ppdc: Duplicate #po for locale %s on line %d of %s."),
1651 locale
, fp
->line
, fp
->filename
);
1655 // Figure out the current directory...
1656 strlcpy(basedir
, fp
->filename
, sizeof(basedir
));
1658 if ((baseptr
= strrchr(basedir
, '/')) != NULL
)
1661 strlcpy(basedir
, ".", sizeof(basedir
));
1663 // Find the po file...
1664 pofilename
[0] = '\0';
1667 find_include(poname
, basedir
, pofilename
, sizeof(pofilename
)))
1669 // Found it, so load it...
1670 cat
= new ppdcCatalog(locale
, pofilename
);
1672 // Reset the filename to the name supplied by the user...
1673 cat
->filename
->release();
1674 cat
->filename
= new ppdcString(poname
);
1676 // Return the catalog...
1681 _cupsLangPrintf(stderr
,
1682 _("ppdc: Unable to find #po file %s on line %d of %s."),
1683 poname
, fp
->line
, fp
->filename
);
1690 // 'ppdcSource::get_resolution()' - Get an old-style resolution option.
1693 ppdcChoice
* // O - Choice data
1694 ppdcSource::get_resolution(ppdcFile
*fp
)// I - File to read
1696 char name
[1024], // Name
1698 temp
[256], // Temporary string
1699 command
[256], // Command string
1700 *commptr
; // Pointer into command
1701 int xdpi
, ydpi
, // X + Y resolution
1702 color_order
, // Color order
1703 color_space
, // Colorspace
1704 compression
, // Compression mode
1705 depth
, // Bits per color
1706 row_count
, // Row count
1707 row_feed
, // Row feed
1708 row_step
; // Row step/interval
1711 // Read the resolution parameters:
1713 // Resolution colorspace bits row-count row-feed row-step name/text
1714 if (!get_token(fp
, temp
, sizeof(temp
)))
1716 _cupsLangPrintf(stderr
,
1717 _("ppdc: Expected override field after Resolution on line "
1718 "%d of %s."), fp
->line
, fp
->filename
);
1722 color_order
= get_color_order(temp
);
1723 color_space
= get_color_space(temp
);
1724 compression
= get_integer(temp
);
1726 depth
= get_integer(fp
);
1727 row_count
= get_integer(fp
);
1728 row_feed
= get_integer(fp
);
1729 row_step
= get_integer(fp
);
1731 if (!get_token(fp
, name
, sizeof(name
)))
1733 _cupsLangPrintf(stderr
,
1734 _("ppdc: Expected name/text after Resolution on line %d of "
1735 "%s."), fp
->line
, fp
->filename
);
1739 if ((text
= strchr(name
, '/')) != NULL
)
1744 switch (sscanf(name
, "%dx%d", &xdpi
, &ydpi
))
1752 _cupsLangPrintf(stderr
,
1753 _("ppdc: Bad resolution name \"%s\" on line %d of "
1754 "%s."), name
, fp
->line
, fp
->filename
);
1758 // Create the necessary PS commands...
1759 snprintf(command
, sizeof(command
),
1760 "<</HWResolution[%d %d]/cupsBitsPerColor %d/cupsRowCount %d"
1761 "/cupsRowFeed %d/cupsRowStep %d",
1762 xdpi
, ydpi
, depth
, row_count
, row_feed
, row_step
);
1763 commptr
= command
+ strlen(command
);
1765 if (color_order
>= 0)
1767 snprintf(commptr
, sizeof(command
) - (size_t)(commptr
- command
),
1768 "/cupsColorOrder %d", color_order
);
1769 commptr
+= strlen(commptr
);
1772 if (color_space
>= 0)
1774 snprintf(commptr
, sizeof(command
) - (size_t)(commptr
- command
),
1775 "/cupsColorSpace %d", color_space
);
1776 commptr
+= strlen(commptr
);
1779 if (compression
>= 0)
1781 snprintf(commptr
, sizeof(command
) - (size_t)(commptr
- command
),
1782 "/cupsCompression %d", compression
);
1783 commptr
+= strlen(commptr
);
1786 snprintf(commptr
, sizeof(command
) - (size_t)(commptr
- command
), ">>setpagedevice");
1788 // Return the new choice...
1789 return (new ppdcChoice(name
, text
, command
));
1794 // 'ppdcSource::get_simple_profile()' - Get a simple color profile definition.
1797 ppdcProfile
* // O - Color profile
1798 ppdcSource::get_simple_profile(ppdcFile
*fp
)
1801 char resolution
[1024], // Resolution/media type
1802 *media_type
; // Media type
1803 float m
[9]; // Transform matrix
1804 float kd
, rd
, g
; // Densities and gamma
1805 float red
, green
, blue
; // RGB adjustments
1806 float yellow
; // Yellow density
1807 float color
; // Color density values
1810 // Get the SimpleColorProfile parameters:
1812 // SimpleColorProfile resolution/mediatype black-density yellow-density
1813 // red-density gamma red-adjust green-adjust blue-adjust
1814 if (!get_token(fp
, resolution
, sizeof(resolution
)))
1816 _cupsLangPrintf(stderr
,
1817 _("ppdc: Expected resolution/mediatype following "
1818 "SimpleColorProfile on line %d of %s."),
1819 fp
->line
, fp
->filename
);
1823 if ((media_type
= strchr(resolution
, '/')) != NULL
)
1824 *media_type
++ = '\0';
1826 media_type
= resolution
;
1828 // Collect the profile parameters...
1830 yellow
= get_float(fp
);
1833 red
= get_float(fp
);
1834 green
= get_float(fp
);
1835 blue
= get_float(fp
);
1837 // Build the color profile...
1838 color
= 0.5f
* rd
/ kd
- kd
;
1840 m
[1] = color
+ blue
; // C + M (blue)
1841 m
[2] = color
- green
; // C + Y (green)
1842 m
[3] = color
- blue
; // M + C (blue)
1844 m
[5] = color
+ red
; // M + Y (red)
1845 m
[6] = yellow
* (color
+ green
); // Y + C (green)
1846 m
[7] = yellow
* (color
- red
); // Y + M (red)
1854 else if (m
[3] > 0.0f
)
1865 else if (m
[6] > 0.0f
)
1876 else if (m
[7] > 0.0f
)
1882 // Return the new profile...
1883 return (new ppdcProfile(resolution
, media_type
, g
, kd
, m
));
1888 // 'ppdcSource::get_size()' - Get a media size definition from a file.
1891 ppdcMediaSize
* // O - Media size
1892 ppdcSource::get_size(ppdcFile
*fp
) // I - File to read
1894 char name
[1024], // Name
1896 float width
, // Width
1900 // Get the name, text, width, and length:
1902 // #media name/text width length
1903 if (!get_token(fp
, name
, sizeof(name
)))
1906 if ((text
= strchr(name
, '/')) != NULL
)
1911 if ((width
= get_measurement(fp
)) < 0.0f
)
1914 if ((length
= get_measurement(fp
)) < 0.0f
)
1917 // Return the new media size...
1918 return (new ppdcMediaSize(name
, text
, width
, length
, 0.0f
, 0.0f
, 0.0f
, 0.0f
));
1923 // 'ppdcSource::get_token()' - Get a token from a file.
1926 char * // O - Token string or NULL
1927 ppdcSource::get_token(ppdcFile
*fp
, // I - File to read
1928 char *buffer
, // I - Buffer
1929 int buflen
) // I - Length of buffer
1931 char *bufptr
, // Pointer into string buffer
1932 *bufend
; // End of string buffer
1933 int ch
, // Character from file
1934 nextch
, // Next char in file
1935 quote
, // Quote character used...
1936 empty
, // Empty input?
1937 startline
; // Start line for quote
1938 char name
[256], // Name string
1939 *nameptr
; // Name pointer
1940 ppdcVariable
*var
; // Variable pointer
1943 // Mark the beginning and end of the buffer...
1945 bufend
= buffer
+ buflen
- 1;
1947 // Loop intil we've read a token...
1952 while ((ch
= fp
->get()) != EOF
)
1954 if (isspace(ch
) && !quote
)
1963 // Variable substitution
1966 for (nameptr
= name
; (ch
= fp
->peek()) != EOF
;)
1968 if (!isalnum(ch
) && ch
!= '_')
1970 else if (nameptr
< (name
+ sizeof(name
) - 1))
1971 *nameptr
++ = (char)fp
->get();
1974 if (nameptr
== name
)
1976 // Just substitute this character...
1980 if (bufptr
< bufend
)
1981 *bufptr
++ = (char)fp
->get();
1986 _cupsLangPrintf(stderr
,
1987 _("ppdc: Bad variable substitution ($%c) on line %d "
1988 "of %s."), ch
, fp
->line
, fp
->filename
);
1990 if (bufptr
< bufend
)
1996 // Substitute the variable value...
1998 var
= find_variable(name
);
2001 strlcpy(bufptr
, var
->value
->value
, (size_t)(bufend
- bufptr
+ 1));
2002 bufptr
+= strlen(bufptr
);
2006 if (!(cond_state
& PPDC_COND_SKIP
))
2007 _cupsLangPrintf(stderr
,
2008 _("ppdc: Undefined variable (%s) on line %d of "
2009 "%s."), name
, fp
->line
, fp
->filename
);
2011 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "$%s", name
);
2012 bufptr
+= strlen(bufptr
);
2016 else if (ch
== '/' && !quote
)
2018 // Possibly a comment...
2019 nextch
= fp
->peek();
2026 while ((nextch
= fp
->get()) != EOF
)
2028 if (ch
== '*' && nextch
== '/')
2037 else if (nextch
== '/')
2040 while ((nextch
= fp
->get()) != EOF
)
2052 if (bufptr
< bufend
)
2053 *bufptr
++ = (char)ch
;
2056 else if (ch
== '\'' || ch
== '\"')
2062 // Ending the current quoted string...
2067 // Insert the opposing quote char...
2068 if (bufptr
< bufend
)
2069 *bufptr
++ = (char)ch
;
2073 // Start a new quoted string...
2074 startline
= fp
->line
;
2078 else if ((ch
== '(' || ch
== '<') && !quote
)
2082 startline
= fp
->line
;
2084 if (bufptr
< bufend
)
2085 *bufptr
++ = (char)ch
;
2087 else if ((ch
== ')' && quote
== '(') || (ch
== '>' && quote
== '<'))
2091 if (bufptr
< bufend
)
2092 *bufptr
++ = (char)ch
;
2094 else if (ch
== '\\')
2098 if ((ch
= fp
->get()) == EOF
)
2101 if (bufptr
< bufend
)
2102 *bufptr
++ = (char)ch
;
2104 else if (bufptr
< bufend
)
2108 *bufptr
++ = (char)ch
;
2110 if ((ch
== '{' || ch
== '}') && !quote
)
2117 _cupsLangPrintf(stderr
,
2118 _("ppdc: Unterminated string starting with %c on line %d "
2119 "of %s."), quote
, startline
, fp
->filename
);
2134 // 'ppdcSource::get_variable()' - Get a variable definition.
2137 ppdcVariable
* // O - Variable
2138 ppdcSource::get_variable(ppdcFile
*fp
) // I - File to read
2140 char name
[1024], // Name
2141 value
[1024]; // Value
2144 // Get the name and value:
2146 // #define name value
2147 if (!get_token(fp
, name
, sizeof(name
)))
2150 if (!get_token(fp
, value
, sizeof(value
)))
2153 // Set the variable...
2154 return (set_variable(name
, value
));
2159 // 'ppdcSource::quotef()' - Write a formatted, quoted string...
2162 int // O - Number bytes on success, -1 on failure
2163 ppdcSource::quotef(cups_file_t
*fp
, // I - File to write to
2164 const char *format
, // I - Printf-style format string
2165 ...) // I - Additional args as needed
2167 va_list ap
; // Pointer to additional arguments
2168 int bytes
; // Bytes written
2169 char sign
, // Sign of format width
2170 size
, // Size character (h, l, L)
2171 type
; // Format type character
2172 const char *bufformat
; // Start of format
2173 int width
, // Width of field
2174 prec
; // Number of characters of precision
2175 char tformat
[100]; // Temporary format string for fprintf()
2176 char *s
; // Pointer to string
2177 int slen
; // Length of string
2178 int i
; // Looping var
2181 // Range check input...
2185 // Loop through the format string, formatting as needed...
2186 va_start(ap
, format
);
2199 cupsFilePutChar(fp
, *format
++);
2203 else if (strchr(" -+#\'", *format
))
2209 while (isdigit(*format
))
2210 width
= width
* 10 + *format
++ - '0';
2217 while (isdigit(*format
))
2218 prec
= prec
* 10 + *format
++ - '0';
2223 if (*format
== 'l' && format
[1] == 'l')
2228 else if (*format
== 'h' || *format
== 'l' || *format
== 'L')
2240 case 'E' : // Floating point formats
2245 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2248 memcpy(tformat
, bufformat
, (size_t)(format
- bufformat
));
2249 tformat
[format
- bufformat
] = '\0';
2251 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, double));
2254 case 'B' : // Integer formats
2262 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2265 memcpy(tformat
, bufformat
, (size_t)(format
- bufformat
));
2266 tformat
[format
- bufformat
] = '\0';
2268 # ifdef HAVE_LONG_LONG
2270 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, long long));
2272 # endif /* HAVE_LONG_LONG */
2274 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, long));
2276 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, int));
2279 case 'p' : // Pointer value
2280 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2283 memcpy(tformat
, bufformat
, (size_t)(format
- bufformat
));
2284 tformat
[format
- bufformat
] = '\0';
2286 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, void *));
2289 case 'c' : // Character or character array
2293 cupsFilePutChar(fp
, va_arg(ap
, int));
2297 cupsFileWrite(fp
, va_arg(ap
, char *), (size_t)width
);
2302 case 's' : // String
2303 if ((s
= va_arg(ap
, char *)) == NULL
)
2304 s
= (char *)"(nil)";
2306 slen
= (int)strlen(s
);
2307 if (slen
> width
&& prec
!= width
)
2315 for (i
= width
- slen
; i
> 0; i
--, bytes
++)
2316 cupsFilePutChar(fp
, ' ');
2319 for (i
= slen
; i
> 0; i
--, s
++, bytes
++)
2321 if (*s
== '\\' || *s
== '\"')
2323 cupsFilePutChar(fp
, '\\');
2327 cupsFilePutChar(fp
, *s
);
2332 for (i
= width
- slen
; i
> 0; i
--, bytes
++)
2333 cupsFilePutChar(fp
, ' ');
2340 cupsFilePutChar(fp
, *format
++);
2347 // Return the number of characters written.
2353 // 'ppdcSource::read_file()' - Read a driver source file.
2357 ppdcSource::read_file(const char *f
, // I - File to read
2358 cups_file_t
*ffp
) // I - File pointer to use
2360 ppdcFile
*fp
= new ppdcFile(f
, ffp
);
2364 if (cond_current
!= cond_stack
)
2365 _cupsLangPrintf(stderr
, _("ppdc: Missing #endif at end of \"%s\"."), f
);
2370 // 'ppdcSource::scan_file()' - Scan a driver source file.
2374 ppdcSource::scan_file(ppdcFile
*fp
, // I - File to read
2375 ppdcDriver
*td
, // I - Driver template
2376 bool inc
) // I - Including?
2378 ppdcDriver
*d
; // Current driver
2379 ppdcGroup
*g
, // Current group
2380 *mg
, // Matching group
2381 *general
, // General options group
2382 *install
; // Installable options group
2383 ppdcOption
*o
; // Current option
2384 ppdcChoice
*c
; // Current choice
2385 char temp
[256], // Token from file...
2386 *ptr
; // Pointer into token
2387 int isdefault
; // Default option?
2390 // Initialize things as needed...
2397 d
= new ppdcDriver(td
);
2399 if ((general
= d
->find_group("General")) == NULL
)
2401 general
= new ppdcGroup("General", NULL
);
2402 d
->add_group(general
);
2405 if ((install
= d
->find_group("InstallableOptions")) == NULL
)
2407 install
= new ppdcGroup("InstallableOptions", "Installable Options");
2408 d
->add_group(install
);
2411 // Loop until EOF or }
2415 while (get_token(fp
, temp
, sizeof(temp
)))
2419 // Mark the next choice as the default
2422 for (ptr
= temp
; ptr
[1]; ptr
++)
2429 // Don't mark the next choice as the default
2433 if (!_cups_strcasecmp(temp
, "}"))
2435 // Close this one out...
2438 else if (!_cups_strcasecmp(temp
, "{"))
2440 // Open a new child...
2443 else if (!_cups_strcasecmp(temp
, "#if"))
2445 if ((cond_current
- cond_stack
) >= 100)
2447 _cupsLangPrintf(stderr
,
2448 _("ppdc: Too many nested #if's on line %d of %s."),
2449 fp
->line
, fp
->filename
);
2454 if (get_integer(fp
) > 0)
2455 *cond_current
= PPDC_COND_SATISFIED
;
2458 *cond_current
= PPDC_COND_SKIP
;
2459 cond_state
|= PPDC_COND_SKIP
;
2462 else if (!_cups_strcasecmp(temp
, "#elif"))
2464 if (cond_current
== cond_stack
)
2466 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s."),
2467 fp
->line
, fp
->filename
);
2471 if (*cond_current
& PPDC_COND_SATISFIED
)
2474 *cond_current
|= PPDC_COND_SKIP
;
2476 else if (get_integer(fp
) > 0)
2478 *cond_current
|= PPDC_COND_SATISFIED
;
2479 *cond_current
&= ~PPDC_COND_SKIP
;
2482 *cond_current
|= PPDC_COND_SKIP
;
2484 // Update the current state
2485 int *cond_temp
= cond_current
; // Temporary stack pointer
2487 cond_state
= PPDC_COND_NORMAL
;
2488 while (cond_temp
> cond_stack
)
2489 if (*cond_temp
& PPDC_COND_SKIP
)
2491 cond_state
= PPDC_COND_SKIP
;
2497 else if (!_cups_strcasecmp(temp
, "#else"))
2499 if (cond_current
== cond_stack
)
2501 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s."),
2502 fp
->line
, fp
->filename
);
2506 if (*cond_current
& PPDC_COND_SATISFIED
)
2507 *cond_current
|= PPDC_COND_SKIP
;
2510 *cond_current
|= PPDC_COND_SATISFIED
;
2511 *cond_current
&= ~PPDC_COND_SKIP
;
2514 // Update the current state
2515 int *cond_temp
= cond_current
; // Temporary stack pointer
2517 cond_state
= PPDC_COND_NORMAL
;
2518 while (cond_temp
> cond_stack
)
2519 if (*cond_temp
& PPDC_COND_SKIP
)
2521 cond_state
= PPDC_COND_SKIP
;
2527 else if (!_cups_strcasecmp(temp
, "#endif"))
2529 if (cond_current
== cond_stack
)
2531 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s."),
2532 fp
->line
, fp
->filename
);
2538 // Update the current state
2539 int *cond_temp
= cond_current
; // Temporary stack pointer
2541 cond_state
= PPDC_COND_NORMAL
;
2542 while (cond_temp
> cond_stack
)
2543 if (*cond_temp
& PPDC_COND_SKIP
)
2545 cond_state
= PPDC_COND_SKIP
;
2551 else if (!_cups_strcasecmp(temp
, "#define"))
2553 // Get the variable...
2556 else if (!_cups_strcasecmp(temp
, "#include"))
2558 // #include filename
2559 char basedir
[1024], // Base directory
2560 *baseptr
, // Pointer into directory
2561 inctemp
[1024], // Initial filename
2562 incname
[1024]; // Include filename
2563 ppdcFile
*incfile
; // Include file
2564 int *old_current
= cond_current
;
2565 // Previous current stack
2568 // Get the include name...
2569 if (!get_token(fp
, inctemp
, sizeof(inctemp
)))
2571 _cupsLangPrintf(stderr
,
2572 _("ppdc: Expected include filename on line %d of "
2573 "%s."), fp
->line
, fp
->filename
);
2580 // Figure out the current directory...
2581 strlcpy(basedir
, fp
->filename
, sizeof(basedir
));
2583 if ((baseptr
= strrchr(basedir
, '/')) != NULL
)
2586 strlcpy(basedir
, ".", sizeof(basedir
));
2588 // Find the include file...
2589 if (find_include(inctemp
, basedir
, incname
, sizeof(incname
)))
2591 // Open the include file, scan it, and then close it...
2592 incfile
= new ppdcFile(incname
);
2593 scan_file(incfile
, d
, true);
2596 if (cond_current
!= old_current
)
2597 _cupsLangPrintf(stderr
, _("ppdc: Missing #endif at end of \"%s\"."),
2603 _cupsLangPrintf(stderr
,
2604 _("ppdc: Unable to find include file \"%s\" on line %d "
2605 "of %s."), inctemp
, fp
->line
, fp
->filename
);
2609 else if (!_cups_strcasecmp(temp
, "#media"))
2611 ppdcMediaSize
*m
; // Media size
2614 // Get a media size...
2624 else if (!_cups_strcasecmp(temp
, "#po"))
2626 ppdcCatalog
*cat
; // Message catalog
2629 // Get a message catalog...
2639 else if (!_cups_strcasecmp(temp
, "Attribute") ||
2640 !_cups_strcasecmp(temp
, "LocAttribute"))
2642 ppdcAttr
*a
; // Attribute
2645 // Get an attribute...
2646 a
= get_attr(fp
, !_cups_strcasecmp(temp
, "LocAttribute"));
2655 else if (!_cups_strcasecmp(temp
, "Choice"))
2668 // Add it to the current option...
2672 _cupsLangPrintf(stderr
,
2673 _("ppdc: Choice found on line %d of %s with no "
2674 "Option."), fp
->line
, fp
->filename
);
2681 o
->set_defchoice(c
);
2683 else if (!_cups_strcasecmp(temp
, "ColorDevice"))
2685 // ColorDevice boolean
2689 d
->color_device
= get_boolean(fp
);
2691 else if (!_cups_strcasecmp(temp
, "ColorModel"))
2693 // Get the color model
2694 c
= get_color_model(fp
);
2704 // Add the choice to the ColorModel option...
2705 if ((o
= d
->find_option("ColorModel")) == NULL
)
2707 // Create the ColorModel option...
2708 o
= new ppdcOption(PPDC_PICKONE
, "ColorModel", "Color Mode", PPDC_SECTION_ANY
, 10.0f
);
2716 o
->set_defchoice(c
);
2720 else if (!_cups_strcasecmp(temp
, "ColorProfile"))
2722 ppdcProfile
*p
; // Color profile
2725 // Get the color profile...
2726 p
= get_color_profile(fp
);
2733 d
->profiles
->add(p
);
2736 else if (!_cups_strcasecmp(temp
, "Copyright"))
2739 char copytemp
[8192], // Copyright string
2740 *copyptr
, // Pointer into string
2741 *copyend
; // Pointer to end of string
2744 // Get the copyright string...
2745 if (!get_token(fp
, copytemp
, sizeof(temp
)))
2747 _cupsLangPrintf(stderr
,
2748 _("ppdc: Expected string after Copyright on line %d "
2749 "of %s."), fp
->line
, fp
->filename
);
2756 // Break it up into individual lines...
2757 for (copyptr
= copytemp
; copyptr
; copyptr
= copyend
)
2759 if ((copyend
= strchr(copyptr
, '\n')) != NULL
)
2762 d
->copyright
->add(new ppdcString(copyptr
));
2765 else if (!_cups_strcasecmp(temp
, "CustomMedia"))
2767 ppdcMediaSize
*m
; // Media size
2770 // Get a custom media size...
2771 m
= get_custom_size(fp
);
2783 d
->set_default_size(m
);
2785 else if (!_cups_strcasecmp(temp
, "Cutter"))
2788 int have_cutter
; // Have a paper cutter?
2791 have_cutter
= get_boolean(fp
);
2792 if (have_cutter
<= 0 || cond_state
)
2795 if ((o
= d
->find_option("CutMedia")) == NULL
)
2797 o
= new ppdcOption(PPDC_BOOLEAN
, "CutMedia", "Cut Media", PPDC_SECTION_ANY
, 10.0f
);
2802 c
= new ppdcChoice("False", NULL
, "<</CutMedia 0>>setpagedevice");
2804 o
->set_defchoice(c
);
2806 c
= new ppdcChoice("True", NULL
, "<</CutMedia 4>>setpagedevice");
2812 else if (!_cups_strcasecmp(temp
, "Darkness"))
2814 // Get the darkness choice...
2815 c
= get_generic(fp
, "Darkness", NULL
, "cupsCompression");
2825 // Add the choice to the cupsDarkness option...
2826 if ((o
= d
->find_option_group("cupsDarkness", &mg
)) == NULL
)
2828 // Create the cupsDarkness option...
2829 o
= new ppdcOption(PPDC_PICKONE
, "cupsDarkness", "Darkness", PPDC_SECTION_ANY
, 10.0f
);
2833 else if (mg
!= general
)
2835 _cupsLangPrintf(stderr
,
2836 _("ppdc: Option %s defined in two different groups on "
2837 "line %d of %s."), "cupsDarkness", fp
->line
,
2846 o
->set_defchoice(c
);
2850 else if (!_cups_strcasecmp(temp
, "DriverType"))
2852 int i
; // Looping var
2855 // DriverType keyword
2856 if (!get_token(fp
, temp
, sizeof(temp
)))
2858 _cupsLangPrintf(stderr
,
2859 _("ppdc: Expected driver type keyword following "
2860 "DriverType on line %d of %s."),
2861 fp
->line
, fp
->filename
);
2868 for (i
= 0; i
< (int)(sizeof(driver_types
) / sizeof(driver_types
[0])); i
++)
2869 if (!_cups_strcasecmp(temp
, driver_types
[i
]))
2872 if (i
< (int)(sizeof(driver_types
) / sizeof(driver_types
[0])))
2873 d
->type
= (ppdcDrvType
)i
;
2874 else if (!_cups_strcasecmp(temp
, "dymo"))
2875 d
->type
= PPDC_DRIVER_LABEL
;
2877 _cupsLangPrintf(stderr
,
2878 _("ppdc: Unknown driver type %s on line %d of %s."),
2879 temp
, fp
->line
, fp
->filename
);
2881 else if (!_cups_strcasecmp(temp
, "Duplex"))
2883 else if (!_cups_strcasecmp(temp
, "Filter"))
2885 ppdcFilter
*f
; // Filter
2888 // Get the filter value...
2898 else if (!_cups_strcasecmp(temp
, "Finishing"))
2900 // Get the finishing choice...
2901 c
= get_generic(fp
, "Finishing", "OutputType", NULL
);
2911 // Add the choice to the cupsFinishing option...
2912 if ((o
= d
->find_option_group("cupsFinishing", &mg
)) == NULL
)
2914 // Create the cupsFinishing option...
2915 o
= new ppdcOption(PPDC_PICKONE
, "cupsFinishing", "Finishing", PPDC_SECTION_ANY
, 10.0f
);
2919 else if (mg
!= general
)
2921 _cupsLangPrintf(stderr
,
2922 _("ppdc: Option %s defined in two different groups on "
2923 "line %d of %s."), "cupsFinishing", fp
->line
,
2932 o
->set_defchoice(c
);
2936 else if (!_cups_strcasecmp(temp
, "Font") ||
2937 !_cups_strcasecmp(temp
, "#font"))
2939 ppdcFont
*f
; // Font
2950 if (!_cups_strcasecmp(temp
, "#font"))
2956 d
->set_default_font(f
);
2960 else if (!_cups_strcasecmp(temp
, "Group"))
2963 ppdcGroup
*tempg
= get_group(fp
, d
);
2970 if (!d
->find_group(tempg
->name
->value
))
2975 if (!d
->find_group(tempg
->name
->value
))
2976 d
->add_group(tempg
);
2981 else if (!_cups_strcasecmp(temp
, "HWMargins"))
2983 // HWMargins left bottom right top
2984 d
->left_margin
= get_measurement(fp
);
2985 d
->bottom_margin
= get_measurement(fp
);
2986 d
->right_margin
= get_measurement(fp
);
2987 d
->top_margin
= get_measurement(fp
);
2989 else if (!_cups_strcasecmp(temp
, "InputSlot"))
2991 // Get the input slot choice...
2992 c
= get_generic(fp
, "InputSlot", NULL
, "MediaPosition");
3002 // Add the choice to the InputSlot option...
3004 if ((o
= d
->find_option_group("InputSlot", &mg
)) == NULL
)
3006 // Create the InputSlot option...
3007 o
= new ppdcOption(PPDC_PICKONE
, "InputSlot", "Media Source",
3008 PPDC_SECTION_ANY
, 10.0f
);
3012 else if (mg
!= general
)
3014 _cupsLangPrintf(stderr
,
3015 _("ppdc: Option %s defined in two different groups on "
3016 "line %d of %s."), "InputSlot", fp
->line
,
3025 o
->set_defchoice(c
);
3029 else if (!_cups_strcasecmp(temp
, "Installable"))
3031 // Get the installable option...
3032 o
= get_installable(fp
);
3034 // Add it as needed...
3040 install
->add_option(o
);
3045 else if (!_cups_strcasecmp(temp
, "ManualCopies"))
3047 // ManualCopies boolean
3051 d
->manual_copies
= get_boolean(fp
);
3053 else if (!_cups_strcasecmp(temp
, "Manufacturer"))
3055 // Manufacturer name
3056 char name
[256]; // Model name string
3059 if (!get_token(fp
, name
, sizeof(name
)))
3061 _cupsLangPrintf(stderr
,
3062 _("ppdc: Expected name after Manufacturer on line %d "
3063 "of %s."), fp
->line
, fp
->filename
);
3068 d
->set_manufacturer(name
);
3070 else if (!_cups_strcasecmp(temp
, "MaxSize"))
3072 // MaxSize width length
3075 get_measurement(fp
);
3076 get_measurement(fp
);
3080 d
->max_width
= get_measurement(fp
);
3081 d
->max_length
= get_measurement(fp
);
3084 else if (!_cups_strcasecmp(temp
, "MediaSize"))
3086 // MediaSize keyword
3087 char name
[41]; // Media size name
3088 ppdcMediaSize
*m
, // Matching media size...
3089 *dm
; // Driver media size...
3092 if (get_token(fp
, name
, sizeof(name
)) == NULL
)
3094 _cupsLangPrintf(stderr
,
3095 _("ppdc: Expected name after MediaSize on line %d of "
3096 "%s."), fp
->line
, fp
->filename
);
3103 m
= find_size(name
);
3107 _cupsLangPrintf(stderr
,
3108 _("ppdc: Unknown media size \"%s\" on line %d of "
3109 "%s."), name
, fp
->line
, fp
->filename
);
3113 // Add this size to the driver...
3114 dm
= new ppdcMediaSize(m
->name
->value
, m
->text
->value
,
3115 m
->width
, m
->length
, d
->left_margin
,
3116 d
->bottom_margin
, d
->right_margin
,
3121 d
->set_default_size(dm
);
3123 else if (!_cups_strcasecmp(temp
, "MediaType"))
3125 // Get the media type choice...
3126 c
= get_generic(fp
, "MediaType", "MediaType", "cupsMediaType");
3136 // Add the choice to the MediaType option...
3137 if ((o
= d
->find_option_group("MediaType", &mg
)) == NULL
)
3139 // Create the MediaType option...
3140 o
= new ppdcOption(PPDC_PICKONE
, "MediaType", "Media Type",
3141 PPDC_SECTION_ANY
, 10.0f
);
3145 else if (mg
!= general
)
3147 _cupsLangPrintf(stderr
,
3148 _("ppdc: Option %s defined in two different groups on "
3149 "line %d of %s."), "MediaType", fp
->line
,
3158 o
->set_defchoice(c
);
3162 else if (!_cups_strcasecmp(temp
, "MinSize"))
3164 // MinSize width length
3167 get_measurement(fp
);
3168 get_measurement(fp
);
3172 d
->min_width
= get_measurement(fp
);
3173 d
->min_length
= get_measurement(fp
);
3176 else if (!_cups_strcasecmp(temp
, "ModelName"))
3179 char name
[256]; // Model name string
3182 if (!get_token(fp
, name
, sizeof(name
)))
3184 _cupsLangPrintf(stderr
,
3185 _("ppdc: Expected name after ModelName on line %d of "
3186 "%s."), fp
->line
, fp
->filename
);
3191 d
->set_model_name(name
);
3193 else if (!_cups_strcasecmp(temp
, "ModelNumber"))
3195 // ModelNumber number
3199 d
->model_number
= get_integer(fp
);
3201 else if (!_cups_strcasecmp(temp
, "Option"))
3204 ppdcOption
*tempo
= get_option(fp
, d
, g
);
3211 if (!g
->find_option(tempo
->name
->value
))
3216 if (!g
->find_option(tempo
->name
->value
))
3217 g
->add_option(tempo
);
3222 else if (!_cups_strcasecmp(temp
, "FileName"))
3225 char name
[256]; // Filename string
3228 if (!get_token(fp
, name
, sizeof(name
)))
3230 _cupsLangPrintf(stderr
,
3231 _("ppdc: Expected name after FileName on line %d of "
3232 "%s."), fp
->line
, fp
->filename
);
3237 d
->set_file_name(name
);
3239 else if (!_cups_strcasecmp(temp
, "PCFileName"))
3242 char name
[256]; // PC filename string
3245 if (!get_token(fp
, name
, sizeof(name
)))
3247 _cupsLangPrintf(stderr
,
3248 _("ppdc: Expected name after PCFileName on line %d of "
3249 "%s."), fp
->line
, fp
->filename
);
3254 d
->set_pc_file_name(name
);
3256 else if (!_cups_strcasecmp(temp
, "Resolution"))
3258 // Get the resolution choice...
3259 c
= get_resolution(fp
);
3269 // Add the choice to the Resolution option...
3270 if ((o
= d
->find_option_group("Resolution", &mg
)) == NULL
)
3272 // Create the Resolution option...
3273 o
= new ppdcOption(PPDC_PICKONE
, "Resolution", NULL
, PPDC_SECTION_ANY
,
3278 else if (mg
!= general
)
3280 _cupsLangPrintf(stderr
,
3281 _("ppdc: Option %s defined in two different groups on "
3282 "line %d of %s."), "Resolution", fp
->line
,
3291 o
->set_defchoice(c
);
3295 else if (!_cups_strcasecmp(temp
, "SimpleColorProfile"))
3297 ppdcProfile
*p
; // Color profile
3300 // Get the color profile...
3301 p
= get_simple_profile(fp
);
3308 d
->profiles
->add(p
);
3311 else if (!_cups_strcasecmp(temp
, "Throughput"))
3313 // Throughput number
3317 d
->throughput
= get_integer(fp
);
3319 else if (!_cups_strcasecmp(temp
, "UIConstraints"))
3321 ppdcConstraint
*con
; // Constraint
3324 con
= get_constraint(fp
);
3331 d
->constraints
->add(con
);
3334 else if (!_cups_strcasecmp(temp
, "VariablePaperSize"))
3336 // VariablePaperSize boolean
3340 d
->variable_paper_size
= get_boolean(fp
);
3342 else if (!_cups_strcasecmp(temp
, "Version"))
3345 char name
[256]; // Model name string
3348 if (!get_token(fp
, name
, sizeof(name
)))
3350 _cupsLangPrintf(stderr
,
3351 _("ppdc: Expected string after Version on line %d of "
3352 "%s."), fp
->line
, fp
->filename
);
3357 d
->set_version(name
);
3361 _cupsLangPrintf(stderr
,
3362 _("ppdc: Unknown token \"%s\" seen on line %d of %s."),
3363 temp
, fp
->line
, fp
->filename
);
3368 // Done processing this block, is there anything to save?
3371 if (!d
->pc_file_name
|| !d
->model_name
|| !d
->manufacturer
|| !d
->version
||
3374 // Nothing to save...
3379 // Got a driver, save it...
3389 // 'ppdcSource::set_variable()' - Set a variable.
3392 ppdcVariable
* // O - Variable
3393 ppdcSource::set_variable(
3394 const char *name
, // I - Name
3395 const char *value
) // I - Value
3397 ppdcVariable
*v
; // Variable
3400 // See if the variable exists already...
3401 v
= find_variable(name
);
3404 // Change the variable value...
3405 v
->set_value(value
);
3409 // Create a new variable and add it...
3410 v
= new ppdcVariable(name
, value
);
3419 // 'ppdcSource::write_file()' - Write the current source data to a file.
3422 int // O - 0 on success, -1 on error
3423 ppdcSource::write_file(const char *f
) // I - File to write
3425 cups_file_t
*fp
; // Output file
3426 char bckname
[1024]; // Backup file
3427 ppdcDriver
*d
; // Current driver
3428 ppdcString
*st
; // Current string
3429 ppdcAttr
*a
; // Current attribute
3430 ppdcConstraint
*co
; // Current constraint
3431 ppdcFilter
*fi
; // Current filter
3432 ppdcFont
*fo
; // Current font
3433 ppdcGroup
*g
; // Current group
3434 ppdcOption
*o
; // Current option
3435 ppdcChoice
*ch
; // Current choice
3436 ppdcProfile
*p
; // Current color profile
3437 ppdcMediaSize
*si
; // Current media size
3438 float left
, // Current left margin
3439 bottom
, // Current bottom margin
3440 right
, // Current right margin
3441 top
; // Current top margin
3442 int dtused
[PPDC_DRIVER_MAX
];// Driver type usage...
3445 // Rename the current file, if any, to .bck...
3446 snprintf(bckname
, sizeof(bckname
), "%s.bck", f
);
3449 // Open the output file...
3450 fp
= cupsFileOpen(f
, "w");
3454 // Can't create file; restore backup and return...
3459 cupsFilePuts(fp
, "// CUPS PPD Compiler " CUPS_SVERSION
"\n\n");
3461 // Include standard files...
3462 cupsFilePuts(fp
, "// Include necessary files...\n");
3463 cupsFilePuts(fp
, "#include <font.defs>\n");
3464 cupsFilePuts(fp
, "#include <media.defs>\n");
3466 memset(dtused
, 0, sizeof(dtused
));
3468 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
3469 if (d
->type
> PPDC_DRIVER_PS
&& !dtused
[d
->type
])
3471 cupsFilePrintf(fp
, "#include <%s.h>\n", driver_types
[d
->type
]);
3472 dtused
[d
->type
] = 1;
3475 // Output each driver...
3476 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
3478 // Start the driver...
3479 cupsFilePrintf(fp
, "\n// %s %s\n", d
->manufacturer
->value
,
3480 d
->model_name
->value
);
3481 cupsFilePuts(fp
, "{\n");
3483 // Write the copyright stings...
3484 for (st
= (ppdcString
*)d
->copyright
->first();
3486 st
= (ppdcString
*)d
->copyright
->next())
3487 quotef(fp
, " Copyright \"%s\"\n", st
->value
);
3489 // Write other strings and values...
3490 if (d
->manufacturer
&& d
->manufacturer
->value
)
3491 quotef(fp
, " Manufacturer \"%s\"\n", d
->manufacturer
->value
);
3492 if (d
->model_name
->value
)
3493 quotef(fp
, " ModelName \"%s\"\n", d
->model_name
->value
);
3494 if (d
->file_name
&& d
->file_name
->value
)
3495 quotef(fp
, " FileName \"%s\"\n", d
->file_name
->value
);
3496 if (d
->pc_file_name
&& d
->pc_file_name
->value
)
3497 quotef(fp
, " PCFileName \"%s\"\n", d
->pc_file_name
->value
);
3498 if (d
->version
&& d
->version
->value
)
3499 quotef(fp
, " Version \"%s\"\n", d
->version
->value
);
3501 cupsFilePrintf(fp
, " DriverType %s\n", driver_types
[d
->type
]);
3503 if (d
->model_number
)
3507 case PPDC_DRIVER_LABEL
:
3508 cupsFilePuts(fp
, " ModelNumber ");
3510 switch (d
->model_number
)
3513 cupsFilePuts(fp
, "$DYMO_3x0\n");
3516 case ZEBRA_EPL_LINE
:
3517 cupsFilePuts(fp
, "$ZEBRA_EPL_LINE\n");
3520 case ZEBRA_EPL_PAGE
:
3521 cupsFilePuts(fp
, "$ZEBRA_EPL_PAGE\n");
3525 cupsFilePuts(fp
, "$ZEBRA_ZPL\n");
3529 cupsFilePuts(fp
, "$ZEBRA_CPCL\n");
3532 case INTELLITECH_PCL
:
3533 cupsFilePuts(fp
, "$INTELLITECH_PCL\n");
3537 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3542 case PPDC_DRIVER_EPSON
:
3543 cupsFilePuts(fp
, " ModelNumber ");
3545 switch (d
->model_number
)
3548 cupsFilePuts(fp
, "$EPSON_9PIN\n");
3552 cupsFilePuts(fp
, "$EPSON_24PIN\n");
3556 cupsFilePuts(fp
, "$EPSON_COLOR\n");
3560 cupsFilePuts(fp
, "$EPSON_PHOTO\n");
3564 cupsFilePuts(fp
, "$EPSON_ICOLOR\n");
3568 cupsFilePuts(fp
, "$EPSON_IPHOTO\n");
3572 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3577 case PPDC_DRIVER_HP
:
3578 cupsFilePuts(fp
, " ModelNumber ");
3579 switch (d
->model_number
)
3582 cupsFilePuts(fp
, "$HP_LASERJET\n");
3586 cupsFilePuts(fp
, "$HP_DESKJET\n");
3590 cupsFilePuts(fp
, "$HP_DESKJET2\n");
3594 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3598 cupsFilePuts(fp
, ")\n");
3602 cupsFilePrintf(fp
, " ModelNumber %d\n", d
->model_number
);
3607 if (d
->manual_copies
)
3608 cupsFilePuts(fp
, " ManualCopies Yes\n");
3610 if (d
->color_device
)
3611 cupsFilePuts(fp
, " ColorDevice Yes\n");
3614 cupsFilePrintf(fp
, " Throughput %d\n", d
->throughput
);
3616 // Output all of the attributes...
3617 for (a
= (ppdcAttr
*)d
->attrs
->first();
3619 a
= (ppdcAttr
*)d
->attrs
->next())
3620 if (a
->text
->value
&& a
->text
->value
[0])
3621 quotef(fp
, " Attribute \"%s\" \"%s/%s\" \"%s\"\n",
3622 a
->name
->value
, a
->selector
->value
? a
->selector
->value
: "",
3623 a
->text
->value
, a
->value
->value
? a
->value
->value
: "");
3625 quotef(fp
, " Attribute \"%s\" \"%s\" \"%s\"\n",
3626 a
->name
->value
, a
->selector
->value
? a
->selector
->value
: "",
3627 a
->value
->value
? a
->value
->value
: "");
3629 // Output all of the constraints...
3630 for (co
= (ppdcConstraint
*)d
->constraints
->first();
3632 co
= (ppdcConstraint
*)d
->constraints
->next())
3634 if (co
->option1
->value
[0] == '*')
3635 cupsFilePrintf(fp
, " UIConstraints \"%s %s", co
->option1
->value
,
3636 co
->choice1
->value
? co
->choice1
->value
: "");
3638 cupsFilePrintf(fp
, " UIConstraints \"*%s %s", co
->option1
->value
,
3639 co
->choice1
->value
? co
->choice1
->value
: "");
3641 if (co
->option2
->value
[0] == '*')
3642 cupsFilePrintf(fp
, " %s %s\"\n", co
->option2
->value
,
3643 co
->choice2
->value
? co
->choice2
->value
: "");
3645 cupsFilePrintf(fp
, " *%s %s\"\n", co
->option2
->value
,
3646 co
->choice2
->value
? co
->choice2
->value
: "");
3649 // Output all of the filters...
3650 for (fi
= (ppdcFilter
*)d
->filters
->first();
3652 fi
= (ppdcFilter
*)d
->filters
->next())
3653 cupsFilePrintf(fp
, " Filter \"%s %d %s\"\n",
3654 fi
->mime_type
->value
, fi
->cost
, fi
->program
->value
);
3656 // Output all of the fonts...
3657 for (fo
= (ppdcFont
*)d
->fonts
->first();
3659 fo
= (ppdcFont
*)d
->fonts
->next())
3660 if (!strcmp(fo
->name
->value
, "*"))
3661 cupsFilePuts(fp
, " Font *\n");
3663 cupsFilePrintf(fp
, " Font \"%s\" \"%s\" \"%s\" \"%s\" %s\n",
3664 fo
->name
->value
, fo
->encoding
->value
,
3665 fo
->version
->value
, fo
->charset
->value
,
3666 fo
->status
== PPDC_FONT_ROM
? "ROM" : "Disk");
3668 // Output all options...
3669 for (g
= (ppdcGroup
*)d
->groups
->first();
3671 g
= (ppdcGroup
*)d
->groups
->next())
3673 if (g
->options
->count
== 0)
3676 if (g
->text
->value
&& g
->text
->value
[0])
3677 quotef(fp
, " Group \"%s/%s\"\n", g
->name
->value
, g
->text
->value
);
3679 cupsFilePrintf(fp
, " Group \"%s\"\n", g
->name
->value
);
3681 for (o
= (ppdcOption
*)g
->options
->first();
3683 o
= (ppdcOption
*)g
->options
->next())
3685 if (o
->choices
->count
== 0)
3688 if (o
->text
->value
&& o
->text
->value
[0])
3689 quotef(fp
, " Option \"%s/%s\"", o
->name
->value
, o
->text
->value
);
3691 cupsFilePrintf(fp
, " Option \"%s\"", o
->name
->value
);
3693 cupsFilePrintf(fp
, " %s %s %.1f\n",
3694 o
->type
== PPDC_BOOLEAN
? "Boolean" :
3695 o
->type
== PPDC_PICKONE
? "PickOne" : "PickMany",
3696 o
->section
== PPDC_SECTION_ANY
? "AnySetup" :
3697 o
->section
== PPDC_SECTION_DOCUMENT
? "DocumentSetup" :
3698 o
->section
== PPDC_SECTION_EXIT
? "ExitServer" :
3699 o
->section
== PPDC_SECTION_JCL
? "JCLSetup" :
3700 o
->section
== PPDC_SECTION_PAGE
? "PageSetup" :
3704 for (ch
= (ppdcChoice
*)o
->choices
->first();
3706 ch
= (ppdcChoice
*)o
->choices
->next())
3708 if (ch
->text
->value
&& ch
->text
->value
[0])
3709 quotef(fp
, " %sChoice \"%s/%s\" \"%s\"\n",
3710 o
->defchoice
== ch
->name
? "*" : "",
3711 ch
->name
->value
, ch
->text
->value
,
3712 ch
->code
->value
? ch
->code
->value
: "");
3714 quotef(fp
, " %sChoice \"%s\" \"%s\"\n",
3715 o
->defchoice
== ch
->name
? "*" : "",
3717 ch
->code
->value
? ch
->code
->value
: "");
3722 // Output all of the color profiles...
3723 for (p
= (ppdcProfile
*)d
->profiles
->first();
3725 p
= (ppdcProfile
*)d
->profiles
->next())
3726 cupsFilePrintf(fp
, " ColorProfile \"%s/%s\" %.3f %.3f "
3727 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
3728 p
->resolution
->value
, p
->media_type
->value
,
3729 p
->density
, p
->gamma
,
3730 p
->profile
[0], p
->profile
[1], p
->profile
[2],
3731 p
->profile
[3], p
->profile
[4], p
->profile
[5],
3732 p
->profile
[6], p
->profile
[7], p
->profile
[8]);
3734 // Output all of the media sizes...
3740 for (si
= (ppdcMediaSize
*)d
->sizes
->first();
3742 si
= (ppdcMediaSize
*)d
->sizes
->next())
3743 if (si
->size_code
->value
&& si
->region_code
->value
)
3745 // Output a custom media size...
3746 quotef(fp
, " %sCustomMedia \"%s/%s\" %.2f %.2f %.2f %.2f %.2f %.2f \"%s\" \"%s\"\n",
3747 si
->name
== d
->default_size
? "*" : "", si
->name
->value
,
3748 si
->text
->value
, si
->width
, si
->length
, si
->left
, si
->bottom
,
3749 si
->right
, si
->top
, si
->size_code
->value
,
3750 si
->region_code
->value
);
3754 // Output a standard media size...
3755 if (fabs(left
- si
->left
) > 0.1 ||
3756 fabs(bottom
- si
->bottom
) > 0.1 ||
3757 fabs(right
- si
->right
) > 0.1 ||
3758 fabs(top
- si
->top
) > 0.1)
3760 cupsFilePrintf(fp
, " HWMargins %.2f %.2f %.2f %.2f\n",
3761 si
->left
, si
->bottom
, si
->right
, si
->top
);
3764 bottom
= si
->bottom
;
3769 cupsFilePrintf(fp
, " %sMediaSize %s\n",
3770 si
->name
== d
->default_size
? "*" : "",
3774 if (d
->variable_paper_size
)
3776 cupsFilePuts(fp
, " VariablePaperSize Yes\n");
3778 if (fabs(left
- d
->left_margin
) > 0.1 ||
3779 fabs(bottom
- d
->bottom_margin
) > 0.1 ||
3780 fabs(right
- d
->right_margin
) > 0.1 ||
3781 fabs(top
- d
->top_margin
) > 0.1)
3783 cupsFilePrintf(fp
, " HWMargins %.2f %.2f %.2f %.2f\n",
3784 d
->left_margin
, d
->bottom_margin
, d
->right_margin
,
3788 cupsFilePrintf(fp
, " MinSize %.2f %.2f\n", d
->min_width
, d
->min_length
);
3789 cupsFilePrintf(fp
, " MaxSize %.2f %.2f\n", d
->max_width
, d
->max_length
);
3792 // End the driver...
3793 cupsFilePuts(fp
, "}\n");
3796 // Close the file and return...