]>
Commit | Line | Data |
---|---|---|
ac884b6a | 1 | // |
d25e43cf | 2 | // PPD file message catalog program for the CUPS PPD Compiler. |
ac884b6a | 3 | // |
d25e43cf MS |
4 | // Copyright 2007-2015 by Apple Inc. |
5 | // Copyright 2002-2005 by Easy Software Products. | |
ac884b6a | 6 | // |
d25e43cf MS |
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 | |
57b7b66b | 11 | // missing or damaged, see the license at "http://www.cups.org/". |
ac884b6a MS |
12 | // |
13 | ||
14 | // | |
15 | // Include necessary headers... | |
16 | // | |
17 | ||
38e73f87 | 18 | #include "ppdc-private.h" |
ac884b6a MS |
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 | |
61cf44e2 | 46 | char *value; // Value in option |
ac884b6a MS |
47 | |
48 | ||
61cf44e2 MS |
49 | _cupsSetLocale(argv); |
50 | ||
ac884b6a MS |
51 | // Scan the command-line... |
52 | catalog = new ppdcCatalog("en"); | |
d25e43cf | 53 | src = new ppdcSource(); |
ac884b6a MS |
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 | { | |
61cf44e2 MS |
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 | ||
ac884b6a MS |
78 | case 'I' : // Include directory... |
79 | i ++; | |
80 | if (i >= argc) | |
81 | usage(); | |
82 | ||
83 | if (verbose > 1) | |
61cf44e2 | 84 | _cupsLangPrintf(stdout, |
0837b7e8 | 85 | _("ppdc: Adding include directory \"%s\"."), |
61cf44e2 | 86 | argv[i]); |
ac884b6a MS |
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) | |
61cf44e2 | 114 | _cupsLangPrintf(stdout, |
0837b7e8 | 115 | _("ppdc: Loading driver information file \"%s\"."), |
61cf44e2 | 116 | argv[i]); |
ac884b6a | 117 | |
d25e43cf MS |
118 | src->read_file(argv[i]); |
119 | } | |
ac884b6a | 120 | |
d25e43cf MS |
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]); | |
ac884b6a | 129 | |
d25e43cf | 130 | add_ui_strings(d, catalog); |
ac884b6a | 131 | |
d25e43cf | 132 | d = (ppdcDriver *)src->drivers->next(); |
ac884b6a | 133 | } |
d25e43cf MS |
134 | } |
135 | else | |
136 | usage(); | |
137 | ||
138 | // Delete the printer driver information... | |
139 | src->release(); | |
ac884b6a MS |
140 | |
141 | // Write the message catalog... | |
142 | if (!outfile) | |
143 | usage(); | |
144 | else | |
145 | catalog->save_messages(outfile); | |
146 | ||
e4572d57 | 147 | catalog->release(); |
ac884b6a | 148 | |
ac884b6a MS |
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 | ||
88f9aafc | 186 | if (_cups_strcasecmp(g->name->value, "General")) |
ac884b6a MS |
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 | ||
d2354e63 | 196 | if (o->text->value) |
ac884b6a MS |
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()) | |
d2354e63 | 204 | if (c->text->value) |
ac884b6a MS |
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] && | |
bdd6c45b MS |
217 | (a->localizable || |
218 | !strncmp(a->name->value, "Custom", 6) || | |
ac884b6a MS |
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") || | |
bdd6c45b MS |
223 | !strcmp(a->name->value, "cupsIPPReason") || |
224 | !strcmp(a->name->value, "cupsMarkerName"))) | |
225 | { | |
ac884b6a | 226 | catalog->add_message(a->text->value); |
bdd6c45b MS |
227 | |
228 | if ((a->localizable && a->value->value[0]) || | |
229 | !strcmp(a->name->value, "cupsIPPReason")) | |
230 | catalog->add_message(a->value->value); | |
231 | } | |
ac884b6a MS |
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 | { | |
0837b7e8 MS |
245 | _cupsLangPuts(stdout, _("Usage: ppdpo [options] -o filename.po filename.drv " |
246 | "[ ... filenameN.drv ]")); | |
247 | _cupsLangPuts(stdout, _("Options:")); | |
84315f46 | 248 | _cupsLangPuts(stdout, _(" -D name=value Set named variable to " |
0837b7e8 | 249 | "value.")); |
84315f46 MS |
250 | _cupsLangPuts(stdout, _(" -I include-dir Add include directory to " |
251 | "search path.")); | |
f3c17241 | 252 | _cupsLangPuts(stdout, _(" -v Be verbose.")); |
ac884b6a MS |
253 | |
254 | exit(1); | |
255 | } |