sort: style knits / cleanups.
Obtained from: OpenBSD
This commit is contained in:
parent
bd0f80c667
commit
db8026c7bb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=281125
@ -147,7 +147,6 @@ wide_str_coll(const wchar_t *s1, const wchar_t *s2)
|
|||||||
void
|
void
|
||||||
bwsprintf(FILE *f, struct bwstring *bws, const char *prefix, const char *suffix)
|
bwsprintf(FILE *f, struct bwstring *bws, const char *prefix, const char *suffix)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (MB_CUR_MAX == 1)
|
if (MB_CUR_MAX == 1)
|
||||||
fprintf(f, "%s%s%s", prefix, bws->data.cstr, suffix);
|
fprintf(f, "%s%s%s", prefix, bws->data.cstr, suffix);
|
||||||
else
|
else
|
||||||
@ -156,20 +155,17 @@ bwsprintf(FILE *f, struct bwstring *bws, const char *prefix, const char *suffix)
|
|||||||
|
|
||||||
const void* bwsrawdata(const struct bwstring *bws)
|
const void* bwsrawdata(const struct bwstring *bws)
|
||||||
{
|
{
|
||||||
|
|
||||||
return (&(bws->data));
|
return (&(bws->data));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bwsrawlen(const struct bwstring *bws)
|
size_t bwsrawlen(const struct bwstring *bws)
|
||||||
{
|
{
|
||||||
|
|
||||||
return ((MB_CUR_MAX == 1) ? bws->len : SIZEOF_WCHAR_STRING(bws->len));
|
return ((MB_CUR_MAX == 1) ? bws->len : SIZEOF_WCHAR_STRING(bws->len));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
bws_memsize(const struct bwstring *bws)
|
bws_memsize(const struct bwstring *bws)
|
||||||
{
|
{
|
||||||
|
|
||||||
return ((MB_CUR_MAX == 1) ? (bws->len + 2 + sizeof(struct bwstring)) :
|
return ((MB_CUR_MAX == 1) ? (bws->len + 2 + sizeof(struct bwstring)) :
|
||||||
(SIZEOF_WCHAR_STRING(bws->len + 1) + sizeof(struct bwstring)));
|
(SIZEOF_WCHAR_STRING(bws->len + 1) + sizeof(struct bwstring)));
|
||||||
}
|
}
|
||||||
@ -177,7 +173,6 @@ bws_memsize(const struct bwstring *bws)
|
|||||||
void
|
void
|
||||||
bws_setlen(struct bwstring *bws, size_t newlen)
|
bws_setlen(struct bwstring *bws, size_t newlen)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (bws && newlen != bws->len && newlen <= bws->len) {
|
if (bws && newlen != bws->len && newlen <= bws->len) {
|
||||||
bws->len = newlen;
|
bws->len = newlen;
|
||||||
if (MB_CUR_MAX == 1)
|
if (MB_CUR_MAX == 1)
|
||||||
@ -217,7 +212,6 @@ bwsalloc(size_t sz)
|
|||||||
struct bwstring *
|
struct bwstring *
|
||||||
bwsdup(const struct bwstring *s)
|
bwsdup(const struct bwstring *s)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
else {
|
else {
|
||||||
@ -239,7 +233,6 @@ bwsdup(const struct bwstring *s)
|
|||||||
struct bwstring *
|
struct bwstring *
|
||||||
bwssbdup(const wchar_t *str, size_t len)
|
bwssbdup(const wchar_t *str, size_t len)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return ((len == 0) ? bwsalloc(0) : NULL);
|
return ((len == 0) ? bwsalloc(0) : NULL);
|
||||||
else {
|
else {
|
||||||
@ -320,7 +313,6 @@ bwscsbdup(const unsigned char *str, size_t len)
|
|||||||
void
|
void
|
||||||
bwsfree(const struct bwstring *s)
|
bwsfree(const struct bwstring *s)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (s)
|
if (s)
|
||||||
sort_free(s);
|
sort_free(s);
|
||||||
}
|
}
|
||||||
@ -391,7 +383,6 @@ struct bwstring *
|
|||||||
bwsnocpy(struct bwstring *dst, const struct bwstring *src, size_t offset,
|
bwsnocpy(struct bwstring *dst, const struct bwstring *src, size_t offset,
|
||||||
size_t size)
|
size_t size)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (offset >= src->len) {
|
if (offset >= src->len) {
|
||||||
dst->data.wstr[0] = 0;
|
dst->data.wstr[0] = 0;
|
||||||
dst->len = 0;
|
dst->len = 0;
|
||||||
@ -424,7 +415,6 @@ bwsnocpy(struct bwstring *dst, const struct bwstring *src, size_t offset,
|
|||||||
size_t
|
size_t
|
||||||
bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended)
|
bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (MB_CUR_MAX == 1) {
|
if (MB_CUR_MAX == 1) {
|
||||||
size_t len = bws->len;
|
size_t len = bws->len;
|
||||||
|
|
||||||
@ -914,7 +904,6 @@ bwstod(struct bwstring *s0, bool *empty)
|
|||||||
int
|
int
|
||||||
bws_month_score(const struct bwstring *s0)
|
bws_month_score(const struct bwstring *s0)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (MB_CUR_MAX == 1) {
|
if (MB_CUR_MAX == 1) {
|
||||||
const unsigned char *end, *s;
|
const unsigned char *end, *s;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -1120,7 +1109,6 @@ dictionary_order(struct bwstring *str)
|
|||||||
struct bwstring *
|
struct bwstring *
|
||||||
ignore_case(struct bwstring *str)
|
ignore_case(struct bwstring *str)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (MB_CUR_MAX == 1) {
|
if (MB_CUR_MAX == 1) {
|
||||||
unsigned char *end, *s;
|
unsigned char *end, *s;
|
||||||
|
|
||||||
@ -1148,7 +1136,6 @@ ignore_case(struct bwstring *str)
|
|||||||
void
|
void
|
||||||
bws_disorder_warnx(struct bwstring *s, const char *fn, size_t pos)
|
bws_disorder_warnx(struct bwstring *s, const char *fn, size_t pos)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (MB_CUR_MAX == 1)
|
if (MB_CUR_MAX == 1)
|
||||||
warnx("%s:%zu: disorder: %s", fn, pos + 1, s->data.cstr);
|
warnx("%s:%zu: disorder: %s", fn, pos + 1, s->data.cstr);
|
||||||
else
|
else
|
||||||
|
@ -93,7 +93,6 @@ key_hint_size(void)
|
|||||||
size_t
|
size_t
|
||||||
keys_array_size(void)
|
keys_array_size(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
return (keys_num * (sizeof(struct key_value) + key_hint_size()));
|
return (keys_num * (sizeof(struct key_value) + key_hint_size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +102,6 @@ keys_array_size(void)
|
|||||||
void
|
void
|
||||||
clean_keys_array(const struct bwstring *s, struct keys_array *ka)
|
clean_keys_array(const struct bwstring *s, struct keys_array *ka)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (ka) {
|
if (ka) {
|
||||||
for (size_t i = 0; i < keys_num; ++i)
|
for (size_t i = 0; i < keys_num; ++i)
|
||||||
if (ka->key[i].k && ka->key[i].k != s)
|
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
|
void
|
||||||
set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind)
|
set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (ka && keys_num > ind) {
|
if (ka && keys_num > ind) {
|
||||||
struct key_value *kv;
|
struct key_value *kv;
|
||||||
|
|
||||||
@ -173,7 +170,6 @@ sort_list_item_size(struct sort_list_item *si)
|
|||||||
static void
|
static void
|
||||||
sort_list_item_make_key(struct sort_list_item *si)
|
sort_list_item_make_key(struct sort_list_item *si)
|
||||||
{
|
{
|
||||||
|
|
||||||
preproc(si->str, &(si->ka));
|
preproc(si->str, &(si->ka));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +180,6 @@ sort_list_item_make_key(struct sort_list_item *si)
|
|||||||
void
|
void
|
||||||
sort_list_item_set(struct sort_list_item *si, struct bwstring *str)
|
sort_list_item_set(struct sort_list_item *si, struct bwstring *str)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (si) {
|
if (si) {
|
||||||
clean_keys_array(si->str, &(si->ka));
|
clean_keys_array(si->str, &(si->ka));
|
||||||
if (si->str) {
|
if (si->str) {
|
||||||
@ -207,7 +202,6 @@ sort_list_item_set(struct sort_list_item *si, struct bwstring *str)
|
|||||||
void
|
void
|
||||||
sort_list_item_clean(struct sort_list_item *si)
|
sort_list_item_clean(struct sort_list_item *si)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (si) {
|
if (si) {
|
||||||
clean_keys_array(si->str, &(si->ka));
|
clean_keys_array(si->str, &(si->ka));
|
||||||
if (si->str) {
|
if (si->str) {
|
||||||
@ -248,7 +242,6 @@ skip_cols_to_start(const struct bwstring *s, size_t cols, size_t start,
|
|||||||
static size_t
|
static size_t
|
||||||
skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field)
|
skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fields < 2) {
|
if (fields < 2) {
|
||||||
if (BWSLEN(s) == 0)
|
if (BWSLEN(s) == 0)
|
||||||
*empty_field = true;
|
*empty_field = true;
|
||||||
@ -297,7 +290,6 @@ static void
|
|||||||
find_field_start(const struct bwstring *s, struct key_specs *ks,
|
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)
|
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);
|
*field_start = skip_fields_to_start(s, ks->f1, empty_field);
|
||||||
if (!*empty_field)
|
if (!*empty_field)
|
||||||
*key_start = skip_cols_to_start(s, ks->c1, *field_start,
|
*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
|
int
|
||||||
preproc(struct bwstring *s, struct keys_array *ka)
|
preproc(struct bwstring *s, struct keys_array *ka)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (sort_opts_vals.kflag)
|
if (sort_opts_vals.kflag)
|
||||||
for (size_t i = 0; i < keys_num; i++) {
|
for (size_t i = 0; i < keys_num; i++) {
|
||||||
struct bwstring *key;
|
struct bwstring *key;
|
||||||
@ -449,7 +440,6 @@ preproc(struct bwstring *s, struct keys_array *ka)
|
|||||||
cmpcoll_t
|
cmpcoll_t
|
||||||
get_sort_func(struct sort_mods *sm)
|
get_sort_func(struct sort_mods *sm)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (sm->nflag)
|
if (sm->nflag)
|
||||||
return (numcoll);
|
return (numcoll);
|
||||||
else if (sm->hflag)
|
else if (sm->hflag)
|
||||||
@ -502,7 +492,6 @@ key_coll(struct keys_array *ps1, struct keys_array *ps2, size_t offset)
|
|||||||
int
|
int
|
||||||
top_level_str_coll(const struct bwstring *s1, const struct bwstring *s2)
|
top_level_str_coll(const struct bwstring *s1, const struct bwstring *s2)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (default_sort_mods->rflag) {
|
if (default_sort_mods->rflag) {
|
||||||
const struct bwstring *tmp;
|
const struct bwstring *tmp;
|
||||||
|
|
||||||
@ -591,7 +580,6 @@ list_coll_offset(struct sort_list_item **ss1, struct sort_list_item **ss2,
|
|||||||
int
|
int
|
||||||
list_coll(struct sort_list_item **ss1, struct sort_list_item **ss2)
|
list_coll(struct sort_list_item **ss1, struct sort_list_item **ss2)
|
||||||
{
|
{
|
||||||
|
|
||||||
return (list_coll_offset(ss1, ss2, 0));
|
return (list_coll_offset(ss1, ss2, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -646,7 +634,6 @@ get_list_call_func(size_t offset)
|
|||||||
int
|
int
|
||||||
list_coll_by_str_only(struct sort_list_item **ss1, struct sort_list_item **ss2)
|
list_coll_by_str_only(struct sort_list_item **ss1, struct sort_list_item **ss2)
|
||||||
{
|
{
|
||||||
|
|
||||||
return (top_level_str_coll(((*ss1)->str), ((*ss2)->str)));
|
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
|
static inline int
|
||||||
cmpsuffix(unsigned char si1, unsigned char si2)
|
cmpsuffix(unsigned char si1, unsigned char si2)
|
||||||
{
|
{
|
||||||
|
|
||||||
return ((char)si1 - (char)si2);
|
return ((char)si1 - (char)si2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,7 +936,6 @@ numcoll_impl(struct key_value *kv1, struct key_value *kv2,
|
|||||||
static int
|
static int
|
||||||
numcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
|
numcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
|
||||||
{
|
{
|
||||||
|
|
||||||
return (numcoll_impl(kv1, kv2, offset, false));
|
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
|
static int
|
||||||
hnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
|
hnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
|
||||||
{
|
{
|
||||||
|
|
||||||
return (numcoll_impl(kv1, kv2, offset, true));
|
return (numcoll_impl(kv1, kv2, offset, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1046,7 +1030,6 @@ versioncoll(struct key_value *kv1, struct key_value *kv2,
|
|||||||
static inline bool
|
static inline bool
|
||||||
huge_minus(double d, int err1)
|
huge_minus(double d, int err1)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (err1 == ERANGE)
|
if (err1 == ERANGE)
|
||||||
if (d == -HUGE_VAL || d == -HUGE_VALF || d == -HUGE_VALL)
|
if (d == -HUGE_VAL || d == -HUGE_VALF || d == -HUGE_VALL)
|
||||||
return (+1);
|
return (+1);
|
||||||
@ -1060,7 +1043,6 @@ huge_minus(double d, int err1)
|
|||||||
static inline bool
|
static inline bool
|
||||||
huge_plus(double d, int err1)
|
huge_plus(double d, int err1)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (err1 == ERANGE)
|
if (err1 == ERANGE)
|
||||||
if (d == HUGE_VAL || d == HUGE_VALF || d == HUGE_VALL)
|
if (d == HUGE_VAL || d == HUGE_VALF || d == HUGE_VALL)
|
||||||
return (+1);
|
return (+1);
|
||||||
@ -1074,7 +1056,6 @@ huge_plus(double d, int err1)
|
|||||||
static bool
|
static bool
|
||||||
is_nan(double d)
|
is_nan(double d)
|
||||||
{
|
{
|
||||||
|
|
||||||
return ((d == NAN) || (isnan(d)));
|
return ((d == NAN) || (isnan(d)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1084,7 +1065,6 @@ is_nan(double d)
|
|||||||
static int
|
static int
|
||||||
cmp_nans(double d1, double d2)
|
cmp_nans(double d1, double d2)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (d1 < d2)
|
if (d1 < d2)
|
||||||
return (-1);
|
return (-1);
|
||||||
if (d2 > d2)
|
if (d2 > d2)
|
||||||
|
@ -125,7 +125,6 @@ static void mt_sort(struct sort_list *list,
|
|||||||
void
|
void
|
||||||
init_tmp_files(void)
|
init_tmp_files(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
LIST_INIT(&tmp_files);
|
LIST_INIT(&tmp_files);
|
||||||
sem_init(&tmp_files_sem, 0, 1);
|
sem_init(&tmp_files_sem, 0, 1);
|
||||||
}
|
}
|
||||||
@ -136,7 +135,6 @@ init_tmp_files(void)
|
|||||||
void
|
void
|
||||||
tmp_file_atexit(const char *tmp_file)
|
tmp_file_atexit(const char *tmp_file)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (tmp_file) {
|
if (tmp_file) {
|
||||||
sem_wait(&tmp_files_sem);
|
sem_wait(&tmp_files_sem);
|
||||||
struct CLEANABLE_FILE *item =
|
struct CLEANABLE_FILE *item =
|
||||||
@ -248,7 +246,6 @@ new_tmp_file_name(void)
|
|||||||
void
|
void
|
||||||
file_list_init(struct file_list *fl, bool tmp)
|
file_list_init(struct file_list *fl, bool tmp)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fl) {
|
if (fl) {
|
||||||
fl->count = 0;
|
fl->count = 0;
|
||||||
fl->sz = 0;
|
fl->sz = 0;
|
||||||
@ -263,7 +260,6 @@ file_list_init(struct file_list *fl, bool tmp)
|
|||||||
void
|
void
|
||||||
file_list_add(struct file_list *fl, char *fn, bool allocate)
|
file_list_add(struct file_list *fl, char *fn, bool allocate)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fl && fn) {
|
if (fl && fn) {
|
||||||
if (fl->count >= fl->sz || (fl->fns == NULL)) {
|
if (fl->count >= fl->sz || (fl->fns == NULL)) {
|
||||||
fl->sz = (fl->sz) * 2 + 1;
|
fl->sz = (fl->sz) * 2 + 1;
|
||||||
@ -281,7 +277,6 @@ file_list_add(struct file_list *fl, char *fn, bool allocate)
|
|||||||
void
|
void
|
||||||
file_list_populate(struct file_list *fl, int argc, char **argv, bool allocate)
|
file_list_populate(struct file_list *fl, int argc, char **argv, bool allocate)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fl && argv) {
|
if (fl && argv) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -297,7 +292,6 @@ file_list_populate(struct file_list *fl, int argc, char **argv, bool allocate)
|
|||||||
void
|
void
|
||||||
file_list_clean(struct file_list *fl)
|
file_list_clean(struct file_list *fl)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fl) {
|
if (fl) {
|
||||||
if (fl->fns) {
|
if (fl->fns) {
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -325,7 +319,6 @@ file_list_clean(struct file_list *fl)
|
|||||||
void
|
void
|
||||||
sort_list_init(struct sort_list *l)
|
sort_list_init(struct sort_list *l)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (l) {
|
if (l) {
|
||||||
l->count = 0;
|
l->count = 0;
|
||||||
l->size = 0;
|
l->size = 0;
|
||||||
@ -340,7 +333,6 @@ sort_list_init(struct sort_list *l)
|
|||||||
void
|
void
|
||||||
sort_list_add(struct sort_list *l, struct bwstring *str)
|
sort_list_add(struct sort_list *l, struct bwstring *str)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (l && str) {
|
if (l && str) {
|
||||||
size_t indx = l->count;
|
size_t indx = l->count;
|
||||||
|
|
||||||
@ -366,7 +358,6 @@ sort_list_add(struct sort_list *l, struct bwstring *str)
|
|||||||
void
|
void
|
||||||
sort_list_clean(struct sort_list *l)
|
sort_list_clean(struct sort_list *l)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (l) {
|
if (l) {
|
||||||
if (l->list) {
|
if (l->list) {
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -397,7 +388,6 @@ sort_list_clean(struct sort_list *l)
|
|||||||
void
|
void
|
||||||
sort_list_dump(struct sort_list *l, const char *fn)
|
sort_list_dump(struct sort_list *l, const char *fn)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (l && fn) {
|
if (l && fn) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
@ -833,7 +823,6 @@ file_reader_readline(struct file_reader *fr)
|
|||||||
static void
|
static void
|
||||||
file_reader_clean(struct file_reader *fr)
|
file_reader_clean(struct file_reader *fr)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fr) {
|
if (fr) {
|
||||||
if (fr->mmapaddr)
|
if (fr->mmapaddr)
|
||||||
munmap(fr->mmapaddr, fr->mmapsize);
|
munmap(fr->mmapaddr, fr->mmapsize);
|
||||||
@ -858,7 +847,6 @@ file_reader_clean(struct file_reader *fr)
|
|||||||
void
|
void
|
||||||
file_reader_free(struct file_reader *fr)
|
file_reader_free(struct file_reader *fr)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fr) {
|
if (fr) {
|
||||||
file_reader_clean(fr);
|
file_reader_clean(fr);
|
||||||
sort_free(fr);
|
sort_free(fr);
|
||||||
@ -906,7 +894,6 @@ procfile(const char *fsrc, struct sort_list *list, struct file_list *fl)
|
|||||||
static int
|
static int
|
||||||
file_header_cmp(struct file_header *f1, struct file_header *f2)
|
file_header_cmp(struct file_header *f1, struct file_header *f2)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (f1 == f2)
|
if (f1 == f2)
|
||||||
return (0);
|
return (0);
|
||||||
else {
|
else {
|
||||||
@ -931,7 +918,6 @@ file_header_cmp(struct file_header *f1, struct file_header *f2)
|
|||||||
static void
|
static void
|
||||||
file_header_init(struct file_header **fh, const char *fn, size_t file_pos)
|
file_header_init(struct file_header **fh, const char *fn, size_t file_pos)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fh && fn) {
|
if (fh && fn) {
|
||||||
struct bwstring *line;
|
struct bwstring *line;
|
||||||
|
|
||||||
@ -960,7 +946,6 @@ file_header_init(struct file_header **fh, const char *fn, size_t file_pos)
|
|||||||
static void
|
static void
|
||||||
file_header_close(struct file_header **fh)
|
file_header_close(struct file_header **fh)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fh && *fh) {
|
if (fh && *fh) {
|
||||||
if ((*fh)->fr) {
|
if ((*fh)->fr) {
|
||||||
file_reader_free((*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
|
static void
|
||||||
file_header_heap_swim(struct file_header **fh, size_t indx)
|
file_header_heap_swim(struct file_header **fh, size_t indx)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (indx > 0) {
|
if (indx > 0) {
|
||||||
size_t parent_index;
|
size_t parent_index;
|
||||||
|
|
||||||
@ -1048,7 +1032,6 @@ file_header_heap_sink(struct file_header **fh, size_t indx, size_t size)
|
|||||||
static void
|
static void
|
||||||
file_header_list_rearrange_from_header(struct file_header **fh, size_t size)
|
file_header_list_rearrange_from_header(struct file_header **fh, size_t size)
|
||||||
{
|
{
|
||||||
|
|
||||||
file_header_heap_sink(fh, 0, 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
|
static void
|
||||||
file_header_list_push(struct file_header *f, struct file_header **fh, size_t size)
|
file_header_list_push(struct file_header *f, struct file_header **fh, size_t size)
|
||||||
{
|
{
|
||||||
|
|
||||||
fh[size++] = f;
|
fh[size++] = f;
|
||||||
file_header_heap_swim(fh, size - 1);
|
file_header_heap_swim(fh, size - 1);
|
||||||
}
|
}
|
||||||
@ -1074,7 +1056,6 @@ struct last_printed
|
|||||||
static void
|
static void
|
||||||
file_header_print(struct file_header *fh, FILE *f_out, struct last_printed *lp)
|
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 (fh && fh->fr && f_out && fh->si && fh->si->str) {
|
||||||
if (sort_opts_vals.uflag) {
|
if (sort_opts_vals.uflag) {
|
||||||
if ((lp->str == NULL) || (str_list_coll(lp->str, &(fh->si)))) {
|
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
|
static void
|
||||||
file_header_read_next(struct file_header *fh)
|
file_header_read_next(struct file_header *fh)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fh && fh->fr) {
|
if (fh && fh->fr) {
|
||||||
struct bwstring *tmp;
|
struct bwstring *tmp;
|
||||||
|
|
||||||
@ -1152,7 +1132,6 @@ file_headers_merge(size_t fnum, struct file_header **fh, FILE *f_out)
|
|||||||
static void
|
static void
|
||||||
merge_files_array(size_t argc, char **argv, const char *fn_out)
|
merge_files_array(size_t argc, char **argv, const char *fn_out)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (argv && fn_out) {
|
if (argv && fn_out) {
|
||||||
struct file_header **fh;
|
struct file_header **fh;
|
||||||
FILE *f_out;
|
FILE *f_out;
|
||||||
@ -1185,7 +1164,6 @@ merge_files_array(size_t argc, char **argv, const char *fn_out)
|
|||||||
static int
|
static int
|
||||||
shrink_file_list(struct file_list *fl)
|
shrink_file_list(struct file_list *fl)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((fl == NULL) || (size_t) (fl->count) < max_open_files)
|
if ((fl == NULL) || (size_t) (fl->count) < max_open_files)
|
||||||
return (0);
|
return (0);
|
||||||
else {
|
else {
|
||||||
@ -1230,7 +1208,6 @@ shrink_file_list(struct file_list *fl)
|
|||||||
void
|
void
|
||||||
merge_files(struct file_list *fl, const char *fn_out)
|
merge_files(struct file_list *fl, const char *fn_out)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fl && fn_out) {
|
if (fl && fn_out) {
|
||||||
while (shrink_file_list(fl));
|
while (shrink_file_list(fl));
|
||||||
|
|
||||||
@ -1241,7 +1218,6 @@ merge_files(struct file_list *fl, const char *fn_out)
|
|||||||
static const char *
|
static const char *
|
||||||
get_sort_method_name(int sm)
|
get_sort_method_name(int sm)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (sm == SORT_MERGESORT)
|
if (sm == SORT_MERGESORT)
|
||||||
return "mergesort";
|
return "mergesort";
|
||||||
else if (sort_opts_vals.sort_method == SORT_RADIXSORT)
|
else if (sort_opts_vals.sort_method == SORT_RADIXSORT)
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -54,7 +53,6 @@ sort_malloc(size_t size)
|
|||||||
void
|
void
|
||||||
sort_free(const void *ptr)
|
sort_free(const void *ptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (ptr)
|
if (ptr)
|
||||||
free(__DECONST(void *, ptr));
|
free(__DECONST(void *, ptr));
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,6 @@ place_item(struct sort_level *sl, size_t item)
|
|||||||
static void
|
static void
|
||||||
free_sort_level(struct sort_level *sl)
|
free_sort_level(struct sort_level *sl)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (sl) {
|
if (sl) {
|
||||||
if (sl->leaves)
|
if (sl->leaves)
|
||||||
sort_free(sl->leaves);
|
sort_free(sl->leaves);
|
||||||
@ -307,7 +306,7 @@ run_sort_level_next(struct sort_level *sl)
|
|||||||
sl->sublevels = NULL;
|
sl->sublevels = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (sl->tosort_num){
|
switch (sl->tosort_num) {
|
||||||
case 0:
|
case 0:
|
||||||
goto end;
|
goto end;
|
||||||
case (1):
|
case (1):
|
||||||
|
@ -196,7 +196,6 @@ void fix_obsolete_keys(int *argc, char **argv);
|
|||||||
static bool
|
static bool
|
||||||
sort_modifier_empty(struct sort_mods *sm)
|
sort_modifier_empty(struct sort_mods *sm)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (sm == NULL)
|
if (sm == NULL)
|
||||||
return (true);
|
return (true);
|
||||||
return (!(sm->Mflag || sm->Vflag || sm->nflag || sm->gflag ||
|
return (!(sm->Mflag || sm->Vflag || sm->nflag || sm->gflag ||
|
||||||
@ -306,7 +305,6 @@ set_hw_params(void)
|
|||||||
static void
|
static void
|
||||||
conv_mbtowc(wchar_t *wc, const char *c, const wchar_t def)
|
conv_mbtowc(wchar_t *wc, const char *c, const wchar_t def)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (wc && c) {
|
if (wc && c) {
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@ -386,7 +384,6 @@ set_tmpdir(void)
|
|||||||
static unsigned long long
|
static unsigned long long
|
||||||
parse_memory_buffer_value(const char *value)
|
parse_memory_buffer_value(const char *value)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
return (available_free_memory);
|
return (available_free_memory);
|
||||||
else {
|
else {
|
||||||
@ -449,7 +446,6 @@ static void
|
|||||||
sig_handler(int sig __unused, siginfo_t *siginfo __unused,
|
sig_handler(int sig __unused, siginfo_t *siginfo __unused,
|
||||||
void *context __unused)
|
void *context __unused)
|
||||||
{
|
{
|
||||||
|
|
||||||
clear_tmp_files();
|
clear_tmp_files();
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
@ -510,7 +506,6 @@ set_signal_handler(void)
|
|||||||
static void
|
static void
|
||||||
unknown(const char *what)
|
unknown(const char *what)
|
||||||
{
|
{
|
||||||
|
|
||||||
errx(2, "%s: %s", getstr(3), 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;
|
int fo_index, mec;
|
||||||
bool found_others, found_this;
|
bool found_others, found_this;
|
||||||
|
|
||||||
found_others = found_this =false;
|
found_others = found_this = false;
|
||||||
fo_index = 0;
|
fo_index = 0;
|
||||||
|
|
||||||
for (int i = 0; i < NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS; i++) {
|
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
|
static void
|
||||||
set_sort_opts(void)
|
set_sort_opts(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
memset(&default_sort_mods_object, 0,
|
memset(&default_sort_mods_object, 0,
|
||||||
sizeof(default_sort_mods_object));
|
sizeof(default_sort_mods_object));
|
||||||
memset(&sort_opts_vals, 0, sizeof(sort_opts_vals));
|
memset(&sort_opts_vals, 0, sizeof(sort_opts_vals));
|
||||||
@ -565,7 +559,6 @@ set_sort_opts(void)
|
|||||||
static bool
|
static bool
|
||||||
set_sort_modifier(struct sort_mods *sm, int c)
|
set_sort_modifier(struct sort_mods *sm, int c)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (sm) {
|
if (sm) {
|
||||||
switch (c){
|
switch (c){
|
||||||
case 'b':
|
case 'b':
|
||||||
|
Loading…
Reference in New Issue
Block a user