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