Module Name: src
Committed By: christos
Date: Wed Jan 12 18:28:19 UTC 2011
Modified Files:
src/usr.bin/ypcat: ypcat.1 ypcat.c
Log Message:
add -s option to compress spaces.
To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/ypcat/ypcat.1
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/ypcat/ypcat.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/ypcat/ypcat.1
diff -u src/usr.bin/ypcat/ypcat.1:1.17 src/usr.bin/ypcat/ypcat.1:1.18
--- src/usr.bin/ypcat/ypcat.1:1.17 Sun Jun 21 11:05:59 2009
+++ src/usr.bin/ypcat/ypcat.1 Wed Jan 12 13:28:19 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: ypcat.1,v 1.17 2009/06/21 15:05:59 wiz Exp $
+.\" $NetBSD: ypcat.1,v 1.18 2011/01/12 18:28:19 christos Exp $
.\"
.\" Copyright (c) 1993 Winning Strategies, Inc.
.\" All rights reserved.
@@ -28,7 +28,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd June 20, 2009
+.Dd January 12, 2011
.Dt YPCAT 1
.Os
.Sh NAME
@@ -36,8 +36,8 @@
.Nd print the values of all keys in a NIS database
.Sh SYNOPSIS
.Nm
-.Op Fl kt
.Op Fl d Ar domainname
+.Op Fl kst
.Ar mapname
.Nm
.Fl x
@@ -57,6 +57,10 @@
Display map keys.
This option is useful with maps in which the values are null or the key
is not part of the value.
+.It Fl s
+When printing the value of a key, compress all whitespace characters to
+a single space.
+Useful when values contain newlines.
.It Fl t
Inhibit translation of map nicknames
to their corresponding map names.
Index: src/usr.bin/ypcat/ypcat.c
diff -u src/usr.bin/ypcat/ypcat.c:1.14 src/usr.bin/ypcat/ypcat.c:1.15
--- src/usr.bin/ypcat/ypcat.c:1.14 Sun Jun 21 10:58:16 2009
+++ src/usr.bin/ypcat/ypcat.c Wed Jan 12 13:28:19 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ypcat.c,v 1.14 2009/06/21 14:58:16 wiz Exp $ */
+/* $NetBSD: ypcat.c,v 1.15 2011/01/12 18:28:19 christos Exp $ */
/*
* Copyright (c) 1992, 1993 Theo de Raadt <[email protected]>
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ypcat.c,v 1.14 2009/06/21 14:58:16 wiz Exp $");
+__RCSID("$NetBSD: ypcat.c,v 1.15 2011/01/12 18:28:19 christos Exp $");
#endif
#include <sys/param.h>
@@ -52,6 +52,8 @@
static int printit(int, char *, int, char *, int, char *);
static void usage(void) __attribute__((__noreturn__));
+static int compressspace;
+
int
main(int argc, char *argv[])
@@ -69,8 +71,20 @@
domainname = NULL;
notrans = key = 0;
ypaliases = ypalias_init();
- while((c = getopt(argc, argv, "xd:kt")) != -1) {
+ while((c = getopt(argc, argv, "d:kstx")) != -1) {
switch (c) {
+ case 'd':
+ domainname = optarg;
+ break;
+
+ case 'k':
+ key++;
+ break;
+
+ case 's':
+ compressspace++;
+ break;
+
case 'x':
for (i = 0; ypaliases[i].alias; i++)
printf("Use \"%s\" for \"%s\"\n",
@@ -78,18 +92,10 @@
ypaliases[i].name);
return 0;
- case 'd':
- domainname = optarg;
- break;
-
case 't':
notrans++;
break;
- case 'k':
- key++;
- break;
-
default:
usage();
}
@@ -137,10 +143,28 @@
return instatus;
if (indata)
(void)printf("%*.*s", inkeylen, inkeylen, inkey);
- if (invallen)
- (void)printf("%s%*.*s", (indata ? " " : ""), invallen, invallen,
- inval);
- (void)printf("\n");
+ if (invallen) {
+ if (indata)
+ (void)putc(' ', stdout);
+ if (compressspace) {
+ int i;
+ int hadspace = 0;
+
+ for (i = 0; i < invallen; i++) {
+ if (isspace((unsigned char)inval[i])) {
+ if (hadspace)
+ continue;
+ hadspace = 1;
+ (void)putc(' ', stdout);
+ } else {
+ hadspace = 0;
+ (void)putc(inval[i], stdout);
+ }
+ }
+ } else
+ (void)printf("%*.*s", invallen, invallen, inval);
+ }
+ (void)putc('\n', stdout);
return 0;
}