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