X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fgnumeric-reader.c;h=74911c469ea902a916f8b87ab2fd29a20dc425a6;hb=ebd0dcdfe65da02a6e541ceea0226c9b0b8d7a47;hp=c379717505cb940de485dbee8c4d05059bb53e0c;hpb=5c3291dc396b795696e94f47780308fd7ace6fc4;p=pspp diff --git a/src/data/gnumeric-reader.c b/src/data/gnumeric-reader.c index c379717505..74911c469e 100644 --- a/src/data/gnumeric-reader.c +++ b/src/data/gnumeric-reader.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 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 @@ -60,6 +60,8 @@ gnumeric_open_reader (struct gnumeric_read_info *gri, struct dictionary **dict) #include #include +/* Default width of string variables. */ +#define GNUMERIC_DEFAULT_WIDTH 8 static void gnm_file_casereader_destroy (struct casereader *, void *); @@ -318,21 +320,17 @@ static void convert_xml_string_to_value (struct ccase *c, const struct variable *var, const xmlChar *xv) { - int n_bytes = 0; union value *v = case_data_rw (c, var); - const char *text = (const char *) xv; - - if ( text) - n_bytes = MIN (var_get_width (var), strlen (text)); - - if ( var_is_alpha (var)) - { - memcpy (value_str_rw (v, var_get_width (var)), text, n_bytes); - } + if (xv == NULL) + value_set_missing (v, var_get_width (var)); + else if ( var_is_alpha (var)) + value_copy_str_rpad (v, var_get_width (var), xv, ' '); else { + const char *text = (const char *) xv; char *endptr; + errno = 0; v->f = strtod (text, &endptr); if ( errno != 0 || endptr == text) @@ -363,7 +361,7 @@ gnumeric_open_reader (struct gnumeric_read_info *gri, struct dictionary **dict) if ( NULL == gz) { - msg (ME, _("Error opening \"%s\" for reading as a gnumeric file: %s."), + msg (ME, _("Error opening \"%s\" for reading as a Gnumeric file: %s."), gri->file_name, strerror (errno)); goto error; @@ -476,7 +474,7 @@ gnumeric_open_reader (struct gnumeric_read_info *gri, struct dictionary **dict) if (-1 == var_spec [idx].width ) var_spec [idx].width = (gri->asw == -1) ? - ROUND_UP (strlen(text), MAX_SHORT_STRING) : gri->asw; + ROUND_UP (strlen(text), GNUMERIC_DEFAULT_WIDTH) : gri->asw; } free (value); @@ -510,7 +508,7 @@ gnumeric_open_reader (struct gnumeric_read_info *gri, struct dictionary **dict) /* Probably no data exists for this variable, so allocate a default width */ if ( var_spec[i].width == -1 ) - var_spec[i].width = MAX_SHORT_STRING; + var_spec[i].width = GNUMERIC_DEFAULT_WIDTH; if ( ! dict_make_unique_var_name (r->dict, var_spec[i].name, &vstart, name))