diff options
author | Rob Landley <rob@landley.net> | 2005-09-01 03:02:23 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-09-01 03:02:23 +0000 |
commit | 078bacf1e92fb8e9c44e020aca6d1c2a9362a24b (patch) | |
tree | 34dc66406b0e1e53c9be4c73d3fd919382455c85 | |
parent | e0537f6194cf37651c6e7ac3033226f09dab7557 (diff) | |
download | busybox-w32-078bacf1e92fb8e9c44e020aca6d1c2a9362a24b.tar.gz busybox-w32-078bacf1e92fb8e9c44e020aca6d1c2a9362a24b.tar.bz2 busybox-w32-078bacf1e92fb8e9c44e020aca6d1c2a9362a24b.zip |
Patch -i support from Berhnard Fischer.
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | editors/patch.c | 28 | ||||
-rw-r--r-- | include/usage.h | 8 |
3 files changed, 26 insertions, 14 deletions
@@ -39,8 +39,8 @@ fuser | |||
39 | Would be nice. The basic susv3 options, plus fuser -k. | 39 | Would be nice. The basic susv3 options, plus fuser -k. |
40 | --- | 40 | --- |
41 | patch | 41 | patch |
42 | should have -i support, and simple fuzz factor support to apply patches | 42 | should have simple fuzz factor support to apply patches at an offset which |
43 | at an offset shouldn't take up too much space. | 43 | shouldn't take up too much space. |
44 | --- | 44 | --- |
45 | man | 45 | man |
46 | It would be nice to have a man command. Not one that handles troff or | 46 | It would be nice to have a man command. Not one that handles troff or |
diff --git a/editors/patch.c b/editors/patch.c index 6a68d2ef8..59b70210f 100644 --- a/editors/patch.c +++ b/editors/patch.c | |||
@@ -107,14 +107,24 @@ extern int patch_main(int argc, char **argv) | |||
107 | { | 107 | { |
108 | unsigned int patch_level = -1; | 108 | unsigned int patch_level = -1; |
109 | char *patch_line; | 109 | char *patch_line; |
110 | int ret = 0; | 110 | int ret; |
111 | FILE *patch_file = NULL; | ||
111 | 112 | ||
112 | /* Handle 'p' option */ | 113 | { |
113 | if (argv[1] && (argv[1][0] == '-') && (argv[1][1] == 'p')) { | 114 | char *p, *i; |
114 | patch_level = atoi(&argv[1][2]); | 115 | ret = bb_getopt_ulflags(argc, argv, "p:i:", &p, &i); |
116 | if (ret & 1) | ||
117 | patch_level = bb_xgetularg10_bnd(p, -1, USHRT_MAX); | ||
118 | if (ret & 2) { | ||
119 | patch_file = bb_xfopen(i, "r"); | ||
120 | } | ||
121 | ret = 0; | ||
115 | } | 122 | } |
116 | 123 | ||
117 | patch_line = bb_get_line_from_file(stdin); | 124 | if (!patch_file) |
125 | patch_file = stdin; | ||
126 | |||
127 | patch_line = bb_get_line_from_file(patch_file); | ||
118 | while (patch_line) { | 128 | while (patch_line) { |
119 | FILE *src_stream; | 129 | FILE *src_stream; |
120 | FILE *dst_stream; | 130 | FILE *dst_stream; |
@@ -133,14 +143,14 @@ extern int patch_main(int argc, char **argv) | |||
133 | */ | 143 | */ |
134 | while (patch_line && strncmp(patch_line, "--- ", 4) != 0) { | 144 | while (patch_line && strncmp(patch_line, "--- ", 4) != 0) { |
135 | free(patch_line); | 145 | free(patch_line); |
136 | patch_line = bb_get_line_from_file(stdin); | 146 | patch_line = bb_get_line_from_file(patch_file); |
137 | } | 147 | } |
138 | 148 | ||
139 | /* Extract the filename used before the patch was generated */ | 149 | /* Extract the filename used before the patch was generated */ |
140 | original_filename = extract_filename(patch_line, patch_level); | 150 | original_filename = extract_filename(patch_line, patch_level); |
141 | free(patch_line); | 151 | free(patch_line); |
142 | 152 | ||
143 | patch_line = bb_get_line_from_file(stdin); | 153 | patch_line = bb_get_line_from_file(patch_file); |
144 | if (strncmp(patch_line, "+++ ", 4) != 0) { | 154 | if (strncmp(patch_line, "+++ ", 4) != 0) { |
145 | ret = 2; | 155 | ret = 2; |
146 | bb_error_msg("Invalid patch"); | 156 | bb_error_msg("Invalid patch"); |
@@ -183,7 +193,7 @@ extern int patch_main(int argc, char **argv) | |||
183 | printf("patching file %s\n", new_filename); | 193 | printf("patching file %s\n", new_filename); |
184 | 194 | ||
185 | /* Handle each hunk */ | 195 | /* Handle each hunk */ |
186 | patch_line = bb_get_line_from_file(stdin); | 196 | patch_line = bb_get_line_from_file(patch_file); |
187 | while (patch_line) { | 197 | while (patch_line) { |
188 | unsigned int count; | 198 | unsigned int count; |
189 | unsigned int src_beg_line; | 199 | unsigned int src_beg_line; |
@@ -214,7 +224,7 @@ extern int patch_main(int argc, char **argv) | |||
214 | } | 224 | } |
215 | hunk_offset_start = src_cur_line; | 225 | hunk_offset_start = src_cur_line; |
216 | 226 | ||
217 | while ((patch_line = bb_get_line_from_file(stdin)) != NULL) { | 227 | while ((patch_line = bb_get_line_from_file(patch_file)) != NULL) { |
218 | if ((*patch_line == '-') || (*patch_line == ' ')) { | 228 | if ((*patch_line == '-') || (*patch_line == ' ')) { |
219 | char *src_line = NULL; | 229 | char *src_line = NULL; |
220 | if (src_stream) { | 230 | if (src_stream) { |
diff --git a/include/usage.h b/include/usage.h index 662227818..9227025b2 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -2064,11 +2064,13 @@ | |||
2064 | "\t-u\tUnlocks (re-enables) the specified user account" | 2064 | "\t-u\tUnlocks (re-enables) the specified user account" |
2065 | 2065 | ||
2066 | #define patch_trivial_usage \ | 2066 | #define patch_trivial_usage \ |
2067 | "[-p<num>]" | 2067 | "[-p<num>] [-i<patch.diff>]" |
2068 | #define patch_full_usage \ | 2068 | #define patch_full_usage \ |
2069 | "[-p<num>]" | 2069 | "[-p<num>]\n" \ |
2070 | "[-i<diff>]" | ||
2070 | #define patch_example_usage \ | 2071 | #define patch_example_usage \ |
2071 | "$ patch -p1 <example.diff" | 2072 | "$ patch -p1 <example.diff\n" \ |
2073 | "$ patch -p0 -i example.diff" | ||
2072 | 2074 | ||
2073 | #define pidof_trivial_usage \ | 2075 | #define pidof_trivial_usage \ |
2074 | "process-name [OPTION] [process-name ...]" | 2076 | "process-name [OPTION] [process-name ...]" |