From: Guy Harris Date: Tue, 8 Mar 2011 17:11:25 +0000 (-0800) Subject: Fix plurals in packet count messages. X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/8b250cbf6f97792950ae756b86eae99fba2af0f5 Fix plurals in packet count messages. Based on a patch from cr4ckn@sourceforge.net, but with a macro PLURAL_SUFFIX() defined to return either "s" or "" (rather than possibly printing a NUL character with %c), and with that macro used in a couple of cases where the equivalent had been done by hand, and with one case the patch missed fixed as well. --- diff --git a/netdissect.h b/netdissect.h index 493010a9..f87d8c71 100644 --- a/netdissect.h +++ b/netdissect.h @@ -254,6 +254,9 @@ extern char *copy_argv(netdissect_options *, char **); extern void safeputchar(int); extern void safeputs(const char *, int); +#define PLURAL_SUFFIX(n) \ + (((n) != 1) ? "s" : "") + #if 0 extern const char *isonsap_string(netdissect_options *, const u_char *); extern const char *protoid_string(netdissect_options *, const u_char *); diff --git a/print-cdp.c b/print-cdp.c index bef7f5ea..7bc617a9 100644 --- a/print-cdp.c +++ b/print-cdp.c @@ -124,7 +124,7 @@ cdp_print(const u_char *pptr, u_int length, u_int caplen) tok2str(cdp_tlv_values,"unknown field type", type), type, len, - len>1 ? "s" : ""); /* plural */ + PLURAL_SUFFIX(len)); /* plural */ switch (type) { diff --git a/print-ospf.c b/print-ospf.c index 983c14f4..738a13c2 100644 --- a/print-ospf.c +++ b/print-ospf.c @@ -1028,7 +1028,7 @@ ospf_decode_v2(register const struct ospfhdr *op, lsap = op->ospf_lsu.lsu_lsa; TCHECK(op->ospf_lsu.lsu_count); lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count); - printf(", %d LSA%s",lsa_count_max, lsa_count_max > 1 ? "s" : ""); + printf(", %d LSA%s",lsa_count_max, PLURAL_SUFFIX(lsa_count_max)); for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) { printf("\n\t LSA #%u",lsa_count); lsap = (const struct lsa *)ospf_print_lsa(lsap); diff --git a/tcpdump.c b/tcpdump.c index 5b66ece8..cdfba892 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -1487,24 +1487,27 @@ info(register int verbose) if (!verbose) fprintf(stderr, "%s: ", program_name); - (void)fprintf(stderr, "%u packets captured", packets_captured); + (void)fprintf(stderr, "%u packet%s captured", packets_captured, + PLURAL_SUFFIX(packets_captured)); if (!verbose) fputs(", ", stderr); else putc('\n', stderr); - (void)fprintf(stderr, "%u packets received by filter", stat.ps_recv); + (void)fprintf(stderr, "%u packet%s received by filter", stat.ps_recv, + PLURAL_SUFFIX(stat.ps_recv)); if (!verbose) fputs(", ", stderr); else putc('\n', stderr); - (void)fprintf(stderr, "%u packets dropped by kernel", stat.ps_drop); + (void)fprintf(stderr, "%u packet%s dropped by kernel", stat.ps_drop, + PLURAL_SUFFIX(stat.ps_drop)); if (stat.ps_ifdrop != 0) { if (!verbose) fputs(", ", stderr); else putc('\n', stderr); - (void)fprintf(stderr, "%u packets dropped by interface\n", - stat.ps_ifdrop); + (void)fprintf(stderr, "%u packet%s dropped by interface\n", + stat.ps_ifdrop, PLURAL_SUFFIX(stat.ps_ifdrop)); } else putc('\n', stderr); infoprint = 0;