Merge remote branch 'origin/master' into import-gui
[pspp] / src / ui / gui / page-separators.c
index e153a231f53a296698ccbddd08e2a1f2198abecf..e147881730e710e6b70472806a2430c241071efa 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <config.h>
 
+#include "page-separators.h"
+
 #include "ui/gui/text-data-import-dialog.h"
 
 #include <errno.h>
@@ -157,10 +159,9 @@ separators_page_create (struct import_assistant *ia)
 
   struct separators_page *p = xzalloc (sizeof *p);
 
-#if 0
   p->page = add_page_to_assistant (ia, get_widget_assert (builder, "Separators"),
                                    GTK_ASSISTANT_PAGE_CONTENT);
-#endif
+
   p->custom_cb = get_widget_assert (builder, "custom-cb");
   p->custom_entry = get_widget_assert (builder, "custom-entry");
   p->quote_combo = get_widget_assert (builder, "quote-combo");
@@ -588,3 +589,28 @@ on_separator_toggle (GtkToggleButton *toggle UNUSED,
   revise_fields_preview (ia);
 }
 
+
+
+void 
+separators_append_syntax (const struct import_assistant *ia, struct string *s)
+{
+  int i;
+  ds_put_cstr (s, "  /DELIMITERS=\"");
+  if (ds_find_byte (&ia->separators->separators, '\t') != SIZE_MAX)
+    ds_put_cstr (s, "\\t");
+  if (ds_find_byte (&ia->separators->separators, '\\') != SIZE_MAX)
+    ds_put_cstr (s, "\\\\");
+  for (i = 0; i < ds_length (&ia->separators->separators); i++)
+    {
+      char c = ds_at (&ia->separators->separators, i);
+      if (c == '"')
+       ds_put_cstr (s, "\"\"");
+      else if (c != '\t' && c != '\\')
+       ds_put_byte (s, c);
+    }
+  ds_put_cstr (s, "\"\n");
+  if (!ds_is_empty (&ia->separators->quotes))
+    syntax_gen_pspp (s, "  /QUALIFIER=%sq\n", ds_cstr (&ia->separators->quotes));
+  if (!ds_is_empty (&ia->separators->quotes) && ia->separators->escape)
+    ds_put_cstr (s, "  /ESCAPE\n");
+}