X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fi18n.c;h=c0459712e71480dba9503aaa9260a28ac115f4c6;hb=ef35211c05259417e4f3dd4a7de44e92e4bc54a3;hp=36215b700c574ee6d9ef69acadc1e684cbde99e5;hpb=be89f5708c5ab602642d3d297f84e9f32931a2f2;p=pspp diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index 36215b700c..c0459712e7 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -204,6 +204,62 @@ i18n_init (void) } +const char * +get_default_encoding (void) +{ + return default_encoding; +} + +void +set_default_encoding (const char *enc) +{ + free (default_encoding); + default_encoding = strdup (enc); +} + + +/* Attempts to set the encoding from a locale name + returns true if successfull. + This function does not (should not!) alter the current locale. +*/ +bool +set_encoding_from_locale (const char *loc) +{ + bool ok = true; + char *c_encoding; + char *loc_encoding; + char *tmp = strdup (setlocale (LC_CTYPE, NULL)); + + setlocale (LC_CTYPE, "C"); + c_encoding = strdup (locale_charset ()); + + setlocale (LC_CTYPE, loc); + loc_encoding = strdup (locale_charset ()); + + + if ( 0 == strcmp (loc_encoding, c_encoding)) + { + ok = false; + } + + + setlocale (LC_CTYPE, tmp); + + free (tmp); + + if (ok) + { + free (default_encoding); + default_encoding = loc_encoding; + } + else + free (loc_encoding); + + free (c_encoding); + + return ok; +} + void i18n_done (void) { @@ -220,6 +276,19 @@ i18n_done (void) +bool +valid_encoding (const char *enc) +{ + iconv_t conv = iconv_open ("UTF8", enc); + + if ( conv == (iconv_t) -1) + return false; + + iconv_close (conv); + + return true; +} + /* Return the system local's idea of the decimal seperator character */