summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/buf.c
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2005-02-07 11:27:47 +0000
committerharti <harti@FreeBSD.org>2005-02-07 11:27:47 +0000
commit4dd5217a47d01a7b9f07ad11f31ba806c42dd690 (patch)
tree8d3e420e3ee021620eeb19049420c02d159537a6 /usr.bin/make/buf.c
parent1a1fea70ded14847d274b940d4dd60cfe23faeb6 (diff)
downloadFreeBSD-src-4dd5217a47d01a7b9f07ad11f31ba806c42dd690.zip
FreeBSD-src-4dd5217a47d01a7b9f07ad11f31ba806c42dd690.tar.gz
Introduce Buf_StripNewLines() and use it where appropriate.
Submitted by: Max Okumoto <okumoto@ucsd.edu>
Diffstat (limited to 'usr.bin/make/buf.c')
-rw-r--r--usr.bin/make/buf.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c
index b3748f0..dc19282 100644
--- a/usr.bin/make/buf.c
+++ b/usr.bin/make/buf.c
@@ -213,6 +213,36 @@ Buf_AppendRange(Buffer *bp, const char str[], const char *end)
}
/**
+ * Convert newlines in buffer to spaces. The trailing newline is
+ * removed.
+ */
+void
+Buf_StripNewlines(Buffer *bp)
+{
+ char *ptr = bp->end;
+
+ /*
+ * If there is anything in the buffer, remove the last
+ * newline character.
+ */
+ if (ptr != bp->buf) {
+ if (*(ptr - 1) == '\n') {
+ /* shorten buffer */
+ *(ptr - 1) = '\0';
+ --bp->end;
+ }
+ --ptr;
+ }
+
+ /* Convert newline characters to a space characters. */
+ while (ptr != bp->buf) {
+ if (*ptr == '\n') {
+ *ptr = ' ';
+ }
+ --ptr;
+ }
+}
+/**
* Clear the contents of the buffer.
*/
void
OpenPOWER on IntegriCloud