]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc-source.cxx
4 // Source class for the CUPS PPD Compiler.
6 // Copyright 2007-2008 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
96 filename
= new ppdcString(f
);
97 base_fonts
= new ppdcArray();
98 drivers
= new ppdcArray();
99 po_files
= new ppdcArray();
100 sizes
= new ppdcArray();
101 vars
= new ppdcArray();
109 // 'ppdcSource::~ppdcSource()' - Free a driver source file.
112 ppdcSource::~ppdcSource()
124 // 'ppdcSource::add_include()' - Add an include directory.
128 ppdcSource::add_include(const char *d
) // I - Include directory
134 includes
= new ppdcArray();
136 includes
->add(new ppdcString(d
));
141 // 'ppdcSource::find_driver()' - Find a driver.
144 ppdcDriver
* // O - Driver
145 ppdcSource::find_driver(const char *f
) // I - Driver file name
147 ppdcDriver
*d
; // Current driver
150 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
151 if (!strcasecmp(f
, d
->pc_file_name
->value
))
159 // 'ppdcSource::find_include()' - Find an include file.
162 char * // O - Found path or NULL
163 ppdcSource::find_include(
164 const char *f
, // I - Include filename
165 const char *base
, // I - Current directory
166 char *n
, // I - Path buffer
167 int nlen
) // I - Path buffer length
169 ppdcString
*dir
; // Include directory
170 char temp
[1024], // Temporary path
171 *ptr
; // Pointer to end of path
174 // Range check input...
175 if (!f
|| !*f
|| !n
|| nlen
< 2)
178 // Check the first character to see if we have <name> or "name"...
181 // Remove the surrounding <> from the name...
182 strlcpy(temp
, f
+ 1, sizeof(temp
));
183 ptr
= temp
+ strlen(temp
) - 1;
187 fprintf(stderr
, "ppdc: Invalid #include/#po filename \"%s\"!\n", n
);
196 // Check for the local file relative to the current directory...
197 if (base
&& *base
&& f
[0] != '/')
198 snprintf(n
, nlen
, "%s/%s", base
, f
);
206 // Absolute path that doesn't exist...
211 // Search the include directories, if any...
214 for (dir
= (ppdcString
*)includes
->first(); dir
; dir
= (ppdcString
*)includes
->next())
216 snprintf(n
, nlen
, "%s/%s", dir
->value
, f
);
222 // Search the standard include directories...
223 _cups_globals_t
*cg
= _cupsGlobals(); // Global data
225 snprintf(n
, nlen
, "%s/ppdc/%s", cg
->cups_datadir
, f
);
229 snprintf(n
, nlen
, "%s/po/%s", cg
->cups_datadir
, f
);
238 // 'ppdcSource::find_po()' - Find a message catalog for the given locale...
241 ppdcCatalog
* // O - Message catalog or NULL
242 ppdcSource::find_po(const char *l
) // I - Locale name
244 ppdcCatalog
*cat
; // Current message catalog
247 for (cat
= (ppdcCatalog
*)po_files
->first();
249 cat
= (ppdcCatalog
*)po_files
->next())
250 if (!strcasecmp(l
, cat
->locale
->value
))
258 // 'ppdcSource::find_size()' - Find a media size.
261 ppdcMediaSize
* // O - Size
262 ppdcSource::find_size(const char *s
) // I - Size name
264 ppdcMediaSize
*m
; // Current media size
267 for (m
= (ppdcMediaSize
*)sizes
->first(); m
; m
= (ppdcMediaSize
*)sizes
->next())
268 if (!strcasecmp(s
, m
->name
->value
))
276 // 'ppdcSource::find_variable()' - Find a variable.
279 ppdcVariable
* // O - Variable
280 ppdcSource::find_variable(const char *n
)// I - Variable name
282 ppdcVariable
*v
; // Current variable
285 for (v
= (ppdcVariable
*)vars
->first(); v
; v
= (ppdcVariable
*)vars
->next())
286 if (!strcasecmp(n
, v
->name
->value
))
294 // 'ppdcSource::get_attr()' - Get an attribute.
297 ppdcAttr
* // O - Attribute
298 ppdcSource::get_attr(ppdcFile
*fp
) // I - File to read
300 char name
[1024], // Name string
301 selector
[1024], // Selector string
302 *text
, // Text string
303 value
[1024]; // Value string
306 // Get the attribute parameters:
308 // Attribute name selector value
309 if (!get_token(fp
, name
, sizeof(name
)))
311 fprintf(stderr
, "ppdc: Expected name after Attribute on line %d of %s!\n",
312 fp
->line
, fp
->filename
);
316 if (!get_token(fp
, selector
, sizeof(selector
)))
318 fprintf(stderr
, "ppdc: Expected selector after Attribute on line %d of %s!\n",
319 fp
->line
, fp
->filename
);
323 if ((text
= strchr(selector
, '/')) != NULL
)
326 if (!get_token(fp
, value
, sizeof(value
)))
328 fprintf(stderr
, "ppdc: Expected value after Attribute on line %d of %s!\n",
329 fp
->line
, fp
->filename
);
333 // printf("name=\"%s\", selector=\"%s\", value=\"%s\"\n", name, selector, value);
335 return (new ppdcAttr(name
, selector
, text
, value
));
340 // 'ppdcSource::get_boolean()' - Get a boolean value.
343 int // O - Boolean value
344 ppdcSource::get_boolean(ppdcFile
*fp
) // I - File to read
346 char buffer
[256]; // String buffer
349 if (!get_token(fp
, buffer
, sizeof(buffer
)))
351 fprintf(stderr
, "ppdc: Expected boolean value on line %d of %s.\n",
352 fp
->line
, fp
->filename
);
356 if (!strcasecmp(buffer
, "on") ||
357 !strcasecmp(buffer
, "yes") ||
358 !strcasecmp(buffer
, "true"))
360 else if (!strcasecmp(buffer
, "off") ||
361 !strcasecmp(buffer
, "no") ||
362 !strcasecmp(buffer
, "false"))
366 fprintf(stderr
, "ppdc: Bad boolean value (%s) on line %d of %s.\n",
367 buffer
, fp
->line
, fp
->filename
);
374 // 'ppdcSource::get_choice()' - Get a choice.
377 ppdcChoice
* // O - Choice data
378 ppdcSource::get_choice(ppdcFile
*fp
) // I - File to read
380 char name
[1024], // Name
385 // Read a choice from the file:
387 // Choice name/text code
388 if (!get_token(fp
, name
, sizeof(name
)))
390 fprintf(stderr
, "ppdc: Expected choice name/text on line %d of %s.\n",
391 fp
->line
, fp
->filename
);
395 if ((text
= strchr(name
, '/')) != NULL
)
400 if (!get_token(fp
, code
, sizeof(code
)))
402 fprintf(stderr
, "ppdc: Expected choice code on line %d of %s.\n",
403 fp
->line
, fp
->filename
);
407 // Return the new choice
408 return (new ppdcChoice(name
, text
, code
));
413 // 'ppdcSource::get_color_model()' - Get an old-style color model option.
416 ppdcChoice
* // O - Choice data
417 ppdcSource::get_color_model(ppdcFile
*fp
)
420 char name
[1024], // Option name
421 *text
, // Text option
422 temp
[256]; // Temporary string
423 int color_space
, // Colorspace
424 color_order
, // Color order
425 compression
; // Compression mode
428 // Get the ColorModel parameters:
430 // ColorModel name/text colorspace colororder compression
431 if (!get_token(fp
, name
, sizeof(name
)))
434 "ppdc: Expected name/text combination for ColorModel on line "
436 fp
->line
, fp
->filename
);
440 if ((text
= strchr(name
, '/')) != NULL
)
445 if (!get_token(fp
, temp
, sizeof(temp
)))
448 "ppdc: Expected colorspace for ColorModel on line %d of %s!\n",
449 fp
->line
, fp
->filename
);
453 if ((color_space
= get_color_space(temp
)) < 0)
454 color_space
= get_integer(temp
);
456 if (!get_token(fp
, temp
, sizeof(temp
)))
459 "ppdc: Expected color order for ColorModel on line %d of %s!\n",
460 fp
->line
, fp
->filename
);
464 if ((color_order
= get_color_order(temp
)) < 0)
465 color_order
= get_integer(temp
);
467 if (!get_token(fp
, temp
, sizeof(temp
)))
470 "ppdc: Expected compression for ColorModel on line %d of %s!\n",
471 fp
->line
, fp
->filename
);
475 compression
= get_integer(temp
);
477 snprintf(temp
, sizeof(temp
),
478 "<</cupsColorSpace %d/cupsColorOrder %d/cupsCompression %d>>"
480 color_space
, color_order
, compression
);
482 return (new ppdcChoice(name
, text
, temp
));
487 // 'ppdcSource::get_color_order()' - Get an old-style color order value.
490 int // O - Color order value
491 ppdcSource::get_color_order(
492 const char *co
) // I - Color order string
494 if (!strcasecmp(co
, "chunked") ||
495 !strcasecmp(co
, "chunky"))
496 return (CUPS_ORDER_CHUNKED
);
497 else if (!strcasecmp(co
, "banded"))
498 return (CUPS_ORDER_BANDED
);
499 else if (!strcasecmp(co
, "planar"))
500 return (CUPS_ORDER_PLANAR
);
507 // 'ppdcSource::get_color_profile()' - Get a color profile definition.
510 ppdcProfile
* // O - Color profile
511 ppdcSource::get_color_profile(
512 ppdcFile
*fp
) // I - File to read
514 char resolution
[1024], // Resolution/media type
515 *media_type
; // Media type
516 int i
; // Looping var
517 float g
, // Gamma value
519 m
[9]; // Transform matrix
522 // Get the ColorProfile parameters:
524 // ColorProfile resolution/mediatype gamma density m00 m01 m02 ... m22
525 if (!get_token(fp
, resolution
, sizeof(resolution
)))
527 fprintf(stderr
, "ppdc: Expected resolution/mediatype following ColorProfile on line %d of %s!\n",
528 fp
->line
, fp
->filename
);
532 if ((media_type
= strchr(resolution
, '/')) != NULL
)
533 *media_type
++ = '\0';
535 media_type
= resolution
;
539 for (i
= 0; i
< 9; i
++)
540 m
[i
] = get_float(fp
);
542 return (new ppdcProfile(resolution
, media_type
, g
, d
, m
));
547 // 'ppdcSource::get_color_space()' - Get an old-style colorspace value.
550 int // O - Colorspace value
551 ppdcSource::get_color_space(
552 const char *cs
) // I - Colorspace string
554 if (!strcasecmp(cs
, "w"))
555 return (CUPS_CSPACE_W
);
556 else if (!strcasecmp(cs
, "rgb"))
557 return (CUPS_CSPACE_RGB
);
558 else if (!strcasecmp(cs
, "rgba"))
559 return (CUPS_CSPACE_RGBA
);
560 else if (!strcasecmp(cs
, "k"))
561 return (CUPS_CSPACE_K
);
562 else if (!strcasecmp(cs
, "cmy"))
563 return (CUPS_CSPACE_CMY
);
564 else if (!strcasecmp(cs
, "ymc"))
565 return (CUPS_CSPACE_YMC
);
566 else if (!strcasecmp(cs
, "cmyk"))
567 return (CUPS_CSPACE_CMYK
);
568 else if (!strcasecmp(cs
, "ymck"))
569 return (CUPS_CSPACE_YMCK
);
570 else if (!strcasecmp(cs
, "kcmy"))
571 return (CUPS_CSPACE_KCMY
);
572 else if (!strcasecmp(cs
, "kcmycm"))
573 return (CUPS_CSPACE_KCMYcm
);
574 else if (!strcasecmp(cs
, "gmck"))
575 return (CUPS_CSPACE_GMCK
);
576 else if (!strcasecmp(cs
, "gmcs"))
577 return (CUPS_CSPACE_GMCS
);
578 else if (!strcasecmp(cs
, "white"))
579 return (CUPS_CSPACE_WHITE
);
580 else if (!strcasecmp(cs
, "gold"))
581 return (CUPS_CSPACE_GOLD
);
582 else if (!strcasecmp(cs
, "silver"))
583 return (CUPS_CSPACE_SILVER
);
584 else if (!strcasecmp(cs
, "CIEXYZ"))
585 return (CUPS_CSPACE_CIEXYZ
);
586 else if (!strcasecmp(cs
, "CIELab"))
587 return (CUPS_CSPACE_CIELab
);
588 else if (!strcasecmp(cs
, "RGBW"))
589 return (CUPS_CSPACE_RGBW
);
590 else if (!strcasecmp(cs
, "ICC1"))
591 return (CUPS_CSPACE_ICC1
);
592 else if (!strcasecmp(cs
, "ICC2"))
593 return (CUPS_CSPACE_ICC2
);
594 else if (!strcasecmp(cs
, "ICC3"))
595 return (CUPS_CSPACE_ICC3
);
596 else if (!strcasecmp(cs
, "ICC4"))
597 return (CUPS_CSPACE_ICC4
);
598 else if (!strcasecmp(cs
, "ICC5"))
599 return (CUPS_CSPACE_ICC5
);
600 else if (!strcasecmp(cs
, "ICC6"))
601 return (CUPS_CSPACE_ICC6
);
602 else if (!strcasecmp(cs
, "ICC7"))
603 return (CUPS_CSPACE_ICC7
);
604 else if (!strcasecmp(cs
, "ICC8"))
605 return (CUPS_CSPACE_ICC8
);
606 else if (!strcasecmp(cs
, "ICC9"))
607 return (CUPS_CSPACE_ICC9
);
608 else if (!strcasecmp(cs
, "ICCA"))
609 return (CUPS_CSPACE_ICCA
);
610 else if (!strcasecmp(cs
, "ICCB"))
611 return (CUPS_CSPACE_ICCB
);
612 else if (!strcasecmp(cs
, "ICCC"))
613 return (CUPS_CSPACE_ICCC
);
614 else if (!strcasecmp(cs
, "ICCD"))
615 return (CUPS_CSPACE_ICCD
);
616 else if (!strcasecmp(cs
, "ICCE"))
617 return (CUPS_CSPACE_ICCE
);
618 else if (!strcasecmp(cs
, "ICCF"))
619 return (CUPS_CSPACE_ICCF
);
626 // 'ppdcSource::get_constraint()' - Get a constraint.
629 ppdcConstraint
* // O - Constraint
630 ppdcSource::get_constraint(ppdcFile
*fp
)// I - File to read
632 char temp
[1024], // One string to rule them all
633 *ptr
, // Pointer into string
634 *option1
, // Constraint option 1
635 *choice1
, // Constraint choice 1
636 *option2
, // Constraint option 2
637 *choice2
; // Constraint choice 2
640 // Read the UIConstaints parameter in one of the following forms:
642 // UIConstraints "*Option1 *Option2"
643 // UIConstraints "*Option1 Choice1 *Option2"
644 // UIConstraints "*Option1 *Option2 Choice2"
645 // UIConstraints "*Option1 Choice1 *Option2 Choice2"
646 if (!get_token(fp
, temp
, sizeof(temp
)))
648 fprintf(stderr
, "ppdc: Expected constraints string for UIConstraints on line %d of %s!\n",
649 fp
->line
, fp
->filename
);
653 for (ptr
= temp
; isspace(*ptr
); ptr
++);
657 fprintf(stderr
, "ppdc: Option constraint must *name on line %d of %s!\n",
658 fp
->line
, fp
->filename
);
664 for (; *ptr
&& !isspace(*ptr
); ptr
++);
665 for (; isspace(*ptr
); *ptr
++ = '\0');
671 for (; *ptr
&& !isspace(*ptr
); ptr
++);
672 for (; isspace(*ptr
); *ptr
++ = '\0');
679 fprintf(stderr
, "ppdc: Expected two option names on line %d of %s!\n",
680 fp
->line
, fp
->filename
);
686 for (; *ptr
&& !isspace(*ptr
); ptr
++);
687 for (; isspace(*ptr
); *ptr
++ = '\0');
694 return (new ppdcConstraint(option1
, choice1
, option2
, choice2
));
699 // 'ppdcSource::get_custom_size()' - Get a custom media size definition from a file.
702 ppdcMediaSize
* // O - Media size
703 ppdcSource::get_custom_size(ppdcFile
*fp
)
706 char name
[1024], // Name
708 size_code
[10240], // PageSize code
709 region_code
[10240]; // PageRegion
710 float width
, // Width
713 bottom
, // Bottom margin
714 right
, // Right margin
718 // Get the name, text, width, length, margins, and code:
720 // CustomMedia name/text width length left bottom right top size-code region-code
721 if (!get_token(fp
, name
, sizeof(name
)))
724 if ((text
= strchr(name
, '/')) != NULL
)
729 if ((width
= get_measurement(fp
)) < 0.0f
)
732 if ((length
= get_measurement(fp
)) < 0.0f
)
735 if ((left
= get_measurement(fp
)) < 0.0f
)
738 if ((bottom
= get_measurement(fp
)) < 0.0f
)
741 if ((right
= get_measurement(fp
)) < 0.0f
)
744 if ((top
= get_measurement(fp
)) < 0.0f
)
747 if (!get_token(fp
, size_code
, sizeof(size_code
)))
750 if (!get_token(fp
, region_code
, sizeof(region_code
)))
753 // Return the new media size...
754 return (new ppdcMediaSize(name
, text
, width
, length
, left
, bottom
,
755 right
, top
, size_code
, region_code
));
760 // 'ppdcSource::get_duplex()' - Get a duplex option.
764 ppdcSource::get_duplex(ppdcFile
*fp
, // I - File to read from
765 ppdcDriver
*d
) // I - Current driver
767 char temp
[256]; // Duplex keyword
768 ppdcAttr
*attr
; // cupsFlipDuplex attribute
769 ppdcGroup
*g
; // Current group
770 ppdcOption
*o
; // Duplex option
773 // Duplex {boolean|none|normal|flip}
774 if (!get_token(fp
, temp
, sizeof(temp
)))
776 fprintf(stderr
, "ppdc: Expected duplex type after Duplex on line %d of %s!\n",
777 fp
->line
, fp
->filename
);
781 if (!strcasecmp(temp
, "none") || !strcasecmp(temp
, "false") ||
782 !strcasecmp(temp
, "no") || !strcasecmp(temp
, "off"))
784 g
= d
->find_group("General");
785 if ((o
= g
->find_option("Duplex")) != NULL
)
786 g
->options
->remove(o
);
788 for (attr
= (ppdcAttr
*)d
->attrs
->first();
790 attr
= (ppdcAttr
*)d
->attrs
->next())
791 if (!strcmp(attr
->name
->value
, "cupsFlipDuplex"))
793 d
->attrs
->remove(attr
);
797 else if (!strcasecmp(temp
, "normal") || !strcasecmp(temp
, "true") ||
798 !strcasecmp(temp
, "yes") || !strcasecmp(temp
, "on") ||
799 !strcasecmp(temp
, "flip"))
801 g
= d
->find_group("General");
802 o
= g
->find_option("Duplex");
806 o
= new ppdcOption(PPDC_PICKONE
, "Duplex", "2-Sided Printing",
807 !strcasecmp(temp
, "flip") ? PPDC_SECTION_PAGE
:
808 PPDC_SECTION_ANY
, 10.0f
);
809 o
->add_choice(new ppdcChoice("None", "Off (1-Sided)",
810 "<</Duplex false>>setpagedevice"));
811 o
->add_choice(new ppdcChoice("DuplexNoTumble", "Long-Edge (Portrait)",
812 "<</Duplex true/Tumble false>>setpagedevice"));
813 o
->add_choice(new ppdcChoice("DuplexTumble", "Short-Edge (Landscape)",
814 "<</Duplex true/Tumble true>>setpagedevice"));
819 for (attr
= (ppdcAttr
*)d
->attrs
->first();
821 attr
= (ppdcAttr
*)d
->attrs
->next())
822 if (!strcmp(attr
->name
->value
, "cupsFlipDuplex"))
824 if (strcasecmp(temp
, "flip"))
825 d
->attrs
->remove(attr
);
829 if (!strcasecmp(temp
, "flip") && !attr
)
830 d
->add_attr(new ppdcAttr("cupsFlipDuplex", NULL
, NULL
, "true"));
833 fprintf(stderr
, "ppdc: Unknown duplex type \"%s\" on line %d of %s!\n",
834 temp
, fp
->line
, fp
->filename
);
839 // 'ppdcSource::get_filter()' - Get a filter.
842 ppdcFilter
* // O - Filter
843 ppdcSource::get_filter(ppdcFile
*fp
) // I - File to read
845 char type
[1024], // MIME type
846 program
[1024], // Filter program
847 *ptr
; // Pointer into MIME type
848 int cost
; // Relative cost
851 // Read filter parameters in one of the following formats:
853 // Filter "type cost program"
854 // Filter type cost program
856 if (!get_token(fp
, type
, sizeof(type
)))
858 fprintf(stderr
, "ppdc: Expected a filter definition on line %d of %s!\n",
859 fp
->line
, fp
->filename
);
863 if ((ptr
= strchr(type
, ' ')) != NULL
)
865 // Old-style filter definition in one string...
867 cost
= strtol(ptr
, &ptr
, 10);
869 while (isspace(*ptr
))
872 strcpy(program
, ptr
);
876 cost
= get_integer(fp
);
878 if (!get_token(fp
, program
, sizeof(program
)))
880 fprintf(stderr
, "ppdc: Expected a program name on line %d of %s!\n",
881 fp
->line
, fp
->filename
);
888 fprintf(stderr
, "ppdc: Invalid empty MIME type for filter on line %d of %s!\n",
889 fp
->line
, fp
->filename
);
893 if (cost
< 0 || cost
> 200)
895 fprintf(stderr
, "ppdc: Invalid cost for filter on line %d of %s!\n",
896 fp
->line
, fp
->filename
);
902 fprintf(stderr
, "ppdc: Invalid empty program name for filter on line %d of %s!\n",
903 fp
->line
, fp
->filename
);
907 return (new ppdcFilter(type
, program
, cost
));
912 // 'ppdcSource::get_float()' - Get a single floating-point number.
916 ppdcSource::get_float(ppdcFile
*fp
) // I - File to read
918 char temp
[256], // String buffer
919 *ptr
; // Pointer into buffer
920 float val
; // Floating point value
923 // Get the number from the file and range-check...
924 if (!get_token(fp
, temp
, sizeof(temp
)))
926 fprintf(stderr
, "ppdc: Expected real number on line %d of %s!\n",
927 fp
->line
, fp
->filename
);
931 val
= (float)strtod(temp
, &ptr
);
935 fprintf(stderr
, "ppdc: Unknown trailing characters in real number \"%s\" on line %d of %s!\n",
936 temp
, fp
->line
, fp
->filename
);
945 // 'ppdcSource::get_font()' - Get a font definition.
948 ppdcFont
* // O - Font data
949 ppdcSource::get_font(ppdcFile
*fp
) // I - File to read
951 char name
[256], // Font name
952 encoding
[256], // Font encoding
953 version
[256], // Font version
954 charset
[256], // Font charset
955 temp
[256]; // Font status string
956 ppdcFontStatus status
; // Font status enumeration
959 // Read font parameters as follows:
962 // Font name encoding version charset status
963 // %font name encoding version charset status
965 // "Name" is the PostScript font name.
967 // "Encoding" is the default encoding of the font: Standard, ISOLatin1,
968 // Special, Expert, ExpertSubset, etc.
970 // "Version" is the version number string.
972 // "Charset" specifies the characters that are included in the font:
973 // Standard, Special, Expert, Adobe-Identity, etc.
975 // "Status" is the keyword ROM or Disk.
976 if (!get_token(fp
, name
, sizeof(name
)))
978 fprintf(stderr
, "ppdc: Expected name after Font on line %d of %s!\n",
979 fp
->line
, fp
->filename
);
983 if (!strcmp(name
, "*"))
985 // Include all base fonts...
989 status
= PPDC_FONT_ROM
;
993 // Load a full font definition...
994 if (!get_token(fp
, encoding
, sizeof(encoding
)))
996 fprintf(stderr
, "ppdc: Expected encoding after Font on line %d of %s!\n",
997 fp
->line
, fp
->filename
);
1001 if (!get_token(fp
, version
, sizeof(version
)))
1003 fprintf(stderr
, "ppdc: Expected version after Font on line %d of %s!\n",
1004 fp
->line
, fp
->filename
);
1008 if (!get_token(fp
, charset
, sizeof(charset
)))
1010 fprintf(stderr
, "ppdc: Expected charset after Font on line %d of %s!\n",
1011 fp
->line
, fp
->filename
);
1015 if (!get_token(fp
, temp
, sizeof(temp
)))
1017 fprintf(stderr
, "ppdc: Expected status after Font on line %d of %s!\n",
1018 fp
->line
, fp
->filename
);
1022 if (!strcasecmp(temp
, "ROM"))
1023 status
= PPDC_FONT_ROM
;
1024 else if (!strcasecmp(temp
, "Disk"))
1025 status
= PPDC_FONT_DISK
;
1028 fprintf(stderr
, "ppdc: Bad status keyword %s on line %d of %s!\n",
1029 temp
, fp
->line
, fp
->filename
);
1034 // printf("Font %s %s %s %s %s\n", name, encoding, version, charset, temp);
1036 return (new ppdcFont(name
, encoding
, version
, charset
, status
));
1041 // 'ppdcSource::get_generic()' - Get a generic old-style option.
1044 ppdcChoice
* // O - Choice data
1045 ppdcSource::get_generic(ppdcFile
*fp
, // I - File to read
1046 const char *keyword
,
1049 // I - Text attribute
1051 // I - Numeric attribute
1053 char name
[1024], // Name
1055 command
[256]; // Command string
1056 int val
; // Numeric value
1059 // Read one of the following parameters:
1062 // Foo integer name/text
1064 val
= get_integer(fp
);
1068 if (!get_token(fp
, name
, sizeof(name
)))
1070 fprintf(stderr
, "ppdc: Expected name/text after %s on line %d of %s!\n",
1071 keyword
, fp
->line
, fp
->filename
);
1075 if ((text
= strchr(name
, '/')) != NULL
)
1083 snprintf(command
, sizeof(command
),
1084 "<</%s(%s)/%s %d>>setpagedevice",
1085 tattr
, name
, nattr
, val
);
1087 snprintf(command
, sizeof(command
),
1088 "<</%s %d>>setpagedevice",
1092 snprintf(command
, sizeof(command
),
1093 "<</%s(%s)>>setpagedevice",
1096 return (new ppdcChoice(name
, text
, command
));
1101 // 'ppdcSource::get_group()' - Get an option group.
1104 ppdcGroup
* // O - Group
1105 ppdcSource::get_group(ppdcFile
*fp
, // I - File to read
1106 ppdcDriver
*d
) // I - Printer driver
1108 char name
[1024], // UI name
1110 ppdcGroup
*g
; // Group
1113 // Read the Group parameters:
1116 if (!get_token(fp
, name
, sizeof(name
)))
1118 fprintf(stderr
, "ppdc: Expected group name/text on line %d of %s!\n",
1119 fp
->line
, fp
->filename
);
1123 if ((text
= strchr(name
, '/')) != NULL
)
1128 // See if the group already exists...
1129 if ((g
= d
->find_group(name
)) == NULL
)
1131 // Nope, add a new one...
1132 g
= new ppdcGroup(name
, text
);
1141 // 'ppdcSource::get_installable()' - Get an installable option.
1144 ppdcOption
* // O - Option
1145 ppdcSource::get_installable(ppdcFile
*fp
)
1148 char name
[1024], // Name for installable option
1149 *text
; // Text for installable option
1150 ppdcOption
*o
; // Option
1153 // Read the parameter for an installable option:
1155 // Installable name/text
1156 if (!get_token(fp
, name
, sizeof(name
)))
1158 fprintf(stderr
, "ppdc: Expected name/text after Installable on line %d of %s!\n",
1159 fp
->line
, fp
->filename
);
1163 if ((text
= strchr(name
, '/')) != NULL
)
1168 // Create the option...
1169 o
= new ppdcOption(PPDC_BOOLEAN
, name
, text
, PPDC_SECTION_ANY
, 10.0f
);
1171 // Add the false and true choices...
1172 o
->add_choice(new ppdcChoice("False", "Not Installed", ""));
1173 o
->add_choice(new ppdcChoice("True", "Installed", ""));
1180 // 'ppdcSource::get_integer()' - Get an integer value from a string.
1183 int // O - Integer value
1184 ppdcSource::get_integer(const char *v
) // I - Value string
1187 int temp
; // Temporary value
1188 char *newv
; // New value string pointer
1191 // Parse the value string...
1195 if (isdigit(*v
) || *v
== '-' || *v
== '+')
1197 // Return a simple integer value
1198 val
= strtol(v
, (char **)&v
, 0);
1199 if (*v
|| val
== LONG_MIN
)
1206 // Return the bitwise OR of each integer in parenthesis...
1210 while (*v
&& *v
!= ')')
1212 temp
= strtol(v
, &newv
, 0);
1214 if (!*newv
|| newv
== v
|| !(isspace(*newv
) || *newv
== ')') ||
1233 // 'ppdcSource::get_integer()' - Get an integer value from a file.
1236 int // O - Integer value
1237 ppdcSource::get_integer(ppdcFile
*fp
) // I - File to read
1239 char temp
[1024]; // String buffer
1242 if (!get_token(fp
, temp
, sizeof(temp
)))
1244 fprintf(stderr
, "ppdc: Expected integer on line %d of %s!\n",
1245 fp
->line
, fp
->filename
);
1249 return (get_integer(temp
));
1254 // 'ppdcSource::get_measurement()' - Get a measurement value.
1257 float // O - Measurement value in points
1258 ppdcSource::get_measurement(ppdcFile
*fp
)
1261 char buffer
[256], // Number buffer
1262 *ptr
; // Pointer into buffer
1263 float val
; // Measurement value
1266 // Grab a token from the file...
1267 if (!get_token(fp
, buffer
, sizeof(buffer
)))
1270 // Get the floating point value of "s" and skip all digits and decimal points.
1271 val
= (float)strtod(buffer
, &ptr
);
1273 // Check for a trailing unit specifier...
1274 if (!strcasecmp(ptr
, "mm"))
1275 val
*= 72.0f
/ 25.4f
;
1276 else if (!strcasecmp(ptr
, "cm"))
1277 val
*= 72.0f
/ 2.54f
;
1278 else if (!strcasecmp(ptr
, "m"))
1279 val
*= 72.0f
/ 0.0254f
;
1280 else if (!strcasecmp(ptr
, "in"))
1282 else if (!strcasecmp(ptr
, "ft"))
1283 val
*= 72.0f
* 12.0f
;
1284 else if (strcasecmp(ptr
, "pt") && *ptr
)
1292 // 'ppdcSource::get_option()' - Get an option definition.
1295 ppdcOption
* // O - Option
1296 ppdcSource::get_option(ppdcFile
*fp
, // I - File to read
1297 ppdcDriver
*d
, // I - Printer driver
1298 ppdcGroup
*g
) // I - Current group
1300 char name
[1024], // UI name
1302 type
[256]; // UI type string
1303 ppdcOptType ot
; // Option type value
1304 ppdcOptSection section
; // Option section
1305 float order
; // Option order
1306 ppdcOption
*o
; // Option
1309 // Read the Option parameters:
1311 // Option name/text type section order
1312 if (!get_token(fp
, name
, sizeof(name
)))
1314 fprintf(stderr
, "ppdc: Expected option name/text on line %d of %s!\n",
1315 fp
->line
, fp
->filename
);
1319 if ((text
= strchr(name
, '/')) != NULL
)
1324 if (!get_token(fp
, type
, sizeof(type
)))
1326 fprintf(stderr
, "ppdc: Expected option type on line %d of %s!\n",
1327 fp
->line
, fp
->filename
);
1331 if (!strcasecmp(type
, "boolean"))
1333 else if (!strcasecmp(type
, "pickone"))
1335 else if (!strcasecmp(type
, "pickmany"))
1339 fprintf(stderr
, "ppdc: Invalid option type \"%s\" on line %d of %s!\n",
1340 type
, fp
->line
, fp
->filename
);
1344 if (!get_token(fp
, type
, sizeof(type
)))
1346 fprintf(stderr
, "ppdc: Expected option section on line %d of %s!\n",
1347 fp
->line
, fp
->filename
);
1351 if (!strcasecmp(type
, "AnySetup"))
1352 section
= PPDC_SECTION_ANY
;
1353 else if (!strcasecmp(type
, "DocumentSetup"))
1354 section
= PPDC_SECTION_DOCUMENT
;
1355 else if (!strcasecmp(type
, "ExitServer"))
1356 section
= PPDC_SECTION_EXIT
;
1357 else if (!strcasecmp(type
, "JCLSetup"))
1358 section
= PPDC_SECTION_JCL
;
1359 else if (!strcasecmp(type
, "PageSetup"))
1360 section
= PPDC_SECTION_PAGE
;
1361 else if (!strcasecmp(type
, "Prolog"))
1362 section
= PPDC_SECTION_PROLOG
;
1365 fprintf(stderr
, "ppdc: Invalid option section \"%s\" on line %d of %s!\n",
1366 type
, fp
->line
, fp
->filename
);
1370 order
= get_float(fp
);
1372 // See if the option already exists...
1373 if ((o
= d
->find_option(name
)) == NULL
)
1375 // Nope, add a new one...
1376 o
= new ppdcOption(ot
, name
, text
, section
, order
);
1379 else if (o
->type
!= ot
)
1381 // printf("o=%p, o->type=%d, o->name=%s, ot=%d, name=%s\n",
1382 // o, o->type, o->name->value, ot, name);
1383 fprintf(stderr
, "ppdc: Option already defined with a different type on line %d of %s!\n",
1384 fp
->line
, fp
->filename
);
1393 // 'ppdcSource::get_po()' - Get a message catalog.
1396 ppdcCatalog
* // O - Message catalog
1397 ppdcSource::get_po(ppdcFile
*fp
) // I - File to read
1399 char locale
[32], // Locale name
1400 poname
[1024], // Message catalog filename
1401 basedir
[1024], // Base directory
1402 *baseptr
, // Pointer into directory
1403 pofilename
[1024]; // Full filename of message catalog
1404 ppdcCatalog
*cat
; // Message catalog
1407 // Read the #po parameters:
1409 // #po locale "filename.po"
1410 if (!get_token(fp
, locale
, sizeof(locale
)))
1412 fprintf(stderr
, "ppdc: Expected locale after #po on line %d of %s!\n",
1413 fp
->line
, fp
->filename
);
1417 if (!get_token(fp
, poname
, sizeof(poname
)))
1419 fprintf(stderr
, "ppdc: Expected filename after #po %s on line %d of %s!\n",
1420 locale
, fp
->line
, fp
->filename
);
1424 // See if the locale is already loaded...
1425 if (find_po(locale
))
1427 fprintf(stderr
, "ppdc: Duplicate #po for locale %s on line %d of %s!\n",
1428 locale
, fp
->line
, fp
->filename
);
1432 // Figure out the current directory...
1433 strlcpy(basedir
, fp
->filename
, sizeof(basedir
));
1435 if ((baseptr
= strrchr(basedir
, '/')) != NULL
)
1438 strcpy(basedir
, ".");
1440 // Find the po file...
1441 if (find_include(poname
, basedir
, pofilename
, sizeof(pofilename
)))
1443 // Found it, so load it...
1444 cat
= new ppdcCatalog(locale
, pofilename
);
1446 // Reset the filename to the name supplied by the user...
1447 delete cat
->filename
;
1448 cat
->filename
= new ppdcString(poname
);
1450 // Return the catalog...
1455 fprintf(stderr
, "ppdc: Unable to find #po file %s on line %d of %s!\n",
1456 poname
, fp
->line
, fp
->filename
);
1463 // 'ppdcSource::get_resolution()' - Get an old-style resolution option.
1466 ppdcChoice
* // O - Choice data
1467 ppdcSource::get_resolution(ppdcFile
*fp
)// I - File to read
1469 char name
[1024], // Name
1471 temp
[256], // Temporary string
1472 command
[256], // Command string
1473 *commptr
; // Pointer into command
1474 int xdpi
, ydpi
, // X + Y resolution
1475 color_order
, // Color order
1476 color_space
, // Colorspace
1477 compression
, // Compression mode
1478 depth
, // Bits per color
1479 row_count
, // Row count
1480 row_feed
, // Row feed
1481 row_step
; // Row step/interval
1484 // Read the resolution parameters:
1486 // Resolution colorspace bits row-count row-feed row-step name/text
1487 if (!get_token(fp
, temp
, sizeof(temp
)))
1489 fprintf(stderr
, "ppdc: Expected override field after Resolution on line %d of %s!\n",
1490 fp
->line
, fp
->filename
);
1494 color_order
= get_color_order(temp
);
1495 color_space
= get_color_space(temp
);
1496 compression
= get_integer(temp
);
1498 depth
= get_integer(fp
);
1499 row_count
= get_integer(fp
);
1500 row_feed
= get_integer(fp
);
1501 row_step
= get_integer(fp
);
1503 if (!get_token(fp
, name
, sizeof(name
)))
1505 fprintf(stderr
, "ppdc: Expected name/text after Resolution on line %d of %s!\n",
1506 fp
->line
, fp
->filename
);
1510 if ((text
= strchr(name
, '/')) != NULL
)
1515 switch (sscanf(name
, "%dx%d", &xdpi
, &ydpi
))
1518 fprintf(stderr
, "ppdc: Bad resolution name \"%s\" on line %d of %s!\n",
1519 name
, fp
->line
, fp
->filename
);
1526 // Create the necessary PS commands...
1527 snprintf(command
, sizeof(command
),
1528 "<</HWResolution[%d %d]/cupsBitsPerColor %d/cupsRowCount %d"
1529 "/cupsRowFeed %d/cupsRowStep %d",
1530 xdpi
, ydpi
, depth
, row_count
, row_feed
, row_step
);
1531 commptr
= command
+ strlen(command
);
1533 if (color_order
>= 0)
1535 snprintf(commptr
, sizeof(command
) - (commptr
- command
),
1536 "/cupsColorOrder %d", color_order
);
1537 commptr
+= strlen(commptr
);
1540 if (color_space
>= 0)
1542 snprintf(commptr
, sizeof(command
) - (commptr
- command
),
1543 "/cupsColorSpace %d", color_space
);
1544 commptr
+= strlen(commptr
);
1547 if (compression
>= 0)
1549 snprintf(commptr
, sizeof(command
) - (commptr
- command
),
1550 "/cupsCompression %d", compression
);
1551 commptr
+= strlen(commptr
);
1554 snprintf(commptr
, sizeof(command
) - (commptr
- command
), ">>setpagedevice");
1556 // Return the new choice...
1557 return (new ppdcChoice(name
, text
, command
));
1562 // 'ppdcSource::get_simple_profile()' - Get a simple color profile definition.
1565 ppdcProfile
* // O - Color profile
1566 ppdcSource::get_simple_profile(ppdcFile
*fp
)
1569 char resolution
[1024], // Resolution/media type
1570 *media_type
; // Media type
1571 float m
[9]; // Transform matrix
1572 float kd
, rd
, g
; // Densities and gamma
1573 float red
, green
, blue
; // RGB adjustments
1574 float yellow
; // Yellow density
1575 float color
; // Color density values
1578 // Get the SimpleColorProfile parameters:
1580 // SimpleColorProfile resolution/mediatype black-density yellow-density
1581 // red-density gamma red-adjust green-adjust blue-adjust
1582 if (!get_token(fp
, resolution
, sizeof(resolution
)))
1584 fprintf(stderr
, "ppdc: Expected resolution/mediatype following SimpleColorProfile on line %d of %s!\n",
1585 fp
->line
, fp
->filename
);
1589 if ((media_type
= strchr(resolution
, '/')) != NULL
)
1590 *media_type
++ = '\0';
1592 media_type
= resolution
;
1594 // Collect the profile parameters...
1596 yellow
= get_float(fp
);
1599 red
= get_float(fp
);
1600 green
= get_float(fp
);
1601 blue
= get_float(fp
);
1603 // Build the color profile...
1604 color
= 0.5f
* rd
/ kd
- kd
;
1606 m
[1] = color
+ blue
; // C + M (blue)
1607 m
[2] = color
- green
; // C + Y (green)
1608 m
[3] = color
- blue
; // M + C (blue)
1610 m
[5] = color
+ red
; // M + Y (red)
1611 m
[6] = yellow
* (color
+ green
); // Y + C (green)
1612 m
[7] = yellow
* (color
- red
); // Y + M (red)
1620 else if (m
[3] > 0.0f
)
1631 else if (m
[6] > 0.0f
)
1642 else if (m
[7] > 0.0f
)
1648 // Return the new profile...
1649 return (new ppdcProfile(resolution
, media_type
, g
, kd
, m
));
1654 // 'ppdcSource::get_size()' - Get a media size definition from a file.
1657 ppdcMediaSize
* // O - Media size
1658 ppdcSource::get_size(ppdcFile
*fp
) // I - File to read
1660 char name
[1024], // Name
1662 float width
, // Width
1666 // Get the name, text, width, and length:
1668 // #media name/text width length
1669 if (!get_token(fp
, name
, sizeof(name
)))
1672 if ((text
= strchr(name
, '/')) != NULL
)
1677 if ((width
= get_measurement(fp
)) < 0.0f
)
1680 if ((length
= get_measurement(fp
)) < 0.0f
)
1683 // Return the new media size...
1684 return (new ppdcMediaSize(name
, text
, width
, length
, 0.0f
, 0.0f
, 0.0f
, 0.0f
));
1689 // 'ppdcSource::get_token()' - Get a token from a file.
1692 char * // O - Token string or NULL
1693 ppdcSource::get_token(ppdcFile
*fp
, // I - File to read
1694 char *buffer
, // I - Buffer
1695 int buflen
) // I - Length of buffer
1697 char *bufptr
, // Pointer into string buffer
1698 *bufend
; // End of string buffer
1699 int ch
, // Character from file
1700 nextch
, // Next char in file
1701 quote
, // Quote character used...
1702 empty
, // Empty input?
1703 startline
; // Start line for quote
1704 char name
[256], // Name string
1705 *nameptr
; // Name pointer
1706 ppdcVariable
*var
; // Variable pointer
1709 // Mark the beginning and end of the buffer...
1711 bufend
= buffer
+ buflen
- 1;
1713 // Loop intil we've read a token...
1718 while ((ch
= fp
->get()) != EOF
)
1720 if (isspace(ch
) && !quote
)
1729 // Variable substitution
1732 for (nameptr
= name
; (ch
= fp
->peek()) != EOF
;)
1734 if (!isalnum(ch
) && ch
!= '_')
1736 else if (nameptr
< (name
+ sizeof(name
) - 1))
1737 *nameptr
++ = fp
->get();
1740 if (nameptr
== name
)
1742 // Just substitute this character...
1746 if (bufptr
< bufend
)
1747 *bufptr
++ = fp
->get();
1752 fprintf(stderr
, "ppdc: Bad variable substitution ($%c) on line %d of %s.\n",
1753 ch
, fp
->line
, fp
->filename
);
1755 if (bufptr
< bufend
)
1761 // Substitute the variable value...
1763 var
= find_variable(name
);
1766 strncpy(bufptr
, var
->value
->value
, bufend
- bufptr
);
1767 bufptr
+= strlen(var
->value
->value
);
1771 fprintf(stderr
, "ppdc: Undefined variable (%s) on line %d of %s.\n",
1772 name
, fp
->line
, fp
->filename
);
1773 snprintf(bufptr
, bufend
- bufptr
+ 1, "$%s", name
);
1774 bufptr
+= strlen(name
) + 1;
1778 else if (ch
== '/' && !quote
)
1780 // Possibly a comment...
1781 nextch
= fp
->peek();
1788 while ((nextch
= fp
->get()) != EOF
)
1790 if (ch
== '*' && nextch
== '/')
1799 else if (nextch
== '/')
1802 while ((nextch
= fp
->get()) != EOF
)
1814 if (bufptr
< bufend
)
1818 else if (ch
== '\'' || ch
== '\"')
1824 // Ending the current quoted string...
1829 // Insert the opposing quote char...
1830 if (bufptr
< bufend
)
1835 // Start a new quoted string...
1836 startline
= fp
->line
;
1840 else if ((ch
== '(' || ch
== '<') && !quote
)
1844 startline
= fp
->line
;
1846 if (bufptr
< bufend
)
1849 else if ((ch
== ')' && quote
== '(') || (ch
== '>' && quote
== '<'))
1853 if (bufptr
< bufend
)
1856 else if (ch
== '\\')
1860 if ((ch
= fp
->get()) == EOF
)
1863 if (bufptr
< bufend
)
1866 else if (bufptr
< bufend
)
1872 if ((ch
== '{' || ch
== '}') && !quote
)
1879 fprintf(stderr
, "ppdc: Unterminated string starting with %c on line %d of %s!\n",
1880 quote
, startline
, fp
->filename
);
1896 // 'ppdcSource::get_variable()' - Get a variable definition.
1899 ppdcVariable
* // O - Variable
1900 ppdcSource::get_variable(ppdcFile
*fp
) // I - File to read
1902 char name
[1024], // Name
1903 value
[1024]; // Value
1906 // Get the name and value:
1908 // #define name value
1909 if (!get_token(fp
, name
, sizeof(name
)))
1912 if (!get_token(fp
, value
, sizeof(value
)))
1915 // Set the variable...
1916 return (set_variable(name
, value
));
1921 // 'ppdcSource::quotef()' - Write a formatted, quoted string...
1924 int // O - Number bytes on success, -1 on failure
1925 ppdcSource::quotef(cups_file_t
*fp
, // I - File to write to
1926 const char *format
, // I - Printf-style format string
1927 ...) // I - Additional args as needed
1929 va_list ap
; // Pointer to additional arguments
1930 int bytes
; // Bytes written
1931 char sign
, // Sign of format width
1932 size
, // Size character (h, l, L)
1933 type
; // Format type character
1934 const char *bufformat
; // Start of format
1935 int width
, // Width of field
1936 prec
; // Number of characters of precision
1937 char tformat
[100]; // Temporary format string for fprintf()
1938 char *s
; // Pointer to string
1939 int slen
; // Length of string
1940 int i
; // Looping var
1943 // Range check input...
1947 // Loop through the format string, formatting as needed...
1948 va_start(ap
, format
);
1961 cupsFilePutChar(fp
, *format
++);
1965 else if (strchr(" -+#\'", *format
))
1971 while (isdigit(*format
))
1972 width
= width
* 10 + *format
++ - '0';
1979 while (isdigit(*format
))
1980 prec
= prec
* 10 + *format
++ - '0';
1985 if (*format
== 'l' && format
[1] == 'l')
1990 else if (*format
== 'h' || *format
== 'l' || *format
== 'L')
2000 case 'E' : // Floating point formats
2005 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2008 strncpy(tformat
, bufformat
, format
- bufformat
);
2009 tformat
[format
- bufformat
] = '\0';
2011 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, double));
2014 case 'B' : // Integer formats
2022 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2025 strncpy(tformat
, bufformat
, format
- bufformat
);
2026 tformat
[format
- bufformat
] = '\0';
2028 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, int));
2031 case 'p' : // Pointer value
2032 if ((format
- bufformat
+ 1) > (int)sizeof(tformat
))
2035 strncpy(tformat
, bufformat
, format
- bufformat
);
2036 tformat
[format
- bufformat
] = '\0';
2038 bytes
+= cupsFilePrintf(fp
, tformat
, va_arg(ap
, void *));
2041 case 'c' : // Character or character array
2045 cupsFilePutChar(fp
, va_arg(ap
, int));
2049 cupsFileWrite(fp
, va_arg(ap
, char *), width
);
2054 case 's' : // String
2055 if ((s
= va_arg(ap
, char *)) == NULL
)
2056 s
= (char *)"(nil)";
2059 if (slen
> width
&& prec
!= width
)
2067 for (i
= width
- slen
; i
> 0; i
--, bytes
++)
2068 cupsFilePutChar(fp
, ' ');
2071 for (i
= slen
; i
> 0; i
--, s
++, bytes
++)
2073 if (*s
== '\\' || *s
== '\"')
2075 cupsFilePutChar(fp
, '\\');
2079 cupsFilePutChar(fp
, *s
);
2084 for (i
= width
- slen
; i
> 0; i
--, bytes
++)
2085 cupsFilePutChar(fp
, ' ');
2092 cupsFilePutChar(fp
, *format
++);
2099 // Return the number of characters written.
2105 // 'ppdcSource::read_file()' - Read a driver source file.
2109 ppdcSource::read_file(const char *f
) // I - File to read
2111 ppdcFile
*fp
= new ppdcFile(f
);
2118 // 'ppdcSource::scan_file()' - Scan a driver source file.
2122 ppdcSource::scan_file(ppdcFile
*fp
, // I - File to read
2123 ppdcDriver
*td
, // I - Driver template
2124 bool inc
) // I - Including?
2126 ppdcDriver
*d
; // Current driver
2127 ppdcGroup
*g
, // Current group
2128 *general
, // General options group
2129 *install
; // Installable options group
2130 ppdcOption
*o
; // Current option
2131 ppdcChoice
*c
; // Current choice
2132 char temp
[256], // Token from file...
2133 *ptr
; // Pointer into token
2134 int isdefault
; // Default option?
2137 // Initialize things as needed...
2141 d
= new ppdcDriver(td
);
2143 if ((general
= d
->find_group("General")) == NULL
)
2145 general
= new ppdcGroup("General", NULL
);
2146 d
->add_group(general
);
2149 if ((install
= d
->find_group("InstallableOptions")) == NULL
)
2151 install
= new ppdcGroup("InstallableOptions", "Installable Options");
2152 d
->add_group(install
);
2155 // Loop until EOF or }
2158 while (get_token(fp
, temp
, sizeof(temp
)))
2162 // Mark the next choice as the default
2165 for (ptr
= temp
; ptr
[1]; ptr
++)
2172 // Don't mark the next choice as the default
2176 if (!strcasecmp(temp
, "}"))
2178 // Close this one out...
2181 else if (!strcasecmp(temp
, "{"))
2183 // Open a new child...
2186 else if (!strcasecmp(temp
, "#define"))
2188 // Get the variable...
2191 else if (!strcasecmp(temp
, "#include"))
2193 // #include filename
2194 char basedir
[1024], // Base directory
2195 *baseptr
, // Pointer into directory
2196 inctemp
[1024], // Initial filename
2197 incname
[1024]; // Include filename
2198 ppdcFile
*incfile
; // Include file
2201 // Get the include name...
2202 if (!get_token(fp
, inctemp
, sizeof(inctemp
)))
2204 fprintf(stderr
, "ppdc: Expected include filename on line %d of %s!\n",
2205 fp
->line
, fp
->filename
);
2209 // Figure out the current directory...
2210 strlcpy(basedir
, fp
->filename
, sizeof(basedir
));
2212 if ((baseptr
= strrchr(basedir
, '/')) != NULL
)
2215 strcpy(basedir
, ".");
2217 // Find the include file...
2218 if (find_include(inctemp
, basedir
, incname
, sizeof(incname
)))
2220 // Open the include file, scan it, and then close it...
2221 incfile
= new ppdcFile(incname
);
2222 scan_file(incfile
, d
, true);
2229 "ppdc: Unable to find include file \"%s\" on line %d of %s!\n",
2230 inctemp
, fp
->line
, fp
->filename
);
2234 else if (!strcasecmp(temp
, "#media"))
2236 ppdcMediaSize
*m
; // Media size
2239 // Get a media size...
2244 else if (!strcasecmp(temp
, "#po"))
2246 ppdcCatalog
*cat
; // Message catalog
2249 // Get a message catalog...
2254 else if (!strcasecmp(temp
, "Attribute"))
2256 ppdcAttr
*a
; // Attribute
2259 // Get an attribute...
2264 else if (!strcasecmp(temp
, "Choice"))
2269 fprintf(stderr
, "ppdc: Choice found on line %d of %s with no Option!\n",
2270 fp
->line
, fp
->filename
);
2278 // Add it to the current option...
2282 o
->set_defchoice(c
);
2284 else if (!strcasecmp(temp
, "ColorDevice"))
2286 // ColorDevice boolean
2287 d
->color_device
= get_boolean(fp
);
2289 else if (!strcasecmp(temp
, "ColorModel"))
2291 // Get the color model
2292 c
= get_color_model(fp
);
2296 // Add the choice to the ColorModel option...
2297 if ((o
= d
->find_option("ColorModel")) == NULL
)
2299 // Create the ColorModel option...
2300 o
= new ppdcOption(PPDC_PICKONE
, "ColorModel", "Color Mode", PPDC_SECTION_ANY
, 10.0f
);
2308 o
->set_defchoice(c
);
2312 else if (!strcasecmp(temp
, "ColorProfile"))
2314 ppdcProfile
*p
; // Color profile
2317 // Get the color profile...
2318 p
= get_color_profile(fp
);
2321 d
->profiles
->add(p
);
2323 else if (!strcasecmp(temp
, "Copyright"))
2326 char copytemp
[8192], // Copyright string
2327 *copyptr
, // Pointer into string
2328 *copyend
; // Pointer to end of string
2331 // Get the copyright string...
2332 if (!get_token(fp
, copytemp
, sizeof(temp
)))
2335 "ppdc: Expected string after Copyright on line %d of %s!\n",
2336 fp
->line
, fp
->filename
);
2340 // Break it up into individual lines...
2341 for (copyptr
= copytemp
; copyptr
; copyptr
= copyend
)
2343 if ((copyend
= strchr(copyptr
, '\n')) != NULL
)
2346 d
->copyright
->add(new ppdcString(copyptr
));
2349 else if (!strcasecmp(temp
, "CustomMedia"))
2351 ppdcMediaSize
*m
; // Media size
2354 // Get a custom media size...
2355 m
= get_custom_size(fp
);
2360 d
->set_default_size(m
);
2362 else if (!strcasecmp(temp
, "Cutter"))
2365 int have_cutter
; // Have a paper cutter?
2368 have_cutter
= get_boolean(fp
);
2369 if (have_cutter
<= 0)
2372 if ((o
= d
->find_option("CutMedia")) == NULL
)
2374 o
= new ppdcOption(PPDC_BOOLEAN
, "CutMedia", "Cut Media", PPDC_SECTION_ANY
, 10.0f
);
2379 c
= new ppdcChoice("False", NULL
, "<</CutMedia 0>>setpagedevice");
2381 o
->set_defchoice(c
);
2383 c
= new ppdcChoice("True", NULL
, "<</CutMedia 4>>setpagedevice");
2389 else if (!strcasecmp(temp
, "Darkness"))
2391 // Get the darkness choice...
2392 c
= get_generic(fp
, "Darkness", NULL
, "cupsCompression");
2396 // Add the choice to the cupsDarkness option...
2397 if ((o
= d
->find_option("cupsDarkness")) == NULL
)
2399 // Create the cupsDarkness option...
2400 o
= new ppdcOption(PPDC_PICKONE
, "cupsDarkness", "Darkness", PPDC_SECTION_ANY
, 10.0f
);
2408 o
->set_defchoice(c
);
2412 else if (!strcasecmp(temp
, "DriverType"))
2414 int i
; // Looping var
2417 // DriverType keyword
2418 if (!get_token(fp
, temp
, sizeof(temp
)))
2420 fprintf(stderr
, "ppdc: Expected driver type keyword following DriverType on line %d of %s!\n",
2421 fp
->line
, fp
->filename
);
2425 for (i
= 0; i
< (int)(sizeof(driver_types
) / sizeof(driver_types
[0])); i
++)
2426 if (!strcasecmp(temp
, driver_types
[i
]))
2429 if (i
< (int)(sizeof(driver_types
) / sizeof(driver_types
[0])))
2430 d
->type
= (ppdcDrvType
)i
;
2431 else if (!strcasecmp(temp
, "dymo"))
2432 d
->type
= PPDC_DRIVER_LABEL
;
2434 fprintf(stderr
, "ppdc: Unknown driver type %s on line %d of %s!\n",
2435 temp
, fp
->line
, fp
->filename
);
2437 else if (!strcasecmp(temp
, "Duplex"))
2439 else if (!strcasecmp(temp
, "Filter"))
2441 ppdcFilter
*f
; // Filter
2444 // Get the filter value...
2449 else if (!strcasecmp(temp
, "Finishing"))
2451 // Get the finishing choice...
2452 c
= get_generic(fp
, "Finishing", "OutputType", NULL
);
2456 // Add the choice to the cupsFinishing option...
2457 if ((o
= d
->find_option("cupsFinishing")) == NULL
)
2459 // Create the cupsFinishing option...
2460 o
= new ppdcOption(PPDC_PICKONE
, "cupsFinishing", "Finishing", PPDC_SECTION_ANY
, 10.0f
);
2468 o
->set_defchoice(c
);
2472 else if (!strcasecmp(temp
, "Font") ||
2473 !strcasecmp(temp
, "#font"))
2475 ppdcFont
*f
; // Font
2482 if (!strcasecmp(temp
, "#font"))
2488 d
->set_default_font(f
);
2491 else if (!strcasecmp(temp
, "Group"))
2494 g
= get_group(fp
, d
);
2498 else if (!strcasecmp(temp
, "HWMargins"))
2500 // HWMargins left bottom right top
2501 d
->left_margin
= get_measurement(fp
);
2502 d
->bottom_margin
= get_measurement(fp
);
2503 d
->right_margin
= get_measurement(fp
);
2504 d
->top_margin
= get_measurement(fp
);
2506 else if (!strcasecmp(temp
, "InputSlot"))
2508 // Get the input slot choice...
2509 c
= get_generic(fp
, "InputSlot", NULL
, "MediaPosition");
2513 // Add the choice to the InputSlot option...
2514 if ((o
= d
->find_option("InputSlot")) == NULL
)
2516 // Create the InputSlot option...
2517 o
= new ppdcOption(PPDC_PICKONE
, "InputSlot", "Media Source",
2518 PPDC_SECTION_ANY
, 10.0f
);
2526 o
->set_defchoice(c
);
2530 else if (!strcasecmp(temp
, "Installable"))
2532 // Get the installable option...
2533 o
= get_installable(fp
);
2535 // Add it as needed...
2538 install
->add_option(o
);
2542 else if (!strcasecmp(temp
, "ManualCopies"))
2544 // ManualCopies boolean
2545 d
->manual_copies
= get_boolean(fp
);
2547 else if (!strcasecmp(temp
, "Manufacturer"))
2549 // Manufacturer name
2550 char name
[256]; // Model name string
2553 if (!get_token(fp
, name
, sizeof(name
)))
2555 fprintf(stderr
, "ppdc: Expected name after Manufacturer on line %d of %s!\n",
2556 fp
->line
, fp
->filename
);
2560 d
->set_manufacturer(name
);
2562 else if (!strcasecmp(temp
, "MaxSize"))
2564 // MaxSize width length
2565 d
->max_width
= get_measurement(fp
);
2566 d
->max_length
= get_measurement(fp
);
2568 else if (!strcasecmp(temp
, "MediaSize"))
2570 // MediaSize keyword
2571 char name
[41]; // Media size name
2572 ppdcMediaSize
*m
, // Matching media size...
2573 *dm
; // Driver media size...
2576 if (get_token(fp
, name
, sizeof(name
)) == NULL
)
2578 fprintf(stderr
, "ppdc: Expected name after MediaSize on line %d of %s!\n",
2579 fp
->line
, fp
->filename
);
2583 m
= find_size(name
);
2587 fprintf(stderr
, "ppdc: Unknown media size \"%s\" on line %d of %s!\n",
2588 name
, fp
->line
, fp
->filename
);
2592 // Add this size to the driver...
2593 dm
= new ppdcMediaSize(m
->name
->value
, m
->text
->value
,
2594 m
->width
, m
->length
, d
->left_margin
,
2595 d
->bottom_margin
, d
->right_margin
,
2600 d
->set_default_size(dm
);
2602 else if (!strcasecmp(temp
, "MediaType"))
2604 // Get the media type choice...
2605 c
= get_generic(fp
, "MediaType", "MediaType", "cupsMediaType");
2609 // Add the choice to the MediaType option...
2610 if ((o
= d
->find_option("MediaType")) == NULL
)
2612 // Create the MediaType option...
2613 o
= new ppdcOption(PPDC_PICKONE
, "MediaType", "Media Type",
2614 PPDC_SECTION_ANY
, 10.0f
);
2622 o
->set_defchoice(c
);
2626 else if (!strcasecmp(temp
, "MinSize"))
2628 // MinSize width length
2629 d
->min_width
= get_measurement(fp
);
2630 d
->min_length
= get_measurement(fp
);
2632 else if (!strcasecmp(temp
, "ModelName"))
2635 char name
[256]; // Model name string
2638 if (!get_token(fp
, name
, sizeof(name
)))
2640 fprintf(stderr
, "ppdc: Expected name after ModelName on line %d of %s!\n",
2641 fp
->line
, fp
->filename
);
2645 d
->set_model_name(name
);
2647 else if (!strcasecmp(temp
, "ModelNumber"))
2649 // ModelNumber number
2650 d
->model_number
= get_integer(fp
);
2652 else if (!strcasecmp(temp
, "Option"))
2655 o
= get_option(fp
, d
, g
);
2659 else if (!strcasecmp(temp
, "PCFileName"))
2662 char name
[256]; // Model name string
2665 if (!get_token(fp
, name
, sizeof(name
)))
2667 fprintf(stderr
, "ppdc: Expected name after PCFileName on line %d of %s!\n",
2668 fp
->line
, fp
->filename
);
2672 d
->set_pc_file_name(name
);
2674 else if (!strcasecmp(temp
, "Resolution"))
2676 // Get the resolution choice...
2677 c
= get_resolution(fp
);
2681 // Add the choice to the Resolution option...
2682 if ((o
= d
->find_option("Resolution")) == NULL
)
2684 // Create the Resolution option...
2685 o
= new ppdcOption(PPDC_PICKONE
, "Resolution", NULL
, PPDC_SECTION_ANY
, 10.0f
);
2693 o
->set_defchoice(c
);
2697 else if (!strcasecmp(temp
, "SimpleColorProfile"))
2699 ppdcProfile
*p
; // Color profile
2702 // Get the color profile...
2703 p
= get_simple_profile(fp
);
2706 d
->profiles
->add(p
);
2708 else if (!strcasecmp(temp
, "Throughput"))
2710 // Throughput number
2711 d
->throughput
= get_integer(fp
);
2713 else if (!strcasecmp(temp
, "UIConstraints"))
2715 ppdcConstraint
*con
; // Constraint
2718 con
= get_constraint(fp
);
2721 d
->constraints
->add(con
);
2723 else if (!strcasecmp(temp
, "VariablePaperSize"))
2725 // VariablePaperSize boolean
2726 d
->variable_paper_size
= get_boolean(fp
);
2728 else if (!strcasecmp(temp
, "Version"))
2731 char name
[256]; // Model name string
2734 if (!get_token(fp
, name
, sizeof(name
)))
2736 fprintf(stderr
, "ppdc: Expected string after Version on line %d of %s!\n",
2737 fp
->line
, fp
->filename
);
2741 d
->set_version(name
);
2745 fprintf(stderr
, "ppdc: Unknown token \"%s\" seen on line %d of %s!\n",
2746 temp
, fp
->line
, fp
->filename
);
2751 // Done processing this block, is there anything to save?
2754 if (!d
->pc_file_name
|| !d
->model_name
|| !d
->manufacturer
|| !d
->version
||
2757 // Nothing to save...
2762 // Got a driver, save it...
2770 // 'ppdcSource::set_variable()' - Set a variable.
2773 ppdcVariable
* // O - Variable
2774 ppdcSource::set_variable(
2775 const char *name
, // I - Name
2776 const char *value
) // I - Value
2778 ppdcVariable
*v
; // Variable
2781 // See if the variable exists already...
2782 v
= find_variable(name
);
2785 // Change the variable value...
2786 v
->set_value(value
);
2790 // Create a new variable and add it...
2791 v
= new ppdcVariable(name
, value
);
2800 // 'ppdcSource::write_file()' - Write the current source data to a file.
2803 int // O - 0 on success, -1 on error
2804 ppdcSource::write_file(const char *f
) // I - File to write
2806 cups_file_t
*fp
; // Output file
2807 char bckname
[1024]; // Backup file
2808 ppdcDriver
*d
; // Current driver
2809 ppdcString
*st
; // Current string
2810 ppdcAttr
*a
; // Current attribute
2811 ppdcConstraint
*co
; // Current constraint
2812 ppdcFilter
*fi
; // Current filter
2813 ppdcFont
*fo
; // Current font
2814 ppdcGroup
*g
; // Current group
2815 ppdcOption
*o
; // Current option
2816 ppdcChoice
*ch
; // Current choice
2817 ppdcProfile
*p
; // Current color profile
2818 ppdcMediaSize
*si
; // Current media size
2819 float left
, // Current left margin
2820 bottom
, // Current bottom margin
2821 right
, // Current right margin
2822 top
; // Current top margin
2823 int dtused
[PPDC_DRIVER_MAX
];// Driver type usage...
2826 // Rename the current file, if any, to .bck...
2827 snprintf(bckname
, sizeof(bckname
), "%s.bck", f
);
2830 // Open the output file...
2831 fp
= cupsFileOpen(f
, "w");
2835 // Can't create file; restore backup and return...
2840 cupsFilePuts(fp
, "// CUPS PPD Compiler " CUPS_SVERSION
"\n\n");
2842 // Include standard files...
2843 cupsFilePuts(fp
, "// Include necessary files...\n");
2844 cupsFilePuts(fp
, "#include <font.defs>\n");
2845 cupsFilePuts(fp
, "#include <media.defs>\n");
2847 memset(dtused
, 0, sizeof(dtused
));
2849 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
2850 if (d
->type
> PPDC_DRIVER_PS
&& !dtused
[d
->type
])
2852 cupsFilePrintf(fp
, "#include <%s.h>\n", driver_types
[d
->type
]);
2853 dtused
[d
->type
] = 1;
2856 // Output each driver...
2857 for (d
= (ppdcDriver
*)drivers
->first(); d
; d
= (ppdcDriver
*)drivers
->next())
2859 // Start the driver...
2860 cupsFilePrintf(fp
, "\n// %s %s\n", d
->manufacturer
->value
, d
->model_name
->value
);
2861 cupsFilePuts(fp
, "{\n");
2863 // Write the copyright stings...
2864 for (st
= (ppdcString
*)d
->copyright
->first();
2866 st
= (ppdcString
*)d
->copyright
->next())
2867 quotef(fp
, " Copyright \"%s\"\n", st
->value
);
2869 // Write other strings and values...
2870 if (d
->manufacturer
->value
)
2871 quotef(fp
, " Manufacturer \"%s\"\n", d
->manufacturer
->value
);
2872 if (d
->model_name
->value
)
2873 quotef(fp
, " ModelName \"%s\"\n", d
->model_name
->value
);
2874 if (d
->pc_file_name
->value
)
2875 quotef(fp
, " PCFileName \"%s\"\n", d
->pc_file_name
->value
);
2876 if (d
->version
->value
)
2877 quotef(fp
, " Version \"%s\"\n", d
->version
->value
);
2879 cupsFilePrintf(fp
, " DriverType %s\n", driver_types
[d
->type
]);
2881 if (d
->model_number
)
2885 case PPDC_DRIVER_ESCP
:
2886 cupsFilePuts(fp
, " ModelNumber (");
2888 if (d
->model_number
& ESCP_DOTMATRIX
)
2889 cupsFilePuts(fp
, " $ESCP_DOTMATRIX");
2890 if (d
->model_number
& ESCP_MICROWEAVE
)
2891 cupsFilePuts(fp
, " $ESCP_MICROWEAVE");
2892 if (d
->model_number
& ESCP_STAGGER
)
2893 cupsFilePuts(fp
, " $ESCP_STAGGER");
2894 if (d
->model_number
& ESCP_ESCK
)
2895 cupsFilePuts(fp
, " $ESCP_ESCK");
2896 if (d
->model_number
& ESCP_EXT_UNITS
)
2897 cupsFilePuts(fp
, " $ESCP_EXT_UNITS");
2898 if (d
->model_number
& ESCP_EXT_MARGINS
)
2899 cupsFilePuts(fp
, " $ESCP_EXT_MARGINS");
2900 if (d
->model_number
& ESCP_USB
)
2901 cupsFilePuts(fp
, " $ESCP_USB");
2902 if (d
->model_number
& ESCP_PAGE_SIZE
)
2903 cupsFilePuts(fp
, " $ESCP_PAGE_SIZE");
2904 if (d
->model_number
& ESCP_RASTER_ESCI
)
2905 cupsFilePuts(fp
, " $ESCP_RASTER_ESCI");
2906 if (d
->model_number
& ESCP_REMOTE
)
2907 cupsFilePuts(fp
, " $ESCP_REMOTE");
2909 cupsFilePuts(fp
, ")\n");
2912 case PPDC_DRIVER_PCL
:
2913 cupsFilePuts(fp
, " ModelNumber (");
2915 if (d
->model_number
& PCL_PAPER_SIZE
)
2916 cupsFilePuts(fp
, " $PCL_PAPER_SIZE");
2917 if (d
->model_number
& PCL_INKJET
)
2918 cupsFilePuts(fp
, " $PCL_INKJET");
2919 if (d
->model_number
& PCL_RASTER_END_COLOR
)
2920 cupsFilePuts(fp
, " $PCL_RASTER_END_COLOR");
2921 if (d
->model_number
& PCL_RASTER_CID
)
2922 cupsFilePuts(fp
, " $PCL_RASTER_CID");
2923 if (d
->model_number
& PCL_RASTER_CRD
)
2924 cupsFilePuts(fp
, " $PCL_RASTER_CRD");
2925 if (d
->model_number
& PCL_RASTER_SIMPLE
)
2926 cupsFilePuts(fp
, " $PCL_RASTER_SIMPLE");
2927 if (d
->model_number
& PCL_RASTER_RGB24
)
2928 cupsFilePuts(fp
, " $PCL_RASTER_RGB24");
2929 if (d
->model_number
& PCL_PJL
)
2930 cupsFilePuts(fp
, " $PCL_PJL");
2931 if (d
->model_number
& PCL_PJL_PAPERWIDTH
)
2932 cupsFilePuts(fp
, " $PCL_PJL_PAPERWIDTH");
2933 if (d
->model_number
& PCL_PJL_HPGL2
)
2934 cupsFilePuts(fp
, " $PCL_PJL_HPGL2");
2935 if (d
->model_number
& PCL_PJL_PCL3GUI
)
2936 cupsFilePuts(fp
, " $PCL_PJL_PCL3GUI");
2937 if (d
->model_number
& PCL_PJL_RESOLUTION
)
2938 cupsFilePuts(fp
, " $PCL_PJL_RESOLUTION");
2940 cupsFilePuts(fp
, ")\n");
2943 case PPDC_DRIVER_LABEL
:
2944 cupsFilePuts(fp
, " ModelNumber ");
2946 switch (d
->model_number
)
2949 cupsFilePuts(fp
, "$DYMO_3x0\n");
2952 case ZEBRA_EPL_LINE
:
2953 cupsFilePuts(fp
, "$ZEBRA_EPL_LINE\n");
2956 case ZEBRA_EPL_PAGE
:
2957 cupsFilePuts(fp
, "$ZEBRA_EPL_PAGE\n");
2961 cupsFilePuts(fp
, "$ZEBRA_ZPL\n");
2965 cupsFilePuts(fp
, "$ZEBRA_CPCL\n");
2968 case INTELLITECH_PCL
:
2969 cupsFilePuts(fp
, "$INTELLITECH_PCL\n");
2973 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
2978 case PPDC_DRIVER_EPSON
:
2979 cupsFilePuts(fp
, " ModelNumber ");
2981 switch (d
->model_number
)
2984 cupsFilePuts(fp
, "$EPSON_9PIN\n");
2988 cupsFilePuts(fp
, "$EPSON_24PIN\n");
2992 cupsFilePuts(fp
, "$EPSON_COLOR\n");
2996 cupsFilePuts(fp
, "$EPSON_PHOTO\n");
3000 cupsFilePuts(fp
, "$EPSON_ICOLOR\n");
3004 cupsFilePuts(fp
, "$EPSON_IPHOTO\n");
3008 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3013 case PPDC_DRIVER_HP
:
3014 cupsFilePuts(fp
, " ModelNumber ");
3015 switch (d
->model_number
)
3018 cupsFilePuts(fp
, "$HP_LASERJET\n");
3022 cupsFilePuts(fp
, "$HP_DESKJET\n");
3026 cupsFilePuts(fp
, "$HP_DESKJET2\n");
3030 cupsFilePrintf(fp
, "%d\n", d
->model_number
);
3034 cupsFilePuts(fp
, ")\n");
3038 cupsFilePrintf(fp
, " ModelNumber %d\n", d
->model_number
);
3043 if (d
->manual_copies
)
3044 cupsFilePuts(fp
, " ManualCopies Yes\n");
3046 if (d
->color_device
)
3047 cupsFilePuts(fp
, " ColorDevice Yes\n");
3050 cupsFilePrintf(fp
, " Throughput %d\n", d
->throughput
);
3052 // Output all of the attributes...
3053 for (a
= (ppdcAttr
*)d
->attrs
->first();
3055 a
= (ppdcAttr
*)d
->attrs
->next())
3056 if (a
->text
->value
&& a
->text
->value
[0])
3057 quotef(fp
, " Attribute \"%s\" \"%s/%s\" \"%s\"\n",
3058 a
->name
->value
, a
->selector
->value
? a
->selector
->value
: "",
3059 a
->text
->value
, a
->value
->value
? a
->value
->value
: "");
3061 quotef(fp
, " Attribute \"%s\" \"%s\" \"%s\"\n",
3062 a
->name
->value
, a
->selector
->value
? a
->selector
->value
: "",
3063 a
->value
->value
? a
->value
->value
: "");
3065 // Output all of the constraints...
3066 for (co
= (ppdcConstraint
*)d
->constraints
->first();
3068 co
= (ppdcConstraint
*)d
->constraints
->next())
3070 if (co
->option1
->value
[0] == '*')
3071 cupsFilePrintf(fp
, " UIConstraints \"%s %s", co
->option1
->value
,
3072 co
->choice1
->value
? co
->choice1
->value
: "");
3074 cupsFilePrintf(fp
, " UIConstraints \"*%s %s", co
->option1
->value
,
3075 co
->choice1
->value
? co
->choice1
->value
: "");
3077 if (co
->option2
->value
[0] == '*')
3078 cupsFilePrintf(fp
, " %s %s\"\n", co
->option2
->value
,
3079 co
->choice2
->value
? co
->choice2
->value
: "");
3081 cupsFilePrintf(fp
, " *%s %s\"\n", co
->option2
->value
,
3082 co
->choice2
->value
? co
->choice2
->value
: "");
3085 // Output all of the filters...
3086 for (fi
= (ppdcFilter
*)d
->filters
->first();
3088 fi
= (ppdcFilter
*)d
->filters
->next())
3089 cupsFilePrintf(fp
, " Filter \"%s %d %s\"\n",
3090 fi
->mime_type
->value
, fi
->cost
, fi
->program
->value
);
3092 // Output all of the fonts...
3093 for (fo
= (ppdcFont
*)d
->fonts
->first();
3095 fo
= (ppdcFont
*)d
->fonts
->next())
3096 if (!strcmp(fo
->name
->value
, "*"))
3097 cupsFilePuts(fp
, " Font *\n");
3099 cupsFilePrintf(fp
, " Font \"%s\" \"%s\" \"%s\" \"%s\" %s\n",
3100 fo
->name
->value
, fo
->encoding
->value
,
3101 fo
->version
->value
, fo
->charset
->value
,
3102 fo
->status
== PPDC_FONT_ROM
? "ROM" : "Disk");
3104 // Output all options...
3105 for (g
= (ppdcGroup
*)d
->groups
->first();
3107 g
= (ppdcGroup
*)d
->groups
->next())
3109 if (g
->options
->count
== 0)
3112 if (g
->text
->value
&& g
->text
->value
[0])
3113 quotef(fp
, " Group \"%s/%s\"\n", g
->name
->value
, g
->text
->value
);
3115 cupsFilePrintf(fp
, " Group \"%s\"\n", g
->name
->value
);
3117 for (o
= (ppdcOption
*)g
->options
->first();
3119 o
= (ppdcOption
*)g
->options
->next())
3121 if (o
->choices
->count
== 0)
3124 if (o
->text
->value
&& o
->text
->value
[0])
3125 quotef(fp
, " Option \"%s/%s\"", o
->name
->value
, o
->text
->value
);
3127 cupsFilePrintf(fp
, " Option \"%s\"", o
->name
->value
);
3129 cupsFilePrintf(fp
, " %s %s %.1f\n",
3130 o
->type
== PPDC_BOOLEAN
? "Boolean" :
3131 o
->type
== PPDC_PICKONE
? "PickOne" : "PickMany",
3132 o
->section
== PPDC_SECTION_ANY
? "AnySetup" :
3133 o
->section
== PPDC_SECTION_DOCUMENT
? "DocumentSetup" :
3134 o
->section
== PPDC_SECTION_EXIT
? "ExitServer" :
3135 o
->section
== PPDC_SECTION_JCL
? "JCLSetup" :
3136 o
->section
== PPDC_SECTION_PAGE
? "PageSetup" :
3140 for (ch
= (ppdcChoice
*)o
->choices
->first();
3142 ch
= (ppdcChoice
*)o
->choices
->next())
3144 if (ch
->text
->value
&& ch
->text
->value
[0])
3145 quotef(fp
, " %sChoice \"%s/%s\" \"%s\"\n",
3146 o
->defchoice
== ch
->name
? "*" : "",
3147 ch
->name
->value
, ch
->text
->value
,
3148 ch
->code
->value
? ch
->code
->value
: "");
3150 quotef(fp
, " %sChoice \"%s\" \"%s\"\n",
3151 o
->defchoice
== ch
->name
? "*" : "",
3153 ch
->code
->value
? ch
->code
->value
: "");
3158 // Output all of the color profiles...
3159 for (p
= (ppdcProfile
*)d
->profiles
->first();
3161 p
= (ppdcProfile
*)d
->profiles
->next())
3162 cupsFilePrintf(fp
, " ColorProfile \"%s/%s\" %.3f %.3f "
3163 "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
3164 p
->resolution
->value
, p
->media_type
->value
,
3165 p
->density
, p
->gamma
,
3166 p
->profile
[0], p
->profile
[1], p
->profile
[2],
3167 p
->profile
[3], p
->profile
[4], p
->profile
[5],
3168 p
->profile
[6], p
->profile
[7], p
->profile
[8]);
3170 // Output all of the media sizes...
3176 for (si
= (ppdcMediaSize
*)d
->sizes
->first();
3178 si
= (ppdcMediaSize
*)d
->sizes
->next())
3179 if (si
->size_code
->value
&& si
->region_code
->value
)
3181 // Output a custom media size...
3182 quotef(fp
, " %sCustomMedia \"%s/%s\" %.2f %.2f %.2f %.2f %.2f %.2f \"%s\" \"%s\"\n",
3183 si
->name
== d
->default_size
? "*" : "", si
->name
->value
,
3184 si
->text
->value
, si
->width
, si
->length
, si
->left
, si
->bottom
,
3185 si
->right
, si
->top
, si
->size_code
->value
,
3186 si
->region_code
->value
);
3190 // Output a standard media size...
3191 if (fabs(left
- si
->left
) > 0.1 ||
3192 fabs(bottom
- si
->bottom
) > 0.1 ||
3193 fabs(right
- si
->right
) > 0.1 ||
3194 fabs(top
- si
->top
) > 0.1)
3196 cupsFilePrintf(fp
, " HWMargins %.2f %.2f %.2f %.2f\n",
3197 si
->left
, si
->bottom
, si
->right
, si
->top
);
3200 bottom
= si
->bottom
;
3205 cupsFilePrintf(fp
, " %sMediaSize %s\n",
3206 si
->name
== d
->default_size
? "*" : "",
3210 if (d
->variable_paper_size
)
3212 cupsFilePuts(fp
, " VariablePaperSize Yes\n");
3214 if (fabs(left
- d
->left_margin
) > 0.1 ||
3215 fabs(bottom
- d
->bottom_margin
) > 0.1 ||
3216 fabs(right
- d
->right_margin
) > 0.1 ||
3217 fabs(top
- d
->top_margin
) > 0.1)
3219 cupsFilePrintf(fp
, " HWMargins %.2f %.2f %.2f %.2f\n",
3220 d
->left_margin
, d
->bottom_margin
, d
->right_margin
,
3224 cupsFilePrintf(fp
, " MinSize %.2f %.2f\n", d
->min_width
, d
->min_length
);
3225 cupsFilePrintf(fp
, " MaxSize %.2f %.2f\n", d
->max_width
, d
->max_length
);
3228 // End the driver...
3229 cupsFilePuts(fp
, "}\n");
3232 // Close the file and return...