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