You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/01/04 13:59:57 UTC

[incubator-nuttx] branch master updated: tools/nxstyle.c: Add -r option to check specified range lines

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 7da409f  tools/nxstyle.c: Add -r option to check specified range lines
     new 3951c4d  Merge branch 'master' of github.com:apache/incubator-nuttx
7da409f is described below

commit 7da409f3b53b4d2607b4551b059abb69ad3ad33b
Author: liuhaitao <li...@xiaomi.com>
AuthorDate: Thu Jan 2 17:22:08 2020 +0800

    tools/nxstyle.c: Add -r option to check specified range lines
    
    Usage: ./nxstyle -r start,count filename
    
    nxstyle with -r option used to parse the range lines rather than the whole file.
    
    Change-Id: I58ec56511fde14d6ec914400a7849e69960a3711
    Signed-off-by: liuhaitao <li...@xiaomi.com>
---
 tools/README.txt |  2 +-
 tools/nxstyle.c  | 40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/tools/README.txt b/tools/README.txt
index 4adcfc4..e297caf 100644
--- a/tools/README.txt
+++ b/tools/README.txt
@@ -316,7 +316,7 @@ nxstyle.c
   Prints formatted messages that are classified as info, warn, error, 
   fatal. In a parsable format that can be used by editors and IDEs.
 
-  Usage: nxstyle [-m <maxline>] [-v <level>] <filename>
+  Usage: nxstyle [-m <maxline>] [-v <level>] [-r <start,count>] <filename>
         nxstyle -h this help
         nxstyle -v <level> where level is
                    0 - no output
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index a7d9ce3..1ccbb75 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -53,6 +53,7 @@
 #define NXSTYLE_VERSION "0.01"
 
 #define LINE_SIZE      512
+#define RANGE_NUMBER   4096
 
 #define FATAL(m, l, o) message(FATAL, (m), (l), (o))
 #define FATALFL(m,s)   message(FATAL, (m), -1, -1)
@@ -93,9 +94,12 @@ enum file_e
 
 static char *g_file_name       = "";
 static enum file_e g_file_type = UNKNOWN;
-static int  g_maxline          = 78;
-static int  g_status           = 0;
-static int  g_verbose          = 2;
+static int g_maxline           = 78;
+static int g_status            = 0;
+static int g_verbose           = 2;
+static int g_rangenumber       = 0;
+static int g_rangestart[RANGE_NUMBER];
+static int g_rangecount[RANGE_NUMBER];
 
 /****************************************************************************
  * Private Functions
@@ -109,7 +113,8 @@ static void show_usage(char *progname, int exitcode, char *what)
       fprintf(stderr, "%s\n", what);
     }
 
-  fprintf(stderr, "Usage:  %s [-m <maxline>] [-v <level>] <filename>\n", basename(progname));
+  fprintf(stderr, "Usage:  %s [-m <maxline>] [-v <level>] [-r <start,count>] <filename>\n",
+          basename(progname));
   fprintf(stderr, "        %s -h this help\n", basename(progname));
   fprintf(stderr, "        %s -v <level> where level is\n", basename(progname));
   fprintf(stderr, "                   0 - no output\n");
@@ -118,10 +123,30 @@ static void show_usage(char *progname, int exitcode, char *what)
   exit(exitcode);
 }
 
+static int skip(int lineno)
+{
+  int i;
+
+  for (i = 0; i < g_rangenumber; i++)
+    {
+      if (lineno >= g_rangestart[i] && lineno < g_rangestart[i] + g_rangecount[i])
+        {
+          return 0;
+        }
+    }
+
+  return g_rangenumber != 0;
+}
+
 static int message(enum class_e class, const char *text, int lineno, int ndx)
 {
   FILE *out = stdout;
 
+  if (skip(lineno))
+    {
+      return g_status;
+    }
+
   if (class > INFO)
     {
       out = stderr;
@@ -217,7 +242,7 @@ int main(int argc, char **argv, char **envp)
   int i;
   int c;
 
-  while ((c = getopt(argc, argv, ":hv:gm:")) != -1)
+  while ((c = getopt(argc, argv, ":hv:gm:r:")) != -1)
     {
       switch (c)
       {
@@ -237,6 +262,11 @@ int main(int argc, char **argv, char **envp)
           }
           break;
 
+      case 'r':
+        g_rangestart[g_rangenumber] = atoi(strtok(optarg, ","));
+        g_rangecount[g_rangenumber++] = atoi(strtok(NULL, ","));
+        break;
+
       case 'h':
         show_usage(argv[0], 0, NULL);
         break;