X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fexamine.q;h=4e28f23917501542defa0803efbc9cc4667b9610;hb=067d02c2b8c591efc368cf5127c497313d7a373f;hp=469b413c743c4ebde5c51d6e6a84ebc11296fac1;hpb=2c4c4a789e9c23478bce195d2ed98bab6064dfc1;p=pspp diff --git a/src/examine.q b/src/examine.q index 469b413c74..4e28f23917 100644 --- a/src/examine.q +++ b/src/examine.q @@ -116,8 +116,8 @@ static void show_descriptives(struct variable **dependent_var, struct factor *factor); static void show_percentiles(struct variable **dependent_var, - int n_dep_var, - struct factor *factor); + int n_dep_var, + struct factor *factor); @@ -132,7 +132,7 @@ void box_plot_group(const struct factor *fctr, void box_plot_variables(const struct factor *fctr, - struct variable **vars, int n_vars, + const struct variable **vars, int n_vars, const struct variable *id ); @@ -151,8 +151,8 @@ void factor_calc(struct ccase *c, int case_no, /* Represent a factor as a string, so it can be printed in a human readable fashion */ const char * factor_to_string(const struct factor *fctr, - struct factor_statistics *fs, - const struct variable *var); + struct factor_statistics *fs, + const struct variable *var); /* Represent a factor as a string, so it can be @@ -211,7 +211,25 @@ cmd_examine(void) multipass_procedure_with_splits (run_examine, &cmd); if ( totals ) - free(totals); + { + free( totals ); + } + + if ( dependent_vars ) + free (dependent_vars); + + { + struct factor *f = factors ; + while ( f ) + { + struct factor *ff = f; + + f = f->next; + free ( ff->fs ); + hsh_destroy ( ff->fstats ) ; + free ( ff ) ; + } + } subc_list_double_destroy(&percentile_list); @@ -464,16 +482,18 @@ xmn_custom_nototal(struct cmd_examine *p) -/* Parser for the variables sub command */ +/* Parser for the variables sub command + Returns 1 on success */ static int xmn_custom_variables(struct cmd_examine *cmd ) { - lex_match('='); if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL) && token != T_ALL) - return 2; + { + return 2; + } if (!parse_variables (default_dict, &dependent_vars, &n_dependent_vars, PV_NO_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH) ) @@ -488,7 +508,13 @@ xmn_custom_variables(struct cmd_examine *cmd ) if ( lex_match(T_BY)) { - return examine_parse_independent_vars(cmd); + int success ; + success = examine_parse_independent_vars(cmd); + if ( success != 1 ) { + free (dependent_vars); + free (totals) ; + } + return success; } return 1; @@ -500,12 +526,15 @@ xmn_custom_variables(struct cmd_examine *cmd ) static int examine_parse_independent_vars(struct cmd_examine *cmd) { - + int success; struct factor *sf = xmalloc(sizeof(struct factor)); if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL) && token != T_ALL) - return 2; + { + free ( sf ) ; + return 2; + } sf->indep_var[0] = parse_variable(); @@ -518,7 +547,10 @@ examine_parse_independent_vars(struct cmd_examine *cmd) if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL) && token != T_ALL) - return 2; + { + free ( sf ) ; + return 2; + } sf->indep_var[1] = parse_variable(); @@ -539,7 +571,12 @@ examine_parse_independent_vars(struct cmd_examine *cmd) if ( token == '.' || token == '/' ) return 1; - return examine_parse_independent_vars(cmd); + success = examine_parse_independent_vars(cmd); + + if ( success != 1 ) + free ( sf ) ; + + return success; } @@ -786,8 +823,15 @@ run_examine(const struct casefile *cf, void *cmd_ ) output_examine(); - for ( v = 0 ; v < n_dependent_vars ; ++v ) - hsh_destroy(totals[v].ordered_data); + + if ( totals ) + { + int i; + for ( i = 0 ; i < n_dependent_vars ; ++i ) + { + metrics_destroy(&totals[i]); + } + } } @@ -819,7 +863,7 @@ show_summary(struct variable **dependent_var, int n_dep_var, n_rows = n_dep_var * n_factors ; if ( fctr->indep_var[1] ) - heading_columns = 3; + heading_columns = 3; } else { @@ -944,17 +988,17 @@ show_summary(struct variable **dependent_var, int n_dep_var, if ( 0 != compare_values(&prev, &(*fs)->id[0], fctr->indep_var[0]->width)) { - tab_text (tbl, - 1, - (i * n_factors ) + count + - heading_rows, - TAB_LEFT | TAT_TITLE, - value_to_string(&(*fs)->id[0], fctr->indep_var[0]) - ); - - if (fctr->indep_var[1] && count > 0 ) - tab_hline(tbl, TAL_1, 1, n_cols - 1, - (i * n_factors ) + count + heading_rows); + tab_text (tbl, + 1, + (i * n_factors ) + count + + heading_rows, + TAB_LEFT | TAT_TITLE, + value_to_string(&(*fs)->id[0], fctr->indep_var[0]) + ); + + if (fctr->indep_var[1] && count > 0 ) + tab_hline(tbl, TAL_1, 1, n_cols - 1, + (i * n_factors ) + count + heading_rows); } @@ -1037,7 +1081,7 @@ show_extremes(struct variable **dependent_var, int n_dep_var, n_rows = n_dep_var * 2 * n_extremities * n_factors; if ( fctr->indep_var[1] ) - heading_columns = 3; + heading_columns = 3; } else { @@ -1214,7 +1258,7 @@ populate_extremes(struct tab_table *t, cn->num, 8, 0); if ( cn->next ) - cn = cn->next; + cn = cn->next; } @@ -1243,7 +1287,7 @@ populate_extremes(struct tab_table *t, cn->num, 8, 0); if ( cn->next ) - cn = cn->next; + cn = cn->next; } @@ -1278,7 +1322,7 @@ show_descriptives(struct variable **dependent_var, n_rows = n_dep_var * n_stat_rows * n_factors; if ( fctr->indep_var[1] ) - heading_columns = 5; + heading_columns = 5; } else { @@ -1378,7 +1422,7 @@ show_descriptives(struct variable **dependent_var, ); populate_descriptives(tbl, heading_columns - 2, - row, &(*fs)->m[i]); + row, &(*fs)->m[i]); count++ ; fs++; @@ -1623,7 +1667,7 @@ populate_descriptives(struct tab_table *tbl, int col, int row, void box_plot_variables(const struct factor *fctr, - struct variable **vars, int n_vars, + const struct variable **vars, int n_vars, const struct variable *id) { @@ -1687,7 +1731,7 @@ void box_plot_group(const struct factor *fctr, const struct variable **vars, int n_vars, - const struct variable *id) + const struct variable *id UNUSED) { int i; @@ -1706,7 +1750,7 @@ box_plot_group(const struct factor *fctr, int n_factors = 0; int f=0; for ( fs = fctr->fs ; *fs ; ++fs ) - ++n_factors; + ++n_factors; chart_write_title(ch, _("Boxplot of %s vs. %s"), var_to_string(vars[i]), var_to_string(fctr->indep_var[0]) ); @@ -1843,8 +1887,8 @@ np_plot(const struct metrics *m, const char *factorname) /* Show the percentiles */ void show_percentiles(struct variable **dependent_var, - int n_dep_var, - struct factor *fctr) + int n_dep_var, + struct factor *fctr) { struct tab_table *tbl; int i; @@ -1869,7 +1913,7 @@ show_percentiles(struct variable **dependent_var, ptiles = (*fs)->m[0].ptile_hash; if ( fctr->indep_var[1] ) - n_heading_columns = 4; + n_heading_columns = 4; } else { @@ -2011,7 +2055,7 @@ show_percentiles(struct variable **dependent_var, populate_percentiles(tbl, n_heading_columns - 1, - row, &(*fs)->m[i]); + row, &(*fs)->m[i]); count++ ; @@ -2023,8 +2067,8 @@ show_percentiles(struct variable **dependent_var, else { populate_percentiles(tbl, n_heading_columns - 1, - i * n_stat_rows * n_factors + n_heading_rows, - &totals[i]); + i * n_stat_rows * n_factors + n_heading_rows, + &totals[i]); } @@ -2133,7 +2177,7 @@ factor_to_string(const struct factor *fctr, const char * factor_to_string_concise(const struct factor *fctr, - struct factor_statistics *fs) + struct factor_statistics *fs) {