Enable the syntax generation
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 14 Feb 2013 18:37:56 +0000 (19:37 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 16 Feb 2013 14:04:11 +0000 (15:04 +0100)
src/ui/gui/page-sheet-spec.c
src/ui/gui/text-data-import-dialog.c

index 041bf080dee7883cffb353cdcca8a8c96f540c5a..b68180bf04cef7c4cdd7ec43e7d867d066c436b8 100644 (file)
@@ -80,6 +80,46 @@ struct sheet_spec_page
     struct spreadsheet_read_options opts;
   };
 
+
+char *
+sheet_spec_gen_syntax (const struct import_assistant *ia)
+{
+  const struct sheet_spec_page *ssp = ia->sheet_spec;
+
+  struct string s = DS_EMPTY_INITIALIZER;
+
+  syntax_gen_pspp (&s,
+                  "GET DATA"
+                  "\n  /TYPE=%ss"
+                  "\n  /FILE=%sq"
+                  "\n  /SHEET=index %d"
+                  "\n  /READNAMES=%ss",
+                  (ia->spreadsheet->type == SPREADSHEET_GNUMERIC) ? "GNM" : "ODS",
+                  ia->file.file_name,                   
+                  ssp->opts.sheet_index,
+                  ssp->sri.read_names ? "ON" : "OFF");
+
+
+  if ( ssp->opts.cell_range)
+    {
+      syntax_gen_pspp (&s,
+                      "\n  /CELLRANGE=RANGE %sq",
+                      ssp->opts.cell_range);
+    }
+  else
+    {
+      syntax_gen_pspp (&s,
+                      "\n  /CELLRANGE=FULL");
+    }
+
+
+  syntax_gen_pspp (&s, ".");
+
+  
+  return ds_cstr (&s);
+}
+
+
 static void 
 on_sheet_combo_changed (GtkComboBox *cb, struct import_assistant *ia)
 {
@@ -249,16 +289,16 @@ update_assistant (struct import_assistant *ia)
            {
              char *ss;
              const struct variable *var = dict_get_var (ssp->dict, col);
-
+             
              ia->columns[col].contents = xrealloc (ia->columns[col].contents,
-                                                     sizeof (struct substring) * rows);
-
+                                                   sizeof (struct substring) * rows);
+             
              ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict), 
                             var_get_print_format (var));
-
+             
              ia->columns[col].contents[rows - 1] = ss_cstr (ss);
            }
-
+         
          if (rows > MAX_PREVIEW_LINES)
            {
              case_unref (c);
index 22425b96ab58c52c45c8defebee9baa38016d838..94fc9300d76b9fc27dfdd1cd691affcc7eb8652f 100644 (file)
@@ -214,8 +214,7 @@ generate_syntax (const struct import_assistant *ia)
 {
   struct string s = DS_EMPTY_INITIALIZER;
 
-#if 0
-  if (ssp->spreadsheet == NULL)
+  if (ia->spreadsheet == NULL)
     {
       size_t var_cnt;
       size_t i;
@@ -232,6 +231,8 @@ generate_syntax (const struct import_assistant *ia)
       ds_put_cstr (&s,
                   "  /ARRANGEMENT=DELIMITED\n"
                   "  /DELCASE=LINE\n");
+
+#if 0
       if (ia->first_line->skip_lines > 0)
        ds_put_format (&s, "  /FIRSTCASE=%d\n", ia->first_line->skip_lines + 1);
       ds_put_cstr (&s, "  /DELIMITERS=\"");
@@ -265,42 +266,15 @@ generate_syntax (const struct import_assistant *ia)
                         i == var_cnt - 1 ? "." : "");
        }
 
+
       apply_dict (ia->formats->dict, &s);
+#endif
     }
   else
-
     {
-      const struct sheet_spec_page *ssp = ia->sheet_spec;
-
-      syntax_gen_pspp (&s,
-                      "GET DATA"
-                      "\n  /TYPE=%ss"
-                      "\n  /FILE=%sq"
-                      "\n  /SHEET=index %d"
-                      "\n  /READNAMES=%ss",
-                      (ssp->spreadsheet->type == SPREADSHEET_GNUMERIC) ? "GNM" : "ODS",
-                      ia->file.file_name,                       
-                      ssp->opts.sheet_index,
-                      ssp->sri.read_names ? "ON" : "OFF");
-
-
-      if ( ssp->opts.cell_range)
-       {
-         syntax_gen_pspp (&s,
-                          "\n  /CELLRANGE=RANGE %sq",
-                          ssp->opts.cell_range);
-       }
-      else
-       {
-         syntax_gen_pspp (&s,
-                          "\n  /CELLRANGE=FULL");
-       }
-
-
-      syntax_gen_pspp (&s, ".");
+      return sheet_spec_gen_syntax (ia);
     }
 
-#endif
   return ds_cstr (&s);
 }