summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/indent/args.c4
-rw-r--r--usr.bin/indent/indent.110
-rw-r--r--usr.bin/indent/indent.c41
-rw-r--r--usr.bin/indent/indent_globs.h4
-rw-r--r--usr.bin/indent/io.c10
5 files changed, 57 insertions, 12 deletions
diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c
index 845a22fad07..ced5cec0c81 100644
--- a/usr.bin/indent/args.c
+++ b/usr.bin/indent/args.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: args.c,v 1.15 2009/10/27 23:59:39 deraadt Exp $ */
+/* $OpenBSD: args.c,v 1.16 2013/06/20 06:28:15 jsg Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -135,6 +135,7 @@ struct pro {
{"nps", PRO_BOOL, false, OFF, &pointer_as_binop },
{"nsc", PRO_BOOL, true, OFF, &star_comment_cont },
{"nsob", PRO_BOOL, false, OFF, &swallow_optional_blanklines },
+ {"nut", PRO_BOOL, true, OFF, &use_tabs},
{"nv", PRO_BOOL, false, OFF, &verbose },
{"pcs", PRO_BOOL, false, ON, &proc_calls_space },
{"psl", PRO_BOOL, true, ON, &procnames_start_line },
@@ -143,6 +144,7 @@ struct pro {
{"sob", PRO_BOOL, false, ON, &swallow_optional_blanklines },
{"st", PRO_SPECIAL, 0, STDIN, 0 },
{"troff", PRO_BOOL, false, ON, &troff },
+ {"ut", PRO_BOOL, true, ON, &use_tabs},
{"v", PRO_BOOL, false, ON, &verbose },
/* whew! */
{ 0, 0, 0, 0, 0 }
diff --git a/usr.bin/indent/indent.1 b/usr.bin/indent/indent.1
index 3f2b824506a..628ae6a608e 100644
--- a/usr.bin/indent/indent.1
+++ b/usr.bin/indent/indent.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: indent.1,v 1.20 2013/01/17 21:29:14 jmc Exp $
+.\" $OpenBSD: indent.1,v 1.21 2013/06/20 06:28:15 jsg Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California.
@@ -32,7 +32,7 @@
.\"
.\" from: @(#)indent.1 8.1 (Berkeley) 7/1/93
.\"
-.Dd $Mdocdate: January 17 2013 $
+.Dd $Mdocdate: June 20 2013 $
.Dt INDENT 1
.Os
.Sh NAME
@@ -71,6 +71,7 @@
.Op Fl \&st
.Op Fl T Ns Ar typename
.Op Fl troff
+.Op Fl ut | Fl nut
.Op Fl v | \&nv
.Ek
.Sh DESCRIPTION
@@ -384,6 +385,11 @@ to format the program for processing by troff,
producing a fancy listing.
If the output file is not specified, the default is standard output,
rather than formatting in place.
+.It Fl ut , nut
+Enables (disables) the use of tab characters in the output.
+Tabs are assumed to be aligned on columns divisible by 8.
+The default is
+.Fl ut .
.It Fl v , \&nv
.Fl v
turns on
diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c
index 2839a2c00dd..9af962af1a4 100644
--- a/usr.bin/indent/indent.c
+++ b/usr.bin/indent/indent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: indent.c,v 1.20 2009/10/27 23:59:39 deraadt Exp $ */
+/* $OpenBSD: indent.c,v 1.21 2013/06/20 06:28:15 jsg Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -73,6 +73,7 @@ main(int argc, char **argv)
* without the matching : in a <c>?<s>:<s>
* construct */
char *t_ptr; /* used for copying tokens */
+ int tabs_to_var; /* true if using tabs to indent to var name */
int type_code; /* the type of token, returned by lexi */
int last_else = 0; /* true iff last keyword was an else */
@@ -891,6 +892,7 @@ check_type:
* : i);
*/
dec_ind = ps.decl_indent > 0 ? ps.decl_indent : i;
+ tabs_to_var = (use_tabs ? ps.decl_indent > 0 : 0);
goto copy_id;
case ident: /* got an identifier or constant */
@@ -907,12 +909,43 @@ check_type:
ps.dumped_decl_indent = 1;
e_code += strlen(e_code);
CHECK_SIZE_CODE;
- }
- else
- while ((e_code - s_code) < dec_ind) {
+ } else {
+ int cur_dec_ind;
+ int pos, startpos;
+
+ /*
+ * in order to get the tab math right for
+ * indentations that are not multiples of 8 we
+ * need to modify both startpos and dec_ind
+ * (cur_dec_ind) here by eight minus the
+ * remainder of the current starting column
+ * divided by eight. This seems to be a
+ * properly working fix
+ */
+ startpos = e_code - s_code;
+ cur_dec_ind = dec_ind;
+ pos = startpos;
+ if ((ps.ind_level * ps.ind_size) % 8 != 0) {
+ pos += (ps.ind_level * ps.ind_size) % 8;
+ cur_dec_ind += (ps.ind_level * ps.ind_size) % 8;
+ }
+
+ if (tabs_to_var) {
+ while ((pos & ~7) + 8 <= cur_dec_ind) {
+ CHECK_SIZE_CODE;
+ *e_code++ = '\t';
+ pos = (pos & ~7) + 8;
+ }
+ }
+ while (pos < cur_dec_ind) {
CHECK_SIZE_CODE;
*e_code++ = ' ';
+ pos++;
}
+ if (ps.want_blank && e_code - s_code == startpos)
+ *e_code++ = ' ';
+ ps.want_blank = false;
+ }
}
}
else {
diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h
index c04ae46faff..079ea0b32db 100644
--- a/usr.bin/indent/indent_globs.h
+++ b/usr.bin/indent/indent_globs.h
@@ -1,4 +1,4 @@
-/* * $OpenBSD: indent_globs.h,v 1.10 2003/06/25 21:24:53 deraadt Exp $*/
+/* * $OpenBSD: indent_globs.h,v 1.11 2013/06/20 06:28:15 jsg Exp $*/
/*
* Copyright (c) 1985 Sun Microsystems, Inc.
* Copyright (c) 1980, 1993
@@ -198,6 +198,8 @@ int extra_expression_indent; /* True if continuation lines from the
* indented an extra tab stop so that
* they don't conflict with the code
* that follows */
+int use_tabs; /* set true to use tabs for spacing,
+ * false uses all spaces */
/* -troff font state information */
diff --git a/usr.bin/indent/io.c b/usr.bin/indent/io.c
index ec283086703..45139bffbff 100644
--- a/usr.bin/indent/io.c
+++ b/usr.bin/indent/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.11 2009/10/27 23:59:39 deraadt Exp $ */
+/* $OpenBSD: io.c,v 1.12 2013/06/20 06:28:15 jsg Exp $ */
/*
* Copyright (c) 1985 Sun Microsystems, Inc.
@@ -458,9 +458,11 @@ pad_output(int current, int target)
if (current >= target)
return (current); /* line is already long enough */
curr = current;
- while ((tcur = ((curr - 1) & tabmask) + tabsize + 1) <= target) {
- putc('\t', output);
- curr = tcur;
+ if (use_tabs) {
+ while ((tcur = ((curr - 1) & tabmask) + tabsize + 1) <= target) {
+ putc('\t', output);
+ curr = tcur;
+ }
}
while (curr++ < target)
putc(' ', output); /* pad with final blanks */