]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
cleanup: clarify preprocessor nesting
authorSami Kerola <kerolasa@iki.fi>
Sun, 9 Oct 2016 20:32:59 +0000 (21:32 +0100)
committerSami Kerola <kerolasa@iki.fi>
Tue, 11 Oct 2016 18:29:20 +0000 (19:29 +0100)
Indent declarations if they are nested, and add at the end of particularly
long #ifdef segments a marker telling where they started.

asn.c
curses.c
display.c
dns.c
gtk.c
mtr.c
net.c
select.c

diff --git a/asn.c b/asn.c
index a6e9f766fb630a9f0b3e1608abb133aad5b267c9..bbf418041c0e6bfdd4992874b00d3b4c622b5641 100644 (file)
--- a/asn.c
+++ b/asn.c
 #include <stdlib.h>
 #include <sys/types.h>
 #ifdef HAVE_ERROR_H
-#include <error.h>
+# include <error.h>
 #else
-#include "portability/error.h"
+# include "portability/error.h"
 #endif
 #include <errno.h>
 
 #ifdef __APPLE__
-#define BIND_8_COMPAT
+# define BIND_8_COMPAT
 #endif
 #include <arpa/nameser.h>
 #ifdef HAVE_ARPA_NAMESER_COMPAT_H
-#include <arpa/nameser_compat.h>
+# include <arpa/nameser_compat.h>
 #endif
 #include <netdb.h>
 #include <netinet/in.h>
 
 /* #define IIDEBUG */
 #ifdef IIDEBUG
-#include <syslog.h>
-#define DEB_syslog syslog
+# include <syslog.h>
+# 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        '|'
index cba17bd5288adfe4b609d1e2be3104a4d658bd32..16e4916e548433e22fa8d28120876a134a98115c 100644 (file)
--- a/curses.c
+++ b/curses.c
 
 /* MacOSX may need this before socket.h...*/
 #if defined(HAVE_SYS_TYPES_H)
-#include <sys/types.h>
+# include <sys/types.h>
 #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 <sys/socket.h>
 #include <arpa/inet.h>
 
 #if defined(HAVE_NCURSES_H)
-#  include <ncurses.h>
+# include <ncurses.h>
 #elif defined(HAVE_NCURSES_CURSES_H)
-#  include <ncurses/curses.h>
+# include <ncurses/curses.h>
 #elif defined(HAVE_CURSES_H)
-#  include <curses.h>
+# include <curses.h>
 #elif defined(HAVE_CURSESX_H)
-#  include <cursesX.h>
+# include <cursesX.h>
 #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"
index d3c95c5a39131479053e00e68f97992263082c07..de80b4a76bc00586c058943f4b64a4d6a37a8da5 100644 (file)
--- a/display.c
+++ b/display.c
 #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 88228783f4b0702a979390316d7d9c68ca381ea9..460f2125e9c6bcbb500fcc7b636a1f005b493410 100644 (file)
--- a/dns.c
+++ b/dns.c
@@ -25,9 +25,9 @@
 #include "config.h"
 
 #ifdef HAVE_ERROR_H
-#include <error.h>
+# include <error.h>
 #else
-#include "portability/error.h"
+# include "portability/error.h"
 #endif
 #include <errno.h>
 #include <unistd.h>
diff --git a/gtk.c b/gtk.c
index 2542285486b54f9c101ddf333db7f75787e71e3a..41cf5969e19ddf237cd3c01e7f5866f4038d499c 100644 (file)
--- a/gtk.c
+++ b/gtk.c
 #include <sys/types.h>
 
 #ifdef HAVE_GTK
-#include <string.h>
-#include <sys/types.h>
-#include <gtk/gtk.h>
-
-#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 <string.h>
+# include <sys/types.h>
+# include <gtk/gtk.h>
+
+# 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 13458a848d56dd13a856abda69db04ef55d2d640..a68fe14c558a328a4be122c7116a6416c4156a43 100644 (file)
--- a/mtr.c
+++ b/mtr.c
 #include <string.h>
 #include <strings.h>
 #ifdef HAVE_ERROR_H
-#include <error.h>
+# include <error.h>
 #else
-#include "portability/error.h"
+# include "portability/error.h"
 #endif
 #ifdef HAVE_VALUES_H
-#include <values.h>
+# include <values.h>
 #endif
 #ifdef HAVE_SYS_LIMITS_H
-#include <sys/limits.h>
+# include <sys/limits.h>
 #endif
 
 #include <netdb.h>
 #include "utils.h"
 
 #ifdef HAVE_GETOPT
-#include <getopt.h>
+# include <getopt.h>
 #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 0bb8b8400fa530112c84a95d9b0a8a52aa1c3575..c7967ea3f491dc241e66bbb5633726b83c998bef 100644 (file)
--- a/net.c
+++ b/net.c
@@ -19,7 +19,7 @@
 #include "config.h"
 
 #if defined(HAVE_SYS_XTI_H)
-#include <sys/xti.h>
+# include <sys/xti.h>
 #endif
 
 #include <sys/types.h>
@@ -31,7 +31,7 @@
 #include <memory.h>
 #include <unistd.h>
 #ifdef HAVE_FCNTL_H
-#include <fcntl.h>
+# include <fcntl.h>
 #endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
 #ifdef HAVE_ERROR_H
-#include <error.h>
+# include <error.h>
 #else
-#include "portability/error.h"
+# include "portability/error.h"
 #endif
 #ifdef HAVE_LINUX_ICMP_H
-#include <linux/icmp.h>
+# include <linux/icmp.h>
 #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);
index 6a2b9fa7c883412be47f18899a2132fb84461406..3d4bb03684cfc18c5fb4a6624674c50e4d1ce6fa 100644 (file)
--- a/select.c
+++ b/select.c
@@ -29,9 +29,9 @@
 #include <math.h>
 #include <errno.h>
 #ifdef HAVE_ERROR_H
-#include <error.h>
+# include <error.h>
 #else
-#include "portability/error.h"
+# include "portability/error.h"
 #endif
 
 #include "mtr.h"