diff options
author | gabor <gabor@FreeBSD.org> | 2012-11-01 11:38:34 +0000 |
---|---|---|
committer | gabor <gabor@FreeBSD.org> | 2012-11-01 11:38:34 +0000 |
commit | 40317d46a3d1b2d77332ff19d4abff62a06f8334 (patch) | |
tree | 8ffc962dccbdf41ba2c4d9c12989e3a8a4a57319 /usr.bin/sort | |
parent | 4be8d9368b2752c5c873a42e74731566ce1d37fe (diff) | |
download | FreeBSD-src-40317d46a3d1b2d77332ff19d4abff62a06f8334.zip FreeBSD-src-40317d46a3d1b2d77332ff19d4abff62a06f8334.tar.gz |
- Portability changes for ARM
- Allow larger sort memory on 64-bit platforms
Submitted by: Oleg Moskalenko <oleg.moskalenko@citrix.com>
Diffstat (limited to 'usr.bin/sort')
-rw-r--r-- | usr.bin/sort/bwstring.c | 32 | ||||
-rw-r--r-- | usr.bin/sort/bwstring.h | 2 | ||||
-rw-r--r-- | usr.bin/sort/coll.c | 25 | ||||
-rw-r--r-- | usr.bin/sort/coll.h | 10 | ||||
-rw-r--r-- | usr.bin/sort/file.c | 59 | ||||
-rw-r--r-- | usr.bin/sort/file.h | 4 | ||||
-rw-r--r-- | usr.bin/sort/radixsort.c | 2 | ||||
-rw-r--r-- | usr.bin/sort/sort.c | 8 | ||||
-rw-r--r-- | usr.bin/sort/sort.h | 2 |
9 files changed, 74 insertions, 70 deletions
diff --git a/usr.bin/sort/bwstring.c b/usr.bin/sort/bwstring.c index 5733732..121aec8 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 828704f..7359523 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 b7e1cf2..a619fcf 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) { @@ -798,7 +798,8 @@ numcoll_impl(struct key_value *kv1, struct key_value *kv2, 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; diff --git a/usr.bin/sort/coll.h b/usr.bin/sort/coll.h index c020e74..a3ceaaf 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 3d8a495..2d185e4 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]); @@ -1379,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; @@ -1395,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; @@ -1415,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; @@ -1445,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 ac3f4dd..8e95fdb 100644 --- a/usr.bin/sort/file.h +++ b/usr.bin/sort/file.h @@ -65,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 d6a97d1..b370723 100644 --- a/usr.bin/sort/radixsort.c +++ b/usr.bin/sort/radixsort.c @@ -203,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; diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c index 1f7f947..9277de0 100644 --- a/usr.bin/sort/sort.c +++ b/usr.bin/sort/sort.c @@ -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; /* @@ -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) @@ -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 525b625..f5b48bd 100644 --- a/usr.bin/sort/sort.h +++ b/usr.bin/sort/sort.h @@ -77,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; |