From: Ben Pfaff Date: Sat, 25 Nov 2006 02:15:00 +0000 (+0000) Subject: We've had a mix of min, max from libpspp/misc.h and MIN, MAX from X-Git-Tag: v0.6.0~687 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19d0debdc5b72e1bb6c79956403a4d3bc054f300;p=pspp-builds.git We've had a mix of min, max from libpspp/misc.h and MIN, MAX from gnulib's minmax.h thus far. This change replaces all instances of the former by the latter. --- diff --git a/src/data/dictionary.c b/src/data/dictionary.c index ebe6a5e5..39001d89 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -38,6 +38,8 @@ #include #include +#include "minmax.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -532,8 +534,8 @@ dict_reorder_var (struct dictionary *d, struct variable *v, move_element (d->var, d->var_cnt, sizeof *d->var, v->index, new_index); - min_idx = min (v->index, new_index); - max_idx = max (v->index, new_index); + min_idx = MIN (v->index, new_index); + max_idx = MAX (v->index, new_index); for (i = min_idx; i <= max_idx; i++) d->var[i]->index = i; } diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index 24054393..1b66a4d2 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -439,7 +439,7 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, break; } - for ( i = 0 ; i < min(n_vars, dict_get_var_cnt(*dict)) ; ++i ) + for ( i = 0 ; i < MIN(n_vars, dict_get_var_cnt(*dict)) ; ++i ) { struct { @@ -1382,7 +1382,7 @@ read_value_labels (struct sfm_reader *r, if (var[0]->type == ALPHA) { - const int copy_len = min (sizeof label->raw_value, + const int copy_len = MIN (sizeof label->raw_value, sizeof label->label); memcpy (label->value.s, label->raw_value, copy_len); } else { @@ -1446,7 +1446,7 @@ buf_read (struct sfm_reader *r, void *buf, size_t byte_cnt, size_t min_alloc) assert (r); if (buf == NULL && byte_cnt > 0 ) - buf = xmalloc (max (byte_cnt, min_alloc)); + buf = xmalloc (MAX (byte_cnt, min_alloc)); if ( byte_cnt == 0 ) return buf; diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index 37792101..517cf416 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -458,7 +458,7 @@ write_variable (struct sfm_writer *w, const struct variable *v) int nm; /* Number of missing values, possibly negative. */ sv.rec_type = 2; - sv.type = min(v->width, MAX_LONG_STRING); + sv.type = MIN(v->width, MAX_LONG_STRING); sv.has_var_label = (v->label != NULL); mv_copy (&mv, &v->miss); @@ -500,7 +500,7 @@ write_variable (struct sfm_writer *w, const struct variable *v) int ext_len; - l.label_len = min (strlen (v->label), 255); + l.label_len = MIN (strlen (v->label), 255); ext_len = ROUND_UP (l.label_len, sizeof l.label_len); memcpy (l.label, v->label, l.label_len); memset (&l.label[l.label_len], ' ', ext_len - l.label_len); @@ -523,7 +523,7 @@ write_variable (struct sfm_writer *w, const struct variable *v) memset (&sv.write, 0, sizeof sv.write); memset (&sv.name, 0, sizeof sv.name); - pad_count = DIV_RND_UP (min(v->width, MAX_LONG_STRING), + pad_count = DIV_RND_UP (MIN(v->width, MAX_LONG_STRING), (int) sizeof (flt64)) - 1; for (i = 0; i < pad_count; i++) buf_write (w, &sv, sizeof sv); @@ -839,7 +839,7 @@ buf_write (struct sfm_writer *w, const void *buf, size_t nbytes) static char * append_string_max (char *dest, const char *src, const char *end) { - int nbytes = min (end - dest, (int) strlen (src)); + int nbytes = MIN (end - dest, (int) strlen (src)); memcpy (dest, src, nbytes); return dest + nbytes; } diff --git a/src/data/variable.c b/src/data/variable.c index fc81c01e..ca302415 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -31,6 +31,8 @@ #include #include "value-labels.h" +#include "minmax.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -106,7 +108,7 @@ compare_values (const union value *a, const union value *b, int width) if (width == 0) return a->f < b->f ? -1 : a->f > b->f; else - return memcmp (a->s, b->s, min(MAX_SHORT_STRING, width)); + return memcmp (a->s, b->s, MIN(MAX_SHORT_STRING, width)); } /* Create a hash of v */ @@ -118,7 +120,7 @@ hash_value(const union value *v, int width) if ( 0 == width ) id_hash = hsh_hash_double (v->f); else - id_hash = hsh_hash_bytes (v->s, min(MAX_SHORT_STRING, width)); + id_hash = hsh_hash_bytes (v->s, MIN(MAX_SHORT_STRING, width)); return id_hash; } diff --git a/src/language/data-io/list.q b/src/language/data-io/list.q index 71238e8e..d4e24cdd 100644 --- a/src/language/data-io/list.q +++ b/src/language/data-io/list.q @@ -44,6 +44,8 @@ #include #include +#include "minmax.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -326,7 +328,7 @@ write_header (struct outp_driver *d) struct variable *v = cmd.v_variables[i]; memset (&prc->header[prc->header_rows - 1][x], '-', - max (v->print.w, (int) strlen (v->name))); + MAX (v->print.w, (int) strlen (v->name))); if ((int) strlen (v->name) < v->print.w) x += v->print.w - strlen (v->name); memcpy (&prc->header[0][x], v->name, strlen (v->name)); @@ -533,7 +535,7 @@ determine_layout (void) outp_open_page (d); max_width = n_chars_width (d); - largest_page_width = max (largest_page_width, max_width); + largest_page_width = MAX (largest_page_width, max_width); prc = d->prc = xmalloc (sizeof *prc); prc->type = 0; @@ -544,7 +546,7 @@ determine_layout (void) for (width = cmd.n_variables - 1, column = 0; column < cmd.n_variables; column++) { struct variable *v = cmd.v_variables[column]; - width += max (v->print.w, (int) strlen (v->name)); + width += MAX (v->print.w, (int) strlen (v->name)); } if (width <= max_width) { @@ -574,7 +576,7 @@ determine_layout (void) { struct variable *v = cmd.v_variables[column]; int trial_width = (width - v->print.w - + max (v->print.w, (int) strlen (v->name))); + + MAX (v->print.w, (int) strlen (v->name))); if (trial_width > max_width) { @@ -590,7 +592,7 @@ determine_layout (void) for (prc->header_rows = 0, column = 0; column < prc->n_vertical; column++) - prc->header_rows = max (prc->header_rows, + prc->header_rows = MAX (prc->header_rows, strlen (cmd.v_variables[column]->name)); prc->header_rows++; continue; @@ -638,7 +640,7 @@ list_cases (const struct ccase *c, void *aux UNUSED, const struct dataset *ds UN int width; if (prc->type == 0 && column >= prc->n_vertical) - width = max ((int) strlen (v->name), v->print.w); + width = MAX ((int) strlen (v->name), v->print.w); else width = v->print.w; diff --git a/src/language/data-io/matrix-data.c b/src/language/data-io/matrix-data.c index 6283279c..88cae91f 100644 --- a/src/language/data-io/matrix-data.c +++ b/src/language/data-io/matrix-data.c @@ -44,6 +44,7 @@ #include #include +#include "minmax.h" #include "size_max.h" #include "gettext.h" @@ -1737,8 +1738,8 @@ wr_read_rowtype (struct wr_aux_data *wr, char s[16]; char *cp; - memcpy (s, token->string, min (15, token->length)); - s[min (15, token->length)] = 0; + memcpy (s, token->string, MIN (15, token->length)); + s[MIN (15, token->length)] = 0; for (cp = s; *cp; cp++) *cp = toupper ((unsigned char) *cp); diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index 0aa32fa2..44278060 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -43,6 +43,8 @@ #include #include +#include "minmax.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -70,7 +72,7 @@ sysfile_info_dim (struct tab_table *t, struct outp_driver *d) int i; for (p = max; *p; p++) - t->w[p - max] = min (tab_natural_width (t, d, p - max), + t->w[p - max] = MIN (tab_natural_width (t, d, p - max), *p * d->prop_em_width); for (i = 0; i < t->nr; i++) t->h[i] = tab_natural_height (t, d, i); @@ -152,7 +154,7 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) if (r + 10 + nvl > nr) { - nr = max (nr * dict_get_var_cnt (d) / (i + 1), nr); + nr = MAX (nr * dict_get_var_cnt (d) / (i + 1), nr); nr += 10 + nvl; tab_realloc (t, 4, nr); } @@ -334,8 +336,8 @@ variables_dim (struct tab_table *t, struct outp_driver *d) t->w[0] = tab_natural_width (t, d, 0); if (_as == AS_DICTIONARY || _as == AS_VARIABLES || _as == AS_LABELS) { - t->w[1] = max (tab_natural_width (t, d, 1), d->prop_em_width * 5); - t->w[2] = max (tab_natural_width (t, d, 2), d->prop_em_width * 35); + t->w[1] = MAX (tab_natural_width (t, d, 1), d->prop_em_width * 5); + t->w[2] = MAX (tab_natural_width (t, d, 2), d->prop_em_width * 35); pc = 3; } else pc = 1; @@ -399,7 +401,7 @@ display_variables (struct variable **vl, size_t n, int as) if (r + 10 + nvl > nr) { - nr = max (nr * n / (i + 1), nr); + nr = MAX (nr * n / (i + 1), nr); nr += 10 + nvl; tab_realloc (t, nc, nr); } diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index 031a84f8..648e8896 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -46,6 +46,8 @@ #include #include +#include "minmax.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -809,7 +811,7 @@ accumulate_aggregate_info (struct agr_proc *agr, moments1_add (iter->moments, v->f, weight); break; case MAX: - iter->dbl[0] = max (iter->dbl[0], v->f); + iter->dbl[0] = MAX (iter->dbl[0], v->f); iter->int1 = 1; break; case MAX | FSTRING: @@ -818,7 +820,7 @@ accumulate_aggregate_info (struct agr_proc *agr, iter->int1 = 1; break; case MIN: - iter->dbl[0] = min (iter->dbl[0], v->f); + iter->dbl[0] = MIN (iter->dbl[0], v->f); iter->int1 = 1; break; case MIN | FSTRING: diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index 87386d6c..00ec6136 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -60,6 +60,8 @@ #include #include +#include "minmax.h" + #include "gettext.h" #define _(msgid) gettext (msgid) #define N_(msgid) msgid @@ -1222,7 +1224,7 @@ output_pivot_table (struct table_entry **pb, struct table_entry **pe, /* Allocate table space for the matrix. */ if (table && tab_row (table) + (n_rows + 1) * num_cells > tab_nr (table)) tab_realloc (table, -1, - max (tab_nr (table) + (n_rows + 1) * num_cells, + MAX (tab_nr (table) + (n_rows + 1) * num_cells, tab_nr (table) * (pe - pb) / (te - tb))); if (mode == GENERAL) @@ -2277,9 +2279,9 @@ calc_fisher (int a, int b, int c, int d, double *fisher1, double *fisher2) { int x; - if (min (c, d) < min (a, b)) + if (MIN (c, d) < MIN (a, b)) swap (&a, &c), swap (&b, &d); - if (min (b, d) < min (a, c)) + if (MIN (b, d) < MIN (a, c)) swap (&a, &b), swap (&c, &d); if (b * c < a * d) { @@ -2471,7 +2473,7 @@ static int calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC], double t[N_SYMMETRIC]) { - int q = min (ns_rows, ns_cols); + int q = MIN (ns_rows, ns_cols); if (q <= 1) return 0; @@ -3194,9 +3196,9 @@ format_short (char *s, const struct fmt_spec *fp, const union value *v) assert (fmt_subst.type == FMT_A || fmt_subst.type == FMT_AHEX); if (fmt_subst.type == FMT_A) - fmt_subst.w = min (8, fmt_subst.w); + fmt_subst.w = MIN (8, fmt_subst.w); else - fmt_subst.w = min (16, fmt_subst.w); + fmt_subst.w = MIN (16, fmt_subst.w); fp = &fmt_subst; } diff --git a/src/language/stats/examine.q b/src/language/stats/examine.q index d705a333..ca986972 100644 --- a/src/language/stats/examine.q +++ b/src/language/stats/examine.q @@ -50,6 +50,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA #include #include +#include "minmax.h" + #include "gettext.h" #define _(msgid) gettext (msgid) #define N_(msgid) msgid @@ -1728,8 +1730,8 @@ box_plot_variables (const struct factor *fctr, for ( i = 0 ; i < n_vars ; ++i ) { - y_max = max (y_max, (*fs)->m[i].max); - y_min = min (y_min, (*fs)->m[i].min); + y_max = MAX (y_max, (*fs)->m[i].max); + y_min = MIN (y_min, (*fs)->m[i].min); } boxplot_draw_yscale (ch, y_max, y_min); @@ -1870,8 +1872,8 @@ np_plot (const struct metrics *m, const char *factorname) { /* Need to make sure that both the scatter plot and the ideal fit into the plot */ - double x_lower = min (m->min, (yfirst - intercept) / slope) ; - double x_upper = max (m->max, (ylast - intercept) / slope) ; + double x_lower = MIN (m->min, (yfirst - intercept) / slope) ; + double x_upper = MAX (m->max, (ylast - intercept) / slope) ; double slack = (x_upper - x_lower) * 0.05 ; chart_write_xscale (np_chart, x_lower - slack, x_upper + slack, 5); diff --git a/src/language/stats/flip.c b/src/language/stats/flip.c index 465ea79c..c4242728 100644 --- a/src/language/stats/flip.c +++ b/src/language/stats/flip.c @@ -49,6 +49,7 @@ #include #include "intprops.h" +#include "minmax.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -231,7 +232,7 @@ make_new_var (struct dictionary *dict, char name[]) for (i = 1; i < 10000000; i++) { - int ofs = min (7 - intlog10 (i), len); + int ofs = MIN (7 - intlog10 (i), len); memcpy (n, name, ofs); sprintf (&n[ofs], "%d", i); @@ -342,7 +343,7 @@ flip_sink_write (struct case_sink *sink, const struct ccase *c) } else { - int width = min (flip->new_names->width, MAX_SHORT_STRING); + int width = MIN (flip->new_names->width, MAX_SHORT_STRING); memcpy (v->name, case_str (c, flip->idx_to_fv[flip->new_names->index]), width); v->name[width] = 0; @@ -430,7 +431,7 @@ flip_file (struct flip_pgm *flip) for (case_idx = 0; case_idx < flip->case_cnt; ) { - unsigned long read_cases = min (flip->case_cnt - case_idx, + unsigned long read_cases = MIN (flip->case_cnt - case_idx, case_capacity); size_t i; diff --git a/src/language/stats/frequencies.q b/src/language/stats/frequencies.q index 929f987a..5460b65f 100644 --- a/src/language/stats/frequencies.q +++ b/src/language/stats/frequencies.q @@ -1144,9 +1144,9 @@ full_dim (struct tab_table *t, struct outp_driver *d) int i; if (lab) - t->w[0] = min (tab_natural_width (t, d, 0), d->prop_em_width * 15); + t->w[0] = MIN (tab_natural_width (t, d, 0), d->prop_em_width * 15); for (i = lab; i < lab + 5; i++) - t->w[i] = max (tab_natural_width (t, d, i), d->prop_em_width * 8); + t->w[i] = MAX (tab_natural_width (t, d, i), d->prop_em_width * 8); for (i = 0; i < t->nr; i++) t->h[i] = d->font_height; } @@ -1268,14 +1268,14 @@ dump_full (struct variable *v) static void condensed_dim (struct tab_table *t, struct outp_driver *d) { - int cum_w = max (outp_string_width (d, _("Cum"), OUTP_PROPORTIONAL), - max (outp_string_width (d, _("Cum"), OUTP_PROPORTIONAL), + int cum_w = MAX (outp_string_width (d, _("Cum"), OUTP_PROPORTIONAL), + MAX (outp_string_width (d, _("Cum"), OUTP_PROPORTIONAL), outp_string_width (d, "000", OUTP_PROPORTIONAL))); int i; for (i = 0; i < 2; i++) - t->w[i] = max (tab_natural_width (t, d, i), d->prop_em_width * 8); + t->w[i] = MAX (tab_natural_width (t, d, i), d->prop_em_width * 8); for (i = 2; i < 4; i++) t->w[i] = cum_w; for (i = 0; i < t->nr; i++) diff --git a/src/libpspp/ChangeLog b/src/libpspp/ChangeLog index e7801687..85ab3204 100644 --- a/src/libpspp/ChangeLog +++ b/src/libpspp/ChangeLog @@ -1,3 +1,9 @@ +Fri Nov 24 17:27:00 2006 Ben Pfaff + + * misc.h: (min) Removed. All references updated to use MIN, from + minmax.h provided by gnulib. + (max) Ditto (for MAX). + Sun Nov 19 09:22:26 2006 Ben Pfaff * str.c (ss_get_long): New function. diff --git a/src/libpspp/array.c b/src/libpspp/array.c index c7e25f60..da2c76e9 100644 --- a/src/libpspp/array.c +++ b/src/libpspp/array.c @@ -99,6 +99,8 @@ #include #include "message.h" + +#include "minmax.h" /* Finds an element in ARRAY, which contains COUNT elements of SIZE bytes each, using COMPARE for comparisons. Returns the @@ -700,12 +702,10 @@ sort (void *array, size_t count, size_t size, of the array to sort, and END_PTR points at the very last element in the array (*not* one beyond it!). */ -#define min(x, y) ((x) < (y) ? (x) : (y)) - { char *const end_ptr = &first[size * (count - 1)]; char *tmp_ptr = first; - char *thresh = min(end_ptr, first + max_thresh); + char *thresh = MIN (end_ptr, first + max_thresh); register char *run_ptr; /* Find smallest element in first threshold and place it at the diff --git a/src/libpspp/misc.h b/src/libpspp/misc.h index a1be9f9f..16f16b97 100644 --- a/src/libpspp/misc.h +++ b/src/libpspp/misc.h @@ -43,14 +43,6 @@ #include /* Declares finite() under Solaris. */ #endif -#ifndef min -#define min(A, B) ((A) < (B) ? (A) : (B)) -#endif - -#ifndef max -#define max(A, B) ((A) > (B) ? (A) : (B)) -#endif - /* Clamps A to be between B and C. */ #define range(A, B, C) ((A) < (B) ? (B) : ((A) > (C) ? (C) : (A))) diff --git a/src/math/percentiles.c b/src/math/percentiles.c index 7fec4ce9..b72a98a1 100644 --- a/src/math/percentiles.c +++ b/src/math/percentiles.c @@ -19,18 +19,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include +#include #include #include "factor-stats.h" #include "percentiles.h" #include +#include "minmax.h" + #include "gettext.h" #define _(msgid) gettext (msgid) #define N_(msgid) msgid -#include - - struct ptile_params { double g1, g1_star; @@ -337,7 +337,7 @@ tukey_hinges(const struct weighted_value **wv, for ( i = 0 ; i < n_data ; ++i ) { - c_star = min(c_star, wv[i]->w); + c_star = MIN(c_star, wv[i]->w); } if ( c_star > 1 ) c_star = 1; diff --git a/src/math/sort.c b/src/math/sort.c index 9f5e5fb9..827c2314 100644 --- a/src/math/sort.c +++ b/src/math/sort.c @@ -44,6 +44,8 @@ #include #include +#include "minmax.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -587,7 +589,7 @@ merge (struct external_sort *xsrt) { while (xsrt->run_cnt > 1) { - int order = min (MAX_MERGE_ORDER, xsrt->run_cnt); + int order = MIN (MAX_MERGE_ORDER, xsrt->run_cnt); int idx = choose_merge (xsrt->runs, xsrt->run_cnt, order); xsrt->runs[idx] = merge_once (xsrt, xsrt->runs + idx, order); remove_range (xsrt->runs, xsrt->run_cnt, sizeof *xsrt->runs, diff --git a/src/output/charts/piechart.c b/src/output/charts/piechart.c index 37788380..cbeaadfd 100644 --- a/src/output/charts/piechart.c +++ b/src/output/charts/piechart.c @@ -33,7 +33,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA #include #include #include -#include + +#include "minmax.h" /* Pie charts of course need to know Pi :) */ @@ -71,7 +72,7 @@ piechart_plot(const char *title, const struct slice *slices, int n_slices) const double centre_x = (ch->data_right + ch->data_left ) / 2.0 ; const double centre_y = (ch->data_top + ch->data_bottom ) / 2.0 ; - const double radius = min( + const double radius = MIN( 5.0 / 12.0 * (ch->data_top - ch->data_bottom), 1.0 / 4.0 * (ch->data_right - ch->data_left) ); diff --git a/src/output/table.c b/src/output/table.c index ca3e467c..a8624488 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -142,8 +142,8 @@ tab_realloc (struct tab_table *t, int nc, int nr) if (nc > t->cf) { - int mr1 = min (nr, t->nr); - int mc1 = min (nc, t->nc); + int mr1 = MIN (nr, t->nr); + int mc1 = MIN (nc, t->nc); struct substring *new_cc; unsigned char *new_ct;