Module Name: src
Committed By: rillig
Date: Sat Nov 27 20:58:16 UTC 2021
Modified Files:
src/usr.bin/indent: lexi.c
Log Message:
indent: illustrate probably_looking_at_definition with examples
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/usr.bin/indent/lexi.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.165 src/usr.bin/indent/lexi.c:1.166
--- src/usr.bin/indent/lexi.c:1.165 Sat Nov 27 20:33:39 2021
+++ src/usr.bin/indent/lexi.c Sat Nov 27 20:58:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.165 2021/11/27 20:33:39 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.166 2021/11/27 20:58:16 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 (
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.165 2021/11/27 20:33:39 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.166 2021/11/27 20:58:16 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
#endif
@@ -451,7 +451,7 @@ cmp_keyword_by_name(const void *key, con
}
/*
- * Looking at a line starting with 'function_name(something)', guess whether
+ * Looking at something like 'function_name(...)' in a line, guess whether
* this starts a function definition or a declaration.
*/
static bool
@@ -463,14 +463,20 @@ probably_looking_at_definition(void)
paren_level++;
if (*p == ')' && --paren_level == 0) {
p++;
+
while (p < e && (ch_isspace(*p) || is_identifier_part(*p)))
- p++;
- if (p < e && (*p == ';' || *p == ','))
+ p++; /* '__dead' or '__unused' */
+
+ if (p == e) /* func(...) */
+ break;
+ if (*p == ';') /* func(...); */
return false;
- if (p < e && *p == '(')
- paren_level++;
+ if (*p == ',') /* double abs(), pi; */
+ return false;
+ if (*p == '(') /* func(...) __attribute__((...)) */
+ paren_level++; /* func(...) __printflike(...) */
else
- break;
+ break; /* func(...) { ... */
}
}