From ba859ad30251db5a30b36134199e307ee06ea09f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 12 Mar 2019 14:22:52 -0600 Subject: [PATCH] tools/nxstyle.c: Don't complain about certain lowercase characters in otherwise uppercase pre-processor identifers: IPv6, IPv4, ICMPv6, IGMPv2, p as a decimal point, d signifying a divisor. It was a bad idea to let the door open a crack for there. While they improve readability, the inconsistently also causes other problems. --- binfmt/nxflat.c | 2 +- net/bluetooth/bluetooth_input.c | 54 +++++++++++++------------- tools/nxstyle.c | 69 ++++++++++++++++++++++++++++++++- 3 files changed, 96 insertions(+), 29 deletions(-) diff --git a/binfmt/nxflat.c b/binfmt/nxflat.c index 2e729a7581..b0096ce156 100644 --- a/binfmt/nxflat.c +++ b/binfmt/nxflat.c @@ -258,7 +258,7 @@ static int nxflat_unloadbinary(FAR struct binary_s *binp) /* Mark alloc[0] (dspace) as freed */ - binp->alloc[0] = NULL; + binp->alloc[0] = NULL; /* The reference count will be decremented to zero and the dspace * container will be freed in sched/sched_releasetcb.c diff --git a/net/bluetooth/bluetooth_input.c b/net/bluetooth/bluetooth_input.c index ac3c7c66b1..ff6a7f05fa 100644 --- a/net/bluetooth/bluetooth_input.c +++ b/net/bluetooth/bluetooth_input.c @@ -140,43 +140,43 @@ static int bluetooth_queue_frame(FAR struct bluetooth_conn_s *conn, } #if CONFIG_NET_BLUETOOTH_BACKLOG > 0 - /* If incrementing the count would exceed the maximum bc_backlog value, then - * delete the oldest frame from the head of the RX queue. - */ + /* If incrementing the count would exceed the maximum bc_backlog value, then + * delete the oldest frame from the head of the RX queue. + */ - if (conn->bc_backlog >= CONFIG_NET_BLUETOOTH_BACKLOG) - { - DEBUGASSERT(conn->bc_backlog == CONFIG_NET_BLUETOOTH_BACKLOG); + if (conn->bc_backlog >= CONFIG_NET_BLUETOOTH_BACKLOG) + { + DEBUGASSERT(conn->bc_backlog == CONFIG_NET_BLUETOOTH_BACKLOG); - /* Remove the container from the tail RX input queue. */ + /* Remove the container from the tail RX input queue. */ - container = conn->bc_rxhead; - DEBUGASSERT(container != NULL); - conn->bc_rxhead = container->bn_flink; - container->bn_flink = NULL; + container = conn->bc_rxhead; + DEBUGASSERT(container != NULL); + conn->bc_rxhead = container->bn_flink; + container->bn_flink = NULL; - /* Did the RX queue become empty? */ + /* Did the RX queue become empty? */ - if (conn->bc_rxhead == NULL) - { - conn->bc_rxtail = NULL; - } + if (conn->bc_rxhead == NULL) + { + conn->bc_rxtail = NULL; + } - DEBUGASSERT(container != NULL && container->bn_iob != NULL); + DEBUGASSERT(container != NULL && container->bn_iob != NULL); - /* Free both the IOB and the container */ + /* Free both the IOB and the container */ - iob_free(container->bn_iob); - bluetooth_container_free(container); - } - else - { - /* Increment the count of frames in the queue. */ + iob_free(container->bn_iob); + bluetooth_container_free(container); + } + else + { + /* Increment the count of frames in the queue. */ - conn->bc_backlog++; - } + conn->bc_backlog++; + } - DEBUGASSERT((int)conn->bc_backlog == bluetooth_count_frames(conn)); + DEBUGASSERT((int)conn->bc_backlog == bluetooth_count_frames(conn)); #endif return OK; diff --git a/tools/nxstyle.c b/tools/nxstyle.c index 4c36a0dfe3..a6334ec4c2 100644 --- a/tools/nxstyle.c +++ b/tools/nxstyle.c @@ -548,7 +548,74 @@ int main(int argc, char **argv, char **envp) do { have_upper |= isupper(line[n]); - have_lower |= islower(line[n]); + + /* The coding standard provides for some exceptions of lower + * case characters in pre-processor strings: + * + * IPv[4|6] as an IP version number + * ICMPv6 as an ICMP version number + * IGMPv2 as an IGMP version number + * [0-9]p[0-9] as a decimal point + * d[0-9] as a divisor + */ + + if (!have_lower && islower(line[n])) + { + switch (line[n]) + { + case 'v': + if (n > 1 && + line[n - 2] == 'I' && + line[n - 1] == 'P' && + (line[n + 1] == '4' || + line[n + 1] == '6')) + { + } + else if (n > 3 && + line[n - 4] == 'I' && + line[n - 3] == 'C' && + line[n - 2] == 'M' && + line[n - 1] == 'P' && + line[n + 1] == '6') + { + } + else if (n > 3 && + line[n - 4] == 'I' && + line[n - 3] == 'G' && + line[n - 2] == 'M' && + line[n - 1] == 'P' && + line[n + 1] == '2') + { + } + else + { + have_lower = true; + } + break; + + case 'p': + if (have_upper && + (n < 1 || + !isdigit(line[n - 1]) || + !isdigit(line[n + 1]))) + { + have_lower = true; + } + break; + + case 'd': + if (have_upper && !isdigit(line[n + 1])) + { + have_lower = true; + } + break; + + default: + have_lower = true; + break; + } + } + n++; } while (line[n] == '_' || isalnum(line[n]));