nxstyle:nxstyle should pass nxstyle checks!

This commit is contained in:
David Sidrane 2020-03-07 05:35:08 -08:00 committed by patacongo
parent 493b8de938
commit c5b4d9b628

View File

@ -1,4 +1,4 @@
/**************************************************************************** /********************************************************************************
* tools/nxstyle.c * tools/nxstyle.c
* *
* Copyright (C) 2015, 2018-2020 Gregory Nutt. All rights reserved. * Copyright (C) 2015, 2018-2020 Gregory Nutt. All rights reserved.
@ -31,11 +31,11 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ADVISED OF THE * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************/ ********************************************************************************/
/**************************************************************************** /********************************************************************************
* Included Files * Included Files
****************************************************************************/ ********************************************************************************/
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
@ -48,9 +48,9 @@
#include <unistd.h> #include <unistd.h>
#include <libgen.h> #include <libgen.h>
/**************************************************************************** /********************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ********************************************************************************/
#define NXSTYLE_VERSION "0.01" #define NXSTYLE_VERSION "0.01"
@ -69,9 +69,9 @@
#define INFO(m, l, o) message(INFO, (m), (l), (o)) #define INFO(m, l, o) message(INFO, (m), (l), (o))
#define INFOFL(m, s) message(INFO, (m), -1, -1) #define INFOFL(m, s) message(INFO, (m), -1, -1)
/**************************************************************************** /********************************************************************************
* Private types * Private types
****************************************************************************/ ********************************************************************************/
enum class_e enum class_e
{ {
@ -118,9 +118,9 @@ struct file_section_s
uint8_t ftype; /* File type where section found */ uint8_t ftype; /* File type where section found */
}; };
/**************************************************************************** /********************************************************************************
* Private data * Private data
****************************************************************************/ ********************************************************************************/
static char *g_file_name = ""; static char *g_file_name = "";
static enum file_e g_file_type = UNKNOWN; static enum file_e g_file_type = UNKNOWN;
@ -184,16 +184,16 @@ static const struct file_section_s g_section_info[] =
} }
}; };
/**************************************************************************** /********************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ********************************************************************************/
/**************************************************************************** /********************************************************************************
* Name: show_usage * Name: show_usage
* *
* Description: * Description:
* *
****************************************************************************/ ********************************************************************************/
static void show_usage(char *progname, int exitcode, char *what) static void show_usage(char *progname, int exitcode, char *what)
{ {
@ -203,22 +203,24 @@ static void show_usage(char *progname, int exitcode, char *what)
fprintf(stderr, "%s\n", what); fprintf(stderr, "%s\n", what);
} }
fprintf(stderr, "Usage: %s [-m <excess>] [-v <level>] [-r <start,count>] <filename>\n", fprintf(stderr, "Usage: %s [-m <excess>] [-v <level>] "
"[-r <start,count>] <filename>\n",
basename(progname)); basename(progname));
fprintf(stderr, " %s -h this help\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, " %s -v <level> where level is\n",
basename(progname));
fprintf(stderr, " 0 - no output\n"); fprintf(stderr, " 0 - no output\n");
fprintf(stderr, " 1 - PASS/FAIL\n"); fprintf(stderr, " 1 - PASS/FAIL\n");
fprintf(stderr, " 2 - output each line (default)\n"); fprintf(stderr, " 2 - output each line (default)\n");
exit(exitcode); exit(exitcode);
} }
/**************************************************************************** /********************************************************************************
* Name: skip * Name: skip
* *
* Description: * Description:
* *
****************************************************************************/ ********************************************************************************/
static int skip(int lineno) static int skip(int lineno)
{ {
@ -226,7 +228,8 @@ static int skip(int lineno)
for (i = 0; i < g_rangenumber; i++) for (i = 0; i < g_rangenumber; i++)
{ {
if (lineno >= g_rangestart[i] && lineno < g_rangestart[i] + g_rangecount[i]) if (lineno >= g_rangestart[i] && lineno < g_rangestart[i] +
g_rangecount[i])
{ {
return 0; return 0;
} }
@ -235,12 +238,12 @@ static int skip(int lineno)
return g_rangenumber != 0; return g_rangenumber != 0;
} }
/**************************************************************************** /********************************************************************************
* Name: message * Name: message
* *
* Description: * Description:
* *
****************************************************************************/ ********************************************************************************/
static int message(enum class_e class, const char *text, int lineno, int ndx) static int message(enum class_e class, const char *text, int lineno, int ndx)
{ {
@ -273,12 +276,12 @@ static int message(enum class_e class, const char *text, int lineno, int ndx)
return g_status; return g_status;
} }
/**************************************************************************** /********************************************************************************
* Name: check_spaces_left * Name: check_spaces_left
* *
* Description: * Description:
* *
****************************************************************************/ ********************************************************************************/
static void check_spaces_left(char *line, int lineno, int ndx) static void check_spaces_left(char *line, int lineno, int ndx)
{ {
@ -294,12 +297,12 @@ static void check_spaces_left(char *line, int lineno, int ndx)
} }
} }
/**************************************************************************** /********************************************************************************
* Name: check_spaces_leftright * Name: check_spaces_leftright
* *
* Description: * Description:
* *
****************************************************************************/ ********************************************************************************/
static void check_spaces_leftright(char *line, int lineno, int ndx1, int ndx2) static void check_spaces_leftright(char *line, int lineno, int ndx1, int ndx2)
{ {
@ -316,13 +319,13 @@ static void check_spaces_leftright(char *line, int lineno, int ndx1, int ndx2)
} }
} }
/**************************************************************************** /********************************************************************************
* Name: block_comment_width * Name: block_comment_width
* *
* Description: * Description:
* Get the width of a block comment * Get the width of a block comment
* *
****************************************************************************/ ********************************************************************************/
static int block_comment_width(char *line) static int block_comment_width(char *line)
{ {
@ -393,13 +396,13 @@ static int block_comment_width(char *line)
return 0; return 0;
} }
/**************************************************************************** /********************************************************************************
* Name: get_line_width * Name: get_line_width
* *
* Description: * Description:
* Get the maximum line width by examining the width of the block comments. * Get the maximum line width by examining the width of the block comments.
* *
****************************************************************************/ ********************************************************************************/
static int get_line_width(FILE *instream) static int get_line_width(FILE *instream)
{ {
@ -446,13 +449,13 @@ static int get_line_width(FILE *instream)
return min; return min;
} }
/**************************************************************************** /********************************************************************************
* Name: check_section_header * Name: check_section_header
* *
* Description: * Description:
* Check if the current line holds a section header * Check if the current line holds a section header
* *
****************************************************************************/ ********************************************************************************/
static bool check_section_header(const char *line, int lineno) static bool check_section_header(const char *line, int lineno)
{ {
@ -480,9 +483,9 @@ static bool check_section_header(const char *line, int lineno)
return false; return false;
} }
/**************************************************************************** /********************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ********************************************************************************/
int main(int argc, char **argv, char **envp) int main(int argc, char **argv, char **envp)
{ {
@ -623,7 +626,8 @@ int main(int argc, char **argv, char **envp)
ppline = false; /* True: Continuation of a pre-processor line */ ppline = false; /* True: Continuation of a pre-processor line */
bexternc = false; /* True: Within 'extern "C"' */ bexternc = false; /* True: Within 'extern "C"' */
brhcomment = false; /* True: Comment to the right of code */ brhcomment = false; /* True: Comment to the right of code */
prevbrhcmt = false; /* True: Previous line had comment to the right of code */ prevbrhcmt = false; /* True: Previous line had comment to the right
* of code */
lineno = 0; /* Current line number */ lineno = 0; /* Current line number */
ncomment = 0; /* Comment nesting level on this line */ ncomment = 0; /* Comment nesting level on this line */
bnest = 0; /* Brace nesting level on this line */ bnest = 0; /* Brace nesting level on this line */
@ -643,12 +647,16 @@ int main(int argc, char **argv, char **envp)
lineno++; lineno++;
indent = 0; indent = 0;
prevbnest = bnest; /* Brace nesting level on the previous line */ prevbnest = bnest; /* Brace nesting level on the previous line */
prevdnest = dnest; /* Data declaration nesting level on the previous line */ prevdnest = dnest; /* Data declaration nesting level on the
* previous line */
prevncomment = ncomment; /* Comment nesting level on the previous line */ prevncomment = ncomment; /* Comment nesting level on the previous line */
bstatm = false; /* True: This line is beginning of a statement */ bstatm = false; /* True: This line is beginning of a
* statement */
bfor = false; /* REVISIT: Implies for() is all on one line */ bfor = false; /* REVISIT: Implies for() is all on one line */
/* If we are not in a comment, then this certainly is not a right-hand comment. */ /* If we are not in a comment, then this certainly is not a right-hand
* comment.
*/
prevbrhcmt = brhcomment; prevbrhcmt = brhcomment;
if (ncomment <= 0) if (ncomment <= 0)
@ -934,7 +942,9 @@ int main(int argc, char **argv, char **envp)
noblank_lineno != lineno - 1 && noblank_lineno != lineno - 1 &&
!brhcomment) !brhcomment)
{ {
/* TODO: This generates a false alarm if preceded by a label. */ /* TODO: This generates a false alarm if preceded
* by a label.
*/
ERROR("Missing blank line before comment found", lineno, 1); ERROR("Missing blank line before comment found", lineno, 1);
} }
@ -2224,10 +2234,11 @@ int main(int argc, char **argv, char **envp)
{ {
/* REVISIT: Generates false alarms on comments at the end of /* REVISIT: Generates false alarms on comments at the end of
* the line if there is nothing preceding (such as the aligned * the line if there is nothing preceding (such as the aligned
* comments with a structure field definition). So disabled for * comments with a structure field definition). So disabled
* comments before beginning of function definitions. * for comments before beginning of function definitions.
* *
* Suppress this error if this is a comment to the right of code. * Suppress this error if this is a comment to the right of
* code.
* Those may be unaligned. * Those may be unaligned.
*/ */