aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2016-12-02 01:25:51 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2016-12-02 01:25:51 +0000
commitf171328eaa687c70bb9a4110761fdf8bc9f6ad20 (patch)
treebd3df11c340b6d5e63878d96acde0bdec90d4037 /usr.bin
parent28db0a5e740c9929ce560572efee40099428a246 (diff)
downloadsrc-f171328eaa687c70bb9a4110761fdf8bc9f6ad20.tar.gz
src-f171328eaa687c70bb9a4110761fdf8bc9f6ad20.zip
indent(1): Fix indent's confusion about custom FreeBSD macros.
Teach indent(1) about storage-class specifiers. Don't assume "in_parameter_declaration" state if "in_decl" hasn't been set. Don't set "in_decl" for storage-class specifiers. That set of changes helps with recognizing the difference between file scope declarations like this: static LIST_HEAD(, alq) ald_active; static int ald_shuttingdown = 0; struct thread *ald_thread; and old style function declarators like this: static int do_execve(td, args, mac_p) struct thread *td; struct image_args *args; struct mac *mac_p; { Unfortunately, at the same time this change makes indent(1) require explicit int in declarations like "static a;", in order to understand that it's part of a declaration. On the other hand, declarations like in the first example are no longer indented as if ald_shuttingdown and ald_thread were parameters of a function named LIST_HEAD. Submitted by: Piotr Stefaniak
Notes
Notes: svn path=/head/; revision=309380
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/indent/indent.c7
-rw-r--r--usr.bin/indent/indent_codes.h1
-rw-r--r--usr.bin/indent/lexi.c15
3 files changed, 16 insertions, 7 deletions
diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c
index 5bcef2793220..1b0506aed9f3 100644
--- a/usr.bin/indent/indent.c
+++ b/usr.bin/indent/indent.c
@@ -920,8 +920,11 @@ check_type:
}
goto copy_id; /* move the token into line */
- case decl: /* we have a declaration type (int, register,
- * etc.) */
+ case storage:
+ prefix_blankline_requested = 0;
+ goto copy_id;
+
+ case decl: /* we have a declaration type (int, etc.) */
parse(decl); /* let parser worry about indentation */
if (ps.last_token == rparen && ps.tos <= 1) {
ps.in_parameter_declaration = 1;
diff --git a/usr.bin/indent/indent_codes.h b/usr.bin/indent/indent_codes.h
index db5b325f7a63..54fdc821b64f 100644
--- a/usr.bin/indent/indent_codes.h
+++ b/usr.bin/indent/indent_codes.h
@@ -69,3 +69,4 @@
#define elsehead 31
#define period 32
#define strpfx 33
+#define storage 34
diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c
index 14de65acd5a6..ec5996931eec 100644
--- a/usr.bin/indent/lexi.c
+++ b/usr.bin/indent/lexi.c
@@ -70,6 +70,7 @@ struct templ {
*/
struct templ specials[] =
{
+ {"auto", 10},
{"break", 9},
{"case", 8},
{"char", 4},
@@ -79,7 +80,7 @@ struct templ specials[] =
{"double", 4},
{"else", 6},
{"enum", 3},
- {"extern", 4},
+ {"extern", 10},
{"float", 4},
{"for", 5},
{"global", 4},
@@ -88,14 +89,14 @@ struct templ specials[] =
{"int", 4},
{"long", 4},
{"offsetof", 1},
- {"register", 4},
+ {"register", 10},
{"return", 9},
{"short", 4},
{"sizeof", 2},
- {"static", 4},
+ {"static", 10},
{"struct", 3},
{"switch", 7},
- {"typedef", 4},
+ {"typedef", 10},
{"union", 3},
{"unsigned", 4},
{"void", 4},
@@ -312,6 +313,9 @@ lexi(void)
case 6: /* do, else */
return (sp_nparen);
+ case 10: /* storage class specifier */
+ return (storage);
+
default: /* all others are treated like any other
* identifier */
return (ident);
@@ -323,7 +327,8 @@ lexi(void)
if (*tp++ == ')' && (*tp == ';' || *tp == ','))
goto not_proc;
strncpy(ps.procname, token, sizeof ps.procname - 1);
- ps.in_parameter_declaration = 1;
+ if (ps.in_decl)
+ ps.in_parameter_declaration = 1;
rparen_count = 1;
not_proc:;
}