From aca4a1b52d159a721d05961f0971b725d3102e02 Mon Sep 17 00:00:00 2001 From: sfeam Date: Fri, 29 Sep 2017 19:23:36 +0000 Subject: [PATCH] rework parsing and handling of filledcurve options --- ChangeLog | 3 +++ src/gadgets.h | 3 +-- src/graphics.c | 26 ++++++++++--------- src/misc.c | 70 ++++++++++++++++++++++++-------------------------- src/plot2d.c | 9 ++++--- src/set.c | 6 ++--- src/tables.h | 7 ++--- 7 files changed, 63 insertions(+), 61 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc65ff0c2..5dac1126a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ range was inverted. The error was introduced by converting from a macro to a subroutine in the run-up to 5.2. + * src/gadgets.h src/graphics.c src/misc.c src/plot2d.c src/set.c + src/tables.h: Rework parsing and handling of filledcurve options. + 2017-09-25 Ethan A Merritt * src/plot2d.c: smoothing options csplines|acsplines|bezier|sbezier diff --git a/src/gadgets.h b/src/gadgets.h index 8c51d4e3c..cc2ea19a5 100644 --- a/src/gadgets.h +++ b/src/gadgets.h @@ -246,8 +246,7 @@ typedef enum en_key_sample_positioning { } t_key_sample_positioning; typedef struct { - int opt_given; /* option given / not given (otherwise default) */ - int closeto; /* from list FILLEDCURVES_CLOSED, ... */ + enum filledcurves_opts_id closeto; /* from list FILLEDCURVES_CLOSED, ... */ double at; /* value for FILLEDCURVES_AT... */ double aty; /* the other value for FILLEDCURVES_ATXY */ int oneside; /* -1 if fill below bound only; +1 if fill above bound only */ diff --git a/src/graphics.c b/src/graphics.c index d91eff0f1..31d37ba8a 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: graphics.c,v 1.574 2017-09-13 22:59:29 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: graphics.c,v 1.575 2017-09-29 19:23:36 sfeam Exp $"); } #endif /* GNUPLOT - graphics.c */ @@ -796,7 +796,17 @@ do_plot(struct curve_points *plots, int pcount) break; case FILLEDCURVES: - if (this_plot->filledcurves_options.closeto == FILLEDCURVES_BETWEEN) { + if (this_plot->filledcurves_options.closeto == FILLEDCURVES_DEFAULT) { + if (this_plot->plot_type == DATA) + memcpy(&this_plot->filledcurves_options, + &filledcurves_opts_data, sizeof(filledcurves_opts)); + else + memcpy(&this_plot->filledcurves_options, + &filledcurves_opts_func, sizeof(filledcurves_opts)); + } + if (this_plot->filledcurves_options.closeto == FILLEDCURVES_BETWEEN + || this_plot->filledcurves_options.closeto == FILLEDCURVES_ABOVE + || this_plot->filledcurves_options.closeto == FILLEDCURVES_BELOW) { plot_betweencurves(this_plot); } else if (!this_plot->plot_smooth && (this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1 @@ -1245,16 +1255,6 @@ plot_filledcurves(struct curve_points *plot) return; } - if (!plot->filledcurves_options.opt_given) { - /* no explicitly given filledcurves option for the current plot => - use the default for data or function, respectively - */ - if (plot->plot_type == DATA) - memcpy(&plot->filledcurves_options, &filledcurves_opts_data, sizeof(filledcurves_opts)); - else - memcpy(&plot->filledcurves_options, &filledcurves_opts_func, sizeof(filledcurves_opts)); - } - /* clip the "at" coordinate to the drawing area */ switch (plot->filledcurves_options.closeto) { case FILLEDCURVES_ATX1: @@ -1276,6 +1276,8 @@ plot_filledcurves(struct curve_points *plot) cliptorange(plot->filledcurves_options.aty, axis_array[FIRST_Y_AXIS].min, axis_array[FIRST_Y_AXIS].max); break; + default: + break; } for (i = 0; i < plot->p_count; i++) { diff --git a/src/misc.c b/src/misc.c index 3399590dc..742a7b7d7 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: misc.c,v 1.213 2017-07-25 21:48:16 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: misc.c,v 1.214 2017-09-29 19:23:36 sfeam Exp $"); } #endif /* GNUPLOT - misc.c */ @@ -781,47 +781,43 @@ get_style() } /* Parse options for style filledcurves and fill fco accordingly. - * If no option given, then set fco->opt_given to 0. + * If no option given, set it to FILLEDCURVES_DEFAULT. */ void get_filledcurves_style_options(filledcurves_opts *fco) { - int p; - p = lookup_table(&filledcurves_opts_tbl[0], c_token); - - if (p == FILLEDCURVES_ABOVE) { - fco->oneside = 1; - p = lookup_table(&filledcurves_opts_tbl[0], ++c_token); - } else if (p == FILLEDCURVES_BELOW) { - fco->oneside = -1; - p = lookup_table(&filledcurves_opts_tbl[0], ++c_token); - } else - fco->oneside = 0; - - if (p == -1) { - fco->opt_given = 0; - return; /* no option given */ - } else - fco->opt_given = 1; + enum filledcurves_opts_id p; + fco->closeto = FILLEDCURVES_DEFAULT; + fco->oneside = 0; - c_token++; + while ((p = lookup_table(&filledcurves_opts_tbl[0], c_token)) != -1) { + fco->closeto = p; + c_token++; - fco->closeto = p; - fco->at = 0; - if (!equals(c_token, "=")) - return; - /* parameter required for filledcurves x1=... and friends */ - if (p < FILLEDCURVES_ATXY) - fco->closeto += 4; - c_token++; - fco->at = real_expression(); - if (p != FILLEDCURVES_ATXY) - return; - /* two values required for FILLEDCURVES_ATXY */ - if (!equals(c_token, ",")) - int_error(c_token, "syntax is xy=,"); - c_token++; - fco->aty = real_expression(); + if (p == FILLEDCURVES_ABOVE) { + fco->oneside = 1; + continue; + } else if (p == FILLEDCURVES_BELOW) { + fco->oneside = -1; + continue; + } + + fco->at = 0; + if (!equals(c_token, "=")) + return; + /* parameter required for filledcurves x1=... and friends */ + if (p < FILLEDCURVES_ATXY) + fco->closeto += 4; + c_token++; + fco->at = real_expression(); + if (p != FILLEDCURVES_ATXY) + return; + /* two values required for FILLEDCURVES_ATXY */ + if (!equals(c_token, ",")) + int_error(c_token, "syntax is xy=,"); + c_token++; + fco->aty = real_expression(); + } return; } @@ -831,7 +827,7 @@ get_filledcurves_style_options(filledcurves_opts *fco) void filledcurves_options_tofile(filledcurves_opts *fco, FILE *fp) { - if (!fco->opt_given) + if (fco->closeto == FILLEDCURVES_DEFAULT) return; if (fco->oneside) fputs(fco->oneside > 0 ? "above " : "below ", fp); diff --git a/src/plot2d.c b/src/plot2d.c index d63500a36..1ecf20422 100644 --- a/src/plot2d.c +++ b/src/plot2d.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: plot2d.c,v 1.458 2017-09-25 16:44:52 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: plot2d.c,v 1.459 2017-09-29 19:23:37 sfeam Exp $"); } #endif /* GNUPLOT - plot2d.c */ @@ -969,7 +969,8 @@ get_data(struct curve_points *current_plot) /* fall through */ case FILLEDCURVES: - current_plot->filledcurves_options.closeto = FILLEDCURVES_BETWEEN; + if (current_plot->filledcurves_options.closeto == FILLEDCURVES_DEFAULT) + current_plot->filledcurves_options.closeto = FILLEDCURVES_BETWEEN; store2d_point(current_plot, i++, v[0], v[1], v[0], v[0], v[1], v[2], -1.0); break; @@ -2081,7 +2082,7 @@ eval_plots() this_plot->plot_type = DATA; this_plot->plot_style = data_style; this_plot->plot_smooth = SMOOTH_NONE; - this_plot->filledcurves_options.opt_given = 0; + this_plot->filledcurves_options.closeto = FILLEDCURVES_DEFAULT; /* Only relevant to "with table" */ free_at(table_filter_at); @@ -2132,7 +2133,7 @@ eval_plots() } this_plot->plot_type = FUNC; this_plot->plot_style = func_style; - this_plot->filledcurves_options.opt_given = 0; + this_plot->filledcurves_options.closeto = FILLEDCURVES_DEFAULT; end_token = c_token - 1; } /* end of IS THIS A FILE OR A FUNC block */ diff --git a/src/set.c b/src/set.c index 3ae52f9a6..aaf138031 100644 --- a/src/set.c +++ b/src/set.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: set.c,v 1.570 2017-09-17 18:54:49 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: set.c,v 1.571 2017-09-29 19:23:37 sfeam Exp $"); } #endif /* GNUPLOT - set.c */ @@ -4615,7 +4615,7 @@ set_style() data_style = get_style(); if (data_style == FILLEDCURVES) { get_filledcurves_style_options(&filledcurves_opts_data); - if (!filledcurves_opts_data.opt_given) /* default value */ + if (filledcurves_opts_func.closeto == FILLEDCURVES_DEFAULT) filledcurves_opts_data.closeto = FILLEDCURVES_CLOSED; } break; @@ -4632,7 +4632,7 @@ set_style() func_style = temp_style; if (func_style == FILLEDCURVES) { get_filledcurves_style_options(&filledcurves_opts_func); - if (!filledcurves_opts_func.opt_given) /* default value */ + if (filledcurves_opts_func.closeto == FILLEDCURVES_DEFAULT) filledcurves_opts_func.closeto = FILLEDCURVES_CLOSED; } break; diff --git a/src/tables.h b/src/tables.h index cc0917316..2f80d7dd4 100644 --- a/src/tables.h +++ b/src/tables.h @@ -1,5 +1,5 @@ /* - * $Id: tables.h,v 1.105 2017-09-11 20:13:24 sfeam Exp $ + * $Id: tables.h,v 1.106 2017-09-29 19:23:37 sfeam Exp $ */ /* GNUPLOT - tables.h */ @@ -199,14 +199,15 @@ enum show_style_id { }; enum filledcurves_opts_id { - FILLEDCURVES_CLOSED, + FILLEDCURVES_CLOSED=0, FILLEDCURVES_X1, FILLEDCURVES_Y1, FILLEDCURVES_X2, FILLEDCURVES_Y2, /* requirement: FILLEDCURVES_ATX1 = FILLEDCURVES_X1+4 */ FILLEDCURVES_ATX1, FILLEDCURVES_ATY1, FILLEDCURVES_ATX2, FILLEDCURVES_ATY2, FILLEDCURVES_ATXY, FILLEDCURVES_ATR, FILLEDCURVES_ABOVE, FILLEDCURVES_BELOW, - FILLEDCURVES_BETWEEN + FILLEDCURVES_BETWEEN, + FILLEDCURVES_DEFAULT }; extern const struct gen_table command_tbl[];