From 8a91782cc5832ff412b472b242e2555439c38509 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 21 Aug 2016 10:53:16 +0100 Subject: [PATCH] cleanup: remove preprocessor missing functions go-arounds Calling empty functions when there is no support is messy, and harder to read than not calling at all functionality that is not present. --- display.c | 58 ++++++++++++++++++++++++++++++++++++------------------- display.h | 18 +++++++++++++++-- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/display.c b/display.c index 6f2b733..10e1271 100644 --- a/display.c +++ b/display.c @@ -36,34 +36,14 @@ extern int DisplayMode; #ifdef HAVE_NCURSES #include "mtr-curses.h" -#else -// No support for curses mode, allow the calls to remain in the code. -#define mtr_curses_open() -#define mtr_curses_close() -#define mtr_curses_redraw() -#define mtr_curses_keyaction() 0 -#define mtr_curses_clear() #endif #ifdef HAVE_GTK #include "mtr-gtk.h" -#else -// No support for gtk mode, allow the calls to remain in the code. -#define gtk_open() -#define gtk_close() -#define gtk_redraw() -#define gtk_keyaction() 0 -#define gtk_loop() {fprintf (stderr, "No GTK support. Sorry.\n"); exit(EXIT_FAILURE); } #endif #include "split.h" -#ifndef HAVE_IPINFO -// No support for IPINFO allow the calls to remain in the main code. -#define asn_open() -#define asn_close() -#endif - #ifdef HAVE_NCURSES #define DEFAULT_DISPLAY DisplayCurses #else @@ -107,17 +87,25 @@ void display_open(void) case DisplayCSV: csv_open(); break; +#ifdef HAVE_NCURSES case DisplayCurses: mtr_curses_open(); +#ifdef HAVE_IPINFO asn_open(); +#endif break; +#endif case DisplaySplit: split_open(); break; +#ifdef HAVE_GTK case DisplayGTK: gtk_open(); +#ifdef HAVE_IPINFO asn_open(); +#endif break; +#endif } } @@ -140,16 +128,22 @@ void display_close(time_t now) case DisplayCSV: csv_close(now); break; +#ifdef HAVE_NCURSES case DisplayCurses: +#ifdef HAVE_IPINFO asn_close(); +#endif mtr_curses_close(); break; +#endif case DisplaySplit: split_close(); break; +#ifdef HAVE_GTK case DisplayGTK: gtk_close(); break; +#endif } } @@ -158,17 +152,21 @@ void display_redraw(void) { switch(DisplayMode) { +#ifdef HAVE_NCURSES case DisplayCurses: mtr_curses_redraw(); break; +#endif case DisplaySplit: split_redraw(); break; +#ifdef HAVE_GTK case DisplayGTK: gtk_redraw(); break; +#endif } } @@ -176,14 +174,18 @@ void display_redraw(void) int display_keyaction(void) { switch(DisplayMode) { +#ifdef HAVE_NCURSES case DisplayCurses: return mtr_curses_keyaction(); +#endif case DisplaySplit: return split_keyaction(); +#ifdef HAVE_GTK case DisplayGTK: return gtk_keyaction(); +#endif } return 0; } @@ -208,8 +210,12 @@ void display_rawping(int host, int msec, int seq) case DisplayXML: case DisplayCSV: case DisplaySplit: +#ifdef HAVE_NCURSES case DisplayCurses: +#endif +#ifdef HAVE_GTK case DisplayGTK: +#endif break; case DisplayRaw: raw_rawping (host, msec, seq); @@ -227,8 +233,12 @@ void display_rawhost(int host, ip_t *ip_addr) case DisplayXML: case DisplayCSV: case DisplaySplit: +#ifdef HAVE_NCURSES case DisplayCurses: +#endif +#ifdef HAVE_GTK case DisplayGTK: +#endif break; case DisplayRaw: raw_rawhost (host, ip_addr); @@ -246,13 +256,17 @@ void display_loop(void) case DisplayXML: case DisplayCSV: case DisplaySplit: +#ifdef HAVE_NCURSES case DisplayCurses: +#endif case DisplayRaw: select_loop(); break; +#ifdef HAVE_GTK case DisplayGTK: gtk_loop(); break; +#endif } } @@ -260,9 +274,11 @@ void display_loop(void) void display_clear(void) { switch(DisplayMode) { +#ifdef HAVE_NCURSES case DisplayCurses: mtr_curses_clear(); break; +#endif case DisplayReport: case DisplayTXT: case DisplayJSON: @@ -272,7 +288,9 @@ void display_clear(void) case DisplayRaw: break; +#ifdef HAVE_GTK case DisplayGTK: break; +#endif } } diff --git a/display.h b/display.h index ec751fe..edd2a99 100644 --- a/display.h +++ b/display.h @@ -26,8 +26,22 @@ enum { ActionNone, ActionQuit, ActionReset, ActionDisplay, ActionII, ActionAS, #endif ActionScrollDown, ActionScrollUp }; -enum { DisplayReport, DisplayCurses, DisplayGTK, DisplaySplit, - DisplayRaw, DisplayXML, DisplayCSV, DisplayTXT, DisplayJSON}; + +enum { + DisplayReport, +#ifdef HAVE_NCURSES + DisplayCurses, +#endif +#ifdef HAVE_GTK + DisplayGTK, +#endif + DisplaySplit, + DisplayRaw, + DisplayXML, + DisplayCSV, + DisplayTXT, + DisplayJSON +}; /* Prototypes for display.c */ void display_detect(int *argc, char ***argv); -- 2.47.2