]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc-source.cxx
4 // Source class for the CUPS PPD Compiler.
6 // Copyright 2007-2009 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_size() - Find a media size.
23 // ppdcSource::find_variable() - Find a variable.
24 // ppdcSource::get_attr() - Get an attribute.
25 // ppdcSource::get_boolean() - Get a boolean value.
26 // ppdcSource::get_choice() - Get a choice.
27 // ppdcSource::get_color_model() - Get an old-style color model option.
28 // ppdcSource::get_color_order() - Get an old-style color order value.
29 // ppdcSource::get_color_profile() - Get a color profile definition.
30 // ppdcSource::get_color_space() - Get an old-style colorspace value.
31 // ppdcSource::get_constraint() - Get a constraint.
32 // ppdcSource::get_custom_size() - Get a custom media size definition
34 // ppdcSource::get_filter() - Get a filter.
35 // ppdcSource::get_float() - Get a single floating-point number.
36 // ppdcSource::get_font() - Get a font definition.
37 // ppdcSource::get_generic() - Get a generic old-style option.
38 // ppdcSource::get_group() - Get an option group.
39 // ppdcSource::get_installable() - Get an installable option.
40 // ppdcSource::get_integer() - Get an integer value from a string.
41 // ppdcSource::get_integer() - Get an integer value from a file.
42 // ppdcSource::get_measurement() - Get a measurement value.
43 // ppdcSource::get_option() - Get an option definition.
44 // ppdcSource::get_resolution() - Get an old-style resolution option.
45 // ppdcSource::get_simple_profile() - Get a simple color profile definition.
46 // ppdcSource::get_size() - Get a media size definition from a file.
47 // ppdcSource::get_token() - Get a token from a file.
48 // ppdcSource::get_variable() - Get a variable definition.
49 // ppdcSource::quotef() - Write a formatted, quoted string...
50 // ppdcSource::read_file() - Read a driver source file.
51 // ppdcSource::scan_file() - Scan a driver source file.
52 // ppdcSource::set_variable() - Set a variable.
53 // ppdcSource::write_file() - Write the current source data to a file.
57 // Include necessary headers...
61 #include <cups/globals.h>
65 #include <cups/raster.h>
66 #include "data/epson.h"
67 #include "data/escp.h"
69 #include "data/label.h"
77 ppdcArray
*ppdcSource::includes
= 0;
78 const char *ppdcSource::driver_types
[] =
91 // 'ppdcSource::ppdcSource()' - Load a driver source file.
94 ppdcSource::ppdcSource(const char *f
, // I - File to read
95 cups_file_t
*ffp
)// I - File pointer to use
97 filename
= new ppdcString(f
);
98 base_fonts
= new ppdcArray();
99 drivers
= new ppdcArray();
100 po_files
= new ppdcArray();
101 sizes
= new ppdcArray();
102 vars
= new ppdcArray();
103 cond_state
= PPDC_COND_NORMAL
;
104 cond_current
= cond_stack
;
105 cond_stack
[0] = PPDC_COND_NORMAL
;
113 // 'ppdcSource::~ppdcSource()' - Free a driver source file.
116 ppdcSource::~ppdcSource()
119 base_fonts
->release();
128 // 'ppdcSource::add_include()' - Add an include directory.
132 ppdcSource::add_include(const char *d
) // I - Include directory
138 includes
= new ppdcArray();
140 includes
->add(new ppdcString(d
));
145 // 'ppdcSource::find_driver()' - Find a driver.
148 ppdcDriver
* // O - Driver
149 ppdcSource::find_driver(const char *f
) // I - Driver file name
151 ppdcDriver
*d
; // Current driver
154 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
155 if (!strcasecmp(f
, d
->pc_file_name
->value
))
163 // 'ppdcSource::find_include()' - Find an include file.
166 char * // O - Found path or NULL
167 ppdcSource::find_include(
168 const char *f
, // I - Include filename
169 const char *base
, // I - Current directory
170 char *n
, // I - Path buffer
171 int nlen
) // I - Path buffer length
173 ppdcString
*dir
; // Include directory
174 char temp
[1024], // Temporary path
175 *ptr
; // Pointer to end of path
178 // Range check input...
179 if (!f
|| !*f
|| !n
|| nlen
< 2)
182 // Check the first character to see if we have <name> or "name"...
185 // Remove the surrounding <> from the name...
186 strlcpy(temp
, f
+ 1, sizeof(temp
));
187 ptr
= temp
+ strlen(temp
) - 1;
191 _cupsLangPrintf(stderr
,
192 _("ppdc: Invalid #include/#po filename \"%s\"!\n"), n
);
201 // Check for the local file relative to the current directory...
202 if (base
&& *base
&& f
[0] != '/')
203 snprintf(n
, nlen
, "%s/%s", base
, f
);
211 // Absolute path that doesn't exist...
216 // Search the include directories, if any...
219 for (dir
= (ppdcString
*)includes
->first(); dir
; dir
= (ppdcString
*)includes
->next())
221 snprintf(n
, nlen
, "%s/%s", dir
->value
, f
);
227 // Search the standard include directories...
228 _cups_globals_t
*cg
= _cupsGlobals(); // Global data
230 snprintf(n
, nlen
, "%s/ppdc/%s", cg
->cups_datadir
, f
);
234 snprintf(n
, nlen
, "%s/po/%s", cg
->cups_datadir
, f
);
243 // 'ppdcSource::find_po()' - Find a message catalog for the given locale...
246 ppdcCatalog
* // O - Message catalog or NULL
247 ppdcSource::find_po(const char *l
) // I - Locale name
249 ppdcCatalog
*cat
; // Current message catalog
252 for (cat
= (ppdcCatalog
*)po_files
->first();
254 cat
= (ppdcCatalog
*)po_files
->next())
255 if (!strcasecmp(l
, cat
->locale
->value
))
263 // 'ppdcSource::find_size()' - Find a media size.
266 ppdcMediaSize
* // O - Size
267 ppdcSource::find_size(const char *s
) // I - Size name
269 ppdcMediaSize
*m
; // Current media size
272 for (m
= (ppdcMediaSize
*)sizes
->first(); m
; m
= (ppdcMediaSize
*)sizes
->next())
273 if (!strcasecmp(s
, m
->name
->value
))
281 // 'ppdcSource::find_variable()' - Find a variable.
284 ppdcVariable
* // O - Variable
285 ppdcSource::find_variable(const char *n
)// I - Variable name
287 ppdcVariable
*v
; // Current variable
290 for (v
= (ppdcVariable
*)vars
->first(); v
; v
= (ppdcVariable
*)vars
->next())
291 if (!strcasecmp(n
, v
->name
->value
))
299 // 'ppdcSource::get_attr()' - Get an attribute.
302 ppdcAttr
* // O - Attribute
303 ppdcSource::get_attr(ppdcFile
*fp
, // I - File to read
304 bool loc
) // I - Localize this attribute?
306 char name
[1024], // Name string
307 selector
[1024], // Selector string
308 *text
, // Text string
309 value
[1024]; // Value string
312 // Get the attribute parameters:
314 // Attribute name selector value
315 if (!get_token(fp
, name
, sizeof(name
)))
317 _cupsLangPrintf(stderr
,
318 _("ppdc: Expected name after %s on line %d of %s!\n"),
319 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
323 if (!get_token(fp
, selector
, sizeof(selector
)))
325 _cupsLangPrintf(stderr
,
326 _("ppdc: Expected selector after %s on line %d of %s!\n"),
327 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
331 if ((text
= strchr(selector
, '/')) != NULL
)
334 if (!get_token(fp
, value
, sizeof(value
)))
336 _cupsLangPrintf(stderr
,
337 _("ppdc: Expected value after %s on line %d of %s!\n"),
338 loc
? "LocAttribute" : "Attribute", fp
->line
, fp
->filename
);
342 return (new ppdcAttr(name
, selector
, text
, value
, loc
));
347 // 'ppdcSource::get_boolean()' - Get a boolean value.
350 int // O - Boolean value
351 ppdcSource::get_boolean(ppdcFile
*fp
) // I - File to read
353 char buffer
[256]; // String buffer
356 if (!get_token(fp
, buffer
, sizeof(buffer
)))
358 _cupsLangPrintf(stderr
,
359 _("ppdc: Expected boolean value on line %d of %s.\n"),
360 fp
->line
, fp
->filename
);
364 if (!strcasecmp(buffer
, "on") ||
365 !strcasecmp(buffer
, "yes") ||
366 !strcasecmp(buffer
, "true"))
368 else if (!strcasecmp(buffer
, "off") ||
369 !strcasecmp(buffer
, "no") ||
370 !strcasecmp(buffer
, "false"))
374 _cupsLangPrintf(stderr
,
375 _("ppdc: Bad boolean value (%s) on line %d of %s.\n"),
376 buffer
, fp
->line
, fp
->filename
);
383 // 'ppdcSource::get_choice()' - Get a choice.
386 ppdcChoice
* // O - Choice data
387 ppdcSource::get_choice(ppdcFile
*fp
) // I - File to read
389 char name
[1024], // Name
394 // Read a choice from the file:
396 // Choice name/text code
397 if (!get_token(fp
, name
, sizeof(name
)))
399 _cupsLangPrintf(stderr
,
400 _("ppdc: Expected choice name/text on line %d of %s.\n"),
401 fp
->line
, fp
->filename
);
405 if ((text
= strchr(name
, '/')) != NULL
)
410 if (!get_token(fp
, code
, sizeof(code
)))
412 _cupsLangPrintf(stderr
, _("ppdc: Expected choice code on line %d of %s.\n"),
413 fp
->line
, fp
->filename
);
417 // Return the new choice
418 return (new ppdcChoice(name
, text
, code
));
423 // 'ppdcSource::get_color_model()' - Get an old-style color model option.
426 ppdcChoice
* // O - Choice data
427 ppdcSource::get_color_model(ppdcFile
*fp
)
430 char name
[1024], // Option name
431 *text
, // Text option
432 temp
[256]; // Temporary string
433 int color_space
, // Colorspace
434 color_order
, // Color order
435 compression
; // Compression mode
438 // Get the ColorModel parameters:
440 // ColorModel name/text colorspace colororder compression
441 if (!get_token(fp
, name
, sizeof(name
)))
443 _cupsLangPrintf(stderr
,
444 _("ppdc: Expected name/text combination for ColorModel on "
445 "line %d of %s!\n"), fp
->line
, fp
->filename
);
449 if ((text
= strchr(name
, '/')) != NULL
)
454 if (!get_token(fp
, temp
, sizeof(temp
)))
456 _cupsLangPrintf(stderr
,
457 _("ppdc: Expected colorspace for ColorModel on line %d of "
458 "%s!\n"), fp
->line
, fp
->filename
);
462 if ((color_space
= get_color_space(temp
)) < 0)
463 color_space
= get_integer(temp
);
465 if (!get_token(fp
, temp
, sizeof(temp
)))
467 _cupsLangPrintf(stderr
,
468 _("ppdc: Expected color order for ColorModel on line %d of "
469 "%s!\n"), fp
->line
, fp
->filename
);
473 if ((color_order
= get_color_order(temp
)) < 0)
474 color_order
= get_integer(temp
);
476 if (!get_token(fp
, temp
, sizeof(temp
)))
478 _cupsLangPrintf(stderr
,
479 _("ppdc: Expected compression for ColorModel on line %d of "
480 "%s!\n"), fp
->line
, fp
->filename
);
484 compression
= get_integer(temp
);
486 snprintf(temp
, sizeof(temp
),
487 "<</cupsColorSpace %d/cupsColorOrder %d/cupsCompression %d>>"
489 color_space
, color_order
, compression
);
491 return (new ppdcChoice(name
, text
, temp
));
496 // 'ppdcSource::get_color_order()' - Get an old-style color order value.
499 int // O - Color order value
500 ppdcSource::get_color_order(
501 const char *co
) // I - Color order string
503 if (!strcasecmp(co
, "chunked") ||
504 !strcasecmp(co
, "chunky"))
505 return (CUPS_ORDER_CHUNKED
);
506 else if (!strcasecmp(co
, "banded"))
507 return (CUPS_ORDER_BANDED
);
508 else if (!strcasecmp(co
, "planar"))
509 return (CUPS_ORDER_PLANAR
);
516 // 'ppdcSource::get_color_profile()' - Get a color profile definition.
519 ppdcProfile
* // O - Color profile
520 ppdcSource::get_color_profile(
521 ppdcFile
*fp
) // I - File to read
523 char resolution
[1024], // Resolution/media type
524 *media_type
; // Media type
525 int i
; // Looping var
526 float g
, // Gamma value
528 m
[9]; // Transform matrix
531 // Get the ColorProfile parameters:
533 // ColorProfile resolution/mediatype gamma density m00 m01 m02 ... m22
534 if (!get_token(fp
, resolution
, sizeof(resolution
)))
536 _cupsLangPrintf(stderr
,
537 _("ppdc: Expected resolution/mediatype following "
538 "ColorProfile on line %d of %s!\n"),
539 fp
->line
, fp
->filename
);
543 if ((media_type
= strchr(resolution
, '/')) != NULL
)
544 *media_type
++ = '\0';
546 media_type
= resolution
;
550 for (i
= 0; i
< 9; i
++)
551 m
[i
] = get_float(fp
);
553 return (new ppdcProfile(resolution
, media_type
, g
, d
, m
));
558 // 'ppdcSource::get_color_space()' - Get an old-style colorspace value.
561 int // O - Colorspace value
562 ppdcSource::get_color_space(
563 const char *cs
) // I - Colorspace string
565 if (!strcasecmp(cs
, "w"))
566 return (CUPS_CSPACE_W
);
567 else if (!strcasecmp(cs
, "rgb"))
568 return (CUPS_CSPACE_RGB
);
569 else if (!strcasecmp(cs
, "rgba"))
570 return (CUPS_CSPACE_RGBA
);
571 else if (!strcasecmp(cs
, "k"))
572 return (CUPS_CSPACE_K
);
573 else if (!strcasecmp(cs
, "cmy"))
574 return (CUPS_CSPACE_CMY
);
575 else if (!strcasecmp(cs
, "ymc"))
576 return (CUPS_CSPACE_YMC
);
577 else if (!strcasecmp(cs
, "cmyk"))
578 return (CUPS_CSPACE_CMYK
);
579 else if (!strcasecmp(cs
, "ymck"))
580 return (CUPS_CSPACE_YMCK
);
581 else if (!strcasecmp(cs
, "kcmy"))
582 return (CUPS_CSPACE_KCMY
);
583 else if (!strcasecmp(cs
, "kcmycm"))
584 return (CUPS_CSPACE_KCMYcm
);
585 else if (!strcasecmp(cs
, "gmck"))
586 return (CUPS_CSPACE_GMCK
);
587 else if (!strcasecmp(cs
, "gmcs"))
588 return (CUPS_CSPACE_GMCS
);
589 else if (!strcasecmp(cs
, "white"))
590 return (CUPS_CSPACE_WHITE
);
591 else if (!strcasecmp(cs
, "gold"))
592 return (CUPS_CSPACE_GOLD
);
593 else if (!strcasecmp(cs
, "silver"))
594 return (CUPS_CSPACE_SILVER
);
595 else if (!strcasecmp(cs
, "CIEXYZ"))
596 return (CUPS_CSPACE_CIEXYZ
);
597 else if (!strcasecmp(cs
, "CIELab"))
598 return (CUPS_CSPACE_CIELab
);
599 else if (!strcasecmp(cs
, "RGBW"))
600 return (CUPS_CSPACE_RGBW
);
601 else if (!strcasecmp(cs
, "ICC1"))
602 return (CUPS_CSPACE_ICC1
);
603 else if (!strcasecmp(cs
, "ICC2"))
604 return (CUPS_CSPACE_ICC2
);
605 else if (!strcasecmp(cs
, "ICC3"))
606 return (CUPS_CSPACE_ICC3
);
607 else if (!strcasecmp(cs
, "ICC4"))
608 return (CUPS_CSPACE_ICC4
);
609 else if (!strcasecmp(cs
, "ICC5"))
610 return (CUPS_CSPACE_ICC5
);
611 else if (!strcasecmp(cs
, "ICC6"))
612 return (CUPS_CSPACE_ICC6
);
613 else if (!strcasecmp(cs
, "ICC7"))
614 return (CUPS_CSPACE_ICC7
);
615 else if (!strcasecmp(cs
, "ICC8"))
616 return (CUPS_CSPACE_ICC8
);
617 else if (!strcasecmp(cs
, "ICC9"))
618 return (CUPS_CSPACE_ICC9
);
619 else if (!strcasecmp(cs
, "ICCA"))
620 return (CUPS_CSPACE_ICCA
);
621 else if (!strcasecmp(cs
, "ICCB"))
622 return (CUPS_CSPACE_ICCB
);
623 else if (!strcasecmp(cs
, "ICCC"))
624 return (CUPS_CSPACE_ICCC
);
625 else if (!strcasecmp(cs
, "ICCD"))
626 return (CUPS_CSPACE_ICCD
);
627 else if (!strcasecmp(cs
, "ICCE"))
628 return (CUPS_CSPACE_ICCE
);
629 else if (!strcasecmp(cs
, "ICCF"))
630 return (CUPS_CSPACE_ICCF
);
637 // 'ppdcSource::get_constraint()' - Get a constraint.
640 ppdcConstraint
* // O - Constraint
641 ppdcSource::get_constraint(ppdcFile
*fp
)// I - File to read
643 char temp
[1024], // One string to rule them all
644 *ptr
, // Pointer into string
645 *option1
, // Constraint option 1
646 *choice1
, // Constraint choice 1
647 *option2
, // Constraint option 2
648 *choice2
; // Constraint choice 2
651 // Read the UIConstaints parameter in one of the following forms:
653 // UIConstraints "*Option1 *Option2"
654 // UIConstraints "*Option1 Choice1 *Option2"
655 // UIConstraints "*Option1 *Option2 Choice2"
656 // UIConstraints "*Option1 Choice1 *Option2 Choice2"
657 if (!get_token(fp
, temp
, sizeof(temp
)))
659 _cupsLangPrintf(stderr
,
660 _("ppdc: Expected constraints string for UIConstraints on "
661 "line %d of %s!\n"), fp
->line
, fp
->filename
);
665 for (ptr
= temp
; isspace(*ptr
); ptr
++);
669 _cupsLangPrintf(stderr
,
670 _("ppdc: Option constraint must *name on line %d of %s!\n"),
671 fp
->line
, fp
->filename
);
677 for (; *ptr
&& !isspace(*ptr
); ptr
++);
678 for (; isspace(*ptr
); *ptr
++ = '\0');
684 for (; *ptr
&& !isspace(*ptr
); ptr
++);
685 for (; isspace(*ptr
); *ptr
++ = '\0');
692 _cupsLangPrintf(stderr
,
693 _("ppdc: Expected two option names on line %d of %s!\n"),
694 fp
->line
, fp
->filename
);
700 for (; *ptr
&& !isspace(*ptr
); ptr
++);
701 for (; isspace(*ptr
); *ptr
++ = '\0');
708 return (new ppdcConstraint(option1
, choice1
, option2
, choice2
));
713 // 'ppdcSource::get_custom_size()' - Get a custom media size definition from a file.
716 ppdcMediaSize
* // O - Media size
717 ppdcSource::get_custom_size(ppdcFile
*fp
)
720 char name
[1024], // Name
722 size_code
[10240], // PageSize code
723 region_code
[10240]; // PageRegion
724 float width
, // Width
727 bottom
, // Bottom margin
728 right
, // Right margin
732 // Get the name, text, width, length, margins, and code:
734 // CustomMedia name/text width length left bottom right top size-code region-code
735 if (!get_token(fp
, name
, sizeof(name
)))
738 if ((text
= strchr(name
, '/')) != NULL
)
743 if ((width
= get_measurement(fp
)) < 0.0f
)
746 if ((length
= get_measurement(fp
)) < 0.0f
)
749 if ((left
= get_measurement(fp
)) < 0.0f
)
752 if ((bottom
= get_measurement(fp
)) < 0.0f
)
755 if ((right
= get_measurement(fp
)) < 0.0f
)
758 if ((top
= get_measurement(fp
)) < 0.0f
)
761 if (!get_token(fp
, size_code
, sizeof(size_code
)))
764 if (!get_token(fp
, region_code
, sizeof(region_code
)))
767 // Return the new media size...
768 return (new ppdcMediaSize(name
, text
, width
, length
, left
, bottom
,
769 right
, top
, size_code
, region_code
));
774 // 'ppdcSource::get_duplex()' - Get a duplex option.
778 ppdcSource::get_duplex(ppdcFile
*fp
, // I - File to read from
779 ppdcDriver
*d
) // I - Current driver
781 char temp
[256]; // Duplex keyword
782 ppdcAttr
*attr
; // cupsFlipDuplex attribute
783 ppdcGroup
*g
; // Current group
784 ppdcOption
*o
; // Duplex option
787 // Duplex {boolean|none|normal|flip}
788 if (!get_token(fp
, temp
, sizeof(temp
)))
790 _cupsLangPrintf(stderr
,
791 _("ppdc: Expected duplex type after Duplex on line %d of "
792 "%s!\n"), fp
->line
, fp
->filename
);
799 if (!strcasecmp(temp
, "none") || !strcasecmp(temp
, "false") ||
800 !strcasecmp(temp
, "no") || !strcasecmp(temp
, "off"))
802 g
= d
->find_group("General");
803 if ((o
= g
->find_option("Duplex")) != NULL
)
804 g
->options
->remove(o
);
806 for (attr
= (ppdcAttr
*)d
->attrs
->first();
808 attr
= (ppdcAttr
*)d
->attrs
->next())
809 if (!strcmp(attr
->name
->value
, "cupsFlipDuplex"))
811 d
->attrs
->remove(attr
);
815 else if (!strcasecmp(temp
, "normal") || !strcasecmp(temp
, "true") ||
816 !strcasecmp(temp
, "yes") || !strcasecmp(temp
, "on") ||
817 !strcasecmp(temp
, "flip") || !strcasecmp(temp
, "rotated") ||
818 !strcasecmp(temp
, "manualtumble"))
820 g
= d
->find_group("General");
821 o
= g
->find_option("Duplex");
825 o
= new ppdcOption(PPDC_PICKONE
, "Duplex", "2-Sided Printing",
826 !strcasecmp(temp
, "flip") ? PPDC_SECTION_PAGE
:
827 PPDC_SECTION_ANY
, 10.0f
);
828 o
->add_choice(new ppdcChoice("None", "Off (1-Sided)",
829 "<</Duplex false>>setpagedevice"));
830 o
->add_choice(new ppdcChoice("DuplexNoTumble", "Long-Edge (Portrait)",
831 "<</Duplex true/Tumble false>>setpagedevice"));
832 o
->add_choice(new ppdcChoice("DuplexTumble", "Short-Edge (Landscape)",
833 "<</Duplex true/Tumble true>>setpagedevice"));
838 for (attr
= (ppdcAttr
*)d
->attrs
->first();
840 attr
= (ppdcAttr
*)d
->attrs
->next())
841 if (!strcmp(attr
->name
->value
, "cupsFlipDuplex"))
843 if (strcasecmp(temp
, "flip"))
844 d
->attrs
->remove(attr
);
848 if (!strcasecmp(temp
, "flip") && !attr
)
849 d
->add_attr(new ppdcAttr("cupsFlipDuplex", NULL
, NULL
, "true"));
851 for (attr
= (ppdcAttr
*)d
->attrs
->first();
853 attr
= (ppdcAttr
*)d
->attrs
->next())
854 if (!strcmp(attr
->name
->value
, "cupsBackSide"))
856 d
->attrs
->remove(attr
);
860 if (!strcasecmp(temp
, "flip"))
861 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Flipped"));
862 else if (!strcasecmp(temp
, "rotated"))
863 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Rotated"));
864 else if (!strcasecmp(temp
, "manualtumble"))
865 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "ManualTumble"));
867 d
->add_attr(new ppdcAttr("cupsBackSide", NULL
, NULL
, "Normal"));
870 _cupsLangPrintf(stderr
,
871 _("ppdc: Unknown duplex type \"%s\" on line %d of %s!\n"),
872 temp
, fp
->line
, fp
->filename
);
877 // 'ppdcSource::get_filter()' - Get a filter.
880 ppdcFilter
* // O - Filter
881 ppdcSource::get_filter(ppdcFile
*fp
) // I - File to read
883 char type
[1024], // MIME type
884 program
[1024], // Filter program
885 *ptr
; // Pointer into MIME type
886 int cost
; // Relative cost
889 // Read filter parameters in one of the following formats:
891 // Filter "type cost program"
892 // Filter type cost program
894 if (!get_token(fp
, type
, sizeof(type
)))
896 _cupsLangPrintf(stderr
,
897 _("ppdc: Expected a filter definition on line %d of %s!\n"),
898 fp
->line
, fp
->filename
);
902 if ((ptr
= strchr(type
, ' ')) != NULL
)
904 // Old-style filter definition in one string...
906 cost
= strtol(ptr
, &ptr
, 10);
908 while (isspace(*ptr
))
911 strcpy(program
, ptr
);
915 cost
= get_integer(fp
);
917 if (!get_token(fp
, program
, sizeof(program
)))
919 _cupsLangPrintf(stderr
,
920 _("ppdc: Expected a program name on line %d of %s!\n"),
921 fp
->line
, fp
->filename
);
928 _cupsLangPrintf(stderr
,
929 _("ppdc: Invalid empty MIME type for filter on line %d of "
930 "%s!\n"), fp
->line
, fp
->filename
);
934 if (cost
< 0 || cost
> 200)
936 _cupsLangPrintf(stderr
,
937 _("ppdc: Invalid cost for filter on line %d of %s!\n"),
938 fp
->line
, fp
->filename
);
944 _cupsLangPrintf(stderr
,
945 _("ppdc: Invalid empty program name for filter on line %d "
946 "of %s!\n"), fp
->line
, fp
->filename
);
950 return (new ppdcFilter(type
, program
, cost
));
955 // 'ppdcSource::get_float()' - Get a single floating-point number.
959 ppdcSource::get_float(ppdcFile
*fp
) // I - File to read
961 char temp
[256], // String buffer
962 *ptr
; // Pointer into buffer
963 float val
; // Floating point value
966 // Get the number from the file and range-check...
967 if (!get_token(fp
, temp
, sizeof(temp
)))
969 _cupsLangPrintf(stderr
, _("ppdc: Expected real number on line %d of %s!\n"),
970 fp
->line
, fp
->filename
);
974 val
= (float)strtod(temp
, &ptr
);
978 _cupsLangPrintf(stderr
,
979 _("ppdc: Unknown trailing characters in real number \"%s\" "
980 "on line %d of %s!\n"), temp
, fp
->line
, fp
->filename
);
989 // 'ppdcSource::get_font()' - Get a font definition.
992 ppdcFont
* // O - Font data
993 ppdcSource::get_font(ppdcFile
*fp
) // I - File to read
995 char name
[256], // Font name
996 encoding
[256], // Font encoding
997 version
[256], // Font version
998 charset
[256], // Font charset
999 temp
[256]; // Font status string
1000 ppdcFontStatus status
; // Font status enumeration
1003 // Read font parameters as follows:
1006 // Font name encoding version charset status
1007 // %font name encoding version charset status
1009 // "Name" is the PostScript font name.
1011 // "Encoding" is the default encoding of the font: Standard, ISOLatin1,
1012 // Special, Expert, ExpertSubset, etc.
1014 // "Version" is the version number string.
1016 // "Charset" specifies the characters that are included in the font:
1017 // Standard, Special, Expert, Adobe-Identity, etc.
1019 // "Status" is the keyword ROM or Disk.
1020 if (!get_token(fp
, name
, sizeof(name
)))
1022 _cupsLangPrintf(stderr
,
1023 _("ppdc: Expected name after Font on line %d of %s!\n"),
1024 fp
->line
, fp
->filename
);
1028 if (!strcmp(name
, "*"))
1030 // Include all base fonts...
1034 status
= PPDC_FONT_ROM
;
1038 // Load a full font definition...
1039 if (!get_token(fp
, encoding
, sizeof(encoding
)))
1041 _cupsLangPrintf(stderr
,
1042 _("ppdc: Expected encoding after Font on line %d of "
1043 "%s!\n"), fp
->line
, fp
->filename
);
1047 if (!get_token(fp
, version
, sizeof(version
)))
1049 _cupsLangPrintf(stderr
,
1050 _("ppdc: Expected version after Font on line %d of "
1051 "%s!\n"), fp
->line
, fp
->filename
);
1055 if (!get_token(fp
, charset
, sizeof(charset
)))
1057 _cupsLangPrintf(stderr
,
1058 _("ppdc: Expected charset after Font on line %d of "
1059 "%s!\n"), fp
->line
, fp
->filename
);
1063 if (!get_token(fp
, temp
, sizeof(temp
)))
1065 _cupsLangPrintf(stderr
,
1066 _("ppdc: Expected status after Font on line %d of %s!\n"),
1067 fp
->line
, fp
->filename
);
1071 if (!strcasecmp(temp
, "ROM"))
1072 status
= PPDC_FONT_ROM
;
1073 else if (!strcasecmp(temp
, "Disk"))
1074 status
= PPDC_FONT_DISK
;
1077 _cupsLangPrintf(stderr
,
1078 _("ppdc: Bad status keyword %s on line %d of %s!\n"),
1079 temp
, fp
->line
, fp
->filename
);
1084 // printf("Font %s %s %s %s %s\n", name, encoding, version, charset, temp);
1086 return (new ppdcFont(name
, encoding
, version
, charset
, status
));
1091 // 'ppdcSource::get_generic()' - Get a generic old-style option.
1094 ppdcChoice
* // O - Choice data
1095 ppdcSource::get_generic(ppdcFile
*fp
, // I - File to read
1096 const char *keyword
,
1099 // I - Text attribute
1101 // I - Numeric attribute
1103 char name
[1024], // Name
1105 command
[256]; // Command string
1106 int val
; // Numeric value
1109 // Read one of the following parameters:
1112 // Foo integer name/text
1114 val
= get_integer(fp
);
1118 if (!get_token(fp
, name
, sizeof(name
)))
1120 _cupsLangPrintf(stderr
,
1121 _("ppdc: Expected name/text after %s on line %d of %s!\n"),
1122 keyword
, fp
->line
, fp
->filename
);
1126 if ((text
= strchr(name
, '/')) != NULL
)
1134 snprintf(command
, sizeof(command
),
1135 "<</%s(%s)/%s %d>>setpagedevice",
1136 tattr
, name
, nattr
, val
);
1138 snprintf(command
, sizeof(command
),
1139 "<</%s %d>>setpagedevice",
1143 snprintf(command
, sizeof(command
),
1144 "<</%s(%s)>>setpagedevice",
1147 return (new ppdcChoice(name
, text
, command
));
1152 // 'ppdcSource::get_group()' - Get an option group.
1155 ppdcGroup
* // O - Group
1156 ppdcSource::get_group(ppdcFile
*fp
, // I - File to read
1157 ppdcDriver
*d
) // I - Printer driver
1159 char name
[1024], // UI name
1161 ppdcGroup
*g
; // Group
1164 // Read the Group parameters:
1167 if (!get_token(fp
, name
, sizeof(name
)))
1169 _cupsLangPrintf(stderr
,
1170 _("ppdc: Expected group name/text on line %d of %s!\n"),
1171 fp
->line
, fp
->filename
);
1175 if ((text
= strchr(name
, '/')) != NULL
)
1180 // See if the group already exists...
1181 if ((g
= d
->find_group(name
)) == NULL
)
1183 // Nope, add a new one...
1184 g
= new ppdcGroup(name
, text
);
1192 // 'ppdcSource::get_installable()' - Get an installable option.
1195 ppdcOption
* // O - Option
1196 ppdcSource::get_installable(ppdcFile
*fp
)
1199 char name
[1024], // Name for installable option
1200 *text
; // Text for installable option
1201 ppdcOption
*o
; // Option
1204 // Read the parameter for an installable option:
1206 // Installable name/text
1207 if (!get_token(fp
, name
, sizeof(name
)))
1209 _cupsLangPrintf(stderr
,
1210 _("ppdc: Expected name/text after Installable on line %d "
1211 "of %s!\n"), fp
->line
, fp
->filename
);
1215 if ((text
= strchr(name
, '/')) != NULL
)
1220 // Create the option...
1221 o
= new ppdcOption(PPDC_BOOLEAN
, name
, text
, PPDC_SECTION_ANY
, 10.0f
);
1223 // Add the false and true choices...
1224 o
->add_choice(new ppdcChoice("False", "Not Installed", ""));
1225 o
->add_choice(new ppdcChoice("True", "Installed", ""));
1232 // 'ppdcSource::get_integer()' - Get an integer value from a string.
1235 #define PPDC_XX -1 // Bad
1236 #define PPDC_EQ 0 // ==
1237 #define PPDC_NE 1 // !=
1238 #define PPDC_LT 2 // <
1239 #define PPDC_LE 3 // <=
1240 #define PPDC_GT 4 // >
1241 #define PPDC_GE 5 // >=
1243 int // O - Integer value
1244 ppdcSource::get_integer(const char *v
) // I - Value string
1247 long temp
, // Temporary value
1248 temp2
; // Second temporary value
1249 char *newv
, // New value string pointer
1250 ch
; // Temporary character
1251 ppdcVariable
*var
; // #define variable
1252 int compop
; // Comparison operator
1255 // Parse the value string...
1259 if (isdigit(*v
& 255) || *v
== '-' || *v
== '+')
1261 // Return a simple integer value
1262 val
= strtol(v
, (char **)&v
, 0);
1263 if (*v
|| val
== LONG_MIN
)
1270 // Evaluate and expression in any of the following formats:
1272 // (number number ... number) Bitwise OR of all numbers
1273 // (NAME == value) 1 if equal, 0 otherwise
1274 // (NAME != value) 1 if not equal, 0 otherwise
1275 // (NAME < value) 1 if less than, 0 otherwise
1276 // (NAME <= value) 1 if less than or equal, 0 otherwise
1277 // (NAME > value) 1 if greater than, 0 otherwise
1278 // (NAME >= value) 1 if greater than or equal, 0 otherwise
1283 while (*v
&& *v
!= ')')
1285 // Skip leading whitespace...
1286 while (*v
&& isspace(*v
& 255));
1289 if (!*v
|| *v
== ')')
1292 if (isdigit(*v
& 255) || *v
== '-' || *v
== '+')
1294 // Bitwise OR a number...
1295 temp
= strtol(v
, &newv
, 0);
1297 if (!*newv
|| newv
== v
|| !(isspace(*newv
) || *newv
== ')') ||
1303 // NAME logicop value
1304 for (newv
= (char *)v
+ 1;
1305 *newv
&& (isalnum(*newv
& 255) || *newv
== '_');
1311 if ((var
= find_variable(v
)) != NULL
)
1313 if (!var
->value
|| !var
->value
->value
|| !var
->value
->value
[0])
1315 else if (isdigit(var
->value
->value
[0] & 255) ||
1316 var
->value
->value
[0] == '-' ||
1317 var
->value
->value
[0] == '+')
1318 temp
= strtol(var
->value
->value
, NULL
, 0);
1326 while (isspace(*newv
& 255))
1329 if (strncmp(newv
, "==", 2))
1334 else if (strncmp(newv
, "!=", 2))
1339 else if (strncmp(newv
, "<=", 2))
1344 else if (*newv
== '<')
1349 else if (strncmp(newv
, ">=", 2))
1354 else if (*newv
== '>')
1362 if (compop
!= PPDC_XX
)
1364 while (isspace(*newv
& 255))
1367 if (*newv
== ')' || !*newv
)
1370 if (isdigit(*v
& 255) || *v
== '-' || *v
== '+')
1372 // Get the second number...
1373 temp2
= strtol(newv
, &newv
, 0);
1374 if (!*newv
|| newv
== v
|| !(isspace(*newv
) || *newv
== ')') ||
1380 // Lookup the second name...
1381 for (v
= newv
, newv
++;
1382 *newv
&& (isalnum(*newv
& 255) || *newv
== '_');
1388 if ((var
= find_variable(v
)) != NULL
)
1390 if (!var
->value
|| !var
->value
->value
|| !var
->value
->value
[0])
1392 else if (isdigit(var
->value
->value
[0] & 255) ||
1393 var
->value
->value
[0] == '-' ||
1394 var
->value
->value
[0] == '+')
1395 temp2
= strtol(var
->value
->value
, NULL
, 0);
1405 // Do the comparison...
1409 temp
= temp
== temp2
;
1412 temp
= temp
!= temp2
;
1415 temp
= temp
< temp2
;
1418 temp
= temp
<= temp2
;
1421 temp
= temp
> temp2
;
1424 temp
= temp
>= temp2
;
1434 if (*v
== ')' && !v
[1])
1439 else if ((var
= find_variable(v
)) != NULL
)
1441 // NAME by itself returns 1 if the #define variable is not blank and
1443 return (var
->value
->value
&& var
->value
->value
[0] &&
1444 strcmp(var
->value
->value
, "0"));
1448 // Anything else is an error...
1455 // 'ppdcSource::get_integer()' - Get an integer value from a file.
1458 int // O - Integer value
1459 ppdcSource::get_integer(ppdcFile
*fp
) // I - File to read
1461 char temp
[1024]; // String buffer
1464 if (!get_token(fp
, temp
, sizeof(temp
)))
1466 _cupsLangPrintf(stderr
, _("ppdc: Expected integer on line %d of %s!\n"),
1467 fp
->line
, fp
->filename
);
1471 return (get_integer(temp
));
1476 // 'ppdcSource::get_measurement()' - Get a measurement value.
1479 float // O - Measurement value in points
1480 ppdcSource::get_measurement(ppdcFile
*fp
)
1483 char buffer
[256], // Number buffer
1484 *ptr
; // Pointer into buffer
1485 float val
; // Measurement value
1488 // Grab a token from the file...
1489 if (!get_token(fp
, buffer
, sizeof(buffer
)))
1492 // Get the floating point value of "s" and skip all digits and decimal points.
1493 val
= (float)strtod(buffer
, &ptr
);
1495 // Check for a trailing unit specifier...
1496 if (!strcasecmp(ptr
, "mm"))
1497 val
*= 72.0f
/ 25.4f
;
1498 else if (!strcasecmp(ptr
, "cm"))
1499 val
*= 72.0f
/ 2.54f
;
1500 else if (!strcasecmp(ptr
, "m"))
1501 val
*= 72.0f
/ 0.0254f
;
1502 else if (!strcasecmp(ptr
, "in"))
1504 else if (!strcasecmp(ptr
, "ft"))
1505 val
*= 72.0f
* 12.0f
;
1506 else if (strcasecmp(ptr
, "pt") && *ptr
)
1514 // 'ppdcSource::get_option()' - Get an option definition.
1517 ppdcOption
* // O - Option
1518 ppdcSource::get_option(ppdcFile
*fp
, // I - File to read
1519 ppdcDriver
*d
, // I - Printer driver
1520 ppdcGroup
*g
) // I - Current group
1522 char name
[1024], // UI name
1524 type
[256]; // UI type string
1525 ppdcOptType ot
; // Option type value
1526 ppdcOptSection section
; // Option section
1527 float order
; // Option order
1528 ppdcOption
*o
; // Option
1531 // Read the Option parameters:
1533 // Option name/text type section order
1534 if (!get_token(fp
, name
, sizeof(name
)))
1536 _cupsLangPrintf(stderr
,
1537 _("ppdc: Expected option name/text on line %d of %s!\n"),
1538 fp
->line
, fp
->filename
);
1542 if ((text
= strchr(name
, '/')) != NULL
)
1547 if (!get_token(fp
, type
, sizeof(type
)))
1549 _cupsLangPrintf(stderr
, _("ppdc: Expected option type on line %d of %s!\n"),
1550 fp
->line
, fp
->filename
);
1554 if (!strcasecmp(type
, "boolean"))
1556 else if (!strcasecmp(type
, "pickone"))
1558 else if (!strcasecmp(type
, "pickmany"))
1562 _cupsLangPrintf(stderr
,
1563 _("ppdc: Invalid option type \"%s\" on line %d of %s!\n"),
1564 type
, fp
->line
, fp
->filename
);
1568 if (!get_token(fp
, type
, sizeof(type
)))
1570 _cupsLangPrintf(stderr
,
1571 _("ppdc: Expected option section on line %d of %s!\n"),
1572 fp
->line
, fp
->filename
);
1576 if (!strcasecmp(type
, "AnySetup"))
1577 section
= PPDC_SECTION_ANY
;
1578 else if (!strcasecmp(type
, "DocumentSetup"))
1579 section
= PPDC_SECTION_DOCUMENT
;
1580 else if (!strcasecmp(type
, "ExitServer"))
1581 section
= PPDC_SECTION_EXIT
;
1582 else if (!strcasecmp(type
, "JCLSetup"))
1583 section
= PPDC_SECTION_JCL
;
1584 else if (!strcasecmp(type
, "PageSetup"))
1585 section
= PPDC_SECTION_PAGE
;
1586 else if (!strcasecmp(type
, "Prolog"))
1587 section
= PPDC_SECTION_PROLOG
;
1590 _cupsLangPrintf(stderr
,
1591 _("ppdc: Invalid option section \"%s\" on line %d of "
1592 "%s!\n"), type
, fp
->line
, fp
->filename
);
1596 order
= get_float(fp
);
1598 // See if the option already exists...
1599 if ((o
= d
->find_option(name
)) == NULL
)
1601 // Nope, add a new one...
1602 o
= new ppdcOption(ot
, name
, text
, section
, order
);
1604 else if (o
->type
!= ot
)
1606 _cupsLangPrintf(stderr
,
1607 _("ppdc: Option %s redefined with a different type on line "
1608 "%d of %s!\n"), name
, fp
->line
, fp
->filename
);
1617 // 'ppdcSource::get_po()' - Get a message catalog.
1620 ppdcCatalog
* // O - Message catalog
1621 ppdcSource::get_po(ppdcFile
*fp
) // I - File to read
1623 char locale
[32], // Locale name
1624 poname
[1024], // Message catalog filename
1625 basedir
[1024], // Base directory
1626 *baseptr
, // Pointer into directory
1627 pofilename
[1024]; // Full filename of message catalog
1628 ppdcCatalog
*cat
; // Message catalog
1631 // Read the #po parameters:
1633 // #po locale "filename.po"
1634 if (!get_token(fp
, locale
, sizeof(locale
)))
1636 _cupsLangPrintf(stderr
,
1637 _("ppdc: Expected locale after #po on line %d of %s!\n"),
1638 fp
->line
, fp
->filename
);
1642 if (!get_token(fp
, poname
, sizeof(poname
)))
1644 _cupsLangPrintf(stderr
,
1645 _("ppdc: Expected filename after #po %s on line %d of "
1646 "%s!\n"), locale
, fp
->line
, fp
->filename
);
1650 // See if the locale is already loaded...
1651 if (find_po(locale
))
1653 _cupsLangPrintf(stderr
,
1654 _("ppdc: Duplicate #po for locale %s on line %d of %s!\n"),
1655 locale
, fp
->line
, fp
->filename
);
1659 // Figure out the current directory...
1660 strlcpy(basedir
, fp
->filename
, sizeof(basedir
));
1662 if ((baseptr
= strrchr(basedir
, '/')) != NULL
)
1665 strcpy(basedir
, ".");
1667 // Find the po file...
1668 if (!pofilename
[0] ||
1669 find_include(poname
, basedir
, pofilename
, sizeof(pofilename
)))
1671 // Found it, so load it...
1672 cat
= new ppdcCatalog(locale
, pofilename
);
1674 // Reset the filename to the name supplied by the user...
1675 cat
->filename
->release();
1676 cat
->filename
= new ppdcString(poname
);
1678 // Return the catalog...
1683 _cupsLangPrintf(stderr
,
1684 _("ppdc: Unable to find #po file %s on line %d of %s!\n"),
1685 poname
, fp
->line
, fp
->filename
);
1692 // 'ppdcSource::get_resolution()' - Get an old-style resolution option.
1695 ppdcChoice
* // O - Choice data
1696 ppdcSource::get_resolution(ppdcFile
*fp
)// I - File to read
1698 char name
[1024], // Name
1700 temp
[256], // Temporary string
1701 command
[256], // Command string
1702 *commptr
; // Pointer into command
1703 int xdpi
, ydpi
, // X + Y resolution
1704 color_order
, // Color order
1705 color_space
, // Colorspace
1706 compression
, // Compression mode
1707 depth
, // Bits per color
1708 row_count
, // Row count
1709 row_feed
, // Row feed
1710 row_step
; // Row step/interval
1713 // Read the resolution parameters:
1715 // Resolution colorspace bits row-count row-feed row-step name/text
1716 if (!get_token(fp
, temp
, sizeof(temp
)))
1718 _cupsLangPrintf(stderr
,
1719 _("ppdc: Expected override field after Resolution on line "
1720 "%d of %s!\n"), fp
->line
, fp
->filename
);
1724 color_order
= get_color_order(temp
);
1725 color_space
= get_color_space(temp
);
1726 compression
= get_integer(temp
);
1728 depth
= get_integer(fp
);
1729 row_count
= get_integer(fp
);
1730 row_feed
= get_integer(fp
);
1731 row_step
= get_integer(fp
);
1733 if (!get_token(fp
, name
, sizeof(name
)))
1735 _cupsLangPrintf(stderr
,
1736 _("ppdc: Expected name/text after Resolution on line %d of "
1737 "%s!\n"), fp
->line
, fp
->filename
);
1741 if ((text
= strchr(name
, '/')) != NULL
)
1746 switch (sscanf(name
, "%dx%d", &xdpi
, &ydpi
))
1749 _cupsLangPrintf(stderr
,
1750 _("ppdc: Bad resolution name \"%s\" on line %d of "
1751 "%s!\n"), name
, fp
->line
, fp
->filename
);
1758 // Create the necessary PS commands...
1759 snprintf(command
, sizeof(command
),
1760 "<</HWResolution[%d %d]/cupsBitsPerColor %d/cupsRowCount %d"
1761 "/cupsRowFeed %d/cupsRowStep %d",
1762 xdpi
, ydpi
, depth
, row_count
, row_feed
, row_step
);
1763 commptr
= command
+ strlen(command
);
1765 if (color_order
>= 0)
1767 snprintf(commptr
, sizeof(command
) - (commptr
- command
),
1768 "/cupsColorOrder %d", color_order
);
1769 commptr
+= strlen(commptr
);
1772 if (color_space
>= 0)
1774 snprintf(commptr
, sizeof(command
) - (commptr
- command
),
1775 "/cupsColorSpace %d", color_space
);
1776 commptr
+= strlen(commptr
);
1779 if (compression
>= 0)
1781 snprintf(commptr
, sizeof(command
) - (commptr
- command
),
1782 "/cupsCompression %d", compression
);
1783 commptr
+= strlen(commptr
);
1786 snprintf(commptr
, sizeof(command
) - (commptr
- command
), ">>setpagedevice");
1788 // Return the new choice...
1789 return (new ppdcChoice(name
, text
, command
));
1794 // 'ppdcSource::get_simple_profile()' - Get a simple color profile definition.
1797 ppdcProfile
* // O - Color profile
1798 ppdcSource::get_simple_profile(ppdcFile
*fp
)
1801 char resolution
[1024], // Resolution/media type
1802 *media_type
; // Media type
1803 float m
[9]; // Transform matrix
1804 float kd
, rd
, g
; // Densities and gamma
1805 float red
, green
, blue
; // RGB adjustments
1806 float yellow
; // Yellow density
1807 float color
; // Color density values
1810 // Get the SimpleColorProfile parameters:
1812 // SimpleColorProfile resolution/mediatype black-density yellow-density
1813 // red-density gamma red-adjust green-adjust blue-adjust
1814 if (!get_token(fp
, resolution
, sizeof(resolution
)))
1816 _cupsLangPrintf(stderr
,
1817 _("ppdc: Expected resolution/mediatype following "
1818 "SimpleColorProfile on line %d of %s!\n"),
1819 fp
->line
, fp
->filename
);
1823 if ((media_type
= strchr(resolution
, '/')) != NULL
)
1824 *media_type
++ = '\0';
1826 media_type
= resolution
;
1828 // Collect the profile parameters...
1830 yellow
= get_float(fp
);
1833 red
= get_float(fp
);
1834 green
= get_float(fp
);
1835 blue
= get_float(fp
);
1837 // Build the color profile...
1838 color
= 0.5f
* rd
/ kd
- kd
;
1840 m
[1] = color
+ blue
; // C + M (blue)
1841 m
[2] = color
- green
; // C + Y (green)
1842 m
[3] = color
- blue
; // M + C (blue)
1844 m
[5] = color
+ red
; // M + Y (red)
1845 m
[6] = yellow
* (color
+ green
); // Y + C (green)
1846 m
[7] = yellow
* (color
- red
); // Y + M (red)
1854 else if (m
[3] > 0.0f
)
1865 else if (m
[6] > 0.0f
)
1876 else if (m
[7] > 0.0f
)
1882 // Return the new profile...
1883 return (new ppdcProfile(resolution
, media_type
, g
, kd
, m
));
1888 // 'ppdcSource::get_size()' - Get a media size definition from a file.
1891 ppdcMediaSize
* // O - Media size
1892 ppdcSource::get_size(ppdcFile
*fp
) // I - File to read
1894 char name
[1024], // Name
1896 float width
, // Width
1900 // Get the name, text, width, and length:
1902 // #media name/text width length
1903 if (!get_token(fp
, name
, sizeof(name
)))
1906 if ((text
= strchr(name
, '/')) != NULL
)
1911 if ((width
= get_measurement(fp
)) < 0.0f
)
1914 if ((length
= get_measurement(fp
)) < 0.0f
)
1917 // Return the new media size...
1918 return (new ppdcMediaSize(name
, text
, width
, length
, 0.0f
, 0.0f
, 0.0f
, 0.0f
));
1923 // 'ppdcSource::get_token()' - Get a token from a file.
1926 char * // O - Token string or NULL
1927 ppdcSource::get_token(ppdcFile
*fp
, // I - File to read
1928 char *buffer
, // I - Buffer
1929 int buflen
) // I - Length of buffer
1931 char *bufptr
, // Pointer into string buffer
1932 *bufend
; // End of string buffer
1933 int ch
, // Character from file
1934 nextch
, // Next char in file
1935 quote
, // Quote character used...
1936 empty
, // Empty input?
1937 startline
; // Start line for quote
1938 char name
[256], // Name string
1939 *nameptr
; // Name pointer
1940 ppdcVariable
*var
; // Variable pointer
1943 // Mark the beginning and end of the buffer...
1945 bufend
= buffer
+ buflen
- 1;
1947 // Loop intil we've read a token...
1952 while ((ch
= fp
->get()) != EOF
)
1954 if (isspace(ch
) && !quote
)
1963 // Variable substitution
1966 for (nameptr
= name
; (ch
= fp
->peek()) != EOF
;)
1968 if (!isalnum(ch
) && ch
!= '_')
1970 else if (nameptr
< (name
+ sizeof(name
) - 1))
1971 *nameptr
++ = fp
->get();
1974 if (nameptr
== name
)
1976 // Just substitute this character...
1980 if (bufptr
< bufend
)
1981 *bufptr
++ = fp
->get();
1986 _cupsLangPrintf(stderr
,
1987 _("ppdc: Bad variable substitution ($%c) on line %d "
1988 "of %s.\n"), ch
, fp
->line
, fp
->filename
);
1990 if (bufptr
< bufend
)
1996 // Substitute the variable value...
1998 var
= find_variable(name
);
2001 strncpy(bufptr
, var
->value
->value
, bufend
- bufptr
);
2002 bufptr
+= strlen(var
->value
->value
);
2006 _cupsLangPrintf(stderr
,
2007 _("ppdc: Undefined variable (%s) on line %d of "
2008 "%s.\n"), name
, fp
->line
, fp
->filename
);
2009 snprintf(bufptr
, bufend
- bufptr
+ 1, "$%s", name
);
2010 bufptr
+= strlen(name
) + 1;
2014 else if (ch
== '/' && !quote
)
2016 // Possibly a comment...
2017 nextch
= fp
->peek();
2024 while ((nextch
= fp
->get()) != EOF
)
2026 if (ch
== '*' && nextch
== '/')
2035 else if (nextch
== '/')
2038 while ((nextch
= fp
->get()) != EOF
)
2050 if (bufptr
< bufend
)
2054 else if (ch
== '\'' || ch
== '\"')
2060 // Ending the current quoted string...
2065 // Insert the opposing quote char...
2066 if (bufptr
< bufend
)
2071 // Start a new quoted string...
2072 startline
= fp
->line
;
2076 else if ((ch
== '(' || ch
== '<') && !quote
)
2080 startline
= fp
->line
;
2082 if (bufptr
< bufend
)
2085 else if ((ch
== ')' && quote
== '(') || (ch
== '>' && quote
== '<'))
2089 if (bufptr
< bufend
)
2092 else if (ch
== '\\')
2096 if ((ch
= fp
->get()) == EOF
)
2099 if (bufptr
< bufend
)
2102 else if (bufptr
< bufend
)
2108 if ((ch
== '{' || ch
== '}') && !quote
)
2115 _cupsLangPrintf(stderr
,
2116 _("ppdc: Unterminated string starting with %c on line %d "
2117 "of %s!\n"), quote
, startline
, fp
->filename
);
2133 // 'ppdcSource::get_variable()' - Get a variable definition.
2136 ppdcVariable
* // O - Variable
2137 ppdcSource::get_variable(ppdcFile
*fp
) // I - File to read
2139 char name
[1024], // Name
2140 value
[1024]; // Value
2143 // Get the name and value:
2145 // #define name value
2146 if (!get_token(fp
, name
, sizeof(name
)))
2149 if (!get_token(fp
, value
, sizeof(value
)))
2152 // Set the variable...
2153 return (set_variable(name
, value
));
2158 // 'ppdcSource::quotef()' - Write a formatted, quoted string...
2161 int // O - Number bytes on success, -1 on failure
2162 ppdcSource::quotef(cups_file_t
*fp
, // I - File to write to
2163 const char *format
, // I - Printf-style format string
2164 ...) // I - Additional args as needed
2166 va_list ap
; // Pointer to additional arguments
2167 int bytes
; // Bytes written
2168 char sign
, // Sign of format width
2169 size
, // Size character (h, l, L)
2170 type
; // Format type character
2171 const char *bufformat
; // Start of format
2172 int width
, // Width of field
2173 prec
; // Number of characters of precision
2174 char tformat
[100]; // Temporary format string for fprintf()
2175 char *s
; // Pointer to string
2176 int slen
; // Length of string
2177 int i
; // Looping var
2180 // Range check input...
2184 // Loop through the format string, formatting as needed...
2185 va_start(ap
, format
);
2198 cupsFilePutChar(fp
, *format
++);
2202 else if (strchr(" -+#\'", *format
))
2208 while (isdigit(*format
))
2209 width
= width
* 10 + *format
++ - '0';
2216 while (isdigit(*format
))
2217 prec
= prec
* 10 + *format
++ - '0';
2222 if (*format
== 'l' && format
[1] == 'l')
2227 else if (*format
== 'h' || *format
== 'l' || *format
== 'L')
2237 case 'E' : // Floating point formats
2242 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2245 strncpy(tformat
, bufformat
, format
- bufformat
);
2246 tformat
[format
- bufformat
] = '\0';
2248 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, double));
2251 case 'B' : // Integer formats
2259 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2262 strncpy(tformat
, bufformat
, format
- bufformat
);
2263 tformat
[format
- bufformat
] = '\0';
2265 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, int));
2268 case 'p' : // Pointer value
2269 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2272 strncpy(tformat
, bufformat
, format
- bufformat
);
2273 tformat
[format
- bufformat
] = '\0';
2275 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, void *));
2278 case 'c' : // Character or character array
2282 cupsFilePutChar(fp
, va_arg(ap
, int));
2286 cupsFileWrite(fp
, va_arg(ap
, char *), width
);
2291 case 's' : // String
2292 if ((s
= va_arg(ap
, char *)) == NULL
)
2293 s
= (char *)"(nil)";
2296 if (slen
> width
&& prec
!= width
)
2304 for (i
= width
- slen
; i
> 0; i
--, bytes
++)
2305 cupsFilePutChar(fp
, ' ');
2308 for (i
= slen
; i
> 0; i
--, s
++, bytes
++)
2310 if (*s
== '\\' || *s
== '\"')
2312 cupsFilePutChar(fp
, '\\');
2316 cupsFilePutChar(fp
, *s
);
2321 for (i
= width
- slen
; i
> 0; i
--, bytes
++)
2322 cupsFilePutChar(fp
, ' ');
2329 cupsFilePutChar(fp
, *format
++);
2336 // Return the number of characters written.
2342 // 'ppdcSource::read_file()' - Read a driver source file.
2346 ppdcSource::read_file(const char *f
, // I - File to read
2347 cups_file_t
*ffp
) // I - File pointer to use
2349 ppdcFile
*fp
= new ppdcFile(f
, ffp
);
2353 if (cond_current
!= cond_stack
)
2354 _cupsLangPrintf(stderr
, _("ppdc: Missing #endif at end of \"%s\"!\n"), f
);
2359 // 'ppdcSource::scan_file()' - Scan a driver source file.
2363 ppdcSource::scan_file(ppdcFile
*fp
, // I - File to read
2364 ppdcDriver
*td
, // I - Driver template
2365 bool inc
) // I - Including?
2367 ppdcDriver
*d
; // Current driver
2368 ppdcGroup
*g
, // Current group
2369 *general
, // General options group
2370 *install
; // Installable options group
2371 ppdcOption
*o
; // Current option
2372 ppdcChoice
*c
; // Current choice
2373 char temp
[256], // Token from file...
2374 *ptr
; // Pointer into token
2375 int isdefault
; // Default option?
2378 // Initialize things as needed...
2382 d
= new ppdcDriver(td
);
2384 if ((general
= d
->find_group("General")) == NULL
)
2386 general
= new ppdcGroup("General", NULL
);
2387 d
->add_group(general
);
2390 if ((install
= d
->find_group("InstallableOptions")) == NULL
)
2392 install
= new ppdcGroup("InstallableOptions", "Installable Options");
2393 d
->add_group(install
);
2396 // Loop until EOF or }
2400 while (get_token(fp
, temp
, sizeof(temp
)))
2404 // Mark the next choice as the default
2407 for (ptr
= temp
; ptr
[1]; ptr
++)
2414 // Don't mark the next choice as the default
2418 if (!strcasecmp(temp
, "}"))
2420 // Close this one out...
2423 else if (!strcasecmp(temp
, "{"))
2425 // Open a new child...
2428 else if (!strcasecmp(temp
, "#if"))
2430 if ((cond_current
- cond_stack
) >= 100)
2432 _cupsLangPrintf(stderr
,
2433 _("ppdc: Too many nested #if's on line %d of %s!\n"),
2434 fp
->line
, fp
->filename
);
2439 if (get_integer(fp
))
2440 *cond_current
= PPDC_COND_SATISFIED
;
2443 *cond_current
= PPDC_COND_SKIP
;
2444 cond_state
|= PPDC_COND_SKIP
;
2447 else if (!strcasecmp(temp
, "#elif"))
2449 if (cond_current
== cond_stack
)
2451 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s!\n"),
2452 fp
->line
, fp
->filename
);
2456 if (*cond_current
& PPDC_COND_SATISFIED
)
2459 *cond_current
|= PPDC_COND_SKIP
;
2461 else if (get_integer(fp
))
2463 *cond_current
|= PPDC_COND_SATISFIED
;
2464 *cond_current
&= ~PPDC_COND_SKIP
;
2467 *cond_current
|= PPDC_COND_SKIP
;
2469 // Update the current state
2470 int *cond_temp
= cond_current
; // Temporary stack pointer
2472 cond_state
= PPDC_COND_NORMAL
;
2473 while (cond_temp
> cond_stack
)
2474 if (*cond_temp
& PPDC_COND_SKIP
)
2476 cond_state
= PPDC_COND_SKIP
;
2482 else if (!strcasecmp(temp
, "#else"))
2484 if (cond_current
== cond_stack
)
2486 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s!\n"),
2487 fp
->line
, fp
->filename
);
2491 if (*cond_current
& PPDC_COND_SATISFIED
)
2492 *cond_current
|= PPDC_COND_SKIP
;
2495 *cond_current
|= PPDC_COND_SATISFIED
;
2496 *cond_current
&= ~PPDC_COND_SKIP
;
2499 // Update the current state
2500 int *cond_temp
= cond_current
; // Temporary stack pointer
2502 cond_state
= PPDC_COND_NORMAL
;
2503 while (cond_temp
> cond_stack
)
2504 if (*cond_temp
& PPDC_COND_SKIP
)
2506 cond_state
= PPDC_COND_SKIP
;
2512 else if (!strcasecmp(temp
, "#endif"))
2514 if (cond_current
== cond_stack
)
2516 _cupsLangPrintf(stderr
, _("ppdc: Missing #if on line %d of %s!\n"),
2517 fp
->line
, fp
->filename
);
2523 // Update the current state
2524 int *cond_temp
= cond_current
; // Temporary stack pointer
2526 cond_state
= PPDC_COND_NORMAL
;
2527 while (cond_temp
> cond_stack
)
2528 if (*cond_temp
& PPDC_COND_SKIP
)
2530 cond_state
= PPDC_COND_SKIP
;
2536 else if (!strcasecmp(temp
, "#define"))
2538 // Get the variable...
2541 else if (!strcasecmp(temp
, "#include"))
2543 // #include filename
2544 char basedir
[1024], // Base directory
2545 *baseptr
, // Pointer into directory
2546 inctemp
[1024], // Initial filename
2547 incname
[1024]; // Include filename
2548 ppdcFile
*incfile
; // Include file
2549 int *old_current
= cond_current
;
2550 // Previous current stack
2553 // Get the include name...
2554 if (!get_token(fp
, inctemp
, sizeof(inctemp
)))
2556 _cupsLangPrintf(stderr
,
2557 _("ppdc: Expected include filename on line %d of "
2558 "%s!\n"), fp
->line
, fp
->filename
);
2565 // Figure out the current directory...
2566 strlcpy(basedir
, fp
->filename
, sizeof(basedir
));
2568 if ((baseptr
= strrchr(basedir
, '/')) != NULL
)
2571 strcpy(basedir
, ".");
2573 // Find the include file...
2574 if (find_include(inctemp
, basedir
, incname
, sizeof(incname
)))
2576 // Open the include file, scan it, and then close it...
2577 incfile
= new ppdcFile(incname
);
2578 scan_file(incfile
, d
, true);
2581 if (cond_current
!= old_current
)
2582 _cupsLangPrintf(stderr
, _("ppdc: Missing #endif at end of \"%s\"!\n"),
2588 _cupsLangPrintf(stderr
,
2589 _("ppdc: Unable to find include file \"%s\" on line %d "
2590 "of %s!\n"), inctemp
, fp
->line
, fp
->filename
);
2594 else if (!strcasecmp(temp
, "#media"))
2596 ppdcMediaSize
*m
; // Media size
2599 // Get a media size...
2609 else if (!strcasecmp(temp
, "#po"))
2611 ppdcCatalog
*cat
; // Message catalog
2614 // Get a message catalog...
2624 else if (!strcasecmp(temp
, "Attribute") ||
2625 !strcasecmp(temp
, "LocAttribute"))
2627 ppdcAttr
*a
; // Attribute
2630 // Get an attribute...
2631 a
= get_attr(fp
, !strcasecmp(temp
, "LocAttribute"));
2640 else if (!strcasecmp(temp
, "Choice"))
2653 // Add it to the current option...
2656 _cupsLangPrintf(stderr
,
2657 _("ppdc: Choice found on line %d of %s with no "
2658 "Option!\n"), fp
->line
, fp
->filename
);
2665 o
->set_defchoice(c
);
2667 else if (!strcasecmp(temp
, "ColorDevice"))
2669 // ColorDevice boolean
2673 d
->color_device
= get_boolean(fp
);
2675 else if (!strcasecmp(temp
, "ColorModel"))
2677 // Get the color model
2678 c
= get_color_model(fp
);
2688 // Add the choice to the ColorModel option...
2689 if ((o
= d
->find_option("ColorModel")) == NULL
)
2691 // Create the ColorModel option...
2692 o
= new ppdcOption(PPDC_PICKONE
, "ColorModel", "Color Mode", PPDC_SECTION_ANY
, 10.0f
);
2700 o
->set_defchoice(c
);
2704 else if (!strcasecmp(temp
, "ColorProfile"))
2706 ppdcProfile
*p
; // Color profile
2709 // Get the color profile...
2710 p
= get_color_profile(fp
);
2717 d
->profiles
->add(p
);
2720 else if (!strcasecmp(temp
, "Copyright"))
2723 char copytemp
[8192], // Copyright string
2724 *copyptr
, // Pointer into string
2725 *copyend
; // Pointer to end of string
2728 // Get the copyright string...
2729 if (!get_token(fp
, copytemp
, sizeof(temp
)))
2731 _cupsLangPrintf(stderr
,
2732 _("ppdc: Expected string after Copyright on line %d "
2733 "of %s!\n"), fp
->line
, fp
->filename
);
2740 // Break it up into individual lines...
2741 for (copyptr
= copytemp
; copyptr
; copyptr
= copyend
)
2743 if ((copyend
= strchr(copyptr
, '\n')) != NULL
)
2746 d
->copyright
->add(new ppdcString(copyptr
));
2749 else if (!strcasecmp(temp
, "CustomMedia"))
2751 ppdcMediaSize
*m
; // Media size
2754 // Get a custom media size...
2755 m
= get_custom_size(fp
);
2767 d
->set_default_size(m
);
2769 else if (!strcasecmp(temp
, "Cutter"))
2772 int have_cutter
; // Have a paper cutter?
2775 have_cutter
= get_boolean(fp
);
2776 if (have_cutter
<= 0 || cond_state
)
2779 if ((o
= d
->find_option("CutMedia")) == NULL
)
2781 o
= new ppdcOption(PPDC_BOOLEAN
, "CutMedia", "Cut Media", PPDC_SECTION_ANY
, 10.0f
);
2786 c
= new ppdcChoice("False", NULL
, "<</CutMedia 0>>setpagedevice");
2788 o
->set_defchoice(c
);
2790 c
= new ppdcChoice("True", NULL
, "<</CutMedia 4>>setpagedevice");
2796 else if (!strcasecmp(temp
, "Darkness"))
2798 // Get the darkness choice...
2799 c
= get_generic(fp
, "Darkness", NULL
, "cupsCompression");
2809 // Add the choice to the cupsDarkness option...
2810 if ((o
= d
->find_option("cupsDarkness")) == NULL
)
2812 // Create the cupsDarkness option...
2813 o
= new ppdcOption(PPDC_PICKONE
, "cupsDarkness", "Darkness", PPDC_SECTION_ANY
, 10.0f
);
2821 o
->set_defchoice(c
);
2825 else if (!strcasecmp(temp
, "DriverType"))
2827 int i
; // Looping var
2830 // DriverType keyword
2831 if (!get_token(fp
, temp
, sizeof(temp
)))
2833 _cupsLangPrintf(stderr
,
2834 _("ppdc: Expected driver type keyword following "
2835 "DriverType on line %d of %s!\n"),
2836 fp
->line
, fp
->filename
);
2843 for (i
= 0; i
< (int)(sizeof(driver_types
) / sizeof(driver_types
[0])); i
++)
2844 if (!strcasecmp(temp
, driver_types
[i
]))
2847 if (i
< (int)(sizeof(driver_types
) / sizeof(driver_types
[0])))
2848 d
->type
= (ppdcDrvType
)i
;
2849 else if (!strcasecmp(temp
, "dymo"))
2850 d
->type
= PPDC_DRIVER_LABEL
;
2852 _cupsLangPrintf(stderr
,
2853 _("ppdc: Unknown driver type %s on line %d of %s!\n"),
2854 temp
, fp
->line
, fp
->filename
);
2856 else if (!strcasecmp(temp
, "Duplex"))
2858 else if (!strcasecmp(temp
, "Filter"))
2860 ppdcFilter
*f
; // Filter
2863 // Get the filter value...
2873 else if (!strcasecmp(temp
, "Finishing"))
2875 // Get the finishing choice...
2876 c
= get_generic(fp
, "Finishing", "OutputType", NULL
);
2886 // Add the choice to the cupsFinishing option...
2887 if ((o
= d
->find_option("cupsFinishing")) == NULL
)
2889 // Create the cupsFinishing option...
2890 o
= new ppdcOption(PPDC_PICKONE
, "cupsFinishing", "Finishing", PPDC_SECTION_ANY
, 10.0f
);
2898 o
->set_defchoice(c
);
2902 else if (!strcasecmp(temp
, "Font") ||
2903 !strcasecmp(temp
, "#font"))
2905 ppdcFont
*f
; // Font
2916 if (!strcasecmp(temp
, "#font"))
2922 d
->set_default_font(f
);
2926 else if (!strcasecmp(temp
, "Group"))
2929 ppdcGroup
*tempg
= get_group(fp
, d
);
2936 if (!d
->find_group(tempg
->name
->value
))
2941 if (!d
->find_group(tempg
->name
->value
))
2942 d
->add_group(tempg
);
2947 else if (!strcasecmp(temp
, "HWMargins"))
2949 // HWMargins left bottom right top
2950 d
->left_margin
= get_measurement(fp
);
2951 d
->bottom_margin
= get_measurement(fp
);
2952 d
->right_margin
= get_measurement(fp
);
2953 d
->top_margin
= get_measurement(fp
);
2955 else if (!strcasecmp(temp
, "InputSlot"))
2957 // Get the input slot choice...
2958 c
= get_generic(fp
, "InputSlot", NULL
, "MediaPosition");
2968 // Add the choice to the InputSlot option...
2969 if ((o
= d
->find_option("InputSlot")) == NULL
)
2971 // Create the InputSlot option...
2972 o
= new ppdcOption(PPDC_PICKONE
, "InputSlot", "Media Source",
2973 PPDC_SECTION_ANY
, 10.0f
);
2981 o
->set_defchoice(c
);
2985 else if (!strcasecmp(temp
, "Installable"))
2987 // Get the installable option...
2988 o
= get_installable(fp
);
2990 // Add it as needed...
2996 install
->add_option(o
);
3001 else if (!strcasecmp(temp
, "ManualCopies"))
3003 // ManualCopies boolean
3007 d
->manual_copies
= get_boolean(fp
);
3009 else if (!strcasecmp(temp
, "Manufacturer"))
3011 // Manufacturer name
3012 char name
[256]; // Model name string
3015 if (!get_token(fp
, name
, sizeof(name
)))
3017 _cupsLangPrintf(stderr
,
3018 _("ppdc: Expected name after Manufacturer on line %d "
3019 "of %s!\n"), fp
->line
, fp
->filename
);
3024 d
->set_manufacturer(name
);
3026 else if (!strcasecmp(temp
, "MaxSize"))
3028 // MaxSize width length
3031 get_measurement(fp
);
3032 get_measurement(fp
);
3036 d
->max_width
= get_measurement(fp
);
3037 d
->max_length
= get_measurement(fp
);
3040 else if (!strcasecmp(temp
, "MediaSize"))
3042 // MediaSize keyword
3043 char name
[41]; // Media size name
3044 ppdcMediaSize
*m
, // Matching media size...
3045 *dm
; // Driver media size...
3048 if (get_token(fp
, name
, sizeof(name
)) == NULL
)
3050 _cupsLangPrintf(stderr
,
3051 _("ppdc: Expected name after MediaSize on line %d of "
3052 "%s!\n"), fp
->line
, fp
->filename
);
3059 m
= find_size(name
);
3063 _cupsLangPrintf(stderr
,
3064 _("ppdc: Unknown media size \"%s\" on line %d of "
3065 "%s!\n"), name
, fp
->line
, fp
->filename
);
3069 // Add this size to the driver...
3070 dm
= new ppdcMediaSize(m
->name
->value
, m
->text
->value
,
3071 m
->width
, m
->length
, d
->left_margin
,
3072 d
->bottom_margin
, d
->right_margin
,
3077 d
->set_default_size(dm
);
3079 else if (!strcasecmp(temp
, "MediaType"))
3081 // Get the media type choice...
3082 c
= get_generic(fp
, "MediaType", "MediaType", "cupsMediaType");
3092 // Add the choice to the MediaType option...
3093 if ((o
= d
->find_option("MediaType")) == NULL
)
3095 // Create the MediaType option...
3096 o
= new ppdcOption(PPDC_PICKONE
, "MediaType", "Media Type",
3097 PPDC_SECTION_ANY
, 10.0f
);
3105 o
->set_defchoice(c
);
3109 else if (!strcasecmp(temp
, "MinSize"))
3111 // MinSize width length
3114 get_measurement(fp
);
3115 get_measurement(fp
);
3119 d
->min_width
= get_measurement(fp
);
3120 d
->min_length
= get_measurement(fp
);
3123 else if (!strcasecmp(temp
, "ModelName"))
3126 char name
[256]; // Model name string
3129 if (!get_token(fp
, name
, sizeof(name
)))
3131 _cupsLangPrintf(stderr
,
3132 _("ppdc: Expected name after ModelName on line %d of "
3133 "%s!\n"), fp
->line
, fp
->filename
);
3138 d
->set_model_name(name
);
3140 else if (!strcasecmp(temp
, "ModelNumber"))
3142 // ModelNumber number
3146 d
->model_number
= get_integer(fp
);
3148 else if (!strcasecmp(temp
, "Option"))
3151 ppdcOption
*tempo
= get_option(fp
, d
, g
);
3158 if (!g
->find_option(tempo
->name
->value
))
3163 if (!g
->find_option(tempo
->name
->value
))
3164 g
->add_option(tempo
);
3169 else if (!strcasecmp(temp
, "FileName"))
3172 char name
[256]; // Filename string
3175 if (!get_token(fp
, name
, sizeof(name
)))
3177 _cupsLangPrintf(stderr
,
3178 _("ppdc: Expected name after FileName on line %d of "
3179 "%s!\n"), fp
->line
, fp
->filename
);
3184 d
->set_file_name(name
);
3186 else if (!strcasecmp(temp
, "PCFileName"))
3189 char name
[256]; // PC filename string
3192 if (!get_token(fp
, name
, sizeof(name
)))
3194 _cupsLangPrintf(stderr
,
3195 _("ppdc: Expected name after PCFileName on line %d of "
3196 "%s!\n"), fp
->line
, fp
->filename
);
3201 d
->set_pc_file_name(name
);
3203 else if (!strcasecmp(temp
, "Resolution"))
3205 // Get the resolution choice...
3206 c
= get_resolution(fp
);
3216 // Add the choice to the Resolution option...
3217 if ((o
= d
->find_option("Resolution")) == NULL
)
3219 // Create the Resolution option...
3220 o
= new ppdcOption(PPDC_PICKONE
, "Resolution", NULL
, PPDC_SECTION_ANY
,
3229 o
->set_defchoice(c
);
3233 else if (!strcasecmp(temp
, "SimpleColorProfile"))
3235 ppdcProfile
*p
; // Color profile
3238 // Get the color profile...
3239 p
= get_simple_profile(fp
);
3246 d
->profiles
->add(p
);
3249 else if (!strcasecmp(temp
, "Throughput"))
3251 // Throughput number
3255 d
->throughput
= get_integer(fp
);
3257 else if (!strcasecmp(temp
, "UIConstraints"))
3259 ppdcConstraint
*con
; // Constraint
3262 con
= get_constraint(fp
);
3269 d
->constraints
->add(con
);
3272 else if (!strcasecmp(temp
, "VariablePaperSize"))
3274 // VariablePaperSize boolean
3278 d
->variable_paper_size
= get_boolean(fp
);
3280 else if (!strcasecmp(temp
, "Version"))
3283 char name
[256]; // Model name string
3286 if (!get_token(fp
, name
, sizeof(name
)))
3288 _cupsLangPrintf(stderr
,
3289 _("ppdc: Expected string after Version on line %d of "
3290 "%s!\n"), fp
->line
, fp
->filename
);
3295 d
->set_version(name
);
3299 _cupsLangPrintf(stderr
,
3300 _("ppdc: Unknown token \"%s\" seen on line %d of %s!\n"),
3301 temp
, fp
->line
, fp
->filename
);
3306 // Done processing this block, is there anything to save?
3309 if (!d
->pc_file_name
|| !d
->model_name
|| !d
->manufacturer
|| !d
->version
||
3312 // Nothing to save...
3317 // Got a driver, save it...
3325 // 'ppdcSource::set_variable()' - Set a variable.
3328 ppdcVariable
* // O - Variable
3329 ppdcSource::set_variable(
3330 const char *name
, // I - Name
3331 const char *value
) // I - Value
3333 ppdcVariable
*v
; // Variable
3336 // See if the variable exists already...
3337 v
= find_variable(name
);
3340 // Change the variable value...
3341 v
->set_value(value
);
3345 // Create a new variable and add it...
3346 v
= new ppdcVariable(name
, value
);
3355 // 'ppdcSource::write_file()' - Write the current source data to a file.
3358 int // O - 0 on success, -1 on error
3359 ppdcSource::write_file(const char *f
) // I - File to write
3361 cups_file_t
*fp
; // Output file
3362 char bckname
[1024]; // Backup file
3363 ppdcDriver
*d
; // Current driver
3364 ppdcString
*st
; // Current string
3365 ppdcAttr
*a
; // Current attribute
3366 ppdcConstraint
*co
; // Current constraint
3367 ppdcFilter
*fi
; // Current filter
3368 ppdcFont
*fo
; // Current font
3369 ppdcGroup
*g
; // Current group
3370 ppdcOption
*o
; // Current option
3371 ppdcChoice
*ch
; // Current choice
3372 ppdcProfile
*p
; // Current color profile
3373 ppdcMediaSize
*si
; // Current media size
3374 float left
, // Current left margin
3375 bottom
, // Current bottom margin
3376 right
, // Current right margin
3377 top
; // Current top margin
3378 int dtused
[PPDC_DRIVER_MAX
];// Driver type usage...
3381 // Rename the current file, if any, to .bck...
3382 snprintf(bckname
, sizeof(bckname
), "%s.bck", f
);
3385 // Open the output file...
3386 fp
= cupsFileOpen(f
, "w");
3390 // Can't create file; restore backup and return...
3395 cupsFilePuts(fp
, "// CUPS PPD Compiler " CUPS_SVERSION
"\n\n");
3397 // Include standard files...
3398 cupsFilePuts(fp
, "// Include necessary files...\n");
3399 cupsFilePuts(fp
, "#include <font.defs>\n");
3400 cupsFilePuts(fp
, "#include <media.defs>\n");
3402 memset(dtused
, 0, sizeof(dtused
));
3404 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
3405 if (d
->type
> PPDC_DRIVER_PS
&& !dtused
[d
->type
])
3407 cupsFilePrintf(fp
, "#include <%s.h>\n", driver_types
[d
->type
]);
3408 dtused
[d
->type
] = 1;
3411 // Output each driver...
3412 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
3414 // Start the driver...
3415 cupsFilePrintf(fp
, "\n// %s %s\n", d
->manufacturer
->value
, d
->model_name
->value
);
3416 cupsFilePuts(fp
, "{\n");
3418 // Write the copyright stings...
3419 for (st
= (ppdcString
*)d
->copyright
->first();
3421 st
= (ppdcString
*)d
->copyright
->next())
3422 quotef(fp
, " Copyright \"%s\"\n", st
->value
);
3424 // Write other strings and values...
3425 if (d
->manufacturer
&& d
->manufacturer
->value
)
3426 quotef(fp
, " Manufacturer \"%s\"\n", d
->manufacturer
->value
);
3427 if (d
->model_name
->value
)
3428 quotef(fp
, " ModelName \"%s\"\n", d
->model_name
->value
);
3429 if (d
->file_name
&& d
->file_name
->value
)
3430 quotef(fp
, " FileName \"%s\"\n", d
->file_name
->value
);
3431 if (d
->pc_file_name
&& d
->pc_file_name
->value
)
3432 quotef(fp
, " PCFileName \"%s\"\n", d
->pc_file_name
->value
);
3433 if (d
->version
&& d
->version
->value
)
3434 quotef(fp
, " Version \"%s\"\n", d
->version
->value
);
3436 cupsFilePrintf(fp
, " DriverType %s\n", driver_types
[d
->type
]);
3438 if (d
->model_number
)
3442 case PPDC_DRIVER_ESCP
:
3443 cupsFilePuts(fp
, " ModelNumber (");
3445 if (d
->model_number
& ESCP_DOTMATRIX
)
3446 cupsFilePuts(fp
, " $ESCP_DOTMATRIX");
3447 if (d
->model_number
& ESCP_MICROWEAVE
)
3448 cupsFilePuts(fp
, " $ESCP_MICROWEAVE");
3449 if (d
->model_number
& ESCP_STAGGER
)
3450 cupsFilePuts(fp
, " $ESCP_STAGGER");
3451 if (d
->model_number
& ESCP_ESCK
)
3452 cupsFilePuts(fp
, " $ESCP_ESCK");
3453 if (d
->model_number
& ESCP_EXT_UNITS
)
3454 cupsFilePuts(fp
, " $ESCP_EXT_UNITS");
3455 if (d
->model_number
& ESCP_EXT_MARGINS
)
3456 cupsFilePuts(fp
, " $ESCP_EXT_MARGINS");
3457 if (d
->model_number
& ESCP_USB
)
3458 cupsFilePuts(fp
, " $ESCP_USB");
3459 if (d
->model_number
& ESCP_PAGE_SIZE
)
3460 cupsFilePuts(fp
, " $ESCP_PAGE_SIZE");
3461 if (d
->model_number
& ESCP_RASTER_ESCI
)
3462 cupsFilePuts(fp
, " $ESCP_RASTER_ESCI");
3463 if (d
->model_number
& ESCP_REMOTE
)
3464 cupsFilePuts(fp
, " $ESCP_REMOTE");
3466 cupsFilePuts(fp
, ")\n");
3469 case PPDC_DRIVER_PCL
:
3470 cupsFilePuts(fp
, " ModelNumber (");
3472 if (d
->model_number
& PCL_PAPER_SIZE
)
3473 cupsFilePuts(fp
, " $PCL_PAPER_SIZE");
3474 if (d
->model_number
& PCL_INKJET
)
3475 cupsFilePuts(fp
, " $PCL_INKJET");
3476 if (d
->model_number
& PCL_RASTER_END_COLOR
)
3477 cupsFilePuts(fp
, " $PCL_RASTER_END_COLOR");
3478 if (d
->model_number
& PCL_RASTER_CID
)
3479 cupsFilePuts(fp
, " $PCL_RASTER_CID");
3480 if (d
->model_number
& PCL_RASTER_CRD
)
3481 cupsFilePuts(fp
, " $PCL_RASTER_CRD");
3482 if (d
->model_number
& PCL_RASTER_SIMPLE
)
3483 cupsFilePuts(fp
, " $PCL_RASTER_SIMPLE");
3484 if (d
->model_number
& PCL_RASTER_RGB24
)
3485 cupsFilePuts(fp
, " $PCL_RASTER_RGB24");
3486 if (d
->model_number
& PCL_PJL
)
3487 cupsFilePuts(fp
, " $PCL_PJL");
3488 if (d
->model_number
& PCL_PJL_PAPERWIDTH
)
3489 cupsFilePuts(fp
, " $PCL_PJL_PAPERWIDTH");
3490 if (d
->model_number
& PCL_PJL_HPGL2
)
3491 cupsFilePuts(fp
, " $PCL_PJL_HPGL2");
3492 if (d
->model_number
& PCL_PJL_PCL3GUI
)
3493 cupsFilePuts(fp
, " $PCL_PJL_PCL3GUI");
3494 if (d
->model_number
& PCL_PJL_RESOLUTION
)
3495 cupsFilePuts(fp
, " $PCL_PJL_RESOLUTION");
3497 cupsFilePuts(fp
, ")\n");
3500 case PPDC_DRIVER_LABEL
:
3501 cupsFilePuts(fp
, " ModelNumber ");
3503 switch (d
->model_number
)
3506 cupsFilePuts(fp
, "$DYMO_3x0\n");
3509 case ZEBRA_EPL_LINE
:
3510 cupsFilePuts(fp
, "$ZEBRA_EPL_LINE\n");
3513 case ZEBRA_EPL_PAGE
:
3514 cupsFilePuts(fp
, "$ZEBRA_EPL_PAGE\n");
3518 cupsFilePuts(fp
, "$ZEBRA_ZPL\n");
3522 cupsFilePuts(fp
, "$ZEBRA_CPCL\n");
3525 case INTELLITECH_PCL
:
3526 cupsFilePuts(fp
, "$INTELLITECH_PCL\n");
3530 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3535 case PPDC_DRIVER_EPSON
:
3536 cupsFilePuts(fp
, " ModelNumber ");
3538 switch (d
->model_number
)
3541 cupsFilePuts(fp
, "$EPSON_9PIN\n");
3545 cupsFilePuts(fp
, "$EPSON_24PIN\n");
3549 cupsFilePuts(fp
, "$EPSON_COLOR\n");
3553 cupsFilePuts(fp
, "$EPSON_PHOTO\n");
3557 cupsFilePuts(fp
, "$EPSON_ICOLOR\n");
3561 cupsFilePuts(fp
, "$EPSON_IPHOTO\n");
3565 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3570 case PPDC_DRIVER_HP
:
3571 cupsFilePuts(fp
, " ModelNumber ");
3572 switch (d
->model_number
)
3575 cupsFilePuts(fp
, "$HP_LASERJET\n");
3579 cupsFilePuts(fp
, "$HP_DESKJET\n");
3583 cupsFilePuts(fp
, "$HP_DESKJET2\n");
3587 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3591 cupsFilePuts(fp
, ")\n");
3595 cupsFilePrintf(fp
, " ModelNumber %d\n", d
->model_number
);
3600 if (d
->manual_copies
)
3601 cupsFilePuts(fp
, " ManualCopies Yes\n");
3603 if (d
->color_device
)
3604 cupsFilePuts(fp
, " ColorDevice Yes\n");
3607 cupsFilePrintf(fp
, " Throughput %d\n", d
->throughput
);
3609 // Output all of the attributes...
3610 for (a
= (ppdcAttr
*)d
->attrs
->first();
3612 a
= (ppdcAttr
*)d
->attrs
->next())
3613 if (a
->text
->value
&& a
->text
->value
[0])
3614 quotef(fp
, " Attribute \"%s\" \"%s/%s\" \"%s\"\n",
3615 a
->name
->value
, a
->selector
->value
? a
->selector
->value
: "",
3616 a
->text
->value
, a
->value
->value
? a
->value
->value
: "");
3618 quotef(fp
, " Attribute \"%s\" \"%s\" \"%s\"\n",
3619 a
->name
->value
, a
->selector
->value
? a
->selector
->value
: "",
3620 a
->value
->value
? a
->value
->value
: "");
3622 // Output all of the constraints...
3623 for (co
= (ppdcConstraint
*)d
->constraints
->first();
3625 co
= (ppdcConstraint
*)d
->constraints
->next())
3627 if (co
->option1
->value
[0] == '*')
3628 cupsFilePrintf(fp
, " UIConstraints \"%s %s", co
->option1
->value
,
3629 co
->choice1
->value
? co
->choice1
->value
: "");
3631 cupsFilePrintf(fp
, " UIConstraints \"*%s %s", co
->option1
->value
,
3632 co
->choice1
->value
? co
->choice1
->value
: "");
3634 if (co
->option2
->value
[0] == '*')
3635 cupsFilePrintf(fp
, " %s %s\"\n", co
->option2
->value
,
3636 co
->choice2
->value
? co
->choice2
->value
: "");
3638 cupsFilePrintf(fp
, " *%s %s\"\n", co
->option2
->value
,
3639 co
->choice2
->value
? co
->choice2
->value
: "");
3642 // Output all of the filters...
3643 for (fi
= (ppdcFilter
*)d
->filters
->first();
3645 fi
= (ppdcFilter
*)d
->filters
->next())
3646 cupsFilePrintf(fp
, " Filter \"%s %d %s\"\n",
3647 fi
->mime_type
->value
, fi
->cost
, fi
->program
->value
);
3649 // Output all of the fonts...
3650 for (fo
= (ppdcFont
*)d
->fonts
->first();
3652 fo
= (ppdcFont
*)d
->fonts
->next())
3653 if (!strcmp(fo
->name
->value
, "*"))
3654 cupsFilePuts(fp
, " Font *\n");
3656 cupsFilePrintf(fp
, " Font \"%s\" \"%s\" \"%s\" \"%s\" %s\n",
3657 fo
->name
->value
, fo
->encoding
->value
,
3658 fo
->version
->value
, fo
->charset
->value
,
3659 fo
->status
== PPDC_FONT_ROM
? "ROM" : "Disk");
3661 // Output all options...
3662 for (g
= (ppdcGroup
*)d
->groups
->first();
3664 g
= (ppdcGroup
*)d
->groups
->next())
3666 if (g
->options
->count
== 0)
3669 if (g
->text
->value
&& g
->text
->value
[0])
3670 quotef(fp
, " Group \"%s/%s\"\n", g
->name
->value
, g
->text
->value
);
3672 cupsFilePrintf(fp
, " Group \"%s\"\n", g
->name
->value
);
3674 for (o
= (ppdcOption
*)g
->options
->first();
3676 o
= (ppdcOption
*)g
->options
->next())
3678 if (o
->choices
->count
== 0)
3681 if (o
->text
->value
&& o
->text
->value
[0])
3682 quotef(fp
, " Option \"%s/%s\"", o
->name
->value
, o
->text
->value
);
3684 cupsFilePrintf(fp
, " Option \"%s\"", o
->name
->value
);
3686 cupsFilePrintf(fp
, " %s %s %.1f\n",
3687 o
->type
== PPDC_BOOLEAN
? "Boolean" :
3688 o
->type
== PPDC_PICKONE
? "PickOne" : "PickMany",
3689 o
->section
== PPDC_SECTION_ANY
? "AnySetup" :
3690 o
->section
== PPDC_SECTION_DOCUMENT
? "DocumentSetup" :
3691 o
->section
== PPDC_SECTION_EXIT
? "ExitServer" :
3692 o
->section
== PPDC_SECTION_JCL
? "JCLSetup" :
3693 o
->section
== PPDC_SECTION_PAGE
? "PageSetup" :
3697 for (ch
= (ppdcChoice
*)o
->choices
->first();
3699 ch
= (ppdcChoice
*)o
->choices
->next())
3701 if (ch
->text
->value
&& ch
->text
->value
[0])
3702 quotef(fp
, " %sChoice \"%s/%s\" \"%s\"\n",
3703 o
->defchoice
== ch
->name
? "*" : "",
3704 ch
->name
->value
, ch
->text
->value
,
3705 ch
->code
->value
? ch
->code
->value
: "");
3707 quotef(fp
, " %sChoice \"%s\" \"%s\"\n",
3708 o
->defchoice
== ch
->name
? "*" : "",
3710 ch
->code
->value
? ch
->code
->value
: "");
3715 // Output all of the color profiles...
3716 for (p
= (ppdcProfile
*)d
->profiles
->first();
3718 p
= (ppdcProfile
*)d
->profiles
->next())
3719 cupsFilePrintf(fp
, " ColorProfile \"%s/%s\" %.3f %.3f "
3720 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
3721 p
->resolution
->value
, p
->media_type
->value
,
3722 p
->density
, p
->gamma
,
3723 p
->profile
[0], p
->profile
[1], p
->profile
[2],
3724 p
->profile
[3], p
->profile
[4], p
->profile
[5],
3725 p
->profile
[6], p
->profile
[7], p
->profile
[8]);
3727 // Output all of the media sizes...
3733 for (si
= (ppdcMediaSize
*)d
->sizes
->first();
3735 si
= (ppdcMediaSize
*)d
->sizes
->next())
3736 if (si
->size_code
->value
&& si
->region_code
->value
)
3738 // Output a custom media size...
3739 quotef(fp
, " %sCustomMedia \"%s/%s\" %.2f %.2f %.2f %.2f %.2f %.2f \"%s\" \"%s\"\n",
3740 si
->name
== d
->default_size
? "*" : "", si
->name
->value
,
3741 si
->text
->value
, si
->width
, si
->length
, si
->left
, si
->bottom
,
3742 si
->right
, si
->top
, si
->size_code
->value
,
3743 si
->region_code
->value
);
3747 // Output a standard media size...
3748 if (fabs(left
- si
->left
) > 0.1 ||
3749 fabs(bottom
- si
->bottom
) > 0.1 ||
3750 fabs(right
- si
->right
) > 0.1 ||
3751 fabs(top
- si
->top
) > 0.1)
3753 cupsFilePrintf(fp
, " HWMargins %.2f %.2f %.2f %.2f\n",
3754 si
->left
, si
->bottom
, si
->right
, si
->top
);
3757 bottom
= si
->bottom
;
3762 cupsFilePrintf(fp
, " %sMediaSize %s\n",
3763 si
->name
== d
->default_size
? "*" : "",
3767 if (d
->variable_paper_size
)
3769 cupsFilePuts(fp
, " VariablePaperSize Yes\n");
3771 if (fabs(left
- d
->left_margin
) > 0.1 ||
3772 fabs(bottom
- d
->bottom_margin
) > 0.1 ||
3773 fabs(right
- d
->right_margin
) > 0.1 ||
3774 fabs(top
- d
->top_margin
) > 0.1)
3776 cupsFilePrintf(fp
, " HWMargins %.2f %.2f %.2f %.2f\n",
3777 d
->left_margin
, d
->bottom_margin
, d
->right_margin
,
3781 cupsFilePrintf(fp
, " MinSize %.2f %.2f\n", d
->min_width
, d
->min_length
);
3782 cupsFilePrintf(fp
, " MaxSize %.2f %.2f\n", d
->max_width
, d
->max_length
);
3785 // End the driver...
3786 cupsFilePuts(fp
, "}\n");
3789 // Close the file and return...