]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc-source.cxx
e806d24499be6548715a276b992bc3c26c8bcab2
4 // Source class for the CUPS PPD Compiler.
6 // Copyright 2007-2011 by Apple Inc.
7 // Copyright 2002-2007 by Easy Software Products.
9 // These coded instructions, statements, and computer programs are the
10 // property of Apple Inc. and are protected by Federal copyright
11 // law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 // which should have been included with this file. If this file is
13 // file is missing or damaged, see the license at "http://www.cups.org/".
17 // ppdcSource::ppdcSource() - Load a driver source file.
18 // ppdcSource::~ppdcSource() - Free a driver source file.
19 // ppdcSource::add_include() - Add an include directory.
20 // ppdcSource::find_driver() - Find a driver.
21 // ppdcSource::find_include() - Find an include file.
22 // ppdcSource::find_po() - Find a message catalog for the given
24 // ppdcSource::find_size() - Find a media size.
25 // ppdcSource::find_variable() - Find a variable.
26 // ppdcSource::get_attr() - Get an attribute.
27 // ppdcSource::get_boolean() - Get a boolean value.
28 // ppdcSource::get_choice() - Get a choice.
29 // ppdcSource::get_color_model() - Get an old-style color model option.
30 // ppdcSource::get_color_order() - Get an old-style color order value.
31 // ppdcSource::get_color_profile() - Get a color profile definition.
32 // ppdcSource::get_color_space() - Get an old-style colorspace value.
33 // ppdcSource::get_constraint() - Get a constraint.
34 // ppdcSource::get_custom_size() - Get a custom media size definition from
36 // ppdcSource::get_duplex() - Get a duplex option.
37 // ppdcSource::get_filter() - Get a filter.
38 // ppdcSource::get_float() - Get a single floating-point number.
39 // ppdcSource::get_font() - Get a font definition.
40 // ppdcSource::get_generic() - Get a generic old-style option.
41 // ppdcSource::get_group() - Get an option group.
42 // ppdcSource::get_installable() - Get an installable option.
43 // ppdcSource::get_integer() - Get an integer value from a file.
44 // ppdcSource::get_measurement() - Get a measurement value.
45 // ppdcSource::get_option() - Get an option definition.
46 // ppdcSource::get_po() - Get a message catalog.
47 // ppdcSource::get_resolution() - Get an old-style resolution option.
48 // ppdcSource::get_simple_profile() - Get a simple color profile definition.
49 // ppdcSource::get_size() - Get a media size definition from a file.
50 // ppdcSource::get_token() - Get a token from a file.
51 // ppdcSource::get_variable() - Get a variable definition.
52 // ppdcSource::quotef() - Write a formatted, quoted string...
53 // ppdcSource::read_file() - Read a driver source file.
54 // ppdcSource::scan_file() - Scan a driver source file.
55 // ppdcSource::set_variable() - Set a variable.
56 // ppdcSource::write_file() - Write the current source data to a file.
60 // Include necessary headers...
63 #include "ppdc-private.h"
67 #include <cups/raster.h>
68 #include "data/epson.h"
70 #include "data/label.h"
72 # include <sys/utsname.h>
80 ppdcArray
*ppdcSource::includes
= 0;
81 const char *ppdcSource::driver_types
[] =
94 // 'ppdcSource::ppdcSource()' - Load a driver source file.
97 ppdcSource::ppdcSource(const char *f
, // I - File to read
98 cups_file_t
*ffp
)// I - File pointer to use
103 filename
= new ppdcString(f
);
104 base_fonts
= new ppdcArray();
105 drivers
= new ppdcArray();
106 po_files
= new ppdcArray();
107 sizes
= new ppdcArray();
108 vars
= new ppdcArray();
109 cond_state
= PPDC_COND_NORMAL
;
110 cond_current
= cond_stack
;
111 cond_stack
[0] = PPDC_COND_NORMAL
;
113 // Add standard #define variables...
114 #define MAKE_STRING(x) #x
116 vars
->add(new ppdcVariable("CUPS_VERSION", MAKE_STRING(CUPS_VERSION
)));
117 vars
->add(new ppdcVariable("CUPS_VERSION_MAJOR", MAKE_STRING(CUPS_VERSION_MAJOR
)));
118 vars
->add(new ppdcVariable("CUPS_VERSION_MINOR", MAKE_STRING(CUPS_VERSION_MINOR
)));
119 vars
->add(new ppdcVariable("CUPS_VERSION_PATCH", MAKE_STRING(CUPS_VERSION_PATCH
)));
122 vars
->add(new ppdcVariable("PLATFORM_NAME", "Windows"));
123 vars
->add(new ppdcVariable("PLATFORM_ARCH", "X86"));
126 struct utsname name
; // uname information
130 vars
->add(new ppdcVariable("PLATFORM_NAME", name
.sysname
));
131 vars
->add(new ppdcVariable("PLATFORM_ARCH", name
.machine
));
135 vars
->add(new ppdcVariable("PLATFORM_NAME", "unknown"));
136 vars
->add(new ppdcVariable("PLATFORM_ARCH", "unknown"));
146 // 'ppdcSource::~ppdcSource()' - Free a driver source file.
149 ppdcSource::~ppdcSource()
154 base_fonts
->release();
163 // 'ppdcSource::add_include()' - Add an include directory.
167 ppdcSource::add_include(const char *d
) // I - Include directory
173 includes
= new ppdcArray();
175 includes
->add(new ppdcString(d
));
180 // 'ppdcSource::find_driver()' - Find a driver.
183 ppdcDriver
* // O - Driver
184 ppdcSource::find_driver(const char *f
) // I - Driver file name
186 ppdcDriver
*d
; // Current driver
189 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
190 if (!_cups_strcasecmp(f
, d
->pc_file_name
->value
))
198 // 'ppdcSource::find_include()' - Find an include file.
201 char * // O - Found path or NULL
202 ppdcSource::find_include(
203 const char *f
, // I - Include filename
204 const char *base
, // I - Current directory
205 char *n
, // I - Path buffer
206 int nlen
) // I - Path buffer length
208 ppdcString
*dir
; // Include directory
209 char temp
[1024], // Temporary path
210 *ptr
; // Pointer to end of path
213 // Range check input...
214 if (!f
|| !*f
|| !n
|| nlen
< 2)
217 // Check the first character to see if we have <name> or "name"...
220 // Remove the surrounding <> from the name...
221 strlcpy(temp
, f
+ 1, sizeof(temp
));
222 ptr
= temp
+ strlen(temp
) - 1;
226 _cupsLangPrintf(stderr
,
227 _("ppdc: Invalid #include/#po filename \"%s\"."), n
);
236 // Check for the local file relative to the current directory...
237 if (base
&& *base
&& f
[0] != '/')
238 snprintf(n
, nlen
, "%s/%s", base
, f
);
246 // Absolute path that doesn't exist...
251 // Search the include directories, if any...
254 for (dir
= (ppdcString
*)includes
->first(); dir
; dir
= (ppdcString
*)includes
->next())
256 snprintf(n
, nlen
, "%s/%s", dir
->value
, f
);
262 // Search the standard include directories...
263 _cups_globals_t
*cg
= _cupsGlobals(); // Global data
265 snprintf(n
, nlen
, "%s/ppdc/%s", cg
->cups_datadir
, f
);
269 snprintf(n
, nlen
, "%s/po/%s", cg
->cups_datadir
, f
);
278 // 'ppdcSource::find_po()' - Find a message catalog for the given locale.
281 ppdcCatalog
* // O - Message catalog or NULL
282 ppdcSource::find_po(const char *l
) // I - Locale name
284 ppdcCatalog
*cat
; // Current message catalog
287 for (cat
= (ppdcCatalog
*)po_files
->first();
289 cat
= (ppdcCatalog
*)po_files
->next())
290 if (!_cups_strcasecmp(l
, cat
->locale
->value
))
298 // 'ppdcSource::find_size()' - Find a media size.
301 ppdcMediaSize
* // O - Size
302 ppdcSource::find_size(const char *s
) // I - Size name
304 ppdcMediaSize
*m
; // Current media size
307 for (m
= (ppdcMediaSize
*)sizes
->first(); m
; m
= (ppdcMediaSize
*)sizes
->next())
308 if (!_cups_strcasecmp(s
, m
->name
->value
))
316 // 'ppdcSource::find_variable()' - Find a variable.
319 ppdcVariable
* // O - Variable
320 ppdcSource::find_variable(const char *n
)// I - Variable name
322 ppdcVariable
*v
; // Current variable
325 for (v
= (ppdcVariable
*)vars
->first(); v
; v
= (ppdcVariable
*)vars
->next())
326 if (!_cups_strcasecmp(n
, v
->name
->value
))
334 // 'ppdcSource::get_attr()' - Get an attribute.
337 ppdcAttr
* // O - Attribute
338 ppdcSource::get_attr(ppdcFile
*fp
, // I - File to read
339 bool loc
) // I - Localize this attribute?
341 char name
[1024], // Name string
342 selector
[1024], // Selector string
343 *text
, // Text string
344 value
[1024]; // Value string
347 // Get the attribute parameters:
349 // Attribute name selector value
350 if (!get_token(fp
, name
, sizeof(name
)))
352 _cupsLangPrintf(stderr
,
353 _("ppdc: Expected name after %s on line %d of %s."),
354 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
358 if (!get_token(fp
, selector
, sizeof(selector
)))
360 _cupsLangPrintf(stderr
,
361 _("ppdc: Expected selector after %s on line %d of %s."),
362 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
366 if ((text
= strchr(selector
, '/')) != NULL
)
369 if (!get_token(fp
, value
, sizeof(value
)))
371 _cupsLangPrintf(stderr
,
372 _("ppdc: Expected value after %s on line %d of %s."),
373 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
377 return (new ppdcAttr(name
, selector
, text
, value
, loc
));
382 // 'ppdcSource::get_boolean()' - Get a boolean value.
385 int // O - Boolean value
386 ppdcSource::get_boolean(ppdcFile
*fp
) // I - File to read
388 char buffer
[256]; // String buffer
391 if (!get_token(fp
, buffer
, sizeof(buffer
)))
393 _cupsLangPrintf(stderr
,
394 _("ppdc: Expected boolean value on line %d of %s."),
395 fp
->line
, fp
->filename
);
399 if (!_cups_strcasecmp(buffer
, "on") ||
400 !_cups_strcasecmp(buffer
, "yes") ||
401 !_cups_strcasecmp(buffer
, "true"))
403 else if (!_cups_strcasecmp(buffer
, "off") ||
404 !_cups_strcasecmp(buffer
, "no") ||
405 !_cups_strcasecmp(buffer
, "false"))
409 _cupsLangPrintf(stderr
,
410 _("ppdc: Bad boolean value (%s) on line %d of %s."),
411 buffer
, fp
->line
, fp
->filename
);
418 // 'ppdcSource::get_choice()' - Get a choice.
421 ppdcChoice
* // O - Choice data
422 ppdcSource::get_choice(ppdcFile
*fp
) // I - File to read
424 char name
[1024], // Name
429 // Read a choice from the file:
431 // Choice name/text code
432 if (!get_token(fp
, name
, sizeof(name
)))
434 _cupsLangPrintf(stderr
,
435 _("ppdc: Expected choice name/text on line %d of %s."),
436 fp
->line
, fp
->filename
);
440 if ((text
= strchr(name
, '/')) != NULL
)
445 if (!get_token(fp
, code
, sizeof(code
)))
447 _cupsLangPrintf(stderr
, _("ppdc: Expected choice code on line %d of %s."),
448 fp
->line
, fp
->filename
);
452 // Return the new choice
453 return (new ppdcChoice(name
, text
, code
));
458 // 'ppdcSource::get_color_model()' - Get an old-style color model option.
461 ppdcChoice
* // O - Choice data
462 ppdcSource::get_color_model(ppdcFile
*fp
)
465 char name
[1024], // Option name
466 *text
, // Text option
467 temp
[256]; // Temporary string
468 int color_space
, // Colorspace
469 color_order
, // Color order
470 compression
; // Compression mode
473 // Get the ColorModel parameters:
475 // ColorModel name/text colorspace colororder compression
476 if (!get_token(fp
, name
, sizeof(name
)))
478 _cupsLangPrintf(stderr
,
479 _("ppdc: Expected name/text combination for ColorModel on "
480 "line %d of %s."), fp
->line
, fp
->filename
);
484 if ((text
= strchr(name
, '/')) != NULL
)
489 if (!get_token(fp
, temp
, sizeof(temp
)))
491 _cupsLangPrintf(stderr
,
492 _("ppdc: Expected colorspace for ColorModel on line %d of "
493 "%s."), fp
->line
, fp
->filename
);
497 if ((color_space
= get_color_space(temp
)) < 0)
498 color_space
= get_integer(temp
);
500 if (!get_token(fp
, temp
, sizeof(temp
)))
502 _cupsLangPrintf(stderr
,
503 _("ppdc: Expected color order for ColorModel on line %d of "
504 "%s."), fp
->line
, fp
->filename
);
508 if ((color_order
= get_color_order(temp
)) < 0)
509 color_order
= get_integer(temp
);
511 if (!get_token(fp
, temp
, sizeof(temp
)))
513 _cupsLangPrintf(stderr
,
514 _("ppdc: Expected compression for ColorModel on line %d of "
515 "%s."), fp
->line
, fp
->filename
);
519 compression
= get_integer(temp
);
521 snprintf(temp
, sizeof(temp
),
522 "<</cupsColorSpace %d/cupsColorOrder %d/cupsCompression %d>>"
524 color_space
, color_order
, compression
);
526 return (new ppdcChoice(name
, text
, temp
));
531 // 'ppdcSource::get_color_order()' - Get an old-style color order value.
534 int // O - Color order value
535 ppdcSource::get_color_order(
536 const char *co
) // I - Color order string
538 if (!_cups_strcasecmp(co
, "chunked") ||
539 !_cups_strcasecmp(co
, "chunky"))
540 return (CUPS_ORDER_CHUNKED
);
541 else if (!_cups_strcasecmp(co
, "banded"))
542 return (CUPS_ORDER_BANDED
);
543 else if (!_cups_strcasecmp(co
, "planar"))
544 return (CUPS_ORDER_PLANAR
);
551 // 'ppdcSource::get_color_profile()' - Get a color profile definition.
554 ppdcProfile
* // O - Color profile
555 ppdcSource::get_color_profile(
556 ppdcFile
*fp
) // I - File to read
558 char resolution
[1024], // Resolution/media type
559 *media_type
; // Media type
560 int i
; // Looping var
561 float g
, // Gamma value
563 m
[9]; // Transform matrix
566 // Get the ColorProfile parameters:
568 // ColorProfile resolution/mediatype gamma density m00 m01 m02 ... m22
569 if (!get_token(fp
, resolution
, sizeof(resolution
)))
571 _cupsLangPrintf(stderr
,
572 _("ppdc: Expected resolution/mediatype following "
573 "ColorProfile on line %d of %s."),
574 fp
->line
, fp
->filename
);
578 if ((media_type
= strchr(resolution
, '/')) != NULL
)
579 *media_type
++ = '\0';
581 media_type
= resolution
;
585 for (i
= 0; i
< 9; i
++)
586 m
[i
] = get_float(fp
);
588 return (new ppdcProfile(resolution
, media_type
, g
, d
, m
));
593 // 'ppdcSource::get_color_space()' - Get an old-style colorspace value.
596 int // O - Colorspace value
597 ppdcSource::get_color_space(
598 const char *cs
) // I - Colorspace string
600 if (!_cups_strcasecmp(cs
, "w"))
601 return (CUPS_CSPACE_W
);
602 else if (!_cups_strcasecmp(cs
, "rgb"))
603 return (CUPS_CSPACE_RGB
);
604 else if (!_cups_strcasecmp(cs
, "rgba"))
605 return (CUPS_CSPACE_RGBA
);
606 else if (!_cups_strcasecmp(cs
, "k"))
607 return (CUPS_CSPACE_K
);
608 else if (!_cups_strcasecmp(cs
, "cmy"))
609 return (CUPS_CSPACE_CMY
);
610 else if (!_cups_strcasecmp(cs
, "ymc"))
611 return (CUPS_CSPACE_YMC
);
612 else if (!_cups_strcasecmp(cs
, "cmyk"))
613 return (CUPS_CSPACE_CMYK
);
614 else if (!_cups_strcasecmp(cs
, "ymck"))
615 return (CUPS_CSPACE_YMCK
);
616 else if (!_cups_strcasecmp(cs
, "kcmy"))
617 return (CUPS_CSPACE_KCMY
);
618 else if (!_cups_strcasecmp(cs
, "kcmycm"))
619 return (CUPS_CSPACE_KCMYcm
);
620 else if (!_cups_strcasecmp(cs
, "gmck"))
621 return (CUPS_CSPACE_GMCK
);
622 else if (!_cups_strcasecmp(cs
, "gmcs"))
623 return (CUPS_CSPACE_GMCS
);
624 else if (!_cups_strcasecmp(cs
, "white"))
625 return (CUPS_CSPACE_WHITE
);
626 else if (!_cups_strcasecmp(cs
, "gold"))
627 return (CUPS_CSPACE_GOLD
);
628 else if (!_cups_strcasecmp(cs
, "silver"))
629 return (CUPS_CSPACE_SILVER
);
630 else if (!_cups_strcasecmp(cs
, "CIEXYZ"))
631 return (CUPS_CSPACE_CIEXYZ
);
632 else if (!_cups_strcasecmp(cs
, "CIELab"))
633 return (CUPS_CSPACE_CIELab
);
634 else if (!_cups_strcasecmp(cs
, "RGBW"))
635 return (CUPS_CSPACE_RGBW
);
636 else if (!_cups_strcasecmp(cs
, "ICC1"))
637 return (CUPS_CSPACE_ICC1
);
638 else if (!_cups_strcasecmp(cs
, "ICC2"))
639 return (CUPS_CSPACE_ICC2
);
640 else if (!_cups_strcasecmp(cs
, "ICC3"))
641 return (CUPS_CSPACE_ICC3
);
642 else if (!_cups_strcasecmp(cs
, "ICC4"))
643 return (CUPS_CSPACE_ICC4
);
644 else if (!_cups_strcasecmp(cs
, "ICC5"))
645 return (CUPS_CSPACE_ICC5
);
646 else if (!_cups_strcasecmp(cs
, "ICC6"))
647 return (CUPS_CSPACE_ICC6
);
648 else if (!_cups_strcasecmp(cs
, "ICC7"))
649 return (CUPS_CSPACE_ICC7
);
650 else if (!_cups_strcasecmp(cs
, "ICC8"))
651 return (CUPS_CSPACE_ICC8
);
652 else if (!_cups_strcasecmp(cs
, "ICC9"))
653 return (CUPS_CSPACE_ICC9
);
654 else if (!_cups_strcasecmp(cs
, "ICCA"))
655 return (CUPS_CSPACE_ICCA
);
656 else if (!_cups_strcasecmp(cs
, "ICCB"))
657 return (CUPS_CSPACE_ICCB
);
658 else if (!_cups_strcasecmp(cs
, "ICCC"))
659 return (CUPS_CSPACE_ICCC
);
660 else if (!_cups_strcasecmp(cs
, "ICCD"))
661 return (CUPS_CSPACE_ICCD
);
662 else if (!_cups_strcasecmp(cs
, "ICCE"))
663 return (CUPS_CSPACE_ICCE
);
664 else if (!_cups_strcasecmp(cs
, "ICCF"))
665 return (CUPS_CSPACE_ICCF
);
672 // 'ppdcSource::get_constraint()' - Get a constraint.
675 ppdcConstraint
* // O - Constraint
676 ppdcSource::get_constraint(ppdcFile
*fp
)// I - File to read
678 char temp
[1024], // One string to rule them all
679 *ptr
, // Pointer into string
680 *option1
, // Constraint option 1
681 *choice1
, // Constraint choice 1
682 *option2
, // Constraint option 2
683 *choice2
; // Constraint choice 2
686 // Read the UIConstaints parameter in one of the following forms:
688 // UIConstraints "*Option1 *Option2"
689 // UIConstraints "*Option1 Choice1 *Option2"
690 // UIConstraints "*Option1 *Option2 Choice2"
691 // UIConstraints "*Option1 Choice1 *Option2 Choice2"
692 if (!get_token(fp
, temp
, sizeof(temp
)))
694 _cupsLangPrintf(stderr
,
695 _("ppdc: Expected constraints string for UIConstraints on "
696 "line %d of %s."), fp
->line
, fp
->filename
);
700 for (ptr
= temp
; isspace(*ptr
); ptr
++);
704 _cupsLangPrintf(stderr
,
705 _("ppdc: Option constraint must *name on line %d of %s."),
706 fp
->line
, fp
->filename
);
712 for (; *ptr
&& !isspace(*ptr
); ptr
++);
713 for (; isspace(*ptr
); *ptr
++ = '\0');
719 for (; *ptr
&& !isspace(*ptr
); ptr
++);
720 for (; isspace(*ptr
); *ptr
++ = '\0');
727 _cupsLangPrintf(stderr
,
728 _("ppdc: Expected two option names on line %d of %s."),
729 fp
->line
, fp
->filename
);
735 for (; *ptr
&& !isspace(*ptr
); ptr
++);
736 for (; isspace(*ptr
); *ptr
++ = '\0');
743 return (new ppdcConstraint(option1
, choice1
, option2
, choice2
));
748 // 'ppdcSource::get_custom_size()' - Get a custom media size definition from a file.
751 ppdcMediaSize
* // O - Media size
752 ppdcSource::get_custom_size(ppdcFile
*fp
)
755 char name
[1024], // Name
757 size_code
[10240], // PageSize code
758 region_code
[10240]; // PageRegion
759 float width
, // Width
762 bottom
, // Bottom margin
763 right
, // Right margin
767 // Get the name, text, width, length, margins, and code:
769 // CustomMedia name/text width length left bottom right top size-code region-code
770 if (!get_token(fp
, name
, sizeof(name
)))
773 if ((text
= strchr(name
, '/')) != NULL
)
778 if ((width
= get_measurement(fp
)) < 0.0f
)
781 if ((length
= get_measurement(fp
)) < 0.0f
)
784 if ((left
= get_measurement(fp
)) < 0.0f
)
787 if ((bottom
= get_measurement(fp
)) < 0.0f
)
790 if ((right
= get_measurement(fp
)) < 0.0f
)
793 if ((top
= get_measurement(fp
)) < 0.0f
)
796 if (!get_token(fp
, size_code
, sizeof(size_code
)))
799 if (!get_token(fp
, region_code
, sizeof(region_code
)))
802 // Return the new media size...
803 return (new ppdcMediaSize(name
, text
, width
, length
, left
, bottom
,
804 right
, top
, size_code
, region_code
));
809 // 'ppdcSource::get_duplex()' - Get a duplex option.
813 ppdcSource::get_duplex(ppdcFile
*fp
, // I - File to read from
814 ppdcDriver
*d
) // I - Current driver
816 char temp
[256]; // Duplex keyword
817 ppdcAttr
*attr
; // cupsFlipDuplex attribute
818 ppdcGroup
*g
; // Current group
819 ppdcOption
*o
; // Duplex option
822 // Duplex {boolean|none|normal|flip}
823 if (!get_token(fp
, temp
, sizeof(temp
)))
825 _cupsLangPrintf(stderr
,
826 _("ppdc: Expected duplex type after Duplex on line %d of "
827 "%s."), fp
->line
, fp
->filename
);
834 if (!_cups_strcasecmp(temp
, "none") || !_cups_strcasecmp(temp
, "false") ||
835 !_cups_strcasecmp(temp
, "no") || !_cups_strcasecmp(temp
, "off"))
837 g
= d
->find_group("General");
838 if ((o
= g
->find_option("Duplex")) != NULL
)
839 g
->options
->remove(o
);
841 for (attr
= (ppdcAttr
*)d
->attrs
->first();
843 attr
= (ppdcAttr
*)d
->attrs
->next())
844 if (!strcmp(attr
->name
->value
, "cupsFlipDuplex"))
846 d
->attrs
->remove(attr
);
850 else if (!_cups_strcasecmp(temp
, "normal") || !_cups_strcasecmp(temp
, "true") ||
851 !_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "on") ||
852 !_cups_strcasecmp(temp
, "flip") || !_cups_strcasecmp(temp
, "rotated") ||
853 !_cups_strcasecmp(temp
, "manualtumble"))
855 g
= d
->find_group("General");
856 o
= g
->find_option("Duplex");
860 o
= new ppdcOption(PPDC_PICKONE
, "Duplex", "2-Sided Printing",
861 !_cups_strcasecmp(temp
, "flip") ? PPDC_SECTION_PAGE
:
862 PPDC_SECTION_ANY
, 10.0f
);
863 o
->add_choice(new ppdcChoice("None", "Off (1-Sided)",
864 "<</Duplex false>>setpagedevice"));
865 o
->add_choice(new ppdcChoice("DuplexNoTumble", "Long-Edge (Portrait)",
866 "<</Duplex true/Tumble false>>setpagedevice"));
867 o
->add_choice(new ppdcChoice("DuplexTumble", "Short-Edge (Landscape)",
868 "<</Duplex true/Tumble true>>setpagedevice"));
873 for (attr
= (ppdcAttr
*)d
->attrs
->first();
875 attr
= (ppdcAttr
*)d
->attrs
->next())
876 if (!strcmp(attr
->name
->value
, "cupsFlipDuplex"))
878 if (_cups_strcasecmp(temp
, "flip"))
879 d
->attrs
->remove(attr
);
883 if (!_cups_strcasecmp(temp
, "flip") && !attr
)
884 d
->add_attr(new ppdcAttr("cupsFlipDuplex", NULL
, NULL
, "true"));
886 for (attr
= (ppdcAttr
*)d
->attrs
->first();
888 attr
= (ppdcAttr
*)d
->attrs
->next())
889 if (!strcmp(attr
->name
->value
, "cupsBackSide"))
891 d
->attrs
->remove(attr
);
895 if (!_cups_strcasecmp(temp
, "flip"))
896 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Flipped"));
897 else if (!_cups_strcasecmp(temp
, "rotated"))
898 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Rotated"));
899 else if (!_cups_strcasecmp(temp
, "manualtumble"))
900 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "ManualTumble"));
902 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Normal"));
905 _cupsLangPrintf(stderr
,
906 _("ppdc: Unknown duplex type \"%s\" on line %d of %s."),
907 temp
, fp
->line
, fp
->filename
);
912 // 'ppdcSource::get_filter()' - Get a filter.
915 ppdcFilter
* // O - Filter
916 ppdcSource::get_filter(ppdcFile
*fp
) // I - File to read
918 char type
[1024], // MIME type
919 program
[1024], // Filter program
920 *ptr
; // Pointer into MIME type
921 int cost
; // Relative cost
924 // Read filter parameters in one of the following formats:
926 // Filter "type cost program"
927 // Filter type cost program
929 if (!get_token(fp
, type
, sizeof(type
)))
931 _cupsLangPrintf(stderr
,
932 _("ppdc: Expected a filter definition on line %d of %s."),
933 fp
->line
, fp
->filename
);
937 if ((ptr
= strchr(type
, ' ')) != NULL
)
939 // Old-style filter definition in one string...
941 cost
= strtol(ptr
, &ptr
, 10);
943 while (isspace(*ptr
))
946 strcpy(program
, ptr
);
950 cost
= get_integer(fp
);
952 if (!get_token(fp
, program
, sizeof(program
)))
954 _cupsLangPrintf(stderr
,
955 _("ppdc: Expected a program name on line %d of %s."),
956 fp
->line
, fp
->filename
);
963 _cupsLangPrintf(stderr
,
964 _("ppdc: Invalid empty MIME type for filter on line %d of "
965 "%s."), fp
->line
, fp
->filename
);
969 if (cost
< 0 || cost
> 200)
971 _cupsLangPrintf(stderr
,
972 _("ppdc: Invalid cost for filter on line %d of %s."),
973 fp
->line
, fp
->filename
);
979 _cupsLangPrintf(stderr
,
980 _("ppdc: Invalid empty program name for filter on line %d "
981 "of %s."), fp
->line
, fp
->filename
);
985 return (new ppdcFilter(type
, program
, cost
));
990 // 'ppdcSource::get_float()' - Get a single floating-point number.
994 ppdcSource::get_float(ppdcFile
*fp
) // I - File to read
996 char temp
[256], // String buffer
997 *ptr
; // Pointer into buffer
998 float val
; // Floating point value
1001 // Get the number from the file and range-check...
1002 if (!get_token(fp
, temp
, sizeof(temp
)))
1004 _cupsLangPrintf(stderr
, _("ppdc: Expected real number on line %d of %s."),
1005 fp
->line
, fp
->filename
);
1009 val
= (float)strtod(temp
, &ptr
);
1013 _cupsLangPrintf(stderr
,
1014 _("ppdc: Unknown trailing characters in real number \"%s\" "
1015 "on line %d of %s."), temp
, fp
->line
, fp
->filename
);
1024 // 'ppdcSource::get_font()' - Get a font definition.
1027 ppdcFont
* // O - Font data
1028 ppdcSource::get_font(ppdcFile
*fp
) // I - File to read
1030 char name
[256], // Font name
1031 encoding
[256], // Font encoding
1032 version
[256], // Font version
1033 charset
[256], // Font charset
1034 temp
[256]; // Font status string
1035 ppdcFontStatus status
; // Font status enumeration
1038 // Read font parameters as follows:
1041 // Font name encoding version charset status
1042 // %font name encoding version charset status
1044 // "Name" is the PostScript font name.
1046 // "Encoding" is the default encoding of the font: Standard, ISOLatin1,
1047 // Special, Expert, ExpertSubset, etc.
1049 // "Version" is the version number string.
1051 // "Charset" specifies the characters that are included in the font:
1052 // Standard, Special, Expert, Adobe-Identity, etc.
1054 // "Status" is the keyword ROM or Disk.
1055 if (!get_token(fp
, name
, sizeof(name
)))
1057 _cupsLangPrintf(stderr
,
1058 _("ppdc: Expected name after Font on line %d of %s."),
1059 fp
->line
, fp
->filename
);
1063 if (!strcmp(name
, "*"))
1065 // Include all base fonts...
1069 status
= PPDC_FONT_ROM
;
1073 // Load a full font definition...
1074 if (!get_token(fp
, encoding
, sizeof(encoding
)))
1076 _cupsLangPrintf(stderr
,
1077 _("ppdc: Expected encoding after Font on line %d of "
1078 "%s."), fp
->line
, fp
->filename
);
1082 if (!get_token(fp
, version
, sizeof(version
)))
1084 _cupsLangPrintf(stderr
,
1085 _("ppdc: Expected version after Font on line %d of "
1086 "%s."), fp
->line
, fp
->filename
);
1090 if (!get_token(fp
, charset
, sizeof(charset
)))
1092 _cupsLangPrintf(stderr
,
1093 _("ppdc: Expected charset after Font on line %d of "
1094 "%s."), fp
->line
, fp
->filename
);
1098 if (!get_token(fp
, temp
, sizeof(temp
)))
1100 _cupsLangPrintf(stderr
,
1101 _("ppdc: Expected status after Font on line %d of %s."),
1102 fp
->line
, fp
->filename
);
1106 if (!_cups_strcasecmp(temp
, "ROM"))
1107 status
= PPDC_FONT_ROM
;
1108 else if (!_cups_strcasecmp(temp
, "Disk"))
1109 status
= PPDC_FONT_DISK
;
1112 _cupsLangPrintf(stderr
,
1113 _("ppdc: Bad status keyword %s on line %d of %s."),
1114 temp
, fp
->line
, fp
->filename
);
1119 // printf("Font %s %s %s %s %s\n", name, encoding, version, charset, temp);
1121 return (new ppdcFont(name
, encoding
, version
, charset
, status
));
1126 // 'ppdcSource::get_generic()' - Get a generic old-style option.
1129 ppdcChoice
* // O - Choice data
1130 ppdcSource::get_generic(ppdcFile
*fp
, // I - File to read
1131 const char *keyword
,
1134 // I - Text attribute
1136 // I - Numeric attribute
1138 char name
[1024], // Name
1140 command
[256]; // Command string
1141 int val
; // Numeric value
1144 // Read one of the following parameters:
1147 // Foo integer name/text
1149 val
= get_integer(fp
);
1153 if (!get_token(fp
, name
, sizeof(name
)))
1155 _cupsLangPrintf(stderr
,
1156 _("ppdc: Expected name/text after %s on line %d of %s."),
1157 keyword
, fp
->line
, fp
->filename
);
1161 if ((text
= strchr(name
, '/')) != NULL
)
1169 snprintf(command
, sizeof(command
),
1170 "<</%s(%s)/%s %d>>setpagedevice",
1171 tattr
, name
, nattr
, val
);
1173 snprintf(command
, sizeof(command
),
1174 "<</%s %d>>setpagedevice",
1178 snprintf(command
, sizeof(command
),
1179 "<</%s(%s)>>setpagedevice",
1182 return (new ppdcChoice(name
, text
, command
));
1187 // 'ppdcSource::get_group()' - Get an option group.
1190 ppdcGroup
* // O - Group
1191 ppdcSource::get_group(ppdcFile
*fp
, // I - File to read
1192 ppdcDriver
*d
) // I - Printer driver
1194 char name
[1024], // UI name
1196 ppdcGroup
*g
; // Group
1199 // Read the Group parameters:
1202 if (!get_token(fp
, name
, sizeof(name
)))
1204 _cupsLangPrintf(stderr
,
1205 _("ppdc: Expected group name/text on line %d of %s."),
1206 fp
->line
, fp
->filename
);
1210 if ((text
= strchr(name
, '/')) != NULL
)
1215 // See if the group already exists...
1216 if ((g
= d
->find_group(name
)) == NULL
)
1218 // Nope, add a new one...
1219 g
= new ppdcGroup(name
, text
);
1227 // 'ppdcSource::get_installable()' - Get an installable option.
1230 ppdcOption
* // O - Option
1231 ppdcSource::get_installable(ppdcFile
*fp
)
1234 char name
[1024], // Name for installable option
1235 *text
; // Text for installable option
1236 ppdcOption
*o
; // Option
1239 // Read the parameter for an installable option:
1241 // Installable name/text
1242 if (!get_token(fp
, name
, sizeof(name
)))
1244 _cupsLangPrintf(stderr
,
1245 _("ppdc: Expected name/text after Installable on line %d "
1246 "of %s."), fp
->line
, fp
->filename
);
1250 if ((text
= strchr(name
, '/')) != NULL
)
1255 // Create the option...
1256 o
= new ppdcOption(PPDC_BOOLEAN
, name
, text
, PPDC_SECTION_ANY
, 10.0f
);
1258 // Add the false and true choices...
1259 o
->add_choice(new ppdcChoice("False", "Not Installed", ""));
1260 o
->add_choice(new ppdcChoice("True", "Installed", ""));
1267 // 'ppdcSource::get_integer()' - Get an integer value from a string.
1270 #define PPDC_XX -1 // Bad
1271 #define PPDC_EQ 0 // ==
1272 #define PPDC_NE 1 // !=
1273 #define PPDC_LT 2 // <
1274 #define PPDC_LE 3 // <=
1275 #define PPDC_GT 4 // >
1276 #define PPDC_GE 5 // >=
1278 int // O - Integer value
1279 ppdcSource::get_integer(const char *v
) // I - Value string
1282 long temp
, // Temporary value
1283 temp2
; // Second temporary value
1284 char *newv
, // New value string pointer
1285 ch
; // Temporary character
1286 ppdcVariable
*var
; // #define variable
1287 int compop
; // Comparison operator
1290 // Parse the value string...
1294 if (isdigit(*v
& 255) || *v
== '-' || *v
== '+')
1296 // Return a simple integer value
1297 val
= strtol(v
, (char **)&v
, 0);
1298 if (*v
|| val
== LONG_MIN
)
1305 // Evaluate and expression in any of the following formats:
1307 // (number number ... number) Bitwise OR of all numbers
1308 // (NAME == value) 1 if equal, 0 otherwise
1309 // (NAME != value) 1 if not equal, 0 otherwise
1310 // (NAME < value) 1 if less than, 0 otherwise
1311 // (NAME <= value) 1 if less than or equal, 0 otherwise
1312 // (NAME > value) 1 if greater than, 0 otherwise
1313 // (NAME >= value) 1 if greater than or equal, 0 otherwise
1318 while (*v
&& *v
!= ')')
1320 // Skip leading whitespace...
1321 while (*v
&& isspace(*v
& 255))
1324 if (!*v
|| *v
== ')')
1327 if (isdigit(*v
& 255) || *v
== '-' || *v
== '+')
1329 // Bitwise OR a number...
1330 temp
= strtol(v
, &newv
, 0);
1332 if (!*newv
|| newv
== v
|| !(isspace(*newv
) || *newv
== ')') ||
1338 // NAME logicop value
1339 for (newv
= (char *)v
+ 1;
1340 *newv
&& (isalnum(*newv
& 255) || *newv
== '_');
1346 if ((var
= find_variable(v
)) != NULL
)
1348 if (!var
->value
|| !var
->value
->value
|| !var
->value
->value
[0])
1350 else if (isdigit(var
->value
->value
[0] & 255) ||
1351 var
->value
->value
[0] == '-' ||
1352 var
->value
->value
[0] == '+')
1353 temp
= strtol(var
->value
->value
, NULL
, 0);
1361 while (isspace(*newv
& 255))
1364 if (!strncmp(newv
, "==", 2))
1369 else if (!strncmp(newv
, "!=", 2))
1374 else if (!strncmp(newv
, "<=", 2))
1379 else if (*newv
== '<')
1384 else if (!strncmp(newv
, ">=", 2))
1389 else if (*newv
== '>')
1397 if (compop
!= PPDC_XX
)
1399 while (isspace(*newv
& 255))
1402 if (*newv
== ')' || !*newv
)
1405 if (isdigit(*newv
& 255) || *newv
== '-' || *newv
== '+')
1407 // Get the second number...
1408 temp2
= strtol(newv
, &newv
, 0);
1409 if (!*newv
|| newv
== v
|| !(isspace(*newv
) || *newv
== ')') ||
1415 // Lookup the second name...
1416 for (v
= newv
, newv
++;
1417 *newv
&& (isalnum(*newv
& 255) || *newv
== '_');
1423 if ((var
= find_variable(v
)) != NULL
)
1425 if (!var
->value
|| !var
->value
->value
|| !var
->value
->value
[0])
1427 else if (isdigit(var
->value
->value
[0] & 255) ||
1428 var
->value
->value
[0] == '-' ||
1429 var
->value
->value
[0] == '+')
1430 temp2
= strtol(var
->value
->value
, NULL
, 0);
1440 // Do the comparison...
1444 temp
= temp
== temp2
;
1447 temp
= temp
!= temp2
;
1450 temp
= temp
< temp2
;
1453 temp
= temp
<= temp2
;
1456 temp
= temp
> temp2
;
1459 temp
= temp
>= temp2
;
1469 if (*v
== ')' && !v
[1])
1474 else if ((var
= find_variable(v
)) != NULL
)
1476 // NAME by itself returns 1 if the #define variable is not blank and
1478 return (var
->value
->value
&& var
->value
->value
[0] &&
1479 strcmp(var
->value
->value
, "0"));
1483 // Anything else is an error...
1490 // 'ppdcSource::get_integer()' - Get an integer value from a file.
1493 int // O - Integer value
1494 ppdcSource::get_integer(ppdcFile
*fp
) // I - File to read
1496 char temp
[1024]; // String buffer
1499 if (!get_token(fp
, temp
, sizeof(temp
)))
1501 _cupsLangPrintf(stderr
, _("ppdc: Expected integer on line %d of %s."),
1502 fp
->line
, fp
->filename
);
1506 return (get_integer(temp
));
1511 // 'ppdcSource::get_measurement()' - Get a measurement value.
1514 float // O - Measurement value in points
1515 ppdcSource::get_measurement(ppdcFile
*fp
)
1518 char buffer
[256], // Number buffer
1519 *ptr
; // Pointer into buffer
1520 float val
; // Measurement value
1523 // Grab a token from the file...
1524 if (!get_token(fp
, buffer
, sizeof(buffer
)))
1527 // Get the floating point value of "s" and skip all digits and decimal points.
1528 val
= (float)strtod(buffer
, &ptr
);
1530 // Check for a trailing unit specifier...
1531 if (!_cups_strcasecmp(ptr
, "mm"))
1532 val
*= 72.0f
/ 25.4f
;
1533 else if (!_cups_strcasecmp(ptr
, "cm"))
1534 val
*= 72.0f
/ 2.54f
;
1535 else if (!_cups_strcasecmp(ptr
, "m"))
1536 val
*= 72.0f
/ 0.0254f
;
1537 else if (!_cups_strcasecmp(ptr
, "in"))
1539 else if (!_cups_strcasecmp(ptr
, "ft"))
1540 val
*= 72.0f
* 12.0f
;
1541 else if (_cups_strcasecmp(ptr
, "pt") && *ptr
)
1549 // 'ppdcSource::get_option()' - Get an option definition.
1552 ppdcOption
* // O - Option
1553 ppdcSource::get_option(ppdcFile
*fp
, // I - File to read
1554 ppdcDriver
*d
, // I - Printer driver
1555 ppdcGroup
*g
) // I - Current group
1557 char name
[1024], // UI name
1559 type
[256]; // UI type string
1560 ppdcOptType ot
; // Option type value
1561 ppdcOptSection section
; // Option section
1562 float order
; // Option order
1563 ppdcOption
*o
; // Option
1564 ppdcGroup
*mg
; // Matching group, if any
1567 // Read the Option parameters:
1569 // Option name/text type section order
1570 if (!get_token(fp
, name
, sizeof(name
)))
1572 _cupsLangPrintf(stderr
,
1573 _("ppdc: Expected option name/text on line %d of %s."),
1574 fp
->line
, fp
->filename
);
1578 if ((text
= strchr(name
, '/')) != NULL
)
1583 if (!get_token(fp
, type
, sizeof(type
)))
1585 _cupsLangPrintf(stderr
, _("ppdc: Expected option type on line %d of %s."),
1586 fp
->line
, fp
->filename
);
1590 if (!_cups_strcasecmp(type
, "boolean"))
1592 else if (!_cups_strcasecmp(type
, "pickone"))
1594 else if (!_cups_strcasecmp(type
, "pickmany"))
1598 _cupsLangPrintf(stderr
,
1599 _("ppdc: Invalid option type \"%s\" on line %d of %s."),
1600 type
, fp
->line
, fp
->filename
);
1604 if (!get_token(fp
, type
, sizeof(type
)))
1606 _cupsLangPrintf(stderr
,
1607 _("ppdc: Expected option section on line %d of %s."),
1608 fp
->line
, fp
->filename
);
1612 if (!_cups_strcasecmp(type
, "AnySetup"))
1613 section
= PPDC_SECTION_ANY
;
1614 else if (!_cups_strcasecmp(type
, "DocumentSetup"))
1615 section
= PPDC_SECTION_DOCUMENT
;
1616 else if (!_cups_strcasecmp(type
, "ExitServer"))
1617 section
= PPDC_SECTION_EXIT
;
1618 else if (!_cups_strcasecmp(type
, "JCLSetup"))
1619 section
= PPDC_SECTION_JCL
;
1620 else if (!_cups_strcasecmp(type
, "PageSetup"))
1621 section
= PPDC_SECTION_PAGE
;
1622 else if (!_cups_strcasecmp(type
, "Prolog"))
1623 section
= PPDC_SECTION_PROLOG
;
1626 _cupsLangPrintf(stderr
,
1627 _("ppdc: Invalid option section \"%s\" on line %d of "
1628 "%s."), type
, fp
->line
, fp
->filename
);
1632 order
= get_float(fp
);
1634 // See if the option already exists...
1635 if ((o
= d
->find_option_group(name
, &mg
)) == NULL
)
1637 // Nope, add a new one...
1638 o
= new ppdcOption(ot
, name
, text
, section
, order
);
1640 else if (o
->type
!= ot
)
1642 _cupsLangPrintf(stderr
,
1643 _("ppdc: Option %s redefined with a different type on line "
1644 "%d of %s."), name
, fp
->line
, fp
->filename
);
1649 _cupsLangPrintf(stderr
,
1650 _("ppdc: Option %s defined in two different groups on line "
1651 "%d of %s."), name
, fp
->line
, fp
->filename
);
1660 // 'ppdcSource::get_po()' - Get a message catalog.
1663 ppdcCatalog
* // O - Message catalog
1664 ppdcSource::get_po(ppdcFile
*fp
) // I - File to read
1666 char locale
[32], // Locale name
1667 poname
[1024], // Message catalog filename
1668 basedir
[1024], // Base directory
1669 *baseptr
, // Pointer into directory
1670 pofilename
[1024]; // Full filename of message catalog
1671 ppdcCatalog
*cat
; // Message catalog
1674 // Read the #po parameters:
1676 // #po locale "filename.po"
1677 if (!get_token(fp
, locale
, sizeof(locale
)))
1679 _cupsLangPrintf(stderr
,
1680 _("ppdc: Expected locale after #po on line %d of %s."),
1681 fp
->line
, fp
->filename
);
1685 if (!get_token(fp
, poname
, sizeof(poname
)))
1687 _cupsLangPrintf(stderr
,
1688 _("ppdc: Expected filename after #po %s on line %d of "
1689 "%s."), locale
, fp
->line
, fp
->filename
);
1693 // See if the locale is already loaded...
1694 if (find_po(locale
))
1696 _cupsLangPrintf(stderr
,
1697 _("ppdc: Duplicate #po for locale %s on line %d of %s."),
1698 locale
, fp
->line
, fp
->filename
);
1702 // Figure out the current directory...
1703 strlcpy(basedir
, fp
->filename
, sizeof(basedir
));
1705 if ((baseptr
= strrchr(basedir
, '/')) != NULL
)
1708 strcpy(basedir
, ".");
1710 // Find the po file...
1711 pofilename
[0] = '\0';
1714 find_include(poname
, basedir
, pofilename
, sizeof(pofilename
)))
1716 // Found it, so load it...
1717 cat
= new ppdcCatalog(locale
, pofilename
);
1719 // Reset the filename to the name supplied by the user...
1720 cat
->filename
->release();
1721 cat
->filename
= new ppdcString(poname
);
1723 // Return the catalog...
1728 _cupsLangPrintf(stderr
,
1729 _("ppdc: Unable to find #po file %s on line %d of %s."),
1730 poname
, fp
->line
, fp
->filename
);
1737 // 'ppdcSource::get_resolution()' - Get an old-style resolution option.
1740 ppdcChoice
* // O - Choice data
1741 ppdcSource::get_resolution(ppdcFile
*fp
)// I - File to read
1743 char name
[1024], // Name
1745 temp
[256], // Temporary string
1746 command
[256], // Command string
1747 *commptr
; // Pointer into command
1748 int xdpi
, ydpi
, // X + Y resolution
1749 color_order
, // Color order
1750 color_space
, // Colorspace
1751 compression
, // Compression mode
1752 depth
, // Bits per color
1753 row_count
, // Row count
1754 row_feed
, // Row feed
1755 row_step
; // Row step/interval
1758 // Read the resolution parameters:
1760 // Resolution colorspace bits row-count row-feed row-step name/text
1761 if (!get_token(fp
, temp
, sizeof(temp
)))
1763 _cupsLangPrintf(stderr
,
1764 _("ppdc: Expected override field after Resolution on line "
1765 "%d of %s."), fp
->line
, fp
->filename
);
1769 color_order
= get_color_order(temp
);
1770 color_space
= get_color_space(temp
);
1771 compression
= get_integer(temp
);
1773 depth
= get_integer(fp
);
1774 row_count
= get_integer(fp
);
1775 row_feed
= get_integer(fp
);
1776 row_step
= get_integer(fp
);
1778 if (!get_token(fp
, name
, sizeof(name
)))
1780 _cupsLangPrintf(stderr
,
1781 _("ppdc: Expected name/text after Resolution on line %d of "
1782 "%s."), fp
->line
, fp
->filename
);
1786 if ((text
= strchr(name
, '/')) != NULL
)
1791 switch (sscanf(name
, "%dx%d", &xdpi
, &ydpi
))
1794 _cupsLangPrintf(stderr
,
1795 _("ppdc: Bad resolution name \"%s\" on line %d of "
1796 "%s."), name
, fp
->line
, fp
->filename
);
1803 // Create the necessary PS commands...
1804 snprintf(command
, sizeof(command
),
1805 "<</HWResolution[%d %d]/cupsBitsPerColor %d/cupsRowCount %d"
1806 "/cupsRowFeed %d/cupsRowStep %d",
1807 xdpi
, ydpi
, depth
, row_count
, row_feed
, row_step
);
1808 commptr
= command
+ strlen(command
);
1810 if (color_order
>= 0)
1812 snprintf(commptr
, sizeof(command
) - (commptr
- command
),
1813 "/cupsColorOrder %d", color_order
);
1814 commptr
+= strlen(commptr
);
1817 if (color_space
>= 0)
1819 snprintf(commptr
, sizeof(command
) - (commptr
- command
),
1820 "/cupsColorSpace %d", color_space
);
1821 commptr
+= strlen(commptr
);
1824 if (compression
>= 0)
1826 snprintf(commptr
, sizeof(command
) - (commptr
- command
),
1827 "/cupsCompression %d", compression
);
1828 commptr
+= strlen(commptr
);
1831 snprintf(commptr
, sizeof(command
) - (commptr
- command
), ">>setpagedevice");
1833 // Return the new choice...
1834 return (new ppdcChoice(name
, text
, command
));
1839 // 'ppdcSource::get_simple_profile()' - Get a simple color profile definition.
1842 ppdcProfile
* // O - Color profile
1843 ppdcSource::get_simple_profile(ppdcFile
*fp
)
1846 char resolution
[1024], // Resolution/media type
1847 *media_type
; // Media type
1848 float m
[9]; // Transform matrix
1849 float kd
, rd
, g
; // Densities and gamma
1850 float red
, green
, blue
; // RGB adjustments
1851 float yellow
; // Yellow density
1852 float color
; // Color density values
1855 // Get the SimpleColorProfile parameters:
1857 // SimpleColorProfile resolution/mediatype black-density yellow-density
1858 // red-density gamma red-adjust green-adjust blue-adjust
1859 if (!get_token(fp
, resolution
, sizeof(resolution
)))
1861 _cupsLangPrintf(stderr
,
1862 _("ppdc: Expected resolution/mediatype following "
1863 "SimpleColorProfile on line %d of %s."),
1864 fp
->line
, fp
->filename
);
1868 if ((media_type
= strchr(resolution
, '/')) != NULL
)
1869 *media_type
++ = '\0';
1871 media_type
= resolution
;
1873 // Collect the profile parameters...
1875 yellow
= get_float(fp
);
1878 red
= get_float(fp
);
1879 green
= get_float(fp
);
1880 blue
= get_float(fp
);
1882 // Build the color profile...
1883 color
= 0.5f
* rd
/ kd
- kd
;
1885 m
[1] = color
+ blue
; // C + M (blue)
1886 m
[2] = color
- green
; // C + Y (green)
1887 m
[3] = color
- blue
; // M + C (blue)
1889 m
[5] = color
+ red
; // M + Y (red)
1890 m
[6] = yellow
* (color
+ green
); // Y + C (green)
1891 m
[7] = yellow
* (color
- red
); // Y + M (red)
1899 else if (m
[3] > 0.0f
)
1910 else if (m
[6] > 0.0f
)
1921 else if (m
[7] > 0.0f
)
1927 // Return the new profile...
1928 return (new ppdcProfile(resolution
, media_type
, g
, kd
, m
));
1933 // 'ppdcSource::get_size()' - Get a media size definition from a file.
1936 ppdcMediaSize
* // O - Media size
1937 ppdcSource::get_size(ppdcFile
*fp
) // I - File to read
1939 char name
[1024], // Name
1941 float width
, // Width
1945 // Get the name, text, width, and length:
1947 // #media name/text width length
1948 if (!get_token(fp
, name
, sizeof(name
)))
1951 if ((text
= strchr(name
, '/')) != NULL
)
1956 if ((width
= get_measurement(fp
)) < 0.0f
)
1959 if ((length
= get_measurement(fp
)) < 0.0f
)
1962 // Return the new media size...
1963 return (new ppdcMediaSize(name
, text
, width
, length
, 0.0f
, 0.0f
, 0.0f
, 0.0f
));
1968 // 'ppdcSource::get_token()' - Get a token from a file.
1971 char * // O - Token string or NULL
1972 ppdcSource::get_token(ppdcFile
*fp
, // I - File to read
1973 char *buffer
, // I - Buffer
1974 int buflen
) // I - Length of buffer
1976 char *bufptr
, // Pointer into string buffer
1977 *bufend
; // End of string buffer
1978 int ch
, // Character from file
1979 nextch
, // Next char in file
1980 quote
, // Quote character used...
1981 empty
, // Empty input?
1982 startline
; // Start line for quote
1983 char name
[256], // Name string
1984 *nameptr
; // Name pointer
1985 ppdcVariable
*var
; // Variable pointer
1988 // Mark the beginning and end of the buffer...
1990 bufend
= buffer
+ buflen
- 1;
1992 // Loop intil we've read a token...
1997 while ((ch
= fp
->get()) != EOF
)
1999 if (isspace(ch
) && !quote
)
2008 // Variable substitution
2011 for (nameptr
= name
; (ch
= fp
->peek()) != EOF
;)
2013 if (!isalnum(ch
) && ch
!= '_')
2015 else if (nameptr
< (name
+ sizeof(name
) - 1))
2016 *nameptr
++ = fp
->get();
2019 if (nameptr
== name
)
2021 // Just substitute this character...
2025 if (bufptr
< bufend
)
2026 *bufptr
++ = fp
->get();
2031 _cupsLangPrintf(stderr
,
2032 _("ppdc: Bad variable substitution ($%c) on line %d "
2033 "of %s."), ch
, fp
->line
, fp
->filename
);
2035 if (bufptr
< bufend
)
2041 // Substitute the variable value...
2043 var
= find_variable(name
);
2046 strlcpy(bufptr
, var
->value
->value
, bufend
- bufptr
+ 1);
2047 bufptr
+= strlen(bufptr
);
2051 if (!(cond_state
& PPDC_COND_SKIP
))
2052 _cupsLangPrintf(stderr
,
2053 _("ppdc: Undefined variable (%s) on line %d of "
2054 "%s."), name
, fp
->line
, fp
->filename
);
2056 snprintf(bufptr
, bufend
- bufptr
+ 1, "$%s", name
);
2057 bufptr
+= strlen(bufptr
);
2061 else if (ch
== '/' && !quote
)
2063 // Possibly a comment...
2064 nextch
= fp
->peek();
2071 while ((nextch
= fp
->get()) != EOF
)
2073 if (ch
== '*' && nextch
== '/')
2082 else if (nextch
== '/')
2085 while ((nextch
= fp
->get()) != EOF
)
2097 if (bufptr
< bufend
)
2101 else if (ch
== '\'' || ch
== '\"')
2107 // Ending the current quoted string...
2112 // Insert the opposing quote char...
2113 if (bufptr
< bufend
)
2118 // Start a new quoted string...
2119 startline
= fp
->line
;
2123 else if ((ch
== '(' || ch
== '<') && !quote
)
2127 startline
= fp
->line
;
2129 if (bufptr
< bufend
)
2132 else if ((ch
== ')' && quote
== '(') || (ch
== '>' && quote
== '<'))
2136 if (bufptr
< bufend
)
2139 else if (ch
== '\\')
2143 if ((ch
= fp
->get()) == EOF
)
2146 if (bufptr
< bufend
)
2149 else if (bufptr
< bufend
)
2155 if ((ch
== '{' || ch
== '}') && !quote
)
2162 _cupsLangPrintf(stderr
,
2163 _("ppdc: Unterminated string starting with %c on line %d "
2164 "of %s."), quote
, startline
, fp
->filename
);
2180 // 'ppdcSource::get_variable()' - Get a variable definition.
2183 ppdcVariable
* // O - Variable
2184 ppdcSource::get_variable(ppdcFile
*fp
) // I - File to read
2186 char name
[1024], // Name
2187 value
[1024]; // Value
2190 // Get the name and value:
2192 // #define name value
2193 if (!get_token(fp
, name
, sizeof(name
)))
2196 if (!get_token(fp
, value
, sizeof(value
)))
2199 // Set the variable...
2200 return (set_variable(name
, value
));
2205 // 'ppdcSource::quotef()' - Write a formatted, quoted string...
2208 int // O - Number bytes on success, -1 on failure
2209 ppdcSource::quotef(cups_file_t
*fp
, // I - File to write to
2210 const char *format
, // I - Printf-style format string
2211 ...) // I - Additional args as needed
2213 va_list ap
; // Pointer to additional arguments
2214 int bytes
; // Bytes written
2215 char sign
, // Sign of format width
2216 size
, // Size character (h, l, L)
2217 type
; // Format type character
2218 const char *bufformat
; // Start of format
2219 int width
, // Width of field
2220 prec
; // Number of characters of precision
2221 char tformat
[100]; // Temporary format string for fprintf()
2222 char *s
; // Pointer to string
2223 int slen
; // Length of string
2224 int i
; // Looping var
2227 // Range check input...
2231 // Loop through the format string, formatting as needed...
2232 va_start(ap
, format
);
2245 cupsFilePutChar(fp
, *format
++);
2249 else if (strchr(" -+#\'", *format
))
2255 while (isdigit(*format
))
2256 width
= width
* 10 + *format
++ - '0';
2263 while (isdigit(*format
))
2264 prec
= prec
* 10 + *format
++ - '0';
2269 if (*format
== 'l' && format
[1] == 'l')
2274 else if (*format
== 'h' || *format
== 'l' || *format
== 'L')
2286 case 'E' : // Floating point formats
2291 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2294 strncpy(tformat
, bufformat
, format
- bufformat
);
2295 tformat
[format
- bufformat
] = '\0';
2297 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, double));
2300 case 'B' : // Integer formats
2308 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2311 strncpy(tformat
, bufformat
, format
- bufformat
);
2312 tformat
[format
- bufformat
] = '\0';
2314 # ifdef HAVE_LONG_LONG
2316 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, long long));
2318 # endif /* HAVE_LONG_LONG */
2320 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, long));
2322 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, int));
2325 case 'p' : // Pointer value
2326 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2329 strncpy(tformat
, bufformat
, format
- bufformat
);
2330 tformat
[format
- bufformat
] = '\0';
2332 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, void *));
2335 case 'c' : // Character or character array
2339 cupsFilePutChar(fp
, va_arg(ap
, int));
2343 cupsFileWrite(fp
, va_arg(ap
, char *), width
);
2348 case 's' : // String
2349 if ((s
= va_arg(ap
, char *)) == NULL
)
2350 s
= (char *)"(nil)";
2353 if (slen
> width
&& prec
!= width
)
2361 for (i
= width
- slen
; i
> 0; i
--, bytes
++)
2362 cupsFilePutChar(fp
, ' ');
2365 for (i
= slen
; i
> 0; i
--, s
++, bytes
++)
2367 if (*s
== '\\' || *s
== '\"')
2369 cupsFilePutChar(fp
, '\\');
2373 cupsFilePutChar(fp
, *s
);
2378 for (i
= width
- slen
; i
> 0; i
--, bytes
++)
2379 cupsFilePutChar(fp
, ' ');
2386 cupsFilePutChar(fp
, *format
++);
2393 // Return the number of characters written.
2399 // 'ppdcSource::read_file()' - Read a driver source file.
2403 ppdcSource::read_file(const char *f
, // I - File to read
2404 cups_file_t
*ffp
) // I - File pointer to use
2406 ppdcFile
*fp
= new ppdcFile(f
, ffp
);
2410 if (cond_current
!= cond_stack
)
2411 _cupsLangPrintf(stderr
, _("ppdc: Missing #endif at end of \"%s\"."), f
);
2416 // 'ppdcSource::scan_file()' - Scan a driver source file.
2420 ppdcSource::scan_file(ppdcFile
*fp
, // I - File to read
2421 ppdcDriver
*td
, // I - Driver template
2422 bool inc
) // I - Including?
2424 ppdcDriver
*d
; // Current driver
2425 ppdcGroup
*g
, // Current group
2426 *mg
, // Matching group
2427 *general
, // General options group
2428 *install
; // Installable options group
2429 ppdcOption
*o
; // Current option
2430 ppdcChoice
*c
; // Current choice
2431 char temp
[256], // Token from file...
2432 *ptr
; // Pointer into token
2433 int isdefault
; // Default option?
2436 // Initialize things as needed...
2443 d
= new ppdcDriver(td
);
2445 if ((general
= d
->find_group("General")) == NULL
)
2447 general
= new ppdcGroup("General", NULL
);
2448 d
->add_group(general
);
2451 if ((install
= d
->find_group("InstallableOptions")) == NULL
)
2453 install
= new ppdcGroup("InstallableOptions", "Installable Options");
2454 d
->add_group(install
);
2457 // Loop until EOF or }
2461 while (get_token(fp
, temp
, sizeof(temp
)))
2465 // Mark the next choice as the default
2468 for (ptr
= temp
; ptr
[1]; ptr
++)
2475 // Don't mark the next choice as the default
2479 if (!_cups_strcasecmp(temp
, "}"))
2481 // Close this one out...
2484 else if (!_cups_strcasecmp(temp
, "{"))
2486 // Open a new child...
2489 else if (!_cups_strcasecmp(temp
, "#if"))
2491 if ((cond_current
- cond_stack
) >= 100)
2493 _cupsLangPrintf(stderr
,
2494 _("ppdc: Too many nested #if's on line %d of %s."),
2495 fp
->line
, fp
->filename
);
2500 if (get_integer(fp
) > 0)
2501 *cond_current
= PPDC_COND_SATISFIED
;
2504 *cond_current
= PPDC_COND_SKIP
;
2505 cond_state
|= PPDC_COND_SKIP
;
2508 else if (!_cups_strcasecmp(temp
, "#elif"))
2510 if (cond_current
== cond_stack
)
2512 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s."),
2513 fp
->line
, fp
->filename
);
2517 if (*cond_current
& PPDC_COND_SATISFIED
)
2520 *cond_current
|= PPDC_COND_SKIP
;
2522 else if (get_integer(fp
) > 0)
2524 *cond_current
|= PPDC_COND_SATISFIED
;
2525 *cond_current
&= ~PPDC_COND_SKIP
;
2528 *cond_current
|= PPDC_COND_SKIP
;
2530 // Update the current state
2531 int *cond_temp
= cond_current
; // Temporary stack pointer
2533 cond_state
= PPDC_COND_NORMAL
;
2534 while (cond_temp
> cond_stack
)
2535 if (*cond_temp
& PPDC_COND_SKIP
)
2537 cond_state
= PPDC_COND_SKIP
;
2543 else if (!_cups_strcasecmp(temp
, "#else"))
2545 if (cond_current
== cond_stack
)
2547 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s."),
2548 fp
->line
, fp
->filename
);
2552 if (*cond_current
& PPDC_COND_SATISFIED
)
2553 *cond_current
|= PPDC_COND_SKIP
;
2556 *cond_current
|= PPDC_COND_SATISFIED
;
2557 *cond_current
&= ~PPDC_COND_SKIP
;
2560 // Update the current state
2561 int *cond_temp
= cond_current
; // Temporary stack pointer
2563 cond_state
= PPDC_COND_NORMAL
;
2564 while (cond_temp
> cond_stack
)
2565 if (*cond_temp
& PPDC_COND_SKIP
)
2567 cond_state
= PPDC_COND_SKIP
;
2573 else if (!_cups_strcasecmp(temp
, "#endif"))
2575 if (cond_current
== cond_stack
)
2577 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s."),
2578 fp
->line
, fp
->filename
);
2584 // Update the current state
2585 int *cond_temp
= cond_current
; // Temporary stack pointer
2587 cond_state
= PPDC_COND_NORMAL
;
2588 while (cond_temp
> cond_stack
)
2589 if (*cond_temp
& PPDC_COND_SKIP
)
2591 cond_state
= PPDC_COND_SKIP
;
2597 else if (!_cups_strcasecmp(temp
, "#define"))
2599 // Get the variable...
2602 else if (!_cups_strcasecmp(temp
, "#include"))
2604 // #include filename
2605 char basedir
[1024], // Base directory
2606 *baseptr
, // Pointer into directory
2607 inctemp
[1024], // Initial filename
2608 incname
[1024]; // Include filename
2609 ppdcFile
*incfile
; // Include file
2610 int *old_current
= cond_current
;
2611 // Previous current stack
2614 // Get the include name...
2615 if (!get_token(fp
, inctemp
, sizeof(inctemp
)))
2617 _cupsLangPrintf(stderr
,
2618 _("ppdc: Expected include filename on line %d of "
2619 "%s."), fp
->line
, fp
->filename
);
2626 // Figure out the current directory...
2627 strlcpy(basedir
, fp
->filename
, sizeof(basedir
));
2629 if ((baseptr
= strrchr(basedir
, '/')) != NULL
)
2632 strcpy(basedir
, ".");
2634 // Find the include file...
2635 if (find_include(inctemp
, basedir
, incname
, sizeof(incname
)))
2637 // Open the include file, scan it, and then close it...
2638 incfile
= new ppdcFile(incname
);
2639 scan_file(incfile
, d
, true);
2642 if (cond_current
!= old_current
)
2643 _cupsLangPrintf(stderr
, _("ppdc: Missing #endif at end of \"%s\"."),
2649 _cupsLangPrintf(stderr
,
2650 _("ppdc: Unable to find include file \"%s\" on line %d "
2651 "of %s."), inctemp
, fp
->line
, fp
->filename
);
2655 else if (!_cups_strcasecmp(temp
, "#media"))
2657 ppdcMediaSize
*m
; // Media size
2660 // Get a media size...
2670 else if (!_cups_strcasecmp(temp
, "#po"))
2672 ppdcCatalog
*cat
; // Message catalog
2675 // Get a message catalog...
2685 else if (!_cups_strcasecmp(temp
, "Attribute") ||
2686 !_cups_strcasecmp(temp
, "LocAttribute"))
2688 ppdcAttr
*a
; // Attribute
2691 // Get an attribute...
2692 a
= get_attr(fp
, !_cups_strcasecmp(temp
, "LocAttribute"));
2701 else if (!_cups_strcasecmp(temp
, "Choice"))
2714 // Add it to the current option...
2717 _cupsLangPrintf(stderr
,
2718 _("ppdc: Choice found on line %d of %s with no "
2719 "Option."), fp
->line
, fp
->filename
);
2726 o
->set_defchoice(c
);
2728 else if (!_cups_strcasecmp(temp
, "ColorDevice"))
2730 // ColorDevice boolean
2734 d
->color_device
= get_boolean(fp
);
2736 else if (!_cups_strcasecmp(temp
, "ColorModel"))
2738 // Get the color model
2739 c
= get_color_model(fp
);
2749 // Add the choice to the ColorModel option...
2750 if ((o
= d
->find_option("ColorModel")) == NULL
)
2752 // Create the ColorModel option...
2753 o
= new ppdcOption(PPDC_PICKONE
, "ColorModel", "Color Mode", PPDC_SECTION_ANY
, 10.0f
);
2761 o
->set_defchoice(c
);
2765 else if (!_cups_strcasecmp(temp
, "ColorProfile"))
2767 ppdcProfile
*p
; // Color profile
2770 // Get the color profile...
2771 p
= get_color_profile(fp
);
2778 d
->profiles
->add(p
);
2781 else if (!_cups_strcasecmp(temp
, "Copyright"))
2784 char copytemp
[8192], // Copyright string
2785 *copyptr
, // Pointer into string
2786 *copyend
; // Pointer to end of string
2789 // Get the copyright string...
2790 if (!get_token(fp
, copytemp
, sizeof(temp
)))
2792 _cupsLangPrintf(stderr
,
2793 _("ppdc: Expected string after Copyright on line %d "
2794 "of %s."), fp
->line
, fp
->filename
);
2801 // Break it up into individual lines...
2802 for (copyptr
= copytemp
; copyptr
; copyptr
= copyend
)
2804 if ((copyend
= strchr(copyptr
, '\n')) != NULL
)
2807 d
->copyright
->add(new ppdcString(copyptr
));
2810 else if (!_cups_strcasecmp(temp
, "CustomMedia"))
2812 ppdcMediaSize
*m
; // Media size
2815 // Get a custom media size...
2816 m
= get_custom_size(fp
);
2828 d
->set_default_size(m
);
2830 else if (!_cups_strcasecmp(temp
, "Cutter"))
2833 int have_cutter
; // Have a paper cutter?
2836 have_cutter
= get_boolean(fp
);
2837 if (have_cutter
<= 0 || cond_state
)
2840 if ((o
= d
->find_option("CutMedia")) == NULL
)
2842 o
= new ppdcOption(PPDC_BOOLEAN
, "CutMedia", "Cut Media", PPDC_SECTION_ANY
, 10.0f
);
2847 c
= new ppdcChoice("False", NULL
, "<</CutMedia 0>>setpagedevice");
2849 o
->set_defchoice(c
);
2851 c
= new ppdcChoice("True", NULL
, "<</CutMedia 4>>setpagedevice");
2857 else if (!_cups_strcasecmp(temp
, "Darkness"))
2859 // Get the darkness choice...
2860 c
= get_generic(fp
, "Darkness", NULL
, "cupsCompression");
2870 // Add the choice to the cupsDarkness option...
2871 if ((o
= d
->find_option_group("cupsDarkness", &mg
)) == NULL
)
2873 // Create the cupsDarkness option...
2874 o
= new ppdcOption(PPDC_PICKONE
, "cupsDarkness", "Darkness", PPDC_SECTION_ANY
, 10.0f
);
2878 else if (mg
!= general
)
2880 _cupsLangPrintf(stderr
,
2881 _("ppdc: Option %s defined in two different groups on "
2882 "line %d of %s."), "cupsDarkness", fp
->line
,
2891 o
->set_defchoice(c
);
2895 else if (!_cups_strcasecmp(temp
, "DriverType"))
2897 int i
; // Looping var
2900 // DriverType keyword
2901 if (!get_token(fp
, temp
, sizeof(temp
)))
2903 _cupsLangPrintf(stderr
,
2904 _("ppdc: Expected driver type keyword following "
2905 "DriverType on line %d of %s."),
2906 fp
->line
, fp
->filename
);
2913 for (i
= 0; i
< (int)(sizeof(driver_types
) / sizeof(driver_types
[0])); i
++)
2914 if (!_cups_strcasecmp(temp
, driver_types
[i
]))
2917 if (i
< (int)(sizeof(driver_types
) / sizeof(driver_types
[0])))
2918 d
->type
= (ppdcDrvType
)i
;
2919 else if (!_cups_strcasecmp(temp
, "dymo"))
2920 d
->type
= PPDC_DRIVER_LABEL
;
2922 _cupsLangPrintf(stderr
,
2923 _("ppdc: Unknown driver type %s on line %d of %s."),
2924 temp
, fp
->line
, fp
->filename
);
2926 else if (!_cups_strcasecmp(temp
, "Duplex"))
2928 else if (!_cups_strcasecmp(temp
, "Filter"))
2930 ppdcFilter
*f
; // Filter
2933 // Get the filter value...
2943 else if (!_cups_strcasecmp(temp
, "Finishing"))
2945 // Get the finishing choice...
2946 c
= get_generic(fp
, "Finishing", "OutputType", NULL
);
2956 // Add the choice to the cupsFinishing option...
2957 if ((o
= d
->find_option_group("cupsFinishing", &mg
)) == NULL
)
2959 // Create the cupsFinishing option...
2960 o
= new ppdcOption(PPDC_PICKONE
, "cupsFinishing", "Finishing", PPDC_SECTION_ANY
, 10.0f
);
2964 else if (mg
!= general
)
2966 _cupsLangPrintf(stderr
,
2967 _("ppdc: Option %s defined in two different groups on "
2968 "line %d of %s."), "cupsFinishing", fp
->line
,
2977 o
->set_defchoice(c
);
2981 else if (!_cups_strcasecmp(temp
, "Font") ||
2982 !_cups_strcasecmp(temp
, "#font"))
2984 ppdcFont
*f
; // Font
2995 if (!_cups_strcasecmp(temp
, "#font"))
3001 d
->set_default_font(f
);
3005 else if (!_cups_strcasecmp(temp
, "Group"))
3008 ppdcGroup
*tempg
= get_group(fp
, d
);
3015 if (!d
->find_group(tempg
->name
->value
))
3020 if (!d
->find_group(tempg
->name
->value
))
3021 d
->add_group(tempg
);
3026 else if (!_cups_strcasecmp(temp
, "HWMargins"))
3028 // HWMargins left bottom right top
3029 d
->left_margin
= get_measurement(fp
);
3030 d
->bottom_margin
= get_measurement(fp
);
3031 d
->right_margin
= get_measurement(fp
);
3032 d
->top_margin
= get_measurement(fp
);
3034 else if (!_cups_strcasecmp(temp
, "InputSlot"))
3036 // Get the input slot choice...
3037 c
= get_generic(fp
, "InputSlot", NULL
, "MediaPosition");
3047 // Add the choice to the InputSlot option...
3049 if ((o
= d
->find_option_group("InputSlot", &mg
)) == NULL
)
3051 // Create the InputSlot option...
3052 o
= new ppdcOption(PPDC_PICKONE
, "InputSlot", "Media Source",
3053 PPDC_SECTION_ANY
, 10.0f
);
3057 else if (mg
!= general
)
3059 _cupsLangPrintf(stderr
,
3060 _("ppdc: Option %s defined in two different groups on "
3061 "line %d of %s."), "InputSlot", fp
->line
,
3070 o
->set_defchoice(c
);
3074 else if (!_cups_strcasecmp(temp
, "Installable"))
3076 // Get the installable option...
3077 o
= get_installable(fp
);
3079 // Add it as needed...
3085 install
->add_option(o
);
3090 else if (!_cups_strcasecmp(temp
, "ManualCopies"))
3092 // ManualCopies boolean
3096 d
->manual_copies
= get_boolean(fp
);
3098 else if (!_cups_strcasecmp(temp
, "Manufacturer"))
3100 // Manufacturer name
3101 char name
[256]; // Model name string
3104 if (!get_token(fp
, name
, sizeof(name
)))
3106 _cupsLangPrintf(stderr
,
3107 _("ppdc: Expected name after Manufacturer on line %d "
3108 "of %s."), fp
->line
, fp
->filename
);
3113 d
->set_manufacturer(name
);
3115 else if (!_cups_strcasecmp(temp
, "MaxSize"))
3117 // MaxSize width length
3120 get_measurement(fp
);
3121 get_measurement(fp
);
3125 d
->max_width
= get_measurement(fp
);
3126 d
->max_length
= get_measurement(fp
);
3129 else if (!_cups_strcasecmp(temp
, "MediaSize"))
3131 // MediaSize keyword
3132 char name
[41]; // Media size name
3133 ppdcMediaSize
*m
, // Matching media size...
3134 *dm
; // Driver media size...
3137 if (get_token(fp
, name
, sizeof(name
)) == NULL
)
3139 _cupsLangPrintf(stderr
,
3140 _("ppdc: Expected name after MediaSize on line %d of "
3141 "%s."), fp
->line
, fp
->filename
);
3148 m
= find_size(name
);
3152 _cupsLangPrintf(stderr
,
3153 _("ppdc: Unknown media size \"%s\" on line %d of "
3154 "%s."), name
, fp
->line
, fp
->filename
);
3158 // Add this size to the driver...
3159 dm
= new ppdcMediaSize(m
->name
->value
, m
->text
->value
,
3160 m
->width
, m
->length
, d
->left_margin
,
3161 d
->bottom_margin
, d
->right_margin
,
3166 d
->set_default_size(dm
);
3168 else if (!_cups_strcasecmp(temp
, "MediaType"))
3170 // Get the media type choice...
3171 c
= get_generic(fp
, "MediaType", "MediaType", "cupsMediaType");
3181 // Add the choice to the MediaType option...
3182 if ((o
= d
->find_option_group("MediaType", &mg
)) == NULL
)
3184 // Create the MediaType option...
3185 o
= new ppdcOption(PPDC_PICKONE
, "MediaType", "Media Type",
3186 PPDC_SECTION_ANY
, 10.0f
);
3190 else if (mg
!= general
)
3192 _cupsLangPrintf(stderr
,
3193 _("ppdc: Option %s defined in two different groups on "
3194 "line %d of %s."), "MediaType", fp
->line
,
3203 o
->set_defchoice(c
);
3207 else if (!_cups_strcasecmp(temp
, "MinSize"))
3209 // MinSize width length
3212 get_measurement(fp
);
3213 get_measurement(fp
);
3217 d
->min_width
= get_measurement(fp
);
3218 d
->min_length
= get_measurement(fp
);
3221 else if (!_cups_strcasecmp(temp
, "ModelName"))
3224 char name
[256]; // Model name string
3227 if (!get_token(fp
, name
, sizeof(name
)))
3229 _cupsLangPrintf(stderr
,
3230 _("ppdc: Expected name after ModelName on line %d of "
3231 "%s."), fp
->line
, fp
->filename
);
3236 d
->set_model_name(name
);
3238 else if (!_cups_strcasecmp(temp
, "ModelNumber"))
3240 // ModelNumber number
3244 d
->model_number
= get_integer(fp
);
3246 else if (!_cups_strcasecmp(temp
, "Option"))
3249 ppdcOption
*tempo
= get_option(fp
, d
, g
);
3256 if (!g
->find_option(tempo
->name
->value
))
3261 if (!g
->find_option(tempo
->name
->value
))
3262 g
->add_option(tempo
);
3267 else if (!_cups_strcasecmp(temp
, "FileName"))
3270 char name
[256]; // Filename string
3273 if (!get_token(fp
, name
, sizeof(name
)))
3275 _cupsLangPrintf(stderr
,
3276 _("ppdc: Expected name after FileName on line %d of "
3277 "%s."), fp
->line
, fp
->filename
);
3282 d
->set_file_name(name
);
3284 else if (!_cups_strcasecmp(temp
, "PCFileName"))
3287 char name
[256]; // PC filename string
3290 if (!get_token(fp
, name
, sizeof(name
)))
3292 _cupsLangPrintf(stderr
,
3293 _("ppdc: Expected name after PCFileName on line %d of "
3294 "%s."), fp
->line
, fp
->filename
);
3299 d
->set_pc_file_name(name
);
3301 else if (!_cups_strcasecmp(temp
, "Resolution"))
3303 // Get the resolution choice...
3304 c
= get_resolution(fp
);
3314 // Add the choice to the Resolution option...
3315 if ((o
= d
->find_option_group("Resolution", &mg
)) == NULL
)
3317 // Create the Resolution option...
3318 o
= new ppdcOption(PPDC_PICKONE
, "Resolution", NULL
, PPDC_SECTION_ANY
,
3323 else if (mg
!= general
)
3325 _cupsLangPrintf(stderr
,
3326 _("ppdc: Option %s defined in two different groups on "
3327 "line %d of %s."), "Resolution", fp
->line
,
3336 o
->set_defchoice(c
);
3340 else if (!_cups_strcasecmp(temp
, "SimpleColorProfile"))
3342 ppdcProfile
*p
; // Color profile
3345 // Get the color profile...
3346 p
= get_simple_profile(fp
);
3353 d
->profiles
->add(p
);
3356 else if (!_cups_strcasecmp(temp
, "Throughput"))
3358 // Throughput number
3362 d
->throughput
= get_integer(fp
);
3364 else if (!_cups_strcasecmp(temp
, "UIConstraints"))
3366 ppdcConstraint
*con
; // Constraint
3369 con
= get_constraint(fp
);
3376 d
->constraints
->add(con
);
3379 else if (!_cups_strcasecmp(temp
, "VariablePaperSize"))
3381 // VariablePaperSize boolean
3385 d
->variable_paper_size
= get_boolean(fp
);
3387 else if (!_cups_strcasecmp(temp
, "Version"))
3390 char name
[256]; // Model name string
3393 if (!get_token(fp
, name
, sizeof(name
)))
3395 _cupsLangPrintf(stderr
,
3396 _("ppdc: Expected string after Version on line %d of "
3397 "%s."), fp
->line
, fp
->filename
);
3402 d
->set_version(name
);
3406 _cupsLangPrintf(stderr
,
3407 _("ppdc: Unknown token \"%s\" seen on line %d of %s."),
3408 temp
, fp
->line
, fp
->filename
);
3413 // Done processing this block, is there anything to save?
3416 if (!d
->pc_file_name
|| !d
->model_name
|| !d
->manufacturer
|| !d
->version
||
3419 // Nothing to save...
3424 // Got a driver, save it...
3434 // 'ppdcSource::set_variable()' - Set a variable.
3437 ppdcVariable
* // O - Variable
3438 ppdcSource::set_variable(
3439 const char *name
, // I - Name
3440 const char *value
) // I - Value
3442 ppdcVariable
*v
; // Variable
3445 // See if the variable exists already...
3446 v
= find_variable(name
);
3449 // Change the variable value...
3450 v
->set_value(value
);
3454 // Create a new variable and add it...
3455 v
= new ppdcVariable(name
, value
);
3464 // 'ppdcSource::write_file()' - Write the current source data to a file.
3467 int // O - 0 on success, -1 on error
3468 ppdcSource::write_file(const char *f
) // I - File to write
3470 cups_file_t
*fp
; // Output file
3471 char bckname
[1024]; // Backup file
3472 ppdcDriver
*d
; // Current driver
3473 ppdcString
*st
; // Current string
3474 ppdcAttr
*a
; // Current attribute
3475 ppdcConstraint
*co
; // Current constraint
3476 ppdcFilter
*fi
; // Current filter
3477 ppdcFont
*fo
; // Current font
3478 ppdcGroup
*g
; // Current group
3479 ppdcOption
*o
; // Current option
3480 ppdcChoice
*ch
; // Current choice
3481 ppdcProfile
*p
; // Current color profile
3482 ppdcMediaSize
*si
; // Current media size
3483 float left
, // Current left margin
3484 bottom
, // Current bottom margin
3485 right
, // Current right margin
3486 top
; // Current top margin
3487 int dtused
[PPDC_DRIVER_MAX
];// Driver type usage...
3490 // Rename the current file, if any, to .bck...
3491 snprintf(bckname
, sizeof(bckname
), "%s.bck", f
);
3494 // Open the output file...
3495 fp
= cupsFileOpen(f
, "w");
3499 // Can't create file; restore backup and return...
3504 cupsFilePuts(fp
, "// CUPS PPD Compiler " CUPS_SVERSION
"\n\n");
3506 // Include standard files...
3507 cupsFilePuts(fp
, "// Include necessary files...\n");
3508 cupsFilePuts(fp
, "#include <font.defs>\n");
3509 cupsFilePuts(fp
, "#include <media.defs>\n");
3511 memset(dtused
, 0, sizeof(dtused
));
3513 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
3514 if (d
->type
> PPDC_DRIVER_PS
&& !dtused
[d
->type
])
3516 cupsFilePrintf(fp
, "#include <%s.h>\n", driver_types
[d
->type
]);
3517 dtused
[d
->type
] = 1;
3520 // Output each driver...
3521 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
3523 // Start the driver...
3524 cupsFilePrintf(fp
, "\n// %s %s\n", d
->manufacturer
->value
,
3525 d
->model_name
->value
);
3526 cupsFilePuts(fp
, "{\n");
3528 // Write the copyright stings...
3529 for (st
= (ppdcString
*)d
->copyright
->first();
3531 st
= (ppdcString
*)d
->copyright
->next())
3532 quotef(fp
, " Copyright \"%s\"\n", st
->value
);
3534 // Write other strings and values...
3535 if (d
->manufacturer
&& d
->manufacturer
->value
)
3536 quotef(fp
, " Manufacturer \"%s\"\n", d
->manufacturer
->value
);
3537 if (d
->model_name
->value
)
3538 quotef(fp
, " ModelName \"%s\"\n", d
->model_name
->value
);
3539 if (d
->file_name
&& d
->file_name
->value
)
3540 quotef(fp
, " FileName \"%s\"\n", d
->file_name
->value
);
3541 if (d
->pc_file_name
&& d
->pc_file_name
->value
)
3542 quotef(fp
, " PCFileName \"%s\"\n", d
->pc_file_name
->value
);
3543 if (d
->version
&& d
->version
->value
)
3544 quotef(fp
, " Version \"%s\"\n", d
->version
->value
);
3546 cupsFilePrintf(fp
, " DriverType %s\n", driver_types
[d
->type
]);
3548 if (d
->model_number
)
3552 case PPDC_DRIVER_LABEL
:
3553 cupsFilePuts(fp
, " ModelNumber ");
3555 switch (d
->model_number
)
3558 cupsFilePuts(fp
, "$DYMO_3x0\n");
3561 case ZEBRA_EPL_LINE
:
3562 cupsFilePuts(fp
, "$ZEBRA_EPL_LINE\n");
3565 case ZEBRA_EPL_PAGE
:
3566 cupsFilePuts(fp
, "$ZEBRA_EPL_PAGE\n");
3570 cupsFilePuts(fp
, "$ZEBRA_ZPL\n");
3574 cupsFilePuts(fp
, "$ZEBRA_CPCL\n");
3577 case INTELLITECH_PCL
:
3578 cupsFilePuts(fp
, "$INTELLITECH_PCL\n");
3582 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3587 case PPDC_DRIVER_EPSON
:
3588 cupsFilePuts(fp
, " ModelNumber ");
3590 switch (d
->model_number
)
3593 cupsFilePuts(fp
, "$EPSON_9PIN\n");
3597 cupsFilePuts(fp
, "$EPSON_24PIN\n");
3601 cupsFilePuts(fp
, "$EPSON_COLOR\n");
3605 cupsFilePuts(fp
, "$EPSON_PHOTO\n");
3609 cupsFilePuts(fp
, "$EPSON_ICOLOR\n");
3613 cupsFilePuts(fp
, "$EPSON_IPHOTO\n");
3617 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3622 case PPDC_DRIVER_HP
:
3623 cupsFilePuts(fp
, " ModelNumber ");
3624 switch (d
->model_number
)
3627 cupsFilePuts(fp
, "$HP_LASERJET\n");
3631 cupsFilePuts(fp
, "$HP_DESKJET\n");
3635 cupsFilePuts(fp
, "$HP_DESKJET2\n");
3639 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3643 cupsFilePuts(fp
, ")\n");
3647 cupsFilePrintf(fp
, " ModelNumber %d\n", d
->model_number
);
3652 if (d
->manual_copies
)
3653 cupsFilePuts(fp
, " ManualCopies Yes\n");
3655 if (d
->color_device
)
3656 cupsFilePuts(fp
, " ColorDevice Yes\n");
3659 cupsFilePrintf(fp
, " Throughput %d\n", d
->throughput
);
3661 // Output all of the attributes...
3662 for (a
= (ppdcAttr
*)d
->attrs
->first();
3664 a
= (ppdcAttr
*)d
->attrs
->next())
3665 if (a
->text
->value
&& a
->text
->value
[0])
3666 quotef(fp
, " Attribute \"%s\" \"%s/%s\" \"%s\"\n",
3667 a
->name
->value
, a
->selector
->value
? a
->selector
->value
: "",
3668 a
->text
->value
, a
->value
->value
? a
->value
->value
: "");
3670 quotef(fp
, " Attribute \"%s\" \"%s\" \"%s\"\n",
3671 a
->name
->value
, a
->selector
->value
? a
->selector
->value
: "",
3672 a
->value
->value
? a
->value
->value
: "");
3674 // Output all of the constraints...
3675 for (co
= (ppdcConstraint
*)d
->constraints
->first();
3677 co
= (ppdcConstraint
*)d
->constraints
->next())
3679 if (co
->option1
->value
[0] == '*')
3680 cupsFilePrintf(fp
, " UIConstraints \"%s %s", co
->option1
->value
,
3681 co
->choice1
->value
? co
->choice1
->value
: "");
3683 cupsFilePrintf(fp
, " UIConstraints \"*%s %s", co
->option1
->value
,
3684 co
->choice1
->value
? co
->choice1
->value
: "");
3686 if (co
->option2
->value
[0] == '*')
3687 cupsFilePrintf(fp
, " %s %s\"\n", co
->option2
->value
,
3688 co
->choice2
->value
? co
->choice2
->value
: "");
3690 cupsFilePrintf(fp
, " *%s %s\"\n", co
->option2
->value
,
3691 co
->choice2
->value
? co
->choice2
->value
: "");
3694 // Output all of the filters...
3695 for (fi
= (ppdcFilter
*)d
->filters
->first();
3697 fi
= (ppdcFilter
*)d
->filters
->next())
3698 cupsFilePrintf(fp
, " Filter \"%s %d %s\"\n",
3699 fi
->mime_type
->value
, fi
->cost
, fi
->program
->value
);
3701 // Output all of the fonts...
3702 for (fo
= (ppdcFont
*)d
->fonts
->first();
3704 fo
= (ppdcFont
*)d
->fonts
->next())
3705 if (!strcmp(fo
->name
->value
, "*"))
3706 cupsFilePuts(fp
, " Font *\n");
3708 cupsFilePrintf(fp
, " Font \"%s\" \"%s\" \"%s\" \"%s\" %s\n",
3709 fo
->name
->value
, fo
->encoding
->value
,
3710 fo
->version
->value
, fo
->charset
->value
,
3711 fo
->status
== PPDC_FONT_ROM
? "ROM" : "Disk");
3713 // Output all options...
3714 for (g
= (ppdcGroup
*)d
->groups
->first();
3716 g
= (ppdcGroup
*)d
->groups
->next())
3718 if (g
->options
->count
== 0)
3721 if (g
->text
->value
&& g
->text
->value
[0])
3722 quotef(fp
, " Group \"%s/%s\"\n", g
->name
->value
, g
->text
->value
);
3724 cupsFilePrintf(fp
, " Group \"%s\"\n", g
->name
->value
);
3726 for (o
= (ppdcOption
*)g
->options
->first();
3728 o
= (ppdcOption
*)g
->options
->next())
3730 if (o
->choices
->count
== 0)
3733 if (o
->text
->value
&& o
->text
->value
[0])
3734 quotef(fp
, " Option \"%s/%s\"", o
->name
->value
, o
->text
->value
);
3736 cupsFilePrintf(fp
, " Option \"%s\"", o
->name
->value
);
3738 cupsFilePrintf(fp
, " %s %s %.1f\n",
3739 o
->type
== PPDC_BOOLEAN
? "Boolean" :
3740 o
->type
== PPDC_PICKONE
? "PickOne" : "PickMany",
3741 o
->section
== PPDC_SECTION_ANY
? "AnySetup" :
3742 o
->section
== PPDC_SECTION_DOCUMENT
? "DocumentSetup" :
3743 o
->section
== PPDC_SECTION_EXIT
? "ExitServer" :
3744 o
->section
== PPDC_SECTION_JCL
? "JCLSetup" :
3745 o
->section
== PPDC_SECTION_PAGE
? "PageSetup" :
3749 for (ch
= (ppdcChoice
*)o
->choices
->first();
3751 ch
= (ppdcChoice
*)o
->choices
->next())
3753 if (ch
->text
->value
&& ch
->text
->value
[0])
3754 quotef(fp
, " %sChoice \"%s/%s\" \"%s\"\n",
3755 o
->defchoice
== ch
->name
? "*" : "",
3756 ch
->name
->value
, ch
->text
->value
,
3757 ch
->code
->value
? ch
->code
->value
: "");
3759 quotef(fp
, " %sChoice \"%s\" \"%s\"\n",
3760 o
->defchoice
== ch
->name
? "*" : "",
3762 ch
->code
->value
? ch
->code
->value
: "");
3767 // Output all of the color profiles...
3768 for (p
= (ppdcProfile
*)d
->profiles
->first();
3770 p
= (ppdcProfile
*)d
->profiles
->next())
3771 cupsFilePrintf(fp
, " ColorProfile \"%s/%s\" %.3f %.3f "
3772 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
3773 p
->resolution
->value
, p
->media_type
->value
,
3774 p
->density
, p
->gamma
,
3775 p
->profile
[0], p
->profile
[1], p
->profile
[2],
3776 p
->profile
[3], p
->profile
[4], p
->profile
[5],
3777 p
->profile
[6], p
->profile
[7], p
->profile
[8]);
3779 // Output all of the media sizes...
3785 for (si
= (ppdcMediaSize
*)d
->sizes
->first();
3787 si
= (ppdcMediaSize
*)d
->sizes
->next())
3788 if (si
->size_code
->value
&& si
->region_code
->value
)
3790 // Output a custom media size...
3791 quotef(fp
, " %sCustomMedia \"%s/%s\" %.2f %.2f %.2f %.2f %.2f %.2f \"%s\" \"%s\"\n",
3792 si
->name
== d
->default_size
? "*" : "", si
->name
->value
,
3793 si
->text
->value
, si
->width
, si
->length
, si
->left
, si
->bottom
,
3794 si
->right
, si
->top
, si
->size_code
->value
,
3795 si
->region_code
->value
);
3799 // Output a standard media size...
3800 if (fabs(left
- si
->left
) > 0.1 ||
3801 fabs(bottom
- si
->bottom
) > 0.1 ||
3802 fabs(right
- si
->right
) > 0.1 ||
3803 fabs(top
- si
->top
) > 0.1)
3805 cupsFilePrintf(fp
, " HWMargins %.2f %.2f %.2f %.2f\n",
3806 si
->left
, si
->bottom
, si
->right
, si
->top
);
3809 bottom
= si
->bottom
;
3814 cupsFilePrintf(fp
, " %sMediaSize %s\n",
3815 si
->name
== d
->default_size
? "*" : "",
3819 if (d
->variable_paper_size
)
3821 cupsFilePuts(fp
, " VariablePaperSize Yes\n");
3823 if (fabs(left
- d
->left_margin
) > 0.1 ||
3824 fabs(bottom
- d
->bottom_margin
) > 0.1 ||
3825 fabs(right
- d
->right_margin
) > 0.1 ||
3826 fabs(top
- d
->top_margin
) > 0.1)
3828 cupsFilePrintf(fp
, " HWMargins %.2f %.2f %.2f %.2f\n",
3829 d
->left_margin
, d
->bottom_margin
, d
->right_margin
,
3833 cupsFilePrintf(fp
, " MinSize %.2f %.2f\n", d
->min_width
, d
->min_length
);
3834 cupsFilePrintf(fp
, " MaxSize %.2f %.2f\n", d
->max_width
, d
->max_length
);
3837 // End the driver...
3838 cupsFilePuts(fp
, "}\n");
3841 // Close the file and return...