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