Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/indent indent: condense code for writing tabs



details:   https://anonhg.NetBSD.org/src/rev/5cdd452a9aca
branches:  trunk
changeset: 376247:5cdd452a9aca
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Jun 06 05:27:56 2023 +0000

description:
indent: condense code for writing tabs

No functional change.

diffstat:

 usr.bin/indent/io.c |  16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

diffs (37 lines):

diff -r 2011622382ed -r 5cdd452a9aca usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Tue Jun 06 05:11:11 2023 +0000
+++ b/usr.bin/indent/io.c       Tue Jun 06 05:27:56 2023 +0000
@@ -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;
                }
        }



Home | Main Index | Thread Index | Old Index