]> git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/genstrings.cxx
Merge changes from CUPS 1.4svn-r8628.
[thirdparty/cups.git] / ppdc / genstrings.cxx
1 //
2 // "$Id$"
3 //
4 // GNU gettext message generator for the CUPS PPD Compiler.
5 //
6 // This program is used to generate a dummy source file containing all of
7 // the standard media and sample driver strings. The results are picked up
8 // by GNU gettext and placed in the CUPS message catalog.
9 //
10 // Copyright 2008-2009 by Apple Inc.
11 //
12 // These coded instructions, statements, and computer programs are the
13 // property of Apple Inc. and are protected by Federal copyright
14 // law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 // which should have been included with this file. If this file is
16 // file is missing or damaged, see the license at "http://www.cups.org/".
17 //
18 // Usage:
19 //
20 // ./genstrings >sample.c
21 //
22 // Contents:
23 //
24 // main() - Main entry for the PPD compiler.
25 // add_ui_strings() - Add all UI strings from the driver.
26 // write_cstring() - Write a translation string as a valid C string to
27 // stdout.
28 //
29
30 //
31 // Include necessary headers...
32 //
33
34 #include "ppdc-private.h"
35 #include <unistd.h>
36
37
38 //
39 // Local functions...
40 //
41
42 static void add_ui_strings(ppdcDriver *d, ppdcCatalog *catalog);
43 static void write_cstring(const char *s);
44
45
46 //
47 // 'main()' - Main entry for the PPD compiler.
48 //
49
50 int // O - Exit status
51 main(void)
52 {
53 ppdcSource *src; // PPD source file data
54 ppdcCatalog *catalog; // Catalog to hold all of the UI strings
55
56
57 // Make sure we are in the right place...
58 if (access("../data", 0) || access("sample.drv", 0))
59 {
60 puts("You must run genstrings from the ppdc directory.");
61 return (1);
62 }
63
64 // Load the sample drivers...
65 ppdcSource::add_include("../data");
66
67 src = new ppdcSource("sample.drv");
68 catalog = new ppdcCatalog(NULL);
69
70 // Add the media size strings...
71 ppdcMediaSize *size; // Current media size
72
73 for (size = (ppdcMediaSize *)src->sizes->first();
74 size;
75 size = (ppdcMediaSize *)src->sizes->next())
76 catalog->add_message(size->text->value);
77
78 // Then collect all of the UI strings from the sample drivers...
79 ppdcDriver *d; // Current driver
80
81 for (d = (ppdcDriver *)src->drivers->first();
82 d;
83 d = (ppdcDriver *)src->drivers->next())
84 add_ui_strings(d, catalog);
85
86 // Finally, write all of the strings...
87 ppdcMessage *message;
88
89 for (message = (ppdcMessage *)catalog->messages->first();
90 message;
91 message = (ppdcMessage *)catalog->messages->next())
92 write_cstring(message->id->value);
93
94 src->release();
95 catalog->release();
96
97 // Return with no errors.
98 return (0);
99 }
100
101
102 //
103 // 'add_ui_strings()' - Add all UI strings from the driver.
104 //
105
106 static void
107 add_ui_strings(ppdcDriver *d, // I - Driver data
108 ppdcCatalog *catalog) // I - Message catalog
109 {
110 // Add the make/model/language strings...
111 catalog->add_message(d->manufacturer->value);
112 catalog->add_message(d->model_name->value);
113
114 // Add the group/option/choice strings...
115 ppdcGroup *g; // Current group
116 ppdcOption *o; // Current option
117 ppdcChoice *c; // Current choice
118
119 for (g = (ppdcGroup *)d->groups->first();
120 g;
121 g = (ppdcGroup *)d->groups->next())
122 {
123 if (!g->options->count)
124 continue;
125
126 if (strcasecmp(g->name->value, "General"))
127 catalog->add_message(g->text->value);
128
129 for (o = (ppdcOption *)g->options->first();
130 o;
131 o = (ppdcOption *)g->options->next())
132 {
133 if (!o->choices->count)
134 continue;
135
136 if (o->text->value && strcmp(o->name->value, o->text->value))
137 catalog->add_message(o->text->value);
138 else
139 catalog->add_message(o->name->value);
140
141 for (c = (ppdcChoice *)o->choices->first();
142 c;
143 c = (ppdcChoice *)o->choices->next())
144 if (c->text->value && strcmp(c->name->value, c->text->value))
145 catalog->add_message(c->text->value);
146 else
147 catalog->add_message(c->name->value);
148 }
149 }
150
151 // Add profile and preset strings...
152 ppdcAttr *a; // Current attribute
153 for (a = (ppdcAttr *)d->attrs->first();
154 a;
155 a = (ppdcAttr *)d->attrs->next())
156 {
157 if (a->text->value && a->text->value[0] &&
158 (a->localizable ||
159 !strncmp(a->name->value, "Custom", 6) ||
160 !strncmp(a->name->value, "ParamCustom", 11) ||
161 !strcmp(a->name->value, "APCustomColorMatchingName") ||
162 !strcmp(a->name->value, "APPrinterPreset") ||
163 !strcmp(a->name->value, "cupsICCProfile") ||
164 !strcmp(a->name->value, "cupsIPPReason") ||
165 !strcmp(a->name->value, "cupsMarkerName")))
166 {
167 catalog->add_message(a->text->value);
168
169 if ((a->localizable && a->value->value[0]) ||
170 !strcmp(a->name->value, "cupsIPPReason"))
171 catalog->add_message(a->value->value);
172 }
173 else if (!strncmp(a->name->value, "Custom", 6) ||
174 !strncmp(a->name->value, "ParamCustom", 11))
175 catalog->add_message(a->name->value);
176 }
177 }
178
179
180 //
181 // 'write_cstring()' - Write a translation string as a valid C string to stdout.
182 //
183
184 static void
185 write_cstring(const char *s) /* I - String to write */
186 {
187 fputs("_(\"", stdout);
188 if (s)
189 {
190 while (*s)
191 {
192 if (*s == '\\')
193 fputs("\\\\", stdout);
194 else if (*s == '\"')
195 fputs("\\\"", stdout);
196 else if (*s == '\t')
197 fputs("\\t", stdout);
198 else if (*s == '\n')
199 fputs("\\n", stdout);
200 else
201 putchar(*s);
202
203 s ++;
204 }
205 }
206 puts("\");");
207 }
208
209
210 //
211 // End of "$Id$".
212 //