diff options
author | jozan <jozan@noemail.net> | 2020-11-04 18:25:53 +0000 |
---|---|---|
committer | jozan <jozan@noemail.net> | 2020-11-04 18:25:53 +0000 |
commit | a269125c73e54a72953cda8accda949bba0d8bbd (patch) | |
tree | d2e530e5e64523b44a0b3a3996f34189f804566d /src/c_opts.c | |
parent | In progress (diff) | |
download | unixize-a269125c73e54a72953cda8accda949bba0d8bbd.tar.gz unixize-a269125c73e54a72953cda8accda949bba0d8bbd.tar.bz2 unixize-a269125c73e54a72953cda8accda949bba0d8bbd.tar.xz unixize-a269125c73e54a72953cda8accda949bba0d8bbd.tar.zst unixize-a269125c73e54a72953cda8accda949bba0d8bbd.zip |
Prompting for confirmation
FossilOrigin-Name: bf69cb11af18c6c4bc824c100d80ade120e14c521db8c9d3389e752fa757a6c7
Diffstat (limited to '')
-rw-r--r-- | src/c_opts.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/c_opts.c b/src/c_opts.c index 98f60cb..7bfd4e7 100644 --- a/src/c_opts.c +++ b/src/c_opts.c @@ -46,21 +46,40 @@ */ #include <stdlib.h> +#include <string.h> #include <unistd.h> #include <stdio.h> #include "c_opts.h" +#include "c_unixize.h" + +static void +c_ask_confirm(const char dir[]) +{ + char c; + + printf("unixize directory %s? (y/n [n]) ", dir); + scanf("%c", &c); + if (c != 'y' && c != 'Y') { + printf("not unixized\n"); + exit(0); + } +} void -c_opts(struct opts_s* opts, int argc, const char* argv[]) +c_get_opts(struct opts_s* opts, + int argc, + const char* argv[]) { - int opt; + int opt; + bool_t confirm; opts->recursive = FALSE; opts->verbose = FALSE; opts->pretend = FALSE; - opts->hidden = FALSE; - opts->hyphen = FALSE; + opts->hidden = FALSE; + opts->hyphen = FALSE; + confirm = FALSE; while ((opt = getopt(argc, (char *const *)argv, C_OPTS)) != -1) { if (opt == 'R') { opts->recursive = TRUE; @@ -75,19 +94,26 @@ c_opts(struct opts_s* opts, int argc, const char* argv[]) /* c_dump_usage(); */ exit(0); } + else if (opt == 'i') { + confirm = TRUE; + } else if (opt == '?') { - dprintf( - STDERR_FILENO, + dprintf(STDERR_FILENO, "unixize: %c: unknown option\n", - optopt - ); + optopt); exit(1); } } + if (optind < argc && argv[optind] != NULL) { + strncpy(opts->dir, argv[optind], PATH_MAX); + } + if (argv[optind] == NULL) { + strncpy(opts->dir, ".", 2); + } + if (confirm == TRUE) { + c_ask_confirm(opts->dir); + } if (opts->pretend == TRUE) { opts->verbose = TRUE; } - if (optind < argc && argv[optind] != NULL) { - printf("arg: %s\n", argv[optind]); - } } |