libarchive: open_zipped() does not need to check extensions for e.g. gzip
[oweals/busybox.git] / editors / diff.c
index daa58af9b18ba0fbce3e4a5acbe3c7e159c95023..a78a0ee283732b359d4e001c09c519e9f264d909 100644 (file)
  * 6n words for files of length n.
  */
 
+//config:config DIFF
+//config:      bool "diff"
+//config:      default y
+//config:      help
+//config:        diff compares two files or directories and outputs the
+//config:        differences between them in a form that can be given to
+//config:        the patch command.
+//config:
+//config:config FEATURE_DIFF_LONG_OPTIONS
+//config:      bool "Enable long options"
+//config:      default y
+//config:      depends on DIFF && LONG_OPTS
+//config:      help
+//config:        Enable use of long options.
+//config:
+//config:config FEATURE_DIFF_DIR
+//config:      bool "Enable directory support"
+//config:      default y
+//config:      depends on DIFF
+//config:      help
+//config:        This option enables support for directory and subdirectory
+//config:        comparison.
+
+//kbuild:lib-$(CONFIG_DIFF) += diff.o
+
+//applet:IF_DIFF(APPLET(diff, BB_DIR_USR_BIN, BB_SUID_DROP))
+
 //usage:#define diff_trivial_usage
 //usage:       "[-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2"
 //usage:#define diff_full_usage "\n\n"
 //usage:       "Compare files line by line and output the differences between them.\n"
 //usage:       "This implementation supports unified diffs only.\n"
-//usage:     "\nOptions:"
 //usage:     "\n       -a      Treat all files as text"
 //usage:     "\n       -b      Ignore changes in the amount of whitespace"
 //usage:     "\n       -B      Ignore changes whose lines are all blank"
 #include "libbb.h"
 
 #if 0
-//#define dbg_error_msg(...) bb_error_msg(__VA_ARGS__)
+define dbg_error_msg(...) bb_error_msg(__VA_ARGS__)
 #else
-#define dbg_error_msg(...) ((void)0)
+# define dbg_error_msg(...) ((void)0)
 #endif
 
 enum {                  /* print_status() and diffreg() return values */
@@ -694,10 +720,12 @@ static bool diff(FILE* fp[2], char *file[2])
 
 static int diffreg(char *file[2])
 {
-       FILE *fp[2] = { stdin, stdin };
+       FILE *fp[2];
        bool binary = false, differ = false;
        int status = STATUS_SAME, i;
 
+       fp[0] = stdin;
+       fp[1] = stdin;
        for (i = 0; i < 2; i++) {
                int fd = open_or_warn_stdin(file[i]);
                if (fd == -1)
@@ -842,7 +870,7 @@ static void diffdir(char *p[2], const char *s_start)
                 * add_to_dirlist will remove it. */
                list[i].len = strlen(p[i]);
                recursive_action(p[i], ACTION_RECURSE | ACTION_FOLLOWLINKS,
-                                add_to_dirlist, skip_dir, &list[i], 0);
+                               add_to_dirlist, skip_dir, &list[i], 0);
                /* Sort dl alphabetically.
                 * GNU diff does this ignoring any number of trailing dots.
                 * We don't, so for us dotted files almost always are