/
display.c
234 lines (195 loc) · 4.11 KB
/
display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
mtr -- a network diagnostic tool
Copyright (C) 1997,1998 Matt Kimball
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include "mtr.h"
#include "display.h"
#include "report.h"
#include "select.h"
#include "raw.h"
#include "dns.h"
#include "asn.h"
#ifdef HAVE_NCURSES
# include "mtr-curses.h"
#endif
#ifdef HAVE_GTK
# include "mtr-gtk.h"
#endif
#include "split.h"
#ifdef HAVE_NCURSES
# define DEFAULT_DISPLAY DisplayCurses
#else
# define DEFAULT_DISPLAY DisplayReport
#endif
#ifdef HAVE_GTK
# define UNUSED_IF_NO_GTK /* empty */
#else
# define UNUSED_IF_NO_GTK ATTRIBUTE_UNUSED
#endif
extern void display_detect(struct mtr_ctl *ctl, int *argc UNUSED_IF_NO_GTK,
char ***argv UNUSED_IF_NO_GTK)
{
ctl->DisplayMode = DEFAULT_DISPLAY;
#ifdef HAVE_GTK
if(gtk_detect(argc, argv)) {
ctl->DisplayMode = DisplayGTK;
}
#endif
}
extern void display_open(struct mtr_ctl *ctl)
{
switch(ctl->DisplayMode) {
case DisplayReport:
report_open();
break;
case DisplayTXT:
txt_open();
break;
case DisplayJSON:
json_open();
break;
case DisplayXML:
xml_open();
break;
case DisplayCSV:
csv_open();
break;
#ifdef HAVE_NCURSES
case DisplayCurses:
mtr_curses_open(ctl);
# ifdef HAVE_IPINFO
asn_open(ctl);
# endif
break;
#endif
case DisplaySplit:
split_open();
break;
#ifdef HAVE_GTK
case DisplayGTK:
gtk_open(ctl);
# ifdef HAVE_IPINFO
asn_open(ctl);
# endif
break;
#endif
}
}
extern void display_close(struct mtr_ctl *ctl)
{
time_t now;
now = time(NULL);
switch(ctl->DisplayMode) {
case DisplayReport:
report_close(ctl);
break;
case DisplayTXT:
txt_close(ctl);
break;
case DisplayJSON:
json_close(ctl);
break;
case DisplayXML:
xml_close(ctl);
break;
case DisplayCSV:
csv_close(ctl, now);
break;
#ifdef HAVE_NCURSES
case DisplayCurses:
# ifdef HAVE_IPINFO
asn_close(ctl);
# endif
mtr_curses_close();
break;
#endif
case DisplaySplit:
split_close();
break;
#ifdef HAVE_GTK
case DisplayGTK:
gtk_close();
break;
#endif
}
}
extern void display_redraw(struct mtr_ctl *ctl)
{
switch(ctl->DisplayMode) {
#ifdef HAVE_NCURSES
case DisplayCurses:
mtr_curses_redraw(ctl);
break;
#endif
case DisplaySplit:
split_redraw(ctl);
break;
#ifdef HAVE_GTK
case DisplayGTK:
gtk_redraw(ctl);
break;
#endif
}
}
extern int display_keyaction(struct mtr_ctl *ctl)
{
switch(ctl->DisplayMode) {
#ifdef HAVE_NCURSES
case DisplayCurses:
return mtr_curses_keyaction(ctl);
#endif
case DisplaySplit:
return split_keyaction();
#ifdef HAVE_GTK
case DisplayGTK:
return gtk_keyaction();
#endif
}
return 0;
}
extern void display_rawxmit(struct mtr_ctl *ctl, int host, int seq)
{
if (ctl->DisplayMode == DisplayRaw)
raw_rawxmit (host, seq);
}
extern void display_rawping(struct mtr_ctl *ctl, int host, int msec, int seq)
{
if (ctl->DisplayMode == DisplayRaw)
raw_rawping (ctl, host, msec, seq);
}
extern void display_rawhost(struct mtr_ctl *ctl, int host, ip_t *ip_addr)
{
if (ctl->DisplayMode == DisplayRaw)
raw_rawhost (ctl, host, ip_addr);
}
extern void display_loop(struct mtr_ctl *ctl)
{
#ifdef HAVE_GTK
if (ctl->DisplayMode == DisplayGTK)
gtk_loop(ctl);
else
#endif
select_loop(ctl);
}
extern void display_clear(struct mtr_ctl *ctl)
{
#ifdef HAVE_NCURSES
if (ctl->DisplayMode == DisplayCurses)
mtr_curses_clear(ctl);
#endif
}