From: Sami Kerola Date: Sun, 9 Oct 2016 20:32:59 +0000 (+0100) Subject: cleanup: clarify preprocessor nesting X-Git-Tag: v0.88~21^2^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=177e172227e4cfe165befde92391dd1d72a82fb7;p=thirdparty%2Fmtr.git cleanup: clarify preprocessor nesting Indent declarations if they are nested, and add at the end of particularly long #ifdef segments a marker telling where they started. --- diff --git a/asn.c b/asn.c index a6e9f76..bbf4180 100644 --- a/asn.c +++ b/asn.c @@ -23,18 +23,18 @@ #include #include #ifdef HAVE_ERROR_H -#include +# include #else -#include "portability/error.h" +# include "portability/error.h" #endif #include #ifdef __APPLE__ -#define BIND_8_COMPAT +# define BIND_8_COMPAT #endif #include #ifdef HAVE_ARPA_NAMESER_COMPAT_H -#include +# include #endif #include #include @@ -49,13 +49,12 @@ /* #define IIDEBUG */ #ifdef IIDEBUG -#include -#define DEB_syslog syslog +# include +# define DEB_syslog syslog #else -#define DEB_syslog(...) do {} while (0) +# define DEB_syslog(...) do {} while (0) #endif - #define IIHASH_HI 128 #define ITEMSMAX 15 #define ITEMSEP '|' diff --git a/curses.c b/curses.c index cba17bd..16e4916 100644 --- a/curses.c +++ b/curses.c @@ -27,10 +27,10 @@ /* MacOSX may need this before socket.h...*/ #if defined(HAVE_SYS_TYPES_H) -#include +# include #else /* If a system doesn't have sys/types.h, lets hope that time_t is an int */ -#define time_t int +# define time_t int #endif #include @@ -38,22 +38,22 @@ #include #if defined(HAVE_NCURSES_H) -# include +# include #elif defined(HAVE_NCURSES_CURSES_H) -# include +# include #elif defined(HAVE_CURSES_H) -# include +# include #elif defined(HAVE_CURSESX_H) -# include +# include #else -# error No curses header file available +# error No curses header file available #endif /* This go-around is needed only when compiling with antique version of curses. getmaxyx is part of Technical Standard X/Open Curses Issue 4, Version 2 (1996). http://pubs.opengroup.org/onlinepubs/9693989999/toc.pdf see page 106 */ #ifndef getmaxyx -# define getmaxyx(win,y,x) ((y) = (win)->_maxy + 1, (x) = (win)->_maxx + 1) +# define getmaxyx(win,y,x) ((y) = (win)->_maxy + 1, (x) = (win)->_maxx + 1) #endif #include "mtr.h" diff --git a/display.c b/display.c index d3c95c5..de80b4a 100644 --- a/display.c +++ b/display.c @@ -31,23 +31,23 @@ #include "asn.h" #ifdef HAVE_NCURSES -#include "mtr-curses.h" +# include "mtr-curses.h" #endif #ifdef HAVE_GTK -#include "mtr-gtk.h" +# include "mtr-gtk.h" #endif #include "split.h" #ifdef HAVE_NCURSES -#define DEFAULT_DISPLAY DisplayCurses +# define DEFAULT_DISPLAY DisplayCurses #else -#define DEFAULT_DISPLAY DisplayReport +# define DEFAULT_DISPLAY DisplayReport #endif #ifdef HAVE_GTK -# define UNUSED_IF_NO_GTK /* empty */ +# define UNUSED_IF_NO_GTK /* empty */ #else # define UNUSED_IF_NO_GTK ATTRIBUTE_UNUSED #endif @@ -87,9 +87,9 @@ extern void display_open(struct mtr_ctl *ctl) #ifdef HAVE_NCURSES case DisplayCurses: mtr_curses_open(ctl); -#ifdef HAVE_IPINFO +# ifdef HAVE_IPINFO asn_open(ctl); -#endif +# endif break; #endif case DisplaySplit: @@ -98,9 +98,9 @@ extern void display_open(struct mtr_ctl *ctl) #ifdef HAVE_GTK case DisplayGTK: gtk_open(ctl); -#ifdef HAVE_IPINFO +# ifdef HAVE_IPINFO asn_open(ctl); -#endif +# endif break; #endif } @@ -127,9 +127,9 @@ extern void display_close(struct mtr_ctl *ctl, time_t now) break; #ifdef HAVE_NCURSES case DisplayCurses: -#ifdef HAVE_IPINFO +# ifdef HAVE_IPINFO asn_close(ctl); -#endif +# endif mtr_curses_close(); break; #endif diff --git a/dns.c b/dns.c index 8822878..460f212 100644 --- a/dns.c +++ b/dns.c @@ -25,9 +25,9 @@ #include "config.h" #ifdef HAVE_ERROR_H -#include +# include #else -#include "portability/error.h" +# include "portability/error.h" #endif #include #include diff --git a/gtk.c b/gtk.c index 2542285..41cf596 100644 --- a/gtk.c +++ b/gtk.c @@ -26,18 +26,18 @@ #include #ifdef HAVE_GTK -#include -#include -#include - -#include "mtr.h" -#include "net.h" -#include "dns.h" -#include "asn.h" -#include "mtr-gtk.h" -#include "utils.h" - -#include "img/mtr_icon.xpm" +# include +# include +# include + +# include "mtr.h" +# include "net.h" +# include "dns.h" +# include "asn.h" +# include "mtr-gtk.h" +# include "utils.h" + +# include "img/mtr_icon.xpm" #endif static gint gtk_ping(gpointer data); diff --git a/mtr.c b/mtr.c index 13458a8..a68fe14 100644 --- a/mtr.c +++ b/mtr.c @@ -27,15 +27,15 @@ #include #include #ifdef HAVE_ERROR_H -#include +# include #else -#include "portability/error.h" +# include "portability/error.h" #endif #ifdef HAVE_VALUES_H -#include +# include #endif #ifdef HAVE_SYS_LIMITS_H -#include +# include #endif #include @@ -58,15 +58,15 @@ #include "utils.h" #ifdef HAVE_GETOPT -#include +# include #else -#include "portability/getopt.h" +# include "portability/getopt.h" #endif #ifdef ENABLE_IPV6 -#define DEFAULT_AF AF_UNSPEC +# define DEFAULT_AF AF_UNSPEC #else -#define DEFAULT_AF AF_INET +# define DEFAULT_AF AF_INET #endif diff --git a/net.c b/net.c index 0bb8b84..c7967ea 100644 --- a/net.c +++ b/net.c @@ -19,7 +19,7 @@ #include "config.h" #if defined(HAVE_SYS_XTI_H) -#include +# include #endif #include @@ -31,7 +31,7 @@ #include #include #ifdef HAVE_FCNTL_H -#include +# include #endif #include #include @@ -40,12 +40,12 @@ #include #include #ifdef HAVE_ERROR_H -#include +# include #else -#include "portability/error.h" +# include "portability/error.h" #endif #ifdef HAVE_LINUX_ICMP_H -#include +# include #endif #include "mtr.h" @@ -125,14 +125,14 @@ struct IPHeader { }; #ifndef ICMP_ECHOREPLY -#define ICMP_ECHOREPLY 0 -#define ICMP_DEST_UNREACH 3 -#define ICMP_ECHO 8 -#define ICMP_TIME_EXCEEDED 11 +# define ICMP_ECHOREPLY 0 +# define ICMP_DEST_UNREACH 3 +# define ICMP_ECHO 8 +# define ICMP_TIME_EXCEEDED 11 #endif #ifndef SOL_IP -#define SOL_IP 0 +# define SOL_IP 0 #endif struct nethost { @@ -205,9 +205,9 @@ static ip_t * remoteaddress; #ifdef ENABLE_IPV6 static char localaddr[INET6_ADDRSTRLEN]; #else -#ifndef INET_ADDRSTRLEN -#define INET_ADDRSTRLEN 16 -#endif +# ifndef INET_ADDRSTRLEN +# define INET_ADDRSTRLEN 16 +# endif static char localaddr[INET_ADDRSTRLEN]; #endif @@ -445,10 +445,10 @@ static void net_send_sctp(struct mtr_ctl *ctl, int index) struct sockaddr_storage remote; struct sockaddr_in *local4 = (struct sockaddr_in *) &local; struct sockaddr_in *remote4 = (struct sockaddr_in *) &remote; -#ifdef ENABLE_IPV6 +# ifdef ENABLE_IPV6 struct sockaddr_in6 *local6 = (struct sockaddr_in6 *) &local; struct sockaddr_in6 *remote6 = (struct sockaddr_in6 *) &remote; -#endif +# endif socklen_t len; ttl = index + 1; @@ -471,14 +471,14 @@ static void net_send_sctp(struct mtr_ctl *ctl, int index) remote4->sin_port = htons(ctl->remoteport); len = sizeof (struct sockaddr_in); break; -#ifdef ENABLE_IPV6 +# ifdef ENABLE_IPV6 case AF_INET6: addrcpy((void *) &local6->sin6_addr, (void *) &ssa6->sin6_addr, ctl->af); addrcpy((void *) &remote6->sin6_addr, (void *) remoteaddress, ctl->af); remote6->sin6_port = htons(ctl->remoteport); len = sizeof (struct sockaddr_in6); break; -#endif +# endif } if (bind(s, (struct sockaddr *) &local, len)) { @@ -508,31 +508,31 @@ static void net_send_sctp(struct mtr_ctl *ctl, int index) error(EXIT_FAILURE, errno, "setsockopt IP_TOS"); } break; -#ifdef ENABLE_IPV6 +# ifdef ENABLE_IPV6 case AF_INET6: if (setsockopt(s, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof (ttl))) { display_clear(ctl); error(EXIT_FAILURE, errno, "setsockopt IPPROTO_IPV6 ttl"); } break; -#endif +# endif } -#ifdef SO_MARK +# ifdef SO_MARK if (ctl->mark && setsockopt( s, SOL_SOCKET, SO_MARK, &ctl->mark, sizeof ctl->mark ) ) { error(EXIT_FAILURE, errno, "setsockopt SO_MARK"); } -#endif +# endif switch (local.ss_family) { case AF_INET: port = ntohs(local4->sin_port); break; -#ifdef ENABLE_IPV6 +# ifdef ENABLE_IPV6 case AF_INET6: port = ntohs(local6->sin6_port); break; -#endif +# endif default: display_clear(ctl); error(EXIT_FAILURE, 0, "unknown address family"); @@ -544,7 +544,7 @@ static void net_send_sctp(struct mtr_ctl *ctl, int index) connect(s, (struct sockaddr *) &remote, len); } -#endif +#endif /* HAS_SCTP */ /* Attempt to find the host at a particular number of hops away */ static void net_send_query(struct mtr_ctl *ctl, int index) @@ -1064,7 +1064,7 @@ extern void net_process_return(struct mtr_ctl *ctl) decodempls(num, packet, &mpls, 156); break; -#ifdef ENABLE_IPV6 +# ifdef ENABLE_IPV6 case AF_INET6: if ((size_t) num < sizeof (struct ICMPHeader) + sizeof (struct ip6_hdr) + sizeof (struct SCTPHeader) ) @@ -1077,12 +1077,12 @@ extern void net_process_return(struct mtr_ctl *ctl) decodempls(num, packet, &mpls, 136); break; -#endif +# endif } seq_num = ntohs(sctpheader->srcport); } break; -#endif +#endif /* HAS_SCTP */ } if (seq_num) net_process_ping (ctl, seq_num, mpls, (void *) fromaddress, now); diff --git a/select.c b/select.c index 6a2b9fa..3d4bb03 100644 --- a/select.c +++ b/select.c @@ -29,9 +29,9 @@ #include #include #ifdef HAVE_ERROR_H -#include +# include #else -#include "portability/error.h" +# include "portability/error.h" #endif #include "mtr.h"