From: Ben Pfaff Date: Tue, 27 Aug 2013 05:04:59 +0000 (-0700) Subject: VARIABLE ROLE: Use correct system file representation. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1076f8e88e2eee1bc780edd9d79d696a38af936d;p=pspp VARIABLE ROLE: Use correct system file representation. Thanks to Paul Vella, Alan Mead, and Bastián Díaz for helping with this. --- diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index d38113e288..4138fa9128 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -1921,19 +1921,19 @@ assign_variable_roles (struct sfm_reader *r, struct dictionary *dict) switch (value) { case 0: - role = ROLE_NONE; + role = ROLE_INPUT; break; case 1: - role = ROLE_INPUT; + role = ROLE_OUTPUT; break; case 2: - role = ROLE_OUTPUT; + role = ROLE_BOTH; break; case 3: - role = ROLE_BOTH; + role = ROLE_NONE; break; case 4: @@ -1945,9 +1945,9 @@ assign_variable_roles (struct sfm_reader *r, struct dictionary *dict) break; default: - role = ROLE_NONE; + role = ROLE_INPUT; if (n_warnings++ == 0) - sys_warn (r, 0, _("Invalid role for variable %s."), + sys_warn (r, -1, _("Invalid role for variable %s."), var_get_name (var)); } @@ -1956,7 +1956,7 @@ assign_variable_roles (struct sfm_reader *r, struct dictionary *dict) } if (n_warnings > 1) - sys_warn (r, 0, _("%zu other variables had invalid roles."), + sys_warn (r, -1, _("%zu other variables had invalid roles."), n_warnings - 1); } diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index 1b73e737c1..2369370ca1 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -691,20 +691,20 @@ add_role_attribute (enum var_role role, struct attrset *attrs) switch (role) { - case ROLE_NONE: + case ROLE_INPUT: default: s = "0"; break; - case ROLE_INPUT: + case ROLE_OUTPUT: s = "1"; break; - case ROLE_OUTPUT: + case ROLE_BOTH: s = "2"; break; - case ROLE_BOTH: + case ROLE_NONE: s = "3"; break; diff --git a/src/data/variable.c b/src/data/variable.c index d3f9addc4c..9f21b1497b 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -103,7 +103,7 @@ var_create (const char *name, int width) type = val_type_from_width (width); v->alignment = var_default_alignment (type); v->measure = var_default_measure (type); - v->role = ROLE_NONE; + v->role = ROLE_INPUT; v->display_width = var_default_display_width (width); v->print = v->write = var_default_formats (width); attrset_init (&v->attributes); @@ -905,9 +905,6 @@ var_role_to_string (enum var_role role) { switch (role) { - case ROLE_NONE: - return _("None"); - case ROLE_INPUT: return _("Input"); @@ -917,6 +914,9 @@ var_role_to_string (enum var_role role) case ROLE_BOTH: return _("Both"); + case ROLE_NONE: + return _("None"); + case ROLE_PARTITION: return _("Partition"); @@ -934,9 +934,6 @@ var_role_to_syntax (enum var_role role) { switch (role) { - case ROLE_NONE: - return "NONE"; - case ROLE_INPUT: return "INPUT"; @@ -946,6 +943,9 @@ var_role_to_syntax (enum var_role role) case ROLE_BOTH: return "BOTH"; + case ROLE_NONE: + return "NONE"; + case ROLE_PARTITION: return "PARTITION"; diff --git a/src/data/variable.h b/src/data/variable.h index e8f5f10146..3210a78f9a 100644 --- a/src/data/variable.h +++ b/src/data/variable.h @@ -145,10 +145,10 @@ enum measure var_default_measure (enum val_type); /* Intended usage of a variable, for populating dialogs. */ enum var_role { - ROLE_NONE, ROLE_INPUT, ROLE_OUTPUT, ROLE_BOTH, + ROLE_NONE, ROLE_PARTITION, ROLE_SPLIT }; diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index 1ce94aa91f..363d5b63b6 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -504,7 +504,7 @@ describe_variable (const struct variable *v, struct tab_table *t, int r, measure_to_string (var_get_measure (v))); r++; - if (role != ROLE_NONE) + if (role != ROLE_INPUT) { tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, _("Role: %s"), var_role_to_string (role)); diff --git a/src/language/dictionary/variable-display.c b/src/language/dictionary/variable-display.c index 9e50551c92..63bc6d472c 100644 --- a/src/language/dictionary/variable-display.c +++ b/src/language/dictionary/variable-display.c @@ -208,7 +208,10 @@ cmd_variable_role (struct lexer *lexer, struct dataset *ds) else if ( lex_match_id (lexer, "SPLIT")) role = ROLE_SPLIT; else - return CMD_FAILURE; + { + lex_error (lexer, NULL); + return CMD_FAILURE; + } if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE)) return CMD_FAILURE; diff --git a/src/ui/gui/psppire-var-sheet.c b/src/ui/gui/psppire-var-sheet.c index df4718696d..b5f305cee3 100644 --- a/src/ui/gui/psppire-var-sheet.c +++ b/src/ui/gui/psppire-var-sheet.c @@ -277,14 +277,14 @@ on_var_column_edited (GtkCellRendererText *cell, break; case VS_ROLE: - if (!strcmp (new_text, var_role_to_string (ROLE_NONE))) - var_set_role (var, ROLE_NONE); - else if (!strcmp (new_text, var_role_to_string (ROLE_INPUT))) + if (!strcmp (new_text, var_role_to_string (ROLE_INPUT))) var_set_role (var, ROLE_INPUT); else if (!strcmp (new_text, var_role_to_string (ROLE_OUTPUT))) var_set_role (var, ROLE_OUTPUT); else if (!strcmp (new_text, var_role_to_string (ROLE_BOTH))) var_set_role (var, ROLE_BOTH); + else if (!strcmp (new_text, var_role_to_string (ROLE_NONE))) + var_set_role (var, ROLE_NONE); else if (!strcmp (new_text, var_role_to_string (ROLE_PARTITION))) var_set_role (var, ROLE_PARTITION); else if (!strcmp (new_text, var_role_to_string (ROLE_SPLIT))) @@ -1300,10 +1300,10 @@ psppire_var_sheet_init (PsppireVarSheet *obj) column, cell, render_var_cell, obj, NULL); add_combo_column (obj, VS_ROLE, _("Role"), 12, - var_role_to_string (ROLE_NONE), ROLE_NONE, var_role_to_string (ROLE_INPUT), ROLE_INPUT, var_role_to_string (ROLE_OUTPUT), ROLE_OUTPUT, var_role_to_string (ROLE_BOTH), ROLE_BOTH, + var_role_to_string (ROLE_NONE), ROLE_NONE, var_role_to_string (ROLE_PARTITION), ROLE_PARTITION, var_role_to_string (ROLE_SPLIT), ROLE_SPLIT, NULL); diff --git a/src/ui/gui/text-data-import-dialog.c b/src/ui/gui/text-data-import-dialog.c index 198a1687a8..6214d5ebae 100644 --- a/src/ui/gui/text-data-import-dialog.c +++ b/src/ui/gui/text-data-import-dialog.c @@ -214,7 +214,7 @@ apply_dict (const struct dictionary *dict, struct string *s) if (measure != var_default_measure (type)) syntax_gen_pspp (s, "VARIABLE LEVEL %ss (%ss).\n", name, measure_to_syntax (measure)); - if (role != ROLE_NONE) + if (role != ROLE_INPUT) syntax_gen_pspp (s, "VARIABLE ROLE /%ss %ss.\n", var_role_to_syntax (role), name); if (alignment != var_default_alignment (type)) diff --git a/tests/data/sys-file-reader.at b/tests/data/sys-file-reader.at index ab7251537e..19ae53687f 100644 --- a/tests/data/sys-file-reader.at +++ b/tests/data/sys-file-reader.at @@ -1111,7 +1111,7 @@ DISPLAY DICTIONARY. AT_CHECK([grep -v Measure pspp.csv | grep -v Display], [0], [[Variable,Description,,Position FirstVariable,Format: F8.0,,1 -,Role: Input,, +,Role: Output,, ,Custom attributes:,, ,adèle[1],23, ,adèle[2],34, diff --git a/tests/language/dictionary/variable-display.at b/tests/language/dictionary/variable-display.at index ef545d9d16..c42fc629e2 100644 --- a/tests/language/dictionary/variable-display.at +++ b/tests/language/dictionary/variable-display.at @@ -6,7 +6,7 @@ DATA LIST FREE /x y z. VARIABLE ALIGNMENT x (LEFT)/y (RIGHT)/z (CENTER). VARIABLE WIDTH x (10)/y (12)/z (14). VARIABLE LEVEL x (SCALE)/y (ORDINAL)/z (NOMINAL). -VARIABLE ROLE /INPUT x /TARGET y /BOTH z. +VARIABLE ROLE /TARGET x /BOTH y /NONE z. DISPLAY DICTIONARY. ]) AT_CHECK([pspp -o pspp.csv var-display.sps]) @@ -14,17 +14,17 @@ AT_CHECK([cat pspp.csv], [0], [dnl Variable,Description,,Position x,Format: F8.2,,1 ,Measure: Scale,, -,Role: Input,, +,Role: Output,, ,Display Alignment: Left,, ,Display Width: 10,, y,Format: F8.2,,2 ,Measure: Ordinal,, -,Role: Output,, +,Role: Both,, ,Display Alignment: Right,, ,Display Width: 12,, z,Format: F8.2,,3 ,Measure: Nominal,, -,Role: Both,, +,Role: None,, ,Display Alignment: Center,, ,Display Width: 14,, ])