From 1864ad281e31f79b1b2b3fd2cdc98cea98adf165 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 8 Feb 2016 23:21:04 -0500 Subject: [PATCH] minor delete tweaks --- Delete-flags.c | 4 ++-- Delete.c | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Delete-flags.c b/Delete-flags.c index 0d435de..d164d46 100644 --- a/Delete-flags.c +++ b/Delete-flags.c @@ -66,7 +66,7 @@ int FlagsParse(int argc, char **argv) { case 'h': FlagsHelp(); - break; + exit(0); case 'y': case 'Y': flags._y = 1; @@ -89,7 +89,7 @@ int FlagsParse(int argc, char **argv) break; default: - fprintf(stderr, "illegal option -- %c\n", c); + fprintf(stderr, "### Delete - \"-%c\" is not an option.", c); exit(1); } diff --git a/Delete.c b/Delete.c index 8eb6a6a..6fe263c 100644 --- a/Delete.c +++ b/Delete.c @@ -88,9 +88,21 @@ int prompt(const char *file) { first = ch = getchar(); while (ch != '\n' && ch != EOF) ch = getchar(); if (first == 'y' || first == 'Y') return 1; + if (first == 'c' || first == 'C') return -1; return 0; } +int check(const char *name) { + int m = mode(name); + if (m != 2 || flags._y) return 1; + + // directory. + if (flags._n) return 0; + if (flags._c) return -1; + + return prompt(name); +} + static char error_message[255]; int main(int argc, char **argv) { @@ -118,20 +130,16 @@ int main(int argc, char **argv) { for (i = 1 ; i < argc; ++i) { OSErr err; - int m; + int st; char *file = argv[i]; char *p = c2p(file); // todo -- y/n/c flags. - m = mode(p); - if (m == 2 && !flags._y) { - // directory... - if (flags._n) continue; - if (flags._c) { status = 4; break; } - - if (!prompt(file)) continue; - } + st = check(file); + if (st == 0) continue; + if (st == -1) { status = 4; break; } + err = FSDelete((unsigned char *)p, 0); if (err && !flags._i) {