port the -ut / -nut options from freebsd. -ut (default) enables tabs

in output, the -nut uses spaces.
This commit is contained in:
mrg 2014-09-04 04:06:07 +00:00
parent 96f3af9446
commit a1ff035944
5 changed files with 70 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: args.c,v 1.10 2009/04/12 11:09:49 lukem Exp $ */
/* $NetBSD: args.c,v 1.11 2014/09/04 04:06:07 mrg Exp $ */
/*
* Copyright (c) 1980, 1993
@ -68,7 +68,7 @@
#if 0
static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: args.c,v 1.10 2009/04/12 11:09:49 lukem Exp $");
__RCSID("$NetBSD: args.c,v 1.11 2014/09/04 04:06:07 mrg Exp $");
#endif
#endif /* not lint */
@ -273,6 +273,9 @@ struct pro {
{
"nsc", PRO_BOOL, true, OFF, &star_comment_cont
},
{
"nut", PRO_BOOL, true, OFF, &use_tabs
},
{
"nsob", PRO_BOOL, false, OFF, &swallow_optional_blanklines
},
@ -300,6 +303,9 @@ struct pro {
{
"troff", PRO_BOOL, false, ON, &troff
},
{
"ut", PRO_BOOL, true, ON, &use_tabs
},
{
"v", PRO_BOOL, false, ON, &verbose
},

View File

@ -1,4 +1,4 @@
.\" $NetBSD: indent.1,v 1.22 2012/10/13 14:18:17 njoly Exp $
.\" $NetBSD: indent.1,v 1.23 2014/09/04 04:06:07 mrg Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -61,7 +61,7 @@
.\"
.\" from: @(#)indent.1 8.1 (Berkeley) 7/1/93
.\"
.Dd July 1, 1993
.Dd September 2, 2014
.Dt INDENT 1
.Os
.Sh NAME
@ -98,6 +98,7 @@
.Op Fl sob | Fl nsob
.Op Fl \&st
.Op Fl troff
.Op Fl ut | Fl nut
.Op Fl v | Fl \&nv
.Sh DESCRIPTION
.Nm
@ -135,6 +136,11 @@ is specified,
checks to make sure it is different from
.Ar input-file .
.Pp
If no
.Ar input-file
is specified
input is read from stdin and the formatted file is written to stdout.
.Pp
The options listed below control the formatting style imposed by
.Nm .
.Bl -tag -width Op
@ -417,6 +423,11 @@ listing in much the same spirit as
.Xr vgrind 1 .
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 `verbose' mode;

View File

@ -1,4 +1,4 @@
/* $NetBSD: indent.c,v 1.18 2009/04/12 11:09:49 lukem Exp $ */
/* $NetBSD: indent.c,v 1.19 2014/09/04 04:06:07 mrg Exp $ */
/*
* Copyright (c) 1980, 1993
@ -75,7 +75,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985 Sun Microsystems, Inc.\
#if 0
static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93";
#else
__RCSID("$NetBSD: indent.c,v 1.18 2009/04/12 11:09:49 lukem Exp $");
__RCSID("$NetBSD: indent.c,v 1.19 2014/09/04 04:06:07 mrg Exp $");
#endif
#endif /* not lint */
@ -123,6 +123,7 @@ main(int argc, char **argv)
* without the matching : in a <c>?<s>:<s>
* construct */
const char *t_ptr; /* used for copying tokens */
int tabs_to_var = 0; /* 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 */
@ -998,6 +999,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 */
@ -1012,11 +1014,44 @@ check_type:
sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);
ps.dumped_decl_indent = 1;
e_code += strlen(e_code);
} else
while ((e_code - s_code) < dec_ind) {
CHECK_SIZE_CODE;
} 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 {
if (dec_ind && s_code != e_code)

View File

@ -1,4 +1,4 @@
/* $NetBSD: indent_globs.h,v 1.9 2009/04/12 11:09:49 lukem Exp $ */
/* $NetBSD: indent_globs.h,v 1.10 2014/09/04 04:06:07 mrg Exp $ */
/*
* Copyright (c) 1980, 1993
@ -222,6 +222,8 @@ EXTERN int extra_expression_indent; /* True if continuation lines from the
* "for(e;e;e)" should be indented an extra
* tab stop so that they don't conflict with
* the code that follows */
EXTERN int use_tabs; /* set true to use tabs for spacing,
* false uses all spaces */
/* -troff font state information */

View File

@ -1,4 +1,4 @@
/* $NetBSD: io.c,v 1.14 2009/04/12 11:09:49 lukem Exp $ */
/* $NetBSD: io.c,v 1.15 2014/09/04 04:06:07 mrg Exp $ */
/*
* Copyright (c) 1980, 1993
@ -68,7 +68,7 @@
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: io.c,v 1.14 2009/04/12 11:09:49 lukem Exp $");
__RCSID("$NetBSD: io.c,v 1.15 2014/09/04 04:06:07 mrg Exp $");
#endif
#endif /* not lint */
@ -516,9 +516,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 */