ports/122266: update bsdsort to latest OpenBSD source
John Hein
jhein at timing.com
Sun Mar 30 18:40:02 UTC 2008
>Number: 122266
>Category: ports
>Synopsis: update bsdsort to latest OpenBSD source
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: update
>Submitter-Id: current-users
>Arrival-Date: Sun Mar 30 18:40:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: John Hein
>Release:
>Organization:
>Environment:
>Description:
Update ports/textproc/bsdsort to latest OpenBSD code.
Most significantly, this adds -s (stable sort).
>How-To-Repeat:
>Fix:
Below is the diff between the OpenBSD sort code as of 20070612 and now.
If you apply this patch directly to the files in the sort-20070612.tar.gz,
there are conflicts only in the $OpenBSD$ and $Mdocdate$ hunks,
which can be resolved manually.
The code parts in the other hunks all apply cleanly.
Update PORTREVISION to 20080330, re-roll a new distfile with the changes
and update distinfo.
Index: fields.c
===================================================================
RCS file: /base/OpenBSD-CVS/src/usr.bin/sort/fields.c,v
retrieving revision 1.11
retrieving revision 1.13
diff -u -p -r1.11 -r1.13
--- fields.c 14 Feb 2006 14:45:36 -0000 1.11
+++ fields.c 22 Feb 2008 01:24:58 -0000 1.13
@@ -1,4 +1,4 @@
-/* $OpenBSD: fields.c,v 1.11 2006/02/14 14:45:36 jmc Exp $ */
+/* $OpenBSD: fields.c,v 1.13 2008/02/22 01:24:58 millert Exp $ */
/*-
* Copyright (c) 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)fields.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: fields.c,v 1.11 2006/02/14 14:45:36 jmc Exp $";
+static char rcsid[] = "$OpenBSD: fields.c,v 1.13 2008/02/22 01:24:58 millert Exp $";
#endif
#endif /* not lint */
@@ -118,7 +118,7 @@ enterkey(RECHEADER *keybuf, /* pointer t
fieldtable->flags)) == NULL)
return (1);
- if (UNIQUE)
+ if (UNIQUE || STABLE)
*(keypos-1) = REC_D;
keybuf->offset = keypos - keybuf->data;
keybuf->length = keybuf->offset + line->size;
@@ -196,7 +196,7 @@ enterfield(u_char *tablepos, u_char *end
* To avoid confusing the exponent and the mantissa, use a field delimiter
* if the exponent is exactly 61, 61+252, etc--this is ok, since it's the
* only time a field delimiter can come in that position.
- * Reverse order is done analagously.
+ * Reverse order is done analogously.
*/
u_char *
@@ -204,8 +204,8 @@ number(u_char *pos, u_char *bufend, u_ch
{
int or_sign, parity = 0;
int expincr = 1, exponent = -1;
- int bite, expsign = 1, sign = 1;
- u_char lastvalue, *nonzero, *tline, *C_TENS;
+ int bite, expsign = 1, sign = 1, zeroskip = 0;
+ u_char lastvalue, *tline, *C_TENS;
u_char *nweights;
if (Rflag)
@@ -227,7 +227,7 @@ number(u_char *pos, u_char *bufend, u_ch
}
/* eat initial zeroes */
for (; *line == '0' && line < lineend; line++)
- ;
+ zeroskip = 1;
/* calculate exponents < 0 */
if (*line == DECIMAL) {
exponent = 1;
@@ -238,8 +238,10 @@ number(u_char *pos, u_char *bufend, u_ch
}
/* next character better be a digit */
if (*line < '1' || *line > '9' || line >= lineend) {
- *pos++ = nweights[127];
- return (pos);
+ if (!zeroskip) {
+ *pos++ = nweights[127];
+ return (pos);
+ }
}
if (expincr) {
for (tline = line-1; *++tline >= '0' &&
@@ -270,8 +272,6 @@ number(u_char *pos, u_char *bufend, u_ch
: *line);
if (pos == bufend)
return (NULL);
- if (*line != '0' || lastvalue != '0')
- nonzero = pos;
} else
lastvalue = *line;
parity ^= 1;
@@ -282,11 +282,10 @@ number(u_char *pos, u_char *bufend, u_ch
} else
break;
}
- if (parity && lastvalue != '0') {
+ if (parity) {
*pos++ = or_sign ? OFF_NTENS[lastvalue] - '0' :
OFF_TENS[lastvalue] + '0';
- } else
- pos = nonzero;
+ }
if (pos > bufend-1)
return (NULL);
*pos++ = or_sign ? nweights[254] : nweights[0];
Index: fsort.c
===================================================================
RCS file: /base/OpenBSD-CVS/src/usr.bin/sort/fsort.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -p -r1.18 -r1.19
--- fsort.c 13 Mar 2007 17:33:58 -0000 1.18
+++ fsort.c 21 Aug 2007 20:29:25 -0000 1.19
@@ -1,4 +1,4 @@
-/* $OpenBSD: fsort.c,v 1.18 2007/03/13 17:33:58 millert Exp $ */
+/* $OpenBSD: fsort.c,v 1.19 2007/08/21 20:29:25 millert Exp $ */
/*-
* Copyright (c) 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)fsort.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: fsort.c,v 1.18 2007/03/13 17:33:58 millert Exp $";
+static char rcsid[] = "$OpenBSD: fsort.c,v 1.19 2007/08/21 20:29:25 millert Exp $";
#endif
#endif /* not lint */
@@ -173,9 +173,17 @@ fsort(int binno, int depth, union f_hand
}
get = getnext;
if (!ntfiles && !mfct) { /* everything in memory--pop */
- if (nelem > 1 && radixsort((const u_char **)keylist,
- nelem, weights, REC_D))
- err(2, NULL);
+ if (nelem > 1) {
+ if (STABLE) {
+ i = sradixsort((const u_char **)keylist,
+ nelem, weights, REC_D);
+ } else {
+ i = radixsort((const u_char **)keylist,
+ nelem, weights, REC_D);
+ }
+ if (i)
+ err(2, NULL);
+ }
append(keylist, nelem, depth, outfp, putline, ftbl);
break; /* pop */
}
Index: init.c
===================================================================
RCS file: /base/OpenBSD-CVS/src/usr.bin/sort/init.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -p -r1.10 -r1.11
--- init.c 2 Apr 2007 08:04:52 -0000 1.10
+++ init.c 1 Sep 2007 18:13:58 -0000 1.11
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.10 2007/04/02 08:04:52 moritz Exp $ */
+/* $OpenBSD: init.c,v 1.11 2007/09/01 18:13:58 kili Exp $ */
/*-
* Copyright (c) 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: init.c,v 1.10 2007/04/02 08:04:52 moritz Exp $";
+static char rcsid[] = "$OpenBSD: init.c,v 1.11 2007/09/01 18:13:58 kili Exp $";
#endif
#endif /* not lint */
@@ -215,11 +215,10 @@ optval(int desc, int tcolflag)
void
fixit(int *argc, char **argv)
{
- int i, j;
+ int i, j, n;
long v, w, x;
char *p, *ep;
char buf[128], *bufp, *bufend;
- size_t n;
bufend = buf + sizeof(buf);
for (i = 1; i < *argc; i++) {
Index: msort.c
===================================================================
RCS file: /base/OpenBSD-CVS/src/usr.bin/sort/msort.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -p -r1.20 -r1.21
--- msort.c 13 Mar 2007 17:33:58 -0000 1.20
+++ msort.c 21 Aug 2007 20:29:25 -0000 1.21
@@ -1,4 +1,4 @@
-/* $OpenBSD: msort.c,v 1.20 2007/03/13 17:33:58 millert Exp $ */
+/* $OpenBSD: msort.c,v 1.21 2007/08/21 20:29:25 millert Exp $ */
/*-
* Copyright (c) 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)msort.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: msort.c,v 1.20 2007/03/13 17:33:58 millert Exp $";
+static char rcsid[] = "$OpenBSD: msort.c,v 1.21 2007/08/21 20:29:25 millert Exp $";
#endif
#endif /* not lint */
@@ -295,7 +295,7 @@ cmp(RECHEADER *rec1, RECHEADER *rec2)
for (cwts = wts; cwts; cwts = (cwts == wts1 ? 0 : wts1)) {
pos1 = rec1->data;
pos2 = rec2->data;
- if (!SINGL_FLD && UNIQUE)
+ if (!SINGL_FLD && (UNIQUE || STABLE))
end = pos1 + min(rec1->offset, rec2->offset);
else
end = pos1 + min(rec1->length, rec2->length);
Index: sort.1
===================================================================
RCS file: /base/OpenBSD-CVS/src/usr.bin/sort/sort.1,v
retrieving revision 1.29
retrieving revision 1.31
diff -u -p -r1.29 -r1.31
--- sort.1 31 May 2007 19:20:16 -0000 1.29
+++ sort.1 21 Aug 2007 21:22:37 -0000 1.31
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sort.1,v 1.29 2007/05/31 19:20:16 jmc Exp $
+.\" $OpenBSD: sort.1,v 1.31 2007/08/21 21:22:37 millert Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" @(#)sort.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate$
+.Dd $Mdocdate: August 21 2007 $
.Dt SORT 1
.Os
.Sh NAME
@@ -40,7 +40,7 @@
.Nd sort or merge text files
.Sh SYNOPSIS
.Nm sort
-.Op Fl bcdfHimnruz
+.Op Fl bcdfHimnrsuz
.Sm off
.Op Fl k\ \& Ar field1 Op , Ar field2
.Sm on
@@ -136,6 +136,10 @@ option no longer implies the
option.)
.It Fl r
Reverse the sense of comparisons.
+.It Fl s
+Enable stable sort.
+Uses additional resources (see
+.Xr sradixsort 3 ) .
.El
.Pp
The treatment of field separators can be altered using these options:
Index: sort.c
===================================================================
RCS file: /base/OpenBSD-CVS/src/usr.bin/sort/sort.c,v
retrieving revision 1.34
retrieving revision 1.36
diff -u -p -r1.34 -r1.36
--- sort.c 13 Mar 2007 17:33:58 -0000 1.34
+++ sort.c 22 Aug 2007 06:56:40 -0000 1.36
@@ -1,4 +1,4 @@
-/* $OpenBSD: sort.c,v 1.34 2007/03/13 17:33:58 millert Exp $ */
+/* $OpenBSD: sort.c,v 1.36 2007/08/22 06:56:40 jmc 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.34 2007/03/13 17:33:58 millert Exp $";
+static char rcsid[] = "$OpenBSD: sort.c,v 1.36 2007/08/22 06:56:40 jmc Exp $";
#endif
#endif /* not lint */
@@ -80,7 +80,7 @@ u_char ascii[NBINS], Rascii[NBINS], RFta
* masks of ignored characters. Alltable is 256 ones
*/
u_char dtable[NBINS], itable[NBINS], alltable[NBINS];
-int SINGL_FLD = 0, SEP_FLAG = 0, UNIQUE = 0;
+int SINGL_FLD = 0, SEP_FLAG = 0, UNIQUE = 0, STABLE = 0;
struct coldesc *clist;
int ncols = 0;
int ND = 10; /* limit on number of -k options. */
@@ -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:z")) != -1) {
+ while ((ch = getopt(argc, argv, "bcdfik:mHno:rR:t:T:uy:zs")) != -1) {
switch (ch) {
case 'b': fldtab->flags |= BI | BT;
break;
@@ -192,6 +192,9 @@ main(int argc, char *argv[])
d_mask['\n'] = d_mask[' '];
d_mask[REC_D] = REC_D_F;
break;
+ case 's':
+ STABLE = 1;
+ break;
case '?':
default:
usage(NULL);
@@ -340,7 +343,7 @@ usage(char *msg)
if (msg != NULL)
warnx("%s", msg);
- (void)fprintf(stderr, "usage: %s [-bcdfHimnruz] "
+ (void)fprintf(stderr, "usage: %s [-bcdfHimnrsuz] "
"[-k field1[,field2]] [-o output] [-R char]\n"
"\t[-T dir] [-t char] [file ...]\n", __progname);
exit(2);
Index: sort.h
===================================================================
RCS file: /base/OpenBSD-CVS/src/usr.bin/sort/sort.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -p -r1.6 -r1.7
--- sort.h 3 Jun 2003 02:56:16 -0000 1.6
+++ sort.h 21 Aug 2007 20:29:25 -0000 1.7
@@ -1,4 +1,4 @@
-/* $OpenBSD: sort.h,v 1.6 2003/06/03 02:56:16 millert Exp $ */
+/* $OpenBSD: sort.h,v 1.7 2007/08/21 20:29:25 millert Exp $ */
/*-
* Copyright (c) 1993
@@ -133,7 +133,7 @@ extern int PANIC; /* maximum depth of fs
extern u_char ascii[NBINS], Rascii[NBINS], Ftable[NBINS], RFtable[NBINS];
extern u_char alltable[NBINS], dtable[NBINS], itable[NBINS];
extern u_char d_mask[NBINS];
-extern int SINGL_FLD, SEP_FLAG, UNIQUE;
+extern int SINGL_FLD, SEP_FLAG, UNIQUE, STABLE;
extern int REC_D;
extern char *tmpdir;
extern int ND; /* limit on number of -k options. */
Index: tmp.c
===================================================================
RCS file: /base/OpenBSD-CVS/src/usr.bin/sort/tmp.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -p -r1.7 -r1.8
--- tmp.c 6 Dec 2006 05:03:29 -0000 1.7
+++ tmp.c 19 Mar 2008 19:25:49 -0000 1.8
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmp.c,v 1.7 2006/12/06 05:03:29 ray Exp $ */
+/* $OpenBSD: tmp.c,v 1.8 2008/03/19 19:25:49 kili Exp $ */
/*-
* Copyright (c) 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)tmp.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: tmp.c,v 1.7 2006/12/06 05:03:29 ray Exp $";
+static char rcsid[] = "$OpenBSD: tmp.c,v 1.8 2008/03/19 19:25:49 kili Exp $";
#endif
#endif /* not lint */
@@ -62,12 +62,11 @@ ftmp(void)
sigset_t set, oset;
FILE *fp;
int fd;
- char pathb[PATH_MAX], *path;
+ char path[PATH_MAX];
- path = pathb;
if (tmpdir[0] == '\0')
errx(2, "invalid temporary directory: \"\"");
- (void)snprintf(path, sizeof(pathb), "%s%s%s", tmpdir,
+ (void)snprintf(path, sizeof(path), "%s%s%s", tmpdir,
(tmpdir[strlen(tmpdir)-1] != '/') ? "/" : "", _NAME_TMP);
sigfillset(&set);
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list