sys-file: Support EBCDIC magic number in system files.
[pspp] / src / libpspp / i18n.c
index a3dc08a1ff26982171e8b9cf9c15543e74a2d506..149ad6fb2fa4a396a60fcb4d1d11963123c180ef 100644 (file)
@@ -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
@@ -722,6 +722,16 @@ get_encoding_info (struct encoding_info *e, const char *name)
   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 +744,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