The following adds ut/nut flags to indent to enable/disable
tabs which seems to have originated in gnu indent. 

-nut seems to have quite a bit of usage and is currently
assumed in the Mesa3D build when generating code.

Diff based on FreeBSD svn rev 131184.

Unrelated to this diff there seems to be a problem with
indent when run on code like

{
<tab>int a;
}

the result is:

{
<tab>int <tab><tab>a;
}

This behaviour is present without the diff and isn't
addressed here.

Index: args.c
===================================================================
RCS file: /cvs/src/usr.bin/indent/args.c,v
retrieving revision 1.15
diff -u -p -r1.15 args.c
--- args.c      27 Oct 2009 23:59:39 -0000      1.15
+++ args.c      8 Apr 2013 13:27:58 -0000
@@ -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 }
Index: indent.1
===================================================================
RCS file: /cvs/src/usr.bin/indent/indent.1,v
retrieving revision 1.20
diff -u -p -r1.20 indent.1
--- indent.1    17 Jan 2013 21:29:14 -0000      1.20
+++ indent.1    8 Apr 2013 13:28:15 -0000
@@ -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 
 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
Index: indent.c
===================================================================
RCS file: /cvs/src/usr.bin/indent/indent.c,v
retrieving revision 1.20
diff -u -p -r1.20 indent.c
--- indent.c    27 Oct 2009 23:59:39 -0000      1.20
+++ indent.c    8 Apr 2013 13:31:06 -0000
@@ -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 {
Index: indent_globs.h
===================================================================
RCS file: /cvs/src/usr.bin/indent/indent_globs.h,v
retrieving revision 1.10
diff -u -p -r1.10 indent_globs.h
--- indent_globs.h      25 Jun 2003 21:24:53 -0000      1.10
+++ indent_globs.h      8 Apr 2013 13:27:22 -0000
@@ -198,6 +198,8 @@ int         extra_expression_indent;        /* 
                                         * 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 */
 
Index: io.c
===================================================================
RCS file: /cvs/src/usr.bin/indent/io.c,v
retrieving revision 1.11
diff -u -p -r1.11 io.c
--- io.c        27 Oct 2009 23:59:39 -0000      1.11
+++ io.c        8 Apr 2013 13:39:27 -0000
@@ -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 */

Reply via email to