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

cederom pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new c81cc02e83d tools/nxstyle: check alignment of statements without a 
leading keyword
c81cc02e83d is described below

commit c81cc02e83dcd9cdabfe0dabdab63c8def15afae
Author: raiden00pl <[email protected]>
AuthorDate: Mon Jul 27 12:20:13 2026 +0200

    tools/nxstyle: check alignment of statements without a leading keyword
    
    Only lines beginning with a C keyword were checked, so an assignment or
    a call could sit at any column.
    
    Signed-off-by: raiden00pl <[email protected]>
    Assisted-by: Claude Code
---
 tools/nxstyle.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index 8beec3dc44a..94970292cd0 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -1445,6 +1445,9 @@ int main(int argc, char **argv, char **envp)
   int externc_lineno;   /* Last line where 'extern "C"' declared */
   bool bexact;          /* True: The expected indentation below is exact */
   bool bppline;         /* True: This line is a pre-processor line */
+  bool blabelline;      /* True: This line holds nothing but a label */
+  bool bstmtstart;      /* True: A new statement begins on this line */
+  bool bprevstmtend;    /* True: The preceding line of code ended a statement 
*/
   bool bctrlline;       /* True: A control statement starts on this line */
   char lastcode;        /* Last code character seen on this line */
   char prevlastcode;    /* Last code character on the preceding line */
@@ -1572,6 +1575,9 @@ int main(int argc, char **argv, char **envp)
   brace_indent   = 0;           /* Indentation of the awaiting keyword */
   bexact         = false;       /* True: Expected indentation is exact */
   bppline        = false;       /* True: This line is a pre-processor line */
+  blabelline     = false;       /* True: This line holds nothing but a label */
+  bstmtstart     = true;        /* True: A statement begins on this line */
+  bprevstmtend   = true;        /* True: The preceding code ended a statement 
*/
   bctrlline      = false;       /* True: A control statement starts here */
   lastcode       = '\0';        /* Last code character seen on this line */
   prevlastcode   = '\0';        /* Last code character on the preceding line */
@@ -1623,7 +1629,25 @@ int main(int argc, char **argv, char **envp)
       bctrlline    = false;    /* No control statement starts on this line */
       ctrl_bswitch = false;    /* That brace does not open a switch body */
       bppline      = false;    /* True: This line is a pre-processor line */
+
+      /* A label ends the preceding statement, like a 'case' does */
+
+      blabelline = false;
+
+      if (isalpha((int)line[indent]) != 0 || line[indent] == '_')
+        {
+          int ii = indent;
+
+          while (isalnum((int)line[ii]) != 0 || line[ii] == '_')
+            {
+              ii++;
+            }
+
+          blabelline = line[ii] == ':' && line[ii + 1] != ':';
+        }
+
       lastcode     = '\0';     /* No code has been seen on this line yet */
+      bstmtstart   = bprevstmtend;
       rbrace_match = -1;       /* No left brace is closed on this line */
 
       /* Where a statement on this line is expected to begin: two columns in
@@ -3798,6 +3822,22 @@ int main(int argc, char **argv, char **envp)
       bexact = bnest > 0 && dnest == 0 && prevpnest == 0 && stmt_indent > 0 &&
                bfunctions && bfuncbody;
 
+      /* A line after one ending in ';', '{', '}' or a label begins a new
+       * statement; anything else continues the previous one.
+       */
+
+      if (lastcode != '\0' && !bppline)
+        {
+          /* A colon ends a statement only in a label, and a line left inside
+           * parentheses is always continued, so a 'for' clause does not.
+           */
+
+          bprevstmtend = pnest == 0 &&
+                         (lastcode == ';' || lastcode == '{' ||
+                          lastcode == '}' ||
+                          (lastcode == ':' && (bcaseline || blabelline)));
+        }
+
       /* A line that follows one ending in ';', '{', '}' or ':' begins a new
        * statement.  Anything else is the continuation of the statement on the
        * preceding line and may be aligned freely.  Pre-processor lines are
@@ -4056,6 +4096,7 @@ int main(int argc, char **argv, char **envp)
                     }
                 }
               else if ((bstatm ||                         /* Begins with C 
keyword */
+                  (bstmtstart && bexact) ||               /* Begins a 
statement */
                   (line[indent] == '/' &&
                   bfunctions &&
                   line[indent + 1] == '*')) &&            /* Comment in 
functions */

Reply via email to