-\f
-
-
-/* A boxed type representing a value, or a range of values which may
- potentially be replaced by something */
-
-enum old_value_type
- {
- OV_NUMERIC,
- OV_STRING,
- OV_SYSMIS,
- OV_MISSING,
- OV_RANGE,
- OV_LOW_UP,
- OV_HIGH_DOWN,
- OV_ELSE
- };
-
-struct old_value
- {
- enum old_value_type type;
- union {
- double v;
- gchar *s;
- double range[2];
- } v;
- };
-
-
-static struct old_value *
-old_value_copy (struct old_value *ov)
-{
- struct old_value *copy = g_memdup (ov, sizeof (*copy));
-
- if ( ov->type == OV_STRING )
- copy->v.s = g_strdup (ov->v.s);
-
- return copy;
-}
-
-
-static void
-old_value_free (struct old_value *ov)
-{
- if (ov->type == OV_STRING)
- g_free (ov->v.s);
- g_free (ov);
-}
-
-static void
-old_value_to_string (const GValue *src, GValue *dest)
-{
- const struct old_value *ov = g_value_get_boxed (src);
-
- switch (ov->type)
- {
- case OV_NUMERIC:
- {
- gchar *text = g_strdup_printf ("%g", ov->v.v);
- g_value_set_string (dest, text);
- g_free (text);
- }
- break;
- case OV_STRING:
- g_value_set_string (dest, ov->v.s);
- break;
- case OV_MISSING:
- g_value_set_string (dest, "MISSING");
- break;
- case OV_SYSMIS:
- g_value_set_string (dest, "SYSMIS");
- break;
- case OV_ELSE:
- g_value_set_string (dest, "ELSE");
- break;
- case OV_RANGE:
- {
- gchar *text;
- char en_dash[6] = {0,0,0,0,0,0};
-
- g_unichar_to_utf8 (0x2013, en_dash);
-
- text = g_strdup_printf ("%g %s %g",
- ov->v.range[0],
- en_dash,
- ov->v.range[1]);
- g_value_set_string (dest, text);
- g_free (text);
- }
- break;
- case OV_LOW_UP:
- {
- gchar *text;
- char en_dash[6] = {0,0,0,0,0,0};
-
- g_unichar_to_utf8 (0x2013, en_dash);
-
- text = g_strdup_printf ("LOWEST %s %g",
- en_dash,
- ov->v.range[1]);
-
- g_value_set_string (dest, text);
- g_free (text);
- }
- break;
- case OV_HIGH_DOWN:
- {
- gchar *text;
- char en_dash[6] = {0,0,0,0,0,0};
-
- g_unichar_to_utf8 (0x2013, en_dash);
-
- text = g_strdup_printf ("%g %s HIGHEST",
- ov->v.range[0],
- en_dash);
-
- g_value_set_string (dest, text);
- g_free (text);
- }
- break;
- default:
- g_warning ("Invalid type in old recode value");
- g_value_set_string (dest, "???");
- break;
- };
-}
-
-static GType
-old_value_get_type (void)
-{
- static GType t = 0;
-
- if (t == 0 )
- {
- t = g_boxed_type_register_static ("psppire-recode-old-values",
- (GBoxedCopyFunc) old_value_copy,
- (GBoxedFreeFunc) old_value_free);
-
- g_value_register_transform_func (t, G_TYPE_STRING,
- old_value_to_string);
- }
-
- return t;
-}
-