pspp-convert: Add --labels and --recode options.
[pspp] / utilities / pspp-convert.c
index 4a2f0f029127b176aa84f983c72be422a4ca38fc..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])
@@ -184,24 +200,11 @@ main (int argc, char *argv[])
   output_fh = fh_create_file (NULL, output_filename, NULL, fh_default_properties ());
   if (encrypted_file_open (&enc, input_fh) > 0)
     {
-      if (encrypted_file_is_sav (enc))
-        {
-          if (strcmp (output_format, "sav") && strcmp (output_format, "sys"))
-            error (1, 0, _("can only convert encrypted data file to sav or "
-                           "sys format"));
-        }
-      else
-        {
-          if (strcmp (output_format, "sps"))
-            error (1, 0, _("can only convert encrypted syntax file to sps "
-                           "format"));
-        }
-
-      if (!decrypt_file (enc, input_fh, output_fh, password,
+      if (decrypt_file (enc, input_fh, output_fh, password,
                          ds_cstr (&alphabet), length, password_list))
+        goto exit;
+      else
        goto error;
-
-      goto exit;
     }
 
 
@@ -215,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"))