[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[VAR_NAME_LEN 16/17] text-data-import-dialog: Eliminate VAR_NAME_LEN res
From: |
Ben Pfaff |
Subject: |
[VAR_NAME_LEN 16/17] text-data-import-dialog: Eliminate VAR_NAME_LEN restriction. |
Date: |
Sat, 5 Feb 2011 13:25:58 -0800 |
Most uses of VAR_NAME_LEN within PSPP are wrong due to encoding issues:
the limit applies to variable names in the encoding used by the data
set, but most uses of VAR_NAME_LEN actually limit the length of a name
in UTF-8. The UTF-8 representation of a name can be longer or shorter
than its representation in the data set encoding, so it seems best to
eliminate references to VAR_NAME_LEN entirely.
---
src/ui/gui/text-data-import-dialog.c | 24 ++++++++++++++++--------
1 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/ui/gui/text-data-import-dialog.c
b/src/ui/gui/text-data-import-dialog.c
index 562f4f2..298fd18 100644
--- a/src/ui/gui/text-data-import-dialog.c
+++ b/src/ui/gui/text-data-import-dialog.c
@@ -225,7 +225,7 @@ static GtkTreeViewColumn *make_data_column (struct
import_assistant *,
gint column_idx);
static GtkTreeView *create_data_tree_view (bool input, GtkContainer *parent,
struct import_assistant *);
-static void escape_underscores (const char *in, char *out);
+static char *escape_underscores (const char *in);
static void push_watch_cursor (struct import_assistant *);
static void pop_watch_cursor (struct import_assistant *);
@@ -1968,17 +1968,17 @@ make_data_column (struct import_assistant *ia,
GtkTreeView *tree_view,
{
struct variable *var = NULL;
struct column *column = NULL;
- char name[(VAR_NAME_LEN * 2) + 1];
size_t char_cnt;
gint content_width, header_width;
GtkTreeViewColumn *tree_column;
+ char *name;
if (input)
column = &ia->separators.columns[dict_idx];
else
var = dict_get_var (ia->formats.dict, dict_idx);
- escape_underscores (input ? column->name : var_get_name (var), name);
+ name = escape_underscores (input ? column->name : var_get_name (var));
char_cnt = input ? column->width : var_get_print_format (var)->w;
content_width = get_monospace_width (tree_view, ia->asst.fixed_renderer,
char_cnt);
@@ -1998,6 +1998,8 @@ make_data_column (struct import_assistant *ia,
GtkTreeView *tree_view,
gtk_tree_view_column_set_fixed_width (tree_column, MAX (content_width,
header_width));
+ free (name);
+
return tree_column;
}
@@ -2028,16 +2030,22 @@ create_data_tree_view (bool input, GtkContainer *parent,
return tree_view;
}
-static void
-escape_underscores (const char *in, char *out)
+static char *
+escape_underscores (const char *in)
{
+ char *out = xmalloc (2 * strlen (in) + 1);
+ char *p;
+
+ p = out;
for (; *in != '\0'; in++)
{
if (*in == '_')
- *out++ = '_';
- *out++ = *in;
+ *p++ = '_';
+ *p++ = *in;
}
- *out = '\0';
+ *p = '\0';
+
+ return out;
}
/* TextImportModel, a GtkTreeModel implementation used by some
--
1.7.1
- [VAR_NAME_LEN 01/17] dict: Make dict_make_unique_var_name() return an allocated string., (continued)
- [VAR_NAME_LEN 01/17] dict: Make dict_make_unique_var_name() return an allocated string., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 07/17] DATAFILE ATTRIBUTE, VARIABLE ATTRIBUTE: Eliminate VAR_NAME_LEN limit., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 06/17] GET DATA /TYPE=TXT: Get rid of VAR_NAME_LEN limit on variable names., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 09/17] VECTOR: Eliminate VAR_NAME_LEN limit for variable names., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 17/17] por-file-reader: Remove dependency on VAR_NAME_LEN., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 02/17] variable: Remove VAR_NAME_LEN limit for internal representation of name., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 10/17] DEBUG EVALUATE: Eliminate VAR_NAME_LEN limit., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 04/17] combine-files: Eliminate VAR_NAME_LEN restriction from combine_files()., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 15/17] REGRESSION: Eliminate restriction to VAR_NAME_LEN in reg_get_name()., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 13/17] DESCRIPTIVES: Eliminate main restriction on Z-score variable name length., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 16/17] text-data-import-dialog: Eliminate VAR_NAME_LEN restriction.,
Ben Pfaff <=
- [VAR_NAME_LEN 11/17] variable-parser: Rewrite parse_DATA_LIST_vars()., Ben Pfaff, 2011/02/05
- [VAR_NAME_LEN 12/17] variable-parser: Drop VAR_NAME_LEN restriction from var_set_lookup_var_idx()., Ben Pfaff, 2011/02/05
- Re: [VAR_NAME_LEN 00/17] Eliminate uses of VAR_NAME_LEN, John Darrington, 2011/02/08