pspp-convert: Add --labels and --recode options.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 07:50:47 +0000 (07:50 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 07:50:47 +0000 (07:50 +0000)
Requested by Dave Trollope <dave@knowledgehound.com>.

NEWS
doc/pspp-convert.texi
utilities/pspp-convert.1
utilities/pspp-convert.c

diff --git a/NEWS b/NEWS
index 9aeaca95eadab4276c85af2d8ed1ce075ec91729..8bbecdf01d9891b80a5854b228619c7f37b0cea3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -26,8 +26,12 @@ Changes from 1.2.0 to 1.3.0:
  * Plain text output is no longer divided into pages, since it is now
    rarely printed on paper.
 
- * The pspp-convert utility has new "-a", "-l", "--password-list"
-   options to search for an encrypted file's password.
+ * pspp-convert improvements:
+
+   - New "-a", "-l", "--password-list" options to search for an
+     encrypted file's password.
+
+   - New "--labels" and "--recode" options for CSV output.
 
  * Improvements to SAVE DATA COLLECTION support for MDD files.
 
index c84d556d8e96b1f0501e81037cbe14bac08f595b..92e15b3cc2406617d6e2750c576673fb200181a0 100644 (file)
@@ -95,6 +95,17 @@ Overrides the encoding in which character strings in @var{input} are
 interpreted.  This option is necessary because old SPSS system files,
 and SPSS/PC+ system files, do not self-identify their encoding.
 
+@item --labels
+By default, @command{pspp-convert} writes variables' values to CVS
+output files.  With this option, @command{pspp-convert} writes value
+labels.
+
+@item --recode
+By default, @command{pspp-convert} writes user-missing values to CVS
+output files as their regular values.  With this option,
+@command{pspp-convert} recodes them to system-missing values (which
+are written as a single space).
+
 @item -p @var{password}
 @item --password=@var{password}
 Specifies the password to use to decrypt an encrypted SPSS system file
index 86530ec76c550c898f857f2a5052b9aa4ebbf685..c568e3c0fc52d56cc27f72e2bbf14b247c589d2a 100644 (file)
@@ -81,6 +81,17 @@ Overrides the encoding in which character strings in \fIinput\fR are
 interpreted.  This option is necessary because old SPSS system files
 do not self-identify their encoding.
 .
+.SS "CSV Output Options"
+.PP
+These options affect only output to \fB.csv\fR and \fB.txt\fR files.
+.IP "\fB\-\-labels\fR"
+By default, \fBpspp\-convert\fR writes variables' values to the output.
+With this option, \fBpspp\-convert\fR writes value labels.
+.IP "\fB\-\-recode\fR"
+By default, \fBpspp\-convert\fR writes user-missing values as their
+regular values.  With this option, \fBpspp\-convert\fR recodes them to
+system-missing values (which are written as a single space).
+.
 .SS "Password Options"
 When the input file is encrypted, \fBpspp\-convert\fR needs to obtain
 a password to decrypt it.  To do so, the user may specify the password
index bb04abbfb20c0f38e08f102964aaa9937cb6659c..f7504c2bd8985f6bbf116510f78688449afc0fc0 100644 (file)
@@ -75,6 +75,9 @@ main (int argc, char *argv[])
   const char *password_list = NULL;
   int length = 0;
 
+  bool recode_user_missing = false;
+  bool use_value_labels = false;
+
   long long int i;
 
   set_program_name (argv[0]);
@@ -87,12 +90,17 @@ main (int argc, char *argv[])
       enum
         {
           OPT_PASSWORD_LIST = UCHAR_MAX + 1,
+          OPT_LABELS,
+          OPT_RECODE,
         };
       static const struct option long_options[] =
         {
           { "cases",    required_argument, NULL, 'c' },
           { "encoding", required_argument, NULL, 'e' },
 
+          { "labels", no_argument, NULL, OPT_LABELS },
+          { "recode", no_argument, NULL, OPT_RECODE },
+
           { "password", required_argument, NULL, 'p' },
           { "password-alphabet", required_argument, NULL, 'a' },
           { "password-length", required_argument, NULL, 'l' },
@@ -133,6 +141,14 @@ main (int argc, char *argv[])
           password_list = optarg;
           break;
 
+        case OPT_LABELS:
+          use_value_labels = true;
+          break;
+
+        case OPT_RECODE:
+          recode_user_missing = true;
+          break;
+
         case 'a':
           for (const char *p = optarg; *p; )
             if (p[1] == '-' && p[2] > p[0])
@@ -202,6 +218,8 @@ main (int argc, char *argv[])
 
       csv_writer_options_init (&options);
       options.include_var_names = true;
+      options.use_value_labels = use_value_labels;
+      options.recode_user_missing = recode_user_missing;
       writer = csv_writer_open (output_fh, dict, &options);
     }
   else if (!strcmp (output_format, "sav") || !strcmp (output_format, "sys"))