VARIABLE ROLE: Use correct system file representation.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 27 Aug 2013 05:04:59 +0000 (22:04 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 27 Aug 2013 05:18:36 +0000 (22:18 -0700)
Thanks to Paul Vella, Alan Mead, and Bastián Díaz for helping with this.

src/data/sys-file-reader.c
src/data/sys-file-writer.c
src/data/variable.c
src/data/variable.h
src/language/dictionary/sys-file-info.c
src/language/dictionary/variable-display.c
src/ui/gui/psppire-var-sheet.c
src/ui/gui/text-data-import-dialog.c
tests/data/sys-file-reader.at
tests/language/dictionary/variable-display.at

index d38113e2883a47fb237548b856ab95cceb57e55a..4138fa912806f5934842452979cc0f51c2e5b13f 100644 (file)
@@ -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);
 }
 
index 1b73e737c1bca6efcaf1ccecf799ae0c8d2c18bf..2369370ca10a2fd09f4a0b80169912033542f665 100644 (file)
@@ -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;
 
index d3f9addc4c1c4d1a4dbc23d7491ae756a748d3c8..9f21b1497be391e5a1ea635a61f7d7d9602b8085 100644 (file)
@@ -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";
 
index e8f5f101469c1514587b0f24d9b053df5919f3fa..3210a78f9a8456e483f7684208622e2d6339b640 100644 (file)
@@ -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
   };
index 1ce94aa91fab83aee356ad0bf15bf31b39550f76..363d5b63b6eb0e5542047bc711d238547db838d5 100644 (file)
@@ -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));
index 9e50551c92b9a17359af658d947014762fb78bc2..63bc6d472c6f4c8b01ac221b339ab6e5d518a3e9 100644 (file)
@@ -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;
index df4718696dbd29faf01b8432287c34ff5f4a3c03..b5f305cee38c25c7a08e45cc354fb2560ae12d31 100644 (file)
@@ -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);
index 198a1687a847dc5ab9b4f60115cd4f177c6ea05c..6214d5ebae4fc05d51df3d3293b3658f4c508faa 100644 (file)
@@ -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))
index ab7251537ea9f2bb21ec4b7fe5f8b4e92e8f831b..19ae53687fcc31fee0ff2b818b3ffe4f9a948550 100644 (file)
@@ -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,
index ef545d9d16ed3933b0115e015fd10a52cf93aca8..c42fc629e25a42b504d37d97c68da65642fb79c2 100644 (file)
@@ -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,,
 ])