aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjozan <jozan@noemail.net>2020-11-04 18:45:02 +0000
committerjozan <jozan@noemail.net>2020-11-04 18:45:02 +0000
commite9c2008b655b894cccd4625e6048b886e38c54fe (patch)
tree1f168891ba4b2955b8dd4a1d71a8406fa044ae05
parentPrompting for confirmation (diff)
downloadunixize-e9c2008b655b894cccd4625e6048b886e38c54fe.tar.gz
unixize-e9c2008b655b894cccd4625e6048b886e38c54fe.tar.bz2
unixize-e9c2008b655b894cccd4625e6048b886e38c54fe.tar.xz
unixize-e9c2008b655b894cccd4625e6048b886e38c54fe.tar.zst
unixize-e9c2008b655b894cccd4625e6048b886e38c54fe.zip
gotopt
FossilOrigin-Name: 22e7d627a10487ea70830d52fe2161827283c14994378df7a8a7ea33d650704e
-rw-r--r--src/c_opts.c36
-rw-r--r--src/c_opts.h8
2 files changed, 29 insertions, 15 deletions
diff --git a/src/c_opts.c b/src/c_opts.c
index 7bfd4e7..c586a61 100644
--- a/src/c_opts.c
+++ b/src/c_opts.c
@@ -58,7 +58,12 @@ c_ask_confirm(const char dir[])
{
char c;
- printf("unixize directory %s? (y/n [n]) ", dir);
+ if (strncmp(dir, ".", 2 * sizeof(char)) == 0) {
+ printf("unixize current directory? (y/n [n]) ");
+ }
+ else {
+ printf("unixize %s? (y/n [n]) ", dir);
+ }
scanf("%c", &c);
if (c != 'y' && c != 'Y') {
printf("not unixized\n");
@@ -81,14 +86,8 @@ c_get_opts(struct opts_s* opts,
opts->hyphen = FALSE;
confirm = FALSE;
while ((opt = getopt(argc, (char *const *)argv, C_OPTS)) != -1) {
- if (opt == 'R') {
- opts->recursive = TRUE;
- }
- else if (opt == 'v') {
- opts->verbose = TRUE;
- }
- else if (opt == 'p') {
- opts->pretend = TRUE;
+ if (opt == 'a') {
+ opts->hidden = TRUE;
}
else if (opt == 'h') {
/* c_dump_usage(); */
@@ -97,6 +96,18 @@ c_get_opts(struct opts_s* opts,
else if (opt == 'i') {
confirm = TRUE;
}
+ else if (opt == 'n') {
+ opts->hyphen = TRUE;
+ }
+ else if (opt == 'p') {
+ opts->pretend = TRUE;
+ }
+ else if (opt == 'R') {
+ opts->recursive = TRUE;
+ }
+ else if (opt == 'v') {
+ opts->verbose = TRUE;
+ }
else if (opt == '?') {
dprintf(STDERR_FILENO,
"unixize: %c: unknown option\n",
@@ -106,9 +117,12 @@ c_get_opts(struct opts_s* opts,
}
if (optind < argc && argv[optind] != NULL) {
strncpy(opts->dir, argv[optind], PATH_MAX);
+ if (opts->dir[strlen(opts->dir) - 1] == '/') {
+ opts->dir[strlen(opts->dir) - 1] = 0x00;
+ }
}
- if (argv[optind] == NULL) {
- strncpy(opts->dir, ".", 2);
+ else if (argv[optind] == NULL) {
+ strncpy(opts->dir, ".", 2 * sizeof(char));
}
if (confirm == TRUE) {
c_ask_confirm(opts->dir);
diff --git a/src/c_opts.h b/src/c_opts.h
index 16b2ce8..5c08b34 100644
--- a/src/c_opts.h
+++ b/src/c_opts.h
@@ -54,14 +54,14 @@
#include "c_unixize.h"
-#define C_OPTS "hinpRv"
+#define C_OPTS "ahinpRv"
struct opts_s {
- bool_t recursive;
- bool_t verbose;
- bool_t pretend;
bool_t hidden;
bool_t hyphen;
+ bool_t pretend;
+ bool_t recursive;
+ bool_t verbose;
char dir[PATH_MAX];
};