X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fi18n.c;h=9658866056f01f7911c905e1d2d4896fb0288cbe;hb=3c70826f9e59d2008305ed8305554a532851f6d9;hp=a3dc08a1ff26982171e8b9cf9c15543e74a2d506;hpb=fe8dc2171009e90d2335f159d05f7e6660e24780;p=pspp diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index a3dc08a1ff..9658866056 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2006, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -694,34 +694,52 @@ get_encoding_info (struct encoding_info *e, const char *name) "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" "abcdefghijklmnopqrstuvwxyz{|}~"); - struct substring out, cr, lf; + 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); - ok = cr.length >= 1 && cr.length <= MAX_UNIT && cr.length == lf.length; + 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); out = recode_substring_pool ("UTF-8", name, in, NULL); e->is_ascii_compatible = ss_equals (in, out); ss_dealloc (&out); + if (!e->is_ascii_compatible && e->unit == 1) + { + out = recode_substring_pool ("UTF-8", name, ss_cstr ("A"), NULL); + e->is_ebcdic_compatible = (out.length == 1 + && (uint8_t) out.string[0] == 0xc1); + ss_dealloc (&out); + } + else + e->is_ebcdic_compatible = false; + return ok; } @@ -734,6 +752,15 @@ is_encoding_ascii_compatible (const char *encoding) return e.is_ascii_compatible; } +bool +is_encoding_ebcdic_compatible (const char *encoding) +{ + struct encoding_info e; + + get_encoding_info (&e, encoding); + return e.is_ebcdic_compatible; +} + /* Returns true if iconv can convert ENCODING to and from UTF-8, otherwise false. */ bool