Patch -i support from Berhnard Fischer.
This commit is contained in:
parent
e0537f6194
commit
078bacf1e9
4
TODO
4
TODO
@ -39,8 +39,8 @@ fuser
|
|||||||
Would be nice. The basic susv3 options, plus fuser -k.
|
Would be nice. The basic susv3 options, plus fuser -k.
|
||||||
---
|
---
|
||||||
patch
|
patch
|
||||||
should have -i support, and simple fuzz factor support to apply patches
|
should have simple fuzz factor support to apply patches at an offset which
|
||||||
at an offset shouldn't take up too much space.
|
shouldn't take up too much space.
|
||||||
---
|
---
|
||||||
man
|
man
|
||||||
It would be nice to have a man command. Not one that handles troff or
|
It would be nice to have a man command. Not one that handles troff or
|
||||||
|
@ -107,14 +107,24 @@ extern int patch_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
unsigned int patch_level = -1;
|
unsigned int patch_level = -1;
|
||||||
char *patch_line;
|
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')) {
|
char *p, *i;
|
||||||
patch_level = atoi(&argv[1][2]);
|
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) {
|
while (patch_line) {
|
||||||
FILE *src_stream;
|
FILE *src_stream;
|
||||||
FILE *dst_stream;
|
FILE *dst_stream;
|
||||||
@ -133,14 +143,14 @@ extern int patch_main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
while (patch_line && strncmp(patch_line, "--- ", 4) != 0) {
|
while (patch_line && strncmp(patch_line, "--- ", 4) != 0) {
|
||||||
free(patch_line);
|
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 */
|
/* Extract the filename used before the patch was generated */
|
||||||
original_filename = extract_filename(patch_line, patch_level);
|
original_filename = extract_filename(patch_line, patch_level);
|
||||||
free(patch_line);
|
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) {
|
if (strncmp(patch_line, "+++ ", 4) != 0) {
|
||||||
ret = 2;
|
ret = 2;
|
||||||
bb_error_msg("Invalid patch");
|
bb_error_msg("Invalid patch");
|
||||||
@ -183,7 +193,7 @@ extern int patch_main(int argc, char **argv)
|
|||||||
printf("patching file %s\n", new_filename);
|
printf("patching file %s\n", new_filename);
|
||||||
|
|
||||||
/* Handle each hunk */
|
/* Handle each hunk */
|
||||||
patch_line = bb_get_line_from_file(stdin);
|
patch_line = bb_get_line_from_file(patch_file);
|
||||||
while (patch_line) {
|
while (patch_line) {
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
unsigned int src_beg_line;
|
unsigned int src_beg_line;
|
||||||
@ -214,7 +224,7 @@ extern int patch_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
hunk_offset_start = src_cur_line;
|
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 == ' ')) {
|
if ((*patch_line == '-') || (*patch_line == ' ')) {
|
||||||
char *src_line = NULL;
|
char *src_line = NULL;
|
||||||
if (src_stream) {
|
if (src_stream) {
|
||||||
|
@ -2064,11 +2064,13 @@
|
|||||||
"\t-u\tUnlocks (re-enables) the specified user account"
|
"\t-u\tUnlocks (re-enables) the specified user account"
|
||||||
|
|
||||||
#define patch_trivial_usage \
|
#define patch_trivial_usage \
|
||||||
"[-p<num>]"
|
"[-p<num>] [-i<patch.diff>]"
|
||||||
#define patch_full_usage \
|
#define patch_full_usage \
|
||||||
"[-p<num>]"
|
"[-p<num>]\n" \
|
||||||
|
"[-i<diff>]"
|
||||||
#define patch_example_usage \
|
#define patch_example_usage \
|
||||||
"$ patch -p1 <example.diff"
|
"$ patch -p1 <example.diff\n" \
|
||||||
|
"$ patch -p0 -i example.diff"
|
||||||
|
|
||||||
#define pidof_trivial_usage \
|
#define pidof_trivial_usage \
|
||||||
"process-name [OPTION] [process-name ...]"
|
"process-name [OPTION] [process-name ...]"
|
||||||
|
Loading…
Reference in New Issue
Block a user