summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorray <ray@openbsd.org>2006-03-27 08:21:01 +0000
committerray <ray@openbsd.org>2006-03-27 08:21:01 +0000
commita7886f03efcb3f88db868f48149aefdf7f05b77f (patch)
treedd52ff9cd45c885216f4541161901fee78204e68
parentbeef up the -z description; ok xsa (diff)
downloadwireguard-openbsd-a7886f03efcb3f88db868f48149aefdf7f05b77f.tar.xz
wireguard-openbsd-a7886f03efcb3f88db868f48149aefdf7f05b77f.zip
Fix and clean up -t flag:
- Add comments. - Support -t-inline-comments-like-man-page-says. - -tfilename still works. - When using -t (read description from stdin) don't end when first character is `.'. Instead, end if whole line consists of one `.'. - Add regression test. I also changed the regression Makefile to have a trailing slash on the final element. As long as we have a blank line it will be fine, plus it will save us some trouble when adding new tests. After adding line breaks, ``rest looks fine.'' xsa@
-rw-r--r--regress/usr.bin/rcs/Makefile35
-rw-r--r--usr.bin/rcs/rcsprog.c28
2 files changed, 57 insertions, 6 deletions
diff --git a/regress/usr.bin/rcs/Makefile b/regress/usr.bin/rcs/Makefile
index 6cc91cf110b..b597e27dc66 100644
--- a/regress/usr.bin/rcs/Makefile
+++ b/regress/usr.bin/rcs/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.11 2006/03/24 15:26:22 xsa Exp $
+# $OpenBSD: Makefile,v 1.12 2006/03/27 08:21:01 ray Exp $
# Regression tests by Niall O'Higgins <niallo@openbsd.org>.
# ksh -> Makefile by Ray Lai <ray@cyth.net>.
@@ -10,7 +10,8 @@ RCSDIFF?= rcsdiff
RCSMERGE?= rcsmerge
RLOG?= rlog
-CLEANFILES= RCS blah.c blah.c,v file file,v newfile newfile,v test test,v
+CLEANFILES= RCS blah.c blah.c,v description file file,v newfile \
+ newfile,v test test,v
# XXX - These may need to be done in order.
# (At least start with ci-initial.)
@@ -40,7 +41,12 @@ LTESTS= ci-initial \
rcsmerge \
ci-dflag \
ci-xflag \
- comma
+ comma \
+ rcs-tflag-stdin \
+ rcs-tflag-stdin2 \
+ rcs-tflag-stdin3 \
+ rcs-tflag-inline \
+ rcs-tflag-file \
.for t in ${LTESTS}
REGRESS_TARGETS+=test-${t}
@@ -253,6 +259,29 @@ test-rcs-Aflag: test-rcs-aflag
@${RCS} -q -Atest newfile
@${RLOG} newfile | diff -u ${.CURDIR}/rcs-Aflag.out -
+test-rcs-tflag-stdin: clean
+ @echo 'This is a description.' | ${RCS} -q -i -t file
+ @fgrep -q 'This is a description.' file,v
+
+test-rcs-tflag-stdin2: clean
+ @echo '.This is not the description end.' | ${RCS} -q -i -t file
+ @fgrep -q '.This is not the description end.' file,v
+
+test-rcs-tflag-stdin3: clean
+ @echo "This is the description end.\n.\nThis should not be here." | \
+ ${RCS} -q -i -t file
+ @fgrep -q 'This should not be here.' file,v || \
+ case "$$?" in 1) exit 0;; esac && exit 1
+
+test-rcs-tflag-inline: clean
+ @${RCS} -q -i '-t-This is a description.' file
+ @fgrep -q 'This is a description.' file,v
+
+test-rcs-tflag-file: clean
+ @echo 'This is a description.' > description
+ @${RCS} -q -i -tdescription file
+ @fgrep -q 'This is a description.' file,v
+
clean:
@rm -rf ${CLEANFILES}
diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c
index 10c5cf11322..60cb97d9f4e 100644
--- a/usr.bin/rcs/rcsprog.c
+++ b/usr.bin/rcs/rcsprog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsprog.c,v 1.87 2006/03/27 07:38:24 ray Exp $ */
+/* $OpenBSD: rcsprog.c,v 1.88 2006/03/27 08:21:01 ray Exp $ */
/*
* Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -718,6 +718,12 @@ rcs_attach_symbol(RCSFILE *file, const char *symname)
}
}
+/*
+ * Load description from <in> to <file>.
+ * If <in> starts with a `-', <in> is taken as the description.
+ * Otherwise <in> is the name of the file containing the description.
+ * If <in> is NULL, the description is read from stdin.
+ */
static void
rcs_set_description(RCSFILE *file, const char *in)
{
@@ -725,15 +731,31 @@ rcs_set_description(RCSFILE *file, const char *in)
char *content, buf[128];
content = NULL;
- if (in != NULL) {
+ /* Description is in file <in>. */
+ if (in != NULL && *in != '-')
bp = cvs_buf_load(in, BUF_AUTOEXT);
+ /* Description is in <in>. */
+ else if (in != NULL) {
+ size_t len;
+ const char *desc;
+
+ /* Skip leading `-'. */
+ desc = in + 1;
+ len = strlen(desc);
+
+ bp = cvs_buf_alloc(len + 1, BUF_AUTOEXT);
+ cvs_buf_append(bp, desc, len);
+ /* Get description from stdin. */
} else {
bp = cvs_buf_alloc(64, BUF_AUTOEXT);
printf(DESC_PROMPT);
for (;;) {
+ /* XXX - fgetln() may be more elegant. */
fgets(buf, sizeof(buf), stdin);
- if (feof(stdin) || ferror(stdin) || buf[0] == '.')
+ if (feof(stdin) || ferror(stdin) ||
+ strcmp(buf, ".\n") == 0 ||
+ strcmp(buf, ".") == 0)
break;
cvs_buf_append(bp, buf, strlen(buf));
printf(">> ");