From 0d30aed42819e3f60309b492547ae650a1eb96b2 Mon Sep 17 00:00:00 2001 From: christos Date: Wed, 20 Aug 2003 23:37:51 +0000 Subject: [PATCH] Add -0 option. --- usr.bin/shuffle/shuffle.1 | 12 +++++++++++- usr.bin/shuffle/shuffle.c | 14 +++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/usr.bin/shuffle/shuffle.1 b/usr.bin/shuffle/shuffle.1 index f92ff286d5b0..8af08ff18cb5 100644 --- a/usr.bin/shuffle/shuffle.1 +++ b/usr.bin/shuffle/shuffle.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: shuffle.1,v 1.3 2002/03/05 15:06:16 wiz Exp $ +.\" $NetBSD: shuffle.1,v 1.4 2003/08/20 23:37:51 christos Exp $ .\" .\" Copyright (c) 1998 .\" Perry E. Metzger. All rights reserved. @@ -38,6 +38,7 @@ .Nd print a random permutation of the command line arguments .Sh SYNOPSIS .Nm +.Op Fl 0 .Op Fl f Ar filename ... .Op Fl n Ar number .Op Fl p Ar number @@ -69,6 +70,15 @@ If the .Fl p option is given, its argument is treated as a number, and the program prints that number of randomly selected lines or arguments in a random order. +.Pp +The +.Fl 0 +option, changes the field separator char from a \en to \e0, so that it +is suitable to be sent to +.Xr xargs 1 +with +.Fl 0 +to handle filenames with whitespace in them. .Sh EXAMPLES .Bd -literal -offset indent $ shuffle a b c d diff --git a/usr.bin/shuffle/shuffle.c b/usr.bin/shuffle/shuffle.c index 35aa03a8d52a..b234ad82e4ba 100644 --- a/usr.bin/shuffle/shuffle.c +++ b/usr.bin/shuffle/shuffle.c @@ -1,4 +1,4 @@ -/* $NetBSD: shuffle.c,v 1.12 2003/04/18 03:21:02 lukem Exp $ */ +/* $NetBSD: shuffle.c,v 1.13 2003/08/20 23:37:51 christos Exp $ */ /* * Copyright (c) 1998 @@ -33,7 +33,7 @@ #include #ifndef lint -__RCSID("$NetBSD: shuffle.c,v 1.12 2003/04/18 03:21:02 lukem Exp $"); +__RCSID("$NetBSD: shuffle.c,v 1.13 2003/08/20 23:37:51 christos Exp $"); #endif /* not lint */ #include @@ -132,7 +132,7 @@ usage(void) { (void) fprintf(stderr, - "Usage: %s [-f ] [-n ] [-p ] [ ...]\n", + "Usage: %s [-0] [-f ] [-n ] [-p ] [ ...]\n", getprogname()); exit(1); } @@ -205,9 +205,13 @@ main(int argc, char *argv[]) struct timeval tv; char **lines = NULL; size_t nlines = 0, pick = 0; + char sep = '\n'; while ((ch = getopt(argc, argv, "f:n:p:")) != -1) { switch(ch) { + case '0': + sep = '\0'; + break; case 'f': fname = optarg; break; @@ -250,9 +254,9 @@ main(int argc, char *argv[]) for (i = 0; i < nlines; i++) { if (nflag) - printf("%ld\n", (long)shuffle[i]); + printf("%ld%c", (long)shuffle[i], sep); else - printf("%s\n", lines[shuffle[i]]); + printf("%s%c", lines[shuffle[i]], sep); } return 0;