diff options
author | Conrad Meyer <cem@FreeBSD.org> | 2019-04-11 00:39:06 +0000 |
---|---|---|
committer | Conrad Meyer <cem@FreeBSD.org> | 2019-04-11 00:39:06 +0000 |
commit | 74504eefa1a772822ed9d4fc75166972f2192f8c (patch) | |
tree | 758523f32c95ae620897917dd3f5ab336d7c67b8 /usr.bin/sort | |
parent | 745598d472b8483c4d9319fca173e84a55a3d0d1 (diff) | |
download | src-74504eefa1a772822ed9d4fc75166972f2192f8c.tar.gz src-74504eefa1a772822ed9d4fc75166972f2192f8c.zip |
Notes
Diffstat (limited to 'usr.bin/sort')
-rw-r--r-- | usr.bin/sort/sort.c | 175 |
1 files changed, 87 insertions, 88 deletions
diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c index bbe8af4607bd..eb034c4ae887 100644 --- a/usr.bin/sort/sort.c +++ b/usr.bin/sort/sort.c @@ -566,55 +566,57 @@ static bool set_sort_modifier(struct sort_mods *sm, int c) { - if (sm) { - switch (c){ - case 'b': - sm->bflag = true; - break; - case 'd': - sm->dflag = true; - break; - case 'f': - sm->fflag = true; - break; - case 'g': - sm->gflag = true; - need_hint = true; - break; - case 'i': - sm->iflag = true; - break; - case 'R': - sm->Rflag = true; - need_random = true; - break; - case 'M': - initialise_months(); - sm->Mflag = true; - need_hint = true; - break; - case 'n': - sm->nflag = true; - need_hint = true; - print_symbols_on_debug = true; - break; - case 'r': - sm->rflag = true; - break; - case 'V': - sm->Vflag = true; - break; - case 'h': - sm->hflag = true; - need_hint = true; - print_symbols_on_debug = true; - break; - default: - return false; - } - sort_opts_vals.complex_sort = true; - sm->func = get_sort_func(sm); + if (sm == NULL) + return (true); + + switch (c){ + case 'b': + sm->bflag = true; + break; + case 'd': + sm->dflag = true; + break; + case 'f': + sm->fflag = true; + break; + case 'g': + sm->gflag = true; + need_hint = true; + break; + case 'i': + sm->iflag = true; + break; + case 'R': + sm->Rflag = true; + need_random = true; + break; + case 'M': + initialise_months(); + sm->Mflag = true; + need_hint = true; + break; + case 'n': + sm->nflag = true; + need_hint = true; + print_symbols_on_debug = true; + break; + case 'r': + sm->rflag = true; + break; + case 'V': + sm->Vflag = true; + break; + case 'h': + sm->hflag = true; + need_hint = true; + print_symbols_on_debug = true; + break; + default: + return (false); } + + sort_opts_vals.complex_sort = true; + sm->func = get_sort_func(sm); return (true); } @@ -910,53 +912,49 @@ fix_obsolete_keys(int *argc, char **argv) static void set_random_seed(void) { - if (need_random) { - - if (strcmp(random_source, DEFAULT_RANDOM_SORT_SEED_FILE) == 0) { - FILE* fseed; - MD5_CTX ctx; - char rsd[MAX_DEFAULT_RANDOM_SEED_DATA_SIZE]; - size_t sz = 0; - - fseed = openfile(random_source, "r"); - while (!feof(fseed)) { - int cr; - - cr = fgetc(fseed); - if (cr == EOF) - break; - - rsd[sz++] = (char) cr; + if (strcmp(random_source, DEFAULT_RANDOM_SORT_SEED_FILE) == 0) { + FILE* fseed; + MD5_CTX ctx; + char rsd[MAX_DEFAULT_RANDOM_SEED_DATA_SIZE]; + size_t sz = 0; + + fseed = openfile(random_source, "r"); + while (!feof(fseed)) { + int cr; + + cr = fgetc(fseed); + if (cr == EOF) + break; - if (sz >= MAX_DEFAULT_RANDOM_SEED_DATA_SIZE) - break; - } + rsd[sz++] = (char) cr; - closefile(fseed, random_source); + if (sz >= MAX_DEFAULT_RANDOM_SEED_DATA_SIZE) + break; + } - MD5Init(&ctx); - MD5Update(&ctx, rsd, sz); + closefile(fseed, random_source); - random_seed = MD5End(&ctx, NULL); - random_seed_size = strlen(random_seed); + MD5Init(&ctx); + MD5Update(&ctx, rsd, sz); - } else { - MD5_CTX ctx; - char *b; + random_seed = MD5End(&ctx, NULL); + random_seed_size = strlen(random_seed); - MD5Init(&ctx); - b = MD5File(random_source, NULL); - if (b == NULL) - err(2, NULL); + } else { + MD5_CTX ctx; + char *b; - random_seed = b; - random_seed_size = strlen(b); - } + MD5Init(&ctx); + b = MD5File(random_source, NULL); + if (b == NULL) + err(2, NULL); - MD5Init(&md5_ctx); - if(random_seed_size>0) { - MD5Update(&md5_ctx, random_seed, random_seed_size); - } + random_seed = b; + random_seed_size = strlen(b); + } + MD5Init(&md5_ctx); + if(random_seed_size>0) { + MD5Update(&md5_ctx, random_seed, random_seed_size); } } @@ -1226,7 +1224,8 @@ main(int argc, char **argv) } } - set_random_seed(); + if (need_random) + set_random_seed(); /* Case when the outfile equals one of the input files: */ if (strcmp(outfile, "-")) { |