From ea1c16c3270e775bfc615b612d11d319f841b812 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 4 Jan 2022 20:03:07 +0100 Subject: misc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- common.h | 12 ++++++++++-- makefile.c | 18 ++++++++++++++++-- mklint.c | 42 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/common.h b/common.h index 01a8c0d..35988cc 100644 --- a/common.h +++ b/common.h @@ -38,7 +38,8 @@ X(WC_CONTINUATION_TO_BLANK, "continuation-to-blank", WARN)\ X(WC_EOF_LINE_CONTINUATION, "eof-line-continuation", WARN)\ X(WC_UNINDENTED_CONTINUATION, "unindented-continuation", WARN)\ - X(WC_SPACELESS_CONTINUATION, "spaceless-continuation", WARN) + X(WC_SPACELESS_CONTINUATION, "spaceless-continuation", WARN)\ + X(WC_COMMENT_CONTINUATION, "comment-continuation", WARN) enum action { @@ -75,12 +76,19 @@ struct line { size_t lineno; int eof; int nest_level; - char continuation_joiner; + char continuation_joiner; /* If '\\', it shall be '\\\n' */ +}; + +enum macro_bracket_style { + INCONSISTENT, + ROUND, + CURLY }; struct style { size_t max_line_length; int only_empty_blank_lines; + enum macro_bracket_style macro_bracket_style; }; diff --git a/makefile.c b/makefile.c index ef280b9..ca3d744 100644 --- a/makefile.c +++ b/makefile.c @@ -36,10 +36,24 @@ open_default_makefile(const char **pathp) "alternatives are ./makefile and ./Makefile"); find_existing_fallbacks: + /* This serves two purposes: to inform the user that + * we are only checking one of the files, and which + * would (which is printed earlier), and to information + * the user that it can be confusing. It is not common + * practice run make(1) to generate ./makefile from + * ./Makefile and (either immediately or by running + * make(1) again) built the project from ./Makefile, + * although that certainly can be useful if there are + * parts of the makefile you want to generate, such + * as .h file dependencies for .c files in very large + * projects that have many .h files and many .c files + * that each only depend on a few .h files. + */ for (i++; i < ELEMSOF(default_makefiles); i++) if (!access(default_makefiles[i], F_OK)) - warnf_warning(WC_EXTRA_MAKEFILE, "found additional standard makefile: %s", - default_makefiles[i]); + warnf_confusing(WC_EXTRA_MAKEFILE, + "found additional standard makefile, this be confusing: %s", + default_makefiles[i]); return fd; } diff --git a/mklint.c b/mklint.c index d2414b8..514be21 100644 --- a/mklint.c +++ b/mklint.c @@ -8,7 +8,8 @@ int exit_status = 0; struct style style = { .max_line_length = 120, - .only_empty_blank_lines = 1 + .only_empty_blank_lines = 1, + .macro_bracket_style = ROUND }; @@ -18,7 +19,7 @@ set_line_continuation_joiner(struct line *line) if (line->len && line->data[line->len - 1] == '\\') { line->data[--line->len] = '\0'; /* Doesn't matter here if the first non-white space is # */ - line->continuation_joiner = line->data[0] == '\t' ? '\t' : ' '; + line->continuation_joiner = line->data[0] == '\t' ? '\\' : ' '; } else { line->continuation_joiner = '\0'; } @@ -82,7 +83,6 @@ check_line_continuations(struct line *lines, size_t nlines) } - static enum line_class classify_line(struct line *line) { @@ -92,6 +92,7 @@ classify_line(struct line *line) if (!line->len) return EMPTY; +start_over: s = line->data; while (isspace(*s)) { @@ -99,7 +100,7 @@ classify_line(struct line *line) warned_bad_space = 1; warnf_undefined(WC_LEADING_BAD_SPACE, "%s:%zu: line contains leading white space other than" - " and , which causes undefined behaviour", + " and , which causes undefined behaviour", line->path, line->lineno); /* TODO what do we do here? */ } @@ -117,12 +118,24 @@ classify_line(struct line *line) return COMMENT; } else if (!*s) { + if (line->continuation_joiner) { + line++; + goto start_over; + } return BLANK; } else if (line->data[0] == '\t') { return COMMAND_LINE; } else { + if (*s == '-') { /* We will warn about this later */ + s++; + while (isspace(*s)) + s++; + } + + /* TODO unspecified behaviour if include line with */ + /* TODO unspecified behaviour if continuation that looks like an include line */ return OTHER; } } @@ -178,12 +191,33 @@ main(int argc, char *argv[]) break; case COMMAND_LINE: + /* TODO list may, for historical reasons, end at a comment line; + * note, the specifications specify “comment line” which is + * define to include empty and blank lines; note however + * that a line that begins with a that is prefixed + * by whitespace is not a comment line, so, if it begins + * with followed by zero or more whitespace, and then + * a , it a command line, not a comment line. */ + /* TODO on line continuation, remove first '\t', if any, and join with '\\\n' */ case OTHER: + /* TODO first non-comment line shall be special target .POSIX without + * prerequisites or commands, behaviour is unspecified otherwise */ + /* TODO on line continuation, remove leading white space and join with ' ' */ break; default: abort(); } + + while (lines[i].continuation_joiner) { + if (memchr(lines[i].data, '#', lines[i].len)) { + warnf_confusing(WC_COMMENT_CONTINUATION, + "%s:%zu: using continuation of line to continue " + "a comment on the next line can cause confusion", + lines[i].path, lines[i].lineno); + } + i += 1; + } } free(lines); -- cgit v1.2.3-70-g09d2