X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fflip.c;h=487417bab149c682fb16c2047d3d416da50e9ffd;hb=11210e8190261d1ab630b1a56f6c0a44a5e82419;hp=c8cb03b92d7f75aff63dc5fe3ca549d8a4d2b365;hpb=7665da99ed70c1a5ffee47e99e1672244b444ed4;p=pspp-builds.git diff --git a/src/language/stats/flip.c b/src/language/stats/flip.c index c8cb03b9..487417ba 100644 --- a/src/language/stats/flip.c +++ b/src/language/stats/flip.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2009 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009, 2010, 2011 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 @@ -109,23 +109,23 @@ cmd_flip (struct lexer *lexer, struct dataset *ds) flip->error = false; flip->dict = dict; - lex_match (lexer, '/'); + lex_match (lexer, T_SLASH); if (lex_match_id (lexer, "VARIABLES")) { - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (!parse_variables_const (lexer, dict, &vars, &flip->n_vars, PV_NO_DUPLICATE)) goto error; - lex_match (lexer, '/'); + lex_match (lexer, T_SLASH); } else dict_get_vars (dict, &vars, &flip->n_vars, DC_SYSTEM); pool_register (flip->pool, free, vars); - lex_match (lexer, '/'); + lex_match (lexer, T_SLASH); if (lex_match_id (lexer, "NEWNAMES")) { - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); flip->new_names_var = parse_variable (lexer, dict); if (!flip->new_names_var) goto error; @@ -144,7 +144,7 @@ cmd_flip (struct lexer *lexer, struct dataset *ds) } } - flip->file = pool_tmpfile (flip->pool); + flip->file = pool_create_temp_file (flip->pool); if (flip->file == NULL) { msg (SE, _("Could not create temporary file for FLIP.")); @@ -186,7 +186,6 @@ cmd_flip (struct lexer *lexer, struct dataset *ds) { name = data_out_pool (value, dict_get_encoding (flip->dict), var_get_write_format (flip->new_names_var), flip->pool); - } var_names_add (flip->pool, &flip->new_names, name); } @@ -210,7 +209,7 @@ cmd_flip (struct lexer *lexer, struct dataset *ds) make_new_var (dict, flip->new_names.names[i]); else { - char s[VAR_NAME_LEN + 1]; + char s[3 + INT_STRLEN_BOUND (i) + 1]; sprintf (s, "VAR%03zu", i); dict_create_var_assert (dict, s, 0); } @@ -261,7 +260,6 @@ make_new_var (struct dictionary *dict, const char *name_) *cp = '_'; } *cp = '\0'; - str_uppercase (name); /* Use the mangled name, if it is available, or add numeric extensions until we find one that is. */ @@ -322,13 +320,13 @@ flip_file (struct flip_pgm *flip) output_buf = input_buf + flip->n_vars * case_capacity; input_file = flip->file; - if (fseek (input_file, 0, SEEK_SET) != 0) + if (fseeko (input_file, 0, SEEK_SET) != 0) { msg (SE, _("Error rewinding FLIP file: %s."), strerror (errno)); return false; } - output_file = pool_tmpfile (flip->pool); + output_file = pool_create_temp_file (flip->pool); if (output_file == NULL) { msg (SE, _("Error creating FLIP source file.")); @@ -379,15 +377,11 @@ flip_file (struct flip_pgm *flip) case_idx += read_cases; } - if (pool_fclose (flip->pool, input_file) == EOF) - { - msg (SE, _("Error closing FLIP source file: %s."), strerror (errno)); - return false; - } + pool_fclose_temp_file (flip->pool, input_file); pool_unregister (flip->pool, input_buf); free (input_buf); - if (fseek (output_file, 0, SEEK_SET) != 0) + if (fseeko (output_file, 0, SEEK_SET) != 0) { msg (SE, _("Error rewinding FLIP source file: %s."), strerror (errno)); return false; @@ -403,6 +397,7 @@ static struct ccase * flip_casereader_read (struct casereader *reader, void *flip_) { struct flip_pgm *flip = flip_; + const char *encoding; struct ccase *c; size_t i; @@ -410,12 +405,10 @@ flip_casereader_read (struct casereader *reader, void *flip_) return false; c = case_create (casereader_get_proto (reader)); - data_in (ss_cstr (flip->old_names.names[flip->cases_read]), dict_get_encoding (flip->dict), - FMT_A, 0, - 0, 0, - flip->dict, - case_data_rw_idx (c, 0), 8); - + encoding = dict_get_encoding (flip->dict); + data_in (ss_cstr (flip->old_names.names[flip->cases_read]), encoding, + FMT_A, case_data_rw_idx (c, 0), 8, encoding); + for (i = 0; i < flip->n_cases; i++) { double in;