X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fflip.c;h=f599fd78f0b399f65ce773d52e39ad5707cee335;hb=0dd2d22c89cc94f92de0323c60ff16b993a46b18;hp=7ee4e70397b440e3b8f228559c6f2abf19e640d3;hpb=4944c86a9318bc5b5578ab145a95c116ffd2c9fd;p=pspp diff --git a/src/flip.c b/src/flip.c index 7ee4e70397..f599fd78f0 100644 --- a/src/flip.c +++ b/src/flip.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "alloc.h" #include "command.h" @@ -43,7 +44,7 @@ static struct variable *newnames; struct varname { struct varname *next; - char name[1]; + char name[9]; }; /* New variable names. */ @@ -61,12 +62,12 @@ cmd_flip (void) if (lex_match_id ("VARIABLES")) { lex_match ('='); - if (!parse_variables (&default_dict, &var, &nvar, PV_NO_DUPLICATE)) + if (!parse_variables (default_dict, &var, &nvar, PV_NO_DUPLICATE)) return CMD_FAILURE; lex_match ('/'); } else - fill_all_vars (&var, &nvar, FV_NO_SYSTEM); + dict_get_vars (default_dict, &var, &nvar, 1u << DC_SYSTEM); lex_match ('/'); if (lex_match_id ("NEWNAMES")) @@ -80,7 +81,7 @@ cmd_flip (void) } } else - newnames = find_variable ("CASE_LBL"); + newnames = dict_lookup_var (default_dict, "CASE_LBL"); if (newnames) { @@ -89,7 +90,7 @@ cmd_flip (void) for (i = 0; i < nvar; i++) if (var[i] == newnames) { - memcpy (&var[i], &var[i + 1], sizeof *var * (nvar - i - 1)); + memmove (&var[i], &var[i + 1], sizeof *var * (nvar - i - 1)); nvar--; break; } @@ -99,9 +100,9 @@ cmd_flip (void) temp_trns = temporary = 0; vfm_sink = &flip_stream; new_names_tail = NULL; - procedure (NULL, NULL, NULL); + procedure (NULL, NULL, NULL, NULL); - clear_default_dict (); + dict_clear (default_dict); if (!build_dictionary ()) { discard_variables (); @@ -126,7 +127,8 @@ make_new_var (char name[]) { *cp = toupper ((unsigned char) *cp); if (!isalpha (*cp) && *cp != '@' && *cp != '#' - && (cp == name || (*cp != '.' && *cp != '$' && *cp != '_'))) + && (cp == name || (*cp != '.' && *cp != '$' && *cp != '_' + && !isdigit (*cp)))) { if (cp == name) *cp = 'V'; /* _ not valid in first position. */ @@ -137,7 +139,7 @@ make_new_var (char name[]) *cp = 0; } - if (create_variable (&default_dict, name, NUMERIC, 0)) + if (dict_create_var (default_dict, name, 0)) return 1; /* Add numeric extensions until acceptable. */ @@ -152,7 +154,7 @@ make_new_var (char name[]) memcpy (n, name, ofs); sprintf (&n[ofs], "%d", i); - if (create_variable (&default_dict, n, NUMERIC, 0)) + if (dict_create_var (default_dict, n, 0)) return 1; } } @@ -165,7 +167,7 @@ make_new_var (char name[]) static int build_dictionary (void) { - force_create_variable (&default_dict, "CASE_LBL", ALPHA, 8); + dict_create_var_assert (default_dict, "CASE_LBL", 8); if (!new_names_tail) { @@ -179,10 +181,11 @@ build_dictionary (void) for (i = 0; i < case_count; i++) { + struct variable *v; char s[9]; sprintf (s, "VAR%03d", i); - force_create_variable (&default_dict, s, NUMERIC, 0); + v = dict_create_var_assert (default_dict, s, 0); } } else @@ -253,7 +256,7 @@ flip_stream_init (void) /* Reads the FLIP stream and passes it to write_case(). */ static void -flip_stream_read (void) +flip_stream_read (write_case_func *write_case, write_case_data wc_data) { if (src || (src == NULL && src_file == NULL)) { @@ -271,7 +274,7 @@ flip_stream_read (void) for (iter = src, j = 1; iter; iter = iter->next, j++) temp_case->data[j].f = iter->v[i]; - if (!write_case ()) + if (!write_case (wc_data)) return; } } @@ -290,7 +293,7 @@ flip_stream_read (void) msg (FE, _("Error reading FLIP source file: %s."), strerror (errno)); - if (!write_case ()) + if (!write_case (wc_data)) return; } } @@ -304,20 +307,31 @@ flip_stream_write (void) if (newnames) { - struct varname *v; - char name[INT_DIGITS + 2]; - - if (newnames->type == NUMERIC) - sprintf (name, "V%d", (int) temp_case->data[newnames->fv].f); + struct varname *v = xmalloc (sizeof (struct varname)); + if (newnames->type == NUMERIC) + { + double f = temp_case->data[newnames->fv].f; + + if (f == SYSMIS) + strcpy (v->name, "VSYSMIS"); + else if (f < INT_MIN) + strcpy (v->name, "VNEGINF"); + else if (f > INT_MAX) + strcpy (v->name, "VPOSINF"); + else + { + char name[INT_DIGITS + 2]; + sprintf (name, "V%d", (int) f); + strncpy (v->name, name, 8); + name[8] = 0; + } + } else { int width = min (newnames->width, 8); - memcpy (name, temp_case->data[newnames->fv].s, width); - name[width] = 0; + memcpy (v->name, temp_case->data[newnames->fv].s, width); + v->name[width] = 0; } - - v = xmalloc (sizeof (struct varname) + strlen (name) - 1); - strcpy (v->name, name); if (new_names_tail == NULL) new_names_head = v;