]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc.h
4 // Definitions 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/".
20 // Include necessary headers...
23 # include <cups/string.h>
25 # include <cups/file.h>
35 # define PPDC_NAME(s) const char *class_name() { return (s); }
36 # define PPDC_NEW fprintf(stderr, "DEBUG: %p new %s\n", this, class_name())
37 # define PPDC_NEWVAL(s) fprintf(stderr, "DEBUG: %p new %s(\"%s\")\n", this, class_name(), s)
38 # define PPDC_DELETE fprintf(stderr, "DEBUG: %p delete %s\n", this, class_name())
42 # define PPDC_NEWVAL(s)
51 enum ppdcDrvType
//// Driver type
53 PPDC_DRIVER_CUSTOM
, // Custom driver
54 PPDC_DRIVER_PS
, // PostScript driver
55 PPDC_DRIVER_ESCP
, // rastertoescpx driver
56 PPDC_DRIVER_PCL
, // rastertopclx driver
57 PPDC_DRIVER_LABEL
, // rastertolabel/rastertodymo driver
58 PPDC_DRIVER_EPSON
, // rastertoepson driver
59 PPDC_DRIVER_HP
, // rastertohp driver
60 PPDC_DRIVER_MAX
// Number of driver types defined
63 enum ppdcFontStatus
//// Load status of font
65 PPDC_FONT_ROM
, // Font is in ROM
66 PPDC_FONT_DISK
// Font is on disk
69 enum ppdcOptSection
//// Option section
71 PPDC_SECTION_ANY
, // AnySetup
72 PPDC_SECTION_DOCUMENT
, // DocumentSetup
73 PPDC_SECTION_EXIT
, // ExitServer
74 PPDC_SECTION_JCL
, // JCLSetup
75 PPDC_SECTION_PAGE
, // PageSetup
76 PPDC_SECTION_PROLOG
// Prolog
79 enum ppdcOptType
//// Option type
81 PPDC_BOOLEAN
, // True/false option
82 PPDC_PICKONE
, // Single choice from list
83 PPDC_PICKMANY
// Multiple choices from list
86 enum ppdcLineEnding
//// Line endings
88 PPDC_LFONLY
, // LF only
89 PPDC_CRONLY
, // CR only
93 enum ppdcCondFlags
//// Condition flags
95 PPDC_COND_NORMAL
= 0, // Normal state
96 PPDC_COND_SKIP
= 1, // Skip state
97 PPDC_COND_SATISFIED
= 2 // At least one condition satisfied
102 // Printer description data...
105 class ppdcShared
//// Shared Data Value
109 int use
; // Use count (delete when 0)
114 virtual ~ppdcShared();
117 virtual const char *class_name() = 0;
124 class ppdcArray
//// Shared Array
129 int count
, // Number of elements
130 alloc
, // Allocated elements
131 current
; // Current element
132 ppdcShared
**data
; // Elements
134 ppdcArray(ppdcArray
*a
= 0);
137 PPDC_NAME("ppdcArray")
139 void add(ppdcShared
*d
);
142 void remove(ppdcShared
*d
);
145 class ppdcString
//// Shared String
150 char *value
; // String value
152 ppdcString(const char *v
);
155 PPDC_NAME("ppdcString")
158 class ppdcInteger
//// Shared integer
163 int *value
; // Integer value
165 ppdcInteger(int *v
) { value
= v
; }
167 PPDC_NAME("ppdcInteger")
170 class ppdcMessage
//// Translation message
175 ppdcString
*id
, // Translation ID
176 *string
; // Translation string
178 ppdcMessage(const char *i
, const char *s
);
181 PPDC_NAME("ppdcMessage")
184 class ppdcCatalog
//// Translation catalog
189 ppdcString
*locale
; // Name of locale
190 ppdcString
*filename
; // Name of translation file
191 ppdcArray
*messages
; // Array of translation messages
193 ppdcCatalog(const char *l
, const char *f
= 0);
196 PPDC_NAME("ppdcCatalog")
198 void add_message(const char *id
, const char *string
= NULL
);
199 const char *find_message(const char *id
);
200 int load_messages(const char *f
);
201 int save_messages(const char *f
);
204 class ppdcAttr
//// Attribute
209 ppdcString
*name
, // Name of attribute
210 *selector
, // Selector string
211 *text
, // Text string
212 *value
; // Value string
213 bool localizable
; // Should this attribute be localized?
215 ppdcAttr(const char *n
, const char *s
, const char *t
, const char *v
,
219 PPDC_NAME("ppdcAttr")
222 class ppdcFont
//// Shared Font
227 ppdcString
*name
, // Font name
228 *encoding
, // Font base encoding
229 *version
, // Font version
230 *charset
; // Font charset
231 ppdcFontStatus status
; // Font status (ROM or Disk)
233 ppdcFont(const char *n
, const char *e
, const char *v
, const char *c
,
237 PPDC_NAME("ppdcFont")
240 class ppdcChoice
//// Option Choice
245 ppdcString
*name
, // Name of choice
246 *text
, // Human-readable text of choice
247 *code
; // PS code of choice
249 ppdcChoice(const char *n
, const char *t
, const char *c
);
252 PPDC_NAME("ppdcChoice")
255 class ppdcOption
//// Option
260 ppdcOptType type
; // Type of option
261 ppdcString
*name
, // Name of option
262 *text
; // Human-readable text of option
263 ppdcOptSection section
; // Section for option code
264 float order
; // Order number
265 ppdcArray
*choices
; // Choices
266 ppdcString
*defchoice
; // Default choice
268 ppdcOption(ppdcOptType ot
, const char *n
, const char *t
, ppdcOptSection s
,
270 ppdcOption(ppdcOption
*o
);
273 PPDC_NAME("ppdcOption")
275 void add_choice(ppdcChoice
*c
) { choices
->add(c
); }
276 ppdcChoice
*find_choice(const char *n
);
277 void set_defchoice(ppdcChoice
*c
);
280 class ppdcGroup
//// Group of Options
285 ppdcString
*name
, // Name of option
286 *text
; // Human-readable text of option
287 ppdcArray
*options
; // Options
289 ppdcGroup(const char *n
, const char *t
);
290 ppdcGroup(ppdcGroup
*g
);
293 PPDC_NAME("ppdcGroup")
295 void add_option(ppdcOption
*o
) { options
->add(o
); }
296 ppdcOption
*find_option(const char *n
);
299 class ppdcConstraint
//// Constraint
304 ppdcString
*option1
, // First option
305 *choice1
, // First choice
306 *option2
, // Second option
307 *choice2
; // Second choice
309 ppdcConstraint(const char *o1
, const char *c1
, const char *o2
,
313 PPDC_NAME("ppdcConstraint")
316 class ppdcFilter
//// Filter Program
321 ppdcString
*mime_type
, // MIME type
322 *program
; // Filter program
323 int cost
; // Relative cost of filter
325 ppdcFilter(const char *t
, const char *p
, int c
);
328 PPDC_NAME("ppdcFilter")
331 class ppdcMediaSize
//// Media Size
336 ppdcString
*name
, // Name of size
337 *text
; // Human-readable text
338 float width
, // Width in points
339 length
, // Length in points
340 left
, // Left limit in points
341 bottom
, // Bottom limit in points
342 right
, // Right limit in points
343 top
; // Top limit in points
344 ppdcString
*size_code
, // PageSize code, if any
345 *region_code
; // PageRegion code, if any
347 ppdcMediaSize(const char *n
, const char *t
, float w
, float l
,
348 float lm
, float bm
, float rm
, float tm
,
349 const char *sc
= 0, const char *rc
= 0);
352 PPDC_NAME("ppdcMediaSize")
355 class ppdcProfile
//// Color Profile
360 ppdcString
*resolution
, // Resolution name
361 *media_type
; // Media type name
362 float density
, // Color profile density
363 gamma
, // Color profile gamma
364 profile
[9]; // Color profile matrix
366 ppdcProfile(const char *r
, const char *m
, float d
, float g
, const float *p
);
369 PPDC_NAME("ppdcProfile")
374 class ppdcDriver
//// Printer Driver Data
379 ppdcDrvType type
; // Driver type
380 ppdcArray
*copyright
; // Copyright strings
381 ppdcString
*manufacturer
, // Manufacturer
382 *model_name
, // Name of printer model
383 *file_name
, // Output filename for PPD
384 *pc_file_name
, // 8 character PC filename for PPD
385 *version
; // Version number
386 int model_number
, // Model number for driver
387 manual_copies
, // Do manual copies?
388 color_device
, // Support color?
389 throughput
; // Throughput in pages per minute
390 ppdcArray
*attrs
, // Attributes
391 *constraints
, // Constraints
394 *groups
, // Option groups
395 *profiles
, // Color profiles
396 *sizes
; // Fixed sizes
397 ppdcString
*default_font
, // Default font
398 *default_size
; // Default size option
399 int variable_paper_size
; // Support variable sizes?
400 ppdcString
*custom_size_code
; // Custom page size code, if any
401 float left_margin
, // Margins for device in points
405 max_width
, // Maximum width (points)
406 max_length
, // Maximum length (points)
407 min_width
, // Minimum width (points)
408 min_length
; // Minimum length (points)
410 ppdcDriver(ppdcDriver
*d
= 0);
413 PPDC_NAME("ppdcDriver")
415 void add_attr(ppdcAttr
*a
) { attrs
->add(a
); }
416 void add_constraint(ppdcConstraint
*c
) { constraints
->add(c
); }
417 void add_copyright(const char *c
) {
418 copyright
->add(new ppdcString(c
));
420 void add_filter(ppdcFilter
*f
) { filters
->add(f
); }
421 void add_font(ppdcFont
*f
) { fonts
->add(f
); }
422 void add_group(ppdcGroup
*g
) { groups
->add(g
); }
423 void add_profile(ppdcProfile
*p
) { profiles
->add(p
); }
424 void add_size(ppdcMediaSize
*m
) { sizes
->add(m
); }
426 ppdcAttr
*find_attr(const char *k
, const char *s
);
427 ppdcGroup
*find_group(const char *n
);
428 ppdcOption
*find_option(const char *n
);
430 void set_custom_size_code(const char *c
);
431 void set_default_font(ppdcFont
*f
);
432 void set_default_size(ppdcMediaSize
*m
);
433 void set_file_name(const char *f
);
434 void set_manufacturer(const char *m
);
435 void set_model_name(const char *m
);
436 void set_pc_file_name(const char *f
);
437 void set_version(const char *v
);
439 int write_ppd_file(cups_file_t
*fp
, ppdcCatalog
*catalog
,
440 ppdcArray
*locales
, ppdcSource
*src
,
444 class ppdcVariable
//// Variable Definition
449 ppdcString
*name
, // Name of variable
450 *value
; // Value of variable
452 ppdcVariable(const char *n
, const char *v
);
455 PPDC_NAME("ppdcVariable")
457 void set_value(const char *v
);
460 class ppdcFile
//// File
464 cups_file_t
*fp
; // File pointer
465 const char *filename
; // Filename
466 int line
; // Line in file
468 ppdcFile(const char *f
, cups_file_t
*ffp
= (cups_file_t
*)0);
475 class ppdcSource
//// Source File
480 static ppdcArray
*includes
; // Include directories
481 static const char *driver_types
[]; // Driver types
483 ppdcString
*filename
; // Filename
484 ppdcArray
*base_fonts
, // Base fonts
485 *drivers
, // Printer drivers
486 *po_files
, // Message catalogs
487 *sizes
, // Predefined media sizes
488 *vars
; // Defined variables
489 int cond_state
, // Cummulative conditional state
490 *cond_current
, // Current #if state
491 cond_stack
[101]; // #if state stack
494 ppdcSource(const char *f
= 0, cups_file_t
*ffp
= (cups_file_t
*)0);
497 PPDC_NAME("ppdcSource")
499 static void add_include(const char *d
);
500 ppdcDriver
*find_driver(const char *f
);
501 static char *find_include(const char *f
, const char *base
, char *n
,
503 ppdcCatalog
*find_po(const char *l
);
504 ppdcMediaSize
*find_size(const char *s
);
505 ppdcVariable
*find_variable(const char *n
);
506 ppdcAttr
*get_attr(ppdcFile
*fp
, bool loc
= false);
507 int get_boolean(ppdcFile
*fp
);
508 ppdcChoice
*get_choice(ppdcFile
*fp
);
509 ppdcChoice
*get_color_model(ppdcFile
*fp
);
510 int get_color_order(const char *co
);
511 ppdcProfile
*get_color_profile(ppdcFile
*fp
);
512 int get_color_space(const char *cs
);
513 ppdcConstraint
*get_constraint(ppdcFile
*fp
);
514 ppdcMediaSize
*get_custom_size(ppdcFile
*fp
);
515 void get_duplex(ppdcFile
*fp
, ppdcDriver
*d
);
516 ppdcFilter
*get_filter(ppdcFile
*fp
);
517 float get_float(ppdcFile
*fp
);
518 ppdcFont
*get_font(ppdcFile
*fp
);
519 ppdcChoice
*get_generic(ppdcFile
*fp
, const char *keyword
,
520 const char *tattr
, const char *nattr
);
521 ppdcGroup
*get_group(ppdcFile
*fp
, ppdcDriver
*d
);
522 ppdcOption
*get_installable(ppdcFile
*fp
);
523 int get_integer(const char *v
);
524 int get_integer(ppdcFile
*fp
);
525 float get_measurement(ppdcFile
*fp
);
526 ppdcOption
*get_option(ppdcFile
*fp
, ppdcDriver
*d
, ppdcGroup
*g
);
527 ppdcCatalog
*get_po(ppdcFile
*fp
);
528 ppdcChoice
*get_resolution(ppdcFile
*fp
);
529 ppdcProfile
*get_simple_profile(ppdcFile
*fp
);
530 ppdcMediaSize
*get_size(ppdcFile
*fp
);
531 char *get_token(ppdcFile
*fp
, char *buffer
, int buflen
);
532 ppdcVariable
*get_variable(ppdcFile
*fp
);
533 int import_ppd(const char *f
);
534 int quotef(cups_file_t
*fp
, const char *format
, ...);
535 void read_file(const char *f
, cups_file_t
*ffp
= (cups_file_t
*)0);
536 void scan_file(ppdcFile
*fp
, ppdcDriver
*td
= 0, bool inc
= false);
537 ppdcVariable
*set_variable(const char *name
, const char *value
);
538 int write_file(const char *f
);