Skip to content

Commit

Permalink
removed double negatives for ipinfo define.
Browse files Browse the repository at this point in the history
  • Loading branch information
rewolff committed Jul 6, 2013
1 parent 3689b69 commit 0d772cc
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 35 deletions.
13 changes: 13 additions & 0 deletions asn.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

// The autoconf system provides us with the NO_IPINFO define.
// Littering the code with #ifndef NO_IPINFO (double negative)
// does not benefit readabilty. So here we invert the sense of the
// define.
//
// Similarly, this include file should be included unconditially.
// It will evaluate to nothing if we don't need it.

#ifndef NO_IPINFO
#define IPINFO


extern int ipinfo_no;
extern int ipinfo_max;
extern int iiwidth_len;
Expand All @@ -26,3 +38,4 @@ char *fmt_ipinfo(ip_t *addr);
int get_iiwidth(void);
int is_printii(void);

#endif
17 changes: 8 additions & 9 deletions curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@

#include "mtr.h"
#include "mtr-curses.h"
#include "display.h"
#include "net.h"
#include "dns.h"
#ifndef NO_IPINFO
#include "asn.h"
#endif
#include "display.h"

#include "version.h"
#endif

Expand Down Expand Up @@ -121,7 +120,7 @@ int mtr_curses_keyaction(void)
return ActionMPLS;
if (tolower(c) == 'n')
return ActionDNS;
#ifndef NO_IPINFO
#ifdef IPINFO
if (tolower(c) == 'y')
return ActionII;
if (tolower(c) == 'z')
Expand Down Expand Up @@ -304,7 +303,7 @@ int mtr_curses_keyaction(void)
printw(" b <c> set ping bit pattern to c(0..255) or random(c<0)\n" );
printw(" Q <t> set ping packet's TOS to t\n" );
printw(" u switch between ICMP ECHO and UDP datagrams\n" );
#ifndef NO_IPINFO
#ifdef IPINFO
printw(" y switching IP info\n");
printw(" z toggle ASN info on/off\n");
pressanykey_row += 2;
Expand Down Expand Up @@ -344,7 +343,7 @@ void mtr_curses_hosts(int startstat)
name = dns_lookup(addr);
if (! net_up(at))
attron(A_BOLD);
#ifndef NO_IPINFO
#ifdef IPINFO
if (is_printii())
printw(fmt_ipinfo(addr));
#endif
Expand Down Expand Up @@ -401,7 +400,7 @@ void mtr_curses_hosts(int startstat)
name = dns_lookup(addrs);
if (! net_up(at)) attron(A_BOLD);
printw("\n ");
#ifndef NO_IPINFO
#ifdef IPINFO
if (is_printii())
printw(fmt_ipinfo(addrs));
#endif
Expand Down Expand Up @@ -552,7 +551,7 @@ void mtr_curses_graph(int startstat, int cols)
if (! net_up(at))
attron(A_BOLD);
if (addrcmp((void *) addr, (void *) &unspec_addr, af)) {
#ifndef NO_IPINFO
#ifdef IPINFO
if (is_printii())
printw(fmt_ipinfo(addr));
#endif
Expand Down Expand Up @@ -642,7 +641,7 @@ void mtr_curses_redraw(void)
} else {
char msg[80];
int padding = 30;
#ifndef NO_IPINFO
#ifdef IPINFO
if (is_printii())
padding += get_iiwidth();
#endif
Expand Down
8 changes: 3 additions & 5 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
#include "select.h"
#include "raw.h"
#include "dns.h"
#ifndef NO_IPINFO
#include <asn.h>
#endif
#include "asn.h"

extern int DisplayMode;

Expand Down Expand Up @@ -97,7 +95,7 @@ void display_open(void)
break;
case DisplayCurses:
mtr_curses_open();
#ifndef NO_IPINFO
#ifdef IPINFO
if (ipinfo_no >= 0)
asn_open();
#endif
Expand Down Expand Up @@ -128,7 +126,7 @@ void display_close(time_t now)
csv_close(now);
break;
case DisplayCurses:
#ifndef NO_IPINFO
#ifdef IPINFO
if (ipinfo_no >= 0)
asn_close();
#endif
Expand Down
2 changes: 1 addition & 1 deletion display.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(notably the one on Irix 5.2) do not like that. */
enum { ActionNone, ActionQuit, ActionReset, ActionDisplay,
ActionClear, ActionPause, ActionResume, ActionMPLS, ActionDNS,
#ifndef NO_IPINFO
#ifdef IPINFO
ActionII, ActionAS,
#endif
ActionScrollDown, ActionScrollUp };
Expand Down
8 changes: 3 additions & 5 deletions mtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
#include "dns.h"
#include "report.h"
#include "net.h"
#ifndef NO_IPINFO
#include "asn.h"
#endif
#include "version.h"


Expand Down Expand Up @@ -290,7 +288,7 @@ void parse_arg (int argc, char **argv)
{ "timeout", 1, 0, 'Z' }, /* timeout for TCP sockets */
{ "inet", 0, 0, '4' }, /* IPv4 only */
{ "inet6", 0, 0, '6' }, /* IPv6 only */
#ifndef NO_IPINFO
#ifdef IPINFO
{ "ipinfo", 1, 0, 'y' }, /* IP info lookup */
{ "aslookup", 0, 0, 'z' }, /* Do AS lookup (--ipinfo 0) */
#endif
Expand Down Expand Up @@ -456,7 +454,7 @@ void parse_arg (int argc, char **argv)
fprintf( stderr, "IPv6 not enabled.\n" );
break;
#endif
#ifndef NO_IPINFO
#ifdef IPINFO
case 'y':
ipinfo_no = atoi (optarg);
if (ipinfo_no < 0)
Expand Down Expand Up @@ -576,7 +574,7 @@ int main(int argc, char **argv)
"\t\t[--report-wide] [--report-cycles=COUNT] [--curses] [--gtk]\n"
"\t\t[--csv|-C] [--raw] [--split] [--mpls] [--no-dns] [--show-ips]\n"
"\t\t[--address interface] [--filename=FILE|-F]\n" /* BL */
#ifndef NO_IPINFO
#ifdef IPINFO
"\t\t[--ipinfo=item_no|-y item_no]\n"
"\t\t[--aslookup|-z]\n"
#endif
Expand Down
20 changes: 9 additions & 11 deletions report.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
#include "report.h"
#include "net.h"
#include "dns.h"
#ifndef NO_IPINFO
#include "asn.h"
#endif

#define MAXLOADBAL 5

Expand Down Expand Up @@ -77,7 +75,7 @@ static size_t snprint_addr(char *dst, size_t dst_len, ip_t *addr)
}


#ifndef NO_IPINFO
#ifdef IPINFO
void print_mpls(struct mplslen *mpls) {
int k;
for (k=0; k < mpls->labels; k++)
Expand Down Expand Up @@ -112,7 +110,7 @@ void report_close(void)
}
}

#ifndef NO_IPINFO
#ifdef IPINFO
int len_tmp = len_hosts;
if (ipinfo_no >= 0) {
ipinfo_no %= iiwidth_len;
Expand Down Expand Up @@ -146,15 +144,15 @@ void report_close(void)
mpls = net_mpls(at);
snprint_addr(name, sizeof(name), addr);

#ifndef NO_IPINFO
#ifdef IPINFO
if (is_printii()) {
snprintf(fmt, sizeof(fmt), " %%2d. %%s%%-%ds", len_hosts);
snprintf(buf, sizeof(buf), fmt, at+1, fmt_ipinfo(addr), name);
} else {
#endif
snprintf( fmt, sizeof(fmt), " %%2d.|-- %%-%ds", len_hosts);
snprintf(buf, sizeof(buf), fmt, at+1, name);
#ifndef NO_IPINFO
#ifdef IPINFO
}
#endif
len = reportwide ? strlen(buf) : len_hosts;
Expand Down Expand Up @@ -192,7 +190,7 @@ void report_close(void)

if (!found) {

#ifndef NO_IPINFO
#ifdef IPINFO
if (is_printii()) {
if (mpls->labels && z == 1 && enablempls)
print_mpls(mpls);
Expand Down Expand Up @@ -221,14 +219,14 @@ void report_close(void)
}
}
#endif
#ifndef NO_IPINFO
#ifdef IPINFO
}
#endif
}
}

/* No multipath */
#ifndef NO_IPINFO
#ifdef IPINFO
if (is_printii()) {
if (mpls->labels && z == 1 && enablempls)
print_mpls(mpls);
Expand All @@ -241,7 +239,7 @@ void report_close(void)
}
}
#endif
#ifndef NO_IPINFO
#ifdef IPINFO
}
#endif
}
Expand Down Expand Up @@ -340,7 +338,7 @@ void csv_close(time_t now)
snprint_addr(name, sizeof(name), addr);

int last = net_last(at);
#ifndef NO_IPINFO
#ifdef IPINFO
if(!ipinfo_no) {
char* fmtinfo = fmt_ipinfo(addr);
if (fmtinfo != NULL) fmtinfo = trim(fmtinfo);
Expand Down
6 changes: 2 additions & 4 deletions select.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
#include <errno.h>

#include "mtr.h"
#include "display.h"
#include "dns.h"
#include "net.h"
#ifndef NO_IPINFO
#include "asn.h"
#endif
#include "display.h"

extern int Interactive;
extern int MaxPing;
Expand Down Expand Up @@ -210,7 +208,7 @@ void select_loop(void) {
display_clear();
}
break;
#ifndef NO_IPINFO
#ifdef IPINFO
case ActionII:
if (ipinfo_no >= 0) {
ipinfo_no++;
Expand Down

0 comments on commit 0d772cc

Please sign in to comment.