+ struct hmapx_node *node;
+ struct converter *cvtr;
+
+ HMAPX_FOR_EACH (cvtr, node, &map)
+ {
+ free (cvtr->tocode);
+ free (cvtr->fromcode);
+ if (cvtr->conv != (iconv_t) -1)
+ iconv_close (cvtr->conv);
+ free (cvtr);
+ }
+
+ hmapx_destroy (&map);
+
+ free (default_encoding);
+ default_encoding = NULL;
+}
+
+
+
+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 */
+char
+get_system_decimal (void)
+{
+ char radix_char;
+
+ char *ol = xstrdup (setlocale (LC_NUMERIC, NULL));
+ setlocale (LC_NUMERIC, "");
+
+#if HAVE_NL_LANGINFO
+ radix_char = nl_langinfo (RADIXCHAR)[0];
+#else
+ {
+ char buf[10];
+ snprintf (buf, sizeof buf, "%f", 2.5);
+ radix_char = buf[1];
+ }
+#endif
+
+ /* We MUST leave LC_NUMERIC untouched, since it would
+ otherwise interfere with data_{in,out} */
+ setlocale (LC_NUMERIC, ol);
+ free (ol);
+ return radix_char;
+}
+
+const char *
+uc_name (ucs4_t uc, char buffer[16])
+{
+ if (uc >= 0x20 && uc < 0x7f)
+ snprintf (buffer, 16, "`%c'", uc);
+ else
+ snprintf (buffer, 16, "U+%04X", uc);
+ return buffer;
+}
+\f
+bool
+get_encoding_info (struct encoding_info *e, const char *name)
+{
+ const struct substring in = SS_LITERAL_INITIALIZER (
+ "\t\n\v\f\r "
+ "!\"#$%&'()*+,-./0123456789:;<=>?@"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`"
+ "abcdefghijklmnopqrstuvwxyz{|}~");
+
+ struct substring out, cr, lf, space;
+ bool ok;
+
+ memset (e, 0, sizeof *e);
+
+ cr = recode_substring_pool (name, "UTF-8", ss_cstr ("\r"), NULL);
+ lf = recode_substring_pool (name, "UTF-8", ss_cstr ("\n"), NULL);
+ space = recode_substring_pool (name, "UTF-8", ss_cstr (" "), NULL);
+ ok = (cr.length >= 1
+ && cr.length <= MAX_UNIT
+ && cr.length == lf.length
+ && cr.length == space.length);
+ if (!ok)
+ {
+ fprintf (stderr, "warning: encoding `%s' is not supported.\n", name);
+ ss_dealloc (&cr);
+ ss_dealloc (&lf);
+ ss_dealloc (&space);
+ ss_alloc_substring (&cr, ss_cstr ("\r"));
+ ss_alloc_substring (&lf, ss_cstr ("\n"));
+ ss_alloc_substring (&space, ss_cstr (" "));
+ }
+
+ e->unit = cr.length;
+ memcpy (e->cr, cr.string, e->unit);
+ memcpy (e->lf, lf.string, e->unit);
+ memcpy (e->space, space.string, e->unit);
+
+ ss_dealloc (&cr);
+ ss_dealloc (&lf);
+ ss_dealloc (&space);