4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change
on this file since d994324 was
5d081ff,
checked in by Shane Alcock <salcock@…>, 12 years ago
|
- Fixed segfault if you specified an invalid output format
- Also make sure we free the duplicated string in the event of failure
|
-
Property mode set to
100644
|
File size:
1.7 KB
|
Line | |
---|
1 | #include "config.h" |
---|
2 | #include <inttypes.h> |
---|
3 | #include <lt_inttypes.h> |
---|
4 | #include <stdio.h> |
---|
5 | #include <assert.h> |
---|
6 | #include <stdlib.h> |
---|
7 | #include <string.h> |
---|
8 | |
---|
9 | #include "output.h" |
---|
10 | |
---|
11 | struct output_type_t *output_formats[] = { |
---|
12 | &output_txt, |
---|
13 | &output_csv, |
---|
14 | &output_html, |
---|
15 | #ifdef HAVE_LIBGDC |
---|
16 | &output_png, |
---|
17 | #endif |
---|
18 | NULL |
---|
19 | }; |
---|
20 | |
---|
21 | struct output_data_t *output_init(char *title,char *type) |
---|
22 | { |
---|
23 | output_data_t *data = malloc(sizeof(output_data_t)); |
---|
24 | int i=0; |
---|
25 | data->title=strdup(title); |
---|
26 | data->labels=NULL; |
---|
27 | data->columns=0; |
---|
28 | data->data=NULL; |
---|
29 | while(output_formats[i]) { |
---|
30 | if (strcmp(output_formats[i]->name,type)==0) { |
---|
31 | data->format = output_formats[i]; |
---|
32 | return data; |
---|
33 | } |
---|
34 | ++i; |
---|
35 | } |
---|
36 | /* Not found */ |
---|
37 | free(data->title); |
---|
38 | free(data); |
---|
39 | return NULL; |
---|
40 | } |
---|
41 | |
---|
42 | void output_add_column(struct output_data_t *out,char *col) |
---|
43 | { |
---|
44 | ++out->columns; |
---|
45 | out->labels=realloc(out->labels,out->columns*sizeof(char *)); |
---|
46 | out->labels[out->columns-1]=strdup(col); |
---|
47 | out->data=realloc(out->data,out->columns*sizeof(struct data_t)); |
---|
48 | } |
---|
49 | |
---|
50 | void output_flush_headings(struct output_data_t *out) |
---|
51 | { |
---|
52 | out->format->init(out); |
---|
53 | } |
---|
54 | |
---|
55 | #define output_set_data(type_) \ |
---|
56 | void output_set_data_ ## type_(struct output_data_t *out, \ |
---|
57 | int col,TYPE__ ## type_ data)\ |
---|
58 | { \ |
---|
59 | assert(col>=0 && col<out->columns); \ |
---|
60 | out->data[col].type=TYPE_ ## type_; \ |
---|
61 | out->data[col].d.d_ ## type_ = data; \ |
---|
62 | } |
---|
63 | |
---|
64 | output_set_data(str) |
---|
65 | output_set_data(int) |
---|
66 | output_set_data(float) |
---|
67 | output_set_data(time) |
---|
68 | #undef output_set_data |
---|
69 | |
---|
70 | void output_flush_row(struct output_data_t *out) |
---|
71 | { |
---|
72 | out->format->flush(out); |
---|
73 | } |
---|
74 | |
---|
75 | void output_destroy(struct output_data_t *out) |
---|
76 | { |
---|
77 | int i; |
---|
78 | out->format->destroy(out); |
---|
79 | for(i=0;i<out->columns;++i) { |
---|
80 | free(out->labels[i]); |
---|
81 | } |
---|
82 | free(out->data); |
---|
83 | free(out->labels); |
---|
84 | free(out); |
---|
85 | } |
---|
86 | |
---|
Note: See
TracBrowser
for help on using the repository browser.