]> git.ipfire.org Git - thirdparty/cups.git/blame - ppdc/ppdpo.cxx
Merge changes from CUPS 1.4svn-r7607.
[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
26#include "ppdc.h"
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
54
55
56 // Scan the command-line...
57 catalog = new ppdcCatalog("en");
58 src = 0;
59 verbose = 0;
60 outfile = 0;
61
62 for (i = 1; i < argc; i ++)
63 if (argv[i][0] == '-')
64 {
65 for (opt = argv[i] + 1; *opt; opt ++)
66 switch (*opt)
67 {
68 case 'I' : // Include directory...
69 i ++;
70 if (i >= argc)
71 usage();
72
73 if (verbose > 1)
74 printf("ppdc: Adding include directory \"%s\"...\n", argv[i]);
75
76 ppdcSource::add_include(argv[i]);
77 break;
78
79 case 'o' : // Output file...
80 i ++;
81 if (i >= argc || outfile)
82 usage();
83
84 outfile = argv[i];
85
86 catalog->load_messages(outfile);
87 break;
88
89 case 'v' : // Be verbose...
90 verbose ++;
91 break;
92
93 default : // Unknown
94 usage();
95 break;
96 }
97 }
98 else
99 {
100 // Open and load the driver info file...
101 if (verbose > 1)
102 printf("ppdc: Loading driver information file \"%s\"...\n", argv[i]);
103
104 src = new ppdcSource(argv[i]);
105
106 // Add UI strings...
107 for (d = (ppdcDriver *)src->drivers->first();
108 d;
109 d = (ppdcDriver *)src->drivers->next())
110 {
111 if (verbose)
112 printf("ppdc: Adding/updating UI text from %s...\n", argv[i]);
113
114 add_ui_strings(d, catalog);
115 }
116
117 // Delete the printer driver information...
118 delete src;
119 }
120
121 // Write the message catalog...
122 if (!outfile)
123 usage();
124 else
125 catalog->save_messages(outfile);
126
127 delete catalog;
128
129 // If no drivers have been loaded, display the program usage message.
130 if (!src)
131 usage();
132
133 // Return with no errors.
134 return (0);
135}
136
137
138//
139// 'add_ui_strings()' - Add all UI strings from the driver.
140//
141
142static void
143add_ui_strings(ppdcDriver *d, // I - Driver data
144 ppdcCatalog *catalog) // I - Message catalog
145{
146 // Add the make/model/language strings...
147 catalog->add_message(d->manufacturer->value);
148 catalog->add_message(d->model_name->value);
149
150 // Add the media size strings...
151 ppdcMediaSize *m; // Current media size
152
153 for (m = (ppdcMediaSize *)d->sizes->first();
154 m;
155 m = (ppdcMediaSize *)d->sizes->next())
156 catalog->add_message(m->text->value);
157
158 // Add the group/option/choice strings...
159 ppdcGroup *g; // Current group
160 ppdcOption *o; // Current option
161 ppdcChoice *c; // Current choice
162
163 for (g = (ppdcGroup *)d->groups->first();
164 g;
165 g = (ppdcGroup *)d->groups->next())
166 {
167 if (!g->options->count)
168 continue;
169
170 if (strcasecmp(g->name->value, "General"))
171 catalog->add_message(g->text->value);
172
173 for (o = (ppdcOption *)g->options->first();
174 o;
175 o = (ppdcOption *)g->options->next())
176 {
177 if (!o->choices->count)
178 continue;
179
180 if (o->text->value && strcmp(o->name->value, o->text->value))
181 catalog->add_message(o->text->value);
182 else
183 catalog->add_message(o->name->value);
184
185 for (c = (ppdcChoice *)o->choices->first();
186 c;
187 c = (ppdcChoice *)o->choices->next())
188 if (c->text->value && strcmp(c->name->value, c->text->value))
189 catalog->add_message(c->text->value);
190 else
191 catalog->add_message(c->name->value);
192 }
193 }
194
195 // Add profile and preset strings...
196 ppdcAttr *a; // Current attribute
197 for (a = (ppdcAttr *)d->attrs->first();
198 a;
199 a = (ppdcAttr *)d->attrs->next())
200 if (a->text->value && a->text->value[0] &&
bdd6c45b
MS
201 (a->localizable ||
202 !strncmp(a->name->value, "Custom", 6) ||
ac884b6a
MS
203 !strncmp(a->name->value, "ParamCustom", 11) ||
204 !strcmp(a->name->value, "APCustomColorMatchingName") ||
205 !strcmp(a->name->value, "APPrinterPreset") ||
206 !strcmp(a->name->value, "cupsICCProfile") ||
bdd6c45b
MS
207 !strcmp(a->name->value, "cupsIPPReason") ||
208 !strcmp(a->name->value, "cupsMarkerName")))
209 {
ac884b6a 210 catalog->add_message(a->text->value);
bdd6c45b
MS
211
212 if ((a->localizable && a->value->value[0]) ||
213 !strcmp(a->name->value, "cupsIPPReason"))
214 catalog->add_message(a->value->value);
215 }
ac884b6a
MS
216 else if (!strncmp(a->name->value, "Custom", 6) ||
217 !strncmp(a->name->value, "ParamCustom", 11))
218 catalog->add_message(a->name->value);
219}
220
221
222//
223// 'usage()' - Show usage and exit.
224//
225
226static void
227usage(void)
228{
229 puts("Usage: ppdpo [options] -o filename.po filename.drv [ ... filenameN.drv ]");
230 puts("Options:");
231 puts(" -I include-dir Add include directory to search path.");
232 puts(" -v Be verbose (more v's for more verbosity).");
233
234 exit(1);
235}
236
237
238//
239// End of "$Id$".
240//