1 // 2 // Option class for the CUPS PPD Compiler. 3 // 4 // Copyright © 2020-2024 by OpenPrinting. 5 // Copyright 2007-2011 by Apple Inc. 6 // Copyright 2002-2005 by Easy Software Products. 7 // 8 // Licensed under Apache License v2.0. See the file "LICENSE" for more information. 9 // 10 11 // 12 // Include necessary headers... 13 // 14 15 #include "ppdc-private.h" 16 17 18 // 19 // 'ppdcOption::ppdcOption()' - Create a new option. 20 // 21 ppdcOption(ppdcOptType ot,const char * n,const char * t,ppdcOptSection s,float o)22ppdcOption::ppdcOption(ppdcOptType ot, // I - Option type 23 const char *n, // I - Option name 24 const char *t, // I - Option text 25 ppdcOptSection s, // I - Section 26 float o) // I - Ordering number 27 : ppdcShared() 28 { 29 PPDC_NEW; 30 31 type = ot; 32 name = new ppdcString(n); 33 text = new ppdcString(t); 34 section = s; 35 order = o; 36 choices = new ppdcArray(); 37 defchoice = 0; 38 } 39 40 41 // 42 // 'ppdcOption::ppdcOption()' - Copy a new option. 43 // 44 ppdcOption(ppdcOption * o)45ppdcOption::ppdcOption(ppdcOption *o) // I - Template option 46 { 47 PPDC_NEW; 48 49 o->name->retain(); 50 o->text->retain(); 51 if (o->defchoice) 52 o->defchoice->retain(); 53 54 type = o->type; 55 name = o->name; 56 text = o->text; 57 section = o->section; 58 order = o->order; 59 choices = new ppdcArray(o->choices); 60 defchoice = o->defchoice; 61 } 62 63 64 // 65 // 'ppdcOption::~ppdcOption()' - Destroy an option. 66 // 67 ~ppdcOption()68ppdcOption::~ppdcOption() 69 { 70 PPDC_DELETE; 71 72 name->release(); 73 text->release(); 74 if (defchoice) 75 defchoice->release(); 76 choices->release(); 77 } 78 79 80 // 81 // 'ppdcOption::find_choice()' - Find an option choice. 82 // 83 84 ppdcChoice * // O - Choice or NULL find_choice(const char * n)85ppdcOption::find_choice(const char *n) // I - Name of choice 86 { 87 ppdcChoice *c; // Current choice 88 89 90 for (c = (ppdcChoice *)choices->first(); c; c = (ppdcChoice *)choices->next()) 91 if (!_cups_strcasecmp(n, c->name->value)) 92 return (c); 93 94 return (0); 95 } 96 97 98 // 99 // 'ppdcOption::set_defchoice()' - Set the default choice. 100 // 101 102 void set_defchoice(ppdcChoice * c)103ppdcOption::set_defchoice(ppdcChoice *c) // I - Choice 104 { 105 if (defchoice) 106 defchoice->release(); 107 108 if (c->name) 109 c->name->retain(); 110 111 defchoice = c->name; 112 } 113