]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/genstrings.cxx
4 // GNU gettext message generator for the CUPS PPD Compiler.
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.
10 // Copyright 2008-2011 by Apple Inc.
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/".
20 // ./genstrings >sample.c
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
31 // Include necessary headers...
34 #include "ppdc-private.h"
42 static void add_ui_strings(ppdcDriver
*d
, ppdcCatalog
*catalog
);
43 static void write_cstring(const char *s
);
47 // 'main()' - Main entry for the PPD compiler.
50 int // O - Exit status
53 ppdcSource
*src
; // PPD source file data
54 ppdcCatalog
*catalog
; // Catalog to hold all of the UI strings
57 // Make sure we are in the right place...
58 if (access("../data", 0) || access("sample.drv", 0))
60 puts("You must run genstrings from the ppdc directory.");
64 // Load the sample drivers...
65 ppdcSource::add_include("../data");
67 src
= new ppdcSource("sample.drv");
68 catalog
= new ppdcCatalog(NULL
);
70 catalog
->add_message("ISOLatin1");
71 catalog
->add_message("English");
73 // Add the media size strings...
74 ppdcMediaSize
*size
; // Current media size
76 for (size
= (ppdcMediaSize
*)src
->sizes
->first();
78 size
= (ppdcMediaSize
*)src
->sizes
->next())
79 catalog
->add_message(size
->text
->value
);
81 // Then collect all of the UI strings from the sample drivers...
82 ppdcDriver
*d
; // Current driver
84 for (d
= (ppdcDriver
*)src
->drivers
->first();
86 d
= (ppdcDriver
*)src
->drivers
->next())
87 add_ui_strings(d
, catalog
);
89 // Finally, write all of the strings...
92 for (message
= (ppdcMessage
*)catalog
->messages
->first();
94 message
= (ppdcMessage
*)catalog
->messages
->next())
95 write_cstring(message
->id
->value
);
100 // Return with no errors.
106 // 'add_ui_strings()' - Add all UI strings from the driver.
110 add_ui_strings(ppdcDriver
*d
, // I - Driver data
111 ppdcCatalog
*catalog
) // I - Message catalog
113 // Add the make/model/language strings...
114 catalog
->add_message(d
->manufacturer
->value
);
115 catalog
->add_message(d
->model_name
->value
);
117 // Add the group/option/choice strings...
118 ppdcGroup
*g
; // Current group
119 ppdcOption
*o
; // Current option
120 ppdcChoice
*c
; // Current choice
122 for (g
= (ppdcGroup
*)d
->groups
->first();
124 g
= (ppdcGroup
*)d
->groups
->next())
126 if (!g
->options
->count
)
129 if (_cups_strcasecmp(g
->name
->value
, "General"))
130 catalog
->add_message(g
->text
->value
);
132 for (o
= (ppdcOption
*)g
->options
->first();
134 o
= (ppdcOption
*)g
->options
->next())
136 if (!o
->choices
->count
)
139 if (o
->text
->value
&& strcmp(o
->name
->value
, o
->text
->value
))
140 catalog
->add_message(o
->text
->value
);
142 catalog
->add_message(o
->name
->value
);
144 for (c
= (ppdcChoice
*)o
->choices
->first();
146 c
= (ppdcChoice
*)o
->choices
->next())
147 if (c
->text
->value
&& strcmp(c
->name
->value
, c
->text
->value
))
148 catalog
->add_message(c
->text
->value
);
150 catalog
->add_message(c
->name
->value
);
154 // Add profile and preset strings...
155 ppdcAttr
*a
; // Current attribute
156 for (a
= (ppdcAttr
*)d
->attrs
->first();
158 a
= (ppdcAttr
*)d
->attrs
->next())
160 if (a
->text
->value
&& a
->text
->value
[0] &&
162 !strncmp(a
->name
->value
, "Custom", 6) ||
163 !strncmp(a
->name
->value
, "ParamCustom", 11) ||
164 !strcmp(a
->name
->value
, "APCustomColorMatchingName") ||
165 !strcmp(a
->name
->value
, "APPrinterPreset") ||
166 !strcmp(a
->name
->value
, "cupsICCProfile") ||
167 !strcmp(a
->name
->value
, "cupsIPPReason") ||
168 !strcmp(a
->name
->value
, "cupsMarkerName")))
170 catalog
->add_message(a
->text
->value
);
172 if ((a
->localizable
&& a
->value
->value
[0]) ||
173 !strcmp(a
->name
->value
, "cupsIPPReason"))
174 catalog
->add_message(a
->value
->value
);
176 else if (!strncmp(a
->name
->value
, "Custom", 6) ||
177 !strncmp(a
->name
->value
, "ParamCustom", 11))
178 catalog
->add_message(a
->name
->value
);
184 // 'write_cstring()' - Write a translation string as a valid C string to stdout.
188 write_cstring(const char *s
) /* I - String to write */
190 fputs("_(\"", stdout
);
196 fputs("\\\\", stdout
);
198 fputs("\\\"", stdout
);
200 fputs("\\t", stdout
);
202 fputs("\\n", stdout
);