Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent port the -ut / -nut options from freebsd. -u...



details:   https://anonhg.NetBSD.org/src/rev/7acc7326d08a
branches:  trunk
changeset: 802145:7acc7326d08a
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu Sep 04 04:06:07 2014 +0000

description:
port the -ut / -nut options from freebsd.  -ut (default) enables tabs
in output, the -nut uses spaces.

diffstat:

 usr.bin/indent/args.c         |  10 ++++++++--
 usr.bin/indent/indent.1       |  15 +++++++++++++--
 usr.bin/indent/indent.c       |  43 +++++++++++++++++++++++++++++++++++++++----
 usr.bin/indent/indent_globs.h |   4 +++-
 usr.bin/indent/io.c           |  12 +++++++-----
 5 files changed, 70 insertions(+), 14 deletions(-)

diffs (220 lines):

diff -r e5a70533bf72 -r 7acc7326d08a usr.bin/indent/args.c
--- a/usr.bin/indent/args.c     Thu Sep 04 02:39:41 2014 +0000
+++ b/usr.bin/indent/args.c     Thu Sep 04 04:06:07 2014 +0000
@@ -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 */
 
@@ -274,6 +274,9 @@
                "nsc", PRO_BOOL, true, OFF, &star_comment_cont
        },
        {
+               "nut", PRO_BOOL, true, OFF, &use_tabs
+       },
+       {
                "nsob", PRO_BOOL, false, OFF, &swallow_optional_blanklines
        },
        {
@@ -301,6 +304,9 @@
                "troff", PRO_BOOL, false, ON, &troff
        },
        {
+               "ut", PRO_BOOL, true, ON, &use_tabs
+       },
+       {
                "v", PRO_BOOL, false, ON, &verbose
        },
        /* whew! */
diff -r e5a70533bf72 -r 7acc7326d08a usr.bin/indent/indent.1
--- a/usr.bin/indent/indent.1   Thu Sep 04 02:39:41 2014 +0000
+++ b/usr.bin/indent/indent.1   Thu Sep 04 04:06:07 2014 +0000
@@ -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 @@
 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 @@
 .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;
diff -r e5a70533bf72 -r 7acc7326d08a usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Thu Sep 04 02:39:41 2014 +0000
+++ b/usr.bin/indent/indent.c   Thu Sep 04 04:06:07 2014 +0000
@@ -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 @@
 #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 @@
                                 * 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 @@
                         * : 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 @@
                                                        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)
diff -r e5a70533bf72 -r 7acc7326d08a usr.bin/indent/indent_globs.h
--- a/usr.bin/indent/indent_globs.h     Thu Sep 04 02:39:41 2014 +0000
+++ b/usr.bin/indent/indent_globs.h     Thu Sep 04 04:06:07 2014 +0000
@@ -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 @@
                                         * "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 */
 
diff -r e5a70533bf72 -r 7acc7326d08a usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Thu Sep 04 02:39:41 2014 +0000
+++ b/usr.bin/indent/io.c       Thu Sep 04 04:06:07 2014 +0000
@@ -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 @@
                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 */



Home | Main Index | Thread Index | Old Index