summaryrefslogtreecommitdiff
path: root/usr.bin/sort
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2012-11-04 02:52:03 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2012-11-04 02:52:03 +0000
commit23090366f729c56cab62de74c7a51792357e98a9 (patch)
treec511c885796e28ec571b5267e8f11f3b103d35e9 /usr.bin/sort
parent7750ad47a9a7dbc83f87158464170c8640723293 (diff)
parent22ff74b2f44234d31540b1f7fd6c91489c37cad3 (diff)
downloadsrc-test-23090366f729c56cab62de74c7a51792357e98a9.tar.gz
src-test-23090366f729c56cab62de74c7a51792357e98a9.zip
Sync from head
Notes
Notes: svn path=/projects/bmake/; revision=242545
Diffstat (limited to 'usr.bin/sort')
-rw-r--r--usr.bin/sort/Makefile14
-rw-r--r--usr.bin/sort/bwstring.c32
-rw-r--r--usr.bin/sort/bwstring.h2
-rw-r--r--usr.bin/sort/coll.c49
-rw-r--r--usr.bin/sort/coll.h10
-rw-r--r--usr.bin/sort/file.c66
-rw-r--r--usr.bin/sort/file.h7
-rw-r--r--usr.bin/sort/radixsort.c14
-rw-r--r--usr.bin/sort/sort.1.in8
-rw-r--r--usr.bin/sort/sort.c18
-rw-r--r--usr.bin/sort/sort.h4
11 files changed, 109 insertions, 115 deletions
diff --git a/usr.bin/sort/Makefile b/usr.bin/sort/Makefile
index 162df21cd5e19..ea68c4503e63c 100644
--- a/usr.bin/sort/Makefile
+++ b/usr.bin/sort/Makefile
@@ -2,26 +2,16 @@
.include <bsd.own.mk>
-.if ${MK_BSD_SORT} == "yes"
PROG= sort
-.else
-PROG= bsdsort
-CLEANFILES+= bsdsort.1
-
-bsdsort.1: sort.1
- cp ${.ALLSRC} ${.TARGET}
-.endif
SRCS= bwstring.c coll.c file.c mem.c radixsort.c sort.c vsort.c
-WARNS= 6
-
sort.1: sort.1.in
/usr/bin/sed ${MAN_SUB} ${.ALLSRC} >${.TARGET}
CLEANFILES+= sort.1
-.if !defined(WITHOUT_THREADS)
+.if defined(WITH_THREADS)
CFLAGS+= -DSORT_THREADS
LDFLAGS+= -lpthread -lmd
MAN_SUB+= -e 's|%%THREADS%%||g'
@@ -39,7 +29,7 @@ NLSSRCDIR_${lang}= ${.CURDIR}/nls
.endfor
.else
CFLAGS+= -DWITHOUT_NLS
-MAN_SUB+= -e 's|%%THREADS%%|\.\\"|g'
+MAN_SUB+= -e 's|%%NLS%%|\.\\"|g'
.endif
.include <bsd.prog.mk>
diff --git a/usr.bin/sort/bwstring.c b/usr.bin/sort/bwstring.c
index 5733732eac6f0..121aec88e627b 100644
--- a/usr.bin/sort/bwstring.c
+++ b/usr.bin/sort/bwstring.c
@@ -69,7 +69,7 @@ initialise_months(void)
continue;
if (debug_sort)
printf("month[%d]=%s\n", i, tmp);
- len = strlen(tmp);
+ len = strlen((char*)tmp);
if (len < 1)
continue;
while (isblank(*tmp))
@@ -95,13 +95,13 @@ initialise_months(void)
continue;
if (debug_sort)
printf("month[%d]=%s\n", i, tmp);
- len = strlen(tmp);
+ len = strlen((char*)tmp);
if (len < 1)
continue;
while (isblank(*tmp))
++tmp;
m = sort_malloc(SIZEOF_WCHAR_STRING(len + 1));
- if (mbstowcs(m, tmp, len) == ((size_t) -1))
+ if (mbstowcs(m, (char*)tmp, len) == ((size_t) -1))
continue;
m[len] = L'\0';
for (unsigned int j = 0; j < len; j++)
@@ -421,7 +421,7 @@ bwsnocpy(struct bwstring *dst, const struct bwstring *src, size_t offset,
* The output is ended either with '\n' (nl == true)
* or '\0' (nl == false).
*/
-int
+size_t
bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended)
{
@@ -442,11 +442,11 @@ bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended)
} else {
wchar_t eols;
- int printed = 0;
+ size_t printed = 0;
eols = zero_ended ? btowc('\0') : btowc('\n');
- while (printed < (int) BWSLEN(bws)) {
+ while (printed < BWSLEN(bws)) {
const wchar_t *s = bws->data.wstr + printed;
if (*s == L'\0') {
@@ -479,7 +479,7 @@ bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended)
struct bwstring *
bwsfgetln(FILE *f, size_t *len, bool zero_ended, struct reader_buffer *rb)
{
- wchar_t eols;
+ wint_t eols;
eols = zero_ended ? btowc('\0') : btowc('\n');
@@ -494,7 +494,7 @@ bwsfgetln(FILE *f, size_t *len, bool zero_ended, struct reader_buffer *rb)
return (NULL);
}
if (*len > 0) {
- if (ret[*len - 1] == eols)
+ if (ret[*len - 1] == (wchar_t)eols)
--(*len);
}
return (bwssbdup(ret, *len));
@@ -513,11 +513,9 @@ bwsfgetln(FILE *f, size_t *len, bool zero_ended, struct reader_buffer *rb)
if (ret[*len - 1] == '\n')
--(*len);
}
- return (bwscsbdup(ret, *len));
+ return (bwscsbdup((unsigned char*)ret, *len));
} else {
- wchar_t c = 0;
-
*len = 0;
if (feof(f))
@@ -532,6 +530,8 @@ bwsfgetln(FILE *f, size_t *len, bool zero_ended, struct reader_buffer *rb)
if (MB_CUR_MAX == 1)
while (!feof(f)) {
+ int c;
+
c = fgetc(f);
if (c == EOF) {
@@ -553,6 +553,8 @@ bwsfgetln(FILE *f, size_t *len, bool zero_ended, struct reader_buffer *rb)
}
else
while (!feof(f)) {
+ wint_t c = 0;
+
c = fgetwc(f);
if (c == WEOF) {
@@ -750,7 +752,7 @@ bwscoll(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset)
} else if (s2[i] == 0)
return (+1);
- res = strcoll(s1 + i, s2 + i);
+ res = strcoll((const char*)(s1 + i), (const char*)(s2 + i));
if (res)
return (res);
@@ -872,7 +874,7 @@ bwstod(struct bwstring *s0, bool *empty)
return (0);
}
- ret = strtod(s, &ep);
+ ret = strtod((char*)s, &ep);
if ((unsigned char*) ep == s) {
*empty = true;
return (0);
@@ -923,11 +925,11 @@ bws_month_score(const struct bwstring *s0)
while (isblank(*s) && s < end)
++s;
- len = strlen(s);
+ len = strlen((const char*)s);
for (int i = 11; i >= 0; --i) {
if (cmonths[i] &&
- (s == (unsigned char*)strstr(s, cmonths[i])))
+ (s == (unsigned char*)strstr((const char*)s, (char*)(cmonths[i]))))
return (i);
}
diff --git a/usr.bin/sort/bwstring.h b/usr.bin/sort/bwstring.h
index 828704f5de41a..73595238b216d 100644
--- a/usr.bin/sort/bwstring.h
+++ b/usr.bin/sort/bwstring.h
@@ -93,7 +93,7 @@ struct bwstring *bwsnocpy(struct bwstring *dst, const struct bwstring *src, size
int bwscmp(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset);
int bwsncmp(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset, size_t len);
int bwscoll(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset);
-int bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended);
+size_t bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended);
struct bwstring *bwsfgetln(FILE *file, size_t *len, bool zero_ended, struct reader_buffer *rb);
static inline bwstring_iterator
diff --git a/usr.bin/sort/coll.c b/usr.bin/sort/coll.c
index 6d2d293ee8e50..a619fcfda0161 100644
--- a/usr.bin/sort/coll.c
+++ b/usr.bin/sort/coll.c
@@ -47,11 +47,11 @@ __FBSDID("$FreeBSD$");
struct key_specs *keys;
size_t keys_num = 0;
-wchar_t symbol_decimal_point = L'.';
+wint_t symbol_decimal_point = L'.';
/* there is no default thousands separator in collate rules: */
-wchar_t symbol_thousands_sep = 0;
-wchar_t symbol_negative_sign = L'-';
-wchar_t symbol_positive_sign = L'+';
+wint_t symbol_thousands_sep = 0;
+wint_t symbol_negative_sign = L'-';
+wint_t symbol_positive_sign = L'+';
static int wstrcoll(struct key_value *kv1, struct key_value *kv2, size_t offset);
static int gnumcoll(struct key_value*, struct key_value *, size_t offset);
@@ -260,7 +260,7 @@ skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field)
while (cpos < BWSLEN(s)) {
bool isblank;
- isblank = iswblank(BWS_GET(s,cpos));
+ isblank = iswblank(BWS_GET(s, cpos));
if (isblank && !pb) {
--fields;
@@ -277,7 +277,7 @@ skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field)
size_t cpos = 0;
while (cpos < BWSLEN(s)) {
- if (BWS_GET(s,cpos) == sort_opts_vals.field_sep) {
+ if (BWS_GET(s,cpos) == (wchar_t)sort_opts_vals.field_sep) {
--fields;
if (fields <= 1)
return (cpos + 1);
@@ -328,7 +328,7 @@ find_field_end(const struct bwstring *s, struct key_specs *ks)
next_field_start = skip_fields_to_start(s, f2 + 1,
&empty_field);
if ((next_field_start > 0) && sort_opts_vals.tflag &&
- (sort_opts_vals.field_sep == BWS_GET(s,
+ ((wchar_t)sort_opts_vals.field_sep == BWS_GET(s,
next_field_start - 1)))
--next_field_start;
} else
@@ -699,7 +699,7 @@ static void setsuffix(wchar_t c, unsigned char *si)
* point is in sfrac, tail is the pointer to the remainder of the string.
*/
static int
-read_number(struct bwstring *s0, int *sign, wchar_t *smain, int *main_len, wchar_t *sfrac, int *frac_len, unsigned char *si)
+read_number(struct bwstring *s0, int *sign, wchar_t *smain, size_t *main_len, wchar_t *sfrac, size_t *frac_len, unsigned char *si)
{
bwstring_iterator s;
@@ -711,7 +711,7 @@ read_number(struct bwstring *s0, int *sign, wchar_t *smain, int *main_len, wchar
while (iswblank(bws_get_iter_value(s)))
s = bws_iterator_inc(s, 1);
- if (bws_get_iter_value(s) == symbol_negative_sign) {
+ if (bws_get_iter_value(s) == (wchar_t)symbol_negative_sign) {
*sign = -1;
s = bws_iterator_inc(s, 1);
}
@@ -727,7 +727,7 @@ read_number(struct bwstring *s0, int *sign, wchar_t *smain, int *main_len, wchar
s = bws_iterator_inc(s, 1);
*main_len += 1;
} else if (symbol_thousands_sep &&
- (bws_get_iter_value(s) == symbol_thousands_sep))
+ (bws_get_iter_value(s) == (wchar_t)symbol_thousands_sep))
s = bws_iterator_inc(s, 1);
else
break;
@@ -735,7 +735,7 @@ read_number(struct bwstring *s0, int *sign, wchar_t *smain, int *main_len, wchar
smain[*main_len] = 0;
- if (bws_get_iter_value(s) == symbol_decimal_point) {
+ if (bws_get_iter_value(s) == (wchar_t)symbol_decimal_point) {
s = bws_iterator_inc(s, 1);
while (iswdigit(bws_get_iter_value(s)) &&
*frac_len < MAX_NUM_SIZE) {
@@ -792,12 +792,14 @@ cmpsuffix(unsigned char si1, unsigned char si2)
* Implements numeric sort for -n and -h.
*/
static int
-numcoll_impl(struct key_value *kv1, struct key_value *kv2, size_t offset, bool use_suffix)
+numcoll_impl(struct key_value *kv1, struct key_value *kv2,
+ size_t offset __unused, bool use_suffix)
{
struct bwstring *s1, *s2;
wchar_t sfrac1[MAX_NUM_SIZE + 1], sfrac2[MAX_NUM_SIZE + 1];
wchar_t smain1[MAX_NUM_SIZE + 1], smain2[MAX_NUM_SIZE + 1];
- int cmp_res, frac1, frac2, main1, main2, sign1, sign2;
+ int cmp_res, sign1, sign2;
+ size_t frac1, frac2, main1, main2;
unsigned char SI1, SI2;
bool e1, e2, key1_read, key2_read;
@@ -810,8 +812,6 @@ numcoll_impl(struct key_value *kv1, struct key_value *kv2, size_t offset, bool u
cmp_res = 0;
key1_read = key2_read = false;
- UNUSED_ARG(offset);
-
if (debug_sort) {
bwsprintf(stdout, s1, "; k1=<", ">");
bwsprintf(stdout, s2, ", k2=<", ">");
@@ -968,14 +968,13 @@ hnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
* Implements random sort (-R).
*/
static int
-randomcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
+randomcoll(struct key_value *kv1, struct key_value *kv2,
+ size_t offset __unused)
{
struct bwstring *s1, *s2;
MD5_CTX ctx1, ctx2;
char *b1, *b2;
- UNUSED_ARG(offset);
-
s1 = kv1->k;
s2 = kv2->k;
@@ -1022,12 +1021,11 @@ randomcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
* Implements version sort (-V).
*/
static int
-versioncoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
+versioncoll(struct key_value *kv1, struct key_value *kv2,
+ size_t offset __unused)
{
struct bwstring *s1, *s2;
- UNUSED_ARG(offset);
-
s1 = kv1->k;
s2 = kv2->k;
@@ -1098,7 +1096,8 @@ cmp_nans(double d1, double d2)
* Implements general numeric sort (-g).
*/
static int
-gnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
+gnumcoll(struct key_value *kv1, struct key_value *kv2,
+ size_t offset __unused)
{
double d1, d2;
int err1, err2;
@@ -1108,8 +1107,6 @@ gnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
err1 = err2 = 0;
key1_read = key2_read = false;
- UNUSED_ARG(offset);
-
if (debug_sort) {
bwsprintf(stdout, kv1->k, "; k1=<", ">");
bwsprintf(stdout, kv2->k, "; k2=<", ">");
@@ -1256,7 +1253,7 @@ gnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
* Implements month sort (-M).
*/
static int
-monthcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
+monthcoll(struct key_value *kv1, struct key_value *kv2, size_t offset __unused)
{
int val1, val2;
bool key1_read, key2_read;
@@ -1264,8 +1261,6 @@ monthcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
val1 = val2 = 0;
key1_read = key2_read = false;
- UNUSED_ARG(offset);
-
if (debug_sort) {
bwsprintf(stdout, kv1->k, "; k1=<", ">");
bwsprintf(stdout, kv2->k, "; k2=<", ">");
diff --git a/usr.bin/sort/coll.h b/usr.bin/sort/coll.h
index c020e74a82448..a3ceaafd8b044 100644
--- a/usr.bin/sort/coll.h
+++ b/usr.bin/sort/coll.h
@@ -133,12 +133,12 @@ extern struct key_specs *keys;
extern size_t keys_num;
/*
- * Main localised symbols
+ * Main localised symbols. These must be wint_t as they may hold WEOF.
*/
-extern wchar_t symbol_decimal_point;
-extern wchar_t symbol_thousands_sep;
-extern wchar_t symbol_negative_sign;
-extern wchar_t symbol_positive_sign;
+extern wint_t symbol_decimal_point;
+extern wint_t symbol_thousands_sep;
+extern wint_t symbol_negative_sign;
+extern wint_t symbol_positive_sign;
/* funcs */
diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c
index 68c3f548e717a..2d185e4a4809d 100644
--- a/usr.bin/sort/file.c
+++ b/usr.bin/sort/file.c
@@ -229,7 +229,7 @@ read_file0_line(struct file0_reader *f0r)
char *
new_tmp_file_name(void)
{
- static unsigned int tfcounter = 0;
+ static size_t tfcounter = 0;
static const char *fn = ".bsdsort.";
char *ret;
size_t sz;
@@ -237,7 +237,7 @@ new_tmp_file_name(void)
sz = strlen(tmpdir) + 1 + strlen(fn) + 32 + 1;
ret = sort_malloc(sz);
- sprintf(ret, "%s/%s%d.%u", tmpdir, fn, (int) getpid(), tfcounter++);
+ sprintf(ret, "%s/%s%d.%lu", tmpdir, fn, (int) getpid(), (unsigned long)(tfcounter++));
tmp_file_atexit(ret);
return (ret);
}
@@ -300,7 +300,7 @@ file_list_clean(struct file_list *fl)
if (fl) {
if (fl->fns) {
- int i;
+ size_t i;
for (i = 0; i < fl->count; i++) {
if (fl->fns[i]) {
@@ -345,7 +345,7 @@ sort_list_add(struct sort_list *l, struct bwstring *str)
size_t indx = l->count;
if ((l->list == NULL) || (indx >= l->size)) {
- int newsize = (l->size + 1) + 1024;
+ size_t newsize = (l->size + 1) + 1024;
l->list = sort_realloc(l->list,
sizeof(struct sort_list_item*) * newsize);
@@ -439,7 +439,8 @@ check(const char *fn)
struct bwstring *s1, *s2, *s1disorder, *s2disorder;
struct file_reader *fr;
struct keys_array *ka1, *ka2;
- int res, pos, posdisorder;
+ int res;
+ size_t pos, posdisorder;
s1 = s2 = s1disorder = s2disorder = NULL;
ka1 = ka2 = NULL;
@@ -979,7 +980,7 @@ file_header_close(struct file_header **fh)
* Swap two array elements
*/
static void
-file_header_swap(struct file_header **fh, int i1, int i2)
+file_header_swap(struct file_header **fh, size_t i1, size_t i2)
{
struct file_header *tmp;
@@ -995,11 +996,11 @@ file_header_swap(struct file_header **fh, int i1, int i2)
* "Raises" last element to its right place
*/
static void
-file_header_heap_swim(struct file_header **fh, int indx)
+file_header_heap_swim(struct file_header **fh, size_t indx)
{
if (indx > 0) {
- int parent_index;
+ size_t parent_index;
parent_index = (indx - 1) >> 1;
@@ -1015,16 +1016,16 @@ file_header_heap_swim(struct file_header **fh, int indx)
* Sink the top element to its correct position
*/
static void
-file_header_heap_sink(struct file_header **fh, int indx, int size)
+file_header_heap_sink(struct file_header **fh, size_t indx, size_t size)
{
- int left_child_index;
- int right_child_index;
+ size_t left_child_index;
+ size_t right_child_index;
left_child_index = indx + indx + 1;
right_child_index = left_child_index + 1;
if (left_child_index < size) {
- int min_child_index;
+ size_t min_child_index;
min_child_index = left_child_index;
@@ -1045,7 +1046,7 @@ file_header_heap_sink(struct file_header **fh, int indx, int size)
* Adds element to the "left" end
*/
static void
-file_header_list_rearrange_from_header(struct file_header **fh, int size)
+file_header_list_rearrange_from_header(struct file_header **fh, size_t size)
{
file_header_heap_sink(fh, 0, size);
@@ -1055,7 +1056,7 @@ file_header_list_rearrange_from_header(struct file_header **fh, int size)
* Adds element to the "right" end
*/
static void
-file_header_list_push(struct file_header *f, struct file_header **fh, int size)
+file_header_list_push(struct file_header *f, struct file_header **fh, size_t size)
{
fh[size++] = f;
@@ -1118,10 +1119,10 @@ file_header_read_next(struct file_header *fh)
* Merge array of "files headers"
*/
static void
-file_headers_merge(int fnum, struct file_header **fh, FILE *f_out)
+file_headers_merge(size_t fnum, struct file_header **fh, FILE *f_out)
{
struct last_printed lp;
- int i;
+ size_t i;
memset(&lp, 0, sizeof(lp));
@@ -1149,13 +1150,13 @@ file_headers_merge(int fnum, struct file_header **fh, FILE *f_out)
* stdout.
*/
static void
-merge_files_array(int argc, char **argv, const char *fn_out)
+merge_files_array(size_t argc, char **argv, const char *fn_out)
{
if (argv && fn_out) {
struct file_header **fh;
FILE *f_out;
- int i;
+ size_t i;
f_out = openfile(fn_out, "w");
@@ -1189,12 +1190,12 @@ shrink_file_list(struct file_list *fl)
return (0);
else {
struct file_list new_fl;
- int indx = 0;
+ size_t indx = 0;
file_list_init(&new_fl, true);
while (indx < fl->count) {
char *fnew;
- int num;
+ size_t num;
num = fl->count - indx;
fnew = new_tmp_file_name();
@@ -1203,7 +1204,7 @@ shrink_file_list(struct file_list *fl)
num = max_open_files - 1;
merge_files_array(num, fl->fns + indx, fnew);
if (fl->tmp) {
- int i;
+ size_t i;
for (i = 0; i < num; i++)
unlink(fl->fns[indx + i]);
@@ -1297,7 +1298,7 @@ sort_list_to_file(struct sort_list *list, const char *outfile)
}
if (sort_opts_vals.sort_method == SORT_DEFAULT)
- sort_opts_vals.sort_method = SORT_QSORT;
+ sort_opts_vals.sort_method = DEFAULT_SORT_ALGORITHM;
if (debug_sort)
printf("sort_method=%s\n",
@@ -1314,9 +1315,12 @@ sort_list_to_file(struct sort_list *list, const char *outfile)
case SORT_HEAPSORT:
mt_sort(list, heapsort, outfile);
break;
- default:
+ case SORT_QSORT:
mt_sort(list, sort_qsort, outfile);
break;
+ default:
+ mt_sort(list, DEFAULT_SORT_FUNC, outfile);
+ break;
}
}
@@ -1376,7 +1380,7 @@ sub_list_cmp(struct sort_list *l1, struct sort_list *l2)
* Swap two array elements
*/
static void
-sub_list_swap(struct sort_list **sl, int i1, int i2)
+sub_list_swap(struct sort_list **sl, size_t i1, size_t i2)
{
struct sort_list *tmp;
@@ -1392,11 +1396,11 @@ sub_list_swap(struct sort_list **sl, int i1, int i2)
* "Raises" last element to its right place
*/
static void
-sub_list_swim(struct sort_list **sl, int indx)
+sub_list_swim(struct sort_list **sl, size_t indx)
{
if (indx > 0) {
- int parent_index;
+ size_t parent_index;
parent_index = (indx - 1) >> 1;
@@ -1412,16 +1416,16 @@ sub_list_swim(struct sort_list **sl, int indx)
* Sink the top element to its correct position
*/
static void
-sub_list_sink(struct sort_list **sl, int indx, int size)
+sub_list_sink(struct sort_list **sl, size_t indx, size_t size)
{
- int left_child_index;
- int right_child_index;
+ size_t left_child_index;
+ size_t right_child_index;
left_child_index = indx + indx + 1;
right_child_index = left_child_index + 1;
if (left_child_index < size) {
- int min_child_index;
+ size_t min_child_index;
min_child_index = left_child_index;
@@ -1442,7 +1446,7 @@ sub_list_sink(struct sort_list **sl, int indx, int size)
* Adds element to the "right" end
*/
static void
-sub_list_push(struct sort_list *s, struct sort_list **sl, int size)
+sub_list_push(struct sort_list *s, struct sort_list **sl, size_t size)
{
sl[size++] = s;
diff --git a/usr.bin/sort/file.h b/usr.bin/sort/file.h
index 47c22992b74e5..8e95fdb3371d3 100644
--- a/usr.bin/sort/file.h
+++ b/usr.bin/sort/file.h
@@ -39,6 +39,9 @@
#define SORT_HEAPSORT 3
#define SORT_RADIXSORT 4
+#define DEFAULT_SORT_ALGORITHM SORT_HEAPSORT
+#define DEFAULT_SORT_FUNC heapsort
+
/*
* List of data to be sorted.
*/
@@ -62,8 +65,8 @@ struct file_reader;
struct file_list
{
char **fns;
- int count;
- int sz;
+ size_t count;
+ size_t sz;
bool tmp;
};
diff --git a/usr.bin/sort/radixsort.c b/usr.bin/sort/radixsort.c
index ccaa994692864..b370723552cf1 100644
--- a/usr.bin/sort/radixsort.c
+++ b/usr.bin/sort/radixsort.c
@@ -45,6 +45,8 @@ __FBSDID("$FreeBSD$");
#include "coll.h"
#include "radixsort.h"
+#define DEFAULT_SORT_FUNC_RADIXSORT mergesort
+
#define TINY_NODE(sl) ((sl)->tosort_num < 65)
#define SMALL_NODE(sl) ((sl)->tosort_num < 5)
@@ -201,7 +203,7 @@ pop_ls_mt(void)
}
static void
-add_to_sublevel(struct sort_level *sl, struct sort_list_item *item, int indx)
+add_to_sublevel(struct sort_level *sl, struct sort_list_item *item, size_t indx)
{
struct sort_level *ssl;
@@ -349,7 +351,7 @@ run_sort_level_next(struct sort_level *sl)
/* NOTREACHED */
err(2, "Radix sort error 3");
} else
- qsort(sl->leaves, sl->leaves_num,
+ DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
sizeof(struct sort_list_item *),
(int(*)(const void *, const void *)) func);
@@ -389,12 +391,12 @@ run_sort_level_next(struct sort_level *sl)
sizeof(struct sort_list_item *),
(int(*)(const void *, const void *)) list_coll);
} else {
- qsort(sl->leaves, sl->leaves_num,
+ DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
sizeof(struct sort_list_item *),
(int(*)(const void *, const void *)) list_coll);
}
} else if (!sort_opts_vals.sflag && sort_opts_vals.complex_sort) {
- qsort(sl->leaves, sl->leaves_num,
+ DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
sizeof(struct sort_list_item *),
(int(*)(const void *, const void *)) list_coll_by_str_only);
}
@@ -541,12 +543,12 @@ run_top_sort_level(struct sort_level *sl)
sizeof(struct sort_list_item *),
(int(*)(const void *, const void *)) list_coll);
} else {
- qsort(sl->leaves, sl->leaves_num,
+ DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
sizeof(struct sort_list_item *),
(int(*)(const void *, const void *)) list_coll);
}
} else if (!sort_opts_vals.sflag && sort_opts_vals.complex_sort) {
- qsort(sl->leaves, sl->leaves_num,
+ DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
sizeof(struct sort_list_item *),
(int(*)(const void *, const void *)) list_coll_by_str_only);
}
diff --git a/usr.bin/sort/sort.1.in b/usr.bin/sort/sort.1.in
index 89800612f41df..6dd765772fbb2 100644
--- a/usr.bin/sort/sort.1.in
+++ b/usr.bin/sort/sort.1.in
@@ -33,7 +33,7 @@
.\"
.\" @(#)sort.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd May 25, 2012
+.Dd July 3, 2012
.Dt SORT 1
.Os
.Sh NAME
@@ -313,8 +313,8 @@ without arguments.
When called with argument
.Fl d
it must decompress standard input to standard output.
-If PROGRAM fails,
-.Nm
+If PROGRAM fails,
+.Nm
must exit with error.
An example of PROGRAM that can be used here is bzip2.
.It Fl Fl random-source Ns = Ns Ar filename
@@ -329,7 +329,7 @@ is used.
.It Fl Fl debug
Print some extra information about the sorting process to the
standard output.
-%%THREADS%%.It Fl Fl nthreads
+%%THREADS%%.It Fl Fl parallel
%%THREADS%%Set the maximum number of execution threads.
%%THREADS%%Default number equals to the number of CPUs.
.It Fl Fl files0-from Ns = Ns Ar filename
diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c
index dd0ed68283115..9277de0ffc451 100644
--- a/usr.bin/sort/sort.c
+++ b/usr.bin/sort/sort.c
@@ -91,7 +91,7 @@ const char *nlsstr[] = { "",
"[--heapsort] [--mergesort] [--radixsort] [--qsort] "
"[--mmap] "
#if defined(SORT_THREADS)
- "[--nthreads thread_no] "
+ "[--parallel thread_no] "
#endif
"[--human-numeric-sort] "
"[--version-sort] [--random-sort [--random-source file]] "
@@ -117,7 +117,7 @@ static bool print_symbols_on_debug;
/*
* Arguments from file (when file0-from option is used:
*/
-static int argc_from_file0 = -1;
+static size_t argc_from_file0 = (size_t)-1;
static char **argv_from_file0;
/*
@@ -132,7 +132,7 @@ enum
VERSION_OPT,
DEBUG_OPT,
#if defined(SORT_THREADS)
- NTHREADS_OPT,
+ PARALLEL_OPT,
#endif
RANDOMSOURCE_OPT,
COMPRESSPROGRAM_OPT,
@@ -146,7 +146,7 @@ enum
#define NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS 6
static const char mutually_exclusive_flags[NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS] = { 'M', 'n', 'g', 'R', 'h', 'V' };
-struct option long_options[] = {
+static struct option long_options[] = {
{ "batch-size", required_argument, NULL, BS_OPT },
{ "buffer-size", required_argument, NULL, 'S' },
{ "check", optional_argument, NULL, 'c' },
@@ -171,7 +171,7 @@ struct option long_options[] = {
{ "numeric-sort", no_argument, NULL, 'n' },
{ "output", required_argument, NULL, 'o' },
#if defined(SORT_THREADS)
- { "nthreads", required_argument, NULL, NTHREADS_OPT },
+ { "parallel", required_argument, NULL, PARALLEL_OPT },
#endif
{ "qsort", no_argument, NULL, QSORT_OPT },
{ "radixsort", no_argument, NULL, RADIXSORT_OPT },
@@ -244,9 +244,9 @@ read_fns_from_file0(const char *fn)
char *line = read_file0_line(&f0r);
if (line && *line) {
+ if (argc_from_file0 == (size_t)-1)
+ argc_from_file0 = 0;
++argc_from_file0;
- if (argc_from_file0 < 1)
- argc_from_file0 = 1;
argv_from_file0 = sort_realloc(argv_from_file0,
argc_from_file0 * sizeof(char *));
if (argv_from_file0 == NULL)
@@ -1119,7 +1119,7 @@ main(int argc, char **argv)
}
break;
#if defined(SORT_THREADS)
- case NTHREADS_OPT:
+ case PARALLEL_OPT:
nthreads = (size_t)(atoi(optarg));
if (nthreads < 1)
nthreads = 1;
@@ -1221,7 +1221,7 @@ main(int argc, char **argv)
ks->sm.func = get_sort_func(&(ks->sm));
}
- if (argc_from_file0 >= 0) {
+ if (argv_from_file0) {
argc = argc_from_file0;
argv = argv_from_file0;
}
diff --git a/usr.bin/sort/sort.h b/usr.bin/sort/sort.h
index f6505c9b2a991..f5b48bd1b9993 100644
--- a/usr.bin/sort/sort.h
+++ b/usr.bin/sort/sort.h
@@ -41,8 +41,6 @@
#define VERSION "2.3-FreeBSD"
-#define UNUSED_ARG(A) do { A=A; } while(0)
-
#ifdef WITHOUT_NLS
#define getstr(n) nlsstr[n]
#else
@@ -79,7 +77,7 @@ extern MD5_CTX md5_ctx;
*/
struct sort_opts
{
- wchar_t field_sep;
+ wint_t field_sep;
int sort_method;
bool cflag;
bool csilentflag;