command 'setplot': add predefined 'previous' and 'next' parameters

to switch to the previous or next plot. A warning results if this
is not possible, then the currnt plot is not changed.
This commit is contained in:
Holger Vogt 2018-08-06 20:06:48 +02:00
parent a244d703c9
commit c5b5190199
1 changed files with 22 additions and 0 deletions

View File

@ -966,6 +966,28 @@ plot_setcur(char *name)
plot_cur = pl;
return;
}
/* plots are listed in pl in reverse order */
else if (cieq(name, "previous")) {
if (plot_cur->pl_next)
plot_cur = plot_cur->pl_next;
else
fprintf(cp_err, "Warning: Switching to previous plot not possible, stay with current plot (%s)\n", plot_cur->pl_typename);
return;
}
else if (cieq(name, "next")) {
struct plot *prev_pl = NULL;
for (pl = plot_list; pl; pl = pl->pl_next) {
if (pl == plot_cur)
break;
prev_pl = pl;
}
if (!prev_pl) {
fprintf(cp_err, "Warning: Switching to next plot not possible, stay with current plot (%s)\n", plot_cur->pl_typename);
return;
}
plot_cur = prev_pl;
return;
}
for (pl = plot_list; pl; pl = pl->pl_next)
if (plot_prefix(name, pl->pl_typename))
break;