]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc.h
4 // Definitions 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/".
20 // Include necessary headers...
23 # include <cups/file.h>
31 # define PPDC_NAME(s) const char *class_name() { return (s); }
38 enum ppdcDrvType
//// Driver type
40 PPDC_DRIVER_CUSTOM
, // Custom driver
41 PPDC_DRIVER_PS
, // PostScript driver
42 PPDC_DRIVER_ESCP
, // rastertoescpx driver
43 PPDC_DRIVER_PCL
, // rastertopclx driver
44 PPDC_DRIVER_LABEL
, // rastertolabel/rastertodymo driver
45 PPDC_DRIVER_EPSON
, // rastertoepson driver
46 PPDC_DRIVER_HP
, // rastertohp driver
47 PPDC_DRIVER_MAX
// Number of driver types defined
50 enum ppdcFontStatus
//// Load status of font
52 PPDC_FONT_ROM
, // Font is in ROM
53 PPDC_FONT_DISK
// Font is on disk
56 enum ppdcOptSection
//// Option section
58 PPDC_SECTION_ANY
, // AnySetup
59 PPDC_SECTION_DOCUMENT
, // DocumentSetup
60 PPDC_SECTION_EXIT
, // ExitServer
61 PPDC_SECTION_JCL
, // JCLSetup
62 PPDC_SECTION_PAGE
, // PageSetup
63 PPDC_SECTION_PROLOG
// Prolog
66 enum ppdcOptType
//// Option type
68 PPDC_BOOLEAN
, // True/false option
69 PPDC_PICKONE
, // Single choice from list
70 PPDC_PICKMANY
// Multiple choices from list
73 enum ppdcLineEnding
//// Line endings
75 PPDC_LFONLY
, // LF only
76 PPDC_CRONLY
, // CR only
80 enum ppdcCondFlags
//// Condition flags
82 PPDC_COND_NORMAL
= 0, // Normal state
83 PPDC_COND_SKIP
= 1, // Skip state
84 PPDC_COND_SATISFIED
= 2 // At least one condition satisfied
89 // Printer description data...
92 class ppdcShared
//// Shared Data Value
96 int use
; // Use count (delete when 0)
101 virtual ~ppdcShared();
103 virtual const char *class_name() = 0;
109 class ppdcArray
//// Shared Array
114 int count
, // Number of elements
115 alloc
, // Allocated elements
116 current
; // Current element
117 ppdcShared
**data
; // Elements
119 ppdcArray(ppdcArray
*a
= 0);
122 PPDC_NAME("ppdcArray")
124 void add(ppdcShared
*d
);
127 void remove(ppdcShared
*d
);
130 class ppdcString
//// Shared String
135 char *value
; // String value
137 ppdcString(const char *v
);
140 PPDC_NAME("ppdcString")
143 class ppdcInteger
//// Shared integer
148 int *value
; // Integer value
150 ppdcInteger(int *v
) { value
= v
; }
152 PPDC_NAME("ppdcInteger")
155 class ppdcMessage
//// Translation message
160 ppdcString
*id
, // Translation ID
161 *string
; // Translation string
163 ppdcMessage(const char *i
, const char *s
);
166 PPDC_NAME("ppdcMessage")
169 class ppdcCatalog
//// Translation catalog
174 ppdcString
*locale
; // Name of locale
175 ppdcString
*filename
; // Name of translation file
176 ppdcArray
*messages
; // Array of translation messages
178 ppdcCatalog(const char *l
, const char *f
= 0);
181 PPDC_NAME("ppdcCatalog")
183 void add_message(const char *id
, const char *string
= NULL
);
184 const char *find_message(const char *id
);
185 int load_messages(const char *f
);
186 int save_messages(const char *f
);
189 class ppdcAttr
//// Attribute
194 ppdcString
*name
, // Name of attribute
195 *selector
, // Selector string
196 *text
, // Text string
197 *value
; // Value string
198 bool localizable
; // Should this attribute be localized?
200 ppdcAttr(const char *n
, const char *s
, const char *t
, const char *v
,
204 PPDC_NAME("ppdcAttr")
207 class ppdcFont
//// Shared Font
212 ppdcString
*name
, // Font name
213 *encoding
, // Font base encoding
214 *version
, // Font version
215 *charset
; // Font charset
216 ppdcFontStatus status
; // Font status (ROM or Disk)
218 ppdcFont(const char *n
, const char *e
, const char *v
, const char *c
,
222 PPDC_NAME("ppdcFont")
225 class ppdcChoice
//// Option Choice
230 ppdcString
*name
, // Name of choice
231 *text
, // Human-readable text of choice
232 *code
; // PS code of choice
234 ppdcChoice(const char *n
, const char *t
, const char *c
);
237 PPDC_NAME("ppdcChoice")
240 class ppdcOption
//// Option
245 ppdcOptType type
; // Type of option
246 ppdcString
*name
, // Name of option
247 *text
; // Human-readable text of option
248 ppdcOptSection section
; // Section for option code
249 float order
; // Order number
250 ppdcArray
*choices
; // Choices
251 ppdcString
*defchoice
; // Default choice
253 ppdcOption(ppdcOptType ot
, const char *n
, const char *t
, ppdcOptSection s
,
255 ppdcOption(ppdcOption
*o
);
258 PPDC_NAME("ppdcOption")
260 void add_choice(ppdcChoice
*c
) { choices
->add(c
); }
261 ppdcChoice
*find_choice(const char *n
);
262 void set_defchoice(ppdcChoice
*c
);
265 class ppdcGroup
//// Group of Options
270 ppdcString
*name
, // Name of option
271 *text
; // Human-readable text of option
272 ppdcArray
*options
; // Options
274 ppdcGroup(const char *n
, const char *t
);
275 ppdcGroup(ppdcGroup
*g
);
278 PPDC_NAME("ppdcGroup")
280 void add_option(ppdcOption
*o
) { options
->add(o
); }
281 ppdcOption
*find_option(const char *n
);
284 class ppdcConstraint
//// Constraint
289 ppdcString
*option1
, // First option
290 *choice1
, // First choice
291 *option2
, // Second option
292 *choice2
; // Second choice
294 ppdcConstraint(const char *o1
, const char *c1
, const char *o2
,
298 PPDC_NAME("ppdcConstraint")
301 class ppdcFilter
//// Filter Program
306 ppdcString
*mime_type
, // MIME type
307 *program
; // Filter program
308 int cost
; // Relative cost of filter
310 ppdcFilter(const char *t
, const char *p
, int c
);
313 PPDC_NAME("ppdcFilter")
316 class ppdcMediaSize
//// Media Size
321 ppdcString
*name
, // Name of size
322 *text
; // Human-readable text
323 float width
, // Width in points
324 length
, // Length in points
325 left
, // Left limit in points
326 bottom
, // Bottom limit in points
327 right
, // Right limit in points
328 top
; // Top limit in points
329 ppdcString
*size_code
, // PageSize code, if any
330 *region_code
; // PageRegion code, if any
332 ppdcMediaSize(const char *n
, const char *t
, float w
, float l
,
333 float lm
, float bm
, float rm
, float tm
,
334 const char *sc
= 0, const char *rc
= 0);
337 PPDC_NAME("ppdcMediaSize")
340 class ppdcProfile
//// Color Profile
345 ppdcString
*resolution
, // Resolution name
346 *media_type
; // Media type name
347 float density
, // Color profile density
348 gamma
, // Color profile gamma
349 profile
[9]; // Color profile matrix
351 ppdcProfile(const char *r
, const char *m
, float d
, float g
, const float *p
);
354 PPDC_NAME("ppdcProfile")
359 class ppdcDriver
//// Printer Driver Data
364 ppdcDrvType type
; // Driver type
365 ppdcArray
*copyright
; // Copyright strings
366 ppdcString
*manufacturer
, // Manufacturer
367 *model_name
, // Name of printer model
368 *file_name
, // Output filename for PPD
369 *pc_file_name
, // 8 character PC filename for PPD
370 *version
; // Version number
371 int model_number
, // Model number for driver
372 manual_copies
, // Do manual copies?
373 color_device
, // Support color?
374 throughput
; // Throughput in pages per minute
375 ppdcArray
*attrs
, // Attributes
376 *constraints
, // Constraints
379 *groups
, // Option groups
380 *profiles
, // Color profiles
381 *sizes
; // Fixed sizes
382 ppdcString
*default_font
, // Default font
383 *default_size
; // Default size option
384 int variable_paper_size
; // Support variable sizes?
385 ppdcString
*custom_size_code
; // Custom page size code, if any
386 float left_margin
, // Margins for device in points
390 max_width
, // Maximum width (points)
391 max_length
, // Maximum length (points)
392 min_width
, // Minimum width (points)
393 min_length
; // Minimum length (points)
395 ppdcDriver(ppdcDriver
*d
= 0);
398 PPDC_NAME("ppdcDriver")
400 void add_attr(ppdcAttr
*a
) { attrs
->add(a
); }
401 void add_constraint(ppdcConstraint
*c
) { constraints
->add(c
); }
402 void add_copyright(const char *c
) {
403 copyright
->add(new ppdcString(c
));
405 void add_filter(ppdcFilter
*f
) { filters
->add(f
); }
406 void add_font(ppdcFont
*f
) { fonts
->add(f
); }
407 void add_group(ppdcGroup
*g
) { groups
->add(g
); }
408 void add_profile(ppdcProfile
*p
) { profiles
->add(p
); }
409 void add_size(ppdcMediaSize
*m
) { sizes
->add(m
); }
411 ppdcAttr
*find_attr(const char *k
, const char *s
);
412 ppdcGroup
*find_group(const char *n
);
413 ppdcOption
*find_option(const char *n
);
414 ppdcOption
*find_option_group(const char *n
, ppdcGroup
**mg
);
416 void set_custom_size_code(const char *c
);
417 void set_default_font(ppdcFont
*f
);
418 void set_default_size(ppdcMediaSize
*m
);
419 void set_file_name(const char *f
);
420 void set_manufacturer(const char *m
);
421 void set_model_name(const char *m
);
422 void set_pc_file_name(const char *f
);
423 void set_version(const char *v
);
425 int write_ppd_file(cups_file_t
*fp
, ppdcCatalog
*catalog
,
426 ppdcArray
*locales
, ppdcSource
*src
,
430 class ppdcVariable
//// Variable Definition
435 ppdcString
*name
, // Name of variable
436 *value
; // Value of variable
438 ppdcVariable(const char *n
, const char *v
);
441 PPDC_NAME("ppdcVariable")
443 void set_value(const char *v
);
446 class ppdcFile
//// File
450 cups_file_t
*fp
; // File pointer
451 const char *filename
; // Filename
452 int line
; // Line in file
454 ppdcFile(const char *f
, cups_file_t
*ffp
= (cups_file_t
*)0);
461 class ppdcSource
//// Source File
466 static ppdcArray
*includes
; // Include directories
467 static const char *driver_types
[]; // Driver types
469 ppdcString
*filename
; // Filename
470 ppdcArray
*base_fonts
, // Base fonts
471 *drivers
, // Printer drivers
472 *po_files
, // Message catalogs
473 *sizes
, // Predefined media sizes
474 *vars
; // Defined variables
475 int cond_state
, // Cummulative conditional state
476 *cond_current
, // Current #if state
477 cond_stack
[101]; // #if state stack
480 ppdcSource(const char *f
= 0, cups_file_t
*ffp
= (cups_file_t
*)0);
483 PPDC_NAME("ppdcSource")
485 static void add_include(const char *d
);
486 ppdcDriver
*find_driver(const char *f
);
487 static char *find_include(const char *f
, const char *base
, char *n
,
489 ppdcCatalog
*find_po(const char *l
);
490 ppdcMediaSize
*find_size(const char *s
);
491 ppdcVariable
*find_variable(const char *n
);
492 ppdcAttr
*get_attr(ppdcFile
*fp
, bool loc
= false);
493 int get_boolean(ppdcFile
*fp
);
494 ppdcChoice
*get_choice(ppdcFile
*fp
);
495 ppdcChoice
*get_color_model(ppdcFile
*fp
);
496 int get_color_order(const char *co
);
497 ppdcProfile
*get_color_profile(ppdcFile
*fp
);
498 int get_color_space(const char *cs
);
499 ppdcConstraint
*get_constraint(ppdcFile
*fp
);
500 ppdcMediaSize
*get_custom_size(ppdcFile
*fp
);
501 void get_duplex(ppdcFile
*fp
, ppdcDriver
*d
);
502 ppdcFilter
*get_filter(ppdcFile
*fp
);
503 float get_float(ppdcFile
*fp
);
504 ppdcFont
*get_font(ppdcFile
*fp
);
505 ppdcChoice
*get_generic(ppdcFile
*fp
, const char *keyword
,
506 const char *tattr
, const char *nattr
);
507 ppdcGroup
*get_group(ppdcFile
*fp
, ppdcDriver
*d
);
508 ppdcOption
*get_installable(ppdcFile
*fp
);
509 int get_integer(const char *v
);
510 int get_integer(ppdcFile
*fp
);
511 float get_measurement(ppdcFile
*fp
);
512 ppdcOption
*get_option(ppdcFile
*fp
, ppdcDriver
*d
, ppdcGroup
*g
);
513 ppdcCatalog
*get_po(ppdcFile
*fp
);
514 ppdcChoice
*get_resolution(ppdcFile
*fp
);
515 ppdcProfile
*get_simple_profile(ppdcFile
*fp
);
516 ppdcMediaSize
*get_size(ppdcFile
*fp
);
517 char *get_token(ppdcFile
*fp
, char *buffer
, int buflen
);
518 ppdcVariable
*get_variable(ppdcFile
*fp
);
519 int import_ppd(const char *f
);
520 int quotef(cups_file_t
*fp
, const char *format
, ...);
521 void read_file(const char *f
, cups_file_t
*ffp
= (cups_file_t
*)0);
522 void scan_file(ppdcFile
*fp
, ppdcDriver
*td
= 0, bool inc
= false);
523 ppdcVariable
*set_variable(const char *name
, const char *value
);
524 int write_file(const char *f
);