From 230bb0491dfc8c7495c5d9221e0dd83f981f3a24 Mon Sep 17 00:00:00 2001 From: bde Date: Mon, 9 Feb 2004 21:48:51 +0000 Subject: Added an option -ldi 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. --- usr.bin/indent/indent.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'usr.bin/indent/indent.c') 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 */ -- cgit v1.1