[PATCH] Adding -N option to the patch applet
Denys Vlasenko
vda.linux at googlemail.com
Wed Aug 19 17:52:38 UTC 2009
On Wed, Aug 19, 2009 at 5:55 PM, Olivier Duclos<olivier.duclos at gmail.com> wrote:
> Hi,
>
> This is my first contribution to Busybox. Be gentle.
>
> I have a lot of scripts that use things like 'patch -Np1 < file.patch' which doesn't work with busybox. Yet the N option is quite easy to implement. So I made a patch a patch to patch patch :D
>
> Tell me what you think.
+ int opt_N = 0;
xfunc_error_retval = 2;
{
const char *p = "-1";
const char *i = "-"; /* compat */
- if (getopt32(argv, "p:i:R", &p, &i) & 4)
+ unsigned int opt;
+ opt = getopt32(argv, "p:i:RN", &p, &i);
+ if (opt & 4)
plus = '-';
+ if (opt & 8)
+ opt_N = 1;
patch_level = xatoi(p); /* can be negative! */
patch_file = xfopen_stdin(i);
}
@@ -202,6 +207,10 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
src_line = NULL;
}
}
+ /* Do not patch an already
patched hunk with -N */
+ if (src_line == 0 && opt_N) {
+ continue;
+ }
You can eliminate opt_N variable. Just:
#define OPT_N 8
...
...
if (src_line == 0 && (opt & OPT_N)) ...
--
vda
More information about the busybox
mailing list