]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/genstrings.cxx
2 // GNU gettext message generator for the CUPS PPD Compiler.
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.
8 // Copyright 2008-2014 by Apple Inc.
10 // Licensed under Apache License v2.0. See the file "LICENSE" for more information.
14 // ./genstrings >sample.c
18 // Include necessary headers...
21 #include "ppdc-private.h"
29 static void add_ui_strings(ppdcDriver
*d
, ppdcCatalog
*catalog
);
30 static void write_cstring(const char *s
);
34 // 'main()' - Main entry for the PPD compiler.
37 int // O - Exit status
40 ppdcSource
*src
; // PPD source file data
41 ppdcCatalog
*catalog
; // Catalog to hold all of the UI strings
44 // Make sure we are in the right place...
45 if (access("../data", 0) || access("sample.drv", 0))
47 puts("You must run genstrings from the ppdc directory.");
51 // Load the sample drivers...
52 ppdcSource::add_include("../data");
54 src
= new ppdcSource("sample.drv");
55 catalog
= new ppdcCatalog(NULL
);
57 catalog
->add_message("ISOLatin1");
58 catalog
->add_message("English");
60 // Add the media size strings...
61 ppdcMediaSize
*size
; // Current media size
63 for (size
= (ppdcMediaSize
*)src
->sizes
->first();
65 size
= (ppdcMediaSize
*)src
->sizes
->next())
66 catalog
->add_message(size
->text
->value
);
68 // Then collect all of the UI strings from the sample drivers...
69 ppdcDriver
*d
; // Current driver
71 for (d
= (ppdcDriver
*)src
->drivers
->first();
73 d
= (ppdcDriver
*)src
->drivers
->next())
74 add_ui_strings(d
, catalog
);
76 // Finally, write all of the strings...
79 for (message
= (ppdcMessage
*)catalog
->messages
->first();
81 message
= (ppdcMessage
*)catalog
->messages
->next())
82 write_cstring(message
->id
->value
);
87 // Return with no errors.
93 // 'add_ui_strings()' - Add all UI strings from the driver.
97 add_ui_strings(ppdcDriver
*d
, // I - Driver data
98 ppdcCatalog
*catalog
) // I - Message catalog
100 // Add the make/model/language strings...
101 catalog
->add_message(d
->manufacturer
->value
);
102 catalog
->add_message(d
->model_name
->value
);
104 // Add the group/option/choice strings...
105 ppdcGroup
*g
; // Current group
106 ppdcOption
*o
; // Current option
107 ppdcChoice
*c
; // Current choice
109 for (g
= (ppdcGroup
*)d
->groups
->first();
111 g
= (ppdcGroup
*)d
->groups
->next())
113 if (!g
->options
->count
)
116 if (_cups_strcasecmp(g
->name
->value
, "General"))
117 catalog
->add_message(g
->text
->value
);
119 for (o
= (ppdcOption
*)g
->options
->first();
121 o
= (ppdcOption
*)g
->options
->next())
123 if (!o
->choices
->count
)
126 if (o
->text
->value
&& strcmp(o
->name
->value
, o
->text
->value
))
127 catalog
->add_message(o
->text
->value
);
129 catalog
->add_message(o
->name
->value
);
131 for (c
= (ppdcChoice
*)o
->choices
->first();
133 c
= (ppdcChoice
*)o
->choices
->next())
134 if (c
->text
->value
&& strcmp(c
->name
->value
, c
->text
->value
))
135 catalog
->add_message(c
->text
->value
);
137 catalog
->add_message(c
->name
->value
);
141 // Add profile and preset strings...
142 ppdcAttr
*a
; // Current attribute
143 for (a
= (ppdcAttr
*)d
->attrs
->first();
145 a
= (ppdcAttr
*)d
->attrs
->next())
147 if (a
->text
->value
&& a
->text
->value
[0] &&
149 !strncmp(a
->name
->value
, "Custom", 6) ||
150 !strncmp(a
->name
->value
, "ParamCustom", 11) ||
151 !strcmp(a
->name
->value
, "APCustomColorMatchingName") ||
152 !strcmp(a
->name
->value
, "APPrinterPreset") ||
153 !strcmp(a
->name
->value
, "cupsICCProfile") ||
154 !strcmp(a
->name
->value
, "cupsIPPReason") ||
155 !strcmp(a
->name
->value
, "cupsMarkerName")))
157 catalog
->add_message(a
->text
->value
);
159 if ((a
->localizable
&& a
->value
->value
[0]) ||
160 !strcmp(a
->name
->value
, "cupsIPPReason"))
161 catalog
->add_message(a
->value
->value
);
163 else if (!strncmp(a
->name
->value
, "Custom", 6) ||
164 !strncmp(a
->name
->value
, "ParamCustom", 11))
165 catalog
->add_message(a
->name
->value
);
171 // 'write_cstring()' - Write a translation string as a valid C string to stdout.
175 write_cstring(const char *s
) /* I - String to write */
177 fputs("_(\"", stdout
);
183 fputs("\\\\", stdout
);
185 fputs("\\\"", stdout
);
187 fputs("\\t", stdout
);
189 fputs("\\n", stdout
);