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: add buf_add_range for adding characte...
details: https://anonhg.NetBSD.org/src/rev/1bb4aa8c9e95
branches: trunk
changeset: 1026490:1bb4aa8c9e95
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Nov 26 15:18:18 2021 +0000
description:
indent: add buf_add_range for adding characters to a buffer
No functional change.
diffstat:
usr.bin/indent/indent.c | 28 +++++++++++++++++-----------
usr.bin/indent/indent.h | 4 +++-
usr.bin/indent/pr_comment.c | 11 ++++-------
3 files changed, 24 insertions(+), 19 deletions(-)
diffs (126 lines):
diff -r a7f0815b4ff2 -r 1bb4aa8c9e95 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Fri Nov 26 15:08:48 2021 +0000
+++ b/usr.bin/indent/indent.c Fri Nov 26 15:18:18 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.233 2021/11/26 14:17:01 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.234 2021/11/26 15:18:18 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.233 2021/11/26 14:17:01 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.234 2021/11/26 15:18:18 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -170,20 +170,26 @@
buf_expand(buf, n);
}
-static void
+void
buf_add_char(struct buffer *buf, char ch)
{
buf_reserve(buf, 1);
*buf->e++ = ch;
}
+void
+buf_add_range(struct buffer *buf, const char *s, const char *e)
+{
+ size_t len = (size_t)(e - s);
+ buf_reserve(buf, len);
+ memcpy(buf->e, s, len);
+ buf->e += len;
+}
+
static void
buf_add_buf(struct buffer *buf, const struct buffer *add)
{
- size_t len = buf_len(add);
- buf_reserve(buf, len);
- memcpy(buf->e, add->s, len);
- buf->e += len;
+ buf_add_range(buf, add->s, add->e);
}
static void
@@ -335,8 +341,8 @@
diag(0, "Line broken");
}
- for (const char *t_ptr = token.s; *t_ptr != '\0'; ++t_ptr)
- inp_comment_add_char(*t_ptr);
+ inp_comment_add_range(token.s, token.e);
+
debug_inp("search_stmt_other end");
return true;
}
@@ -379,12 +385,12 @@
}
struct parser_state backup_ps = ps;
- debug_println("made backup of parser state");
+ debug_println("backed up parser state");
*lsym = lexi();
if (*lsym == lsym_newline || *lsym == lsym_form_feed ||
*lsym == lsym_comment || ps.search_stmt) {
ps = backup_ps;
- debug_println("rolled back parser state");
+ debug_println("restored parser state");
}
}
diff -r a7f0815b4ff2 -r 1bb4aa8c9e95 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Fri Nov 26 15:08:48 2021 +0000
+++ b/usr.bin/indent/indent.h Fri Nov 26 15:18:18 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.102 2021/11/25 18:48:37 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.103 2021/11/26 15:18:18 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -405,6 +405,8 @@
char *xstrdup(const char *);
void buf_expand(struct buffer *, size_t);
+void buf_add_char(struct buffer *, char);
+void buf_add_range(struct buffer *, const char *, const char *);
static inline bool
ch_isalnum(char ch)
diff -r a7f0815b4ff2 -r 1bb4aa8c9e95 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c Fri Nov 26 15:08:48 2021 +0000
+++ b/usr.bin/indent/pr_comment.c Fri Nov 26 15:18:18 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.124 2021/11/25 21:01:32 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.125 2021/11/26 15:18:18 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.124 2021/11/25 21:01:32 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.125 2021/11/26 15:18:18 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -67,11 +67,8 @@
{
if (!opt.star_comment_cont)
return;
- size_t len = 3;
- if (len >= (size_t)(com.l - com.e))
- buf_expand(&com, len);
- memcpy(com.e, " * ", len);
- com.e += len;
+ const char *delim = " * ";
+ buf_add_range(&com, delim, delim + 3);
}
static void
Home |
Main Index |
Thread Index |
Old Index