1// 2// "$Id: ppdpo.cxx 3796 2012-04-23 22:54:48Z msweet $" 3// 4// PPD file message catalog program for the CUPS PPD Compiler. 5// 6// Copyright 2007-2012 by Apple Inc. 7// Copyright 2002-2005 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// Contents: 16// 17// main() - Main entry for the PPD compiler. 18// add_ui_strings() - Add all UI strings from the driver. 19// usage() - Show usage and exit. 20// 21 22// 23// Include necessary headers... 24// 25 26#include "ppdc-private.h" 27#include <sys/stat.h> 28#include <sys/types.h> 29 30 31// 32// Local functions... 33// 34 35static void add_ui_strings(ppdcDriver *d, ppdcCatalog *catalog); 36static void usage(void); 37 38 39// 40// 'main()' - Main entry for the PPD compiler. 41// 42 43int // O - Exit status 44main(int argc, // I - Number of command-line arguments 45 char *argv[]) // I - Command-line arguments 46{ 47 int i; // Looping var 48 ppdcCatalog *catalog; // Message catalog 49 ppdcSource *src; // PPD source file data 50 ppdcDriver *d; // Current driver 51 char *opt; // Current option 52 int verbose; // Verbosity 53 const char *outfile; // Output file 54 char *value; // Value in option 55 56 57 _cupsSetLocale(argv); 58 59 // Scan the command-line... 60 catalog = new ppdcCatalog("en"); 61 src = 0; 62 verbose = 0; 63 outfile = 0; 64 65 for (i = 1; i < argc; i ++) 66 if (argv[i][0] == '-') 67 { 68 for (opt = argv[i] + 1; *opt; opt ++) 69 switch (*opt) 70 { 71 case 'D' : // Define variable 72 i ++; 73 if (i >= argc) 74 usage(); 75 76 if ((value = strchr(argv[i], '=')) != NULL) 77 { 78 *value++ = '\0'; 79 80 src->set_variable(argv[i], value); 81 } 82 else 83 src->set_variable(argv[i], "1"); 84 break; 85 86 case 'I' : // Include directory... 87 i ++; 88 if (i >= argc) 89 usage(); 90 91 if (verbose > 1) 92 _cupsLangPrintf(stdout, 93 _("ppdc: Adding include directory \"%s\"."), 94 argv[i]); 95 96 ppdcSource::add_include(argv[i]); 97 break; 98 99 case 'o' : // Output file... 100 i ++; 101 if (i >= argc || outfile) 102 usage(); 103 104 outfile = argv[i]; 105 106 catalog->load_messages(outfile); 107 break; 108 109 case 'v' : // Be verbose... 110 verbose ++; 111 break; 112 113 default : // Unknown 114 usage(); 115 break; 116 } 117 } 118 else 119 { 120 // Open and load the driver info file... 121 if (verbose > 1) 122 _cupsLangPrintf(stdout, 123 _("ppdc: Loading driver information file \"%s\"."), 124 argv[i]); 125 126 src = new ppdcSource(argv[i]); 127 128 // Add UI strings... 129 for (d = (ppdcDriver *)src->drivers->first(); 130 d; 131 d = (ppdcDriver *)src->drivers->next()) 132 { 133 if (verbose) 134 _cupsLangPrintf(stderr, _("ppdc: Adding/updating UI text from %s."), 135 argv[i]); 136 137 add_ui_strings(d, catalog); 138 } 139 140 // Delete the printer driver information... 141 src->release(); 142 } 143 144 // Write the message catalog... 145 if (!outfile) 146 usage(); 147 else 148 catalog->save_messages(outfile); 149 150 catalog->release(); 151 152 // If no drivers have been loaded, display the program usage message. 153 if (!src) 154 usage(); 155 156 // Return with no errors. 157 return (0); 158} 159 160 161// 162// 'add_ui_strings()' - Add all UI strings from the driver. 163// 164 165static void 166add_ui_strings(ppdcDriver *d, // I - Driver data 167 ppdcCatalog *catalog) // I - Message catalog 168{ 169 // Add the make/model/language strings... 170 catalog->add_message(d->manufacturer->value); 171 catalog->add_message(d->model_name->value); 172 173 // Add the media size strings... 174 ppdcMediaSize *m; // Current media size 175 176 for (m = (ppdcMediaSize *)d->sizes->first(); 177 m; 178 m = (ppdcMediaSize *)d->sizes->next()) 179 catalog->add_message(m->text->value); 180 181 // Add the group/option/choice strings... 182 ppdcGroup *g; // Current group 183 ppdcOption *o; // Current option 184 ppdcChoice *c; // Current choice 185 186 for (g = (ppdcGroup *)d->groups->first(); 187 g; 188 g = (ppdcGroup *)d->groups->next()) 189 { 190 if (!g->options->count) 191 continue; 192 193 if (_cups_strcasecmp(g->name->value, "General")) 194 catalog->add_message(g->text->value); 195 196 for (o = (ppdcOption *)g->options->first(); 197 o; 198 o = (ppdcOption *)g->options->next()) 199 { 200 if (!o->choices->count) 201 continue; 202 203 if (o->text->value) 204 catalog->add_message(o->text->value); 205 else 206 catalog->add_message(o->name->value); 207 208 for (c = (ppdcChoice *)o->choices->first(); 209 c; 210 c = (ppdcChoice *)o->choices->next()) 211 if (c->text->value) 212 catalog->add_message(c->text->value); 213 else 214 catalog->add_message(c->name->value); 215 } 216 } 217 218 // Add profile and preset strings... 219 ppdcAttr *a; // Current attribute 220 for (a = (ppdcAttr *)d->attrs->first(); 221 a; 222 a = (ppdcAttr *)d->attrs->next()) 223 if (a->text->value && a->text->value[0] && 224 (a->localizable || 225 !strncmp(a->name->value, "Custom", 6) || 226 !strncmp(a->name->value, "ParamCustom", 11) || 227 !strcmp(a->name->value, "APCustomColorMatchingName") || 228 !strcmp(a->name->value, "APPrinterPreset") || 229 !strcmp(a->name->value, "cupsICCProfile") || 230 !strcmp(a->name->value, "cupsIPPReason") || 231 !strcmp(a->name->value, "cupsMarkerName"))) 232 { 233 catalog->add_message(a->text->value); 234 235 if ((a->localizable && a->value->value[0]) || 236 !strcmp(a->name->value, "cupsIPPReason")) 237 catalog->add_message(a->value->value); 238 } 239 else if (!strncmp(a->name->value, "Custom", 6) || 240 !strncmp(a->name->value, "ParamCustom", 11)) 241 catalog->add_message(a->name->value); 242} 243 244 245// 246// 'usage()' - Show usage and exit. 247// 248 249static void 250usage(void) 251{ 252 _cupsLangPuts(stdout, _("Usage: ppdpo [options] -o filename.po filename.drv " 253 "[ ... filenameN.drv ]")); 254 _cupsLangPuts(stdout, _("Options:")); 255 _cupsLangPuts(stdout, _(" -D name=value Set named variable to " 256 "value.")); 257 _cupsLangPuts(stdout, _(" -I include-dir Add include directory to " 258 "search path.")); 259 _cupsLangPuts(stdout, _(" -v Be verbose.")); 260 261 exit(1); 262} 263 264 265// 266// End of "$Id: ppdpo.cxx 3796 2012-04-23 22:54:48Z msweet $". 267// 268