diff options
author | pfg <pfg@FreeBSD.org> | 2015-04-05 23:06:42 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2015-04-05 23:06:42 +0000 |
commit | cf28b0945a1c59bf45b1597ca00e2d7a869cdd61 (patch) | |
tree | 5b7919e029572807945448873868897e2e354d05 /usr.bin | |
parent | b99203e9f238ca35e979d253dbb5c6ad7bff2bc1 (diff) | |
download | FreeBSD-src-cf28b0945a1c59bf45b1597ca00e2d7a869cdd61.zip FreeBSD-src-cf28b0945a1c59bf45b1597ca00e2d7a869cdd61.tar.gz |
sort: style knits / cleanups.
Obtained from: OpenBSD
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/sort/bwstring.c | 13 | ||||
-rw-r--r-- | usr.bin/sort/coll.c | 20 | ||||
-rw-r--r-- | usr.bin/sort/file.c | 24 | ||||
-rw-r--r-- | usr.bin/sort/mem.c | 2 | ||||
-rw-r--r-- | usr.bin/sort/radixsort.c | 3 | ||||
-rw-r--r-- | usr.bin/sort/sort.c | 9 |
6 files changed, 2 insertions, 69 deletions
diff --git a/usr.bin/sort/bwstring.c b/usr.bin/sort/bwstring.c index a4656b8..9c37b73 100644 --- a/usr.bin/sort/bwstring.c +++ b/usr.bin/sort/bwstring.c @@ -147,7 +147,6 @@ wide_str_coll(const wchar_t *s1, const wchar_t *s2) void bwsprintf(FILE *f, struct bwstring *bws, const char *prefix, const char *suffix) { - if (MB_CUR_MAX == 1) fprintf(f, "%s%s%s", prefix, bws->data.cstr, suffix); else @@ -156,20 +155,17 @@ bwsprintf(FILE *f, struct bwstring *bws, const char *prefix, const char *suffix) const void* bwsrawdata(const struct bwstring *bws) { - return (&(bws->data)); } size_t bwsrawlen(const struct bwstring *bws) { - return ((MB_CUR_MAX == 1) ? bws->len : SIZEOF_WCHAR_STRING(bws->len)); } size_t bws_memsize(const struct bwstring *bws) { - return ((MB_CUR_MAX == 1) ? (bws->len + 2 + sizeof(struct bwstring)) : (SIZEOF_WCHAR_STRING(bws->len + 1) + sizeof(struct bwstring))); } @@ -177,7 +173,6 @@ bws_memsize(const struct bwstring *bws) void bws_setlen(struct bwstring *bws, size_t newlen) { - if (bws && newlen != bws->len && newlen <= bws->len) { bws->len = newlen; if (MB_CUR_MAX == 1) @@ -217,7 +212,6 @@ bwsalloc(size_t sz) struct bwstring * bwsdup(const struct bwstring *s) { - if (s == NULL) return (NULL); else { @@ -239,7 +233,6 @@ bwsdup(const struct bwstring *s) struct bwstring * bwssbdup(const wchar_t *str, size_t len) { - if (str == NULL) return ((len == 0) ? bwsalloc(0) : NULL); else { @@ -320,7 +313,6 @@ bwscsbdup(const unsigned char *str, size_t len) void bwsfree(const struct bwstring *s) { - if (s) sort_free(s); } @@ -391,7 +383,6 @@ struct bwstring * bwsnocpy(struct bwstring *dst, const struct bwstring *src, size_t offset, size_t size) { - if (offset >= src->len) { dst->data.wstr[0] = 0; dst->len = 0; @@ -424,7 +415,6 @@ bwsnocpy(struct bwstring *dst, const struct bwstring *src, size_t offset, size_t bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended) { - if (MB_CUR_MAX == 1) { size_t len = bws->len; @@ -914,7 +904,6 @@ bwstod(struct bwstring *s0, bool *empty) int bws_month_score(const struct bwstring *s0) { - if (MB_CUR_MAX == 1) { const unsigned char *end, *s; size_t len; @@ -1120,7 +1109,6 @@ dictionary_order(struct bwstring *str) struct bwstring * ignore_case(struct bwstring *str) { - if (MB_CUR_MAX == 1) { unsigned char *end, *s; @@ -1148,7 +1136,6 @@ ignore_case(struct bwstring *str) void bws_disorder_warnx(struct bwstring *s, const char *fn, size_t pos) { - if (MB_CUR_MAX == 1) warnx("%s:%zu: disorder: %s", fn, pos + 1, s->data.cstr); else diff --git a/usr.bin/sort/coll.c b/usr.bin/sort/coll.c index 66f91da..18afec8 100644 --- a/usr.bin/sort/coll.c +++ b/usr.bin/sort/coll.c @@ -93,7 +93,6 @@ key_hint_size(void) size_t keys_array_size(void) { - return (keys_num * (sizeof(struct key_value) + key_hint_size())); } @@ -103,7 +102,6 @@ keys_array_size(void) void clean_keys_array(const struct bwstring *s, struct keys_array *ka) { - if (ka) { for (size_t i = 0; i < keys_num; ++i) if (ka->key[i].k && ka->key[i].k != s) @@ -118,7 +116,6 @@ clean_keys_array(const struct bwstring *s, struct keys_array *ka) void set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind) { - if (ka && keys_num > ind) { struct key_value *kv; @@ -173,7 +170,6 @@ sort_list_item_size(struct sort_list_item *si) static void sort_list_item_make_key(struct sort_list_item *si) { - preproc(si->str, &(si->ka)); } @@ -184,7 +180,6 @@ sort_list_item_make_key(struct sort_list_item *si) void sort_list_item_set(struct sort_list_item *si, struct bwstring *str) { - if (si) { clean_keys_array(si->str, &(si->ka)); if (si->str) { @@ -207,7 +202,6 @@ sort_list_item_set(struct sort_list_item *si, struct bwstring *str) void sort_list_item_clean(struct sort_list_item *si) { - if (si) { clean_keys_array(si->str, &(si->ka)); if (si->str) { @@ -248,7 +242,6 @@ skip_cols_to_start(const struct bwstring *s, size_t cols, size_t start, static size_t skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field) { - if (fields < 2) { if (BWSLEN(s) == 0) *empty_field = true; @@ -297,7 +290,6 @@ static void find_field_start(const struct bwstring *s, struct key_specs *ks, size_t *field_start, size_t *key_start, bool *empty_field, bool *empty_key) { - *field_start = skip_fields_to_start(s, ks->f1, empty_field); if (!*empty_field) *key_start = skip_cols_to_start(s, ks->c1, *field_start, @@ -394,7 +386,6 @@ cut_field(const struct bwstring *s, struct key_specs *ks) int preproc(struct bwstring *s, struct keys_array *ka) { - if (sort_opts_vals.kflag) for (size_t i = 0; i < keys_num; i++) { struct bwstring *key; @@ -449,7 +440,6 @@ preproc(struct bwstring *s, struct keys_array *ka) cmpcoll_t get_sort_func(struct sort_mods *sm) { - if (sm->nflag) return (numcoll); else if (sm->hflag) @@ -502,7 +492,6 @@ key_coll(struct keys_array *ps1, struct keys_array *ps2, size_t offset) int top_level_str_coll(const struct bwstring *s1, const struct bwstring *s2) { - if (default_sort_mods->rflag) { const struct bwstring *tmp; @@ -591,7 +580,6 @@ list_coll_offset(struct sort_list_item **ss1, struct sort_list_item **ss2, int list_coll(struct sort_list_item **ss1, struct sort_list_item **ss2) { - return (list_coll_offset(ss1, ss2, 0)); } @@ -646,7 +634,6 @@ get_list_call_func(size_t offset) int list_coll_by_str_only(struct sort_list_item **ss1, struct sort_list_item **ss2) { - return (top_level_str_coll(((*ss1)->str), ((*ss2)->str))); } @@ -784,7 +771,6 @@ wstrcoll(struct key_value *kv1, struct key_value *kv2, size_t offset) static inline int cmpsuffix(unsigned char si1, unsigned char si2) { - return ((char)si1 - (char)si2); } @@ -950,7 +936,6 @@ numcoll_impl(struct key_value *kv1, struct key_value *kv2, static int numcoll(struct key_value *kv1, struct key_value *kv2, size_t offset) { - return (numcoll_impl(kv1, kv2, offset, false)); } @@ -960,7 +945,6 @@ numcoll(struct key_value *kv1, struct key_value *kv2, size_t offset) static int hnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset) { - return (numcoll_impl(kv1, kv2, offset, true)); } @@ -1046,7 +1030,6 @@ versioncoll(struct key_value *kv1, struct key_value *kv2, static inline bool huge_minus(double d, int err1) { - if (err1 == ERANGE) if (d == -HUGE_VAL || d == -HUGE_VALF || d == -HUGE_VALL) return (+1); @@ -1060,7 +1043,6 @@ huge_minus(double d, int err1) static inline bool huge_plus(double d, int err1) { - if (err1 == ERANGE) if (d == HUGE_VAL || d == HUGE_VALF || d == HUGE_VALL) return (+1); @@ -1074,7 +1056,6 @@ huge_plus(double d, int err1) static bool is_nan(double d) { - return ((d == NAN) || (isnan(d))); } @@ -1084,7 +1065,6 @@ is_nan(double d) static int cmp_nans(double d1, double d2) { - if (d1 < d2) return (-1); if (d2 > d2) diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c index 7a35a1b..d7888d1 100644 --- a/usr.bin/sort/file.c +++ b/usr.bin/sort/file.c @@ -125,7 +125,6 @@ static void mt_sort(struct sort_list *list, void init_tmp_files(void) { - LIST_INIT(&tmp_files); sem_init(&tmp_files_sem, 0, 1); } @@ -136,7 +135,6 @@ init_tmp_files(void) void tmp_file_atexit(const char *tmp_file) { - if (tmp_file) { sem_wait(&tmp_files_sem); struct CLEANABLE_FILE *item = @@ -248,7 +246,6 @@ new_tmp_file_name(void) void file_list_init(struct file_list *fl, bool tmp) { - if (fl) { fl->count = 0; fl->sz = 0; @@ -263,7 +260,6 @@ file_list_init(struct file_list *fl, bool tmp) void file_list_add(struct file_list *fl, char *fn, bool allocate) { - if (fl && fn) { if (fl->count >= fl->sz || (fl->fns == NULL)) { fl->sz = (fl->sz) * 2 + 1; @@ -281,7 +277,6 @@ file_list_add(struct file_list *fl, char *fn, bool allocate) void file_list_populate(struct file_list *fl, int argc, char **argv, bool allocate) { - if (fl && argv) { int i; @@ -297,7 +292,6 @@ file_list_populate(struct file_list *fl, int argc, char **argv, bool allocate) void file_list_clean(struct file_list *fl) { - if (fl) { if (fl->fns) { size_t i; @@ -325,7 +319,6 @@ file_list_clean(struct file_list *fl) void sort_list_init(struct sort_list *l) { - if (l) { l->count = 0; l->size = 0; @@ -340,7 +333,6 @@ sort_list_init(struct sort_list *l) void sort_list_add(struct sort_list *l, struct bwstring *str) { - if (l && str) { size_t indx = l->count; @@ -366,7 +358,6 @@ sort_list_add(struct sort_list *l, struct bwstring *str) void sort_list_clean(struct sort_list *l) { - if (l) { if (l->list) { size_t i; @@ -397,7 +388,6 @@ sort_list_clean(struct sort_list *l) void sort_list_dump(struct sort_list *l, const char *fn) { - if (l && fn) { FILE *f; @@ -833,7 +823,6 @@ file_reader_readline(struct file_reader *fr) static void file_reader_clean(struct file_reader *fr) { - if (fr) { if (fr->mmapaddr) munmap(fr->mmapaddr, fr->mmapsize); @@ -858,7 +847,6 @@ file_reader_clean(struct file_reader *fr) void file_reader_free(struct file_reader *fr) { - if (fr) { file_reader_clean(fr); sort_free(fr); @@ -906,7 +894,6 @@ procfile(const char *fsrc, struct sort_list *list, struct file_list *fl) static int file_header_cmp(struct file_header *f1, struct file_header *f2) { - if (f1 == f2) return (0); else { @@ -931,7 +918,6 @@ file_header_cmp(struct file_header *f1, struct file_header *f2) static void file_header_init(struct file_header **fh, const char *fn, size_t file_pos) { - if (fh && fn) { struct bwstring *line; @@ -960,7 +946,6 @@ file_header_init(struct file_header **fh, const char *fn, size_t file_pos) static void file_header_close(struct file_header **fh) { - if (fh && *fh) { if ((*fh)->fr) { file_reader_free((*fh)->fr); @@ -998,7 +983,6 @@ file_header_swap(struct file_header **fh, size_t i1, size_t i2) static void file_header_heap_swim(struct file_header **fh, size_t indx) { - if (indx > 0) { size_t parent_index; @@ -1048,7 +1032,6 @@ file_header_heap_sink(struct file_header **fh, size_t indx, size_t size) static void file_header_list_rearrange_from_header(struct file_header **fh, size_t size) { - file_header_heap_sink(fh, 0, size); } @@ -1058,7 +1041,6 @@ file_header_list_rearrange_from_header(struct file_header **fh, size_t size) static void file_header_list_push(struct file_header *f, struct file_header **fh, size_t size) { - fh[size++] = f; file_header_heap_swim(fh, size - 1); } @@ -1074,7 +1056,6 @@ struct last_printed static void file_header_print(struct file_header *fh, FILE *f_out, struct last_printed *lp) { - if (fh && fh->fr && f_out && fh->si && fh->si->str) { if (sort_opts_vals.uflag) { if ((lp->str == NULL) || (str_list_coll(lp->str, &(fh->si)))) { @@ -1094,7 +1075,6 @@ file_header_print(struct file_header *fh, FILE *f_out, struct last_printed *lp) static void file_header_read_next(struct file_header *fh) { - if (fh && fh->fr) { struct bwstring *tmp; @@ -1152,7 +1132,6 @@ file_headers_merge(size_t fnum, struct file_header **fh, FILE *f_out) static void merge_files_array(size_t argc, char **argv, const char *fn_out) { - if (argv && fn_out) { struct file_header **fh; FILE *f_out; @@ -1185,7 +1164,6 @@ merge_files_array(size_t argc, char **argv, const char *fn_out) static int shrink_file_list(struct file_list *fl) { - if ((fl == NULL) || (size_t) (fl->count) < max_open_files) return (0); else { @@ -1230,7 +1208,6 @@ shrink_file_list(struct file_list *fl) void merge_files(struct file_list *fl, const char *fn_out) { - if (fl && fn_out) { while (shrink_file_list(fl)); @@ -1241,7 +1218,6 @@ merge_files(struct file_list *fl, const char *fn_out) static const char * get_sort_method_name(int sm) { - if (sm == SORT_MERGESORT) return "mergesort"; else if (sort_opts_vals.sort_method == SORT_RADIXSORT) diff --git a/usr.bin/sort/mem.c b/usr.bin/sort/mem.c index 93cb019..b123de9 100644 --- a/usr.bin/sort/mem.c +++ b/usr.bin/sort/mem.c @@ -29,7 +29,6 @@ __FBSDID("$FreeBSD$"); #include <err.h> -#include <stdint.h> #include <stdlib.h> #include <string.h> @@ -54,7 +53,6 @@ sort_malloc(size_t size) void sort_free(const void *ptr) { - if (ptr) free(__DECONST(void *, ptr)); } diff --git a/usr.bin/sort/radixsort.c b/usr.bin/sort/radixsort.c index 3466987..1370990 100644 --- a/usr.bin/sort/radixsort.c +++ b/usr.bin/sort/radixsort.c @@ -269,7 +269,6 @@ place_item(struct sort_level *sl, size_t item) static void free_sort_level(struct sort_level *sl) { - if (sl) { if (sl->leaves) sort_free(sl->leaves); @@ -307,7 +306,7 @@ run_sort_level_next(struct sort_level *sl) sl->sublevels = NULL; } - switch (sl->tosort_num){ + switch (sl->tosort_num) { case 0: goto end; case (1): diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c index 372c661..e222c78 100644 --- a/usr.bin/sort/sort.c +++ b/usr.bin/sort/sort.c @@ -196,7 +196,6 @@ void fix_obsolete_keys(int *argc, char **argv); static bool sort_modifier_empty(struct sort_mods *sm) { - if (sm == NULL) return (true); return (!(sm->Mflag || sm->Vflag || sm->nflag || sm->gflag || @@ -306,7 +305,6 @@ set_hw_params(void) static void conv_mbtowc(wchar_t *wc, const char *c, const wchar_t def) { - if (wc && c) { int res; @@ -386,7 +384,6 @@ set_tmpdir(void) static unsigned long long parse_memory_buffer_value(const char *value) { - if (value == NULL) return (available_free_memory); else { @@ -449,7 +446,6 @@ static void sig_handler(int sig __unused, siginfo_t *siginfo __unused, void *context __unused) { - clear_tmp_files(); exit(-1); } @@ -510,7 +506,6 @@ set_signal_handler(void) static void unknown(const char *what) { - errx(2, "%s: %s", getstr(3), what); } @@ -523,7 +518,7 @@ check_mutually_exclusive_flags(char c, bool *mef_flags) int fo_index, mec; bool found_others, found_this; - found_others = found_this =false; + found_others = found_this = false; fo_index = 0; for (int i = 0; i < NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS; i++) { @@ -551,7 +546,6 @@ check_mutually_exclusive_flags(char c, bool *mef_flags) static void set_sort_opts(void) { - memset(&default_sort_mods_object, 0, sizeof(default_sort_mods_object)); memset(&sort_opts_vals, 0, sizeof(sort_opts_vals)); @@ -565,7 +559,6 @@ set_sort_opts(void) static bool set_sort_modifier(struct sort_mods *sm, int c) { - if (sm) { switch (c){ case 'b': |