Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/ypcat add -s option to compress spaces.



details:   https://anonhg.NetBSD.org/src/rev/99984735dca6
branches:  trunk
changeset: 760752:99984735dca6
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jan 12 18:28:19 2011 +0000

description:
add -s option to compress spaces.

diffstat:

 usr.bin/ypcat/ypcat.1 |  10 ++++++--
 usr.bin/ypcat/ypcat.c |  54 ++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 46 insertions(+), 18 deletions(-)

diffs (140 lines):

diff -r 92e963bcb501 -r 99984735dca6 usr.bin/ypcat/ypcat.1
--- a/usr.bin/ypcat/ypcat.1     Wed Jan 12 18:09:03 2011 +0000
+++ b/usr.bin/ypcat/ypcat.1     Wed Jan 12 18:28:19 2011 +0000
@@ -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.
diff -r 92e963bcb501 -r 99984735dca6 usr.bin/ypcat/ypcat.c
--- a/usr.bin/ypcat/ypcat.c     Wed Jan 12 18:09:03 2011 +0000
+++ b/usr.bin/ypcat/ypcat.c     Wed Jan 12 18:28:19 2011 +0000
@@ -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 <deraadt%fsa.ca@localhost>
@@ -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;
 }
 



Home | Main Index | Thread Index | Old Index