From: John Darrington Date: Sat, 16 Feb 2013 15:54:57 +0000 (+0100) Subject: Got the text file import working again X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b74528713f14d1fd9e852f04d2a815a3967c5a5c;p=pspp Got the text file import working again --- diff --git a/src/ui/gui/page-first-line.c b/src/ui/gui/page-first-line.c index 4109f043ee..3296b50a43 100644 --- a/src/ui/gui/page-first-line.c +++ b/src/ui/gui/page-first-line.c @@ -50,7 +50,6 @@ #include "ui/gui/psppire-var-sheet.h" #include "ui/gui/psppire-var-store.h" #include "ui/gui/psppire-scanf.h" -#include "ui/syntax-gen.h" #include "gl/error.h" #include "gl/intprops.h" @@ -234,3 +233,12 @@ get_first_line (struct import_assistant *ia) gtk_widget_set_sensitive (ia->first_line->variable_names_cb, ia->skip_lines > 0); } + + + +void +first_line_append_syntax (struct import_assistant *ia, struct string *s) +{ + if (ia->skip_lines > 0) + ds_put_format (s, " /FIRSTCASE=%d\n", ia->skip_lines + 1); +} diff --git a/src/ui/gui/page-formats.c b/src/ui/gui/page-formats.c index 16438eeaee..d3d379a4f4 100644 --- a/src/ui/gui/page-formats.c +++ b/src/ui/gui/page-formats.c @@ -48,7 +48,6 @@ #include "ui/gui/psppire-var-sheet.h" #include "ui/gui/psppire-var-store.h" #include "ui/gui/psppire-scanf.h" -#include "ui/syntax-gen.h" #include "gl/error.h" #include "gl/intprops.h" @@ -269,3 +268,23 @@ on_variable_change (PsppireDict *dict, int dict_idx, } + + +void +formats_append_syntax (struct import_assistant *ia, struct string *s) +{ + int i; + int var_cnt; + ds_put_cstr (s, " /VARIABLES=\n"); + + var_cnt = dict_get_var_cnt (ia->dict); + for (i = 0; i < var_cnt; i++) + { + struct variable *var = dict_get_var (ia->dict, i); + char format_string[FMT_STRING_LEN_MAX + 1]; + fmt_to_string (var_get_print_format (var), format_string); + ds_put_format (s, " %s %s%s\n", + var_get_name (var), format_string, + i == var_cnt - 1 ? "." : ""); + } +} diff --git a/src/ui/gui/page-separators.c b/src/ui/gui/page-separators.c index fee511e0c3..185fa5b9a4 100644 --- a/src/ui/gui/page-separators.c +++ b/src/ui/gui/page-separators.c @@ -50,7 +50,6 @@ #include "ui/gui/psppire-var-sheet.h" #include "ui/gui/psppire-var-store.h" #include "ui/gui/psppire-scanf.h" -#include "ui/syntax-gen.h" #include "gl/error.h" #include "gl/intprops.h" @@ -589,3 +588,28 @@ on_separator_toggle (GtkToggleButton *toggle UNUSED, revise_fields_preview (ia); } + + +void +separators_append_syntax (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"); +} diff --git a/src/ui/gui/text-data-import-dialog.c b/src/ui/gui/text-data-import-dialog.c index ab7d743b1d..fe08caa9b1 100644 --- a/src/ui/gui/text-data-import-dialog.c +++ b/src/ui/gui/text-data-import-dialog.c @@ -231,50 +231,18 @@ generate_syntax (const struct import_assistant *ia) if (ia->file.encoding && strcmp (ia->file.encoding, "Auto")) syntax_gen_pspp (&s, " /ENCODING=%sq\n", ia->file.encoding); -#if 0 + intro_append_syntax (ia->intro, &s); + ds_put_cstr (&s, " /ARRANGEMENT=DELIMITED\n" " /DELCASE=LINE\n"); - - 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=\""); - 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"); - ds_put_cstr (&s, " /VARIABLES=\n"); - - var_cnt = dict_get_var_cnt (ia->formats->dict); - for (i = 0; i < var_cnt; i++) - { - struct variable *var = dict_get_var (ia->formats->dict, i); - char format_string[FMT_STRING_LEN_MAX + 1]; - fmt_to_string (var_get_print_format (var), format_string); - ds_put_format (&s, " %s %s%s\n", - var_get_name (var), format_string, - i == var_cnt - 1 ? "." : ""); - } - - - apply_dict (ia->formats->dict, &s); -#endif + first_line_append_syntax (ia, &s); + separators_append_syntax (ia, &s); + formats_append_syntax (ia, &s); + apply_dict (ia->dict, &s); } else {