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