1 | /* |
---|
2 | * |
---|
3 | * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand. |
---|
4 | * All rights reserved. |
---|
5 | * |
---|
6 | * This file is part of libtrace. |
---|
7 | * |
---|
8 | * This code has been developed by the University of Waikato WAND |
---|
9 | * research group. For further information please see http://www.wand.net.nz/ |
---|
10 | * |
---|
11 | * libtrace is free software; you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Lesser General Public License as published by |
---|
13 | * the Free Software Foundation; either version 3 of the License, or |
---|
14 | * (at your option) any later version. |
---|
15 | * |
---|
16 | * libtrace is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU Lesser General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU Lesser General Public License |
---|
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | * |
---|
25 | */ |
---|
26 | |
---|
27 | |
---|
28 | #include "output.h" |
---|
29 | #include <stdio.h> |
---|
30 | #include <stdlib.h> |
---|
31 | #include <inttypes.h> |
---|
32 | #include <lt_inttypes.h> |
---|
33 | |
---|
34 | static void output_html_init(struct output_data_t *out) |
---|
35 | { |
---|
36 | int i; |
---|
37 | printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n"); |
---|
38 | printf("<html>\n"); |
---|
39 | printf("<head>\n"); |
---|
40 | printf(" <title>%s</title>\n",out->title); |
---|
41 | printf(" <style type=\"text/css\">\n"); |
---|
42 | printf(" table { border-collapse: collapse; width: 100%%}\n"); |
---|
43 | printf(" td { border: thin black solid; }\n"); |
---|
44 | printf(" .numeric { text-align: right; }\n"); |
---|
45 | printf(" .even { background: #e0e0e0; }\n"); |
---|
46 | printf(" .odd { background: #ffffff; }\n"); |
---|
47 | printf(" .rowheading { text-align: right; }\n"); |
---|
48 | printf(" </style>\n"); |
---|
49 | printf("</head>\n"); |
---|
50 | printf("<body>\n"); |
---|
51 | printf("<h1>%s</h1>\n",out->title); |
---|
52 | printf("<table>\n"); |
---|
53 | printf(" <tr>\n"); |
---|
54 | for(i=0;i<out->columns;++i) { |
---|
55 | printf(" <th>%s</th>",out->labels[i]); |
---|
56 | } |
---|
57 | printf(" </tr>\n"); |
---|
58 | out->private_format_data=malloc(sizeof(int)); |
---|
59 | *(int*)out->private_format_data=0; |
---|
60 | } |
---|
61 | |
---|
62 | static void output_html_flush(struct output_data_t *out) |
---|
63 | { |
---|
64 | int i; |
---|
65 | printf(" <tr class=\"%s\">\n",((*(int*)out->private_format_data)++)&1?"odd":"even"); |
---|
66 | for(i=0;i<out->columns;++i) { |
---|
67 | switch (out->data[i].type) { |
---|
68 | case TYPE_int: |
---|
69 | printf(" <td class=\"numeric\">%" PRIu64 "</td>\n",out->data[i].d.d_int); |
---|
70 | break; |
---|
71 | case TYPE_str: |
---|
72 | printf(" <td>%s</td>\n",out->data[i].d.d_str); |
---|
73 | free(out->data[i].d.d_str); |
---|
74 | break; |
---|
75 | case TYPE_float: |
---|
76 | printf(" <td class=\"numeric\">%f</td>\n",out->data[i].d.d_float); |
---|
77 | break; |
---|
78 | case TYPE_time: |
---|
79 | printf(" <td class=\"numeric\">%.03f</td>\n",out->data[i].d.d_time); |
---|
80 | break; |
---|
81 | } |
---|
82 | } |
---|
83 | printf(" </tr>\n"); |
---|
84 | } |
---|
85 | |
---|
86 | static void output_html_destroy(struct output_data_t *out) |
---|
87 | { |
---|
88 | (void)out; |
---|
89 | printf("</table>\n"); |
---|
90 | printf("</body>\n"); |
---|
91 | printf("</html>\n"); |
---|
92 | } |
---|
93 | |
---|
94 | struct output_type_t output_html = { |
---|
95 | .name= "html", |
---|
96 | .init= output_html_init, |
---|
97 | .flush= output_html_flush, |
---|
98 | .destroy= output_html_destroy, |
---|
99 | }; |
---|