From 382acc80353cd758fd07efc5d3e108ec365b21c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sat, 22 Jan 2005 23:00:57 +0000 Subject: [PATCH] add --restore option (acts as untrash) git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10970 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/trash.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/apps/bin/trash.cpp b/src/apps/bin/trash.cpp index 3b7f5d7d6a..610eb72955 100644 --- a/src/apps/bin/trash.cpp +++ b/src/apps/bin/trash.cpp @@ -24,9 +24,10 @@ static const char *kTrackerSig = "application/x-vnd.Be-TRAK"; int usage(int ret) { printf("\nSend files to trash, or restore them.\nUsage:\n"); - printf("trash [--empty|--list] file ...\n"); - printf("\t--empty\tempty the Trash\n"); - printf("\t--list\tlist what's already in the Trash\n"); + printf("trash [--restore|--empty|--list] file ...\n"); + printf("\t--restore\trestore files (act as untrash)\n"); + printf("\t--empty\t\tempty the Trash\n"); + printf("\t--list\t\tlist what's already in the Trash\n"); printf("untrash [--all] [file ...]\n"); //printf("restore [--all] [file ...]\n"); return ret; @@ -151,7 +152,7 @@ status_t foreach_in_trash(status_t (*iterator)(const char *)) int main(int argc, char **argv) { int dountrash = 0; - int i; + int i = 1; int err = 0; if (strstr(argv[0], "untrash") || strstr(argv[0], "restore")) dountrash = 1; @@ -159,6 +160,10 @@ int main(int argc, char **argv) return usage(1); if (!strcmp(argv[1], "--help")) return usage(0); + if (!strcmp(argv[1], "--restore")) { + dountrash = 1; + i++; + } if (!dountrash && !strcmp(argv[1], "--empty")) { /* XXX: clean that */ BMessage msg(B_DELETE_PROPERTY); @@ -171,7 +176,7 @@ int main(int argc, char **argv) } return 0; } - if (dountrash && !strcmp(argv[1], "--all")) { + if (dountrash && !strcmp(argv[i], "--all")) { /* restore all trashed files */ err = foreach_in_trash(untrash); if (err) { @@ -180,13 +185,13 @@ int main(int argc, char **argv) } return 0; } - if (!strcmp(argv[1], "--list")) { + if (!strcmp(argv[i], "--list")) { err = foreach_in_trash(show_trashed_file); return 0; } /* restore files... */ if (dountrash) { - for (i = 1; i < argc; i++) { + for (; i < argc; i++) { err = untrash(argv[i]); if (err) { fprintf(stderr, "%s: %s\n", argv[i], strerror(err));