Changed all the licence notices in all the files.
[pspp] / src / pfm-read.c
index 3e20f0396561344876a4ee23e44b9065e2148304..139532784f686f0a381fa879841261b50a9d1ee5 100644 (file)
@@ -16,8 +16,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA. */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
 
 #include <config.h>
 #include "pfm-read.h"
@@ -82,7 +82,7 @@ error (struct pfm_reader *r, const char *msg, ...)
   getl_location (&e.where.filename, &e.where.line_number);
   filename = handle_get_filename (r->fh);
   e.title = title = pool_alloc (r->pool, strlen (filename) + 80);
-  sprintf (e.title, _("portable file %s corrupt at offset %ld: "),
+  sprintf (title, _("portable file %s corrupt at offset %ld: "),
            filename, ftell (r->file));
 
   va_start (args, msg);
@@ -396,8 +396,11 @@ read_header (struct pfm_reader *r)
 
   /* Skip and verify signature. */
   for (i = 0; i < 8; i++) 
-    if (!match (r, "SPSSPORT"[i]))
-      error (r, _("Missing SPSSPORT signature."));
+    if (!match (r, "SPSSPORT"[i])) 
+      {
+        msg (SE, _("%s: Not a portable file."), handle_get_filename (r->fh));
+        longjmp (r->bail_out, 1);
+      }
 }
 
 /* Reads the version and date info record, as well as product and
@@ -494,7 +497,7 @@ read_variables (struct pfm_reader *r, struct dictionary *dict)
   if (match (r, '6'))
     {
       weight_name = read_pool_string (r);
-      if (strlen (weight_name) > 8
+      if (strlen (weight_name) > SHORT_NAME_LEN
         error (r, _("Weight variable name (%s) truncated."), weight_name);
     }
   
@@ -517,7 +520,29 @@ read_variables (struct pfm_reader *r, struct dictionary *dict)
       read_string (r, name);
       for (j = 0; j < 6; j++)
         fmt[j] = read_int (r);
+#if 0 
+        /* Weirdly enough, there is no # character in the SPSS portable
+        character set, so we can't check for it. */
+      if (strlen (name) > SHORT_NAME_LEN)
+       lose ((r, _("position %d: Variable name has %u characters."),
+              i, strlen (name)));
+      if ((name[0] < 74 /* A */ || name[0] > 125 /* Z */)
+         && name[0] != 152 /* @ */)
+       lose ((r, _("position %d: Variable name begins with invalid "
+                   "character."), i));
+      if (name[0] >= 100 /* a */ && name[0] <= 125 /* z */)
+       {
+         corrupt_msg (r, _("position %d: Variable name begins with "
+                           "lowercase letter %c."),
+                      i, name[0] - 100 + 'a');
+         name[0] -= 26 /* a - A */;
+       }
 
+      /* Verify remaining characters of variable name. */
+      for (j = 1; j < (int) strlen (name); j++)
+       {
+         int c = name[j];
+#endif
       if (!var_is_valid_name (name, false) || *name == '#') 
         error (r, _("position %d: Invalid variable name `%s'."), name);
       st_uppercase (name);