File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / mtr / display.c
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Sun Jul 21 23:43:41 2013 UTC (11 years, 3 months ago) by misho
CVS tags: MAIN, HEAD
Initial revision

    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: #include <stdio.h>
   21: #include <stdlib.h>
   22: #include <sys/types.h>
   23: 
   24: #include "mtr.h"
   25: #include "display.h"
   26: #include "mtr-curses.h"
   27: #include "mtr-gtk.h"
   28: #include "report.h"
   29: #include "select.h"
   30: #include "raw.h"
   31: #include "dns.h"
   32: #ifndef NO_IPINFO
   33: #include <asn.h>
   34: #endif
   35: 
   36: extern int DisplayMode;
   37: 
   38: #ifdef NO_CURSES
   39: #define mtr_curses_open()
   40: #define mtr_curses_close()
   41: #define mtr_curses_redraw()
   42: #define mtr_curses_keyaction()
   43: #define mtr_curses_clear()
   44: #else
   45: #include "mtr-curses.h"
   46: #endif
   47: 
   48: #ifdef NO_GTK
   49: #define gtk_open()
   50: #define gtk_close()
   51: #define gtk_redraw()
   52: #define gtk_keyaction() 0
   53: #define gtk_loop() {fprintf (stderr, "No GTK support. Sorry.\n"); exit (1); } 
   54: #else
   55: #include "mtr-gtk.h"
   56: #endif
   57: 
   58: #ifdef NO_SPLIT
   59: #define split_open()
   60: #define split_close()
   61: #define split_redraw()
   62: #define split_keyaction() 0
   63: #else
   64: #include "split.h"
   65: #endif
   66: 
   67: void display_detect(int *argc, char ***argv) {
   68:   DisplayMode = DisplayReport;
   69: 
   70: #ifndef NO_CURSES
   71:   DisplayMode = DisplayCurses;
   72: #endif
   73: 
   74: #ifndef NO_GTK
   75:   if(gtk_detect(argc, argv)) {
   76:     DisplayMode = DisplayGTK;
   77:   }
   78: #endif
   79: }
   80: 
   81: 
   82: void display_open(void)
   83: {
   84:   switch(DisplayMode) {
   85: 
   86:   case DisplayReport:
   87:     report_open();
   88:     break;
   89:   case DisplayTXT:
   90:     txt_open();
   91:     break;
   92:   case DisplayXML:
   93:     xml_open();
   94:     break;
   95:   case DisplayCSV:
   96:     csv_open();
   97:     break;
   98:   case DisplayCurses:
   99:     mtr_curses_open();  
  100: #ifndef NO_IPINFO
  101:     if (ipinfo_no >= 0)
  102:         asn_open();
  103: #endif
  104:     break;
  105:   case DisplaySplit:
  106:     split_open();
  107:     break;
  108:   case DisplayGTK:
  109:     gtk_open();
  110:     break;
  111:   }
  112: }
  113: 
  114: 
  115: void display_close(time_t now)
  116: {
  117:   switch(DisplayMode) {
  118:   case DisplayReport:
  119:     report_close();
  120:     break;
  121:   case DisplayTXT:
  122:     txt_close();
  123:     break;
  124:   case DisplayXML:
  125:     xml_close();
  126:     break;
  127:   case DisplayCSV:
  128:     csv_close(now);
  129:     break;
  130:   case DisplayCurses:
  131: #ifndef NO_IPINFO
  132:     if (ipinfo_no >= 0)
  133:         asn_close();
  134: #endif
  135:     mtr_curses_close();
  136:     break;
  137:   case DisplaySplit:
  138:     split_close();
  139:     break;
  140:   case DisplayGTK:
  141:     gtk_close();
  142:     break;
  143:   }
  144: }
  145: 
  146: 
  147: void display_redraw(void)
  148: {
  149:   switch(DisplayMode) {
  150: 
  151:   case DisplayCurses:
  152:     mtr_curses_redraw();
  153:     break;
  154: 
  155:   case DisplaySplit:
  156:     split_redraw();
  157:     break;
  158: 
  159:   case DisplayGTK:
  160:     gtk_redraw();
  161:     break;
  162:   }
  163: }
  164: 
  165: 
  166: int display_keyaction(void)
  167: {
  168:   switch(DisplayMode) {
  169:   case DisplayCurses:
  170:     return mtr_curses_keyaction();
  171: 
  172:   case DisplaySplit:
  173:     return split_keyaction();
  174: 
  175:   case DisplayGTK:
  176:     return gtk_keyaction();
  177:   }
  178:   return 0;
  179: }
  180: 
  181: 
  182: void display_rawping(int host, int msec) 
  183: {
  184:   switch(DisplayMode) {
  185:   case DisplayReport:
  186:   case DisplayTXT:
  187:   case DisplayXML:
  188:   case DisplayCSV:
  189:   case DisplaySplit:
  190:   case DisplayCurses:
  191:   case DisplayGTK:
  192:     break;
  193:   case DisplayRaw:
  194:     raw_rawping (host, msec);
  195:     break;
  196:   }
  197: }
  198: 
  199: 
  200: void display_rawhost(int host, ip_t *ip_addr) 
  201: {
  202:   switch(DisplayMode) {
  203:   case DisplayReport:
  204:   case DisplayTXT:
  205:   case DisplayXML:
  206:   case DisplayCSV:
  207:   case DisplaySplit:
  208:   case DisplayCurses:
  209:   case DisplayGTK:
  210:     break;
  211:   case DisplayRaw:
  212:     raw_rawhost (host, ip_addr);
  213:     break;
  214:   }
  215: }
  216: 
  217: 
  218: void display_loop(void)
  219: {
  220:   switch(DisplayMode) {
  221:   case DisplayReport:
  222:   case DisplayTXT:
  223:   case DisplayXML:
  224:   case DisplayCSV:
  225:   case DisplaySplit:
  226:   case DisplayCurses:
  227:   case DisplayRaw:
  228:     select_loop();
  229:     break;
  230:   case DisplayGTK:
  231:     gtk_loop();
  232:     break;
  233:   }
  234: }
  235: 
  236: 
  237: void display_clear(void)
  238: {
  239:   switch(DisplayMode) {
  240:   case DisplayCurses:
  241:     mtr_curses_clear();
  242:     break;
  243:   case DisplayReport:
  244:   case DisplayTXT:
  245:   case DisplayXML:
  246:   case DisplayCSV:
  247:   case DisplaySplit:
  248:   case DisplayRaw:
  249:     break;
  250: 
  251:   case DisplayGTK:
  252:     break;
  253:   }
  254: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>