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