sys-file-reader: Successfully read files with duplicate names.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 8 Feb 2014 16:56:45 +0000 (08:56 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 8 Feb 2014 16:56:45 +0000 (08:56 -0800)
This allows PSPP to read some files written by SPSS.

Bug #41475.

NEWS
doc/dev/system-file-format.texi
src/data/sys-file-reader.c
tests/data/sys-file-reader.at

diff --git a/NEWS b/NEWS
index 4e7581c2434e83fcc114d14c836b849562f369e9..57de7877b2ad907e3d758c89c6451035698cb358 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,9 @@ Changes since 0.8.2:
    - File|Display Data File Information|External File... now allows an
      encoding to be selected.
 
+ * System files that contain duplicate variable names may now be read
+   successfully (bug #41475).
+
 Changes from 0.8.1 to 0.8.2:
 
  * Charts are now rendered with colours from the Tango palette instead
index 0da1997b3f7f8b611040d62aa9d17dfefd752c76..a480195857f8d027cc910d9c9ac76b6d6ff26fb7 100644 (file)
@@ -316,6 +316,13 @@ the at-sign (@samp{@@}).  Subsequent characters may also be digits, octothorpes
 (@samp{#}), dollar signs (@samp{$}), underscores (@samp{_}), or full
 stops (@samp{.}).  The variable name is padded on the right with spaces.
 
+The @samp{name} fields should be unique within a system file.  System
+files written by SPSS that contain very long string variables with
+similar names sometimes contain duplicate names that are later
+eliminated by resolving the very long string names (@pxref{Very Long
+String Record}).  PSPP handles duplicates by assigning them new,
+unique names.
+
 @item int32 label_len;
 This field is present only if @code{has_var_label} is set to 1.  It is
 set to the length, in characters, of the variable label.  The
index 9a4ef860423cd18193fc4fedb0514208d8dddecf..2c18abe322bdd94b0d38fc55b93316dcb9289344 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-2000, 2006-2007, 2009-2013 Free Software Foundation, Inc.
+   Copyright (C) 1997-2000, 2006-2007, 2009-2014 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
@@ -1090,7 +1090,14 @@ parse_variable_records (struct sfm_reader *r, struct dictionary *dict,
 
       var = rec->var = dict_create_var (dict, name, rec->width);
       if (var == NULL)
-        sys_error (r, rec->pos, _("Duplicate variable name `%s'."), name);
+        {
+          char *new_name = dict_make_unique_var_name (dict, NULL, NULL);
+          sys_warn (r, rec->pos, _("Renaming variable with duplicate name "
+                                   "`%s' to `%s'."),
+                    name, new_name);
+          var = rec->var = dict_create_var_assert (dict, new_name, rec->width);
+          free (new_name);
+        }
 
       /* Set the short name the same as the long name. */
       var_set_short_name (var, 0, name);
index 60d5ff705430c9fa14d2ea620d54c78007828a65..3bbc8060d6185896cefa0a81f05564ea18db2d02 100644 (file)
@@ -1755,6 +1755,8 @@ do
 done
 AT_CLEANUP
 
+dnl SPSS-generated system file can contain duplicate variable names
+dnl (see bug #41475).
 AT_SETUP([duplicate variable name])
 AT_KEYWORDS([sack synthetic system file negative])
 AT_DATA([sys-file.sack], [dnl
@@ -1777,9 +1779,20 @@ do
   AT_CHECK_UNQUOTED([sack --$[1] sys-file.sack > sys-file.sav], [0], [], [$[2]
 ])
   AT_DATA([sys-file.sps], [GET FILE='sys-file.sav'.
+DISPLAY DICTIONARY.
 ])
-  AT_CHECK([pspp -O format=csv sys-file.sps], [1], 
-   [error: `sys-file.sav' near offset 0xd4: Duplicate variable name `VAR1'.
+  AT_CHECK([pspp -O format=csv sys-file.sps], [0],
+   [warning: `sys-file.sav' near offset 0xd4: Renaming variable with duplicate name `VAR1' to `VAR001'.
+
+Variable,Description,,Position
+var1,Format: F8.0,,1
+,Measure: Scale,,
+,Display Alignment: Right,,
+,Display Width: 8,,
+var001,Format: F8.0,,2
+,Measure: Scale,,
+,Display Alignment: Right,,
+,Display Width: 8,,
 ])
 done
 AT_CLEANUP