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