summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2015-04-05 13:56:04 +0000
committermillert <millert@openbsd.org>2015-04-05 13:56:04 +0000
commit352abeac3c6b85c2017d9b88f041080c0b3471e2 (patch)
tree53812e16848e0853d5191f33a8992fe3c2835820
parentDo not permute command line arguments but still support the (diff)
downloadwireguard-openbsd-352abeac3c6b85c2017d9b88f041080c0b3471e2.tar.xz
wireguard-openbsd-352abeac3c6b85c2017d9b88f041080c0b3471e2.zip
The -b flag should only apply when key fields are specified.
If -b follows -k it has no effect.
-rw-r--r--usr.bin/sort/coll.c4
-rw-r--r--usr.bin/sort/sort.19
-rw-r--r--usr.bin/sort/sort.c24
3 files changed, 24 insertions, 13 deletions
diff --git a/usr.bin/sort/coll.c b/usr.bin/sort/coll.c
index 4735d3ebaff..047c3ca03bf 100644
--- a/usr.bin/sort/coll.c
+++ b/usr.bin/sort/coll.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: coll.c,v 1.8 2015/04/02 22:14:51 deraadt Exp $ */
+/* $OpenBSD: coll.c,v 1.9 2015/04/05 13:56:04 millert Exp $ */
/*-
* Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org>
@@ -406,11 +406,13 @@ preproc(struct bwstring *s, struct keys_array *ka)
struct bwstring *ret = NULL;
struct sort_mods *sm = default_sort_mods;
+#ifdef GNUSORT_COMPATIBILITY
if (sm->bflag) {
if (ret == NULL)
ret = bwsdup(s);
ret = ignore_leading_blanks(ret);
}
+#endif
if (sm->dflag) {
if (ret == NULL)
ret = bwsdup(s);
diff --git a/usr.bin/sort/sort.1 b/usr.bin/sort/sort.1
index 41252ea0a3e..7d927290254 100644
--- a/usr.bin/sort/sort.1
+++ b/usr.bin/sort/sort.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sort.1,v 1.52 2015/04/05 13:54:06 millert Exp $
+.\" $OpenBSD: sort.1,v 1.53 2015/04/05 13:56:04 millert Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -137,8 +137,6 @@ appear after
.Fl k
or results may be unexpected.
.Bl -tag -width indent
-.It Fl b, Fl Fl ignore-leading-blanks
-Ignore leading blank characters when comparing lines.
.It Fl d , Fl Fl dictionary-order
Consider only blank spaces and alphanumeric characters in comparisons.
.It Fl f , Fl Fl ignore-case
@@ -235,6 +233,11 @@ Otherwise,
can be attached independently to each
.Ar field
argument of the key specifications.
+Note that
+.Fl b
+should not appear after
+.Fl k ,
+and that it has no effect unless key fields are specified.
.It Xo
.Fl k Ar field1 Ns Op , Ns Ar field2 ,
.Fl Fl key Ns = Ns Ar field1 Ns Op , Ns Ar field2
diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c
index fa7abb9d753..6594ab63a73 100644
--- a/usr.bin/sort/sort.c
+++ b/usr.bin/sort/sort.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sort.c,v 1.78 2015/04/05 13:54:06 millert Exp $ */
+/* $OpenBSD: sort.c,v 1.79 2015/04/05 13:56:04 millert Exp $ */
/*-
* Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org>
@@ -913,13 +913,16 @@ main(int argc, char *argv[])
sort_opts_vals.complex_sort = true;
sort_opts_vals.kflag = true;
- keys_num++;
- keys = sort_reallocarray(keys, keys_num,
+ keys = sort_reallocarray(keys, keys_num + 1,
sizeof(struct key_specs));
- memset(&(keys[keys_num - 1]), 0,
+ memset(&(keys[keys_num]), 0,
sizeof(struct key_specs));
+#ifndef GNUSORT_COMPATIBILITY
+ keys[keys_num].pos1b = default_sort_mods->bflag;
+ keys[keys_num].pos2b = default_sort_mods->bflag;
+#endif
- if (parse_k(optarg, &(keys[keys_num - 1])) < 0)
+ if (parse_k(optarg, &(keys[keys_num++])) < 0)
errc(2, EINVAL, "-k %s", optarg);
break;
@@ -1064,10 +1067,11 @@ main(int argc, char *argv[])
keys = sort_reallocarray(keys, 1, sizeof(struct key_specs));
memset(&(keys[0]), 0, sizeof(struct key_specs));
keys[0].c1 = 1;
- keys[0].pos1b = default_sort_mods->bflag;
- keys[0].pos2b = default_sort_mods->bflag;
- memcpy(&(keys[0].sm), default_sort_mods,
- sizeof(struct sort_mods));
+#ifdef GNUSORT_COMPATIBILITY
+ keys[0].pos1b = sm->bflag;
+ keys[0].pos2b = sm->bflag;
+#endif
+ memcpy(&(keys[0].sm), sm, sizeof(struct sort_mods));
}
for (i = 0; i < keys_num; i++) {
@@ -1077,8 +1081,10 @@ main(int argc, char *argv[])
if (sort_modifier_empty(&(ks->sm)) && !(ks->pos1b) &&
!(ks->pos2b)) {
+#ifdef GNUSORT_COMPATIBILITY
ks->pos1b = sm->bflag;
ks->pos2b = sm->bflag;
+#endif
memcpy(&(ks->sm), sm, sizeof(struct sort_mods));
}