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