Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Jul 2017 17:04:35 +0000 (UTC)
From:      Piotr Pawel Stefaniak <pstef@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r321487 - head/usr.bin/indent
Message-ID:  <201707251704.v6PH4ZLP090923@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pstef
Date: Tue Jul 25 17:04:35 2017
New Revision: 321487
URL: https://svnweb.freebsd.org/changeset/base/321487

Log:
  indent(1): add option -tsn for setting tab size.

Modified:
  head/usr.bin/indent/args.c
  head/usr.bin/indent/indent.1
  head/usr.bin/indent/indent.c
  head/usr.bin/indent/indent_globs.h
  head/usr.bin/indent/io.c
  head/usr.bin/indent/pr_comment.c

Modified: head/usr.bin/indent/args.c
==============================================================================
--- head/usr.bin/indent/args.c	Tue Jul 25 16:57:25 2017	(r321486)
+++ head/usr.bin/indent/args.c	Tue Jul 25 17:04:35 2017	(r321487)
@@ -166,6 +166,7 @@ struct pro {
     {"sob", PRO_BOOL, false, ON, &swallow_optional_blanklines},
     {"st", PRO_SPECIAL, 0, STDIN, 0},
     {"ta", PRO_BOOL, false, ON, &auto_typedefs},
+    {"ts", PRO_INT, 8, 0, &tabsize},
     {"troff", PRO_BOOL, false, ON, &troff},
     {"ut", PRO_BOOL, true, ON, &use_tabs},
     {"v", PRO_BOOL, false, ON, &verbose},

Modified: head/usr.bin/indent/indent.1
==============================================================================
--- head/usr.bin/indent/indent.1	Tue Jul 25 16:57:25 2017	(r321486)
+++ head/usr.bin/indent/indent.1	Tue Jul 25 17:04:35 2017	(r321487)
@@ -30,7 +30,7 @@
 .\"	@(#)indent.1	8.1 (Berkeley) 7/1/93
 .\" $FreeBSD$
 .\"
-.Dd January 2, 2017
+.Dd July 25, 2017
 .Dt INDENT 1
 .Os
 .Sh NAME
@@ -85,6 +85,7 @@
 .Op Fl \&st
 .Op Fl \&ta
 .Op Fl troff
+.Op Fl ts Ns Ar n
 .Op Fl U Ns Ar file
 .Op Fl ut | Fl nut
 .Op Fl v | Fl \&nv
@@ -459,13 +460,15 @@ 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 ts Ns Ar n
+Assumed distance between tab stops.
+The default is 8.
 .It Fl U Ns Ar file
 Adds type names from
 .Ar file
 to the list of type keywords.
 .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

Modified: head/usr.bin/indent/indent.c
==============================================================================
--- head/usr.bin/indent/indent.c	Tue Jul 25 16:57:25 2017	(r321486)
+++ head/usr.bin/indent/indent.c	Tue Jul 25 17:04:35 2017	(r321487)
@@ -292,7 +292,7 @@ main(int argc, char **argv)
 	    if (*p == ' ')
 		col++;
 	    else if (*p == '\t')
-		col = ((col - 1) & ~7) + 9;
+		col = tabsize * (1 + (col - 1) / tabsize) + 1;
 	    else
 		break;
 	    p++;
@@ -1050,7 +1050,7 @@ check_type:
 	    if (ps.p_l_follow == 0) {
 		if (ps.block_init_level <= 0)
 		    ps.block_init = 0;
-		if (break_comma && (!ps.leave_comma || compute_code_target() + (e_code - s_code) > max_col - 8))
+		if (break_comma && (!ps.leave_comma || compute_code_target() + (e_code - s_code) > max_col - tabsize))
 		    force_nl = true;
 	    }
 	    break;
@@ -1267,18 +1267,21 @@ indent_declaration(int cur_dec_ind, int tabs_to_var)
     char *startpos = e_code;
 
     /*
-     * get the tab math right for indentations that are not multiples of 8
+     * get the tab math right for indentations that are not multiples of tabsize
      */
-    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 ((ps.ind_level * ps.ind_size) % tabsize != 0) {
+	pos += (ps.ind_level * ps.ind_size) % tabsize;
+	cur_dec_ind += (ps.ind_level * ps.ind_size) % tabsize;
     }
-    if (tabs_to_var)
-	while ((pos & ~7) + 8 <= cur_dec_ind) {
+    if (tabs_to_var) {
+	int tpos;
+
+	while ((tpos = tabsize * (1 + pos / tabsize)) <= cur_dec_ind) {
 	    CHECK_SIZE_CODE;
 	    *e_code++ = '\t';
-	    pos = (pos & ~7) + 8;
+	    pos = tpos;
 	}
+    }
     while (pos < cur_dec_ind) {
 	CHECK_SIZE_CODE;
 	*e_code++ = ' ';

Modified: head/usr.bin/indent/indent_globs.h
==============================================================================
--- head/usr.bin/indent/indent_globs.h	Tue Jul 25 16:57:25 2017	(r321486)
+++ head/usr.bin/indent/indent_globs.h	Tue Jul 25 17:04:35 2017	(r321487)
@@ -42,11 +42,7 @@
 #define label_offset 2		/* number of levels a label is placed to left
 				 * of code */
 
-#define tabsize 8		/* the size of a tab */
-#define tabmask 0177770		/* mask used when figuring length of lines
-				 * with tabs */
 
-
 #define false 0
 #define true  1
 
@@ -213,6 +209,7 @@ int	    use_tabs;			/* set true to use tabs for spacin
 int	    auto_typedefs;		/* set true to recognize identifiers
 					 * ending in "_t" like typedefs */
 int	    space_after_cast;		/* "b = (int) a" vs "b = (int)a" */
+int	    tabsize;			/* the size of a tab */
 
 /* -troff font state information */
 

Modified: head/usr.bin/indent/io.c
==============================================================================
--- head/usr.bin/indent/io.c	Tue Jul 25 16:57:25 2017	(r321486)
+++ head/usr.bin/indent/io.c	Tue Jul 25 17:04:35 2017	(r321487)
@@ -227,12 +227,12 @@ dump_line(void)
 		target += ps.comment_delta;
 		while (*com_st == '\t')	/* consider original indentation in
 					 * case this is a box comment */
-		    com_st++, target += 8;
+		    com_st++, target += tabsize;
 		while (target <= 0)
 		    if (*com_st == ' ')
 			target++, com_st++;
 		    else if (*com_st == '\t')
-			target = ((target - 1) & ~7) + 9, com_st++;
+			target = tabsize * (1 + (target - 1) / tabsize) + 1, com_st++;
 		    else
 			target = 1;
 		if (cur_col > target) {	/* if comment can't fit on this line,
@@ -458,17 +458,19 @@ pad_output(int current, int target)
     /* current: the current column value */
     /* target: position we want it at */
 {
-    int curr;		/* internal column pointer */
-    int tcur;
 
     if (troff)
 	fprintf(output, "\\h'|%dp'", (target - 1) * 7);
     else {
+	int curr;		/* internal column pointer */
+
 	if (current >= target)
 	    return (current);	/* line is already long enough */
 	curr = current;
         if (use_tabs) {
-            while ((tcur = ((curr - 1) & tabmask) + tabsize + 1) <= target) {
+	    int tcur;
+
+	    while ((tcur = tabsize * (1 + (curr - 1) / tabsize) + 1) <= target) {
                 putc('\t', output);
                 curr = tcur;
             }
@@ -517,7 +519,7 @@ count_spaces_until(int cur, char *buffer, char *end)
 	    break;
 
 	case '\t':
-	    cur = ((cur - 1) & tabmask) + tabsize + 1;
+	    cur = tabsize * (1 + (cur - 1) / tabsize) + 1;
 	    break;
 
 	case 010:		/* backspace */

Modified: head/usr.bin/indent/pr_comment.c
==============================================================================
--- head/usr.bin/indent/pr_comment.c	Tue Jul 25 16:57:25 2017	(r321486)
+++ head/usr.bin/indent/pr_comment.c	Tue Jul 25 17:04:35 2017	(r321487)
@@ -142,7 +142,7 @@ pr_comment(void)
 	    }
 	    ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? ps.decl_com_ind : ps.com_ind;
 	    if (ps.com_col <= target_col)
-		ps.com_col = ((target_col + 7) & ~7) + 1;
+		ps.com_col = tabsize * (1 + (target_col - 1) / tabsize) + 1;
 	    if (ps.com_col + 24 > adj_max_col)
 		adj_max_col = ps.com_col + 24;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707251704.v6PH4ZLP090923>