]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc-source.cxx
2 // Source class for the CUPS PPD Compiler.
4 // Copyright 2007-2014 by Apple Inc.
5 // Copyright 2002-2007 by Easy Software Products.
7 // These coded instructions, statements, and computer programs are the
8 // property of Apple Inc. and are protected by Federal copyright
9 // law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 // which should have been included with this file. If this file is
11 // missing or damaged, see the license at "http://www.cups.org/".
15 // Include necessary headers...
18 #include "ppdc-private.h"
22 #include <cups/raster.h>
23 #include "data/epson.h"
25 #include "data/label.h"
27 # include <sys/utsname.h>
35 ppdcArray
*ppdcSource::includes
= 0;
36 const char *ppdcSource::driver_types
[] =
49 // 'ppdcSource::ppdcSource()' - Load a driver source file.
52 ppdcSource::ppdcSource(const char *f
, // I - File to read
53 cups_file_t
*ffp
)// I - File pointer to use
58 filename
= new ppdcString(f
);
59 base_fonts
= new ppdcArray();
60 drivers
= new ppdcArray();
61 po_files
= new ppdcArray();
62 sizes
= new ppdcArray();
63 vars
= new ppdcArray();
64 cond_state
= PPDC_COND_NORMAL
;
65 cond_current
= cond_stack
;
66 cond_stack
[0] = PPDC_COND_NORMAL
;
68 // Add standard #define variables...
69 #define MAKE_STRING(x) #x
71 vars
->add(new ppdcVariable("CUPS_VERSION", MAKE_STRING(CUPS_VERSION
)));
72 vars
->add(new ppdcVariable("CUPS_VERSION_MAJOR", MAKE_STRING(CUPS_VERSION_MAJOR
)));
73 vars
->add(new ppdcVariable("CUPS_VERSION_MINOR", MAKE_STRING(CUPS_VERSION_MINOR
)));
74 vars
->add(new ppdcVariable("CUPS_VERSION_PATCH", MAKE_STRING(CUPS_VERSION_PATCH
)));
77 vars
->add(new ppdcVariable("PLATFORM_NAME", "Windows"));
78 vars
->add(new ppdcVariable("PLATFORM_ARCH", "X86"));
81 struct utsname name
; // uname information
85 vars
->add(new ppdcVariable("PLATFORM_NAME", name
.sysname
));
86 vars
->add(new ppdcVariable("PLATFORM_ARCH", name
.machine
));
90 vars
->add(new ppdcVariable("PLATFORM_NAME", "unknown"));
91 vars
->add(new ppdcVariable("PLATFORM_ARCH", "unknown"));
101 // 'ppdcSource::~ppdcSource()' - Free a driver source file.
104 ppdcSource::~ppdcSource()
109 base_fonts
->release();
118 // 'ppdcSource::add_include()' - Add an include directory.
122 ppdcSource::add_include(const char *d
) // I - Include directory
128 includes
= new ppdcArray();
130 includes
->add(new ppdcString(d
));
135 // 'ppdcSource::find_driver()' - Find a driver.
138 ppdcDriver
* // O - Driver
139 ppdcSource::find_driver(const char *f
) // I - Driver file name
141 ppdcDriver
*d
; // Current driver
144 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
145 if (!_cups_strcasecmp(f
, d
->pc_file_name
->value
))
153 // 'ppdcSource::find_include()' - Find an include file.
156 char * // O - Found path or NULL
157 ppdcSource::find_include(
158 const char *f
, // I - Include filename
159 const char *base
, // I - Current directory
160 char *n
, // I - Path buffer
161 int nlen
) // I - Path buffer length
163 ppdcString
*dir
; // Include directory
164 char temp
[1024], // Temporary path
165 *ptr
; // Pointer to end of path
168 // Range check input...
169 if (!f
|| !*f
|| !n
|| nlen
< 2)
172 // Check the first character to see if we have <name> or "name"...
175 // Remove the surrounding <> from the name...
176 strlcpy(temp
, f
+ 1, sizeof(temp
));
177 ptr
= temp
+ strlen(temp
) - 1;
181 _cupsLangPrintf(stderr
,
182 _("ppdc: Invalid #include/#po filename \"%s\"."), n
);
191 // Check for the local file relative to the current directory...
192 if (base
&& *base
&& f
[0] != '/')
193 snprintf(n
, (size_t)nlen
, "%s/%s", base
, f
);
195 strlcpy(n
, f
, (size_t)nlen
);
201 // Absolute path that doesn't exist...
206 // Search the include directories, if any...
209 for (dir
= (ppdcString
*)includes
->first(); dir
; dir
= (ppdcString
*)includes
->next())
211 snprintf(n
, (size_t)nlen
, "%s/%s", dir
->value
, f
);
217 // Search the standard include directories...
218 _cups_globals_t
*cg
= _cupsGlobals(); // Global data
220 snprintf(n
, (size_t)nlen
, "%s/ppdc/%s", cg
->cups_datadir
, f
);
224 snprintf(n
, (size_t)nlen
, "%s/po/%s", cg
->cups_datadir
, f
);
233 // 'ppdcSource::find_po()' - Find a message catalog for the given locale.
236 ppdcCatalog
* // O - Message catalog or NULL
237 ppdcSource::find_po(const char *l
) // I - Locale name
239 ppdcCatalog
*cat
; // Current message catalog
242 for (cat
= (ppdcCatalog
*)po_files
->first();
244 cat
= (ppdcCatalog
*)po_files
->next())
245 if (!_cups_strcasecmp(l
, cat
->locale
->value
))
253 // 'ppdcSource::find_size()' - Find a media size.
256 ppdcMediaSize
* // O - Size
257 ppdcSource::find_size(const char *s
) // I - Size name
259 ppdcMediaSize
*m
; // Current media size
262 for (m
= (ppdcMediaSize
*)sizes
->first(); m
; m
= (ppdcMediaSize
*)sizes
->next())
263 if (!_cups_strcasecmp(s
, m
->name
->value
))
271 // 'ppdcSource::find_variable()' - Find a variable.
274 ppdcVariable
* // O - Variable
275 ppdcSource::find_variable(const char *n
)// I - Variable name
277 ppdcVariable
*v
; // Current variable
280 for (v
= (ppdcVariable
*)vars
->first(); v
; v
= (ppdcVariable
*)vars
->next())
281 if (!_cups_strcasecmp(n
, v
->name
->value
))
289 // 'ppdcSource::get_attr()' - Get an attribute.
292 ppdcAttr
* // O - Attribute
293 ppdcSource::get_attr(ppdcFile
*fp
, // I - File to read
294 bool loc
) // I - Localize this attribute?
296 char name
[1024], // Name string
297 selector
[1024], // Selector string
298 *text
, // Text string
299 value
[1024]; // Value string
302 // Get the attribute parameters:
304 // Attribute name selector value
305 if (!get_token(fp
, name
, sizeof(name
)))
307 _cupsLangPrintf(stderr
,
308 _("ppdc: Expected name after %s on line %d of %s."),
309 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
313 if (!get_token(fp
, selector
, sizeof(selector
)))
315 _cupsLangPrintf(stderr
,
316 _("ppdc: Expected selector after %s on line %d of %s."),
317 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
321 if ((text
= strchr(selector
, '/')) != NULL
)
324 if (!get_token(fp
, value
, sizeof(value
)))
326 _cupsLangPrintf(stderr
,
327 _("ppdc: Expected value after %s on line %d of %s."),
328 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
332 return (new ppdcAttr(name
, selector
, text
, value
, loc
));
337 // 'ppdcSource::get_boolean()' - Get a boolean value.
340 int // O - Boolean value
341 ppdcSource::get_boolean(ppdcFile
*fp
) // I - File to read
343 char buffer
[256]; // String buffer
346 if (!get_token(fp
, buffer
, sizeof(buffer
)))
348 _cupsLangPrintf(stderr
,
349 _("ppdc: Expected boolean value on line %d of %s."),
350 fp
->line
, fp
->filename
);
354 if (!_cups_strcasecmp(buffer
, "on") ||
355 !_cups_strcasecmp(buffer
, "yes") ||
356 !_cups_strcasecmp(buffer
, "true"))
358 else if (!_cups_strcasecmp(buffer
, "off") ||
359 !_cups_strcasecmp(buffer
, "no") ||
360 !_cups_strcasecmp(buffer
, "false"))
364 _cupsLangPrintf(stderr
,
365 _("ppdc: Bad boolean value (%s) on line %d of %s."),
366 buffer
, fp
->line
, fp
->filename
);
373 // 'ppdcSource::get_choice()' - Get a choice.
376 ppdcChoice
* // O - Choice data
377 ppdcSource::get_choice(ppdcFile
*fp
) // I - File to read
379 char name
[1024], // Name
384 // Read a choice from the file:
386 // Choice name/text code
387 if (!get_token(fp
, name
, sizeof(name
)))
389 _cupsLangPrintf(stderr
,
390 _("ppdc: Expected choice name/text on line %d of %s."),
391 fp
->line
, fp
->filename
);
395 if ((text
= strchr(name
, '/')) != NULL
)
400 if (!get_token(fp
, code
, sizeof(code
)))
402 _cupsLangPrintf(stderr
, _("ppdc: Expected choice code on line %d of %s."),
403 fp
->line
, fp
->filename
);
407 // Return the new choice
408 return (new ppdcChoice(name
, text
, code
));
413 // 'ppdcSource::get_color_model()' - Get an old-style color model option.
416 ppdcChoice
* // O - Choice data
417 ppdcSource::get_color_model(ppdcFile
*fp
)
420 char name
[1024], // Option name
421 *text
, // Text option
422 temp
[256]; // Temporary string
423 int color_space
, // Colorspace
424 color_order
, // Color order
425 compression
; // Compression mode
428 // Get the ColorModel parameters:
430 // ColorModel name/text colorspace colororder compression
431 if (!get_token(fp
, name
, sizeof(name
)))
433 _cupsLangPrintf(stderr
,
434 _("ppdc: Expected name/text combination for ColorModel on "
435 "line %d of %s."), fp
->line
, fp
->filename
);
439 if ((text
= strchr(name
, '/')) != NULL
)
444 if (!get_token(fp
, temp
, sizeof(temp
)))
446 _cupsLangPrintf(stderr
,
447 _("ppdc: Expected colorspace for ColorModel on line %d of "
448 "%s."), fp
->line
, fp
->filename
);
452 if ((color_space
= get_color_space(temp
)) < 0)
453 color_space
= get_integer(temp
);
455 if (!get_token(fp
, temp
, sizeof(temp
)))
457 _cupsLangPrintf(stderr
,
458 _("ppdc: Expected color order for ColorModel on line %d of "
459 "%s."), fp
->line
, fp
->filename
);
463 if ((color_order
= get_color_order(temp
)) < 0)
464 color_order
= get_integer(temp
);
466 if (!get_token(fp
, temp
, sizeof(temp
)))
468 _cupsLangPrintf(stderr
,
469 _("ppdc: Expected compression for ColorModel on line %d of "
470 "%s."), fp
->line
, fp
->filename
);
474 compression
= get_integer(temp
);
476 snprintf(temp
, sizeof(temp
),
477 "<</cupsColorSpace %d/cupsColorOrder %d/cupsCompression %d>>"
479 color_space
, color_order
, compression
);
481 return (new ppdcChoice(name
, text
, temp
));
486 // 'ppdcSource::get_color_order()' - Get an old-style color order value.
489 int // O - Color order value
490 ppdcSource::get_color_order(
491 const char *co
) // I - Color order string
493 if (!_cups_strcasecmp(co
, "chunked") ||
494 !_cups_strcasecmp(co
, "chunky"))
495 return (CUPS_ORDER_CHUNKED
);
496 else if (!_cups_strcasecmp(co
, "banded"))
497 return (CUPS_ORDER_BANDED
);
498 else if (!_cups_strcasecmp(co
, "planar"))
499 return (CUPS_ORDER_PLANAR
);
506 // 'ppdcSource::get_color_profile()' - Get a color profile definition.
509 ppdcProfile
* // O - Color profile
510 ppdcSource::get_color_profile(
511 ppdcFile
*fp
) // I - File to read
513 char resolution
[1024], // Resolution/media type
514 *media_type
; // Media type
515 int i
; // Looping var
516 float g
, // Gamma value
518 m
[9]; // Transform matrix
521 // Get the ColorProfile parameters:
523 // ColorProfile resolution/mediatype gamma density m00 m01 m02 ... m22
524 if (!get_token(fp
, resolution
, sizeof(resolution
)))
526 _cupsLangPrintf(stderr
,
527 _("ppdc: Expected resolution/mediatype following "
528 "ColorProfile on line %d of %s."),
529 fp
->line
, fp
->filename
);
533 if ((media_type
= strchr(resolution
, '/')) != NULL
)
534 *media_type
++ = '\0';
536 media_type
= resolution
;
540 for (i
= 0; i
< 9; i
++)
541 m
[i
] = get_float(fp
);
543 return (new ppdcProfile(resolution
, media_type
, g
, d
, m
));
548 // 'ppdcSource::get_color_space()' - Get an old-style colorspace value.
551 int // O - Colorspace value
552 ppdcSource::get_color_space(
553 const char *cs
) // I - Colorspace string
555 if (!_cups_strcasecmp(cs
, "w"))
556 return (CUPS_CSPACE_W
);
557 else if (!_cups_strcasecmp(cs
, "rgb"))
558 return (CUPS_CSPACE_RGB
);
559 else if (!_cups_strcasecmp(cs
, "rgba"))
560 return (CUPS_CSPACE_RGBA
);
561 else if (!_cups_strcasecmp(cs
, "k"))
562 return (CUPS_CSPACE_K
);
563 else if (!_cups_strcasecmp(cs
, "cmy"))
564 return (CUPS_CSPACE_CMY
);
565 else if (!_cups_strcasecmp(cs
, "ymc"))
566 return (CUPS_CSPACE_YMC
);
567 else if (!_cups_strcasecmp(cs
, "cmyk"))
568 return (CUPS_CSPACE_CMYK
);
569 else if (!_cups_strcasecmp(cs
, "ymck"))
570 return (CUPS_CSPACE_YMCK
);
571 else if (!_cups_strcasecmp(cs
, "kcmy"))
572 return (CUPS_CSPACE_KCMY
);
573 else if (!_cups_strcasecmp(cs
, "kcmycm"))
574 return (CUPS_CSPACE_KCMYcm
);
575 else if (!_cups_strcasecmp(cs
, "gmck"))
576 return (CUPS_CSPACE_GMCK
);
577 else if (!_cups_strcasecmp(cs
, "gmcs"))
578 return (CUPS_CSPACE_GMCS
);
579 else if (!_cups_strcasecmp(cs
, "white"))
580 return (CUPS_CSPACE_WHITE
);
581 else if (!_cups_strcasecmp(cs
, "gold"))
582 return (CUPS_CSPACE_GOLD
);
583 else if (!_cups_strcasecmp(cs
, "silver"))
584 return (CUPS_CSPACE_SILVER
);
585 else if (!_cups_strcasecmp(cs
, "CIEXYZ"))
586 return (CUPS_CSPACE_CIEXYZ
);
587 else if (!_cups_strcasecmp(cs
, "CIELab"))
588 return (CUPS_CSPACE_CIELab
);
589 else if (!_cups_strcasecmp(cs
, "RGBW"))
590 return (CUPS_CSPACE_RGBW
);
591 else if (!_cups_strcasecmp(cs
, "ICC1"))
592 return (CUPS_CSPACE_ICC1
);
593 else if (!_cups_strcasecmp(cs
, "ICC2"))
594 return (CUPS_CSPACE_ICC2
);
595 else if (!_cups_strcasecmp(cs
, "ICC3"))
596 return (CUPS_CSPACE_ICC3
);
597 else if (!_cups_strcasecmp(cs
, "ICC4"))
598 return (CUPS_CSPACE_ICC4
);
599 else if (!_cups_strcasecmp(cs
, "ICC5"))
600 return (CUPS_CSPACE_ICC5
);
601 else if (!_cups_strcasecmp(cs
, "ICC6"))
602 return (CUPS_CSPACE_ICC6
);
603 else if (!_cups_strcasecmp(cs
, "ICC7"))
604 return (CUPS_CSPACE_ICC7
);
605 else if (!_cups_strcasecmp(cs
, "ICC8"))
606 return (CUPS_CSPACE_ICC8
);
607 else if (!_cups_strcasecmp(cs
, "ICC9"))
608 return (CUPS_CSPACE_ICC9
);
609 else if (!_cups_strcasecmp(cs
, "ICCA"))
610 return (CUPS_CSPACE_ICCA
);
611 else if (!_cups_strcasecmp(cs
, "ICCB"))
612 return (CUPS_CSPACE_ICCB
);
613 else if (!_cups_strcasecmp(cs
, "ICCC"))
614 return (CUPS_CSPACE_ICCC
);
615 else if (!_cups_strcasecmp(cs
, "ICCD"))
616 return (CUPS_CSPACE_ICCD
);
617 else if (!_cups_strcasecmp(cs
, "ICCE"))
618 return (CUPS_CSPACE_ICCE
);
619 else if (!_cups_strcasecmp(cs
, "ICCF"))
620 return (CUPS_CSPACE_ICCF
);
627 // 'ppdcSource::get_constraint()' - Get a constraint.
630 ppdcConstraint
* // O - Constraint
631 ppdcSource::get_constraint(ppdcFile
*fp
)// I - File to read
633 char temp
[1024], // One string to rule them all
634 *ptr
, // Pointer into string
635 *option1
, // Constraint option 1
636 *choice1
, // Constraint choice 1
637 *option2
, // Constraint option 2
638 *choice2
; // Constraint choice 2
641 // Read the UIConstaints parameter in one of the following forms:
643 // UIConstraints "*Option1 *Option2"
644 // UIConstraints "*Option1 Choice1 *Option2"
645 // UIConstraints "*Option1 *Option2 Choice2"
646 // UIConstraints "*Option1 Choice1 *Option2 Choice2"
647 if (!get_token(fp
, temp
, sizeof(temp
)))
649 _cupsLangPrintf(stderr
,
650 _("ppdc: Expected constraints string for UIConstraints on "
651 "line %d of %s."), fp
->line
, fp
->filename
);
655 for (ptr
= temp
; isspace(*ptr
); ptr
++);
659 _cupsLangPrintf(stderr
,
660 _("ppdc: Option constraint must *name on line %d of %s."),
661 fp
->line
, fp
->filename
);
667 for (; *ptr
&& !isspace(*ptr
); ptr
++);
668 for (; isspace(*ptr
); *ptr
++ = '\0');
674 for (; *ptr
&& !isspace(*ptr
); ptr
++);
675 for (; isspace(*ptr
); *ptr
++ = '\0');
682 _cupsLangPrintf(stderr
,
683 _("ppdc: Expected two option names on line %d of %s."),
684 fp
->line
, fp
->filename
);
690 for (; *ptr
&& !isspace(*ptr
); ptr
++);
691 for (; isspace(*ptr
); *ptr
++ = '\0');
698 return (new ppdcConstraint(option1
, choice1
, option2
, choice2
));
703 // 'ppdcSource::get_custom_size()' - Get a custom media size definition from a file.
706 ppdcMediaSize
* // O - Media size
707 ppdcSource::get_custom_size(ppdcFile
*fp
)
710 char name
[1024], // Name
712 size_code
[10240], // PageSize code
713 region_code
[10240]; // PageRegion
714 float width
, // Width
717 bottom
, // Bottom margin
718 right
, // Right margin
722 // Get the name, text, width, length, margins, and code:
724 // CustomMedia name/text width length left bottom right top size-code region-code
725 if (!get_token(fp
, name
, sizeof(name
)))
728 if ((text
= strchr(name
, '/')) != NULL
)
733 if ((width
= get_measurement(fp
)) < 0.0f
)
736 if ((length
= get_measurement(fp
)) < 0.0f
)
739 if ((left
= get_measurement(fp
)) < 0.0f
)
742 if ((bottom
= get_measurement(fp
)) < 0.0f
)
745 if ((right
= get_measurement(fp
)) < 0.0f
)
748 if ((top
= get_measurement(fp
)) < 0.0f
)
751 if (!get_token(fp
, size_code
, sizeof(size_code
)))
754 if (!get_token(fp
, region_code
, sizeof(region_code
)))
757 // Return the new media size...
758 return (new ppdcMediaSize(name
, text
, width
, length
, left
, bottom
,
759 right
, top
, size_code
, region_code
));
764 // 'ppdcSource::get_duplex()' - Get a duplex option.
768 ppdcSource::get_duplex(ppdcFile
*fp
, // I - File to read from
769 ppdcDriver
*d
) // I - Current driver
771 char temp
[256]; // Duplex keyword
772 ppdcAttr
*attr
; // cupsFlipDuplex attribute
773 ppdcGroup
*g
; // Current group
774 ppdcOption
*o
; // Duplex option
777 // Duplex {boolean|none|normal|flip}
778 if (!get_token(fp
, temp
, sizeof(temp
)))
780 _cupsLangPrintf(stderr
,
781 _("ppdc: Expected duplex type after Duplex on line %d of "
782 "%s."), fp
->line
, fp
->filename
);
789 if (!_cups_strcasecmp(temp
, "none") || !_cups_strcasecmp(temp
, "false") ||
790 !_cups_strcasecmp(temp
, "no") || !_cups_strcasecmp(temp
, "off"))
792 g
= d
->find_group("General");
793 if ((o
= g
->find_option("Duplex")) != NULL
)
794 g
->options
->remove(o
);
796 for (attr
= (ppdcAttr
*)d
->attrs
->first();
798 attr
= (ppdcAttr
*)d
->attrs
->next())
799 if (!strcmp(attr
->name
->value
, "cupsFlipDuplex"))
801 d
->attrs
->remove(attr
);
805 else if (!_cups_strcasecmp(temp
, "normal") || !_cups_strcasecmp(temp
, "true") ||
806 !_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "on") ||
807 !_cups_strcasecmp(temp
, "flip") || !_cups_strcasecmp(temp
, "rotated") ||
808 !_cups_strcasecmp(temp
, "manualtumble"))
810 g
= d
->find_group("General");
811 o
= g
->find_option("Duplex");
815 o
= new ppdcOption(PPDC_PICKONE
, "Duplex", "2-Sided Printing",
816 !_cups_strcasecmp(temp
, "flip") ? PPDC_SECTION_PAGE
:
817 PPDC_SECTION_ANY
, 10.0f
);
818 o
->add_choice(new ppdcChoice("None", "Off (1-Sided)",
819 "<</Duplex false>>setpagedevice"));
820 o
->add_choice(new ppdcChoice("DuplexNoTumble", "Long-Edge (Portrait)",
821 "<</Duplex true/Tumble false>>setpagedevice"));
822 o
->add_choice(new ppdcChoice("DuplexTumble", "Short-Edge (Landscape)",
823 "<</Duplex true/Tumble true>>setpagedevice"));
828 for (attr
= (ppdcAttr
*)d
->attrs
->first();
830 attr
= (ppdcAttr
*)d
->attrs
->next())
831 if (!strcmp(attr
->name
->value
, "cupsFlipDuplex"))
833 if (_cups_strcasecmp(temp
, "flip"))
834 d
->attrs
->remove(attr
);
838 if (!_cups_strcasecmp(temp
, "flip") && !attr
)
839 d
->add_attr(new ppdcAttr("cupsFlipDuplex", NULL
, NULL
, "true"));
841 for (attr
= (ppdcAttr
*)d
->attrs
->first();
843 attr
= (ppdcAttr
*)d
->attrs
->next())
844 if (!strcmp(attr
->name
->value
, "cupsBackSide"))
846 d
->attrs
->remove(attr
);
850 if (!_cups_strcasecmp(temp
, "flip"))
851 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Flipped"));
852 else if (!_cups_strcasecmp(temp
, "rotated"))
853 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Rotated"));
854 else if (!_cups_strcasecmp(temp
, "manualtumble"))
855 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "ManualTumble"));
857 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Normal"));
860 _cupsLangPrintf(stderr
,
861 _("ppdc: Unknown duplex type \"%s\" on line %d of %s."),
862 temp
, fp
->line
, fp
->filename
);
867 // 'ppdcSource::get_filter()' - Get a filter.
870 ppdcFilter
* // O - Filter
871 ppdcSource::get_filter(ppdcFile
*fp
) // I - File to read
873 char type
[1024], // MIME type
874 program
[1024], // Filter program
875 *ptr
; // Pointer into MIME type
876 int cost
; // Relative cost
879 // Read filter parameters in one of the following formats:
881 // Filter "type cost program"
882 // Filter type cost program
884 if (!get_token(fp
, type
, sizeof(type
)))
886 _cupsLangPrintf(stderr
,
887 _("ppdc: Expected a filter definition on line %d of %s."),
888 fp
->line
, fp
->filename
);
892 if ((ptr
= strchr(type
, ' ')) != NULL
)
894 // Old-style filter definition in one string...
896 cost
= strtol(ptr
, &ptr
, 10);
898 while (isspace(*ptr
))
901 strlcpy(program
, ptr
, sizeof(program
));
905 cost
= get_integer(fp
);
907 if (!get_token(fp
, program
, sizeof(program
)))
909 _cupsLangPrintf(stderr
,
910 _("ppdc: Expected a program name on line %d of %s."),
911 fp
->line
, fp
->filename
);
918 _cupsLangPrintf(stderr
,
919 _("ppdc: Invalid empty MIME type for filter on line %d of "
920 "%s."), fp
->line
, fp
->filename
);
924 if (cost
< 0 || cost
> 200)
926 _cupsLangPrintf(stderr
,
927 _("ppdc: Invalid cost for filter on line %d of %s."),
928 fp
->line
, fp
->filename
);
934 _cupsLangPrintf(stderr
,
935 _("ppdc: Invalid empty program name for filter on line %d "
936 "of %s."), fp
->line
, fp
->filename
);
940 return (new ppdcFilter(type
, program
, cost
));
945 // 'ppdcSource::get_float()' - Get a single floating-point number.
949 ppdcSource::get_float(ppdcFile
*fp
) // I - File to read
951 char temp
[256], // String buffer
952 *ptr
; // Pointer into buffer
953 float val
; // Floating point value
956 // Get the number from the file and range-check...
957 if (!get_token(fp
, temp
, sizeof(temp
)))
959 _cupsLangPrintf(stderr
, _("ppdc: Expected real number on line %d of %s."),
960 fp
->line
, fp
->filename
);
964 val
= (float)strtod(temp
, &ptr
);
968 _cupsLangPrintf(stderr
,
969 _("ppdc: Unknown trailing characters in real number \"%s\" "
970 "on line %d of %s."), temp
, fp
->line
, fp
->filename
);
979 // 'ppdcSource::get_font()' - Get a font definition.
982 ppdcFont
* // O - Font data
983 ppdcSource::get_font(ppdcFile
*fp
) // I - File to read
985 char name
[256], // Font name
986 encoding
[256], // Font encoding
987 version
[256], // Font version
988 charset
[256], // Font charset
989 temp
[256]; // Font status string
990 ppdcFontStatus status
; // Font status enumeration
993 // Read font parameters as follows:
996 // Font name encoding version charset status
997 // %font name encoding version charset status
999 // "Name" is the PostScript font name.
1001 // "Encoding" is the default encoding of the font: Standard, ISOLatin1,
1002 // Special, Expert, ExpertSubset, etc.
1004 // "Version" is the version number string.
1006 // "Charset" specifies the characters that are included in the font:
1007 // Standard, Special, Expert, Adobe-Identity, etc.
1009 // "Status" is the keyword ROM or Disk.
1010 if (!get_token(fp
, name
, sizeof(name
)))
1012 _cupsLangPrintf(stderr
,
1013 _("ppdc: Expected name after Font on line %d of %s."),
1014 fp
->line
, fp
->filename
);
1018 if (!strcmp(name
, "*"))
1020 // Include all base fonts...
1024 status
= PPDC_FONT_ROM
;
1028 // Load a full font definition...
1029 if (!get_token(fp
, encoding
, sizeof(encoding
)))
1031 _cupsLangPrintf(stderr
,
1032 _("ppdc: Expected encoding after Font on line %d of "
1033 "%s."), fp
->line
, fp
->filename
);
1037 if (!get_token(fp
, version
, sizeof(version
)))
1039 _cupsLangPrintf(stderr
,
1040 _("ppdc: Expected version after Font on line %d of "
1041 "%s."), fp
->line
, fp
->filename
);
1045 if (!get_token(fp
, charset
, sizeof(charset
)))
1047 _cupsLangPrintf(stderr
,
1048 _("ppdc: Expected charset after Font on line %d of "
1049 "%s."), fp
->line
, fp
->filename
);
1053 if (!get_token(fp
, temp
, sizeof(temp
)))
1055 _cupsLangPrintf(stderr
,
1056 _("ppdc: Expected status after Font on line %d of %s."),
1057 fp
->line
, fp
->filename
);
1061 if (!_cups_strcasecmp(temp
, "ROM"))
1062 status
= PPDC_FONT_ROM
;
1063 else if (!_cups_strcasecmp(temp
, "Disk"))
1064 status
= PPDC_FONT_DISK
;
1067 _cupsLangPrintf(stderr
,
1068 _("ppdc: Bad status keyword %s on line %d of %s."),
1069 temp
, fp
->line
, fp
->filename
);
1074 // printf("Font %s %s %s %s %s\n", name, encoding, version, charset, temp);
1076 return (new ppdcFont(name
, encoding
, version
, charset
, status
));
1081 // 'ppdcSource::get_generic()' - Get a generic old-style option.
1084 ppdcChoice
* // O - Choice data
1085 ppdcSource::get_generic(ppdcFile
*fp
, // I - File to read
1086 const char *keyword
,
1089 // I - Text attribute
1091 // I - Numeric attribute
1093 char name
[1024], // Name
1095 command
[256]; // Command string
1096 int val
; // Numeric value
1099 // Read one of the following parameters:
1102 // Foo integer name/text
1104 val
= get_integer(fp
);
1108 if (!get_token(fp
, name
, sizeof(name
)))
1110 _cupsLangPrintf(stderr
,
1111 _("ppdc: Expected name/text after %s on line %d of %s."),
1112 keyword
, fp
->line
, fp
->filename
);
1116 if ((text
= strchr(name
, '/')) != NULL
)
1124 snprintf(command
, sizeof(command
),
1125 "<</%s(%s)/%s %d>>setpagedevice",
1126 tattr
, name
, nattr
, val
);
1128 snprintf(command
, sizeof(command
),
1129 "<</%s %d>>setpagedevice",
1133 snprintf(command
, sizeof(command
),
1134 "<</%s(%s)>>setpagedevice",
1137 return (new ppdcChoice(name
, text
, command
));
1142 // 'ppdcSource::get_group()' - Get an option group.
1145 ppdcGroup
* // O - Group
1146 ppdcSource::get_group(ppdcFile
*fp
, // I - File to read
1147 ppdcDriver
*d
) // I - Printer driver
1149 char name
[1024], // UI name
1151 ppdcGroup
*g
; // Group
1154 // Read the Group parameters:
1157 if (!get_token(fp
, name
, sizeof(name
)))
1159 _cupsLangPrintf(stderr
,
1160 _("ppdc: Expected group name/text on line %d of %s."),
1161 fp
->line
, fp
->filename
);
1165 if ((text
= strchr(name
, '/')) != NULL
)
1170 // See if the group already exists...
1171 if ((g
= d
->find_group(name
)) == NULL
)
1173 // Nope, add a new one...
1174 g
= new ppdcGroup(name
, text
);
1182 // 'ppdcSource::get_installable()' - Get an installable option.
1185 ppdcOption
* // O - Option
1186 ppdcSource::get_installable(ppdcFile
*fp
)
1189 char name
[1024], // Name for installable option
1190 *text
; // Text for installable option
1191 ppdcOption
*o
; // Option
1194 // Read the parameter for an installable option:
1196 // Installable name/text
1197 if (!get_token(fp
, name
, sizeof(name
)))
1199 _cupsLangPrintf(stderr
,
1200 _("ppdc: Expected name/text after Installable on line %d "
1201 "of %s."), fp
->line
, fp
->filename
);
1205 if ((text
= strchr(name
, '/')) != NULL
)
1210 // Create the option...
1211 o
= new ppdcOption(PPDC_BOOLEAN
, name
, text
, PPDC_SECTION_ANY
, 10.0f
);
1213 // Add the false and true choices...
1214 o
->add_choice(new ppdcChoice("False", "Not Installed", ""));
1215 o
->add_choice(new ppdcChoice("True", "Installed", ""));
1222 // 'ppdcSource::get_integer()' - Get an integer value from a string.
1225 #define PPDC_XX -1 // Bad
1226 #define PPDC_EQ 0 // ==
1227 #define PPDC_NE 1 // !=
1228 #define PPDC_LT 2 // <
1229 #define PPDC_LE 3 // <=
1230 #define PPDC_GT 4 // >
1231 #define PPDC_GE 5 // >=
1233 int // O - Integer value
1234 ppdcSource::get_integer(const char *v
) // I - Value string
1237 long temp
, // Temporary value
1238 temp2
; // Second temporary value
1239 char *newv
, // New value string pointer
1240 ch
; // Temporary character
1241 ppdcVariable
*var
; // #define variable
1242 int compop
; // Comparison operator
1245 // Parse the value string...
1249 if (isdigit(*v
& 255) || *v
== '-' || *v
== '+')
1251 // Return a simple integer value
1252 val
= strtol(v
, (char **)&v
, 0);
1253 if (*v
|| val
== LONG_MIN
)
1260 // Evaluate and expression in any of the following formats:
1262 // (number number ... number) Bitwise OR of all numbers
1263 // (NAME == value) 1 if equal, 0 otherwise
1264 // (NAME != value) 1 if not equal, 0 otherwise
1265 // (NAME < value) 1 if less than, 0 otherwise
1266 // (NAME <= value) 1 if less than or equal, 0 otherwise
1267 // (NAME > value) 1 if greater than, 0 otherwise
1268 // (NAME >= value) 1 if greater than or equal, 0 otherwise
1273 while (*v
&& *v
!= ')')
1275 // Skip leading whitespace...
1276 while (*v
&& isspace(*v
& 255))
1279 if (!*v
|| *v
== ')')
1282 if (isdigit(*v
& 255) || *v
== '-' || *v
== '+')
1284 // Bitwise OR a number...
1285 temp
= strtol(v
, &newv
, 0);
1287 if (!*newv
|| newv
== v
|| !(isspace(*newv
) || *newv
== ')') ||
1293 // NAME logicop value
1294 for (newv
= (char *)v
+ 1;
1295 *newv
&& (isalnum(*newv
& 255) || *newv
== '_');
1302 if ((var
= find_variable(v
)) != NULL
)
1304 if (!var
->value
|| !var
->value
->value
|| !var
->value
->value
[0])
1306 else if (isdigit(var
->value
->value
[0] & 255) ||
1307 var
->value
->value
[0] == '-' ||
1308 var
->value
->value
[0] == '+')
1309 temp
= strtol(var
->value
->value
, NULL
, 0);
1317 while (isspace(*newv
& 255))
1320 if (!strncmp(newv
, "==", 2))
1325 else if (!strncmp(newv
, "!=", 2))
1330 else if (!strncmp(newv
, "<=", 2))
1335 else if (*newv
== '<')
1340 else if (!strncmp(newv
, ">=", 2))
1345 else if (*newv
== '>')
1353 if (compop
!= PPDC_XX
)
1355 while (isspace(*newv
& 255))
1358 if (*newv
== ')' || !*newv
)
1361 if (isdigit(*newv
& 255) || *newv
== '-' || *newv
== '+')
1363 // Get the second number...
1364 temp2
= strtol(newv
, &newv
, 0);
1365 if (!*newv
|| newv
== v
|| !(isspace(*newv
) || *newv
== ')') ||
1371 // Lookup the second name...
1372 for (v
= newv
, newv
++;
1373 *newv
&& (isalnum(*newv
& 255) || *newv
== '_');
1379 if ((var
= find_variable(v
)) != NULL
)
1381 if (!var
->value
|| !var
->value
->value
|| !var
->value
->value
[0])
1383 else if (isdigit(var
->value
->value
[0] & 255) ||
1384 var
->value
->value
[0] == '-' ||
1385 var
->value
->value
[0] == '+')
1386 temp2
= strtol(var
->value
->value
, NULL
, 0);
1396 // Do the comparison...
1400 temp
= temp
== temp2
;
1403 temp
= temp
!= temp2
;
1406 temp
= temp
< temp2
;
1409 temp
= temp
<= temp2
;
1412 temp
= temp
> temp2
;
1415 temp
= temp
>= temp2
;
1425 if (*v
== ')' && !v
[1])
1430 else if ((var
= find_variable(v
)) != NULL
)
1432 // NAME by itself returns 1 if the #define variable is not blank and
1434 return (var
->value
->value
&& var
->value
->value
[0] &&
1435 strcmp(var
->value
->value
, "0"));
1439 // Anything else is an error...
1446 // 'ppdcSource::get_integer()' - Get an integer value from a file.
1449 int // O - Integer value
1450 ppdcSource::get_integer(ppdcFile
*fp
) // I - File to read
1452 char temp
[1024]; // String buffer
1455 if (!get_token(fp
, temp
, sizeof(temp
)))
1457 _cupsLangPrintf(stderr
, _("ppdc: Expected integer on line %d of %s."),
1458 fp
->line
, fp
->filename
);
1462 return (get_integer(temp
));
1467 // 'ppdcSource::get_measurement()' - Get a measurement value.
1470 float // O - Measurement value in points
1471 ppdcSource::get_measurement(ppdcFile
*fp
)
1474 char buffer
[256], // Number buffer
1475 *ptr
; // Pointer into buffer
1476 float val
; // Measurement value
1479 // Grab a token from the file...
1480 if (!get_token(fp
, buffer
, sizeof(buffer
)))
1483 // Get the floating point value of "s" and skip all digits and decimal points.
1484 val
= (float)strtod(buffer
, &ptr
);
1486 // Check for a trailing unit specifier...
1487 if (!_cups_strcasecmp(ptr
, "mm"))
1488 val
*= 72.0f
/ 25.4f
;
1489 else if (!_cups_strcasecmp(ptr
, "cm"))
1490 val
*= 72.0f
/ 2.54f
;
1491 else if (!_cups_strcasecmp(ptr
, "m"))
1492 val
*= 72.0f
/ 0.0254f
;
1493 else if (!_cups_strcasecmp(ptr
, "in"))
1495 else if (!_cups_strcasecmp(ptr
, "ft"))
1496 val
*= 72.0f
* 12.0f
;
1497 else if (_cups_strcasecmp(ptr
, "pt") && *ptr
)
1505 // 'ppdcSource::get_option()' - Get an option definition.
1508 ppdcOption
* // O - Option
1509 ppdcSource::get_option(ppdcFile
*fp
, // I - File to read
1510 ppdcDriver
*d
, // I - Printer driver
1511 ppdcGroup
*g
) // I - Current group
1513 char name
[1024], // UI name
1515 type
[256]; // UI type string
1516 ppdcOptType ot
; // Option type value
1517 ppdcOptSection section
; // Option section
1518 float order
; // Option order
1519 ppdcOption
*o
; // Option
1520 ppdcGroup
*mg
; // Matching group, if any
1523 // Read the Option parameters:
1525 // Option name/text type section order
1526 if (!get_token(fp
, name
, sizeof(name
)))
1528 _cupsLangPrintf(stderr
,
1529 _("ppdc: Expected option name/text on line %d of %s."),
1530 fp
->line
, fp
->filename
);
1534 if ((text
= strchr(name
, '/')) != NULL
)
1539 if (!get_token(fp
, type
, sizeof(type
)))
1541 _cupsLangPrintf(stderr
, _("ppdc: Expected option type on line %d of %s."),
1542 fp
->line
, fp
->filename
);
1546 if (!_cups_strcasecmp(type
, "boolean"))
1548 else if (!_cups_strcasecmp(type
, "pickone"))
1550 else if (!_cups_strcasecmp(type
, "pickmany"))
1554 _cupsLangPrintf(stderr
,
1555 _("ppdc: Invalid option type \"%s\" on line %d of %s."),
1556 type
, fp
->line
, fp
->filename
);
1560 if (!get_token(fp
, type
, sizeof(type
)))
1562 _cupsLangPrintf(stderr
,
1563 _("ppdc: Expected option section on line %d of %s."),
1564 fp
->line
, fp
->filename
);
1568 if (!_cups_strcasecmp(type
, "AnySetup"))
1569 section
= PPDC_SECTION_ANY
;
1570 else if (!_cups_strcasecmp(type
, "DocumentSetup"))
1571 section
= PPDC_SECTION_DOCUMENT
;
1572 else if (!_cups_strcasecmp(type
, "ExitServer"))
1573 section
= PPDC_SECTION_EXIT
;
1574 else if (!_cups_strcasecmp(type
, "JCLSetup"))
1575 section
= PPDC_SECTION_JCL
;
1576 else if (!_cups_strcasecmp(type
, "PageSetup"))
1577 section
= PPDC_SECTION_PAGE
;
1578 else if (!_cups_strcasecmp(type
, "Prolog"))
1579 section
= PPDC_SECTION_PROLOG
;
1582 _cupsLangPrintf(stderr
,
1583 _("ppdc: Invalid option section \"%s\" on line %d of "
1584 "%s."), type
, fp
->line
, fp
->filename
);
1588 order
= get_float(fp
);
1590 // See if the option already exists...
1591 if ((o
= d
->find_option_group(name
, &mg
)) == NULL
)
1593 // Nope, add a new one...
1594 o
= new ppdcOption(ot
, name
, text
, section
, order
);
1596 else if (o
->type
!= ot
)
1598 _cupsLangPrintf(stderr
,
1599 _("ppdc: Option %s redefined with a different type on line "
1600 "%d of %s."), name
, fp
->line
, fp
->filename
);
1605 _cupsLangPrintf(stderr
,
1606 _("ppdc: Option %s defined in two different groups on line "
1607 "%d of %s."), name
, fp
->line
, fp
->filename
);
1616 // 'ppdcSource::get_po()' - Get a message catalog.
1619 ppdcCatalog
* // O - Message catalog
1620 ppdcSource::get_po(ppdcFile
*fp
) // I - File to read
1622 char locale
[32], // Locale name
1623 poname
[1024], // Message catalog filename
1624 basedir
[1024], // Base directory
1625 *baseptr
, // Pointer into directory
1626 pofilename
[1024]; // Full filename of message catalog
1627 ppdcCatalog
*cat
; // Message catalog
1630 // Read the #po parameters:
1632 // #po locale "filename.po"
1633 if (!get_token(fp
, locale
, sizeof(locale
)))
1635 _cupsLangPrintf(stderr
,
1636 _("ppdc: Expected locale after #po on line %d of %s."),
1637 fp
->line
, fp
->filename
);
1641 if (!get_token(fp
, poname
, sizeof(poname
)))
1643 _cupsLangPrintf(stderr
,
1644 _("ppdc: Expected filename after #po %s on line %d of "
1645 "%s."), locale
, fp
->line
, fp
->filename
);
1649 // See if the locale is already loaded...
1650 if (find_po(locale
))
1652 _cupsLangPrintf(stderr
,
1653 _("ppdc: Duplicate #po for locale %s on line %d of %s."),
1654 locale
, fp
->line
, fp
->filename
);
1658 // Figure out the current directory...
1659 strlcpy(basedir
, fp
->filename
, sizeof(basedir
));
1661 if ((baseptr
= strrchr(basedir
, '/')) != NULL
)
1664 strlcpy(basedir
, ".", sizeof(basedir
));
1666 // Find the po file...
1667 pofilename
[0] = '\0';
1670 find_include(poname
, basedir
, pofilename
, sizeof(pofilename
)))
1672 // Found it, so load it...
1673 cat
= new ppdcCatalog(locale
, pofilename
);
1675 // Reset the filename to the name supplied by the user...
1676 cat
->filename
->release();
1677 cat
->filename
= new ppdcString(poname
);
1679 // Return the catalog...
1684 _cupsLangPrintf(stderr
,
1685 _("ppdc: Unable to find #po file %s on line %d of %s."),
1686 poname
, fp
->line
, fp
->filename
);
1693 // 'ppdcSource::get_resolution()' - Get an old-style resolution option.
1696 ppdcChoice
* // O - Choice data
1697 ppdcSource::get_resolution(ppdcFile
*fp
)// I - File to read
1699 char name
[1024], // Name
1701 temp
[256], // Temporary string
1702 command
[256], // Command string
1703 *commptr
; // Pointer into command
1704 int xdpi
, ydpi
, // X + Y resolution
1705 color_order
, // Color order
1706 color_space
, // Colorspace
1707 compression
, // Compression mode
1708 depth
, // Bits per color
1709 row_count
, // Row count
1710 row_feed
, // Row feed
1711 row_step
; // Row step/interval
1714 // Read the resolution parameters:
1716 // Resolution colorspace bits row-count row-feed row-step name/text
1717 if (!get_token(fp
, temp
, sizeof(temp
)))
1719 _cupsLangPrintf(stderr
,
1720 _("ppdc: Expected override field after Resolution on line "
1721 "%d of %s."), fp
->line
, fp
->filename
);
1725 color_order
= get_color_order(temp
);
1726 color_space
= get_color_space(temp
);
1727 compression
= get_integer(temp
);
1729 depth
= get_integer(fp
);
1730 row_count
= get_integer(fp
);
1731 row_feed
= get_integer(fp
);
1732 row_step
= get_integer(fp
);
1734 if (!get_token(fp
, name
, sizeof(name
)))
1736 _cupsLangPrintf(stderr
,
1737 _("ppdc: Expected name/text after Resolution on line %d of "
1738 "%s."), fp
->line
, fp
->filename
);
1742 if ((text
= strchr(name
, '/')) != NULL
)
1747 switch (sscanf(name
, "%dx%d", &xdpi
, &ydpi
))
1750 _cupsLangPrintf(stderr
,
1751 _("ppdc: Bad resolution name \"%s\" on line %d of "
1752 "%s."), name
, fp
->line
, fp
->filename
);
1759 // Create the necessary PS commands...
1760 snprintf(command
, sizeof(command
),
1761 "<</HWResolution[%d %d]/cupsBitsPerColor %d/cupsRowCount %d"
1762 "/cupsRowFeed %d/cupsRowStep %d",
1763 xdpi
, ydpi
, depth
, row_count
, row_feed
, row_step
);
1764 commptr
= command
+ strlen(command
);
1766 if (color_order
>= 0)
1768 snprintf(commptr
, sizeof(command
) - (size_t)(commptr
- command
),
1769 "/cupsColorOrder %d", color_order
);
1770 commptr
+= strlen(commptr
);
1773 if (color_space
>= 0)
1775 snprintf(commptr
, sizeof(command
) - (size_t)(commptr
- command
),
1776 "/cupsColorSpace %d", color_space
);
1777 commptr
+= strlen(commptr
);
1780 if (compression
>= 0)
1782 snprintf(commptr
, sizeof(command
) - (size_t)(commptr
- command
),
1783 "/cupsCompression %d", compression
);
1784 commptr
+= strlen(commptr
);
1787 snprintf(commptr
, sizeof(command
) - (size_t)(commptr
- command
), ">>setpagedevice");
1789 // Return the new choice...
1790 return (new ppdcChoice(name
, text
, command
));
1795 // 'ppdcSource::get_simple_profile()' - Get a simple color profile definition.
1798 ppdcProfile
* // O - Color profile
1799 ppdcSource::get_simple_profile(ppdcFile
*fp
)
1802 char resolution
[1024], // Resolution/media type
1803 *media_type
; // Media type
1804 float m
[9]; // Transform matrix
1805 float kd
, rd
, g
; // Densities and gamma
1806 float red
, green
, blue
; // RGB adjustments
1807 float yellow
; // Yellow density
1808 float color
; // Color density values
1811 // Get the SimpleColorProfile parameters:
1813 // SimpleColorProfile resolution/mediatype black-density yellow-density
1814 // red-density gamma red-adjust green-adjust blue-adjust
1815 if (!get_token(fp
, resolution
, sizeof(resolution
)))
1817 _cupsLangPrintf(stderr
,
1818 _("ppdc: Expected resolution/mediatype following "
1819 "SimpleColorProfile on line %d of %s."),
1820 fp
->line
, fp
->filename
);
1824 if ((media_type
= strchr(resolution
, '/')) != NULL
)
1825 *media_type
++ = '\0';
1827 media_type
= resolution
;
1829 // Collect the profile parameters...
1831 yellow
= get_float(fp
);
1834 red
= get_float(fp
);
1835 green
= get_float(fp
);
1836 blue
= get_float(fp
);
1838 // Build the color profile...
1839 color
= 0.5f
* rd
/ kd
- kd
;
1841 m
[1] = color
+ blue
; // C + M (blue)
1842 m
[2] = color
- green
; // C + Y (green)
1843 m
[3] = color
- blue
; // M + C (blue)
1845 m
[5] = color
+ red
; // M + Y (red)
1846 m
[6] = yellow
* (color
+ green
); // Y + C (green)
1847 m
[7] = yellow
* (color
- red
); // Y + M (red)
1855 else if (m
[3] > 0.0f
)
1866 else if (m
[6] > 0.0f
)
1877 else if (m
[7] > 0.0f
)
1883 // Return the new profile...
1884 return (new ppdcProfile(resolution
, media_type
, g
, kd
, m
));
1889 // 'ppdcSource::get_size()' - Get a media size definition from a file.
1892 ppdcMediaSize
* // O - Media size
1893 ppdcSource::get_size(ppdcFile
*fp
) // I - File to read
1895 char name
[1024], // Name
1897 float width
, // Width
1901 // Get the name, text, width, and length:
1903 // #media name/text width length
1904 if (!get_token(fp
, name
, sizeof(name
)))
1907 if ((text
= strchr(name
, '/')) != NULL
)
1912 if ((width
= get_measurement(fp
)) < 0.0f
)
1915 if ((length
= get_measurement(fp
)) < 0.0f
)
1918 // Return the new media size...
1919 return (new ppdcMediaSize(name
, text
, width
, length
, 0.0f
, 0.0f
, 0.0f
, 0.0f
));
1924 // 'ppdcSource::get_token()' - Get a token from a file.
1927 char * // O - Token string or NULL
1928 ppdcSource::get_token(ppdcFile
*fp
, // I - File to read
1929 char *buffer
, // I - Buffer
1930 int buflen
) // I - Length of buffer
1932 char *bufptr
, // Pointer into string buffer
1933 *bufend
; // End of string buffer
1934 int ch
, // Character from file
1935 nextch
, // Next char in file
1936 quote
, // Quote character used...
1937 empty
, // Empty input?
1938 startline
; // Start line for quote
1939 char name
[256], // Name string
1940 *nameptr
; // Name pointer
1941 ppdcVariable
*var
; // Variable pointer
1944 // Mark the beginning and end of the buffer...
1946 bufend
= buffer
+ buflen
- 1;
1948 // Loop intil we've read a token...
1953 while ((ch
= fp
->get()) != EOF
)
1955 if (isspace(ch
) && !quote
)
1964 // Variable substitution
1967 for (nameptr
= name
; (ch
= fp
->peek()) != EOF
;)
1969 if (!isalnum(ch
) && ch
!= '_')
1971 else if (nameptr
< (name
+ sizeof(name
) - 1))
1972 *nameptr
++ = (char)fp
->get();
1975 if (nameptr
== name
)
1977 // Just substitute this character...
1981 if (bufptr
< bufend
)
1982 *bufptr
++ = (char)fp
->get();
1987 _cupsLangPrintf(stderr
,
1988 _("ppdc: Bad variable substitution ($%c) on line %d "
1989 "of %s."), ch
, fp
->line
, fp
->filename
);
1991 if (bufptr
< bufend
)
1997 // Substitute the variable value...
1999 var
= find_variable(name
);
2002 strlcpy(bufptr
, var
->value
->value
, (size_t)(bufend
- bufptr
+ 1));
2003 bufptr
+= strlen(bufptr
);
2007 if (!(cond_state
& PPDC_COND_SKIP
))
2008 _cupsLangPrintf(stderr
,
2009 _("ppdc: Undefined variable (%s) on line %d of "
2010 "%s."), name
, fp
->line
, fp
->filename
);
2012 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "$%s", name
);
2013 bufptr
+= strlen(bufptr
);
2017 else if (ch
== '/' && !quote
)
2019 // Possibly a comment...
2020 nextch
= fp
->peek();
2027 while ((nextch
= fp
->get()) != EOF
)
2029 if (ch
== '*' && nextch
== '/')
2038 else if (nextch
== '/')
2041 while ((nextch
= fp
->get()) != EOF
)
2053 if (bufptr
< bufend
)
2054 *bufptr
++ = (char)ch
;
2057 else if (ch
== '\'' || ch
== '\"')
2063 // Ending the current quoted string...
2068 // Insert the opposing quote char...
2069 if (bufptr
< bufend
)
2070 *bufptr
++ = (char)ch
;
2074 // Start a new quoted string...
2075 startline
= fp
->line
;
2079 else if ((ch
== '(' || ch
== '<') && !quote
)
2083 startline
= fp
->line
;
2085 if (bufptr
< bufend
)
2086 *bufptr
++ = (char)ch
;
2088 else if ((ch
== ')' && quote
== '(') || (ch
== '>' && quote
== '<'))
2092 if (bufptr
< bufend
)
2093 *bufptr
++ = (char)ch
;
2095 else if (ch
== '\\')
2099 if ((ch
= fp
->get()) == EOF
)
2102 if (bufptr
< bufend
)
2103 *bufptr
++ = (char)ch
;
2105 else if (bufptr
< bufend
)
2109 *bufptr
++ = (char)ch
;
2111 if ((ch
== '{' || ch
== '}') && !quote
)
2118 _cupsLangPrintf(stderr
,
2119 _("ppdc: Unterminated string starting with %c on line %d "
2120 "of %s."), quote
, startline
, fp
->filename
);
2135 // 'ppdcSource::get_variable()' - Get a variable definition.
2138 ppdcVariable
* // O - Variable
2139 ppdcSource::get_variable(ppdcFile
*fp
) // I - File to read
2141 char name
[1024], // Name
2142 value
[1024]; // Value
2145 // Get the name and value:
2147 // #define name value
2148 if (!get_token(fp
, name
, sizeof(name
)))
2151 if (!get_token(fp
, value
, sizeof(value
)))
2154 // Set the variable...
2155 return (set_variable(name
, value
));
2160 // 'ppdcSource::quotef()' - Write a formatted, quoted string...
2163 int // O - Number bytes on success, -1 on failure
2164 ppdcSource::quotef(cups_file_t
*fp
, // I - File to write to
2165 const char *format
, // I - Printf-style format string
2166 ...) // I - Additional args as needed
2168 va_list ap
; // Pointer to additional arguments
2169 int bytes
; // Bytes written
2170 char sign
, // Sign of format width
2171 size
, // Size character (h, l, L)
2172 type
; // Format type character
2173 const char *bufformat
; // Start of format
2174 int width
, // Width of field
2175 prec
; // Number of characters of precision
2176 char tformat
[100]; // Temporary format string for fprintf()
2177 char *s
; // Pointer to string
2178 int slen
; // Length of string
2179 int i
; // Looping var
2182 // Range check input...
2186 // Loop through the format string, formatting as needed...
2187 va_start(ap
, format
);
2200 cupsFilePutChar(fp
, *format
++);
2204 else if (strchr(" -+#\'", *format
))
2210 while (isdigit(*format
))
2211 width
= width
* 10 + *format
++ - '0';
2218 while (isdigit(*format
))
2219 prec
= prec
* 10 + *format
++ - '0';
2224 if (*format
== 'l' && format
[1] == 'l')
2229 else if (*format
== 'h' || *format
== 'l' || *format
== 'L')
2241 case 'E' : // Floating point formats
2246 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2249 memcpy(tformat
, bufformat
, (size_t)(format
- bufformat
));
2250 tformat
[format
- bufformat
] = '\0';
2252 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, double));
2255 case 'B' : // Integer formats
2263 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2266 memcpy(tformat
, bufformat
, (size_t)(format
- bufformat
));
2267 tformat
[format
- bufformat
] = '\0';
2269 # ifdef HAVE_LONG_LONG
2271 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, long long));
2273 # endif /* HAVE_LONG_LONG */
2275 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, long));
2277 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, int));
2280 case 'p' : // Pointer value
2281 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2284 memcpy(tformat
, bufformat
, (size_t)(format
- bufformat
));
2285 tformat
[format
- bufformat
] = '\0';
2287 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, void *));
2290 case 'c' : // Character or character array
2294 cupsFilePutChar(fp
, va_arg(ap
, int));
2298 cupsFileWrite(fp
, va_arg(ap
, char *), (size_t)width
);
2303 case 's' : // String
2304 if ((s
= va_arg(ap
, char *)) == NULL
)
2305 s
= (char *)"(nil)";
2307 slen
= (int)strlen(s
);
2308 if (slen
> width
&& prec
!= width
)
2316 for (i
= width
- slen
; i
> 0; i
--, bytes
++)
2317 cupsFilePutChar(fp
, ' ');
2320 for (i
= slen
; i
> 0; i
--, s
++, bytes
++)
2322 if (*s
== '\\' || *s
== '\"')
2324 cupsFilePutChar(fp
, '\\');
2328 cupsFilePutChar(fp
, *s
);
2333 for (i
= width
- slen
; i
> 0; i
--, bytes
++)
2334 cupsFilePutChar(fp
, ' ');
2341 cupsFilePutChar(fp
, *format
++);
2348 // Return the number of characters written.
2354 // 'ppdcSource::read_file()' - Read a driver source file.
2358 ppdcSource::read_file(const char *f
, // I - File to read
2359 cups_file_t
*ffp
) // I - File pointer to use
2361 ppdcFile
*fp
= new ppdcFile(f
, ffp
);
2365 if (cond_current
!= cond_stack
)
2366 _cupsLangPrintf(stderr
, _("ppdc: Missing #endif at end of \"%s\"."), f
);
2371 // 'ppdcSource::scan_file()' - Scan a driver source file.
2375 ppdcSource::scan_file(ppdcFile
*fp
, // I - File to read
2376 ppdcDriver
*td
, // I - Driver template
2377 bool inc
) // I - Including?
2379 ppdcDriver
*d
; // Current driver
2380 ppdcGroup
*g
, // Current group
2381 *mg
, // Matching group
2382 *general
, // General options group
2383 *install
; // Installable options group
2384 ppdcOption
*o
; // Current option
2385 ppdcChoice
*c
; // Current choice
2386 char temp
[256], // Token from file...
2387 *ptr
; // Pointer into token
2388 int isdefault
; // Default option?
2391 // Initialize things as needed...
2398 d
= new ppdcDriver(td
);
2400 if ((general
= d
->find_group("General")) == NULL
)
2402 general
= new ppdcGroup("General", NULL
);
2403 d
->add_group(general
);
2406 if ((install
= d
->find_group("InstallableOptions")) == NULL
)
2408 install
= new ppdcGroup("InstallableOptions", "Installable Options");
2409 d
->add_group(install
);
2412 // Loop until EOF or }
2416 while (get_token(fp
, temp
, sizeof(temp
)))
2420 // Mark the next choice as the default
2423 for (ptr
= temp
; ptr
[1]; ptr
++)
2430 // Don't mark the next choice as the default
2434 if (!_cups_strcasecmp(temp
, "}"))
2436 // Close this one out...
2439 else if (!_cups_strcasecmp(temp
, "{"))
2441 // Open a new child...
2444 else if (!_cups_strcasecmp(temp
, "#if"))
2446 if ((cond_current
- cond_stack
) >= 100)
2448 _cupsLangPrintf(stderr
,
2449 _("ppdc: Too many nested #if's on line %d of %s."),
2450 fp
->line
, fp
->filename
);
2455 if (get_integer(fp
) > 0)
2456 *cond_current
= PPDC_COND_SATISFIED
;
2459 *cond_current
= PPDC_COND_SKIP
;
2460 cond_state
|= PPDC_COND_SKIP
;
2463 else if (!_cups_strcasecmp(temp
, "#elif"))
2465 if (cond_current
== cond_stack
)
2467 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s."),
2468 fp
->line
, fp
->filename
);
2472 if (*cond_current
& PPDC_COND_SATISFIED
)
2475 *cond_current
|= PPDC_COND_SKIP
;
2477 else if (get_integer(fp
) > 0)
2479 *cond_current
|= PPDC_COND_SATISFIED
;
2480 *cond_current
&= ~PPDC_COND_SKIP
;
2483 *cond_current
|= PPDC_COND_SKIP
;
2485 // Update the current state
2486 int *cond_temp
= cond_current
; // Temporary stack pointer
2488 cond_state
= PPDC_COND_NORMAL
;
2489 while (cond_temp
> cond_stack
)
2490 if (*cond_temp
& PPDC_COND_SKIP
)
2492 cond_state
= PPDC_COND_SKIP
;
2498 else if (!_cups_strcasecmp(temp
, "#else"))
2500 if (cond_current
== cond_stack
)
2502 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s."),
2503 fp
->line
, fp
->filename
);
2507 if (*cond_current
& PPDC_COND_SATISFIED
)
2508 *cond_current
|= PPDC_COND_SKIP
;
2511 *cond_current
|= PPDC_COND_SATISFIED
;
2512 *cond_current
&= ~PPDC_COND_SKIP
;
2515 // Update the current state
2516 int *cond_temp
= cond_current
; // Temporary stack pointer
2518 cond_state
= PPDC_COND_NORMAL
;
2519 while (cond_temp
> cond_stack
)
2520 if (*cond_temp
& PPDC_COND_SKIP
)
2522 cond_state
= PPDC_COND_SKIP
;
2528 else if (!_cups_strcasecmp(temp
, "#endif"))
2530 if (cond_current
== cond_stack
)
2532 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s."),
2533 fp
->line
, fp
->filename
);
2539 // Update the current state
2540 int *cond_temp
= cond_current
; // Temporary stack pointer
2542 cond_state
= PPDC_COND_NORMAL
;
2543 while (cond_temp
> cond_stack
)
2544 if (*cond_temp
& PPDC_COND_SKIP
)
2546 cond_state
= PPDC_COND_SKIP
;
2552 else if (!_cups_strcasecmp(temp
, "#define"))
2554 // Get the variable...
2557 else if (!_cups_strcasecmp(temp
, "#include"))
2559 // #include filename
2560 char basedir
[1024], // Base directory
2561 *baseptr
, // Pointer into directory
2562 inctemp
[1024], // Initial filename
2563 incname
[1024]; // Include filename
2564 ppdcFile
*incfile
; // Include file
2565 int *old_current
= cond_current
;
2566 // Previous current stack
2569 // Get the include name...
2570 if (!get_token(fp
, inctemp
, sizeof(inctemp
)))
2572 _cupsLangPrintf(stderr
,
2573 _("ppdc: Expected include filename on line %d of "
2574 "%s."), fp
->line
, fp
->filename
);
2581 // Figure out the current directory...
2582 strlcpy(basedir
, fp
->filename
, sizeof(basedir
));
2584 if ((baseptr
= strrchr(basedir
, '/')) != NULL
)
2587 strlcpy(basedir
, ".", sizeof(basedir
));
2589 // Find the include file...
2590 if (find_include(inctemp
, basedir
, incname
, sizeof(incname
)))
2592 // Open the include file, scan it, and then close it...
2593 incfile
= new ppdcFile(incname
);
2594 scan_file(incfile
, d
, true);
2597 if (cond_current
!= old_current
)
2598 _cupsLangPrintf(stderr
, _("ppdc: Missing #endif at end of \"%s\"."),
2604 _cupsLangPrintf(stderr
,
2605 _("ppdc: Unable to find include file \"%s\" on line %d "
2606 "of %s."), inctemp
, fp
->line
, fp
->filename
);
2610 else if (!_cups_strcasecmp(temp
, "#media"))
2612 ppdcMediaSize
*m
; // Media size
2615 // Get a media size...
2625 else if (!_cups_strcasecmp(temp
, "#po"))
2627 ppdcCatalog
*cat
; // Message catalog
2630 // Get a message catalog...
2640 else if (!_cups_strcasecmp(temp
, "Attribute") ||
2641 !_cups_strcasecmp(temp
, "LocAttribute"))
2643 ppdcAttr
*a
; // Attribute
2646 // Get an attribute...
2647 a
= get_attr(fp
, !_cups_strcasecmp(temp
, "LocAttribute"));
2656 else if (!_cups_strcasecmp(temp
, "Choice"))
2669 // 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...