27#ifdef HAVE_LANGINFO_CODESET
32#include <libcharset.h>
50# define local_encoding get_local_encoding()
51# define data_encoding get_local_encoding()
52# define internal_encoding get_local_encoding()
61 char *buf,
size_t bufsz)
71 bool my_use_transliteration)
75 if (my_use_transliteration) {
93#ifdef HAVE_LANGINFO_CODESET
127#ifdef FREECIV_ENABLE_NLS
132 fprintf(stderr,
"Encodings: Data=%s, Local=%s, Internal=%s\n",
139 _(
"You are running Freeciv without using iconv. Unless\n"
140 "you are using the UTF-8 character set, some characters\n"
141 "may not be displayed properly. You can download iconv\n"
142 "at https://gnu.org/.\n"));
166# ifdef HAVE_LIBCHARSET
167 return locale_charset();
169# ifdef HAVE_LANGINFO_CODESET
170 return nl_langinfo(CODESET);
199 char *buf,
size_t bufsz)
202 iconv_t cd = iconv_open(to, from);
203 size_t from_len = strlen(text) + 1, to_len;
204 bool alloc = (buf == NULL);
206 if (cd == (iconv_t) (-1)) {
219 fprintf(stderr,
_(
"Could not convert text from %s to %s: %s.\n"),
220 from, to, strerror(errno));
247 size_t flen = from_len, tlen = to_len, res;
248 const char *mytext = text;
259 iconv(cd, NULL, NULL, NULL, NULL);
261 res = iconv(cd, (ICONV_CONST
char **)&mytext, &flen, &myresult, &tlen);
262 if (res == (
size_t) (-1)) {
263 if (errno != E2BIG) {
266 fprintf(stderr,
"Invalid string conversion from %s to %s: %s.\n",
267 from, to, strerror(errno));
298 strncpy(buf, text,
bufsz);
299 buf[
bufsz - 1] =
'\0';
307#define CONV_FUNC_MALLOC(src, dst) \
308char *src ## _to_ ## dst ## _string_malloc(const char *text) \
310 const char *encoding1 = (dst ## _encoding); \
311 char encoding[strlen(encoding1) + strlen(transliteration_string) + 1]; \
313 fc_snprintf(encoding, sizeof(encoding), \
314 "%s%s", encoding1, transliteration_string); \
315 return convert_string(text, (src ## _encoding), \
316 (encoding), NULL, 0); \
319#define CONV_FUNC_BUFFER(src, dst) \
320char *src ## _to_ ## dst ## _string_buffer(const char *text, \
321 char *buf, size_t bufsz) \
323 const char *encoding1 = (dst ## _encoding); \
324 char encoding[strlen(encoding1) + strlen(transliteration_string) + 1]; \
326 fc_snprintf(encoding, sizeof(encoding), \
327 "%s%s", encoding1, transliteration_string); \
328 return convert_string(text, (src ## _encoding), \
329 encoding, buf, bufsz); \
332#define CONV_FUNC_STATIC(src, dst) \
333char *src ## _to_ ## dst ## _string_static(const char *text) \
335 (src ## _to_ ## dst ## _string_buffer)(text, \
337 sizeof(convert_buffer)); \
338 return convert_buffer; \
354void fc_fprintf(FILE *stream, const
char *format, ...)
369 va_start(ap, format);
375 output = internal_to_local_string_static(
string);
381 fputs(output, stream);
397 int text2[(strlen(text) + 1)];
402 (
char *)text2,
sizeof(text2));
407 if (text2[i] != 0x0000FEFF && text2[i] != 0xFFFE0000) {
size_t get_internal_string_length(const char *text)
#define CONV_FUNC_BUFFER(src, dst)
static char convert_buffer[4096]
static const char * transliteration_string
void fc_iconv_close(void)
#define CONV_FUNC_MALLOC(src, dst)
const char * get_data_encoding(void)
#define internal_encoding
static char * convert_string(const char *text, const char *from, const char *to, char *buf, size_t bufsz) fc__attribute((nonnull(1
const char * get_internal_encoding(void)
#define CONV_FUNC_STATIC(src, dst)
static char void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration)
const char * get_local_encoding(void)
#define FC_DEFAULT_DATA_ENCODING
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
#define fc_assert_ret_val(condition, val)
static int recursion[AIT_LAST]
int fc_snprintf(char *str, size_t n, const char *format,...)
int fc_strcasecmp(const char *str0, const char *str1)
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)