]> git.ipfire.org Git - thirdparty/cups.git/blame - ppdc/ppdpo.cxx
Don't create the full name twice (<rdar://problem/23144358>)
[thirdparty/cups.git] / ppdc / ppdpo.cxx
CommitLineData
ac884b6a
MS
1//
2// "$Id$"
3//
d25e43cf 4// PPD file message catalog program for the CUPS PPD Compiler.
ac884b6a 5//
d25e43cf
MS
6// Copyright 2007-2015 by Apple Inc.
7// Copyright 2002-2005 by Easy Software Products.
ac884b6a 8//
d25e43cf
MS
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/".
ac884b6a
MS
14//
15
16//
17// Include necessary headers...
18//
19
38e73f87 20#include "ppdc-private.h"
ac884b6a
MS
21#include <sys/stat.h>
22#include <sys/types.h>
23
24
25//
26// Local functions...
27//
28
29static void add_ui_strings(ppdcDriver *d, ppdcCatalog *catalog);
30static void usage(void);
31
32
33//
34// 'main()' - Main entry for the PPD compiler.
35//
36
37int // O - Exit status
38main(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
61cf44e2 48 char *value; // Value in option
ac884b6a
MS
49
50
61cf44e2
MS
51 _cupsSetLocale(argv);
52
ac884b6a
MS
53 // Scan the command-line...
54 catalog = new ppdcCatalog("en");
d25e43cf 55 src = new ppdcSource();
ac884b6a
MS
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 {
61cf44e2
MS
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
ac884b6a
MS
80 case 'I' : // Include directory...
81 i ++;
82 if (i >= argc)
83 usage();
84
85 if (verbose > 1)
61cf44e2 86 _cupsLangPrintf(stdout,
0837b7e8 87 _("ppdc: Adding include directory \"%s\"."),
61cf44e2 88 argv[i]);
ac884b6a
MS
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)
61cf44e2 116 _cupsLangPrintf(stdout,
0837b7e8 117 _("ppdc: Loading driver information file \"%s\"."),
61cf44e2 118 argv[i]);
ac884b6a 119
d25e43cf
MS
120 src->read_file(argv[i]);
121 }
ac884b6a 122
d25e43cf
MS
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]);
ac884b6a 131
d25e43cf 132 add_ui_strings(d, catalog);
ac884b6a 133
d25e43cf 134 d = (ppdcDriver *)src->drivers->next();
ac884b6a 135 }
d25e43cf
MS
136 }
137 else
138 usage();
139
140 // Delete the printer driver information...
141 src->release();
ac884b6a
MS
142
143 // Write the message catalog...
144 if (!outfile)
145 usage();
146 else
147 catalog->save_messages(outfile);
148
e4572d57 149 catalog->release();
ac884b6a 150
ac884b6a
MS
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
160static void
161add_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
88f9aafc 188 if (_cups_strcasecmp(g->name->value, "General"))
ac884b6a
MS
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
d2354e63 198 if (o->text->value)
ac884b6a
MS
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())
d2354e63 206 if (c->text->value)
ac884b6a
MS
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] &&
bdd6c45b
MS
219 (a->localizable ||
220 !strncmp(a->name->value, "Custom", 6) ||
ac884b6a
MS
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") ||
bdd6c45b
MS
225 !strcmp(a->name->value, "cupsIPPReason") ||
226 !strcmp(a->name->value, "cupsMarkerName")))
227 {
ac884b6a 228 catalog->add_message(a->text->value);
bdd6c45b
MS
229
230 if ((a->localizable && a->value->value[0]) ||
231 !strcmp(a->name->value, "cupsIPPReason"))
232 catalog->add_message(a->value->value);
233 }
ac884b6a
MS
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
244static void
245usage(void)
246{
0837b7e8
MS
247 _cupsLangPuts(stdout, _("Usage: ppdpo [options] -o filename.po filename.drv "
248 "[ ... filenameN.drv ]"));
249 _cupsLangPuts(stdout, _("Options:"));
84315f46 250 _cupsLangPuts(stdout, _(" -D name=value Set named variable to "
0837b7e8 251 "value."));
84315f46
MS
252 _cupsLangPuts(stdout, _(" -I include-dir Add include directory to "
253 "search path."));
f3c17241 254 _cupsLangPuts(stdout, _(" -v Be verbose."));
ac884b6a
MS
255
256 exit(1);
257}
258
259
260//
261// End of "$Id$".
262//