diff options
author | Mark Whitley <markw@lineo.com> | 2001-03-13 00:40:19 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2001-03-13 00:40:19 +0000 |
commit | e0bf91d7c612619526772605890538f0c3e44c05 (patch) | |
tree | 468e0e8126f57b7be69f471ed3ac046a9f8fedb4 | |
parent | 53737c5421b2356ead7659249000daac7c1aea21 (diff) | |
download | busybox-w32-e0bf91d7c612619526772605890538f0c3e44c05.tar.gz busybox-w32-e0bf91d7c612619526772605890538f0c3e44c05.tar.bz2 busybox-w32-e0bf91d7c612619526772605890538f0c3e44c05.zip |
Applied patch from Christophe Boyanique to add -i support to rm.
-rw-r--r-- | Config.h | 3 | ||||
-rw-r--r-- | Config.h.Hurd | 3 | ||||
-rw-r--r-- | applets/usage.h | 6 | ||||
-rw-r--r-- | busybox.h | 4 | ||||
-rw-r--r-- | coreutils/rm.c | 25 | ||||
-rw-r--r-- | docs/busybox.sgml | 1 | ||||
-rw-r--r-- | include/busybox.h | 4 | ||||
-rw-r--r-- | include/usage.h | 6 | ||||
-rw-r--r-- | rm.c | 25 | ||||
-rw-r--r-- | usage.h | 6 | ||||
-rw-r--r-- | utility.c | 18 |
11 files changed, 101 insertions, 0 deletions
@@ -224,6 +224,9 @@ | |||
224 | // (i.e. in case of an unreachable NFS system). | 224 | // (i.e. in case of an unreachable NFS system). |
225 | #define BB_FEATURE_MOUNT_FORCE | 225 | #define BB_FEATURE_MOUNT_FORCE |
226 | // | 226 | // |
227 | // use -i (interactive) flag for rm | ||
228 | //#define BB_FEATURE_RM_INTERACTIVE | ||
229 | // | ||
227 | // Enable support for creation of tar files. | 230 | // Enable support for creation of tar files. |
228 | #define BB_FEATURE_TAR_CREATE | 231 | #define BB_FEATURE_TAR_CREATE |
229 | // | 232 | // |
diff --git a/Config.h.Hurd b/Config.h.Hurd index 9238761a2..0320f8ab2 100644 --- a/Config.h.Hurd +++ b/Config.h.Hurd | |||
@@ -212,6 +212,9 @@ | |||
212 | // (i.e. in case of an unreachable NFS system). | 212 | // (i.e. in case of an unreachable NFS system). |
213 | #define BB_FEATURE_MOUNT_FORCE | 213 | #define BB_FEATURE_MOUNT_FORCE |
214 | // | 214 | // |
215 | // use -i (interactive) flag for rm | ||
216 | //#define BB_FEATURE_RM_INTERACTIVE | ||
217 | // | ||
215 | // Enable support for creation of tar files. | 218 | // Enable support for creation of tar files. |
216 | #define BB_FEATURE_TAR_CREATE | 219 | #define BB_FEATURE_TAR_CREATE |
217 | // | 220 | // |
diff --git a/applets/usage.h b/applets/usage.h index f241d3a04..f316018c8 100644 --- a/applets/usage.h +++ b/applets/usage.h | |||
@@ -821,12 +821,18 @@ | |||
821 | #define reset_full_usage \ | 821 | #define reset_full_usage \ |
822 | "Resets the screen." | 822 | "Resets the screen." |
823 | 823 | ||
824 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
825 | #define USAGE_RM_INTERACTIVE(a) a | ||
826 | #else | ||
827 | #define USAGE_RM_INTERACTIVE(a) | ||
828 | #endif | ||
824 | #define rm_trivial_usage \ | 829 | #define rm_trivial_usage \ |
825 | "[OPTION]... FILE..." | 830 | "[OPTION]... FILE..." |
826 | #define rm_full_usage \ | 831 | #define rm_full_usage \ |
827 | "Remove (unlink) the FILE(s). You may use '--' to\n" \ | 832 | "Remove (unlink) the FILE(s). You may use '--' to\n" \ |
828 | "indicate that all following arguments are non-options.\n\n" \ | 833 | "indicate that all following arguments are non-options.\n\n" \ |
829 | "Options:\n" \ | 834 | "Options:\n" \ |
835 | USAGE_RM_INTERACTIVE("\t-i\t\talways prompt before removing each destinations\n") \ | ||
830 | "\t-f\t\tremove existing destinations, never prompt\n" \ | 836 | "\t-f\t\tremove existing destinations, never prompt\n" \ |
831 | "\t-r or -R\tremove the contents of directories recursively" | 837 | "\t-r or -R\tremove the contents of directories recursively" |
832 | 838 | ||
@@ -255,4 +255,8 @@ enum { | |||
255 | #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len) | 255 | #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len) |
256 | #endif | 256 | #endif |
257 | 257 | ||
258 | #if defined(BB_FEATURE_RM_INTERACTIVE) && defined(BB_RM) | ||
259 | int ask_confirmation(void); | ||
260 | #endif | ||
261 | |||
258 | #endif /* _BB_INTERNAL_H_ */ | 262 | #endif /* _BB_INTERNAL_H_ */ |
diff --git a/coreutils/rm.c b/coreutils/rm.c index a84163272..6d92b5daa 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c | |||
@@ -33,11 +33,21 @@ | |||
33 | 33 | ||
34 | static int recursiveFlag = FALSE; | 34 | static int recursiveFlag = FALSE; |
35 | static int forceFlag = FALSE; | 35 | static int forceFlag = FALSE; |
36 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
37 | static int interactiveFlag = FALSE; | ||
38 | #endif | ||
36 | static const char *srcName; | 39 | static const char *srcName; |
37 | 40 | ||
38 | 41 | ||
39 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | 42 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) |
40 | { | 43 | { |
44 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
45 | if (interactiveFlag == TRUE) { | ||
46 | printf("rm: remove `%s'? ", fileName); | ||
47 | if (ask_confirmation() == 0) | ||
48 | return (TRUE); | ||
49 | } | ||
50 | #endif | ||
41 | if (unlink(fileName) < 0) { | 51 | if (unlink(fileName) < 0) { |
42 | perror_msg("%s", fileName); | 52 | perror_msg("%s", fileName); |
43 | return (FALSE); | 53 | return (FALSE); |
@@ -52,6 +62,13 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk) | |||
52 | perror_msg("%s", fileName); | 62 | perror_msg("%s", fileName); |
53 | return (FALSE); | 63 | return (FALSE); |
54 | } | 64 | } |
65 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
66 | if (interactiveFlag == TRUE) { | ||
67 | printf("rm: remove directory `%s'? ", fileName); | ||
68 | if (ask_confirmation() == 0) | ||
69 | return (TRUE); | ||
70 | } | ||
71 | #endif | ||
55 | if (rmdir(fileName) < 0) { | 72 | if (rmdir(fileName) < 0) { |
56 | perror_msg("%s", fileName); | 73 | perror_msg("%s", fileName); |
57 | return (FALSE); | 74 | return (FALSE); |
@@ -79,6 +96,14 @@ extern int rm_main(int argc, char **argv) | |||
79 | break; | 96 | break; |
80 | case 'f': | 97 | case 'f': |
81 | forceFlag = TRUE; | 98 | forceFlag = TRUE; |
99 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
100 | interactiveFlag = FALSE; | ||
101 | #endif | ||
102 | break; | ||
103 | case 'i': | ||
104 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
105 | interactiveFlag = TRUE; | ||
106 | #endif | ||
82 | break; | 107 | break; |
83 | case '-': | 108 | case '-': |
84 | stopIt = TRUE; | 109 | stopIt = TRUE; |
diff --git a/docs/busybox.sgml b/docs/busybox.sgml index 02d85e499..f794f896c 100644 --- a/docs/busybox.sgml +++ b/docs/busybox.sgml | |||
@@ -2728,6 +2728,7 @@ | |||
2728 | 2728 | ||
2729 | <para> | 2729 | <para> |
2730 | <screen> | 2730 | <screen> |
2731 | -i Always prompt before removing each destinations | ||
2731 | -f Remove existing destinations, never prompt | 2732 | -f Remove existing destinations, never prompt |
2732 | -r or -R Remove the contents of directories recursively | 2733 | -r or -R Remove the contents of directories recursively |
2733 | </screen> | 2734 | </screen> |
diff --git a/include/busybox.h b/include/busybox.h index abf62410f..7ae648501 100644 --- a/include/busybox.h +++ b/include/busybox.h | |||
@@ -255,4 +255,8 @@ enum { | |||
255 | #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len) | 255 | #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len) |
256 | #endif | 256 | #endif |
257 | 257 | ||
258 | #if defined(BB_FEATURE_RM_INTERACTIVE) && defined(BB_RM) | ||
259 | int ask_confirmation(void); | ||
260 | #endif | ||
261 | |||
258 | #endif /* _BB_INTERNAL_H_ */ | 262 | #endif /* _BB_INTERNAL_H_ */ |
diff --git a/include/usage.h b/include/usage.h index f241d3a04..f316018c8 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -821,12 +821,18 @@ | |||
821 | #define reset_full_usage \ | 821 | #define reset_full_usage \ |
822 | "Resets the screen." | 822 | "Resets the screen." |
823 | 823 | ||
824 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
825 | #define USAGE_RM_INTERACTIVE(a) a | ||
826 | #else | ||
827 | #define USAGE_RM_INTERACTIVE(a) | ||
828 | #endif | ||
824 | #define rm_trivial_usage \ | 829 | #define rm_trivial_usage \ |
825 | "[OPTION]... FILE..." | 830 | "[OPTION]... FILE..." |
826 | #define rm_full_usage \ | 831 | #define rm_full_usage \ |
827 | "Remove (unlink) the FILE(s). You may use '--' to\n" \ | 832 | "Remove (unlink) the FILE(s). You may use '--' to\n" \ |
828 | "indicate that all following arguments are non-options.\n\n" \ | 833 | "indicate that all following arguments are non-options.\n\n" \ |
829 | "Options:\n" \ | 834 | "Options:\n" \ |
835 | USAGE_RM_INTERACTIVE("\t-i\t\talways prompt before removing each destinations\n") \ | ||
830 | "\t-f\t\tremove existing destinations, never prompt\n" \ | 836 | "\t-f\t\tremove existing destinations, never prompt\n" \ |
831 | "\t-r or -R\tremove the contents of directories recursively" | 837 | "\t-r or -R\tremove the contents of directories recursively" |
832 | 838 | ||
@@ -33,11 +33,21 @@ | |||
33 | 33 | ||
34 | static int recursiveFlag = FALSE; | 34 | static int recursiveFlag = FALSE; |
35 | static int forceFlag = FALSE; | 35 | static int forceFlag = FALSE; |
36 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
37 | static int interactiveFlag = FALSE; | ||
38 | #endif | ||
36 | static const char *srcName; | 39 | static const char *srcName; |
37 | 40 | ||
38 | 41 | ||
39 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | 42 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) |
40 | { | 43 | { |
44 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
45 | if (interactiveFlag == TRUE) { | ||
46 | printf("rm: remove `%s'? ", fileName); | ||
47 | if (ask_confirmation() == 0) | ||
48 | return (TRUE); | ||
49 | } | ||
50 | #endif | ||
41 | if (unlink(fileName) < 0) { | 51 | if (unlink(fileName) < 0) { |
42 | perror_msg("%s", fileName); | 52 | perror_msg("%s", fileName); |
43 | return (FALSE); | 53 | return (FALSE); |
@@ -52,6 +62,13 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk) | |||
52 | perror_msg("%s", fileName); | 62 | perror_msg("%s", fileName); |
53 | return (FALSE); | 63 | return (FALSE); |
54 | } | 64 | } |
65 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
66 | if (interactiveFlag == TRUE) { | ||
67 | printf("rm: remove directory `%s'? ", fileName); | ||
68 | if (ask_confirmation() == 0) | ||
69 | return (TRUE); | ||
70 | } | ||
71 | #endif | ||
55 | if (rmdir(fileName) < 0) { | 72 | if (rmdir(fileName) < 0) { |
56 | perror_msg("%s", fileName); | 73 | perror_msg("%s", fileName); |
57 | return (FALSE); | 74 | return (FALSE); |
@@ -79,6 +96,14 @@ extern int rm_main(int argc, char **argv) | |||
79 | break; | 96 | break; |
80 | case 'f': | 97 | case 'f': |
81 | forceFlag = TRUE; | 98 | forceFlag = TRUE; |
99 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
100 | interactiveFlag = FALSE; | ||
101 | #endif | ||
102 | break; | ||
103 | case 'i': | ||
104 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
105 | interactiveFlag = TRUE; | ||
106 | #endif | ||
82 | break; | 107 | break; |
83 | case '-': | 108 | case '-': |
84 | stopIt = TRUE; | 109 | stopIt = TRUE; |
@@ -821,12 +821,18 @@ | |||
821 | #define reset_full_usage \ | 821 | #define reset_full_usage \ |
822 | "Resets the screen." | 822 | "Resets the screen." |
823 | 823 | ||
824 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
825 | #define USAGE_RM_INTERACTIVE(a) a | ||
826 | #else | ||
827 | #define USAGE_RM_INTERACTIVE(a) | ||
828 | #endif | ||
824 | #define rm_trivial_usage \ | 829 | #define rm_trivial_usage \ |
825 | "[OPTION]... FILE..." | 830 | "[OPTION]... FILE..." |
826 | #define rm_full_usage \ | 831 | #define rm_full_usage \ |
827 | "Remove (unlink) the FILE(s). You may use '--' to\n" \ | 832 | "Remove (unlink) the FILE(s). You may use '--' to\n" \ |
828 | "indicate that all following arguments are non-options.\n\n" \ | 833 | "indicate that all following arguments are non-options.\n\n" \ |
829 | "Options:\n" \ | 834 | "Options:\n" \ |
835 | USAGE_RM_INTERACTIVE("\t-i\t\talways prompt before removing each destinations\n") \ | ||
830 | "\t-f\t\tremove existing destinations, never prompt\n" \ | 836 | "\t-f\t\tremove existing destinations, never prompt\n" \ |
831 | "\t-r or -R\tremove the contents of directories recursively" | 837 | "\t-r or -R\tremove the contents of directories recursively" |
832 | 838 | ||
@@ -1859,6 +1859,24 @@ void trim(char *s) | |||
1859 | } | 1859 | } |
1860 | #endif | 1860 | #endif |
1861 | 1861 | ||
1862 | #ifdef BB_FEATURE_RM_INTERACTIVE | ||
1863 | #if defined (BB_CP_MV) || defined (BB_RM) | ||
1864 | int ask_confirmation() | ||
1865 | { | ||
1866 | int c = '\0'; | ||
1867 | int ret = 0; | ||
1868 | |||
1869 | while (c != '\n') { | ||
1870 | c = getchar(); | ||
1871 | if ( c != '\n' ) { | ||
1872 | ret = ((c=='y')||(c=='Y')) ? 1 : 0; | ||
1873 | } | ||
1874 | } | ||
1875 | return ret; | ||
1876 | } | ||
1877 | #endif | ||
1878 | #endif | ||
1879 | |||
1862 | /* END CODE */ | 1880 | /* END CODE */ |
1863 | /* | 1881 | /* |
1864 | Local Variables: | 1882 | Local Variables: |