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