]>
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>
34 enum ppdcDrvType
//// Driver type
36 PPDC_DRIVER_CUSTOM
, // Custom driver
37 PPDC_DRIVER_PS
, // PostScript driver
38 PPDC_DRIVER_ESCP
, // rastertoescpx driver
39 PPDC_DRIVER_PCL
, // rastertopclx driver
40 PPDC_DRIVER_LABEL
, // rastertolabel/rastertodymo driver
41 PPDC_DRIVER_EPSON
, // rastertoepson driver
42 PPDC_DRIVER_HP
, // rastertohp driver
43 PPDC_DRIVER_MAX
// Number of driver types defined
46 enum ppdcFontStatus
//// Load status of font
48 PPDC_FONT_ROM
, // Font is in ROM
49 PPDC_FONT_DISK
// Font is on disk
52 enum ppdcOptSection
//// Option section
54 PPDC_SECTION_ANY
, // AnySetup
55 PPDC_SECTION_DOCUMENT
, // DocumentSetup
56 PPDC_SECTION_EXIT
, // ExitServer
57 PPDC_SECTION_JCL
, // JCLSetup
58 PPDC_SECTION_PAGE
, // PageSetup
59 PPDC_SECTION_PROLOG
// Prolog
62 enum ppdcOptType
//// Option type
64 PPDC_BOOLEAN
, // True/false option
65 PPDC_PICKONE
, // Single choice from list
66 PPDC_PICKMANY
// Multiple choices from list
69 enum ppdcLineEnding
//// Line endings
71 PPDC_LFONLY
, // LF only
72 PPDC_CRONLY
, // CR only
76 enum ppdcCondFlags
//// Condition flags
78 PPDC_COND_NORMAL
= 0, // Normal state
79 PPDC_COND_SKIP
= 1, // Skip state
80 PPDC_COND_SATISFIED
= 2 // At least one condition satisfied
85 // Printer description data...
88 class ppdcShared
//// Shared Data Value
92 int use
; // Use count (delete when 0)
97 virtual ~ppdcShared();
103 class ppdcArray
//// Shared Array
108 int count
, // Number of elements
109 alloc
, // Allocated elements
110 current
; // Current element
111 ppdcShared
**data
; // Elements
113 ppdcArray(ppdcArray
*a
= 0);
116 void add(ppdcShared
*d
);
119 void remove(ppdcShared
*d
);
122 class ppdcString
//// Shared String
127 char *value
; // String value
129 ppdcString(const char *v
);
133 class ppdcInteger
//// Shared integer
138 int *value
; // Integer value
140 ppdcInteger(int *v
) { value
= v
; }
143 class ppdcMessage
//// Translation message
148 ppdcString
*id
, // Translation ID
149 *string
; // Translation string
151 ppdcMessage(const char *i
, const char *s
);
155 class ppdcCatalog
//// Translation catalog
160 ppdcString
*locale
; // Name of locale
161 ppdcString
*filename
; // Name of translation file
162 ppdcArray
*messages
; // Array of translation messages
164 ppdcCatalog(const char *l
, const char *f
= 0);
167 void add_message(const char *id
, const char *string
= NULL
);
168 const char *find_message(const char *id
);
169 int load_messages(const char *f
);
170 int save_messages(const char *f
);
173 class ppdcAttr
//// Attribute
178 ppdcString
*name
, // Name of attribute
179 *selector
, // Selector string
180 *text
, // Text string
181 *value
; // Value string
182 bool localizable
; // Should this attribute be localized?
184 ppdcAttr(const char *n
, const char *s
, const char *t
, const char *v
,
189 class ppdcFont
//// Shared Font
194 ppdcString
*name
, // Font name
195 *encoding
, // Font base encoding
196 *version
, // Font version
197 *charset
; // Font charset
198 ppdcFontStatus status
; // Font status (ROM or Disk)
200 ppdcFont(const char *n
, const char *e
, const char *v
, const char *c
,
205 class ppdcChoice
//// Option Choice
210 ppdcString
*name
, // Name of choice
211 *text
, // Human-readable text of choice
212 *code
; // PS code of choice
214 ppdcChoice(const char *n
, const char *t
, const char *c
);
218 class ppdcOption
//// Option
223 ppdcOptType type
; // Type of option
224 ppdcString
*name
, // Name of option
225 *text
; // Human-readable text of option
226 ppdcOptSection section
; // Section for option code
227 float order
; // Order number
228 ppdcArray
*choices
; // Choices
229 ppdcString
*defchoice
; // Default choice
231 ppdcOption(ppdcOptType ot
, const char *n
, const char *t
, ppdcOptSection s
,
233 ppdcOption(ppdcOption
*o
);
236 void add_choice(ppdcChoice
*c
) { choices
->add(c
); }
237 ppdcChoice
*find_choice(const char *n
);
238 void set_defchoice(ppdcChoice
*c
);
241 class ppdcGroup
//// Group of Options
246 ppdcString
*name
, // Name of option
247 *text
; // Human-readable text of option
248 ppdcArray
*options
; // Options
250 ppdcGroup(const char *n
, const char *t
);
251 ppdcGroup(ppdcGroup
*g
);
254 void add_option(ppdcOption
*o
) { options
->add(o
); }
255 ppdcOption
*find_option(const char *n
);
258 class ppdcConstraint
//// Constraint
263 ppdcString
*option1
, // First option
264 *choice1
, // First choice
265 *option2
, // Second option
266 *choice2
; // Second choice
268 ppdcConstraint(const char *o1
, const char *c1
, const char *o2
,
273 class ppdcFilter
//// Filter Program
278 ppdcString
*mime_type
, // MIME type
279 *program
; // Filter program
280 int cost
; // Relative cost of filter
282 ppdcFilter(const char *t
, const char *p
, int c
);
286 class ppdcMediaSize
//// Media Size
291 ppdcString
*name
, // Name of size
292 *text
; // Human-readable text
293 float width
, // Width in points
294 length
, // Length in points
295 left
, // Left limit in points
296 bottom
, // Bottom limit in points
297 right
, // Right limit in points
298 top
; // Top limit in points
299 ppdcString
*size_code
, // PageSize code, if any
300 *region_code
; // PageRegion code, if any
302 ppdcMediaSize(const char *n
, const char *t
, float w
, float l
,
303 float lm
, float bm
, float rm
, float tm
,
304 const char *sc
= 0, const char *rc
= 0);
308 class ppdcProfile
//// Color Profile
313 ppdcString
*resolution
, // Resolution name
314 *media_type
; // Media type name
315 float density
, // Color profile density
316 gamma
, // Color profile gamma
317 profile
[9]; // Color profile matrix
319 ppdcProfile(const char *r
, const char *m
, float d
, float g
, const float *p
);
325 class ppdcDriver
//// Printer Driver Data
330 ppdcDrvType type
; // Driver type
331 ppdcArray
*copyright
; // Copyright strings
332 ppdcString
*manufacturer
, // Manufacturer
333 *model_name
, // Name of printer model
334 *file_name
, // Output filename for PPD
335 *pc_file_name
, // 8 character PC filename for PPD
336 *version
; // Version number
337 int model_number
, // Model number for driver
338 manual_copies
, // Do manual copies?
339 color_device
, // Support color?
340 throughput
; // Throughput in pages per minute
341 ppdcArray
*attrs
, // Attributes
342 *constraints
, // Constraints
345 *groups
, // Option groups
346 *profiles
, // Color profiles
347 *sizes
; // Fixed sizes
348 ppdcString
*default_font
, // Default font
349 *default_size
; // Default size option
350 int variable_paper_size
; // Support variable sizes?
351 ppdcString
*custom_size_code
; // Custom page size code, if any
352 float left_margin
, // Margins for device in points
356 max_width
, // Maximum width (points)
357 max_length
, // Maximum length (points)
358 min_width
, // Minimum width (points)
359 min_length
; // Minimum length (points)
361 ppdcDriver(ppdcDriver
*d
= 0);
364 void add_attr(ppdcAttr
*a
) { attrs
->add(a
); }
365 void add_constraint(ppdcConstraint
*c
) { constraints
->add(c
); }
366 void add_copyright(const char *c
) {
367 copyright
->add(new ppdcString(c
));
369 void add_filter(ppdcFilter
*f
) { filters
->add(f
); }
370 void add_font(ppdcFont
*f
) { fonts
->add(f
); }
371 void add_group(ppdcGroup
*g
) { groups
->add(g
); }
372 void add_profile(ppdcProfile
*p
) { profiles
->add(p
); }
373 void add_size(ppdcMediaSize
*m
) { sizes
->add(m
); }
375 ppdcAttr
*find_attr(const char *k
, const char *s
);
376 ppdcGroup
*find_group(const char *n
);
377 ppdcOption
*find_option(const char *n
);
379 void set_custom_size_code(const char *c
);
380 void set_default_font(ppdcFont
*f
);
381 void set_default_size(ppdcMediaSize
*m
);
382 void set_file_name(const char *f
);
383 void set_manufacturer(const char *m
);
384 void set_model_name(const char *m
);
385 void set_pc_file_name(const char *f
);
386 void set_version(const char *v
);
388 int write_ppd_file(cups_file_t
*fp
, ppdcCatalog
*catalog
,
389 ppdcArray
*locales
, ppdcSource
*src
,
393 class ppdcVariable
//// Variable Definition
398 ppdcString
*name
, // Name of variable
399 *value
; // Value of variable
401 ppdcVariable(const char *n
, const char *v
);
404 void set_value(const char *v
);
407 class ppdcFile
//// File
411 cups_file_t
*fp
; // File pointer
412 const char *filename
; // Filename
413 int line
; // Line in file
415 ppdcFile(const char *f
, cups_file_t
*ffp
= (cups_file_t
*)0);
422 class ppdcSource
//// Source File
427 static ppdcArray
*includes
; // Include directories
428 static const char *driver_types
[]; // Driver types
430 ppdcString
*filename
; // Filename
431 ppdcArray
*base_fonts
, // Base fonts
432 *drivers
, // Printer drivers
433 *po_files
, // Message catalogs
434 *sizes
, // Predefined media sizes
435 *vars
; // Defined variables
436 int cond_state
, // Cummulative conditional state
437 *cond_current
, // Current #if state
438 cond_stack
[101]; // #if state stack
441 ppdcSource(const char *f
= 0, cups_file_t
*ffp
= (cups_file_t
*)0);
444 static void add_include(const char *d
);
445 ppdcDriver
*find_driver(const char *f
);
446 static char *find_include(const char *f
, const char *base
, char *n
,
448 ppdcCatalog
*find_po(const char *l
);
449 ppdcMediaSize
*find_size(const char *s
);
450 ppdcVariable
*find_variable(const char *n
);
451 ppdcAttr
*get_attr(ppdcFile
*fp
, bool loc
= false);
452 int get_boolean(ppdcFile
*fp
);
453 ppdcChoice
*get_choice(ppdcFile
*fp
);
454 ppdcChoice
*get_color_model(ppdcFile
*fp
);
455 int get_color_order(const char *co
);
456 ppdcProfile
*get_color_profile(ppdcFile
*fp
);
457 int get_color_space(const char *cs
);
458 ppdcConstraint
*get_constraint(ppdcFile
*fp
);
459 ppdcMediaSize
*get_custom_size(ppdcFile
*fp
);
460 void get_duplex(ppdcFile
*fp
, ppdcDriver
*d
);
461 ppdcFilter
*get_filter(ppdcFile
*fp
);
462 float get_float(ppdcFile
*fp
);
463 ppdcFont
*get_font(ppdcFile
*fp
);
464 ppdcChoice
*get_generic(ppdcFile
*fp
, const char *keyword
,
465 const char *tattr
, const char *nattr
);
466 ppdcGroup
*get_group(ppdcFile
*fp
, ppdcDriver
*d
);
467 ppdcOption
*get_installable(ppdcFile
*fp
);
468 int get_integer(const char *v
);
469 int get_integer(ppdcFile
*fp
);
470 float get_measurement(ppdcFile
*fp
);
471 ppdcOption
*get_option(ppdcFile
*fp
, ppdcDriver
*d
, ppdcGroup
*g
);
472 ppdcCatalog
*get_po(ppdcFile
*fp
);
473 ppdcChoice
*get_resolution(ppdcFile
*fp
);
474 ppdcProfile
*get_simple_profile(ppdcFile
*fp
);
475 ppdcMediaSize
*get_size(ppdcFile
*fp
);
476 char *get_token(ppdcFile
*fp
, char *buffer
, int buflen
);
477 ppdcVariable
*get_variable(ppdcFile
*fp
);
478 int import_ppd(const char *f
);
479 int quotef(cups_file_t
*fp
, const char *format
, ...);
480 void read_file(const char *f
, cups_file_t
*ffp
= (cups_file_t
*)0);
481 void scan_file(ppdcFile
*fp
, ppdcDriver
*td
= 0, bool inc
= false);
482 ppdcVariable
*set_variable(const char *name
, const char *value
);
483 int write_file(const char *f
);