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