1 | #include "output.h" |
---|
2 | #include <stdio.h> |
---|
3 | #include <stdlib.h> |
---|
4 | #include <inttypes.h> |
---|
5 | #include <lt_inttypes.h> |
---|
6 | |
---|
7 | static void output_html_init(struct output_data_t *out) |
---|
8 | { |
---|
9 | int i; |
---|
10 | printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n"); |
---|
11 | printf("<html>\n"); |
---|
12 | printf("<head>\n"); |
---|
13 | printf(" <title>%s</title>\n",out->title); |
---|
14 | printf(" <style type=\"text/css\">\n"); |
---|
15 | printf(" table { border-collapse: collapse; width: 100%%}\n"); |
---|
16 | printf(" td { border: thin black solid; }\n"); |
---|
17 | printf(" .numeric { text-align: right; }\n"); |
---|
18 | printf(" .even { background: #e0e0e0; }\n"); |
---|
19 | printf(" .odd { background: #ffffff; }\n"); |
---|
20 | printf(" .rowheading { text-align: right; }\n"); |
---|
21 | printf(" </style>\n"); |
---|
22 | printf("</head>\n"); |
---|
23 | printf("<body>\n"); |
---|
24 | printf("<h1>%s</h1>\n",out->title); |
---|
25 | printf("<table>\n"); |
---|
26 | printf(" <tr>\n"); |
---|
27 | for(i=0;i<out->columns;++i) { |
---|
28 | printf(" <th>%s</th>",out->labels[i]); |
---|
29 | } |
---|
30 | printf(" </tr>\n"); |
---|
31 | out->private_format_data=malloc(sizeof(int)); |
---|
32 | *(int*)out->private_format_data=0; |
---|
33 | } |
---|
34 | |
---|
35 | static void output_html_flush(struct output_data_t *out) |
---|
36 | { |
---|
37 | int i; |
---|
38 | printf(" <tr class=\"%s\">\n",((*(int*)out->private_format_data)++)&1?"odd":"even"); |
---|
39 | for(i=0;i<out->columns;++i) { |
---|
40 | switch (out->data[i].type) { |
---|
41 | case TYPE_int: |
---|
42 | printf(" <td class=\"numeric\">%" PRIu64 "</td>\n",out->data[i].d.d_int); |
---|
43 | break; |
---|
44 | case TYPE_str: |
---|
45 | printf(" <td>%s</td>\n",out->data[i].d.d_str); |
---|
46 | free(out->data[i].d.d_str); |
---|
47 | break; |
---|
48 | case TYPE_float: |
---|
49 | printf(" <td class=\"numeric\">%f</td>\n",out->data[i].d.d_float); |
---|
50 | break; |
---|
51 | case TYPE_time: |
---|
52 | printf(" <td class=\"numeric\">%.03f</td>\n",out->data[i].d.d_time); |
---|
53 | break; |
---|
54 | } |
---|
55 | } |
---|
56 | printf(" </tr>\n"); |
---|
57 | } |
---|
58 | |
---|
59 | static void output_html_destroy(struct output_data_t *out) |
---|
60 | { |
---|
61 | printf("</table>\n"); |
---|
62 | printf("</body>\n"); |
---|
63 | printf("</html>\n"); |
---|
64 | } |
---|
65 | |
---|
66 | struct output_type_t output_html = { |
---|
67 | name: "html", |
---|
68 | init: output_html_init, |
---|
69 | flush: output_html_flush, |
---|
70 | destroy: output_html_destroy, |
---|
71 | }; |
---|