summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2015-04-06 02:35:55 +0000
committerpfg <pfg@FreeBSD.org>2015-04-06 02:35:55 +0000
commit4a1d849efc0ea57e9674e144e3143e3ae1a6a9e0 (patch)
treed1c5358fe6cffe6f70e5fd3eed94b8b3378138e9 /usr.bin
parent2dd3dad9006c5abe62339289e358cbb8150d32bb (diff)
downloadFreeBSD-src-4a1d849efc0ea57e9674e144e3143e3ae1a6a9e0.zip
FreeBSD-src-4a1d849efc0ea57e9674e144e3143e3ae1a6a9e0.tar.gz
Revert (partial) r281123, r281125:
sort: style knits / cleanups. Our style guide(9) specifies that in absence of local variables an empty line must be inserted. Pointed out by: eadler
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sort/bwstring.c13
-rw-r--r--usr.bin/sort/coll.c32
-rw-r--r--usr.bin/sort/file.c24
-rw-r--r--usr.bin/sort/mem.c1
-rw-r--r--usr.bin/sort/radixsort.c4
-rw-r--r--usr.bin/sort/sort.c9
-rw-r--r--usr.bin/sort/vsort.c4
7 files changed, 79 insertions, 8 deletions
diff --git a/usr.bin/sort/bwstring.c b/usr.bin/sort/bwstring.c
index 9c37b73..a4656b8 100644
--- a/usr.bin/sort/bwstring.c
+++ b/usr.bin/sort/bwstring.c
@@ -147,6 +147,7 @@ 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
@@ -155,17 +156,20 @@ 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)));
}
@@ -173,6 +177,7 @@ 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)
@@ -212,6 +217,7 @@ bwsalloc(size_t sz)
struct bwstring *
bwsdup(const struct bwstring *s)
{
+
if (s == NULL)
return (NULL);
else {
@@ -233,6 +239,7 @@ 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 {
@@ -313,6 +320,7 @@ bwscsbdup(const unsigned char *str, size_t len)
void
bwsfree(const struct bwstring *s)
{
+
if (s)
sort_free(s);
}
@@ -383,6 +391,7 @@ 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;
@@ -415,6 +424,7 @@ 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;
@@ -904,6 +914,7 @@ 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;
@@ -1109,6 +1120,7 @@ dictionary_order(struct bwstring *str)
struct bwstring *
ignore_case(struct bwstring *str)
{
+
if (MB_CUR_MAX == 1) {
unsigned char *end, *s;
@@ -1136,6 +1148,7 @@ 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 18afec8..0b7eb57 100644
--- a/usr.bin/sort/coll.c
+++ b/usr.bin/sort/coll.c
@@ -93,6 +93,7 @@ key_hint_size(void)
size_t
keys_array_size(void)
{
+
return (keys_num * (sizeof(struct key_value) + key_hint_size()));
}
@@ -102,6 +103,7 @@ 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)
@@ -116,6 +118,7 @@ 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;
@@ -170,6 +173,7 @@ 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));
}
@@ -180,6 +184,7 @@ 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) {
@@ -202,6 +207,7 @@ 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) {
@@ -242,6 +248,7 @@ 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;
@@ -290,6 +297,7 @@ 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,
@@ -386,6 +394,7 @@ 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;
@@ -440,6 +449,7 @@ 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)
@@ -492,6 +502,7 @@ 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;
@@ -580,15 +591,16 @@ 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));
}
-#define LSCDEF(N) \
-static int \
-list_coll_##N(struct sort_list_item **ss1, struct sort_list_item **ss2) \
-{ \
- \
- return (list_coll_offset(ss1, ss2, N)); \
+#define LSCDEF(N) \
+static int \
+list_coll_##N(struct sort_list_item **ss1, struct sort_list_item **ss2) \
+{ \
+ \
+ return (list_coll_offset(ss1, ss2, N)); \
}
LSCDEF(1)
@@ -634,6 +646,7 @@ 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)));
}
@@ -771,6 +784,7 @@ 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);
}
@@ -936,6 +950,7 @@ 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));
}
@@ -945,6 +960,7 @@ 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));
}
@@ -1030,6 +1046,7 @@ 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);
@@ -1043,6 +1060,7 @@ 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);
@@ -1056,6 +1074,7 @@ huge_plus(double d, int err1)
static bool
is_nan(double d)
{
+
return ((d == NAN) || (isnan(d)));
}
@@ -1065,6 +1084,7 @@ 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 d7888d1..7a35a1b 100644
--- a/usr.bin/sort/file.c
+++ b/usr.bin/sort/file.c
@@ -125,6 +125,7 @@ static void mt_sort(struct sort_list *list,
void
init_tmp_files(void)
{
+
LIST_INIT(&tmp_files);
sem_init(&tmp_files_sem, 0, 1);
}
@@ -135,6 +136,7 @@ init_tmp_files(void)
void
tmp_file_atexit(const char *tmp_file)
{
+
if (tmp_file) {
sem_wait(&tmp_files_sem);
struct CLEANABLE_FILE *item =
@@ -246,6 +248,7 @@ new_tmp_file_name(void)
void
file_list_init(struct file_list *fl, bool tmp)
{
+
if (fl) {
fl->count = 0;
fl->sz = 0;
@@ -260,6 +263,7 @@ 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;
@@ -277,6 +281,7 @@ 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;
@@ -292,6 +297,7 @@ 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;
@@ -319,6 +325,7 @@ file_list_clean(struct file_list *fl)
void
sort_list_init(struct sort_list *l)
{
+
if (l) {
l->count = 0;
l->size = 0;
@@ -333,6 +340,7 @@ 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;
@@ -358,6 +366,7 @@ 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;
@@ -388,6 +397,7 @@ sort_list_clean(struct sort_list *l)
void
sort_list_dump(struct sort_list *l, const char *fn)
{
+
if (l && fn) {
FILE *f;
@@ -823,6 +833,7 @@ 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);
@@ -847,6 +858,7 @@ file_reader_clean(struct file_reader *fr)
void
file_reader_free(struct file_reader *fr)
{
+
if (fr) {
file_reader_clean(fr);
sort_free(fr);
@@ -894,6 +906,7 @@ 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 {
@@ -918,6 +931,7 @@ 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;
@@ -946,6 +960,7 @@ 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);
@@ -983,6 +998,7 @@ 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;
@@ -1032,6 +1048,7 @@ 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);
}
@@ -1041,6 +1058,7 @@ 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);
}
@@ -1056,6 +1074,7 @@ 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)))) {
@@ -1075,6 +1094,7 @@ 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;
@@ -1132,6 +1152,7 @@ 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;
@@ -1164,6 +1185,7 @@ 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 {
@@ -1208,6 +1230,7 @@ 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));
@@ -1218,6 +1241,7 @@ 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 b123de9..c6e9a53 100644
--- a/usr.bin/sort/mem.c
+++ b/usr.bin/sort/mem.c
@@ -53,6 +53,7 @@ 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 1370990..3b395cf 100644
--- a/usr.bin/sort/radixsort.c
+++ b/usr.bin/sort/radixsort.c
@@ -231,6 +231,7 @@ add_to_sublevel(struct sort_level *sl, struct sort_list_item *item, size_t indx)
static inline void
add_leaf(struct sort_level *sl, struct sort_list_item *item)
{
+
if (++(sl->leaves_num) > sl->leaves_sz) {
sl->leaves_sz = sl->leaves_num + 128;
sl->leaves = sort_realloc(sl->leaves,
@@ -269,6 +270,7 @@ 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);
@@ -306,7 +308,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 e222c78..372c661 100644
--- a/usr.bin/sort/sort.c
+++ b/usr.bin/sort/sort.c
@@ -196,6 +196,7 @@ 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 ||
@@ -305,6 +306,7 @@ set_hw_params(void)
static void
conv_mbtowc(wchar_t *wc, const char *c, const wchar_t def)
{
+
if (wc && c) {
int res;
@@ -384,6 +386,7 @@ set_tmpdir(void)
static unsigned long long
parse_memory_buffer_value(const char *value)
{
+
if (value == NULL)
return (available_free_memory);
else {
@@ -446,6 +449,7 @@ static void
sig_handler(int sig __unused, siginfo_t *siginfo __unused,
void *context __unused)
{
+
clear_tmp_files();
exit(-1);
}
@@ -506,6 +510,7 @@ set_signal_handler(void)
static void
unknown(const char *what)
{
+
errx(2, "%s: %s", getstr(3), what);
}
@@ -518,7 +523,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++) {
@@ -546,6 +551,7 @@ 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));
@@ -559,6 +565,7 @@ set_sort_opts(void)
static bool
set_sort_modifier(struct sort_mods *sm, int c)
{
+
if (sm) {
switch (c){
case 'b':
diff --git a/usr.bin/sort/vsort.c b/usr.bin/sort/vsort.c
index c666814..5d15f9a 100644
--- a/usr.bin/sort/vsort.c
+++ b/usr.bin/sort/vsort.c
@@ -40,18 +40,21 @@ __FBSDID("$FreeBSD$");
static inline bool
isdigit_clocale(wchar_t c)
{
+
return (c >= L'0' && c <= L'9');
}
static inline bool
isalpha_clocale(wchar_t c)
{
+
return ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'));
}
static inline bool
isalnum_clocale(wchar_t c)
{
+
return ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z') ||
(c >= L'0' && c <= L'9'));
}
@@ -112,6 +115,7 @@ find_suffix(bwstring_iterator si, bwstring_iterator se, size_t *len)
static inline int
cmp_chars(wchar_t c1, wchar_t c2)
{
+
if (c1 == c2)
return (0);
OpenPOWER on IntegriCloud