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