]> git.ipfire.org Git - thirdparty/cups.git/blame - ppdc/ppdpo.cxx
Import changes from CUPS 1.5svn-r9085.
[thirdparty/cups.git] / ppdc / ppdpo.cxx
CommitLineData
ac884b6a
MS
1//
2// "$Id$"
3//
4// PPD file message catalog program for the CUPS PPD Compiler.
5//
bdd6c45b 6// Copyright 2007-2008 by Apple Inc.
ac884b6a
MS
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
38e73f87 26#include "ppdc-private.h"
ac884b6a
MS
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
61cf44e2 54 char *value; // Value in option
ac884b6a
MS
55
56
61cf44e2
MS
57 _cupsSetLocale(argv);
58
ac884b6a
MS
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 {
61cf44e2
MS
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
ac884b6a
MS
86 case 'I' : // Include directory...
87 i ++;
88 if (i >= argc)
89 usage();
90
91 if (verbose > 1)
61cf44e2
MS
92 _cupsLangPrintf(stdout,
93 _("ppdc: Adding include directory \"%s\"...\n"),
94 argv[i]);
ac884b6a
MS
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)
61cf44e2
MS
122 _cupsLangPrintf(stdout,
123 _("ppdc: Loading driver information file \"%s\"...\n"),
124 argv[i]);
ac884b6a
MS
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)
61cf44e2
MS
134 _cupsLangPrintf(stderr,
135 _("ppdc: Adding/updating UI text from %s...\n"),
136 argv[i]);
ac884b6a
MS
137
138 add_ui_strings(d, catalog);
139 }
140
141 // Delete the printer driver information...
e4572d57 142 src->release();
ac884b6a
MS
143 }
144
145 // Write the message catalog...
146 if (!outfile)
147 usage();
148 else
149 catalog->save_messages(outfile);
150
e4572d57 151 catalog->release();
ac884b6a
MS
152
153 // If no drivers have been loaded, display the program usage message.
154 if (!src)
155 usage();
156
157 // Return with no errors.
158 return (0);
159}
160
161
162//
163// 'add_ui_strings()' - Add all UI strings from the driver.
164//
165
166static void
167add_ui_strings(ppdcDriver *d, // I - Driver data
168 ppdcCatalog *catalog) // I - Message catalog
169{
170 // Add the make/model/language strings...
171 catalog->add_message(d->manufacturer->value);
172 catalog->add_message(d->model_name->value);
173
174 // Add the media size strings...
175 ppdcMediaSize *m; // Current media size
176
177 for (m = (ppdcMediaSize *)d->sizes->first();
178 m;
179 m = (ppdcMediaSize *)d->sizes->next())
180 catalog->add_message(m->text->value);
181
182 // Add the group/option/choice strings...
183 ppdcGroup *g; // Current group
184 ppdcOption *o; // Current option
185 ppdcChoice *c; // Current choice
186
187 for (g = (ppdcGroup *)d->groups->first();
188 g;
189 g = (ppdcGroup *)d->groups->next())
190 {
191 if (!g->options->count)
192 continue;
193
194 if (strcasecmp(g->name->value, "General"))
195 catalog->add_message(g->text->value);
196
197 for (o = (ppdcOption *)g->options->first();
198 o;
199 o = (ppdcOption *)g->options->next())
200 {
201 if (!o->choices->count)
202 continue;
203
d2354e63 204 if (o->text->value)
ac884b6a
MS
205 catalog->add_message(o->text->value);
206 else
207 catalog->add_message(o->name->value);
208
209 for (c = (ppdcChoice *)o->choices->first();
210 c;
211 c = (ppdcChoice *)o->choices->next())
d2354e63 212 if (c->text->value)
ac884b6a
MS
213 catalog->add_message(c->text->value);
214 else
215 catalog->add_message(c->name->value);
216 }
217 }
218
219 // Add profile and preset strings...
220 ppdcAttr *a; // Current attribute
221 for (a = (ppdcAttr *)d->attrs->first();
222 a;
223 a = (ppdcAttr *)d->attrs->next())
224 if (a->text->value && a->text->value[0] &&
bdd6c45b
MS
225 (a->localizable ||
226 !strncmp(a->name->value, "Custom", 6) ||
ac884b6a
MS
227 !strncmp(a->name->value, "ParamCustom", 11) ||
228 !strcmp(a->name->value, "APCustomColorMatchingName") ||
229 !strcmp(a->name->value, "APPrinterPreset") ||
230 !strcmp(a->name->value, "cupsICCProfile") ||
bdd6c45b
MS
231 !strcmp(a->name->value, "cupsIPPReason") ||
232 !strcmp(a->name->value, "cupsMarkerName")))
233 {
ac884b6a 234 catalog->add_message(a->text->value);
bdd6c45b
MS
235
236 if ((a->localizable && a->value->value[0]) ||
237 !strcmp(a->name->value, "cupsIPPReason"))
238 catalog->add_message(a->value->value);
239 }
ac884b6a
MS
240 else if (!strncmp(a->name->value, "Custom", 6) ||
241 !strncmp(a->name->value, "ParamCustom", 11))
242 catalog->add_message(a->name->value);
243}
244
245
246//
247// 'usage()' - Show usage and exit.
248//
249
250static void
251usage(void)
252{
61cf44e2
MS
253 _cupsLangPuts(stdout,
254 _("Usage: ppdpo [options] -o filename.po filename.drv [ ... "
255 "filenameN.drv ]\n"
256 "Options:\n"
257 " -D name=value Set named variable to value.\n"
258 " -I include-dir Add include directory to search path.\n"
259 " -v Be verbose (more v's for more "
260 "verbosity).\n"));
ac884b6a
MS
261
262 exit(1);
263}
264
265
266//
267// End of "$Id$".
268//