]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
f7faf1f5 | 2 | * "$Id: langprintf.c 4924 2006-01-13 01:55:20Z mike $" |
ef416fc2 | 3 | * |
4 | * Localized printf/puts functions for the Common UNIX Printing | |
5 | * System (CUPS). | |
6 | * | |
fa73b229 | 7 | * Copyright 2002-2006 by Easy Software Products. |
ef416fc2 | 8 | * |
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 | |
14 | * at: | |
15 | * | |
16 | * Attn: CUPS Licensing Information | |
17 | * Easy Software Products | |
18 | * 44141 Airport View Drive, Suite 204 | |
19 | * Hollywood, Maryland 20636 USA | |
20 | * | |
21 | * Voice: (301) 373-9600 | |
22 | * EMail: cups-info@cups.org | |
23 | * WWW: http://www.cups.org | |
24 | * | |
25 | * This file is subject to the Apple OS-Developed Software exception. | |
26 | * | |
27 | * Contents: | |
28 | * | |
29 | * _cupsLangPrintf() - Print a formatted message string to a file. | |
30 | * _cupsLangPuts() - Print a static message string to a file. | |
31 | */ | |
32 | ||
33 | /* | |
34 | * Include necessary headers... | |
35 | */ | |
36 | ||
37 | #include <stdio.h> | |
fa73b229 | 38 | #include "globals.h" |
ef416fc2 | 39 | |
40 | ||
41 | /* | |
42 | * '_cupsLangPrintf()' - Print a formatted message string to a file. | |
43 | */ | |
44 | ||
45 | int /* O - Number of bytes written */ | |
46 | _cupsLangPrintf(FILE *fp, /* I - File to write to */ | |
ef416fc2 | 47 | const char *message, /* I - Message string to use */ |
48 | ...) /* I - Additional arguments as needed */ | |
49 | { | |
50 | int bytes; /* Number of bytes formatted */ | |
51 | char buffer[2048], /* Message buffer */ | |
52 | output[8192]; /* Output buffer */ | |
53 | va_list ap; /* Pointer to additional arguments */ | |
fa73b229 | 54 | _cups_globals_t *cg; /* Global data */ |
ef416fc2 | 55 | |
56 | ||
57 | /* | |
58 | * Range check... | |
59 | */ | |
60 | ||
61 | if (!fp || !message) | |
62 | return (-1); | |
63 | ||
fa73b229 | 64 | cg = _cupsGlobals(); |
65 | ||
66 | if (!cg->lang_default) | |
67 | cg->lang_default = cupsLangDefault(); | |
ef416fc2 | 68 | |
69 | /* | |
70 | * Format the string... | |
71 | */ | |
72 | ||
73 | va_start(ap, message); | |
74 | bytes = vsnprintf(buffer, sizeof(buffer), | |
fa73b229 | 75 | _cupsLangString(cg->lang_default, message), ap); |
ef416fc2 | 76 | va_end(ap); |
77 | ||
78 | /* | |
79 | * Transcode to the destination charset... | |
80 | */ | |
81 | ||
82 | bytes = cupsUTF8ToCharset(output, (cups_utf8_t *)buffer, sizeof(output), | |
fa73b229 | 83 | cg->lang_default->encoding); |
ef416fc2 | 84 | |
85 | /* | |
86 | * Write the string and return the number of bytes written... | |
87 | */ | |
88 | ||
89 | if (bytes > 0) | |
90 | return (fwrite(output, 1, bytes, fp)); | |
91 | else | |
92 | return (bytes); | |
93 | } | |
94 | ||
95 | ||
96 | /* | |
97 | * '_cupsLangPuts()' - Print a static message string to a file. | |
98 | */ | |
99 | ||
100 | int /* O - Number of bytes written */ | |
101 | _cupsLangPuts(FILE *fp, /* I - File to write to */ | |
ef416fc2 | 102 | const char *message) /* I - Message string to use */ |
103 | { | |
104 | int bytes; /* Number of bytes formatted */ | |
105 | char output[2048]; /* Message buffer */ | |
fa73b229 | 106 | _cups_globals_t *cg; /* Global data */ |
ef416fc2 | 107 | |
108 | ||
109 | /* | |
110 | * Range check... | |
111 | */ | |
112 | ||
113 | if (!fp || !message) | |
114 | return (-1); | |
115 | ||
fa73b229 | 116 | cg = _cupsGlobals(); |
117 | ||
118 | if (!cg->lang_default) | |
119 | cg->lang_default = cupsLangDefault(); | |
ef416fc2 | 120 | |
121 | /* | |
122 | * Transcode to the destination charset... | |
123 | */ | |
124 | ||
125 | bytes = cupsUTF8ToCharset(output, | |
fa73b229 | 126 | (cups_utf8_t *)_cupsLangString(cg->lang_default, |
127 | message), | |
128 | sizeof(output), cg->lang_default->encoding); | |
ef416fc2 | 129 | |
130 | /* | |
131 | * Write the string and return the number of bytes written... | |
132 | */ | |
133 | ||
134 | if (bytes > 0) | |
135 | return (fwrite(output, 1, bytes, fp)); | |
136 | else | |
137 | return (bytes); | |
138 | } | |
139 | ||
140 | ||
141 | /* | |
f7faf1f5 | 142 | * End of "$Id: langprintf.c 4924 2006-01-13 01:55:20Z mike $". |
ef416fc2 | 143 | */ |