summaryrefslogtreecommitdiff
path: root/usr.bin/tsort
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2015-10-11 17:39:51 +0000
committerMarc Espie <espie@cvs.openbsd.org>2015-10-11 17:39:51 +0000
commitd8b25b8a4a625e354dc50c6c47e6f200a45586d2 (patch)
treee716a3ee0aef7ec0a2280aeafd5d8c9e70f00c84 /usr.bin/tsort
parentbe1ab1b22057216a2366879300de2fa1dfe090e0 (diff)
reorg code to have an array with all the files used apparent.
okay millert@
Diffstat (limited to 'usr.bin/tsort')
-rw-r--r--usr.bin/tsort/tsort.c56
1 files changed, 35 insertions, 21 deletions
diff --git a/usr.bin/tsort/tsort.c b/usr.bin/tsort/tsort.c
index 442591a7cde..4f25618ae68 100644
--- a/usr.bin/tsort/tsort.c
+++ b/usr.bin/tsort/tsort.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tsort.c,v 1.30 2015/10/10 15:47:22 deraadt Exp $ */
+/* $OpenBSD: tsort.c,v 1.31 2015/10/11 17:39:50 espie Exp $ */
/* ex:ts=8 sw=4:
*
* Copyright (c) 1999-2004 Marc Espie <espie@openbsd.org>
@@ -824,25 +824,19 @@ parse_args(int argc, char *argv[], struct ohash *pairs)
int c;
unsigned int order;
int reverse_flag;
+ char **files;
+ int i, j;
- order = 0;
+ i = 0;
reverse_flag = quiet_flag = long_flag =
warn_flag = hints_flag = verbose_flag = 0;
- nodes_init(pairs);
+ /* argc is good enough, as we start at argv[1] */
+ files = ereallocarray(NULL, argc, sizeof (char *));
while ((c = getopt(argc, argv, "h:flqrvw")) != -1) {
switch(c) {
- case 'h': {
- FILE *f;
-
- f = fopen(optarg, "r");
- if (f == NULL)
- err(EX_NOINPUT, "Can't open hint file %s",
- optarg);
- order = read_hints(f, pairs, quiet_flag,
- optarg, order);
- fclose(f);
- }
+ case 'h':
+ files[i++] = optarg;
hints_flag = 1;
break;
/*FALLTHRU*/
@@ -873,7 +867,32 @@ parse_args(int argc, char *argv[], struct ohash *pairs)
argv += optind;
switch(argc) {
- case 1: {
+ case 1:
+ files[i++] = argv[0];
+ break;
+ case 0:
+ break;
+ default:
+ usage();
+ }
+
+ files[i] = NULL;
+
+ nodes_init(pairs);
+ order = 0;
+
+ for (j = 0; j != i-argc; j++) {
+ FILE *f;
+
+ f = fopen(files[j], "r");
+ if (f == NULL)
+ err(EX_NOINPUT, "Can't open hint file %s", files[i]);
+ order = read_hints(f, pairs, quiet_flag, files[i], order);
+ fclose(f);
+ }
+ free(files);
+
+ if (argc == 1) {
FILE *f;
f = fopen(argv[0], "r");
@@ -882,14 +901,9 @@ parse_args(int argc, char *argv[], struct ohash *pairs)
order = read_pairs(f, pairs, reverse_flag, argv[0], order,
hints_flag == 2);
fclose(f);
- break;
- }
- case 0:
+ } else {
order = read_pairs(stdin, pairs, reverse_flag, "stdin",
order, hints_flag == 2);
- break;
- default:
- usage();
}
}