pspp-cvs
[Top][All Lists]
Advanced

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

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


From: Ben Pfaff
Subject: [Pspp-cvs] pspp/src/data ChangeLog format.c format.h missi...
Date: Mon, 23 Jul 2007 04:44:12 +0000

CVSROOT:        /cvsroot/pspp
Module name:    pspp
Changes by:     Ben Pfaff <blp> 07/07/23 04:44:12

Modified files:
        src/data       : ChangeLog format.c format.h missing-values.c 
                         variable.c 

Log message:
        * variable.c (var_set_width): Use new var_set_width function.
        
        * missing-values.c (mv_n_values): Drop assertion, which was not
        needed.
        
        * format.c (fmt_default_for_width): New function.
        (fmt_resize): New function.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/ChangeLog?cvsroot=pspp&r1=1.135&r2=1.136
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/format.c?cvsroot=pspp&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/format.h?cvsroot=pspp&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/missing-values.c?cvsroot=pspp&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/variable.c?cvsroot=pspp&r1=1.27&r2=1.28

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/ChangeLog,v
retrieving revision 1.135
retrieving revision 1.136
diff -u -b -r1.135 -r1.136
--- ChangeLog   18 Jul 2007 00:50:58 -0000      1.135
+++ ChangeLog   23 Jul 2007 04:44:11 -0000      1.136
@@ -1,3 +1,13 @@
+2007-07-22  Ben Pfaff  <address@hidden>
+
+       * variable.c (var_set_width): Use new var_set_width function.
+
+       * missing-values.c (mv_n_values): Drop assertion, which was not
+       needed.
+
+       * format.c (fmt_default_for_width): New function.
+       (fmt_resize): New function.
+
 2007-07-18 John Darrington <address@hidden>
 
        * datasheet.c (datasheet_delete_columns): Added assertion to check

Index: format.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/format.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- format.c    7 Jul 2007 06:14:08 -0000       1.21
+++ format.c    23 Jul 2007 04:44:11 -0000      1.22
@@ -207,6 +207,16 @@
   return output;
 }
 
+/* Returns the default format for the given WIDTH: F8.2 format
+   for a numeric value, A format for a string value. */
+struct fmt_spec
+fmt_default_for_width (int width)
+{
+  return (width == 0
+          ? fmt_for_output (FMT_F, 8, 2)
+          : fmt_for_output (FMT_A, width, 0));
+}
+
 /* Checks whether SPEC is valid as an input format (if FOR_INPUT)
    or an output format (otherwise) and returns nonzero if so.
    Otherwise, emits an error message and returns zero. */
@@ -369,6 +379,28 @@
   return a->type == b->type && a->w == b->w && a->d == b->d;
 }
 
+/* Adjusts FMT to be valid for a value of the given WIDTH. */
+void
+fmt_resize (struct fmt_spec *fmt, int width) 
+{
+  if ((width > 0) != fmt_is_string (fmt->type))
+    {
+      /* Changed from numeric to string or vice versa.  Set to
+         default format for new width. */
+      *fmt = fmt_default_for_width (width);
+    }
+  else if (width > 0)
+    {
+      /* Changed width of string.  Preserve format type, adjust
+         width. */
+      fmt->w = fmt->type == FMT_AHEX ? width * 2 : width;
+    }
+  else 
+    {
+      /* Still numeric. */
+    }
+}
+
 /* Describes a display format. */
 struct fmt_desc
   {

Index: format.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/format.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- format.h    7 Jul 2007 06:14:09 -0000       1.15
+++ format.h    23 Jul 2007 04:44:11 -0000      1.16
@@ -87,6 +87,7 @@
 int fmt_var_width (const struct fmt_spec *);
 char *fmt_to_string (const struct fmt_spec *, char s[FMT_STRING_LEN_MAX + 1]);
 bool fmt_equal (const struct fmt_spec *, const struct fmt_spec *);
+void fmt_resize (struct fmt_spec *, int new_width);
 
 /* Format types. */
 const char *fmt_name (enum fmt_type) PURE_FUNCTION;

Index: missing-values.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/missing-values.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- missing-values.c    7 Jul 2007 06:14:09 -0000       1.11
+++ missing-values.c    23 Jul 2007 04:44:12 -0000      1.12
@@ -208,11 +208,11 @@
 }
 
 
-
+/* Returns the number of individual (not part of a range) missing
+   values in MV. */
 int
 mv_n_values (const struct missing_values *mv)
 {
-  assert(mv_has_value(mv));
   return mv->type & 3;
 }
 

Index: variable.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/data/variable.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- variable.c  18 Jul 2007 00:50:58 -0000      1.27
+++ variable.c  23 Jul 2007 04:44:12 -0000      1.28
@@ -351,7 +351,6 @@
 var_set_width (struct variable *v, int new_width)
 {
   const int old_width = v->width;
-  enum var_type new_type = var_type_from_width (new_width);
 
   if (mv_is_resizable (&v->miss, new_width))
     mv_resize (&v->miss, new_width);
@@ -369,18 +368,8 @@
         }
     }
 
-  if (var_get_type (v) != new_type)
-    {
-      v->print = (new_type == VAR_NUMERIC
-                  ? fmt_for_output (FMT_F, 8, 2)
-                  : fmt_for_output (FMT_A, new_width, 0));
-      v->write = v->print;
-    }
-  else if (new_type == VAR_STRING)
-    {
-      v->print.w = v->print.type == FMT_AHEX ? new_width * 2 : new_width;
-      v->write.w = v->write.type == FMT_AHEX ? new_width * 2 : new_width;
-    }
+  fmt_resize (&v->print, new_width);
+  fmt_resize (&v->write, new_width);
 
   v->width = new_width;
 




reply via email to

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