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 | #include <string.h> |
---|
34 | |
---|
35 | #define COLWIDTH 11 |
---|
36 | |
---|
37 | static void output_txt_init(struct output_data_t *out) |
---|
38 | { |
---|
39 | int i; |
---|
40 | for(i=0;i<out->columns;++i) { |
---|
41 | if (strlen(out->labels[i])>8) |
---|
42 | printf("[%i]: %s\n",i,out->labels[i]); |
---|
43 | } |
---|
44 | printf("\n"); |
---|
45 | for(i=0;i<out->columns;++i) { |
---|
46 | if (strlen(out->labels[i])>8) |
---|
47 | printf("[%*i] ",COLWIDTH-3,i); |
---|
48 | else |
---|
49 | printf("%*s ",COLWIDTH-1,out->labels[i]); |
---|
50 | } |
---|
51 | printf("\n"); |
---|
52 | } |
---|
53 | |
---|
54 | static void output_txt_flush(struct output_data_t *out) |
---|
55 | { |
---|
56 | int i; |
---|
57 | for(i=0;i<out->columns;++i) { |
---|
58 | switch (out->data[i].type) { |
---|
59 | case TYPE_int: |
---|
60 | printf("%*" PRIu64 " ",COLWIDTH-1,out->data[i].d.d_int); |
---|
61 | break; |
---|
62 | case TYPE_str: |
---|
63 | printf("%*s ",COLWIDTH-1,out->data[i].d.d_str); |
---|
64 | free(out->data[i].d.d_str); |
---|
65 | break; |
---|
66 | case TYPE_float: |
---|
67 | printf("%*f ",COLWIDTH-1,out->data[i].d.d_float); |
---|
68 | break; |
---|
69 | case TYPE_time: |
---|
70 | printf("%*.0f ",COLWIDTH-1,out->data[i].d.d_time); |
---|
71 | break; |
---|
72 | } |
---|
73 | } |
---|
74 | printf("\n"); |
---|
75 | } |
---|
76 | |
---|
77 | static void output_txt_destroy(struct output_data_t *out) |
---|
78 | { |
---|
79 | (void)out; |
---|
80 | /* Do nothing */ |
---|
81 | } |
---|
82 | |
---|
83 | struct output_type_t output_txt = { |
---|
84 | .name= "txt", |
---|
85 | .init= output_txt_init, |
---|
86 | .flush= output_txt_flush, |
---|
87 | .destroy= output_txt_destroy, |
---|
88 | }; |
---|