]>
Commit | Line | Data |
---|---|---|
ac884b6a | 1 | // |
503b54c9 | 2 | // Definitions for the CUPS PPD Compiler. |
ac884b6a | 3 | // |
d3454c3e | 4 | // Copyright 2007-2019 by Apple Inc. |
503b54c9 | 5 | // Copyright 2002-2007 by Easy Software Products. |
ac884b6a | 6 | // |
e3101897 | 7 | // Licensed under Apache License v2.0. See the file "LICENSE" for more information. |
ac884b6a MS |
8 | // |
9 | ||
10 | #ifndef _PPDC_H_ | |
11 | # define _PPDC_H_ | |
12 | ||
13 | // | |
14 | // Include necessary headers... | |
15 | // | |
16 | ||
ac884b6a MS |
17 | # include <cups/file.h> |
18 | # include <stdlib.h> | |
ac884b6a MS |
19 | |
20 | ||
94da7e34 MS |
21 | // |
22 | // Macros... | |
23 | // | |
24 | ||
38e73f87 | 25 | # define PPDC_NAME(s) const char *class_name() { return (s); } |
94da7e34 MS |
26 | |
27 | ||
ac884b6a MS |
28 | // |
29 | // Enumerations... | |
30 | // | |
31 | ||
32 | enum ppdcDrvType //// Driver type | |
33 | { | |
34 | PPDC_DRIVER_CUSTOM, // Custom driver | |
35 | PPDC_DRIVER_PS, // PostScript driver | |
36 | PPDC_DRIVER_ESCP, // rastertoescpx driver | |
37 | PPDC_DRIVER_PCL, // rastertopclx driver | |
38 | PPDC_DRIVER_LABEL, // rastertolabel/rastertodymo driver | |
39 | PPDC_DRIVER_EPSON, // rastertoepson driver | |
40 | PPDC_DRIVER_HP, // rastertohp driver | |
41 | PPDC_DRIVER_MAX // Number of driver types defined | |
42 | }; | |
43 | ||
44 | enum ppdcFontStatus //// Load status of font | |
45 | { | |
46 | PPDC_FONT_ROM, // Font is in ROM | |
47 | PPDC_FONT_DISK // Font is on disk | |
48 | }; | |
49 | ||
50 | enum ppdcOptSection //// Option section | |
51 | { | |
52 | PPDC_SECTION_ANY, // AnySetup | |
53 | PPDC_SECTION_DOCUMENT, // DocumentSetup | |
54 | PPDC_SECTION_EXIT, // ExitServer | |
55 | PPDC_SECTION_JCL, // JCLSetup | |
56 | PPDC_SECTION_PAGE, // PageSetup | |
57 | PPDC_SECTION_PROLOG // Prolog | |
58 | }; | |
59 | ||
60 | enum ppdcOptType //// Option type | |
61 | { | |
62 | PPDC_BOOLEAN, // True/false option | |
63 | PPDC_PICKONE, // Single choice from list | |
64 | PPDC_PICKMANY // Multiple choices from list | |
65 | }; | |
66 | ||
67 | enum ppdcLineEnding //// Line endings | |
68 | { | |
69 | PPDC_LFONLY, // LF only | |
70 | PPDC_CRONLY, // CR only | |
71 | PPDC_CRLF // CR + LF | |
72 | }; | |
73 | ||
bdd6c45b MS |
74 | enum ppdcCondFlags //// Condition flags |
75 | { | |
76 | PPDC_COND_NORMAL = 0, // Normal state | |
77 | PPDC_COND_SKIP = 1, // Skip state | |
78 | PPDC_COND_SATISFIED = 2 // At least one condition satisfied | |
79 | }; | |
80 | ||
ac884b6a MS |
81 | |
82 | // | |
83 | // Printer description data... | |
84 | // | |
85 | ||
86 | class ppdcShared //// Shared Data Value | |
87 | { | |
88 | private: | |
89 | ||
90 | int use; // Use count (delete when 0) | |
91 | ||
92 | public: | |
93 | ||
94 | ppdcShared(); | |
95 | virtual ~ppdcShared(); | |
96 | ||
94da7e34 | 97 | virtual const char *class_name() = 0; |
94da7e34 | 98 | |
e4572d57 MS |
99 | void retain(); |
100 | void release(); | |
ac884b6a MS |
101 | }; |
102 | ||
103 | class ppdcArray //// Shared Array | |
104 | : public ppdcShared | |
105 | { | |
106 | public: | |
107 | ||
d3454c3e | 108 | size_t count, // Number of elements |
ac884b6a MS |
109 | alloc, // Allocated elements |
110 | current; // Current element | |
111 | ppdcShared **data; // Elements | |
112 | ||
113 | ppdcArray(ppdcArray *a = 0); | |
114 | ~ppdcArray(); | |
115 | ||
94da7e34 MS |
116 | PPDC_NAME("ppdcArray") |
117 | ||
ac884b6a MS |
118 | void add(ppdcShared *d); |
119 | ppdcShared *first(); | |
120 | ppdcShared *next(); | |
121 | void remove(ppdcShared *d); | |
122 | }; | |
123 | ||
124 | class ppdcString //// Shared String | |
125 | : public ppdcShared | |
126 | { | |
127 | public: | |
128 | ||
129 | char *value; // String value | |
130 | ||
131 | ppdcString(const char *v); | |
132 | ~ppdcString(); | |
94da7e34 MS |
133 | |
134 | PPDC_NAME("ppdcString") | |
ac884b6a MS |
135 | }; |
136 | ||
137 | class ppdcInteger //// Shared integer | |
138 | : public ppdcShared | |
139 | { | |
140 | public: | |
141 | ||
142 | int *value; // Integer value | |
143 | ||
144 | ppdcInteger(int *v) { value = v; } | |
94da7e34 MS |
145 | |
146 | PPDC_NAME("ppdcInteger") | |
ac884b6a MS |
147 | }; |
148 | ||
149 | class ppdcMessage //// Translation message | |
150 | : public ppdcShared | |
151 | { | |
152 | public: | |
153 | ||
154 | ppdcString *id, // Translation ID | |
155 | *string; // Translation string | |
156 | ||
157 | ppdcMessage(const char *i, const char *s); | |
158 | ~ppdcMessage(); | |
94da7e34 MS |
159 | |
160 | PPDC_NAME("ppdcMessage") | |
ac884b6a MS |
161 | }; |
162 | ||
163 | class ppdcCatalog //// Translation catalog | |
164 | : public ppdcShared | |
165 | { | |
166 | public: | |
167 | ||
168 | ppdcString *locale; // Name of locale | |
169 | ppdcString *filename; // Name of translation file | |
170 | ppdcArray *messages; // Array of translation messages | |
171 | ||
172 | ppdcCatalog(const char *l, const char *f = 0); | |
173 | ~ppdcCatalog(); | |
174 | ||
94da7e34 MS |
175 | PPDC_NAME("ppdcCatalog") |
176 | ||
61cf44e2 | 177 | void add_message(const char *id, const char *string = NULL); |
ac884b6a MS |
178 | const char *find_message(const char *id); |
179 | int load_messages(const char *f); | |
180 | int save_messages(const char *f); | |
181 | }; | |
182 | ||
183 | class ppdcAttr //// Attribute | |
184 | : public ppdcShared | |
185 | { | |
186 | public: | |
187 | ||
188 | ppdcString *name, // Name of attribute | |
189 | *selector, // Selector string | |
190 | *text, // Text string | |
191 | *value; // Value string | |
bdd6c45b | 192 | bool localizable; // Should this attribute be localized? |
ac884b6a | 193 | |
bdd6c45b MS |
194 | ppdcAttr(const char *n, const char *s, const char *t, const char *v, |
195 | bool loc = false); | |
ac884b6a | 196 | ~ppdcAttr(); |
94da7e34 MS |
197 | |
198 | PPDC_NAME("ppdcAttr") | |
ac884b6a MS |
199 | }; |
200 | ||
201 | class ppdcFont //// Shared Font | |
202 | : public ppdcShared | |
203 | { | |
204 | public: | |
205 | ||
206 | ppdcString *name, // Font name | |
207 | *encoding, // Font base encoding | |
208 | *version, // Font version | |
209 | *charset; // Font charset | |
210 | ppdcFontStatus status; // Font status (ROM or Disk) | |
211 | ||
212 | ppdcFont(const char *n, const char *e, const char *v, const char *c, | |
213 | ppdcFontStatus s); | |
214 | ~ppdcFont(); | |
94da7e34 MS |
215 | |
216 | PPDC_NAME("ppdcFont") | |
ac884b6a MS |
217 | }; |
218 | ||
219 | class ppdcChoice //// Option Choice | |
220 | : public ppdcShared | |
221 | { | |
222 | public: | |
223 | ||
224 | ppdcString *name, // Name of choice | |
225 | *text, // Human-readable text of choice | |
226 | *code; // PS code of choice | |
227 | ||
228 | ppdcChoice(const char *n, const char *t, const char *c); | |
229 | ~ppdcChoice(); | |
94da7e34 MS |
230 | |
231 | PPDC_NAME("ppdcChoice") | |
ac884b6a MS |
232 | }; |
233 | ||
234 | class ppdcOption //// Option | |
235 | : public ppdcShared | |
236 | { | |
237 | public: | |
238 | ||
239 | ppdcOptType type; // Type of option | |
240 | ppdcString *name, // Name of option | |
241 | *text; // Human-readable text of option | |
242 | ppdcOptSection section; // Section for option code | |
243 | float order; // Order number | |
244 | ppdcArray *choices; // Choices | |
245 | ppdcString *defchoice; // Default choice | |
246 | ||
247 | ppdcOption(ppdcOptType ot, const char *n, const char *t, ppdcOptSection s, | |
248 | float o); | |
249 | ppdcOption(ppdcOption *o); | |
250 | ~ppdcOption(); | |
251 | ||
94da7e34 MS |
252 | PPDC_NAME("ppdcOption") |
253 | ||
ac884b6a MS |
254 | void add_choice(ppdcChoice *c) { choices->add(c); } |
255 | ppdcChoice *find_choice(const char *n); | |
256 | void set_defchoice(ppdcChoice *c); | |
257 | }; | |
258 | ||
259 | class ppdcGroup //// Group of Options | |
260 | : public ppdcShared | |
261 | { | |
262 | public: | |
263 | ||
264 | ppdcString *name, // Name of option | |
265 | *text; // Human-readable text of option | |
266 | ppdcArray *options; // Options | |
267 | ||
268 | ppdcGroup(const char *n, const char *t); | |
269 | ppdcGroup(ppdcGroup *g); | |
270 | ~ppdcGroup(); | |
271 | ||
94da7e34 MS |
272 | PPDC_NAME("ppdcGroup") |
273 | ||
ac884b6a MS |
274 | void add_option(ppdcOption *o) { options->add(o); } |
275 | ppdcOption *find_option(const char *n); | |
276 | }; | |
277 | ||
278 | class ppdcConstraint //// Constraint | |
279 | : public ppdcShared | |
280 | { | |
281 | public: | |
282 | ||
283 | ppdcString *option1, // First option | |
284 | *choice1, // First choice | |
285 | *option2, // Second option | |
286 | *choice2; // Second choice | |
287 | ||
288 | ppdcConstraint(const char *o1, const char *c1, const char *o2, | |
289 | const char *c2); | |
290 | ~ppdcConstraint(); | |
94da7e34 MS |
291 | |
292 | PPDC_NAME("ppdcConstraint") | |
ac884b6a MS |
293 | }; |
294 | ||
295 | class ppdcFilter //// Filter Program | |
296 | : public ppdcShared | |
297 | { | |
298 | public: | |
299 | ||
300 | ppdcString *mime_type, // MIME type | |
301 | *program; // Filter program | |
302 | int cost; // Relative cost of filter | |
303 | ||
304 | ppdcFilter(const char *t, const char *p, int c); | |
305 | ~ppdcFilter(); | |
94da7e34 MS |
306 | |
307 | PPDC_NAME("ppdcFilter") | |
ac884b6a MS |
308 | }; |
309 | ||
310 | class ppdcMediaSize //// Media Size | |
311 | : public ppdcShared | |
312 | { | |
313 | public: | |
314 | ||
315 | ppdcString *name, // Name of size | |
316 | *text; // Human-readable text | |
317 | float width, // Width in points | |
318 | length, // Length in points | |
319 | left, // Left limit in points | |
320 | bottom, // Bottom limit in points | |
321 | right, // Right limit in points | |
322 | top; // Top limit in points | |
323 | ppdcString *size_code, // PageSize code, if any | |
324 | *region_code; // PageRegion code, if any | |
325 | ||
326 | ppdcMediaSize(const char *n, const char *t, float w, float l, | |
327 | float lm, float bm, float rm, float tm, | |
328 | const char *sc = 0, const char *rc = 0); | |
329 | ~ppdcMediaSize(); | |
94da7e34 MS |
330 | |
331 | PPDC_NAME("ppdcMediaSize") | |
ac884b6a MS |
332 | }; |
333 | ||
334 | class ppdcProfile //// Color Profile | |
335 | : public ppdcShared | |
336 | { | |
337 | public: | |
338 | ||
339 | ppdcString *resolution, // Resolution name | |
340 | *media_type; // Media type name | |
341 | float density, // Color profile density | |
342 | gamma, // Color profile gamma | |
343 | profile[9]; // Color profile matrix | |
344 | ||
345 | ppdcProfile(const char *r, const char *m, float d, float g, const float *p); | |
346 | ~ppdcProfile(); | |
94da7e34 MS |
347 | |
348 | PPDC_NAME("ppdcProfile") | |
ac884b6a MS |
349 | }; |
350 | ||
351 | class ppdcSource; | |
352 | ||
353 | class ppdcDriver //// Printer Driver Data | |
354 | : public ppdcShared | |
355 | { | |
356 | public: | |
357 | ||
358 | ppdcDrvType type; // Driver type | |
359 | ppdcArray *copyright; // Copyright strings | |
360 | ppdcString *manufacturer, // Manufacturer | |
361 | *model_name, // Name of printer model | |
bdd6c45b | 362 | *file_name, // Output filename for PPD |
ac884b6a MS |
363 | *pc_file_name, // 8 character PC filename for PPD |
364 | *version; // Version number | |
365 | int model_number, // Model number for driver | |
366 | manual_copies, // Do manual copies? | |
367 | color_device, // Support color? | |
368 | throughput; // Throughput in pages per minute | |
369 | ppdcArray *attrs, // Attributes | |
370 | *constraints, // Constraints | |
371 | *filters, // Filters | |
372 | *fonts, // Fonts | |
373 | *groups, // Option groups | |
374 | *profiles, // Color profiles | |
375 | *sizes; // Fixed sizes | |
376 | ppdcString *default_font, // Default font | |
377 | *default_size; // Default size option | |
378 | int variable_paper_size; // Support variable sizes? | |
379 | ppdcString *custom_size_code; // Custom page size code, if any | |
380 | float left_margin, // Margins for device in points | |
381 | bottom_margin, | |
382 | right_margin, | |
383 | top_margin, | |
384 | max_width, // Maximum width (points) | |
385 | max_length, // Maximum length (points) | |
386 | min_width, // Minimum width (points) | |
387 | min_length; // Minimum length (points) | |
388 | ||
389 | ppdcDriver(ppdcDriver *d = 0); | |
390 | ~ppdcDriver(); | |
391 | ||
94da7e34 MS |
392 | PPDC_NAME("ppdcDriver") |
393 | ||
ac884b6a MS |
394 | void add_attr(ppdcAttr *a) { attrs->add(a); } |
395 | void add_constraint(ppdcConstraint *c) { constraints->add(c); } | |
396 | void add_copyright(const char *c) { | |
397 | copyright->add(new ppdcString(c)); | |
398 | } | |
399 | void add_filter(ppdcFilter *f) { filters->add(f); } | |
400 | void add_font(ppdcFont *f) { fonts->add(f); } | |
401 | void add_group(ppdcGroup *g) { groups->add(g); } | |
402 | void add_profile(ppdcProfile *p) { profiles->add(p); } | |
403 | void add_size(ppdcMediaSize *m) { sizes->add(m); } | |
404 | ||
405 | ppdcAttr *find_attr(const char *k, const char *s); | |
406 | ppdcGroup *find_group(const char *n); | |
407 | ppdcOption *find_option(const char *n); | |
97c9a8d7 | 408 | ppdcOption *find_option_group(const char *n, ppdcGroup **mg); |
ac884b6a MS |
409 | |
410 | void set_custom_size_code(const char *c); | |
411 | void set_default_font(ppdcFont *f); | |
412 | void set_default_size(ppdcMediaSize *m); | |
bdd6c45b | 413 | void set_file_name(const char *f); |
ac884b6a MS |
414 | void set_manufacturer(const char *m); |
415 | void set_model_name(const char *m); | |
416 | void set_pc_file_name(const char *f); | |
417 | void set_version(const char *v); | |
418 | ||
419 | int write_ppd_file(cups_file_t *fp, ppdcCatalog *catalog, | |
420 | ppdcArray *locales, ppdcSource *src, | |
421 | ppdcLineEnding le); | |
422 | }; | |
423 | ||
424 | class ppdcVariable //// Variable Definition | |
425 | : public ppdcShared | |
426 | { | |
427 | public: | |
428 | ||
429 | ppdcString *name, // Name of variable | |
430 | *value; // Value of variable | |
431 | ||
432 | ppdcVariable(const char *n, const char *v); | |
433 | ~ppdcVariable(); | |
434 | ||
94da7e34 MS |
435 | PPDC_NAME("ppdcVariable") |
436 | ||
ac884b6a MS |
437 | void set_value(const char *v); |
438 | }; | |
439 | ||
440 | class ppdcFile //// File | |
441 | { | |
442 | public: | |
443 | ||
82cc1f9a | 444 | bool close_on_delete; // Close file on delete? |
ac884b6a MS |
445 | cups_file_t *fp; // File pointer |
446 | const char *filename; // Filename | |
447 | int line; // Line in file | |
448 | ||
4509bb49 | 449 | ppdcFile(const char *f, cups_file_t *ffp = (cups_file_t *)0); |
ac884b6a MS |
450 | ~ppdcFile(); |
451 | ||
452 | int get(); | |
453 | int peek(); | |
454 | }; | |
455 | ||
456 | class ppdcSource //// Source File | |
457 | : public ppdcShared | |
458 | { | |
459 | public: | |
460 | ||
461 | static ppdcArray *includes; // Include directories | |
462 | static const char *driver_types[]; // Driver types | |
463 | ||
464 | ppdcString *filename; // Filename | |
465 | ppdcArray *base_fonts, // Base fonts | |
466 | *drivers, // Printer drivers | |
467 | *po_files, // Message catalogs | |
468 | *sizes, // Predefined media sizes | |
469 | *vars; // Defined variables | |
bdd6c45b MS |
470 | int cond_state, // Cummulative conditional state |
471 | *cond_current, // Current #if state | |
472 | cond_stack[101]; // #if state stack | |
473 | ||
ac884b6a | 474 | |
4509bb49 | 475 | ppdcSource(const char *f = 0, cups_file_t *ffp = (cups_file_t *)0); |
ac884b6a MS |
476 | ~ppdcSource(); |
477 | ||
94da7e34 MS |
478 | PPDC_NAME("ppdcSource") |
479 | ||
ac884b6a MS |
480 | static void add_include(const char *d); |
481 | ppdcDriver *find_driver(const char *f); | |
482 | static char *find_include(const char *f, const char *base, char *n, | |
483 | int nlen); | |
484 | ppdcCatalog *find_po(const char *l); | |
485 | ppdcMediaSize *find_size(const char *s); | |
486 | ppdcVariable *find_variable(const char *n); | |
bdd6c45b | 487 | ppdcAttr *get_attr(ppdcFile *fp, bool loc = false); |
ac884b6a MS |
488 | int get_boolean(ppdcFile *fp); |
489 | ppdcChoice *get_choice(ppdcFile *fp); | |
490 | ppdcChoice *get_color_model(ppdcFile *fp); | |
491 | int get_color_order(const char *co); | |
492 | ppdcProfile *get_color_profile(ppdcFile *fp); | |
493 | int get_color_space(const char *cs); | |
494 | ppdcConstraint *get_constraint(ppdcFile *fp); | |
495 | ppdcMediaSize *get_custom_size(ppdcFile *fp); | |
496 | void get_duplex(ppdcFile *fp, ppdcDriver *d); | |
497 | ppdcFilter *get_filter(ppdcFile *fp); | |
498 | float get_float(ppdcFile *fp); | |
499 | ppdcFont *get_font(ppdcFile *fp); | |
500 | ppdcChoice *get_generic(ppdcFile *fp, const char *keyword, | |
501 | const char *tattr, const char *nattr); | |
502 | ppdcGroup *get_group(ppdcFile *fp, ppdcDriver *d); | |
503 | ppdcOption *get_installable(ppdcFile *fp); | |
504 | int get_integer(const char *v); | |
505 | int get_integer(ppdcFile *fp); | |
506 | float get_measurement(ppdcFile *fp); | |
507 | ppdcOption *get_option(ppdcFile *fp, ppdcDriver *d, ppdcGroup *g); | |
508 | ppdcCatalog *get_po(ppdcFile *fp); | |
509 | ppdcChoice *get_resolution(ppdcFile *fp); | |
510 | ppdcProfile *get_simple_profile(ppdcFile *fp); | |
511 | ppdcMediaSize *get_size(ppdcFile *fp); | |
512 | char *get_token(ppdcFile *fp, char *buffer, int buflen); | |
513 | ppdcVariable *get_variable(ppdcFile *fp); | |
514 | int import_ppd(const char *f); | |
515 | int quotef(cups_file_t *fp, const char *format, ...); | |
4509bb49 | 516 | void read_file(const char *f, cups_file_t *ffp = (cups_file_t *)0); |
ac884b6a MS |
517 | void scan_file(ppdcFile *fp, ppdcDriver *td = 0, bool inc = false); |
518 | ppdcVariable *set_variable(const char *name, const char *value); | |
519 | int write_file(const char *f); | |
520 | }; | |
521 | ||
522 | ||
523 | #endif // !_PPDC_H_ |