pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp/src/data ChangeLog variable.c variable.h


From: Ben Pfaff
Subject: [Pspp-cvs] pspp/src/data ChangeLog variable.c variable.h
Date: Tue, 19 Feb 2008 06:41:25 +0000

CVSROOT:        /cvsroot/pspp
Module name:    pspp
Changes by:     Ben Pfaff <blp> 08/02/19 06:41:25

Modified files:
        src/data       : ChangeLog variable.c variable.h 

Log message:
        (var_create): Use the new functions for default variable attributes 
below.
        (var_default_formats): New function.
        (var_default_measure): New function.
        (var_default_alignment): New function.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/ChangeLog?cvsroot=pspp&r1=1.187&r2=1.188
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/variable.c?cvsroot=pspp&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/variable.h?cvsroot=pspp&r1=1.27&r2=1.28

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/ChangeLog,v
retrieving revision 1.187
retrieving revision 1.188
diff -u -b -r1.187 -r1.188
--- ChangeLog   19 Feb 2008 06:37:57 -0000      1.187
+++ ChangeLog   19 Feb 2008 06:41:25 -0000      1.188
@@ -8,6 +8,11 @@
        references.
        (max_decimals): Renamed fmt_max_decimals and made public.  Updated
        all references.
+       (var_create): Use the new functions for default variable
+       attributes below.
+       (var_default_formats): New function.
+       (var_default_measure): New function.
+       (var_default_alignment): New function.
 
        * format.h (macro FMT_MAX_NUMERIC_WIDTH): New macro.
 

Index: variable.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/variable.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- variable.c  2 Jan 2008 03:46:43 -0000       1.34
+++ variable.c  19 Feb 2008 06:41:25 -0000      1.35
@@ -86,6 +86,7 @@
 var_create (const char *name, int width)
 {
   struct variable *v;
+  enum val_type type;
 
   assert (width >= 0 && width <= MAX_STRING);
 
@@ -95,20 +96,11 @@
   v->width = width;
   mv_init (&v->miss, width);
   v->leave = var_must_leave (v);
-  if (var_is_numeric (v))
-    {
-      v->print = fmt_for_output (FMT_F, 8, 2);
-      v->alignment = ALIGN_RIGHT;
-      v->measure = MEASURE_SCALE;
-    }
-  else
-    {
-      v->print = fmt_for_output (FMT_A, var_get_width (v), 0);
-      v->alignment = ALIGN_LEFT;
-      v->measure = MEASURE_NOMINAL;
-    }
+  type = val_type_from_width (width);
+  v->alignment = var_default_alignment (type);
+  v->measure = var_default_measure (type);
   v->display_width = var_default_display_width (width);
-  v->write = v->print;
+  v->print = v->write = var_default_formats (width);
   v->val_labs = NULL;
   v->label = NULL;
   v->short_names = NULL;
@@ -597,8 +589,9 @@
 }
 
 /* Sets V's print format specification to PRINT, which must be a
-   valid format specification for outputting a variable of V's
-   width. */
+   valid format specification for a variable of V's width
+   (ordinarily an output format, but input formats are not
+   rejected). */
 void
 var_set_print_format (struct variable *v, const struct fmt_spec *print)
 {
@@ -615,8 +608,9 @@
 }
 
 /* Sets V's write format specification to WRITE, which must be a
-   valid format specification for outputting a variable of V's
-   width. */
+   valid format specification for a variable of V's width
+   (ordinarily an output format, but input formats are not
+   rejected). */
 void
 var_set_write_format (struct variable *v, const struct fmt_spec *write)
 {
@@ -626,8 +620,9 @@
 }
 
 /* Sets V's print and write format specifications to FORMAT,
-   which must be a valid format specification for outputting a
-   variable of V's width. */
+   which must be a valid format specification for a variable of
+   V's width (ordinarily an output format, but input formats are
+   not rejected). */
 void
 var_set_both_formats (struct variable *v, const struct fmt_spec *format)
 {
@@ -635,6 +630,18 @@
   var_set_write_format (v, format);
 }
 
+/* Returns the default print and write format for a variable of
+   the given TYPE, as set by var_create.  The return value can be
+   used to reset a variable's print and write formats to the
+   default. */
+struct fmt_spec
+var_default_formats (int width)
+{
+  return (width == 0
+          ? fmt_for_output (FMT_F, 8, 2)
+          : fmt_for_output (FMT_A, width, 0));
+}
+
 /* Return a string representing this variable, in the form most
    appropriate from a human factors perspective, that is, its
    variable label if it has one, otherwise its name. */
@@ -712,6 +719,16 @@
   dict_var_changed (v);
 }
 
+/* Returns the default measurement level for a variable of the
+   given TYPE, as set by var_create.  The return value can be
+   used to reset a variable's measurement level to the
+   default. */
+enum measure
+var_default_measure (enum val_type type)
+{
+  return type == VAL_NUMERIC ? MEASURE_SCALE : MEASURE_NOMINAL;
+}
+
 /* Returns V's display width, which applies only to GUIs. */
 int
 var_get_display_width (const struct variable *v)
@@ -760,6 +777,15 @@
   dict_var_changed (v);
 }
 
+/* Returns the default display alignment for a variable of the
+   given TYPE, as set by var_create.  The return value can be
+   used to reset a variable's display alignment to the default. */
+enum alignment
+var_default_alignment (enum val_type type)
+{
+  return type == VAL_NUMERIC ? ALIGN_RIGHT : ALIGN_LEFT;
+}
+
 /* Whether variables' values should be preserved from case to
    case. */
 

Index: variable.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/variable.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- variable.h  2 Jan 2008 03:46:43 -0000       1.27
+++ variable.h  19 Feb 2008 06:41:25 -0000      1.28
@@ -99,6 +99,8 @@
 void var_set_write_format (struct variable *, const struct fmt_spec *);
 void var_set_both_formats (struct variable *, const struct fmt_spec *);
 
+struct fmt_spec var_default_formats (int width);
+
 /* Variable labels. */
 const char *var_to_string (const struct variable *);
 const char *var_get_label (const struct variable *);
@@ -119,6 +121,8 @@
 enum measure var_get_measure (const struct variable *);
 void var_set_measure (struct variable *, enum measure);
 
+enum measure var_default_measure (enum val_type);
+
 /* GUI display width. */
 int var_get_display_width (const struct variable *);
 void var_set_display_width (struct variable *, int display_width);
@@ -138,6 +142,8 @@
 enum alignment var_get_alignment (const struct variable *);
 void var_set_alignment (struct variable *, enum alignment);
 
+enum alignment var_default_alignment (enum val_type);
+
 /* Whether variables' values should be preserved from case to
    case. */
 bool var_get_leave (const struct variable *);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]