summaryrefslogtreecommitdiff
path: root/editors/patch.c
diff options
context:
space:
mode:
authorRob Landley2005-09-01 03:02:23 +0000
committerRob Landley2005-09-01 03:02:23 +0000
commit078bacf1e92fb8e9c44e020aca6d1c2a9362a24b (patch)
tree34dc66406b0e1e53c9be4c73d3fd919382455c85 /editors/patch.c
parente0537f6194cf37651c6e7ac3033226f09dab7557 (diff)
downloadbusybox-078bacf1e92fb8e9c44e020aca6d1c2a9362a24b.zip
busybox-078bacf1e92fb8e9c44e020aca6d1c2a9362a24b.tar.gz
Patch -i support from Berhnard Fischer.
Diffstat (limited to 'editors/patch.c')
-rw-r--r--editors/patch.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/editors/patch.c b/editors/patch.c
index 6a68d2e..59b7021 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -107,14 +107,24 @@ extern int patch_main(int argc, char **argv)
{
unsigned int patch_level = -1;
char *patch_line;
- int ret = 0;
+ int ret;
+ FILE *patch_file = NULL;
- /* Handle 'p' option */
- if (argv[1] && (argv[1][0] == '-') && (argv[1][1] == 'p')) {
- patch_level = atoi(&argv[1][2]);
+ {
+ char *p, *i;
+ ret = bb_getopt_ulflags(argc, argv, "p:i:", &p, &i);
+ if (ret & 1)
+ patch_level = bb_xgetularg10_bnd(p, -1, USHRT_MAX);
+ if (ret & 2) {
+ patch_file = bb_xfopen(i, "r");
+ }
+ ret = 0;
}
- patch_line = bb_get_line_from_file(stdin);
+ if (!patch_file)
+ patch_file = stdin;
+
+ patch_line = bb_get_line_from_file(patch_file);
while (patch_line) {
FILE *src_stream;
FILE *dst_stream;
@@ -133,14 +143,14 @@ extern int patch_main(int argc, char **argv)
*/
while (patch_line && strncmp(patch_line, "--- ", 4) != 0) {
free(patch_line);
- patch_line = bb_get_line_from_file(stdin);
+ patch_line = bb_get_line_from_file(patch_file);
}
/* Extract the filename used before the patch was generated */
original_filename = extract_filename(patch_line, patch_level);
free(patch_line);
- patch_line = bb_get_line_from_file(stdin);
+ patch_line = bb_get_line_from_file(patch_file);
if (strncmp(patch_line, "+++ ", 4) != 0) {
ret = 2;
bb_error_msg("Invalid patch");
@@ -183,7 +193,7 @@ extern int patch_main(int argc, char **argv)
printf("patching file %s\n", new_filename);
/* Handle each hunk */
- patch_line = bb_get_line_from_file(stdin);
+ patch_line = bb_get_line_from_file(patch_file);
while (patch_line) {
unsigned int count;
unsigned int src_beg_line;
@@ -214,7 +224,7 @@ extern int patch_main(int argc, char **argv)
}
hunk_offset_start = src_cur_line;
- while ((patch_line = bb_get_line_from_file(stdin)) != NULL) {
+ while ((patch_line = bb_get_line_from_file(patch_file)) != NULL) {
if ((*patch_line == '-') || (*patch_line == ' ')) {
char *src_line = NULL;
if (src_stream) {