From 2722fd8192b1fff42afd389ac1733b5bed6e0aaf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 24 Aug 2018 05:51:44 -0600 Subject: [PATCH] tools/nxstyle.c: Add capability to detect multiple blank lines. Single spacing required by the coding standard. Also coding standard fixes to server .c files for problems found during testing nxstyle. --- audio/audio.c | 2 + audio/pcm_decode.c | 2 + binfmt/binfmt_dumpmodule.c | 2 - binfmt/binfmt_globals.c | 2 - binfmt/pcode.c | 2 +- drivers/rwbuffer.c | 5 +- libs/libdsp/lib_misc.c | 1 - libs/libdsp/lib_observer.c | 3 +- libs/libdsp/lib_svm.c | 2 +- tools/nxstyle.c | 134 ++++++++++++++------------ wireless/pktradio/pktradio_loopback.c | 1 + 11 files changed, 84 insertions(+), 72 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 1dde458efd..848a7b0496 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -66,6 +66,7 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + /* Debug ********************************************************************/ /* Non-standard debug that may be enabled just for testing Audio */ @@ -416,6 +417,7 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg) audinfo("AUDIOIOC_SHUTDOWN\n"); /* Call the lower-half driver initialize handler */ + ret = lower->ops->shutdown(lower); } break; diff --git a/audio/pcm_decode.c b/audio/pcm_decode.c index 20b0b2943f..6aa6579a5f 100644 --- a/audio/pcm_decode.c +++ b/audio/pcm_decode.c @@ -62,6 +62,7 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + /* Configuration ************************************************************/ #define CONFIG_PCM_DEBUG 1 /* For now */ @@ -79,6 +80,7 @@ /**************************************************************************** * Private Types ****************************************************************************/ + /* This structure describes the internal state of the PCM decoder */ struct pcm_decode_s diff --git a/binfmt/binfmt_dumpmodule.c b/binfmt/binfmt_dumpmodule.c index a94f76930c..04568c8baf 100644 --- a/binfmt/binfmt_dumpmodule.c +++ b/binfmt/binfmt_dumpmodule.c @@ -90,5 +90,3 @@ int dump_module(FAR const struct binary_s *bin) return OK; } #endif - - diff --git a/binfmt/binfmt_globals.c b/binfmt/binfmt_globals.c index d3246bd506..ea01ab025b 100644 --- a/binfmt/binfmt_globals.c +++ b/binfmt/binfmt_globals.c @@ -67,5 +67,3 @@ FAR struct binfmt_s *g_binfmts; ****************************************************************************/ #endif /* CONFIG_BINFMT_DISABLE */ - - diff --git a/binfmt/pcode.c b/binfmt/pcode.c index b8fc5aaf09..e335d6ca25 100644 --- a/binfmt/pcode.c +++ b/binfmt/pcode.c @@ -199,7 +199,7 @@ static int pcode_run(FAR char *exepath, size_t varsize, size_t strsize) /* Execute the P-Code program until a stopping condition occurs */ - for (;;) + for (; ; ) { /* Execute the instruction; Check for exceptional conditions */ diff --git a/drivers/rwbuffer.c b/drivers/rwbuffer.c index 6fe67bdfac..c43ec5f67b 100644 --- a/drivers/rwbuffer.c +++ b/drivers/rwbuffer.c @@ -944,11 +944,15 @@ ssize_t rwb_readbytes(FAR struct rwbuffer_s *dev, off_t offset, size_t nbytes, FAR uint8_t *buffer) { /* Loop while there are bytes still be be read */ + /* Make sure that the sector containing the next bytes to transfer is in * memory. */ + /* How many bytes can be transfer from the in-memory data? */ + /* Transfer the bytes */ + /* Adjust counts and offsets for the next time through the loop */ #warning Not Implemented @@ -956,7 +960,6 @@ ssize_t rwb_readbytes(FAR struct rwbuffer_s *dev, off_t offset, } #endif - /**************************************************************************** * Name: rwb_mediaremoved * diff --git a/libs/libdsp/lib_misc.c b/libs/libdsp/lib_misc.c index 3ac815547e..f4481d429e 100644 --- a/libs/libdsp/lib_misc.c +++ b/libs/libdsp/lib_misc.c @@ -240,7 +240,6 @@ float fast_cos(float angle) return fast_sin(angle + M_PI_2_F); } - /**************************************************************************** * Name: fast_sin2 * diff --git a/libs/libdsp/lib_observer.c b/libs/libdsp/lib_observer.c index a94af4d95a..b459c54d8e 100644 --- a/libs/libdsp/lib_observer.c +++ b/libs/libdsp/lib_observer.c @@ -375,7 +375,7 @@ void motor_observer_smo(FAR struct motor_observer_s *o, FAR ab_frame_t *i_ab, angle_norm_2pi(&angle, 0.0f, 2.0f*M_PI_F); - /* Store estimated angle in observer data*/ + /* Store estimated angle in observer data */ o->angle = angle; } @@ -423,7 +423,6 @@ void motor_sobserver_div_init(FAR struct motor_sobserver_div_s *so, so->one_by_dt = 1.0f/(so->samples * per); } - /**************************************************************************** * Name: motor_sobserver_div * diff --git a/libs/libdsp/lib_svm.c b/libs/libdsp/lib_svm.c index 87fc419480..0bfb2c0ade 100644 --- a/libs/libdsp/lib_svm.c +++ b/libs/libdsp/lib_svm.c @@ -152,7 +152,7 @@ static uint8_t svm3_sector_get(FAR abc_frame_t *ijk) * Returned Value: * None * -****************************************************************************/ + ****************************************************************************/ static void svm3_duty_calc(FAR struct svm3_state_s *s, FAR abc_frame_t *ijk) { diff --git a/tools/nxstyle.c b/tools/nxstyle.c index 438867a79e..39671de8f2 100644 --- a/tools/nxstyle.c +++ b/tools/nxstyle.c @@ -74,8 +74,9 @@ int main(int argc, char **argv, char **envp) int prevncomment; int n; int i; - int last_oneline_comment; - int last_blank_line; + int comment_lineno; + int blank_lineno; + int noblank_lineno; int linelen; instream = fopen(argv[1], "r"); @@ -85,19 +86,19 @@ int main(int argc, char **argv, char **envp) return 1; } - btabs = false; - bfunctions = false; - bswitch = false; - bstring = false; - lineno = 0; - ncomment = 0; - nnest = 0; - declnest = 0; - prevdeclnest = 0; - prevncomment = 0; - last_oneline_comment = -1; /* Line on which the last one line comment was - * closed */ - last_blank_line = -1; /* lineno of last blank line */ + btabs = false; + bfunctions = false; + bswitch = false; + bstring = false; + lineno = 0; + ncomment = 0; + nnest = 0; + declnest = 0; + prevdeclnest = 0; + prevncomment = 0; + comment_lineno = -1; /* Line on which the last one line comment was closed */ + blank_lineno = -1; /* Line number of the last blank line */ + noblank_lineno = -1; /* A blank line is not needed after this line */ while (fgets(line, LINE_SIZE, instream)) { @@ -113,20 +114,25 @@ int main(int argc, char **argv, char **envp) if (line[0] == '\n') { - last_blank_line = lineno; + if (lineno == blank_lineno + 1) + { + fprintf(stderr, "Too many blank lines at line %d\n", lineno); + } + + blank_lineno = lineno; } else /* this line is non-blank */ { - if (lineno == last_oneline_comment + 1) + if (lineno == comment_lineno + 1) { /* TODO: This generates a false alarm if the current line - * contains a right brace. No blank line should be present in - * that case. + * contains a right brace or a pre-processor line. No blank line + * should be present in those cases. */ fprintf(stderr, "Missing blank line after comment line. Found at line %d\n", - last_oneline_comment); + comment_lineno); } } @@ -171,7 +177,7 @@ int main(int argc, char **argv, char **envp) { /* Suppress error for comment following conditional compilation */ - last_blank_line = lineno; + noblank_lineno = lineno; continue; } @@ -184,8 +190,9 @@ int main(int argc, char **argv, char **envp) if (line[indent] == '/' && line[indent +1] == '*' && lptr - line == linelen - 3) { - if (last_oneline_comment != lineno - 1 && - last_blank_line != lineno - 1) + if (comment_lineno != lineno - 1 && + blank_lineno != lineno - 1 && + noblank_lineno != lineno - 1) { /* TODO: This generates a false alarm if preceded by a label. */ @@ -194,7 +201,7 @@ int main(int argc, char **argv, char **envp) lineno); } - last_oneline_comment = lineno; + comment_lineno = lineno; } } @@ -261,7 +268,7 @@ int main(int argc, char **argv, char **envp) /* Check for a keyword indicating the beginning of a statement. * REVISIT: This, obviously, will not detect statements that do not - * begin with a C keyword (such as assignement statements). + * begin with a C keyword (such as assignment statements). */ else if (strncmp(&line[indent], "break ", 6) == 0 || @@ -322,14 +329,14 @@ int main(int argc, char **argv, char **envp) { /* Check for start of a C comment */ - if (line[n+1] == '*') + if (line[n + 1] == '*') { - if (line[n+2] == '\n') + if (line[n + 2] == '\n') { fprintf(stderr, "C comment on separate line at %d:%d\n", lineno, n); } - else if (line[n+2] != ' ' && line[n+2] != '*') + else if (line[n + 2] != ' ' && line[n + 2] != '*') { fprintf(stderr, "Missing space after opening C comment at line %d:%d\n", @@ -343,14 +350,14 @@ int main(int argc, char **argv, char **envp) /* Check for end of a C comment */ - else if (n > 0 && line[n-1] == '*') + else if (n > 0 && line[n - 1] == '*') { if (n < 2) { fprintf(stderr, "Closing C comment not indented at line %d:%d\n", lineno, n); } - else if (line[n-2] != ' ' && line[n-2] != '*') + else if (line[n - 2] != ' ' && line[n - 2] != '*') { fprintf(stderr, "Missing space before closing C comment at line %d:%d\n", @@ -362,7 +369,7 @@ int main(int argc, char **argv, char **envp) * expression are commented out within the expression. */ - if (line[n+1] != '\n') + if (line[n + 1] != '\n') { fprintf(stderr, "Garbage on line after C comment at line %d:%d\n", @@ -383,9 +390,12 @@ int main(int argc, char **argv, char **envp) } } - /* Check for C++ style comments */ + /* Check for C++ style comments + * NOTE: Gives false alarms on URLs (http://...) embedded + * inside of comments. + */ - else if (line[n+1] == '/') + else if (line[n + 1] == '/') { fprintf(stderr, "C++ style comment on at %d:%d\n", lineno, n); @@ -442,7 +452,7 @@ int main(int argc, char **argv, char **envp) lineno, n); } } - else if (line[n+1] != '\n') + else if (line[n + 1] != '\n') { if (declnest == 0) { @@ -460,7 +470,7 @@ int main(int argc, char **argv, char **envp) /* Suppress error for comment following a left brace */ - last_blank_line = lineno; + noblank_lineno = lineno; } break; @@ -498,9 +508,9 @@ int main(int argc, char **argv, char **envp) lineno, n); } } - else if (line[n+1] != '\n' && - line[n+1] != ',' && - line[n+1] != ';') + else if (line[n + 1] != '\n' && + line[n + 1] != ',' && + line[n + 1] != ';') { /* One case where there may be garbage after the right * bracket is, for example, when declaring a until or @@ -522,7 +532,7 @@ int main(int argc, char **argv, char **envp) case '(': { - if (line[n+1] == ' ' /* && !bfor */) + if (line[n + 1] == ' ' /* && !bfor */) { fprintf(stderr, "Space follows left parenthesis at line %d:%d\n", @@ -537,7 +547,7 @@ int main(int argc, char **argv, char **envp) * Allow "for (xx; xx; )" (bfor == true) */ - if (n > 0 && n != indent && line[n-1] == ' ' && !bfor) + if (n > 0 && n != indent && line[n - 1] == ' ' && !bfor) { fprintf(stderr, "Space precedes right parenthesis at line %d:%d\n", @@ -550,7 +560,7 @@ int main(int argc, char **argv, char **envp) case '[': { - if (line[n+1] == ' ') + if (line[n + 1] == ' ') { fprintf(stderr, "Space follows left bracket at line %d:%d\n", @@ -561,7 +571,7 @@ int main(int argc, char **argv, char **envp) case ']': { - if (n > 0 && line[n-1] == ' ') + if (n > 0 && line[n - 1] == ' ') { fprintf(stderr, "Space precedes right bracket at line %d:%d\n", @@ -574,7 +584,7 @@ int main(int argc, char **argv, char **envp) case ';': { - if (!isspace((int)line[n+1])) + if (!isspace((int)line[n + 1])) { fprintf(stderr, "Missing whitespace after semicolon at line %d:%d\n", lineno, n); @@ -595,7 +605,7 @@ int main(int argc, char **argv, char **envp) case ',': { - if (!isspace((int)line[n+1])) + if (!isspace((int)line[n + 1])) { fprintf(stderr, "Missing whitespace after comma at line %d:%d\n", lineno, n); @@ -617,9 +627,9 @@ int main(int argc, char **argv, char **envp) { int endndx = n + 2; - if (line[n+1] != '\n' && line[n+1] != '\0') + if (line[n + 1] != '\n' && line[n + 1] != '\0') { - if (line[n+1] == '\\') + if (line[n + 1] == '\\') { for (; line[endndx] != '\n' && @@ -637,7 +647,7 @@ int main(int argc, char **argv, char **envp) case '\n': { - if (n > 0 && isspace((int)line[n-1])) + if (n > 0 && isspace((int)line[n - 1])) { fprintf(stderr, "Dangling whitespace at the end of line %d:%d\n", @@ -651,7 +661,7 @@ int main(int argc, char **argv, char **envp) case '-': /* -> */ - if (line[n+1] == '>') + if (line[n + 1] == '>') { n++; break; @@ -660,7 +670,7 @@ int main(int argc, char **argv, char **envp) case '+': /* ++, -- */ - if (line[n+1] == line[n]) + if (line[n + 1] == line[n]) { n++; break; @@ -669,7 +679,7 @@ int main(int argc, char **argv, char **envp) case '&': /* && */ - if (line[n] == '&' && line[n+1] == line[n]) + if (line[n] == '&' && line[n + 1] == line[n]) { int curr; int next; @@ -697,7 +707,7 @@ int main(int argc, char **argv, char **envp) /* & OR &()*/ - else if (isalpha((int)line[n+1]) || line[n+1] == '_' || line[n+1] == '(') + else if (isalpha((int)line[n + 1]) || line[n + 1] == '_' || line[n + 1] == '(') { break; } @@ -706,12 +716,12 @@ int main(int argc, char **argv, char **envp) { if (line[n] == '/') { - if (line[n-1] == '*') + if (line[n - 1] == '*') { n++; break; } - else if (line[n+1] == '/') + else if (line[n + 1] == '/') { fprintf(stderr, "C++ style comment on at %d:%d\n", lineno, n); @@ -726,8 +736,8 @@ int main(int argc, char **argv, char **envp) /* *\/, ** */ if (line[n] == '*' && - (line[n+1] == '/' || - line[n+1] == '*')) + (line[n + 1] == '/' || + line[n + 1] == '*')) { n++; break; @@ -735,20 +745,20 @@ int main(int argc, char **argv, char **envp) /* *, *() */ - else if (isalpha((int)line[n+1]) || - line[n+1] == '_' || - line[n+1] == '(') + else if (isalpha((int)line[n + 1]) || + line[n + 1] == '_' || + line[n + 1] == '(') { break; } /* ( *) */ - else if (line[n+1] == ')') + else if (line[n + 1] == ')') { /* REVISIT: This gives false alarms on syntax like *--ptr */ - if (line[n-1] != ' ') + if (line[n - 1] != ' ') { fprintf(stderr, "Operator/assignment must be preceded with whitespace at line %d:%d\n", @@ -761,7 +771,7 @@ int main(int argc, char **argv, char **envp) case '%': { - if (isalnum((int)line[n+1])) + if (isalnum((int)line[n + 1])) { break; } @@ -784,7 +794,7 @@ int main(int argc, char **argv, char **envp) lineno, curr); } - next = n+1; + next = n + 1; /* <<, >>, <<=, >>= */ diff --git a/wireless/pktradio/pktradio_loopback.c b/wireless/pktradio/pktradio_loopback.c index 1aaf9174c8..3437fd88b6 100644 --- a/wireless/pktradio/pktradio_loopback.c +++ b/wireless/pktradio/pktradio_loopback.c @@ -592,6 +592,7 @@ static void lo_txavail_work(FAR void *arg) if (priv->lo_bifup) { /* If so, then poll the network for new XMIT data */ + #ifdef CONFIG_NET_6LOWPAN /* Make sure the our single packet buffer is attached */