sort.c (241737) | sort.c (242430) |
---|---|
1/*- 2 * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> 3 * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko@citrix.com> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> 3 * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko@citrix.com> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/usr.bin/sort/sort.c 241737 2012-10-19 14:49:42Z ed $"); | 29__FBSDID("$FreeBSD: head/usr.bin/sort/sort.c 242430 2012-11-01 11:38:34Z gabor $"); |
30 31#include <sys/stat.h> 32#include <sys/sysctl.h> 33#include <sys/types.h> 34 35#include <err.h> 36#include <errno.h> 37#include <getopt.h> --- 74 unchanged lines hidden (view full) --- 112static struct sort_mods default_sort_mods_object; 113struct sort_mods * const default_sort_mods = &default_sort_mods_object; 114 115static bool print_symbols_on_debug; 116 117/* 118 * Arguments from file (when file0-from option is used: 119 */ | 30 31#include <sys/stat.h> 32#include <sys/sysctl.h> 33#include <sys/types.h> 34 35#include <err.h> 36#include <errno.h> 37#include <getopt.h> --- 74 unchanged lines hidden (view full) --- 112static struct sort_mods default_sort_mods_object; 113struct sort_mods * const default_sort_mods = &default_sort_mods_object; 114 115static bool print_symbols_on_debug; 116 117/* 118 * Arguments from file (when file0-from option is used: 119 */ |
120static int argc_from_file0 = -1; | 120static size_t argc_from_file0 = (size_t)-1; |
121static char **argv_from_file0; 122 123/* 124 * Placeholder symbols for options which have no single-character equivalent 125 */ 126enum 127{ 128 SORT_OPT = CHAR_MAX + 1, --- 110 unchanged lines hidden (view full) --- 239 240 memset(&f0r, 0, sizeof(f0r)); 241 f0r.f = f; 242 243 while (!feof(f)) { 244 char *line = read_file0_line(&f0r); 245 246 if (line && *line) { | 121static char **argv_from_file0; 122 123/* 124 * Placeholder symbols for options which have no single-character equivalent 125 */ 126enum 127{ 128 SORT_OPT = CHAR_MAX + 1, --- 110 unchanged lines hidden (view full) --- 239 240 memset(&f0r, 0, sizeof(f0r)); 241 f0r.f = f; 242 243 while (!feof(f)) { 244 char *line = read_file0_line(&f0r); 245 246 if (line && *line) { |
247 if (argc_from_file0 == (size_t)-1) 248 argc_from_file0 = 0; |
|
247 ++argc_from_file0; | 249 ++argc_from_file0; |
248 if (argc_from_file0 < 1) 249 argc_from_file0 = 1; | |
250 argv_from_file0 = sort_realloc(argv_from_file0, 251 argc_from_file0 * sizeof(char *)); 252 if (argv_from_file0 == NULL) 253 err(2, NULL); 254 argv_from_file0[argc_from_file0 - 1] = 255 sort_strdup(line); 256 } 257 } --- 958 unchanged lines hidden (view full) --- 1216 ks->pos1b = sm->bflag; 1217 ks->pos2b = sm->bflag; 1218 memcpy(&(ks->sm), sm, sizeof(struct sort_mods)); 1219 } 1220 1221 ks->sm.func = get_sort_func(&(ks->sm)); 1222 } 1223 | 250 argv_from_file0 = sort_realloc(argv_from_file0, 251 argc_from_file0 * sizeof(char *)); 252 if (argv_from_file0 == NULL) 253 err(2, NULL); 254 argv_from_file0[argc_from_file0 - 1] = 255 sort_strdup(line); 256 } 257 } --- 958 unchanged lines hidden (view full) --- 1216 ks->pos1b = sm->bflag; 1217 ks->pos2b = sm->bflag; 1218 memcpy(&(ks->sm), sm, sizeof(struct sort_mods)); 1219 } 1220 1221 ks->sm.func = get_sort_func(&(ks->sm)); 1222 } 1223 |
1224 if (argc_from_file0 >= 0) { | 1224 if (argv_from_file0) { |
1225 argc = argc_from_file0; 1226 argv = argv_from_file0; 1227 } 1228 1229 if (debug_sort) { 1230#if defined(SORT_THREADS) 1231 nthreads = 1; 1232#endif --- 103 unchanged lines hidden --- | 1225 argc = argc_from_file0; 1226 argv = argv_from_file0; 1227 } 1228 1229 if (debug_sort) { 1230#if defined(SORT_THREADS) 1231 nthreads = 1; 1232#endif --- 103 unchanged lines hidden --- |