svn commit: trunk/busybox/coreutils

aldot at busybox.net aldot at busybox.net
Thu Apr 6 11:28:21 UTC 2006


Author: aldot
Date: 2006-04-06 04:28:19 -0700 (Thu, 06 Apr 2006)
New Revision: 14763

Log:
- shrink it a little bit and make it buildable with gcc-2.95
   text    data     bss     dec     hex filename
   7332       4      92    7428    1d04 diff.o-gcc-4.2-HEAD.orig
   7185       4      92    7281    1c71 diff.o-gcc-4.2-HEAD.new
   7336       4      92    7432    1d08 diff.o-gcc-4.1-HEAD.orig
   7148       4      92    7244    1c4c diff.o-gcc-4.1-HEAD.new
   7485       4      92    7581    1d9d diff.o-gcc-4.0.orig
   7318       4      92    7414    1cf6 diff.o-gcc-4.0.new
   7511       4      92    7607    1db7 diff.o-gcc-3.4.orig
   7252       4      92    7348    1cb4 diff.o-gcc-3.4.new
   8214       4      92    8310    2076 diff.o-gcc-3.3.orig
   7882       4      92    7978    1f2a diff.o-gcc-3.3.new
      -       -       -       -       - diff.o-gcc-2.95.orig
   8238       8      88    8334    208e diff.o-gcc-2.95.new


Modified:
   trunk/busybox/coreutils/diff.c


Changeset:
Modified: trunk/busybox/coreutils/diff.c
===================================================================
--- trunk/busybox/coreutils/diff.c	2006-04-06 08:23:11 UTC (rev 14762)
+++ trunk/busybox/coreutils/diff.c	2006-04-06 11:28:19 UTC (rev 14763)
@@ -154,47 +154,48 @@
 
 static void print_status(int val, char *path1, char *path2, char *entry)
 {
+	const char * const _entry = entry ? entry : "";
+	char *_path1 = entry ? concat_path_file(path1, _entry) : path1;
+	char *_path2 = entry ? concat_path_file(path2, _entry) : path2;
         switch (val) {
         case D_ONLY:
                 print_only(path1, strlen(path1), entry);
                 break;
         case D_COMMON:
-                printf("Common subdirectories: %s%s and %s%s\n",
-                    path1, entry ? entry : "", path2, entry ? entry : "");
+                printf("Common subdirectories: %s and %s\n", _path1, _path2);
                 break;
         case D_BINARY:
-                printf("Binary files %s%s and %s%s differ\n",
-                    path1, entry ? entry : "", path2, entry ? entry : "");
+                printf("Binary files %s and %s differ\n", _path1, _path2);
                 break;
         case D_DIFFER:
                 if (cmd_flags & FLAG_q)
-                        printf("Files %s%s and %s%s differ\n",
-                            path1, entry ? entry : "",
-                            path2, entry ? entry : "");
+                        printf("Files %s and %s differ\n", _path1, _path2);
                 break;
         case D_SAME:
                 if (cmd_flags & FLAG_s)
-                        printf("Files %s%s and %s%s are identical\n",
-                            path1, entry ? entry : "",
-                            path2, entry ? entry : "");
+                        printf("Files %s and %s are identical\n", _path1, _path2);
                 break;
         case D_MISMATCH1:
-                printf("File %s%s is a directory while file %s%s is a regular file\n",
-                    path1, entry ? entry : "", path2, entry ? entry : "");
+                printf("File %s is a directory while file %s is a regular file\n",
+                    _path1, _path2);
                 break;
         case D_MISMATCH2:
-                printf("File %s%s is a regular file while file %s%s is a directory\n",
-                    path1, entry ? entry : "", path2, entry ? entry : "");
+                printf("File %s is a regular file while file %s is a directory\n",
+                    _path1, _path2);
                 break;
         case D_SKIPPED1:
-                printf("File %s%s is not a regular file or directory and was skipped\n",
-                    path1, entry ? entry : "");
+                printf("File %s is not a regular file or directory and was skipped\n",
+                    _path1);
                 break;
         case D_SKIPPED2:
-                printf("File %s%s is not a regular file or directory and was skipped\n",
-                    path2, entry ? entry : "");
+                printf("File %s is not a regular file or directory and was skipped\n",
+                    _path2);
                 break;
         }
+		if (entry) {
+			free(_path1);
+			free(_path2);
+		}
 }
 
 /*
@@ -293,8 +294,8 @@
 static void prepare(int i, FILE *fd, off_t filesize)
 {
         struct line *p;
-        int j, h;
-        size_t sz;
+        int h;
+        size_t j, sz;
 
         rewind(fd);
 
@@ -671,13 +672,15 @@
 
 static int asciifile(FILE *f)
 {
+#ifdef CONFIG_FEATURE_DIFF_BINARY
+	unsigned char buf[BUFSIZ];
+	int i, cnt;
+#endif
 
 	if ((cmd_flags & FLAG_a) || f == NULL)
 		return (1);
+
 #ifdef CONFIG_FEATURE_DIFF_BINARY
-        unsigned char buf[BUFSIZ];
-        int i, cnt;
-
 	rewind(f);
         cnt = fread(buf, 1, sizeof(buf), f);
         for (i = 0; i < cnt; i++)
@@ -730,7 +733,7 @@
                         ch = 'c';
                 else
                         ch = (a <= b) ? 'd' : 'a';
-
+#if 0
                 switch (ch) {
                 case 'c':
                         fetch(ixold, lowa, a - 1, f1, ' ');
@@ -746,6 +749,16 @@
                         fetch(ixnew, c, d, f2, '+');
                         break;
                 }
+#else
+                if (ch == 'c' || ch == 'd') {
+                        fetch(ixold, lowa, a - 1, f1, ' ');
+                        fetch(ixold, a, b, f1, '-');
+				}
+                if (ch == 'a')
+                        fetch(ixnew, lowc, c - 1, f2, ' ');
+                if (ch == 'c' || ch == 'a')
+                        fetch(ixnew, c, d, f2, '+');
+#endif
                 lowa = b + 1;
                 lowc = d + 1;
         }
@@ -948,12 +961,9 @@
                         f2 = bb_xfopen(file2, "r");
         }
 	
-	switch (files_differ(f1, f2, flags)) {
-        case 0:
+	if ((i=files_differ(f1, f2, flags)) == 0)
                 goto closem;
-        case 1:
-                break;
-        default:
+	else if (i != 1) {/* 1 == ok */
                 /* error */
                 status |= 2;
                 goto closem;
@@ -1078,11 +1088,8 @@
 static char **get_dir(char *path) {
 
 	int i;
+	char **retval;
 
-	/* Reset dl_count - there's no need to free dl as bb_xrealloc does
-	 * the job nicely. */	
-	dl_count = 0;
-
 	/* If -r has been set, then the recursive_action function will be
 	 * used. Unfortunately, this outputs the root directory along with
 	 * the recursed paths, so use void *userdata to specify the string
@@ -1091,7 +1098,11 @@
 
 	int path_len = strlen(path);
 	void *userdata = &path_len;
-	
+
+	/* Reset dl_count - there's no need to free dl as bb_xrealloc does
+	 * the job nicely. */
+	dl_count = 0;
+
 	/* Now fill dl with a listing. */
 	if (cmd_flags & FLAG_r)
 		recursive_action(path, TRUE, TRUE, FALSE, add_to_dirlist, NULL, userdata);
@@ -1112,7 +1123,7 @@
 	qsort(dl, dl_count, sizeof(char *), dir_strcmp);
 
 	/* Copy dl so that we can return it. */
-	char **retval = xmalloc(dl_count * sizeof(char *));
+	retval = xmalloc(dl_count * sizeof(char *));
 	for (i = 0; i < dl_count; i++)
 		retval[i] = bb_xstrdup(dl[i]);
 




More information about the busybox-cvs mailing list