]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/genstrings.cxx
709b083c104040d4d6bb7286079dff6b07d5ee7c
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 // 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
14 // file is missing or damaged, see the license at "http://www.cups.org/".
18 // ./genstrings >sample.c
22 // Include necessary headers...
25 #include "ppdc-private.h"
33 static void add_ui_strings(ppdcDriver
*d
, ppdcCatalog
*catalog
);
34 static void write_cstring(const char *s
);
38 // 'main()' - Main entry for the PPD compiler.
41 int // O - Exit status
44 ppdcSource
*src
; // PPD source file data
45 ppdcCatalog
*catalog
; // Catalog to hold all of the UI strings
48 // Make sure we are in the right place...
49 if (access("../data", 0) || access("sample.drv", 0))
51 puts("You must run genstrings from the ppdc directory.");
55 // Load the sample drivers...
56 ppdcSource::add_include("../data");
58 src
= new ppdcSource("sample.drv");
59 catalog
= new ppdcCatalog(NULL
);
61 catalog
->add_message("ISOLatin1");
62 catalog
->add_message("English");
64 // Add the media size strings...
65 ppdcMediaSize
*size
; // Current media size
67 for (size
= (ppdcMediaSize
*)src
->sizes
->first();
69 size
= (ppdcMediaSize
*)src
->sizes
->next())
70 catalog
->add_message(size
->text
->value
);
72 // Then collect all of the UI strings from the sample drivers...
73 ppdcDriver
*d
; // Current driver
75 for (d
= (ppdcDriver
*)src
->drivers
->first();
77 d
= (ppdcDriver
*)src
->drivers
->next())
78 add_ui_strings(d
, catalog
);
80 // Finally, write all of the strings...
83 for (message
= (ppdcMessage
*)catalog
->messages
->first();
85 message
= (ppdcMessage
*)catalog
->messages
->next())
86 write_cstring(message
->id
->value
);
91 // Return with no errors.
97 // 'add_ui_strings()' - Add all UI strings from the driver.
101 add_ui_strings(ppdcDriver
*d
, // I - Driver data
102 ppdcCatalog
*catalog
) // I - Message catalog
104 // Add the make/model/language strings...
105 catalog
->add_message(d
->manufacturer
->value
);
106 catalog
->add_message(d
->model_name
->value
);
108 // Add the group/option/choice strings...
109 ppdcGroup
*g
; // Current group
110 ppdcOption
*o
; // Current option
111 ppdcChoice
*c
; // Current choice
113 for (g
= (ppdcGroup
*)d
->groups
->first();
115 g
= (ppdcGroup
*)d
->groups
->next())
117 if (!g
->options
->count
)
120 if (_cups_strcasecmp(g
->name
->value
, "General"))
121 catalog
->add_message(g
->text
->value
);
123 for (o
= (ppdcOption
*)g
->options
->first();
125 o
= (ppdcOption
*)g
->options
->next())
127 if (!o
->choices
->count
)
130 if (o
->text
->value
&& strcmp(o
->name
->value
, o
->text
->value
))
131 catalog
->add_message(o
->text
->value
);
133 catalog
->add_message(o
->name
->value
);
135 for (c
= (ppdcChoice
*)o
->choices
->first();
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
);
141 catalog
->add_message(c
->name
->value
);
145 // Add profile and preset strings...
146 ppdcAttr
*a
; // Current attribute
147 for (a
= (ppdcAttr
*)d
->attrs
->first();
149 a
= (ppdcAttr
*)d
->attrs
->next())
151 if (a
->text
->value
&& a
->text
->value
[0] &&
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")))
161 catalog
->add_message(a
->text
->value
);
163 if ((a
->localizable
&& a
->value
->value
[0]) ||
164 !strcmp(a
->name
->value
, "cupsIPPReason"))
165 catalog
->add_message(a
->value
->value
);
167 else if (!strncmp(a
->name
->value
, "Custom", 6) ||
168 !strncmp(a
->name
->value
, "ParamCustom", 11))
169 catalog
->add_message(a
->name
->value
);
175 // 'write_cstring()' - Write a translation string as a valid C string to stdout.
179 write_cstring(const char *s
) /* I - String to write */
181 fputs("_(\"", stdout
);
187 fputs("\\\\", stdout
);
189 fputs("\\\"", stdout
);
191 fputs("\\t", stdout
);
193 fputs("\\n", stdout
);