Module Name:    src
Committed By:   rillig
Date:           Tue Jun  6 05:27:56 UTC 2023

Modified Files:
        src/usr.bin/indent: io.c

Log Message:
indent: condense code for writing tabs

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.200 -r1.201 src/usr.bin/indent/io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.200 src/usr.bin/indent/io.c:1.201
--- src/usr.bin/indent/io.c:1.200	Tue Jun  6 05:11:11 2023
+++ src/usr.bin/indent/io.c	Tue Jun  6 05:27:56 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.200 2023/06/06 05:11:11 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.201 2023/06/06 05:27:56 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.200 2023/06/06 05:11:11 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.201 2023/06/06 05:27:56 rillig Exp $");
 
 #include <stdio.h>
 
@@ -130,13 +130,11 @@ output_indent(int new_ind)
 	int ind = out_ind;
 
 	if (opt.use_tabs) {
-		int tabsize = opt.tabsize;
-		int n = new_ind / tabsize - ind / tabsize;
-		if (n > 0)
-			ind -= ind % tabsize;
-		for (int i = 0; i < n; i++) {
-			fputc('\t', output);
-			ind += tabsize;
+		int n = new_ind / opt.tabsize - ind / opt.tabsize;
+		if (n > 0) {
+			ind = ind - ind % opt.tabsize + n * opt.tabsize;
+			while (n-- > 0)
+				fputc('\t', output);
 			wrote_newlines = 0;
 		}
 	}

Reply via email to