Clarify confusing category stuff.
[pspp] / dump.c
diff --git a/dump.c b/dump.c
index 7665a4ccd0898cde3972beec00f7b6eb5efcd50f..e37202000c64f310a309f872ccbbd0ae2f46cc96 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -7,6 +7,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include "u8-mbtouc.h"
 
 static uint8_t *data;
 static size_t n;
@@ -178,6 +179,22 @@ dump_raw(FILE *stream, int start, int end)
 
 }
 
+static bool __attribute__((unused))
+all_utf8(const char *p_)
+{
+  const uint8_t *p = (const uint8_t *) p_;
+  size_t len = strlen ((char *) p);
+  for (size_t ofs = 0, mblen; ofs < len; ofs += mblen)
+    {
+      ucs4_t uc;
+
+      mblen = u8_mbtouc (&uc, p + ofs, len - ofs);
+      if ((uc < 32 && uc != '\n') || uc == 127 || uc == 0xfffd)
+        return false;
+    }
+  return true;
+}
+
 static char *
 get_string(const char *where)
 {
@@ -563,17 +580,16 @@ dump_category(int level, int *indexes, int *n_indexes, int max_indexes)
   match_byte(0);
   match_byte(0);
 
-  if (match_u32 (1))
-    match_byte (0);
-  else if (match_byte (1))
+  if (match_byte (1))
     {
-      match_byte (0);
-      if (!match_u32 (2))
-        match_u32_assert (1);
-      match_byte (0);
+      if (!match_byte (0) && !match_byte (1))
+        match_byte_assert (2);
     }
-  else if (!match_u32(2))
-    match_u32_assert (0);
+  else if (!match_byte (2))
+    match_byte_assert (0);
+  match_byte_assert (0);
+  match_byte_assert (0);
+  match_byte_assert (0);
 
   int indx = get_u32();
   int n_categories = get_u32();
@@ -612,7 +628,7 @@ dump_dim(int indx)
   printf ("<dimension index=\"%d\">\n", indx);
   dump_value (stdout, 0);
 
-  /* This byte is usually 0x02 but many other values have been spotted. */
+  /* This byte is usually 0 but many other values have been spotted. */
   pos++;
 
   if (!match_byte(0) && !match_byte(1))
@@ -734,15 +750,19 @@ dump_fonts(void)
       match_byte_assert(0);
       if (!match_byte(0x40) && !match_byte(0x20) && !match_byte(0x80) && !match_byte(0x10) && !match_byte(0x70))
         match_byte_assert(0x50);
-      if (!match_byte(0x41))
-        match_byte_assert(0x51);
+      match_byte_assert(0x41);
       if (!match_u32(0) && !match_u32(1))
         match_u32_assert(2);
       match_byte_assert(0);
 
       /* OK, this seems really unlikely to be totally correct, but it matches my corpus... */
       if (!match_u32(0) && !match_u32(2))
-        match_u32_assert(0xfaad);
+        {
+          if (i == 7)
+            match_u32_assert(0xfaad);
+          else
+            match_u32_assert(0);
+        }
 
       if (!match_u32(0) && !match_u32(1) && !match_u32(2))
         match_u32_assert(3);
@@ -754,7 +774,6 @@ dump_fonts(void)
 
       if (version > 1)
         {
-          /* These seem unlikely to be correct too. */
           if (i != 3)
             {
               if (!match_u32(8))