summaryrefslogtreecommitdiff
path: root/usr.bin/sort/sort.c
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2005-09-27 23:40:08 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2005-09-27 23:40:08 +0000
commita0ec5e6d29ce08b2f2472d1cc16b0d7b006ebb55 (patch)
treef123191ba91c90bef630a7eda04f53ccc174adc6 /usr.bin/sort/sort.c
parentab818fa8908bb05ac7e1579de18648ebd8af2a05 (diff)
add a -z option that allows you to split records on the nul character
('\0'). useful in combination with things like "find . -print0" and "xargs -0". for dewi, a chump. ok deraadt@
Diffstat (limited to 'usr.bin/sort/sort.c')
-rw-r--r--usr.bin/sort/sort.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c
index 60611021c08..242abc1f7c4 100644
--- a/usr.bin/sort/sort.c
+++ b/usr.bin/sort/sort.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sort.c,v 1.25 2005/04/11 21:04:48 moritz Exp $ */
+/* $OpenBSD: sort.c,v 1.26 2005/09/27 23:40:07 dlg Exp $ */
/*-
* Copyright (c) 1993
@@ -42,7 +42,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)sort.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: sort.c,v 1.25 2005/04/11 21:04:48 moritz Exp $";
+static char rcsid[] = "$OpenBSD: sort.c,v 1.26 2005/09/27 23:40:07 dlg Exp $";
#endif
#endif /* not lint */
@@ -125,7 +125,7 @@ main(int argc, char *argv[])
fixit(&argc, argv);
if (!issetugid() && (outfile = getenv("TMPDIR")))
tmpdir = outfile;
- while ((ch = getopt(argc, argv, "bcdfik:mHno:rR:t:T:uy:")) != -1) {
+ while ((ch = getopt(argc, argv, "bcdfik:mHno:rR:t:T:uy:z")) != -1) {
switch (ch) {
case 'b': fldtab->flags |= BI | BT;
break;
@@ -185,6 +185,13 @@ main(int argc, char *argv[])
case 'y':
/* accept -y for backwards compat. */
break;
+ case 'z':
+ if (REC_D != '\n')
+ usage("multiple record delimiters");
+ REC_D = '\0';
+ d_mask['\n'] = d_mask[' '];
+ d_mask[REC_D] = REC_D_F;
+ break;
case '?':
default:
usage(NULL);
@@ -328,7 +335,7 @@ usage(char *msg)
if (msg != NULL)
warnx("%s", msg);
- (void)fprintf(stderr, "usage: %s [-T dir] [-o output] [-cmubdfinrH] "
+ (void)fprintf(stderr, "usage: %s [-T dir] [-o output] [-cmubdfinrHz] "
"[-t char] [-R char] [-k keydef] ... [files]\n", __progname);
exit(2);
}