summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.bin/indent/args.c1
-rw-r--r--usr.bin/indent/indent.113
-rw-r--r--usr.bin/indent/indent.c16
-rw-r--r--usr.bin/indent/indent_globs.h1
4 files changed, 27 insertions, 4 deletions
diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c
index a8c4f9f..25078f6 100644
--- a/usr.bin/indent/args.c
+++ b/usr.bin/indent/args.c
@@ -121,6 +121,7 @@ struct pro {
{"ip", PRO_BOOL, true, ON, &ps.indent_parameters},
{"i", PRO_INT, 8, 0, &ps.ind_size},
{"lc", PRO_INT, 0, 0, &block_comment_max_col},
+ {"ldi", PRO_INT, -1, 0, &ps.local_decl_indent},
{"lp", PRO_BOOL, true, ON, &lineup_to_parens},
{"l", PRO_INT, 78, 0, &max_col},
{"nbacc", PRO_BOOL, false, OFF, &blanklines_around_conditional_compilation},
diff --git a/usr.bin/indent/indent.1 b/usr.bin/indent/indent.1
index c0b77ab..1720c99 100644
--- a/usr.bin/indent/indent.1
+++ b/usr.bin/indent/indent.1
@@ -69,6 +69,7 @@
.Op Fl \&ip | Fl nip
.Op Fl l Ns Ar n
.Op Fl \&lc Ns Ar n
+.Op Fl \&ldi Ns Ar n
.Op Fl \&lp | Fl nlp
.Op Fl npro
.Op Fl pcs | Fl npcs
@@ -219,8 +220,10 @@ left of code. Specifying the default
lines-up these comments with the code. See the section on comment
indentation below.
.It Fl \&di Ns Ar n
-Specifies the indentation, in character positions, from a declaration keyword
-to the following identifier. The default is
+Specifies the indentation, in character positions,
+of global variable names and all struct/union member names
+relative to the beginning of their type declaration.
+The default is
.Fl di16 .
.It Fl dj , ndj
.Fl \&dj
@@ -267,6 +270,12 @@ margin. The default is
.Fl \&ip .
.It Fl l Ns Ar n
Maximum length of an output line. The default is 78.
+.It Fl \&ldi Ns Ar n
+Specifies the indentation, in character positions,
+of local variable names
+relative to the beginning of their type declaration.
+The default is for local variable names to be indented
+by the same amount as global ones.
.It Fl \&lp , nlp
Lines-up code surrounded by parenthesis in continuation lines. If a line
has a left paren which is not closed on that line, then continuation lines
diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c
index ba7d463..d75a521 100644
--- a/usr.bin/indent/indent.c
+++ b/usr.bin/indent/indent.c
@@ -168,6 +168,9 @@ main(int argc, char **argv)
ps.ind_size = 8; /* -i8 */
verbose = 0;
ps.decl_indent = 16; /* -di16 */
+ ps.local_decl_indent = -1; /* if this is not set to some nonnegative value
+ * by an arg, we will set this equal to
+ * ps.decl_ind */
ps.indent_parameters = 1; /* -ip */
ps.decl_com_ind = 0; /* if this is not set to some positive value
* by an arg, we will set this equal to
@@ -254,6 +257,8 @@ main(int argc, char **argv)
}
if (block_comment_max_col <= 0)
block_comment_max_col = max_col;
+ if (ps.local_decl_indent < 0) /* if not specified by user, set this */
+ ps.local_decl_indent = ps.decl_indent;
if (ps.decl_com_ind <= 0) /* if not specified by user, set this */
ps.decl_com_ind = ps.ljust_decl ? (ps.com_ind <= 10 ? 2 : ps.com_ind - 8) : ps.com_ind;
if (continuation_indent == 0)
@@ -906,8 +911,15 @@ check_type:
prefix_blankline_requested = 0;
for (i = 0; token[i++];); /* get length of token */
- dec_ind = ps.decl_indent > 0 ? ps.decl_indent : i;
- use_tabs = ps.decl_indent > 0;
+ if (ps.ind_level == 0 || ps.dec_nest > 0) {
+ /* global variable or struct member in local variable */
+ dec_ind = ps.decl_indent > 0 ? ps.decl_indent : i;
+ use_tabs = ps.decl_indent > 0;
+ } else {
+ /* local variable */
+ dec_ind = ps.local_decl_indent > 0 ? ps.local_decl_indent : i;
+ use_tabs = ps.local_decl_indent > 0;
+ }
goto copy_id;
case ident: /* got an identifier or constant */
diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h
index c189bfd..d35900e 100644
--- a/usr.bin/indent/indent_globs.h
+++ b/usr.bin/indent/indent_globs.h
@@ -303,6 +303,7 @@ struct parser_state {
int else_if; /* True iff else if pairs should be handled
* specially */
int decl_indent; /* column to indent declared identifiers to */
+ int local_decl_indent; /* like decl_indent but for locals */
int its_a_keyword;
int sizeof_keyword;
int dumped_decl_indent;
OpenPOWER on IntegriCloud