aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjozan <jozan@noemail.net>2020-11-04 18:25:53 +0000
committerjozan <jozan@noemail.net>2020-11-04 18:25:53 +0000
commita269125c73e54a72953cda8accda949bba0d8bbd (patch)
treed2e530e5e64523b44a0b3a3996f34189f804566d
parentIn progress (diff)
downloadunixize-a269125c73e54a72953cda8accda949bba0d8bbd.tar.gz
unixize-a269125c73e54a72953cda8accda949bba0d8bbd.tar.bz2
unixize-a269125c73e54a72953cda8accda949bba0d8bbd.tar.xz
unixize-a269125c73e54a72953cda8accda949bba0d8bbd.tar.zst
unixize-a269125c73e54a72953cda8accda949bba0d8bbd.zip
Prompting for confirmation
FossilOrigin-Name: bf69cb11af18c6c4bc824c100d80ade120e14c521db8c9d3389e752fa757a6c7
-rw-r--r--Makefile6
-rw-r--r--src/c_opts.c48
-rw-r--r--src/c_opts.h11
-rw-r--r--src/c_unixize.c17
4 files changed, 57 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index a27e1b0..49dc8ac 100644
--- a/Makefile
+++ b/Makefile
@@ -51,14 +51,14 @@ ${TARGET}: ${OBJS}
all: ${TARGET}
-debug: CFLAGS += -glldb
+debug: CFLAGS += -g3
debug: all
-asan: CFLAGS += -glldb
+asan: CFLAGS += -g3
asan: CFLAGS += -fsanitize=address
asan: all
-msan: CFLAGS += -glldb
+msan: CFLAGS += -g3
msan: CFLAGS += -fsanitize=memory
msan: CFLAGS += -fsanitize-memory-track-origins
msan: all
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]);
- }
}
diff --git a/src/c_opts.h b/src/c_opts.h
index cbe2e54..16b2ce8 100644
--- a/src/c_opts.h
+++ b/src/c_opts.h
@@ -46,9 +46,15 @@
#ifndef __C_OPTS_H__
#define __C_OPTS_H__ value
+#ifdef __linux__
+# include <linux/limits.h>
+#else
+# include <limits.h>
+#endif
+
#include "c_unixize.h"
-#define C_OPTS "hpnRv"
+#define C_OPTS "hinpRv"
struct opts_s {
bool_t recursive;
@@ -56,8 +62,9 @@ struct opts_s {
bool_t pretend;
bool_t hidden;
bool_t hyphen;
+ char dir[PATH_MAX];
};
-void c_opts(struct opts_s*, int, const char*[]);
+void c_get_opts(struct opts_s*, int, const char*[]);
#endif /* ifndef __C_OPTS_H__ */
diff --git a/src/c_unixize.c b/src/c_unixize.c
index d05c78e..7f3495d 100644
--- a/src/c_unixize.c
+++ b/src/c_unixize.c
@@ -45,28 +45,27 @@
* This is the main function and entrypoint of the program.
*/
-/* #ifdef __linux__ */
-/* # include <linux/limits.h> */
-/* #else */
-/* # include <limits.h> */
-/* #endif */
-
#include <stdio.h>
#include "c_opts.h"
int
-main(int argc, const char* argv[])
+main(int argc,
+ const char* argv[])
{
- struct opts_s opts;
+ struct opts_s opts;
- c_opts(&opts, argc, argv);
+ c_get_opts(&opts, argc, argv);
if (opts.recursive == TRUE)
printf("Recursive\n");
if (opts.verbose == TRUE)
printf("Verbose\n");
if (opts.pretend == TRUE)
printf("Pretend\n");
+ if (opts.hidden == TRUE)
+ printf("Hidden\n");
+ if (opts.hyphen == TRUE)
+ printf("Hyphen\n");
return (0);
}