If sys files have no long_name table, implicitly add one, use the lower case
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 20 Apr 2007 11:04:55 +0000 (11:04 +0000)
committerJohn Darrington <john@darrington.wattle.id.au>
Fri, 20 Apr 2007 11:04:55 +0000 (11:04 +0000)
version of the variable names.

src/data/ChangeLog
src/data/sys-file-reader.c
tests/ChangeLog
tests/command/no_case_size.sh
tests/command/sysfiles-old.sh

index 1c616aebbb4c90016df34c41834bf01379c03b6f..b5a299ad6dd86f67606d326149329843a6e5b738 100644 (file)
@@ -1,3 +1,9 @@
+2007-04-19 John Darrington <john@darrington.wattle.id.au>
+
+       * sys-file-reader.c: When reading a system file which has no 
+       long name table, automatically create one where the long names 
+       are the lower case versions of the short names.
+       
 2007-04-16 John Darrington <john@darrington.wattle.id.au>
 
        * sys-file-reader.c: Some versions of Other Software seem to 
index 281edcbcadee23794b517cc6d888b6dfb72e2425..d04a757f3d60d89e12cb0ba1f0044485695148b8 100644 (file)
@@ -76,6 +76,7 @@ struct sfm_reader
     int value_cnt;             /* Number of 8-byte units per case. */
     struct sfm_var *vars;       /* Variables. */
     size_t var_cnt;             /* Number of variables. */
+    bool has_long_var_names;    /* File has a long variable name map */
     bool has_vls;               /* File has one or more very long strings? */
 
     /* Decompression. */
@@ -192,6 +193,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict,
   r->error = false;
   r->value_cnt = 0;
   r->has_vls = false;
+  r->has_long_var_names = false;
   r->opcode_idx = sizeof r->opcodes;
 
   if (setjmp (r->bail_out)) 
@@ -250,6 +252,33 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict,
       rec_type = read_int32 (r);
     }
 
+
+  if ( ! r->has_long_var_names )
+    {
+      int i;
+      for (i = 0; i < dict_get_var_cnt (*dict); i++)
+       {
+         struct variable *var = dict_get_var (*dict, i);
+         char short_name [SHORT_NAME_LEN + 1];
+         char long_name [SHORT_NAME_LEN + 1];
+         char *s = short_name;
+         char *d = long_name;
+
+         strcpy (short_name, var_get_name (var));
+
+         strcpy (long_name, short_name);
+         str_lowercase (long_name);
+
+         /* Set long name.  Renaming a variable may clear the short
+            name, but we want to retain it, so re-set it
+            explicitly. */
+         dict_rename_var (*dict, var, long_name);
+         var_set_short_name (var, short_name);
+       }
+
+      r->has_long_var_names = true;
+    }
+
   /* Read record 999 data, which is just filler. */
   read_int32 (r);
 
@@ -880,6 +909,7 @@ read_long_var_name_map (struct sfm_reader *r, size_t size, size_t count,
       var_set_short_name (var, short_name);
     }
   close_variable_to_value_map (r, map);
+  r->has_long_var_names = true;
 }
 
 /* Reads record type 7, subtype 14, which gives the real length
index 1c8eff1fc750586efb7cd169c0a306421e6e243d..4a549761783460c4c97793aeffd45984ace778cb 100644 (file)
@@ -1,3 +1,9 @@
+2007-04-19 John Darrington <john@darrington.wattle.id.au>
+       
+        * tests/command/no_case_size.sh tests/command/sysfiles-old.sh :
+       Changed tests to reflect new behaviour (case changing) when
+       reading system files with no long name table.
+
 2007-04-15  Ben Pfaff  <blp@gnu.org>
 
        * automake.mk: Add recode.sh to tests.
index d9016eb9c05d858f9cbcea55fa7116ae88a43be2..738ea1404791fe22963f40f2e3fa92b6fb12d4af 100755 (executable)
@@ -78,19 +78,19 @@ diff -b -w pspp.list - <<EOF
 +--------+-------------------------------------------+--------+
 |Variable|Description                                |Position|
 #========#===========================================#========#
-|CONT    |continents of the world                    |       1|
+|cont    |continents of the world                    |       1|
 |        |Format: A32                                |        |
 +--------+-------------------------------------------+--------+
-|SIZE    |sq km                                      |       2|
+|size    |sq km                                      |       2|
 |        |Format: F8.2                               |        |
 +--------+-------------------------------------------+--------+
-|POP     |population                                 |       3|
+|pop     |population                                 |       3|
 |        |Format: F8.2                               |        |
 +--------+-------------------------------------------+--------+
-|COUNT   |number of countries                        |       4|
+|count   |number of countries                        |       4|
 |        |Format: F8.2                               |        |
 +--------+-------------------------------------------+--------+
-                            CONT     SIZE      POP    COUNT
+                            cont     size      pop    count
 -------------------------------- -------- -------- --------
 Asia                             44579000 3.7E+009    44.00 
 Africa                           30065000 7.8E+008    53.00 
index d199172477c40287bba503474ccb4c5115e790ab..81ef556cfc454bd4af73645f429f07ba27ae2fd1 100755 (executable)
@@ -95,7 +95,7 @@ if [ $? -eq 0 ] ; then fail ; fi
 activity="compare output"
 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
 diff -b  -w $TEMPDIR/pspp.list - << EOF
-       X VARIABLE VARIAB_A VARIAB_B
+       x variable variab_a variab_b
 -------- -------- -------- --------
     1.00     1.00     1.00     2.00 
     1.00     1.00     2.00    30.00