data_out function to dynamically allocate return value.
[pspp-builds.git] / src / ui / gui / psppire-data-store.c
index 8808fd32588fe29f46b73dfe232a1dfccdf620a6..13ad0cc6cd283edfb9656a67f4eb2b3f7ae7873b 100644 (file)
@@ -347,7 +347,6 @@ insert_variable_callback (GObject *obj, gint var_num, gpointer data)
 
   variable = psppire_dict_get_variable (store->dict, var_num);
   posn = var_get_case_index (variable);
-  printf ("insert var_num=%d, posn=%d\n", var_num, posn);
   psppire_data_store_insert_value (store, var_get_width (variable), posn);
 
 #if AXIS_TRANSITION
@@ -586,7 +585,6 @@ psppire_data_store_get_string (PsppireDataStore *store, glong row, glong column)
   const struct variable *pv ;
   union value v;
   int width;
-  GString *s;
 
   g_return_val_if_fail (store->dict, NULL);
   g_return_val_if_fail (store->datasheet, NULL);
@@ -623,21 +621,10 @@ psppire_data_store_get_string (PsppireDataStore *store, glong row, glong column)
 
   fp = var_get_write_format (pv);
 
-  s = g_string_sized_new (fp->w + 1);
-  g_string_set_size (s, fp->w);
-
-  memset (s->str, 0, fp->w);
-
-  g_assert (fp->w == s->len);
-
   /* Converts binary value V into printable form in the exactly
      FP->W character in buffer S according to format specification
      FP.  No null terminator is appended to the buffer.  */
-  data_out (&v, fp, s->str);
-
-  text = recode_string (UTF8, psppire_dict_encoding (store->dict),
-                       s->str, fp->w);
-  g_string_free (s, TRUE);
+  text = data_out (&v, fp);
 
   g_strchomp (text);
 
@@ -653,12 +640,11 @@ psppire_data_store_clear_datum (PsppireSheetModel *model,
   PsppireDataStore *store = PSPPIRE_DATA_STORE (model);
 
   union value v;
-  int width;
   const struct variable *pv = psppire_dict_get_variable (store->dict, col);
+  int width = var_get_width (pv);
 
   const gint index = var_get_case_index (pv) ;
 
-  width = var_is_numeric (pv) ? 0 : MAX_SHORT_STRING;
   value_init (&v, width);
   value_set_missing (&v, width);
   psppire_data_store_set_value (store, row, index, &v);
@@ -797,7 +783,6 @@ get_row_sensitivity (const PsppireSheetModel *model, gint unit)
 static gchar *
 get_column_subtitle (const PsppireSheetModel *model, gint col)
 {
-  gchar *text;
   const struct variable *v ;
   PsppireDataStore *ds = PSPPIRE_DATA_STORE (model);
 
@@ -809,16 +794,12 @@ get_column_subtitle (const PsppireSheetModel *model, gint col)
   if ( ! var_has_label (v))
     return NULL;
 
-  text =  recode_string (UTF8, psppire_dict_encoding (ds->dict),
-                        var_get_label (v), -1);
-
-  return text;
+  return xstrdup (var_get_label (v));
 }
 
 static gchar *
 get_column_button_label (const PsppireSheetModel *model, gint col)
 {
-  gchar *text;
   struct variable *pv ;
   PsppireDataStore *ds = PSPPIRE_DATA_STORE (model);
 
@@ -827,10 +808,7 @@ get_column_button_label (const PsppireSheetModel *model, gint col)
 
   pv = psppire_dict_get_variable (ds->dict, col);
 
-  text = recode_string (UTF8, psppire_dict_encoding (ds->dict),
-                       var_get_name (pv), -1);
-
-  return text;
+  return xstrdup (var_get_name (pv));
 }
 
 static gboolean
@@ -1018,7 +996,6 @@ psppire_data_store_insert_value (PsppireDataStore *ds,
   else
     value_set_missing (&value, width);
 
-  printf("insert column width=%d\n", width);
   datasheet_insert_column (ds->datasheet, &value, width, where);
 
   return TRUE;