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