From: Ben Pfaff Date: Fri, 9 Apr 2010 04:28:42 +0000 (-0700) Subject: variable: Introduce and use new function var_get_encoding(). X-Git-Tag: v0.7.5~83 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd674641880b82597fa35492207f189136e83fbb;p=pspp-builds.git variable: Introduce and use new function var_get_encoding(). These changes seem like slight cleanups since they eliminate a function parameter in these cases. --- diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index 5daea89d..0d93bd12 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -95,9 +95,9 @@ struct sfm_writer static const struct casewriter_class sys_file_casewriter_class; static void write_header (struct sfm_writer *, const struct dictionary *); -static void write_variable (struct sfm_writer *, const struct variable *, const struct dictionary *); -static void write_value_labels (struct sfm_writer *, - struct variable *, int idx, const struct dictionary *); +static void write_variable (struct sfm_writer *, const struct variable *); +static void write_value_labels (struct sfm_writer *, struct variable *, + int idx); static void write_integer_info_record (struct sfm_writer *); static void write_float_info_record (struct sfm_writer *); @@ -223,7 +223,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, /* Write basic variable info. */ short_names_assign (d); for (i = 0; i < dict_get_var_cnt (d); i++) - write_variable (w, dict_get_var (d, i), d); + write_variable (w, dict_get_var (d, i)); /* Write out value labels. */ idx = 0; @@ -231,7 +231,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, { struct variable *v = dict_get_var (d, i); - write_value_labels (w, v, idx, d); + write_value_labels (w, v, idx); idx += sfm_width_to_octs (var_get_width (v)); } @@ -421,7 +421,7 @@ write_variable_continuation_records (struct sfm_writer *w, int width) /* Write the variable record(s) for variable V to system file W. */ static void -write_variable (struct sfm_writer *w, const struct variable *v, const struct dictionary *dict) +write_variable (struct sfm_writer *w, const struct variable *v) { int width = var_get_width (v); int segment_cnt = sfm_width_to_segments (width); @@ -461,7 +461,7 @@ write_variable (struct sfm_writer *w, const struct variable *v, const struct dic /* Value label. */ if (var_has_label (v)) { - char *label = recode_string (dict_get_encoding (dict), UTF8, var_get_label (v), -1); + char *label = recode_string (var_get_encoding (v), UTF8, var_get_label (v), -1); size_t label_len = MIN (strlen (label), 255); size_t padded_len = ROUND_UP (label_len, 4); write_int (w, label_len); @@ -508,7 +508,7 @@ write_variable (struct sfm_writer *w, const struct variable *v, const struct dic Value labels for long string variables are written separately, by write_long_string_value_labels. */ static void -write_value_labels (struct sfm_writer *w, struct variable *v, int idx, const struct dictionary *dict) +write_value_labels (struct sfm_writer *w, struct variable *v, int idx) { const struct val_labs *val_labs; const struct val_lab **labels; @@ -527,7 +527,7 @@ write_value_labels (struct sfm_writer *w, struct variable *v, int idx, const str for (i = 0; i < n_labels; i++) { const struct val_lab *vl = labels[i]; - char *label = recode_string (dict_get_encoding (dict), UTF8, val_lab_get_label (vl), -1); + char *label = recode_string (var_get_encoding (v), UTF8, val_lab_get_label (vl), -1); uint8_t len = MIN (strlen (label), 255); write_value (w, val_lab_get_value (vl), var_get_width (v)); diff --git a/src/data/variable.c b/src/data/variable.c index 05edc57e..79925fa8 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -590,10 +590,9 @@ var_append_value_name (const struct variable *v, const union value *value, struct string *str) { const char *name = var_lookup_value_label (v, value); - const struct dictionary *dict = var_get_vardict (v)->dict; if (name == NULL) { - char *s = data_out (value, dict_get_encoding (dict), &v->print); + char *s = data_out (value, var_get_encoding (v), &v->print); ds_put_cstr (str, s); free (s); } @@ -1053,6 +1052,15 @@ var_has_attributes (const struct variable *v) return attrset_count (&v->attributes) > 0; } +/* Returns the encoding of values of variable VAR. (This is actually a + property of the dictionary.) Returns null if no specific encoding has been + set. */ +const char * +var_get_encoding (const struct variable *var) +{ + return var_has_vardict (var) ? dict_get_encoding (var->vardict.dict) : NULL; +} + /* Returns V's vardict structure. */ const struct vardict_info * var_get_vardict (const struct variable *v) diff --git a/src/data/variable.h b/src/data/variable.h index 0b619a49..d730768e 100644 --- a/src/data/variable.h +++ b/src/data/variable.h @@ -178,6 +178,9 @@ struct attrset *var_get_attributes (const struct variable *); void var_set_attributes (struct variable *, const struct attrset *); bool var_has_attributes (const struct variable *); +/* Encoding. */ +const char *var_get_encoding (const struct variable *); + /* Function types. */ typedef bool var_predicate_func (const struct variable *); diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index b137e284..d0fd6dd5 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -1191,7 +1191,8 @@ create_crosstab_table (struct crosstabs_proc *proc, struct pivot_table *pt) /* Insert the formatted value of the variable, then trim leading spaces in what was just inserted. */ ofs = ds_length (&title); - s = data_out (&pt->const_values[i], dict_get_encoding (proc->dict), var_get_print_format (var)); + s = data_out (&pt->const_values[i], var_get_encoding (var), + var_get_print_format (var)); ds_put_cstr (&title, s); free (s); ds_remove (&title, ofs, ss_cspan (ds_substr (&title, ofs, SIZE_MAX), diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 8a882e2c..036b9b77 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -1653,14 +1653,13 @@ enum { /* Perform data_out for case CC, variable V, appending to STRING */ static void -data_out_g_string (GString *string, const struct dictionary *dict, - const struct variable *v, +data_out_g_string (GString *string, const struct variable *v, const struct ccase *cc) { const struct fmt_spec *fs = var_get_print_format (v); const union value *val = case_data (cc, v); - char *s = data_out (val, dict_get_encoding (dict), fs); + char *s = data_out (val, var_get_encoding (v), fs); g_string_append (string, s); @@ -1694,7 +1693,7 @@ clip_to_text (void) for (c = 0 ; c < var_cnt ; ++c) { const struct variable *v = dict_get_var (clip_dict, c); - data_out_g_string (string, clip_dict, v, cc); + data_out_g_string (string, v, cc); if ( c < val_cnt - 1 ) g_string_append (string, "\t"); } @@ -1741,7 +1740,7 @@ clip_to_html (void) { const struct variable *v = dict_get_var (clip_dict, c); g_string_append (string, ""); - data_out_g_string (string, clip_dict, v, cc); + data_out_g_string (string, v, cc); g_string_append (string, "\n"); }