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: replace column computation with inden...
details: https://anonhg.NetBSD.org/src/rev/9ad90ad30f2b
branches: trunk
changeset: 953567:9ad90ad30f2b
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Mar 13 10:20:54 2021 +0000
description:
indent: replace column computation with indentation computation
No functional change.
diffstat:
usr.bin/indent/indent.h | 6 +++-
usr.bin/indent/io.c | 60 ++++++++++++++++++++++--------------------------
2 files changed, 32 insertions(+), 34 deletions(-)
diffs (114 lines):
diff -r 3148aeda9ee9 -r 9ad90ad30f2b usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Sat Mar 13 10:06:47 2021 +0000
+++ b/usr.bin/indent/indent.h Sat Mar 13 10:20:54 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.11 2021/03/13 10:06:47 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.12 2021/03/13 10:20:54 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,7 +30,7 @@
#if 0
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.h,v 1.11 2021/03/13 10:06:47 rillig Exp $");
+__RCSID("$NetBSD: indent.h,v 1.12 2021/03/13 10:20:54 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $");
#endif
@@ -49,6 +49,8 @@
int compute_label_indent(void);
int count_spaces(int, const char *);
int count_spaces_until(int, const char *, const char *);
+int indentation_after_range(int, const char *, const char *);
+int indentation_after(int, const char *);
void init_constant_tt(void);
#ifdef debug
void debug_vis_range(const char *, const char *, const char *, const char *);
diff -r 3148aeda9ee9 -r 9ad90ad30f2b usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Sat Mar 13 10:06:47 2021 +0000
+++ b/usr.bin/indent/io.c Sat Mar 13 10:20:54 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.39 2021/03/13 10:06:47 rillig Exp $ */
+/* $NetBSD: io.c,v 1.40 2021/03/13 10:20:54 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
#include <sys/cdefs.h>
#ifndef lint
#if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.39 2021/03/13 10:06:47 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.40 2021/03/13 10:20:54 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -425,42 +425,38 @@
}
}
-/*
- * Copyright (C) 1976 by the Board of Trustees of the University of Illinois
- *
- * All rights reserved
- */
int
-count_spaces_until(int col, const char *buffer, const char *end)
+indentation_after_range(int ind, const char *start, const char *end)
{
- for (const char *p = buffer; *p != '\0' && p != end; ++p) {
- switch (*p) {
-
- case '\n':
- case 014: /* form feed */
- col = 1;
- break;
-
- case '\t':
- col = 1 + opt.tabsize * ((col - 1) / opt.tabsize + 1);
- break;
-
- case 010: /* backspace */
- --col;
- break;
-
- default:
- ++col;
- break;
- } /* end of switch */
- } /* end of for loop */
- return col;
+ for (const char *p = start; *p != '\0' && p != end; ++p) {
+ if (*p == '\n' || *p == '\f')
+ ind = 0;
+ else if (*p == '\t')
+ ind = opt.tabsize * (ind / opt.tabsize + 1);
+ else if (*p == '\b')
+ --ind;
+ else
+ ++ind;
+ }
+ return ind;
}
int
-count_spaces(int col, const char *buffer)
+indentation_after(int ind, const char *s)
+{
+ return indentation_after_range(ind, s, NULL);
+}
+
+int
+count_spaces_until(int col, const char *s, const char *e)
{
- return count_spaces_until(col, buffer, NULL);
+ return 1 + indentation_after_range(col - 1, s, e);
+}
+
+int
+count_spaces(int col, const char *s)
+{
+ return 1 + indentation_after(col - 1, s);
}
void
Home |
Main Index |
Thread Index |
Old Index