]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc.h
2 // Definitions for the CUPS PPD Compiler.
4 // Copyright 2007-2009 by Apple Inc.
5 // Copyright 2002-2007 by Easy Software Products.
7 // These coded instructions, statements, and computer programs are the
8 // property of Apple Inc. and are protected by Federal copyright
9 // law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 // which should have been included with this file. If this file is
11 // file is missing or damaged, see the license at "http://www.cups.org/".
18 // Include necessary headers...
21 # include <cups/file.h>
29 # define PPDC_NAME(s) const char *class_name() { return (s); }
36 enum ppdcDrvType
//// Driver type
38 PPDC_DRIVER_CUSTOM
, // Custom driver
39 PPDC_DRIVER_PS
, // PostScript driver
40 PPDC_DRIVER_ESCP
, // rastertoescpx driver
41 PPDC_DRIVER_PCL
, // rastertopclx driver
42 PPDC_DRIVER_LABEL
, // rastertolabel/rastertodymo driver
43 PPDC_DRIVER_EPSON
, // rastertoepson driver
44 PPDC_DRIVER_HP
, // rastertohp driver
45 PPDC_DRIVER_MAX
// Number of driver types defined
48 enum ppdcFontStatus
//// Load status of font
50 PPDC_FONT_ROM
, // Font is in ROM
51 PPDC_FONT_DISK
// Font is on disk
54 enum ppdcOptSection
//// Option section
56 PPDC_SECTION_ANY
, // AnySetup
57 PPDC_SECTION_DOCUMENT
, // DocumentSetup
58 PPDC_SECTION_EXIT
, // ExitServer
59 PPDC_SECTION_JCL
, // JCLSetup
60 PPDC_SECTION_PAGE
, // PageSetup
61 PPDC_SECTION_PROLOG
// Prolog
64 enum ppdcOptType
//// Option type
66 PPDC_BOOLEAN
, // True/false option
67 PPDC_PICKONE
, // Single choice from list
68 PPDC_PICKMANY
// Multiple choices from list
71 enum ppdcLineEnding
//// Line endings
73 PPDC_LFONLY
, // LF only
74 PPDC_CRONLY
, // CR only
78 enum ppdcCondFlags
//// Condition flags
80 PPDC_COND_NORMAL
= 0, // Normal state
81 PPDC_COND_SKIP
= 1, // Skip state
82 PPDC_COND_SATISFIED
= 2 // At least one condition satisfied
87 // Printer description data...
90 class ppdcShared
//// Shared Data Value
94 int use
; // Use count (delete when 0)
99 virtual ~ppdcShared();
101 virtual const char *class_name() = 0;
107 class ppdcArray
//// Shared Array
112 int count
, // Number of elements
113 alloc
, // Allocated elements
114 current
; // Current element
115 ppdcShared
**data
; // Elements
117 ppdcArray(ppdcArray
*a
= 0);
120 PPDC_NAME("ppdcArray")
122 void add(ppdcShared
*d
);
125 void remove(ppdcShared
*d
);
128 class ppdcString
//// Shared String
133 char *value
; // String value
135 ppdcString(const char *v
);
138 PPDC_NAME("ppdcString")
141 class ppdcInteger
//// Shared integer
146 int *value
; // Integer value
148 ppdcInteger(int *v
) { value
= v
; }
150 PPDC_NAME("ppdcInteger")
153 class ppdcMessage
//// Translation message
158 ppdcString
*id
, // Translation ID
159 *string
; // Translation string
161 ppdcMessage(const char *i
, const char *s
);
164 PPDC_NAME("ppdcMessage")
167 class ppdcCatalog
//// Translation catalog
172 ppdcString
*locale
; // Name of locale
173 ppdcString
*filename
; // Name of translation file
174 ppdcArray
*messages
; // Array of translation messages
176 ppdcCatalog(const char *l
, const char *f
= 0);
179 PPDC_NAME("ppdcCatalog")
181 void add_message(const char *id
, const char *string
= NULL
);
182 const char *find_message(const char *id
);
183 int load_messages(const char *f
);
184 int save_messages(const char *f
);
187 class ppdcAttr
//// Attribute
192 ppdcString
*name
, // Name of attribute
193 *selector
, // Selector string
194 *text
, // Text string
195 *value
; // Value string
196 bool localizable
; // Should this attribute be localized?
198 ppdcAttr(const char *n
, const char *s
, const char *t
, const char *v
,
202 PPDC_NAME("ppdcAttr")
205 class ppdcFont
//// Shared Font
210 ppdcString
*name
, // Font name
211 *encoding
, // Font base encoding
212 *version
, // Font version
213 *charset
; // Font charset
214 ppdcFontStatus status
; // Font status (ROM or Disk)
216 ppdcFont(const char *n
, const char *e
, const char *v
, const char *c
,
220 PPDC_NAME("ppdcFont")
223 class ppdcChoice
//// Option Choice
228 ppdcString
*name
, // Name of choice
229 *text
, // Human-readable text of choice
230 *code
; // PS code of choice
232 ppdcChoice(const char *n
, const char *t
, const char *c
);
235 PPDC_NAME("ppdcChoice")
238 class ppdcOption
//// Option
243 ppdcOptType type
; // Type of option
244 ppdcString
*name
, // Name of option
245 *text
; // Human-readable text of option
246 ppdcOptSection section
; // Section for option code
247 float order
; // Order number
248 ppdcArray
*choices
; // Choices
249 ppdcString
*defchoice
; // Default choice
251 ppdcOption(ppdcOptType ot
, const char *n
, const char *t
, ppdcOptSection s
,
253 ppdcOption(ppdcOption
*o
);
256 PPDC_NAME("ppdcOption")
258 void add_choice(ppdcChoice
*c
) { choices
->add(c
); }
259 ppdcChoice
*find_choice(const char *n
);
260 void set_defchoice(ppdcChoice
*c
);
263 class ppdcGroup
//// Group of Options
268 ppdcString
*name
, // Name of option
269 *text
; // Human-readable text of option
270 ppdcArray
*options
; // Options
272 ppdcGroup(const char *n
, const char *t
);
273 ppdcGroup(ppdcGroup
*g
);
276 PPDC_NAME("ppdcGroup")
278 void add_option(ppdcOption
*o
) { options
->add(o
); }
279 ppdcOption
*find_option(const char *n
);
282 class ppdcConstraint
//// Constraint
287 ppdcString
*option1
, // First option
288 *choice1
, // First choice
289 *option2
, // Second option
290 *choice2
; // Second choice
292 ppdcConstraint(const char *o1
, const char *c1
, const char *o2
,
296 PPDC_NAME("ppdcConstraint")
299 class ppdcFilter
//// Filter Program
304 ppdcString
*mime_type
, // MIME type
305 *program
; // Filter program
306 int cost
; // Relative cost of filter
308 ppdcFilter(const char *t
, const char *p
, int c
);
311 PPDC_NAME("ppdcFilter")
314 class ppdcMediaSize
//// Media Size
319 ppdcString
*name
, // Name of size
320 *text
; // Human-readable text
321 float width
, // Width in points
322 length
, // Length in points
323 left
, // Left limit in points
324 bottom
, // Bottom limit in points
325 right
, // Right limit in points
326 top
; // Top limit in points
327 ppdcString
*size_code
, // PageSize code, if any
328 *region_code
; // PageRegion code, if any
330 ppdcMediaSize(const char *n
, const char *t
, float w
, float l
,
331 float lm
, float bm
, float rm
, float tm
,
332 const char *sc
= 0, const char *rc
= 0);
335 PPDC_NAME("ppdcMediaSize")
338 class ppdcProfile
//// Color Profile
343 ppdcString
*resolution
, // Resolution name
344 *media_type
; // Media type name
345 float density
, // Color profile density
346 gamma
, // Color profile gamma
347 profile
[9]; // Color profile matrix
349 ppdcProfile(const char *r
, const char *m
, float d
, float g
, const float *p
);
352 PPDC_NAME("ppdcProfile")
357 class ppdcDriver
//// Printer Driver Data
362 ppdcDrvType type
; // Driver type
363 ppdcArray
*copyright
; // Copyright strings
364 ppdcString
*manufacturer
, // Manufacturer
365 *model_name
, // Name of printer model
366 *file_name
, // Output filename for PPD
367 *pc_file_name
, // 8 character PC filename for PPD
368 *version
; // Version number
369 int model_number
, // Model number for driver
370 manual_copies
, // Do manual copies?
371 color_device
, // Support color?
372 throughput
; // Throughput in pages per minute
373 ppdcArray
*attrs
, // Attributes
374 *constraints
, // Constraints
377 *groups
, // Option groups
378 *profiles
, // Color profiles
379 *sizes
; // Fixed sizes
380 ppdcString
*default_font
, // Default font
381 *default_size
; // Default size option
382 int variable_paper_size
; // Support variable sizes?
383 ppdcString
*custom_size_code
; // Custom page size code, if any
384 float left_margin
, // Margins for device in points
388 max_width
, // Maximum width (points)
389 max_length
, // Maximum length (points)
390 min_width
, // Minimum width (points)
391 min_length
; // Minimum length (points)
393 ppdcDriver(ppdcDriver
*d
= 0);
396 PPDC_NAME("ppdcDriver")
398 void add_attr(ppdcAttr
*a
) { attrs
->add(a
); }
399 void add_constraint(ppdcConstraint
*c
) { constraints
->add(c
); }
400 void add_copyright(const char *c
) {
401 copyright
->add(new ppdcString(c
));
403 void add_filter(ppdcFilter
*f
) { filters
->add(f
); }
404 void add_font(ppdcFont
*f
) { fonts
->add(f
); }
405 void add_group(ppdcGroup
*g
) { groups
->add(g
); }
406 void add_profile(ppdcProfile
*p
) { profiles
->add(p
); }
407 void add_size(ppdcMediaSize
*m
) { sizes
->add(m
); }
409 ppdcAttr
*find_attr(const char *k
, const char *s
);
410 ppdcGroup
*find_group(const char *n
);
411 ppdcOption
*find_option(const char *n
);
412 ppdcOption
*find_option_group(const char *n
, ppdcGroup
**mg
);
414 void set_custom_size_code(const char *c
);
415 void set_default_font(ppdcFont
*f
);
416 void set_default_size(ppdcMediaSize
*m
);
417 void set_file_name(const char *f
);
418 void set_manufacturer(const char *m
);
419 void set_model_name(const char *m
);
420 void set_pc_file_name(const char *f
);
421 void set_version(const char *v
);
423 int write_ppd_file(cups_file_t
*fp
, ppdcCatalog
*catalog
,
424 ppdcArray
*locales
, ppdcSource
*src
,
428 class ppdcVariable
//// Variable Definition
433 ppdcString
*name
, // Name of variable
434 *value
; // Value of variable
436 ppdcVariable(const char *n
, const char *v
);
439 PPDC_NAME("ppdcVariable")
441 void set_value(const char *v
);
444 class ppdcFile
//// File
448 bool close_on_delete
; // Close file on delete?
449 cups_file_t
*fp
; // File pointer
450 const char *filename
; // Filename
451 int line
; // Line in file
453 ppdcFile(const char *f
, cups_file_t
*ffp
= (cups_file_t
*)0);
460 class ppdcSource
//// Source File
465 static ppdcArray
*includes
; // Include directories
466 static const char *driver_types
[]; // Driver types
468 ppdcString
*filename
; // Filename
469 ppdcArray
*base_fonts
, // Base fonts
470 *drivers
, // Printer drivers
471 *po_files
, // Message catalogs
472 *sizes
, // Predefined media sizes
473 *vars
; // Defined variables
474 int cond_state
, // Cummulative conditional state
475 *cond_current
, // Current #if state
476 cond_stack
[101]; // #if state stack
479 ppdcSource(const char *f
= 0, cups_file_t
*ffp
= (cups_file_t
*)0);
482 PPDC_NAME("ppdcSource")
484 static void add_include(const char *d
);
485 ppdcDriver
*find_driver(const char *f
);
486 static char *find_include(const char *f
, const char *base
, char *n
,
488 ppdcCatalog
*find_po(const char *l
);
489 ppdcMediaSize
*find_size(const char *s
);
490 ppdcVariable
*find_variable(const char *n
);
491 ppdcAttr
*get_attr(ppdcFile
*fp
, bool loc
= false);
492 int get_boolean(ppdcFile
*fp
);
493 ppdcChoice
*get_choice(ppdcFile
*fp
);
494 ppdcChoice
*get_color_model(ppdcFile
*fp
);
495 int get_color_order(const char *co
);
496 ppdcProfile
*get_color_profile(ppdcFile
*fp
);
497 int get_color_space(const char *cs
);
498 ppdcConstraint
*get_constraint(ppdcFile
*fp
);
499 ppdcMediaSize
*get_custom_size(ppdcFile
*fp
);
500 void get_duplex(ppdcFile
*fp
, ppdcDriver
*d
);
501 ppdcFilter
*get_filter(ppdcFile
*fp
);
502 float get_float(ppdcFile
*fp
);
503 ppdcFont
*get_font(ppdcFile
*fp
);
504 ppdcChoice
*get_generic(ppdcFile
*fp
, const char *keyword
,
505 const char *tattr
, const char *nattr
);
506 ppdcGroup
*get_group(ppdcFile
*fp
, ppdcDriver
*d
);
507 ppdcOption
*get_installable(ppdcFile
*fp
);
508 int get_integer(const char *v
);
509 int get_integer(ppdcFile
*fp
);
510 float get_measurement(ppdcFile
*fp
);
511 ppdcOption
*get_option(ppdcFile
*fp
, ppdcDriver
*d
, ppdcGroup
*g
);
512 ppdcCatalog
*get_po(ppdcFile
*fp
);
513 ppdcChoice
*get_resolution(ppdcFile
*fp
);
514 ppdcProfile
*get_simple_profile(ppdcFile
*fp
);
515 ppdcMediaSize
*get_size(ppdcFile
*fp
);
516 char *get_token(ppdcFile
*fp
, char *buffer
, int buflen
);
517 ppdcVariable
*get_variable(ppdcFile
*fp
);
518 int import_ppd(const char *f
);
519 int quotef(cups_file_t
*fp
, const char *format
, ...);
520 void read_file(const char *f
, cups_file_t
*ffp
= (cups_file_t
*)0);
521 void scan_file(ppdcFile
*fp
, ppdcDriver
*td
= 0, bool inc
= false);
522 ppdcVariable
*set_variable(const char *name
, const char *value
);
523 int write_file(const char *f
);