]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc.h
2 // Definitions for the CUPS PPD Compiler.
4 // Copyright 2007-2019 by Apple Inc.
5 // Copyright 2002-2007 by Easy Software Products.
7 // Licensed under Apache License v2.0. See the file "LICENSE" for more information.
14 // Include necessary headers...
17 # include <cups/file.h>
25 # define PPDC_NAME(s) const char *class_name() { return (s); }
32 enum ppdcDrvType
//// Driver type
34 PPDC_DRIVER_CUSTOM
, // Custom driver
35 PPDC_DRIVER_PS
, // PostScript driver
36 PPDC_DRIVER_ESCP
, // rastertoescpx driver
37 PPDC_DRIVER_PCL
, // rastertopclx driver
38 PPDC_DRIVER_LABEL
, // rastertolabel/rastertodymo driver
39 PPDC_DRIVER_EPSON
, // rastertoepson driver
40 PPDC_DRIVER_HP
, // rastertohp driver
41 PPDC_DRIVER_MAX
// Number of driver types defined
44 enum ppdcFontStatus
//// Load status of font
46 PPDC_FONT_ROM
, // Font is in ROM
47 PPDC_FONT_DISK
// Font is on disk
50 enum ppdcOptSection
//// Option section
52 PPDC_SECTION_ANY
, // AnySetup
53 PPDC_SECTION_DOCUMENT
, // DocumentSetup
54 PPDC_SECTION_EXIT
, // ExitServer
55 PPDC_SECTION_JCL
, // JCLSetup
56 PPDC_SECTION_PAGE
, // PageSetup
57 PPDC_SECTION_PROLOG
// Prolog
60 enum ppdcOptType
//// Option type
62 PPDC_BOOLEAN
, // True/false option
63 PPDC_PICKONE
, // Single choice from list
64 PPDC_PICKMANY
// Multiple choices from list
67 enum ppdcLineEnding
//// Line endings
69 PPDC_LFONLY
, // LF only
70 PPDC_CRONLY
, // CR only
74 enum ppdcCondFlags
//// Condition flags
76 PPDC_COND_NORMAL
= 0, // Normal state
77 PPDC_COND_SKIP
= 1, // Skip state
78 PPDC_COND_SATISFIED
= 2 // At least one condition satisfied
83 // Printer description data...
86 class ppdcShared
//// Shared Data Value
90 int use
; // Use count (delete when 0)
95 virtual ~ppdcShared();
97 virtual const char *class_name() = 0;
103 class ppdcArray
//// Shared Array
108 size_t count
, // Number of elements
109 alloc
, // Allocated elements
110 current
; // Current element
111 ppdcShared
**data
; // Elements
113 ppdcArray(ppdcArray
*a
= 0);
116 PPDC_NAME("ppdcArray")
118 void add(ppdcShared
*d
);
121 void remove(ppdcShared
*d
);
124 class ppdcString
//// Shared String
129 char *value
; // String value
131 ppdcString(const char *v
);
134 PPDC_NAME("ppdcString")
137 class ppdcInteger
//// Shared integer
142 int *value
; // Integer value
144 ppdcInteger(int *v
) { value
= v
; }
146 PPDC_NAME("ppdcInteger")
149 class ppdcMessage
//// Translation message
154 ppdcString
*id
, // Translation ID
155 *string
; // Translation string
157 ppdcMessage(const char *i
, const char *s
);
160 PPDC_NAME("ppdcMessage")
163 class ppdcCatalog
//// Translation catalog
168 ppdcString
*locale
; // Name of locale
169 ppdcString
*filename
; // Name of translation file
170 ppdcArray
*messages
; // Array of translation messages
172 ppdcCatalog(const char *l
, const char *f
= 0);
175 PPDC_NAME("ppdcCatalog")
177 void add_message(const char *id
, const char *string
= NULL
);
178 const char *find_message(const char *id
);
179 int load_messages(const char *f
);
180 int save_messages(const char *f
);
183 class ppdcAttr
//// Attribute
188 ppdcString
*name
, // Name of attribute
189 *selector
, // Selector string
190 *text
, // Text string
191 *value
; // Value string
192 bool localizable
; // Should this attribute be localized?
194 ppdcAttr(const char *n
, const char *s
, const char *t
, const char *v
,
198 PPDC_NAME("ppdcAttr")
201 class ppdcFont
//// Shared Font
206 ppdcString
*name
, // Font name
207 *encoding
, // Font base encoding
208 *version
, // Font version
209 *charset
; // Font charset
210 ppdcFontStatus status
; // Font status (ROM or Disk)
212 ppdcFont(const char *n
, const char *e
, const char *v
, const char *c
,
216 PPDC_NAME("ppdcFont")
219 class ppdcChoice
//// Option Choice
224 ppdcString
*name
, // Name of choice
225 *text
, // Human-readable text of choice
226 *code
; // PS code of choice
228 ppdcChoice(const char *n
, const char *t
, const char *c
);
231 PPDC_NAME("ppdcChoice")
234 class ppdcOption
//// Option
239 ppdcOptType type
; // Type of option
240 ppdcString
*name
, // Name of option
241 *text
; // Human-readable text of option
242 ppdcOptSection section
; // Section for option code
243 float order
; // Order number
244 ppdcArray
*choices
; // Choices
245 ppdcString
*defchoice
; // Default choice
247 ppdcOption(ppdcOptType ot
, const char *n
, const char *t
, ppdcOptSection s
,
249 ppdcOption(ppdcOption
*o
);
252 PPDC_NAME("ppdcOption")
254 void add_choice(ppdcChoice
*c
) { choices
->add(c
); }
255 ppdcChoice
*find_choice(const char *n
);
256 void set_defchoice(ppdcChoice
*c
);
259 class ppdcGroup
//// Group of Options
264 ppdcString
*name
, // Name of option
265 *text
; // Human-readable text of option
266 ppdcArray
*options
; // Options
268 ppdcGroup(const char *n
, const char *t
);
269 ppdcGroup(ppdcGroup
*g
);
272 PPDC_NAME("ppdcGroup")
274 void add_option(ppdcOption
*o
) { options
->add(o
); }
275 ppdcOption
*find_option(const char *n
);
278 class ppdcConstraint
//// Constraint
283 ppdcString
*option1
, // First option
284 *choice1
, // First choice
285 *option2
, // Second option
286 *choice2
; // Second choice
288 ppdcConstraint(const char *o1
, const char *c1
, const char *o2
,
292 PPDC_NAME("ppdcConstraint")
295 class ppdcFilter
//// Filter Program
300 ppdcString
*mime_type
, // MIME type
301 *program
; // Filter program
302 int cost
; // Relative cost of filter
304 ppdcFilter(const char *t
, const char *p
, int c
);
307 PPDC_NAME("ppdcFilter")
310 class ppdcMediaSize
//// Media Size
315 ppdcString
*name
, // Name of size
316 *text
; // Human-readable text
317 float width
, // Width in points
318 length
, // Length in points
319 left
, // Left limit in points
320 bottom
, // Bottom limit in points
321 right
, // Right limit in points
322 top
; // Top limit in points
323 ppdcString
*size_code
, // PageSize code, if any
324 *region_code
; // PageRegion code, if any
326 ppdcMediaSize(const char *n
, const char *t
, float w
, float l
,
327 float lm
, float bm
, float rm
, float tm
,
328 const char *sc
= 0, const char *rc
= 0);
331 PPDC_NAME("ppdcMediaSize")
334 class ppdcProfile
//// Color Profile
339 ppdcString
*resolution
, // Resolution name
340 *media_type
; // Media type name
341 float density
, // Color profile density
342 gamma
, // Color profile gamma
343 profile
[9]; // Color profile matrix
345 ppdcProfile(const char *r
, const char *m
, float d
, float g
, const float *p
);
348 PPDC_NAME("ppdcProfile")
353 class ppdcDriver
//// Printer Driver Data
358 ppdcDrvType type
; // Driver type
359 ppdcArray
*copyright
; // Copyright strings
360 ppdcString
*manufacturer
, // Manufacturer
361 *model_name
, // Name of printer model
362 *file_name
, // Output filename for PPD
363 *pc_file_name
, // 8 character PC filename for PPD
364 *version
; // Version number
365 int model_number
, // Model number for driver
366 manual_copies
, // Do manual copies?
367 color_device
, // Support color?
368 throughput
; // Throughput in pages per minute
369 ppdcArray
*attrs
, // Attributes
370 *constraints
, // Constraints
373 *groups
, // Option groups
374 *profiles
, // Color profiles
375 *sizes
; // Fixed sizes
376 ppdcString
*default_font
, // Default font
377 *default_size
; // Default size option
378 int variable_paper_size
; // Support variable sizes?
379 ppdcString
*custom_size_code
; // Custom page size code, if any
380 float left_margin
, // Margins for device in points
384 max_width
, // Maximum width (points)
385 max_length
, // Maximum length (points)
386 min_width
, // Minimum width (points)
387 min_length
; // Minimum length (points)
389 ppdcDriver(ppdcDriver
*d
= 0);
392 PPDC_NAME("ppdcDriver")
394 void add_attr(ppdcAttr
*a
) { attrs
->add(a
); }
395 void add_constraint(ppdcConstraint
*c
) { constraints
->add(c
); }
396 void add_copyright(const char *c
) {
397 copyright
->add(new ppdcString(c
));
399 void add_filter(ppdcFilter
*f
) { filters
->add(f
); }
400 void add_font(ppdcFont
*f
) { fonts
->add(f
); }
401 void add_group(ppdcGroup
*g
) { groups
->add(g
); }
402 void add_profile(ppdcProfile
*p
) { profiles
->add(p
); }
403 void add_size(ppdcMediaSize
*m
) { sizes
->add(m
); }
405 ppdcAttr
*find_attr(const char *k
, const char *s
);
406 ppdcGroup
*find_group(const char *n
);
407 ppdcOption
*find_option(const char *n
);
408 ppdcOption
*find_option_group(const char *n
, ppdcGroup
**mg
);
410 void set_custom_size_code(const char *c
);
411 void set_default_font(ppdcFont
*f
);
412 void set_default_size(ppdcMediaSize
*m
);
413 void set_file_name(const char *f
);
414 void set_manufacturer(const char *m
);
415 void set_model_name(const char *m
);
416 void set_pc_file_name(const char *f
);
417 void set_version(const char *v
);
419 int write_ppd_file(cups_file_t
*fp
, ppdcCatalog
*catalog
,
420 ppdcArray
*locales
, ppdcSource
*src
,
424 class ppdcVariable
//// Variable Definition
429 ppdcString
*name
, // Name of variable
430 *value
; // Value of variable
432 ppdcVariable(const char *n
, const char *v
);
435 PPDC_NAME("ppdcVariable")
437 void set_value(const char *v
);
440 class ppdcFile
//// File
444 bool close_on_delete
; // Close file on delete?
445 cups_file_t
*fp
; // File pointer
446 const char *filename
; // Filename
447 int line
; // Line in file
449 ppdcFile(const char *f
, cups_file_t
*ffp
= (cups_file_t
*)0);
456 class ppdcSource
//// Source File
461 static ppdcArray
*includes
; // Include directories
462 static const char *driver_types
[]; // Driver types
464 ppdcString
*filename
; // Filename
465 ppdcArray
*base_fonts
, // Base fonts
466 *drivers
, // Printer drivers
467 *po_files
, // Message catalogs
468 *sizes
, // Predefined media sizes
469 *vars
; // Defined variables
470 int cond_state
, // Cummulative conditional state
471 *cond_current
, // Current #if state
472 cond_stack
[101]; // #if state stack
475 ppdcSource(const char *f
= 0, cups_file_t
*ffp
= (cups_file_t
*)0);
478 PPDC_NAME("ppdcSource")
480 static void add_include(const char *d
);
481 ppdcDriver
*find_driver(const char *f
);
482 static char *find_include(const char *f
, const char *base
, char *n
,
484 ppdcCatalog
*find_po(const char *l
);
485 ppdcMediaSize
*find_size(const char *s
);
486 ppdcVariable
*find_variable(const char *n
);
487 ppdcAttr
*get_attr(ppdcFile
*fp
, bool loc
= false);
488 int get_boolean(ppdcFile
*fp
);
489 ppdcChoice
*get_choice(ppdcFile
*fp
);
490 ppdcChoice
*get_color_model(ppdcFile
*fp
);
491 int get_color_order(const char *co
);
492 ppdcProfile
*get_color_profile(ppdcFile
*fp
);
493 int get_color_space(const char *cs
);
494 ppdcConstraint
*get_constraint(ppdcFile
*fp
);
495 ppdcMediaSize
*get_custom_size(ppdcFile
*fp
);
496 void get_duplex(ppdcFile
*fp
, ppdcDriver
*d
);
497 ppdcFilter
*get_filter(ppdcFile
*fp
);
498 float get_float(ppdcFile
*fp
);
499 ppdcFont
*get_font(ppdcFile
*fp
);
500 ppdcChoice
*get_generic(ppdcFile
*fp
, const char *keyword
,
501 const char *tattr
, const char *nattr
);
502 ppdcGroup
*get_group(ppdcFile
*fp
, ppdcDriver
*d
);
503 ppdcOption
*get_installable(ppdcFile
*fp
);
504 int get_integer(const char *v
);
505 int get_integer(ppdcFile
*fp
);
506 float get_measurement(ppdcFile
*fp
);
507 ppdcOption
*get_option(ppdcFile
*fp
, ppdcDriver
*d
, ppdcGroup
*g
);
508 ppdcCatalog
*get_po(ppdcFile
*fp
);
509 ppdcChoice
*get_resolution(ppdcFile
*fp
);
510 ppdcProfile
*get_simple_profile(ppdcFile
*fp
);
511 ppdcMediaSize
*get_size(ppdcFile
*fp
);
512 char *get_token(ppdcFile
*fp
, char *buffer
, int buflen
);
513 ppdcVariable
*get_variable(ppdcFile
*fp
);
514 int import_ppd(const char *f
);
515 int quotef(cups_file_t
*fp
, const char *format
, ...);
516 void read_file(const char *f
, cups_file_t
*ffp
= (cups_file_t
*)0);
517 void scan_file(ppdcFile
*fp
, ppdcDriver
*td
= 0, bool inc
= false);
518 ppdcVariable
*set_variable(const char *name
, const char *value
);
519 int write_file(const char *f
);