]> git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc.h
Merge changes from CUPS 1.4svn-r8469.
[thirdparty/cups.git] / ppdc / ppdc.h
1 //
2 // "$Id$"
3 //
4 // Definitions for the CUPS PPD Compiler.
5 //
6 // Copyright 2007-2008 by Apple Inc.
7 // Copyright 2002-2007 by Easy Software Products.
8 //
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/".
14 //
15
16 #ifndef _PPDC_H_
17 # define _PPDC_H_
18
19 //
20 // Include necessary headers...
21 //
22
23 # include <cups/string.h>
24
25 # include <cups/file.h>
26 # include <stdlib.h>
27 # include <errno.h>
28
29
30 //
31 // Macros...
32 //
33
34 # ifdef DEBUG
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())
39 # else
40 # define PPDC_NAME(s)
41 # define PPDC_NEW
42 # define PPDC_NEWVAL(s)
43 # define PPDC_DELETE
44 # endif // DEBUG
45
46
47 //
48 // Enumerations...
49 //
50
51 enum ppdcDrvType //// Driver type
52 {
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
61 };
62
63 enum ppdcFontStatus //// Load status of font
64 {
65 PPDC_FONT_ROM, // Font is in ROM
66 PPDC_FONT_DISK // Font is on disk
67 };
68
69 enum ppdcOptSection //// Option section
70 {
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
77 };
78
79 enum ppdcOptType //// Option type
80 {
81 PPDC_BOOLEAN, // True/false option
82 PPDC_PICKONE, // Single choice from list
83 PPDC_PICKMANY // Multiple choices from list
84 };
85
86 enum ppdcLineEnding //// Line endings
87 {
88 PPDC_LFONLY, // LF only
89 PPDC_CRONLY, // CR only
90 PPDC_CRLF // CR + LF
91 };
92
93 enum ppdcCondFlags //// Condition flags
94 {
95 PPDC_COND_NORMAL = 0, // Normal state
96 PPDC_COND_SKIP = 1, // Skip state
97 PPDC_COND_SATISFIED = 2 // At least one condition satisfied
98 };
99
100
101 //
102 // Printer description data...
103 //
104
105 class ppdcShared //// Shared Data Value
106 {
107 private:
108
109 int use; // Use count (delete when 0)
110
111 public:
112
113 ppdcShared();
114 virtual ~ppdcShared();
115
116 # ifdef DEBUG
117 virtual const char *class_name() = 0;
118 # endif // DEBUG
119
120 void retain();
121 void release();
122 };
123
124 class ppdcArray //// Shared Array
125 : public ppdcShared
126 {
127 public:
128
129 int count, // Number of elements
130 alloc, // Allocated elements
131 current; // Current element
132 ppdcShared **data; // Elements
133
134 ppdcArray(ppdcArray *a = 0);
135 ~ppdcArray();
136
137 PPDC_NAME("ppdcArray")
138
139 void add(ppdcShared *d);
140 ppdcShared *first();
141 ppdcShared *next();
142 void remove(ppdcShared *d);
143 };
144
145 class ppdcString //// Shared String
146 : public ppdcShared
147 {
148 public:
149
150 char *value; // String value
151
152 ppdcString(const char *v);
153 ~ppdcString();
154
155 PPDC_NAME("ppdcString")
156 };
157
158 class ppdcInteger //// Shared integer
159 : public ppdcShared
160 {
161 public:
162
163 int *value; // Integer value
164
165 ppdcInteger(int *v) { value = v; }
166
167 PPDC_NAME("ppdcInteger")
168 };
169
170 class ppdcMessage //// Translation message
171 : public ppdcShared
172 {
173 public:
174
175 ppdcString *id, // Translation ID
176 *string; // Translation string
177
178 ppdcMessage(const char *i, const char *s);
179 ~ppdcMessage();
180
181 PPDC_NAME("ppdcMessage")
182 };
183
184 class ppdcCatalog //// Translation catalog
185 : public ppdcShared
186 {
187 public:
188
189 ppdcString *locale; // Name of locale
190 ppdcString *filename; // Name of translation file
191 ppdcArray *messages; // Array of translation messages
192
193 ppdcCatalog(const char *l, const char *f = 0);
194 ~ppdcCatalog();
195
196 PPDC_NAME("ppdcCatalog")
197
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);
202 };
203
204 class ppdcAttr //// Attribute
205 : public ppdcShared
206 {
207 public:
208
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?
214
215 ppdcAttr(const char *n, const char *s, const char *t, const char *v,
216 bool loc = false);
217 ~ppdcAttr();
218
219 PPDC_NAME("ppdcAttr")
220 };
221
222 class ppdcFont //// Shared Font
223 : public ppdcShared
224 {
225 public:
226
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)
232
233 ppdcFont(const char *n, const char *e, const char *v, const char *c,
234 ppdcFontStatus s);
235 ~ppdcFont();
236
237 PPDC_NAME("ppdcFont")
238 };
239
240 class ppdcChoice //// Option Choice
241 : public ppdcShared
242 {
243 public:
244
245 ppdcString *name, // Name of choice
246 *text, // Human-readable text of choice
247 *code; // PS code of choice
248
249 ppdcChoice(const char *n, const char *t, const char *c);
250 ~ppdcChoice();
251
252 PPDC_NAME("ppdcChoice")
253 };
254
255 class ppdcOption //// Option
256 : public ppdcShared
257 {
258 public:
259
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
267
268 ppdcOption(ppdcOptType ot, const char *n, const char *t, ppdcOptSection s,
269 float o);
270 ppdcOption(ppdcOption *o);
271 ~ppdcOption();
272
273 PPDC_NAME("ppdcOption")
274
275 void add_choice(ppdcChoice *c) { choices->add(c); }
276 ppdcChoice *find_choice(const char *n);
277 void set_defchoice(ppdcChoice *c);
278 };
279
280 class ppdcGroup //// Group of Options
281 : public ppdcShared
282 {
283 public:
284
285 ppdcString *name, // Name of option
286 *text; // Human-readable text of option
287 ppdcArray *options; // Options
288
289 ppdcGroup(const char *n, const char *t);
290 ppdcGroup(ppdcGroup *g);
291 ~ppdcGroup();
292
293 PPDC_NAME("ppdcGroup")
294
295 void add_option(ppdcOption *o) { options->add(o); }
296 ppdcOption *find_option(const char *n);
297 };
298
299 class ppdcConstraint //// Constraint
300 : public ppdcShared
301 {
302 public:
303
304 ppdcString *option1, // First option
305 *choice1, // First choice
306 *option2, // Second option
307 *choice2; // Second choice
308
309 ppdcConstraint(const char *o1, const char *c1, const char *o2,
310 const char *c2);
311 ~ppdcConstraint();
312
313 PPDC_NAME("ppdcConstraint")
314 };
315
316 class ppdcFilter //// Filter Program
317 : public ppdcShared
318 {
319 public:
320
321 ppdcString *mime_type, // MIME type
322 *program; // Filter program
323 int cost; // Relative cost of filter
324
325 ppdcFilter(const char *t, const char *p, int c);
326 ~ppdcFilter();
327
328 PPDC_NAME("ppdcFilter")
329 };
330
331 class ppdcMediaSize //// Media Size
332 : public ppdcShared
333 {
334 public:
335
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
346
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);
350 ~ppdcMediaSize();
351
352 PPDC_NAME("ppdcMediaSize")
353 };
354
355 class ppdcProfile //// Color Profile
356 : public ppdcShared
357 {
358 public:
359
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
365
366 ppdcProfile(const char *r, const char *m, float d, float g, const float *p);
367 ~ppdcProfile();
368
369 PPDC_NAME("ppdcProfile")
370 };
371
372 class ppdcSource;
373
374 class ppdcDriver //// Printer Driver Data
375 : public ppdcShared
376 {
377 public:
378
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
392 *filters, // Filters
393 *fonts, // Fonts
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
402 bottom_margin,
403 right_margin,
404 top_margin,
405 max_width, // Maximum width (points)
406 max_length, // Maximum length (points)
407 min_width, // Minimum width (points)
408 min_length; // Minimum length (points)
409
410 ppdcDriver(ppdcDriver *d = 0);
411 ~ppdcDriver();
412
413 PPDC_NAME("ppdcDriver")
414
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));
419 }
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); }
425
426 ppdcAttr *find_attr(const char *k, const char *s);
427 ppdcGroup *find_group(const char *n);
428 ppdcOption *find_option(const char *n);
429
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);
438
439 int write_ppd_file(cups_file_t *fp, ppdcCatalog *catalog,
440 ppdcArray *locales, ppdcSource *src,
441 ppdcLineEnding le);
442 };
443
444 class ppdcVariable //// Variable Definition
445 : public ppdcShared
446 {
447 public:
448
449 ppdcString *name, // Name of variable
450 *value; // Value of variable
451
452 ppdcVariable(const char *n, const char *v);
453 ~ppdcVariable();
454
455 PPDC_NAME("ppdcVariable")
456
457 void set_value(const char *v);
458 };
459
460 class ppdcFile //// File
461 {
462 public:
463
464 cups_file_t *fp; // File pointer
465 const char *filename; // Filename
466 int line; // Line in file
467
468 ppdcFile(const char *f, cups_file_t *ffp = (cups_file_t *)0);
469 ~ppdcFile();
470
471 int get();
472 int peek();
473 };
474
475 class ppdcSource //// Source File
476 : public ppdcShared
477 {
478 public:
479
480 static ppdcArray *includes; // Include directories
481 static const char *driver_types[]; // Driver types
482
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
492
493
494 ppdcSource(const char *f = 0, cups_file_t *ffp = (cups_file_t *)0);
495 ~ppdcSource();
496
497 PPDC_NAME("ppdcSource")
498
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,
502 int nlen);
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);
539 };
540
541
542 #endif // !_PPDC_H_
543
544 //
545 // End of "$Id$".
546 //