This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch revert-12794-nxstyle_if_statement
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit f28cb956777b72b19963635ba6d10054a87bb3c7
Author: Xiang Xiao <[email protected]>
AuthorDate: Thu Aug 22 07:22:58 2024 -0700

    Revert "tools: nxstyle if statement check"
    
    This reverts commit 780366de6269227fced5d8395d192b6d20be1c36.
---
 tools/nxstyle.c | 40 ++++++++++------------------------------
 1 file changed, 10 insertions(+), 30 deletions(-)

diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index bcf796203d..4fbb558d25 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -1085,7 +1085,6 @@ int main(int argc, char **argv, char **envp)
   bool bfunctions;      /* True: In private or public functions */
   bool bstatm;          /* True: This line is beginning of a statement */
   bool bfor;            /* True: This line is beginning of a 'for' statement */
-  bool bif;             /* True: This line is beginning of a 'if' statement */
   bool bswitch;         /* True: Within a switch statement */
   bool bstring;         /* True: Within a string */
   bool bquote;          /* True: Backslash quoted character next */
@@ -1258,7 +1257,6 @@ int main(int argc, char **argv, char **envp)
       bstatm       = false;    /* True: This line is beginning of a
                                 * statement */
       bfor         = false;    /* REVISIT: Implies for() is all on one line */
-      bif          = false;    /* True: This line is beginning of a 'if' 
statement */
 
       /* If we are not in a comment, then this certainly is not a right-hand
        * comment.
@@ -1775,10 +1773,7 @@ int main(int argc, char **argv, char **envp)
       /* Check for a single line comment */
 
       linelen = strlen(line);
-
-      /* Minimum is slash, star, star, slash, newline */
-
-      if (linelen >= 5)
+      if (linelen >= 5)      /* Minimum is slash, star, star, slash, newline */
         {
           lptr = strstr(line, "*/");
           if (line[indent] == '/' && line[indent + 1] == '*' &&
@@ -1970,6 +1965,7 @@ int main(int argc, char **argv, char **envp)
                    strncmp(&line[indent], "do ", 3) == 0 ||
                    strncmp(&line[indent], "else ", 5) == 0 ||
                    strncmp(&line[indent], "goto ", 5) == 0 ||
+                   strncmp(&line[indent], "if ", 3) == 0 ||
                    strncmp(&line[indent], "return ", 7) == 0 ||
     #if 0 /* Doesn't follow pattern */
                    strncmp(&line[indent], "switch ", 7) == 0 ||
@@ -1979,12 +1975,6 @@ int main(int argc, char **argv, char **envp)
               bstatm = true;
             }
 
-          else if(strncmp(&line[indent], "if ", 3) == 0)
-            {
-              bif    = true;
-              bstatm = true;
-            }
-
           /* Spacing works a little differently for and switch statements */
 
           else if (strncmp(&line[indent], "for ", 4) == 0)
@@ -2000,17 +1990,12 @@ int main(int argc, char **argv, char **envp)
           /* Also check for C keywords with missing white space */
 
           else if (strncmp(&line[indent], "do(", 3) == 0 ||
+                   strncmp(&line[indent], "if(", 3) == 0 ||
                    strncmp(&line[indent], "while(", 6) == 0)
             {
               ERROR("Missing whitespace after keyword", lineno, n);
               bstatm = true;
             }
-          else if (strncmp(&line[indent], "if(", 3) == 0)
-            {
-              ERROR("Missing whitespace after keyword", lineno, n);
-              bif   = true;
-              bstatm = true;
-            }
           else if (strncmp(&line[indent], "for(", 4) == 0)
             {
               ERROR("Missing whitespace after keyword", lineno, n);
@@ -2600,7 +2585,7 @@ int main(int argc, char **argv, char **envp)
 
                    /* Check for inappropriate space around parentheses */
 
-                    if (line[n + 1] == ' ')
+                    if (line[n + 1] == ' ')  /* && !bfor */
                       {
                          ERROR("Space follows left parenthesis", lineno, n);
                       }
@@ -2612,11 +2597,11 @@ int main(int argc, char **argv, char **envp)
                     /* Decrease the parenthetical nesting level */
 
                     if (pnest < 1)
-                      {
-                        ERROR("Unmatched right parentheses", lineno, n);
-                        pnest = 0;
-                      }
-                    else
+                     {
+                       ERROR("Unmatched right parentheses", lineno, n);
+                       pnest = 0;
+                     }
+                   else
                      {
                        pnest--;
                      }
@@ -2627,12 +2612,7 @@ int main(int argc, char **argv, char **envp)
 
                     if (n > 0 && n != indent && line[n - 1] == ' ' && !bfor)
                       {
-                        ERROR("Space precedes right parenthesis", lineno, n);
-                      }
-
-                    if (bif == true && pnest == 0 && line[n + 1] != '\n')
-                      {
-                        ERROR("If statement followed by garbage", lineno, n);
+                         ERROR("Space precedes right parenthesis", lineno, n);
                       }
                   }
                   break;

Reply via email to