summaryrefslogtreecommitdiffstats
path: root/usr.bin/indent/indent.c
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>2004-02-09 21:48:51 +0000
committerbde <bde@FreeBSD.org>2004-02-09 21:48:51 +0000
commit230bb0491dfc8c7495c5d9221e0dd83f981f3a24 (patch)
tree433a65a96ac9674af5f002fd33f672392a77b318 /usr.bin/indent/indent.c
parentfb0b5ce61d257b76d357e8c73de3a01f08a2d4b7 (diff)
downloadFreeBSD-src-230bb0491dfc8c7495c5d9221e0dd83f981f3a24.zip
FreeBSD-src-230bb0491dfc8c7495c5d9221e0dd83f981f3a24.tar.gz
Added an option -ldi<N> to control indentation of local variable names.
The default is to be backwards compatible and non-KNF (use the same indentation for locals as for globals; -ldi0 gives KNF indentation for locals (none)). The indentation for globals also applies to struct member names in local declatations. The indentation of variable names in multi-line declarations is broken in various ways and this commit gives some new variations. indent.1: Also clarified the description of -di<N>.
Diffstat (limited to 'usr.bin/indent/indent.c')
-rw-r--r--usr.bin/indent/indent.c16
1 files changed, 14 insertions, 2 deletions
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 */
OpenPOWER on IntegriCloud