1// 2// "$Id: ppdc.h 3757 2012-03-30 06:13:47Z msweet $" 3// 4// Definitions for the CUPS PPD Compiler. 5// 6// Copyright 2007-2009 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/file.h> 24# include <stdlib.h> 25 26 27// 28// Macros... 29// 30 31# define PPDC_NAME(s) const char *class_name() { return (s); } 32 33 34// 35// Enumerations... 36// 37 38enum 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 50enum ppdcFontStatus //// Load status of font 51{ 52 PPDC_FONT_ROM, // Font is in ROM 53 PPDC_FONT_DISK // Font is on disk 54}; 55 56enum 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 66enum 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 73enum ppdcLineEnding //// Line endings 74{ 75 PPDC_LFONLY, // LF only 76 PPDC_CRONLY, // CR only 77 PPDC_CRLF // CR + LF 78}; 79 80enum 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 87 88// 89// Printer description data... 90// 91 92class 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 103 virtual const char *class_name() = 0; 104 105 void retain(); 106 void release(); 107}; 108 109class 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 122 PPDC_NAME("ppdcArray") 123 124 void add(ppdcShared *d); 125 ppdcShared *first(); 126 ppdcShared *next(); 127 void remove(ppdcShared *d); 128}; 129 130class ppdcString //// Shared String 131 : public ppdcShared 132{ 133 public: 134 135 char *value; // String value 136 137 ppdcString(const char *v); 138 ~ppdcString(); 139 140 PPDC_NAME("ppdcString") 141}; 142 143class ppdcInteger //// Shared integer 144 : public ppdcShared 145{ 146 public: 147 148 int *value; // Integer value 149 150 ppdcInteger(int *v) { value = v; } 151 152 PPDC_NAME("ppdcInteger") 153}; 154 155class 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(); 165 166 PPDC_NAME("ppdcMessage") 167}; 168 169class 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 181 PPDC_NAME("ppdcCatalog") 182 183 void add_message(const char *id, const char *string = NULL); 184 const char *find_message(const char *id); 185 int load_messages(const char *f); 186 int save_messages(const char *f); 187}; 188 189class 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 198 bool localizable; // Should this attribute be localized? 199 200 ppdcAttr(const char *n, const char *s, const char *t, const char *v, 201 bool loc = false); 202 ~ppdcAttr(); 203 204 PPDC_NAME("ppdcAttr") 205}; 206 207class 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(); 221 222 PPDC_NAME("ppdcFont") 223}; 224 225class 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(); 236 237 PPDC_NAME("ppdcChoice") 238}; 239 240class 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 258 PPDC_NAME("ppdcOption") 259 260 void add_choice(ppdcChoice *c) { choices->add(c); } 261 ppdcChoice *find_choice(const char *n); 262 void set_defchoice(ppdcChoice *c); 263}; 264 265class 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 278 PPDC_NAME("ppdcGroup") 279 280 void add_option(ppdcOption *o) { options->add(o); } 281 ppdcOption *find_option(const char *n); 282}; 283 284class 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(); 297 298 PPDC_NAME("ppdcConstraint") 299}; 300 301class 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(); 312 313 PPDC_NAME("ppdcFilter") 314}; 315 316class 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(); 336 337 PPDC_NAME("ppdcMediaSize") 338}; 339 340class 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(); 353 354 PPDC_NAME("ppdcProfile") 355}; 356 357class ppdcSource; 358 359class 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 368 *file_name, // Output filename for PPD 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 398 PPDC_NAME("ppdcDriver") 399 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); 414 ppdcOption *find_option_group(const char *n, ppdcGroup **mg); 415 416 void set_custom_size_code(const char *c); 417 void set_default_font(ppdcFont *f); 418 void set_default_size(ppdcMediaSize *m); 419 void set_file_name(const char *f); 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 430class 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 441 PPDC_NAME("ppdcVariable") 442 443 void set_value(const char *v); 444}; 445 446class ppdcFile //// File 447{ 448 public: 449 450 bool close_on_delete; // Close file on delete? 451 cups_file_t *fp; // File pointer 452 const char *filename; // Filename 453 int line; // Line in file 454 455 ppdcFile(const char *f, cups_file_t *ffp = (cups_file_t *)0); 456 ~ppdcFile(); 457 458 int get(); 459 int peek(); 460}; 461 462class ppdcSource //// Source File 463 : public ppdcShared 464{ 465 public: 466 467 static ppdcArray *includes; // Include directories 468 static const char *driver_types[]; // Driver types 469 470 ppdcString *filename; // Filename 471 ppdcArray *base_fonts, // Base fonts 472 *drivers, // Printer drivers 473 *po_files, // Message catalogs 474 *sizes, // Predefined media sizes 475 *vars; // Defined variables 476 int cond_state, // Cummulative conditional state 477 *cond_current, // Current #if state 478 cond_stack[101]; // #if state stack 479 480 481 ppdcSource(const char *f = 0, cups_file_t *ffp = (cups_file_t *)0); 482 ~ppdcSource(); 483 484 PPDC_NAME("ppdcSource") 485 486 static void add_include(const char *d); 487 ppdcDriver *find_driver(const char *f); 488 static char *find_include(const char *f, const char *base, char *n, 489 int nlen); 490 ppdcCatalog *find_po(const char *l); 491 ppdcMediaSize *find_size(const char *s); 492 ppdcVariable *find_variable(const char *n); 493 ppdcAttr *get_attr(ppdcFile *fp, bool loc = false); 494 int get_boolean(ppdcFile *fp); 495 ppdcChoice *get_choice(ppdcFile *fp); 496 ppdcChoice *get_color_model(ppdcFile *fp); 497 int get_color_order(const char *co); 498 ppdcProfile *get_color_profile(ppdcFile *fp); 499 int get_color_space(const char *cs); 500 ppdcConstraint *get_constraint(ppdcFile *fp); 501 ppdcMediaSize *get_custom_size(ppdcFile *fp); 502 void get_duplex(ppdcFile *fp, ppdcDriver *d); 503 ppdcFilter *get_filter(ppdcFile *fp); 504 float get_float(ppdcFile *fp); 505 ppdcFont *get_font(ppdcFile *fp); 506 ppdcChoice *get_generic(ppdcFile *fp, const char *keyword, 507 const char *tattr, const char *nattr); 508 ppdcGroup *get_group(ppdcFile *fp, ppdcDriver *d); 509 ppdcOption *get_installable(ppdcFile *fp); 510 int get_integer(const char *v); 511 int get_integer(ppdcFile *fp); 512 float get_measurement(ppdcFile *fp); 513 ppdcOption *get_option(ppdcFile *fp, ppdcDriver *d, ppdcGroup *g); 514 ppdcCatalog *get_po(ppdcFile *fp); 515 ppdcChoice *get_resolution(ppdcFile *fp); 516 ppdcProfile *get_simple_profile(ppdcFile *fp); 517 ppdcMediaSize *get_size(ppdcFile *fp); 518 char *get_token(ppdcFile *fp, char *buffer, int buflen); 519 ppdcVariable *get_variable(ppdcFile *fp); 520 int import_ppd(const char *f); 521 int quotef(cups_file_t *fp, const char *format, ...); 522 void read_file(const char *f, cups_file_t *ffp = (cups_file_t *)0); 523 void scan_file(ppdcFile *fp, ppdcDriver *td = 0, bool inc = false); 524 ppdcVariable *set_variable(const char *name, const char *value); 525 int write_file(const char *f); 526}; 527 528 529#endif // !_PPDC_H_ 530 531// 532// End of "$Id: ppdc.h 3757 2012-03-30 06:13:47Z msweet $". 533// 534