X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fpfm-read.c;h=1999628c462ae7fdde3c15048d22995d37dcf464;hb=93abfcc57a1e6ff792e5ae01784172459eee783f;hp=3e20f0396561344876a4ee23e44b9065e2148304;hpb=25fae0555073f526e5d5825133a2f62454a7b4c6;p=pspp-builds.git diff --git a/src/pfm-read.c b/src/pfm-read.c index 3e20f039..1999628c 100644 --- a/src/pfm-read.c +++ b/src/pfm-read.c @@ -16,8 +16,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ #include #include "pfm-read.h" @@ -30,12 +30,12 @@ #include #include #include "alloc.h" -#include "bool.h" +#include #include "case.h" #include "dictionary.h" #include "file-handle.h" #include "format.h" -#include "getline.h" +#include "getl.h" #include "hash.h" #include "magic.h" #include "misc.h" @@ -44,6 +44,9 @@ #include "value-labels.h" #include "var.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) + #include "debug-print.h" /* Portable file reader. */ @@ -82,7 +85,7 @@ error (struct pfm_reader *r, const char *msg, ...) getl_location (&e.where.filename, &e.where.line_number); filename = handle_get_filename (r->fh); e.title = title = pool_alloc (r->pool, strlen (filename) + 80); - sprintf (e.title, _("portable file %s corrupt at offset %ld: "), + sprintf (title, _("portable file %s corrupt at offset %ld: "), filename, ftell (r->file)); va_start (args, msg); @@ -396,8 +399,11 @@ read_header (struct pfm_reader *r) /* Skip and verify signature. */ for (i = 0; i < 8; i++) - if (!match (r, "SPSSPORT"[i])) - error (r, _("Missing SPSSPORT signature.")); + if (!match (r, "SPSSPORT"[i])) + { + msg (SE, _("%s: Not a portable file."), handle_get_filename (r->fh)); + longjmp (r->bail_out, 1); + } } /* Reads the version and date info record, as well as product and @@ -405,7 +411,7 @@ read_header (struct pfm_reader *r) static void read_version_data (struct pfm_reader *r, struct pfm_read_info *info) { - char *date, *time, *product, *subproduct; + char *date, *time, *product, *author, *subproduct; int i; /* Read file. */ @@ -414,6 +420,7 @@ read_version_data (struct pfm_reader *r, struct pfm_read_info *info) date = read_pool_string (r); time = read_pool_string (r); product = match (r, '1') ? read_pool_string (r) : (unsigned char *) ""; + author = match (r, '2') ? read_pool_string (r) : (unsigned char *) ""; subproduct = match (r, '3') ? read_pool_string (r) : (unsigned char *) ""; @@ -445,8 +452,8 @@ read_version_data (struct pfm_reader *r, struct pfm_read_info *info) info->creation_time[8] = 0; /* Product. */ - st_trim_copy (info->product, product, sizeof info->product); - st_trim_copy (info->subproduct, subproduct, sizeof info->subproduct); + str_copy_trunc (info->product, sizeof info->product, product); + str_copy_trunc (info->subproduct, sizeof info->subproduct, subproduct); } } @@ -494,7 +501,7 @@ read_variables (struct pfm_reader *r, struct dictionary *dict) if (match (r, '6')) { weight_name = read_pool_string (r); - if (strlen (weight_name) > 8) + if (strlen (weight_name) > SHORT_NAME_LEN) error (r, _("Weight variable name (%s) truncated."), weight_name); } @@ -518,9 +525,9 @@ read_variables (struct pfm_reader *r, struct dictionary *dict) for (j = 0; j < 6; j++) fmt[j] = read_int (r); - if (!var_is_valid_name (name, false) || *name == '#') - error (r, _("position %d: Invalid variable name `%s'."), name); - st_uppercase (name); + if (!var_is_valid_name (name, false) || *name == '#' || *name == '$') + error (r, _("position %d: Invalid variable name `%s'."), i, name); + str_uppercase (name); if (width < 0 || width > 255) error (r, "Bad width %d for variable %s.", width, name); @@ -533,45 +540,23 @@ read_variables (struct pfm_reader *r, struct dictionary *dict) convert_format (r, &fmt[3], &v->write, v); /* Range missing values. */ - if (match (r, 'B')) - { - v->miss_type = MISSING_RANGE; - v->missing[0] = parse_value (r, v); - v->missing[1] = parse_value (r, v); - } + if (match (r, 'B')) + { + double x = read_float (r); + double y = read_float (r); + mv_add_num_range (&v->miss, x, y); + } else if (match (r, 'A')) - { - v->miss_type = MISSING_HIGH; - v->missing[0] = parse_value (r, v); - } + mv_add_num_range (&v->miss, read_float (r), HIGHEST); else if (match (r, '9')) - { - v->miss_type = MISSING_LOW; - v->missing[0] = parse_value (r, v); - } + mv_add_num_range (&v->miss, LOWEST, read_float (r)); /* Single missing values. */ - while (match (r, '8')) - { - static const int map_next[MISSING_COUNT] = - { - MISSING_1, MISSING_2, MISSING_3, -1, - MISSING_RANGE_1, MISSING_LOW_1, MISSING_HIGH_1, - -1, -1, -1, - }; - - static const int map_ofs[MISSING_COUNT] = - { - -1, 0, 1, 2, -1, -1, -1, 2, 1, 1, - }; - - v->miss_type = map_next[v->miss_type]; - if (v->miss_type == -1) - error (r, _("Bad missing values for %s."), v->name); - - assert (map_ofs[v->miss_type] != -1); - v->missing[map_ofs[v->miss_type]] = parse_value (r, v); - } + while (match (r, '8')) + { + union value value = parse_value (r, v); + mv_add_value (&v->miss, &value); + } if (match (r, 'C')) { @@ -602,7 +587,7 @@ parse_value (struct pfm_reader *r, struct variable *vv) { char string[256]; read_string (r, string); - st_bare_pad_copy (v.s, string, 8); + buf_copy_str_rpad (v.s, 8, string); } else v.f = read_float (r); @@ -696,7 +681,7 @@ pfm_read_case (struct pfm_reader *r, struct ccase *c) { char string[256]; read_string (r, string); - st_bare_pad_copy (case_data_rw (c, idx)->s, string, width); + buf_copy_str_rpad (case_data_rw (c, idx)->s, width, string); idx += DIV_RND_UP (width, MAX_SHORT_STRING); } }