commit 705d45cf7f4bf7006081d44dc0a6439ec90dcede
parent ffc510064c8ef611cd41786404991115ded87cb1
Author: sin <sin@2f30.org>
Date: Wed, 21 Mar 2018 17:25:19 +0000
Rework arg parsing again
Diffstat:
M | dedup.c | | | 32 | +++++++++++++++++--------------- |
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/dedup.c b/dedup.c
@@ -552,8 +552,24 @@ main(int argc, char *argv[])
usage();
} ARGEND
- if (argc > 1)
+ if (argc > 1) {
usage();
+ } else if (argc == 1) {
+ if (id) {
+ fd = open(argv[0], O_RDWR | O_CREAT, 0600);
+ if (fd == -1)
+ err(1, "open %s", argv[0]);
+ } else {
+ fd = open(argv[0], O_RDONLY);
+ if (fd == -1)
+ err(1, "open %s", argv[0]);
+ }
+ } else {
+ if (id)
+ fd = STDOUT_FILENO;
+ else
+ fd = STDIN_FILENO;
+ }
if (root != NULL) {
mkdir(root, 0700);
@@ -575,22 +591,8 @@ main(int argc, char *argv[])
}
if (id) {
- if (argc == 1) {
- fd = open(argv[0], O_RDWR | O_CREAT, 0600);
- if (fd == -1)
- err(1, "open %s", argv[0]);
- } else {
- fd = STDOUT_FILENO;
- }
extract(id, fd);
} else {
- if (argc == 1) {
- fd = open(argv[0], O_RDONLY);
- if (fd == -1)
- err(1, "open %s", argv[0]);
- } else {
- fd = STDIN_FILENO;
- }
dedup(fd);
}