]> git.ipfire.org Git - thirdparty/cups.git/blame - ppdc/ppdc.h
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / ppdc / ppdc.h
CommitLineData
ac884b6a 1//
503b54c9 2// Definitions for the CUPS PPD Compiler.
ac884b6a 3//
503b54c9
MS
4// Copyright 2007-2009 by Apple Inc.
5// Copyright 2002-2007 by Easy Software Products.
ac884b6a 6//
503b54c9
MS
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
57b7b66b 11// missing or damaged, see the license at "http://www.cups.org/".
ac884b6a
MS
12//
13
14#ifndef _PPDC_H_
15# define _PPDC_H_
16
17//
18// Include necessary headers...
19//
20
ac884b6a
MS
21# include <cups/file.h>
22# include <stdlib.h>
ac884b6a
MS
23
24
94da7e34
MS
25//
26// Macros...
27//
28
38e73f87 29# define PPDC_NAME(s) const char *class_name() { return (s); }
94da7e34
MS
30
31
ac884b6a
MS
32//
33// Enumerations...
34//
35
36enum ppdcDrvType //// Driver type
37{
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
46};
47
48enum ppdcFontStatus //// Load status of font
49{
50 PPDC_FONT_ROM, // Font is in ROM
51 PPDC_FONT_DISK // Font is on disk
52};
53
54enum ppdcOptSection //// Option section
55{
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
62};
63
64enum ppdcOptType //// Option type
65{
66 PPDC_BOOLEAN, // True/false option
67 PPDC_PICKONE, // Single choice from list
68 PPDC_PICKMANY // Multiple choices from list
69};
70
71enum ppdcLineEnding //// Line endings
72{
73 PPDC_LFONLY, // LF only
74 PPDC_CRONLY, // CR only
75 PPDC_CRLF // CR + LF
76};
77
bdd6c45b
MS
78enum ppdcCondFlags //// Condition flags
79{
80 PPDC_COND_NORMAL = 0, // Normal state
81 PPDC_COND_SKIP = 1, // Skip state
82 PPDC_COND_SATISFIED = 2 // At least one condition satisfied
83};
84
ac884b6a
MS
85
86//
87// Printer description data...
88//
89
90class ppdcShared //// Shared Data Value
91{
92 private:
93
94 int use; // Use count (delete when 0)
95
96 public:
97
98 ppdcShared();
99 virtual ~ppdcShared();
100
94da7e34 101 virtual const char *class_name() = 0;
94da7e34 102
e4572d57
MS
103 void retain();
104 void release();
ac884b6a
MS
105};
106
107class ppdcArray //// Shared Array
108 : public ppdcShared
109{
110 public:
111
112 int count, // Number of elements
113 alloc, // Allocated elements
114 current; // Current element
115 ppdcShared **data; // Elements
116
117 ppdcArray(ppdcArray *a = 0);
118 ~ppdcArray();
119
94da7e34
MS
120 PPDC_NAME("ppdcArray")
121
ac884b6a
MS
122 void add(ppdcShared *d);
123 ppdcShared *first();
124 ppdcShared *next();
125 void remove(ppdcShared *d);
126};
127
128class ppdcString //// Shared String
129 : public ppdcShared
130{
131 public:
132
133 char *value; // String value
134
135 ppdcString(const char *v);
136 ~ppdcString();
94da7e34
MS
137
138 PPDC_NAME("ppdcString")
ac884b6a
MS
139};
140
141class ppdcInteger //// Shared integer
142 : public ppdcShared
143{
144 public:
145
146 int *value; // Integer value
147
148 ppdcInteger(int *v) { value = v; }
94da7e34
MS
149
150 PPDC_NAME("ppdcInteger")
ac884b6a
MS
151};
152
153class ppdcMessage //// Translation message
154 : public ppdcShared
155{
156 public:
157
158 ppdcString *id, // Translation ID
159 *string; // Translation string
160
161 ppdcMessage(const char *i, const char *s);
162 ~ppdcMessage();
94da7e34
MS
163
164 PPDC_NAME("ppdcMessage")
ac884b6a
MS
165};
166
167class ppdcCatalog //// Translation catalog
168 : public ppdcShared
169{
170 public:
171
172 ppdcString *locale; // Name of locale
173 ppdcString *filename; // Name of translation file
174 ppdcArray *messages; // Array of translation messages
175
176 ppdcCatalog(const char *l, const char *f = 0);
177 ~ppdcCatalog();
178
94da7e34
MS
179 PPDC_NAME("ppdcCatalog")
180
61cf44e2 181 void add_message(const char *id, const char *string = NULL);
ac884b6a
MS
182 const char *find_message(const char *id);
183 int load_messages(const char *f);
184 int save_messages(const char *f);
185};
186
187class ppdcAttr //// Attribute
188 : public ppdcShared
189{
190 public:
191
192 ppdcString *name, // Name of attribute
193 *selector, // Selector string
194 *text, // Text string
195 *value; // Value string
bdd6c45b 196 bool localizable; // Should this attribute be localized?
ac884b6a 197
bdd6c45b
MS
198 ppdcAttr(const char *n, const char *s, const char *t, const char *v,
199 bool loc = false);
ac884b6a 200 ~ppdcAttr();
94da7e34
MS
201
202 PPDC_NAME("ppdcAttr")
ac884b6a
MS
203};
204
205class ppdcFont //// Shared Font
206 : public ppdcShared
207{
208 public:
209
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)
215
216 ppdcFont(const char *n, const char *e, const char *v, const char *c,
217 ppdcFontStatus s);
218 ~ppdcFont();
94da7e34
MS
219
220 PPDC_NAME("ppdcFont")
ac884b6a
MS
221};
222
223class ppdcChoice //// Option Choice
224 : public ppdcShared
225{
226 public:
227
228 ppdcString *name, // Name of choice
229 *text, // Human-readable text of choice
230 *code; // PS code of choice
231
232 ppdcChoice(const char *n, const char *t, const char *c);
233 ~ppdcChoice();
94da7e34
MS
234
235 PPDC_NAME("ppdcChoice")
ac884b6a
MS
236};
237
238class ppdcOption //// Option
239 : public ppdcShared
240{
241 public:
242
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
250
251 ppdcOption(ppdcOptType ot, const char *n, const char *t, ppdcOptSection s,
252 float o);
253 ppdcOption(ppdcOption *o);
254 ~ppdcOption();
255
94da7e34
MS
256 PPDC_NAME("ppdcOption")
257
ac884b6a
MS
258 void add_choice(ppdcChoice *c) { choices->add(c); }
259 ppdcChoice *find_choice(const char *n);
260 void set_defchoice(ppdcChoice *c);
261};
262
263class ppdcGroup //// Group of Options
264 : public ppdcShared
265{
266 public:
267
268 ppdcString *name, // Name of option
269 *text; // Human-readable text of option
270 ppdcArray *options; // Options
271
272 ppdcGroup(const char *n, const char *t);
273 ppdcGroup(ppdcGroup *g);
274 ~ppdcGroup();
275
94da7e34
MS
276 PPDC_NAME("ppdcGroup")
277
ac884b6a
MS
278 void add_option(ppdcOption *o) { options->add(o); }
279 ppdcOption *find_option(const char *n);
280};
281
282class ppdcConstraint //// Constraint
283 : public ppdcShared
284{
285 public:
286
287 ppdcString *option1, // First option
288 *choice1, // First choice
289 *option2, // Second option
290 *choice2; // Second choice
291
292 ppdcConstraint(const char *o1, const char *c1, const char *o2,
293 const char *c2);
294 ~ppdcConstraint();
94da7e34
MS
295
296 PPDC_NAME("ppdcConstraint")
ac884b6a
MS
297};
298
299class ppdcFilter //// Filter Program
300 : public ppdcShared
301{
302 public:
303
304 ppdcString *mime_type, // MIME type
305 *program; // Filter program
306 int cost; // Relative cost of filter
307
308 ppdcFilter(const char *t, const char *p, int c);
309 ~ppdcFilter();
94da7e34
MS
310
311 PPDC_NAME("ppdcFilter")
ac884b6a
MS
312};
313
314class ppdcMediaSize //// Media Size
315 : public ppdcShared
316{
317 public:
318
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
329
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);
333 ~ppdcMediaSize();
94da7e34
MS
334
335 PPDC_NAME("ppdcMediaSize")
ac884b6a
MS
336};
337
338class ppdcProfile //// Color Profile
339 : public ppdcShared
340{
341 public:
342
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
348
349 ppdcProfile(const char *r, const char *m, float d, float g, const float *p);
350 ~ppdcProfile();
94da7e34
MS
351
352 PPDC_NAME("ppdcProfile")
ac884b6a
MS
353};
354
355class ppdcSource;
356
357class ppdcDriver //// Printer Driver Data
358 : public ppdcShared
359{
360 public:
361
362 ppdcDrvType type; // Driver type
363 ppdcArray *copyright; // Copyright strings
364 ppdcString *manufacturer, // Manufacturer
365 *model_name, // Name of printer model
bdd6c45b 366 *file_name, // Output filename for PPD
ac884b6a
MS
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
375 *filters, // Filters
376 *fonts, // Fonts
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
385 bottom_margin,
386 right_margin,
387 top_margin,
388 max_width, // Maximum width (points)
389 max_length, // Maximum length (points)
390 min_width, // Minimum width (points)
391 min_length; // Minimum length (points)
392
393 ppdcDriver(ppdcDriver *d = 0);
394 ~ppdcDriver();
395
94da7e34
MS
396 PPDC_NAME("ppdcDriver")
397
ac884b6a
MS
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));
402 }
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); }
408
409 ppdcAttr *find_attr(const char *k, const char *s);
410 ppdcGroup *find_group(const char *n);
411 ppdcOption *find_option(const char *n);
97c9a8d7 412 ppdcOption *find_option_group(const char *n, ppdcGroup **mg);
ac884b6a
MS
413
414 void set_custom_size_code(const char *c);
415 void set_default_font(ppdcFont *f);
416 void set_default_size(ppdcMediaSize *m);
bdd6c45b 417 void set_file_name(const char *f);
ac884b6a
MS
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);
422
423 int write_ppd_file(cups_file_t *fp, ppdcCatalog *catalog,
424 ppdcArray *locales, ppdcSource *src,
425 ppdcLineEnding le);
426};
427
428class ppdcVariable //// Variable Definition
429 : public ppdcShared
430{
431 public:
432
433 ppdcString *name, // Name of variable
434 *value; // Value of variable
435
436 ppdcVariable(const char *n, const char *v);
437 ~ppdcVariable();
438
94da7e34
MS
439 PPDC_NAME("ppdcVariable")
440
ac884b6a
MS
441 void set_value(const char *v);
442};
443
444class ppdcFile //// File
445{
446 public:
447
82cc1f9a 448 bool close_on_delete; // Close file on delete?
ac884b6a
MS
449 cups_file_t *fp; // File pointer
450 const char *filename; // Filename
451 int line; // Line in file
452
4509bb49 453 ppdcFile(const char *f, cups_file_t *ffp = (cups_file_t *)0);
ac884b6a
MS
454 ~ppdcFile();
455
456 int get();
457 int peek();
458};
459
460class ppdcSource //// Source File
461 : public ppdcShared
462{
463 public:
464
465 static ppdcArray *includes; // Include directories
466 static const char *driver_types[]; // Driver types
467
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
bdd6c45b
MS
474 int cond_state, // Cummulative conditional state
475 *cond_current, // Current #if state
476 cond_stack[101]; // #if state stack
477
ac884b6a 478
4509bb49 479 ppdcSource(const char *f = 0, cups_file_t *ffp = (cups_file_t *)0);
ac884b6a
MS
480 ~ppdcSource();
481
94da7e34
MS
482 PPDC_NAME("ppdcSource")
483
ac884b6a
MS
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,
487 int nlen);
488 ppdcCatalog *find_po(const char *l);
489 ppdcMediaSize *find_size(const char *s);
490 ppdcVariable *find_variable(const char *n);
bdd6c45b 491 ppdcAttr *get_attr(ppdcFile *fp, bool loc = false);
ac884b6a
MS
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, ...);
4509bb49 520 void read_file(const char *f, cups_file_t *ffp = (cups_file_t *)0);
ac884b6a
MS
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);
524};
525
526
527#endif // !_PPDC_H_