X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fvalue.c;h=34e3fe58bb37bf40d80943d38fc4d5ecafdc76d2;hb=daa89632abf5920a2d2aaa622bac44ab012e1da8;hp=cd52f147ca3a0f4fd924c40861788cfc22081623;hpb=d22c3971e926ceaf62416c6482fe0fb1dc5407f0;p=pspp-builds.git
diff --git a/src/data/value.c b/src/data/value.c
index cd52f147..34e3fe58 100644
--- a/src/data/value.c
+++ b/src/data/value.c
@@ -15,8 +15,9 @@
along with this program. If not, see . */
#include
-#include "value.h"
+#include
+#include
#include
#include
@@ -83,3 +84,32 @@ value_set_missing (union value *v, int width)
else
memset (v->s, ' ', width);
}
+
+/* Tests whether VALUE may be resized from OLD_WIDTH to
+ NEW_WIDTH, using the following rules that match those for
+ resizing missing values and value labels. First, OLD_WIDTH
+ and NEW_WIDTH must be both numeric or both string. Second, if
+ NEW_WIDTH is less than OLD_WIDTH, then the bytes that would be
+ trimmed off the right end of VALUE must be all spaces. */
+bool
+value_is_resizable (const union value *value, int old_width, int new_width)
+{
+ int i;
+
+ if (val_type_from_width (old_width) != val_type_from_width (new_width))
+ return false;
+ for (i = new_width; i < old_width; i++)
+ if (value->s[i] != ' ')
+ return false;
+ return true;
+}
+
+/* Resizes VALUE from OLD_WIDTH to NEW_WIDTH. The arguments must
+ satisfy the rules specified above for value_is_resizable. */
+void
+value_resize (union value *value, int old_width, int new_width)
+{
+ assert (value_is_resizable (value, old_width, new_width));
+ if (new_width > old_width)
+ memset (&value->s[old_width], ' ', new_width - old_width);
+}