]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/langprintf.c
2 * "$Id: langprintf.c 5833 2006-08-16 20:05:58Z mike $"
4 * Localized printf/puts functions for the Common UNIX Printing
7 * Copyright 2002-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Easy Software Products and are protected by Federal
11 * copyright law. Distribution and use rights are outlined in the file
12 * "LICENSE.txt" which should have been included with this file. If this
13 * file is missing or damaged please contact Easy Software Products
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44141 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636 USA
21 * Voice: (301) 373-9600
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
25 * This file is subject to the Apple OS-Developed Software exception.
29 * _cupsLangPrintf() - Print a formatted message string to a file.
30 * _cupsLangPuts() - Print a static message string to a file.
31 * _cupsSetLocale() - Set the current locale.
35 * Include necessary headers...
43 * '_cupsLangPrintf()' - Print a formatted message string to a file.
46 int /* O - Number of bytes written */
47 _cupsLangPrintf(FILE *fp
, /* I - File to write to */
48 const char *message
, /* I - Message string to use */
49 ...) /* I - Additional arguments as needed */
51 int bytes
; /* Number of bytes formatted */
52 char buffer
[2048], /* Message buffer */
53 output
[8192]; /* Output buffer */
54 va_list ap
; /* Pointer to additional arguments */
55 _cups_globals_t
*cg
; /* Global data */
67 if (!cg
->lang_default
)
68 cg
->lang_default
= cupsLangDefault();
71 * Format the string...
74 va_start(ap
, message
);
75 bytes
= vsnprintf(buffer
, sizeof(buffer
),
76 _cupsLangString(cg
->lang_default
, message
), ap
);
80 * Transcode to the destination charset...
83 bytes
= cupsUTF8ToCharset(output
, (cups_utf8_t
*)buffer
, sizeof(output
),
84 cg
->lang_default
->encoding
);
87 * Write the string and return the number of bytes written...
91 return (fwrite(output
, 1, bytes
, fp
));
98 * '_cupsLangPuts()' - Print a static message string to a file.
101 int /* O - Number of bytes written */
102 _cupsLangPuts(FILE *fp
, /* I - File to write to */
103 const char *message
) /* I - Message string to use */
105 int bytes
; /* Number of bytes formatted */
106 char output
[2048]; /* Message buffer */
107 _cups_globals_t
*cg
; /* Global data */
119 if (!cg
->lang_default
)
120 cg
->lang_default
= cupsLangDefault();
123 * Transcode to the destination charset...
126 bytes
= cupsUTF8ToCharset(output
,
127 (cups_utf8_t
*)_cupsLangString(cg
->lang_default
,
129 sizeof(output
), cg
->lang_default
->encoding
);
132 * Write the string and return the number of bytes written...
136 return (fwrite(output
, 1, bytes
, fp
));
143 * '_cupsSetLocale()' - Set the current locale.
150 const char *lc_time
; /* Current LC_TIME value */
151 char new_lc_time
[255], /* New LC_TIME value */
152 *charset
; /* Pointer to character set */
157 * Set the locale so that times, etc. are displayed properly.
159 * Unfortunately, while we need the localized time value, we *don't*
160 * want to use the localized charset for the time value, so we need
161 * to set LC_TIME to the locale name with .UTF-8 on the end (if
162 * the locale includes a character set specifier...)
165 setlocale(LC_ALL
, "");
168 if ((lc_time
= setlocale(LC_TIME
, NULL
)) == NULL
)
169 lc_time
= setlocale(LC_ALL
, NULL
);
173 strlcpy(new_lc_time
, lc_time
, sizeof(new_lc_time
));
174 if ((charset
= strchr(new_lc_time
, '.')) == NULL
)
175 charset
= new_lc_time
+ strlen(new_lc_time
);
177 strlcpy(charset
, ".UTF-8", sizeof(new_lc_time
) - (charset
- new_lc_time
));
180 strcpy(new_lc_time
, "C");
182 setlocale(LC_TIME
, new_lc_time
);
188 * End of "$Id: langprintf.c 5833 2006-08-16 20:05:58Z mike $".