diff options
Diffstat (limited to 'trace-plot.c')
| -rw-r--r-- | trace-plot.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/trace-plot.c b/trace-plot.c new file mode 100644 index 0000000..35d3352 --- /dev/null +++ b/trace-plot.c | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | #include <string.h> | ||
| 2 | #include "trace-graph.h" | ||
| 3 | |||
| 4 | void trace_graph_plot_free(struct graph_info *ginfo) | ||
| 5 | { | ||
| 6 | struct graph_plot *plot; | ||
| 7 | |||
| 8 | while (ginfo->plot_list) { | ||
| 9 | plot = ginfo->plot_list; | ||
| 10 | ginfo->plot_list = plot->next; | ||
| 11 | free(plot); | ||
| 12 | } | ||
| 13 | |||
| 14 | if (ginfo->plot_array) { | ||
| 15 | free(ginfo->plot_array); | ||
| 16 | ginfo->plot_array = NULL; | ||
| 17 | }; | ||
| 18 | |||
| 19 | ginfo->plots = 0; | ||
| 20 | } | ||
| 21 | |||
| 22 | void trace_graph_plot_init(struct graph_info *ginfo) | ||
| 23 | { | ||
| 24 | ginfo->plots = 0; | ||
| 25 | ginfo->plot_array = NULL; | ||
| 26 | ginfo->plot_list = NULL; | ||
| 27 | } | ||
| 28 | |||
| 29 | void trace_graph_plot_append(struct graph_info *ginfo, | ||
| 30 | const char *label, struct plot_callbacks *cb) | ||
| 31 | { | ||
| 32 | struct graph_plot *plot; | ||
| 33 | char *name; | ||
| 34 | |||
| 35 | name = strdup(label); | ||
| 36 | if (!name) | ||
| 37 | die("Unable to allocate label"); | ||
| 38 | |||
| 39 | plot = malloc_or_die(sizeof(*plot)); | ||
| 40 | memset(plot, 0, sizeof(*plot)); | ||
| 41 | |||
| 42 | plot->label = name; | ||
| 43 | plot->cb = cb; | ||
| 44 | |||
| 45 | plot->next = ginfo->plot_list; | ||
| 46 | ginfo->plot_list = plot; | ||
| 47 | |||
| 48 | if (!ginfo->plots) { | ||
| 49 | ginfo->plot_array = malloc_or_die(sizeof(ginfo->plot_array[0])); | ||
| 50 | ginfo->plot_array[0] = plot; | ||
| 51 | } else { | ||
| 52 | ginfo->plot_array = realloc(ginfo->plot_array, | ||
| 53 | sizeof(ginfo->plot_array[0]) * | ||
| 54 | (ginfo->plots + 1)); | ||
| 55 | |||
| 56 | if (!ginfo->plot_array) | ||
| 57 | die("unable to resize plot array"); | ||
| 58 | |||
| 59 | ginfo->plot_array[ginfo->plots] = plot; | ||
| 60 | } | ||
| 61 | |||
| 62 | ginfo->plots++; | ||
| 63 | } | ||
