diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-03-19 18:52:37 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-03-19 18:52:37 +0000 |
commit | 7c25441792a0685a1eb27c6563ed293e505f5b2c (patch) | |
tree | 7f6690b321500b3dbd2b00d347d550937bed5369 /coreutils | |
parent | c75586e06d77ff82262e2199ccb5b2863b42caf3 (diff) | |
download | busybox-w32-7c25441792a0685a1eb27c6563ed293e505f5b2c.tar.gz busybox-w32-7c25441792a0685a1eb27c6563ed293e505f5b2c.tar.bz2 busybox-w32-7c25441792a0685a1eb27c6563ed293e505f5b2c.zip |
getopt-ify rm so that BB_FEATURE_RM_INTERACTIVE will work
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/rm.c | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/coreutils/rm.c b/coreutils/rm.c index f1152eab3..96808aee8 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <errno.h> | 33 | #include <errno.h> |
34 | #include <unistd.h> | 34 | #include <unistd.h> |
35 | #include <stdlib.h> | 35 | #include <stdlib.h> |
36 | #include <getopt.h> | ||
36 | #include "busybox.h" | 37 | #include "busybox.h" |
37 | 38 | ||
38 | static int recursiveFlag = FALSE; | 39 | static int recursiveFlag = FALSE; |
@@ -82,52 +83,48 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk) | |||
82 | 83 | ||
83 | extern int rm_main(int argc, char **argv) | 84 | extern int rm_main(int argc, char **argv) |
84 | { | 85 | { |
86 | int opt; | ||
85 | int status = EXIT_SUCCESS; | 87 | int status = EXIT_SUCCESS; |
86 | int stopIt=FALSE; | 88 | int stopIt=FALSE; |
87 | struct stat statbuf; | 89 | struct stat statbuf; |
88 | 90 | ||
89 | argc--; | 91 | |
90 | argv++; | 92 | /* do normal option parsing */ |
91 | 93 | while ((opt = getopt(argc, argv, "Rrf-" | |
92 | /* Parse any options */ | ||
93 | while (argc > 0 && stopIt == FALSE) { | ||
94 | if (**argv == '-') { | ||
95 | while (*++(*argv)) | ||
96 | switch (**argv) { | ||
97 | case 'R': | ||
98 | case 'r': | ||
99 | recursiveFlag = TRUE; | ||
100 | break; | ||
101 | case 'f': | ||
102 | forceFlag = TRUE; | ||
103 | #ifdef BB_FEATURE_RM_INTERACTIVE | 94 | #ifdef BB_FEATURE_RM_INTERACTIVE |
104 | interactiveFlag = FALSE; | 95 | "i" |
105 | #endif | 96 | #endif |
106 | break; | 97 | )) > 0) { |
107 | case 'i': | 98 | switch (opt) { |
99 | case 'R': | ||
100 | case 'r': | ||
101 | recursiveFlag = TRUE; | ||
102 | break; | ||
103 | case 'f': | ||
104 | forceFlag = TRUE; | ||
108 | #ifdef BB_FEATURE_RM_INTERACTIVE | 105 | #ifdef BB_FEATURE_RM_INTERACTIVE |
109 | interactiveFlag = TRUE; | 106 | interactiveFlag = FALSE; |
110 | #endif | 107 | #endif |
111 | break; | 108 | break; |
112 | case '-': | 109 | case 'i': |
113 | stopIt = TRUE; | 110 | #ifdef BB_FEATURE_RM_INTERACTIVE |
114 | break; | 111 | interactiveFlag = TRUE; |
115 | default: | 112 | #endif |
116 | show_usage(); | 113 | break; |
117 | } | 114 | case '-': |
118 | argc--; | 115 | stopIt = TRUE; |
119 | argv++; | 116 | break; |
117 | default: | ||
118 | show_usage(); | ||
120 | } | 119 | } |
121 | else | ||
122 | break; | ||
123 | } | 120 | } |
124 | 121 | ||
125 | if (argc < 1 && forceFlag == FALSE) { | 122 | if ((argc-optind) < 1 && forceFlag == FALSE) { |
126 | show_usage(); | 123 | show_usage(); |
127 | } | 124 | } |
128 | 125 | ||
129 | while (argc-- > 0) { | 126 | while (optind < argc) { |
130 | srcName = *(argv++); | 127 | srcName = argv[optind]; |
131 | if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 | 128 | if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 |
132 | && errno == ENOENT) { | 129 | && errno == ENOENT) { |
133 | /* do not reports errors for non-existent files if -f, just skip them */ | 130 | /* do not reports errors for non-existent files if -f, just skip them */ |
@@ -137,6 +134,7 @@ extern int rm_main(int argc, char **argv) | |||
137 | status = EXIT_FAILURE; | 134 | status = EXIT_FAILURE; |
138 | } | 135 | } |
139 | } | 136 | } |
137 | optind++; | ||
140 | } | 138 | } |
141 | return status; | 139 | return status; |
142 | } | 140 | } |