]>
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-2014 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 // Include necessary headers...
27 #include "ppdc-private.h"
35 static void add_ui_strings(ppdcDriver
*d
, ppdcCatalog
*catalog
);
36 static void write_cstring(const char *s
);
40 // 'main()' - Main entry for the PPD compiler.
43 int // O - Exit status
46 ppdcSource
*src
; // PPD source file data
47 ppdcCatalog
*catalog
; // Catalog to hold all of the UI strings
50 // Make sure we are in the right place...
51 if (access("../data", 0) || access("sample.drv", 0))
53 puts("You must run genstrings from the ppdc directory.");
57 // Load the sample drivers...
58 ppdcSource::add_include("../data");
60 src
= new ppdcSource("sample.drv");
61 catalog
= new ppdcCatalog(NULL
);
63 catalog
->add_message("ISOLatin1");
64 catalog
->add_message("English");
66 // Add the media size strings...
67 ppdcMediaSize
*size
; // Current media size
69 for (size
= (ppdcMediaSize
*)src
->sizes
->first();
71 size
= (ppdcMediaSize
*)src
->sizes
->next())
72 catalog
->add_message(size
->text
->value
);
74 // Then collect all of the UI strings from the sample drivers...
75 ppdcDriver
*d
; // Current driver
77 for (d
= (ppdcDriver
*)src
->drivers
->first();
79 d
= (ppdcDriver
*)src
->drivers
->next())
80 add_ui_strings(d
, catalog
);
82 // Finally, write all of the strings...
85 for (message
= (ppdcMessage
*)catalog
->messages
->first();
87 message
= (ppdcMessage
*)catalog
->messages
->next())
88 write_cstring(message
->id
->value
);
93 // Return with no errors.
99 // 'add_ui_strings()' - Add all UI strings from the driver.
103 add_ui_strings(ppdcDriver
*d
, // I - Driver data
104 ppdcCatalog
*catalog
) // I - Message catalog
106 // Add the make/model/language strings...
107 catalog
->add_message(d
->manufacturer
->value
);
108 catalog
->add_message(d
->model_name
->value
);
110 // Add the group/option/choice strings...
111 ppdcGroup
*g
; // Current group
112 ppdcOption
*o
; // Current option
113 ppdcChoice
*c
; // Current choice
115 for (g
= (ppdcGroup
*)d
->groups
->first();
117 g
= (ppdcGroup
*)d
->groups
->next())
119 if (!g
->options
->count
)
122 if (_cups_strcasecmp(g
->name
->value
, "General"))
123 catalog
->add_message(g
->text
->value
);
125 for (o
= (ppdcOption
*)g
->options
->first();
127 o
= (ppdcOption
*)g
->options
->next())
129 if (!o
->choices
->count
)
132 if (o
->text
->value
&& strcmp(o
->name
->value
, o
->text
->value
))
133 catalog
->add_message(o
->text
->value
);
135 catalog
->add_message(o
->name
->value
);
137 for (c
= (ppdcChoice
*)o
->choices
->first();
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
);
143 catalog
->add_message(c
->name
->value
);
147 // Add profile and preset strings...
148 ppdcAttr
*a
; // Current attribute
149 for (a
= (ppdcAttr
*)d
->attrs
->first();
151 a
= (ppdcAttr
*)d
->attrs
->next())
153 if (a
->text
->value
&& a
->text
->value
[0] &&
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")))
163 catalog
->add_message(a
->text
->value
);
165 if ((a
->localizable
&& a
->value
->value
[0]) ||
166 !strcmp(a
->name
->value
, "cupsIPPReason"))
167 catalog
->add_message(a
->value
->value
);
169 else if (!strncmp(a
->name
->value
, "Custom", 6) ||
170 !strncmp(a
->name
->value
, "ParamCustom", 11))
171 catalog
->add_message(a
->name
->value
);
177 // 'write_cstring()' - Write a translation string as a valid C string to stdout.
181 write_cstring(const char *s
) /* I - String to write */
183 fputs("_(\"", stdout
);
189 fputs("\\\\", stdout
);
191 fputs("\\\"", stdout
);
193 fputs("\\t", stdout
);
195 fputs("\\n", stdout
);