summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2019-05-19 19:45:13 +0000
committerTom Lane2019-05-19 19:45:13 +0000
commitcc7924c81b92f227bd074b7626fc84e54f5b9e2e (patch)
treec16df142683bb19ab161adf2fad09902c3930af7
parent8d0b0495a4818abfccc4decfdcba016229dba3fd (diff)
Rip out -kr/-nkr switches again.
The upstream maintainer doesn't want these, so drop 'em. Also, teach is_func_definition() about //-style comments. The main lexi.c code doesn't know about those either, but I assume somebody will wish to fix that at some point.
-rw-r--r--args.c2
-rw-r--r--indent.113
-rw-r--r--indent.c1
-rw-r--r--indent_globs.h2
-rw-r--r--lexi.c44
-rw-r--r--tests/declarations.08
-rw-r--r--tests/declarations.0.stdout8
-rw-r--r--tests/list_head.07
-rw-r--r--tests/list_head.0.stdout7
9 files changed, 33 insertions, 59 deletions
diff --git a/args.c b/args.c
index a93d335..1850542 100644
--- a/args.c
+++ b/args.c
@@ -125,7 +125,6 @@ struct pro {
{"fcb", PRO_BOOL, true, ON, &format_block_comments},
{"ip", PRO_BOOL, true, ON, &ps.indent_parameters},
{"i", PRO_INT, 8, 0, &ps.ind_size},
- {"kr", PRO_BOOL, true, ON, &knr_function_style},
{"lc", PRO_INT, 0, 0, &block_comment_max_col},
{"ldi", PRO_INT, -1, 0, &ps.local_decl_indent},
{"lpl", PRO_BOOL, false, ON, &lineup_to_parens_always},
@@ -147,7 +146,6 @@ struct pro {
{"nfc1", PRO_BOOL, true, OFF, &format_col1_comments},
{"nfcb", PRO_BOOL, true, OFF, &format_block_comments},
{"nip", PRO_BOOL, true, OFF, &ps.indent_parameters},
- {"nkr", PRO_BOOL, true, OFF, &knr_function_style},
{"nlpl", PRO_BOOL, false, OFF, &lineup_to_parens_always},
{"nlp", PRO_BOOL, true, OFF, &lineup_to_parens},
{"npcs", PRO_BOOL, false, OFF, &proc_calls_space},
diff --git a/indent.1 b/indent.1
index a92adb4..131abfe 100644
--- a/indent.1
+++ b/indent.1
@@ -70,7 +70,6 @@
.Ek
.Op Fl i Ns Ar n
.Op Fl \&ip | Fl nip
-.Op Fl kr | Fl nkr
.Op Fl l Ns Ar n
.Op Fl \&lc Ns Ar n
.Op Fl \&ldi Ns Ar n
@@ -346,18 +345,6 @@ Enables (disables) the indentation of parameter declarations from the left
margin.
The default is
.Fl \&ip .
-.It Fl kr , nkr
-If
-.Fl kr
-is specified, assume text following a possible function declaration
-is parameter declaration(s) as in Kernighan-and-Ritchie C; that is,
-the presence of such text means it's a function definition.
-If
-.Fl nkr
-is specified, assume such text is an attribute declaration,
-as in modern C.
-Default:
-.Fl kr .
.It Fl l Ns Ar n
Maximum length of an output line.
The default is 78.
diff --git a/indent.c b/indent.c
index 4c9a5f7..9faf57a 100644
--- a/indent.c
+++ b/indent.c
@@ -173,7 +173,6 @@ main(int argc, char **argv)
ps.case_indent = 0; /* -cli0 */
format_block_comments = 1; /* -fcb */
format_col1_comments = 1; /* -fc1 */
- knr_function_style = 1; /* -kr */
procnames_start_line = 1; /* -psl */
proc_calls_space = 0; /* -npcs */
comment_delimiter_on_blankline = 1; /* -cdb */
diff --git a/indent_globs.h b/indent_globs.h
index 9feb362..d018af1 100644
--- a/indent_globs.h
+++ b/indent_globs.h
@@ -219,8 +219,6 @@ int use_tabs; /* set true to use tabs for spacing,
* false uses all spaces */
int auto_typedefs; /* set true to recognize identifiers
* ending in "_t" like typedefs */
-int knr_function_style; /* assume stuff after int foo(...)
- * is K&R-style param declarations */
int space_after_cast; /* "b = (int) a" vs "b = (int)a" */
int postgres_tab_rules; /* use Postgres tab-vs-space rules */
int tabsize; /* the size of a tab */
diff --git a/lexi.c b/lexi.c
index 7279fa0..d43723c 100644
--- a/lexi.c
+++ b/lexi.c
@@ -150,26 +150,22 @@ strcmp_type(const void *e1, const void *e2)
/*
* Decide whether "foo(..." is a function definition or declaration.
- * At call, we are looking at the '('. Look ahead past the argument(s)
- * to the matching ')'. Then:
*
- * In knr_function_style mode, if the next non-whitespace character
- * is ';' or ',', it's a declaration; otherwise it's a definition.
- * (This mode is fooled by function attributes, which look too much
- * like a K&R-style parameter declaration.)
- *
- * In non-K&R mode, keep scanning until we find '{', ';' or ',' not
- * within parentheses; then it's a definition if we found '{', otherwise a
- * declaration. (This mode is fooled by K&R-style parameter declarations.)
- *
- * We ignore whitespace and comments in either mode. (The current
- * coding does not handle // comments, but that could be fixed.)
+ * At call, we are looking at the '('. Look ahead to find the first
+ * '{', ';' or ',' that is not within parentheses or comments; then
+ * it's a definition if we found '{', otherwise a declaration.
+ * Note that this rule is fooled by K&R-style parameter declarations,
+ * but telling the difference between those and function attributes
+ * seems like more trouble than it's worth. This code could also be
+ * fooled by mismatched parens or apparent comment starts within string
+ * literals, but that seems unlikely in the context it's used in.
*/
static int
is_func_definition(char *tp)
{
int paren_depth = 0;
int in_comment = false;
+ int in_slash_comment = false;
int lastc = 0;
/* We may need to look past the end of the current buffer. */
@@ -189,8 +185,13 @@ is_func_definition(char *tp)
if (in_comment) {
if (lastc == '*' && c == '/')
in_comment = false;
- } else if (lastc == '/' && c == '*')
+ } else if (lastc == '/' && c == '*' && !in_slash_comment)
in_comment = true;
+ else if (in_slash_comment) {
+ if (c == '\n')
+ in_slash_comment = false;
+ } else if (lastc == '/' && c == '/')
+ in_slash_comment = true;
/* Count nested parens properly. */
else if (c == '(')
paren_depth++;
@@ -204,17 +205,10 @@ is_func_definition(char *tp)
return false;
} else if (paren_depth == 0) {
/* We are outside any parentheses or comments. */
- if (knr_function_style) {
- /* First nonblank determines it. */
- if (!isspace((unsigned char) c))
- return !(c == ';' || c == ',');
- } else {
- /* In this mode, we scan till we find definitive punctuation. */
- if (c == '{')
- return true;
- else if (c == ';' || c == ',')
- return false;
- }
+ if (c == '{')
+ return true;
+ else if (c == ';' || c == ',')
+ return false;
}
lastc = c;
}
diff --git a/tests/declarations.0 b/tests/declarations.0
index 6d668b1..8419494 100644
--- a/tests/declarations.0
+++ b/tests/declarations.0
@@ -70,10 +70,10 @@ static int ald_shutingdown = 0;
struct thread *ald_thread;
static int
-do_execve(td, args, mac_p)
- struct thread *td;
- struct image_args *args;
- struct mac *mac_p;
+do_execve(
+struct thread *td,
+struct image_args *args,
+struct mac *mac_p)
{
}
diff --git a/tests/declarations.0.stdout b/tests/declarations.0.stdout
index e97e447..ab5a447 100644
--- a/tests/declarations.0.stdout
+++ b/tests/declarations.0.stdout
@@ -64,10 +64,10 @@ static int ald_shutingdown = 0;
struct thread *ald_thread;
static int
-do_execve(td, args, mac_p)
- struct thread *td;
- struct image_args *args;
- struct mac *mac_p;
+do_execve(
+ struct thread *td,
+ struct image_args *args,
+ struct mac *mac_p)
{
}
diff --git a/tests/list_head.0 b/tests/list_head.0
index 3a186ca..35874eb 100644
--- a/tests/list_head.0
+++ b/tests/list_head.0
@@ -1,10 +1,9 @@
/* $FreeBSD$ */
/* See r309380 */
static int
-do_execve(td, args, mac_p)
- struct thread *td;
- struct image_args *args;
- struct mac *mac_p;
+do_execve(struct thread *td,
+struct image_args *args,
+struct mac *mac_p)
{
}
diff --git a/tests/list_head.0.stdout b/tests/list_head.0.stdout
index b6f0762..2ebcca5 100644
--- a/tests/list_head.0.stdout
+++ b/tests/list_head.0.stdout
@@ -1,10 +1,9 @@
/* $FreeBSD$ */
/* See r309380 */
static int
-do_execve(td, args, mac_p)
- struct thread *td;
- struct image_args *args;
- struct mac *mac_p;
+do_execve(struct thread *td,
+ struct image_args *args,
+ struct mac *mac_p)
{
}