Skip to content

Commit

Permalink
minor delete tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ksherlock committed Feb 9, 2016
1 parent ac2093c commit 1864ad2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Delete-flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int FlagsParse(int argc, char **argv)
{
case 'h':
FlagsHelp();
break;
exit(0);
case 'y':
case 'Y':
flags._y = 1;
Expand All @@ -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);
}

Expand Down
26 changes: 17 additions & 9 deletions Delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1864ad2

Please sign in to comment.