From f6221ae2dc4dca32af0d293ba7ef4369398660c3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 29 Jun 2019 18:38:56 -0600 Subject: [PATCH] tools/nxstyle.c: Fix logic from commit 005a077310f2f362a3f1147fdf38ae381d858d42 for the case of header files when contain no functions. --- tools/nxstyle.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/nxstyle.c b/tools/nxstyle.c index 2b6843ab75..1a39f1ed7f 100644 --- a/tools/nxstyle.c +++ b/tools/nxstyle.c @@ -103,6 +103,7 @@ int main(int argc, char **argv, char **envp) char line[LINE_SIZE]; /* The current line being examined */ char *filename; /* Name of the file to open */ char *lptr; /* Temporary pointer into line[] */ + char *ext; /* Temporary file extension */ bool btabs; /* True: TAB characters found on the line */ bool bfunctions; /* True: In private or public functions */ bool bstatm; /* True: This line is beginning of a statement */ @@ -112,6 +113,7 @@ int main(int argc, char **argv, char **envp) bool bquote; /* True: Backslash quoted character next */ bool bblank; /* Used to verify block comment terminator */ bool ppline; /* True: The next line the continuation of a pre-processor command */ + bool hdrfile; /* True: File is a header file */ int lineno; /* Current line number */ int indent; /* Indentation level */ int ncomment; /* Comment nesting level on this line */ @@ -174,6 +176,24 @@ int main(int argc, char **argv, char **envp) return 1; } + /* Are we parsing a header file? */ + + hdrfile = false; + ext = strrchr(filename, '.'); + + if (ext == 0) + { + printf("No file extension\n"); + } + else if (strcmp(ext, ".h") == 0) + { + hdrfile = true; + } + else if (strcmp(ext, ".c") != 0) + { + printf("Unrecognized file extension: \"%s\"\n", ext + 1); + } + btabs = false; /* True: TAB characters found on the line */ bfunctions = false; /* True: In private or public functions */ bswitch = false; /* True: Within a switch statement */ @@ -1601,7 +1621,7 @@ int main(int argc, char **argv, char **envp) } } - if (!bfunctions) + if (!bfunctions && !hdrfile) { fprintf(stderr, "ERROR: \"Private/Public Functions\" not found!\n"); fprintf(stderr, " File could not be checked.\n");