Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Jul 2008 14:53:27 GMT
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 145974 for review
Message-ID:  <200807261453.m6QErRl1001770@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=145974

Change 145974 by gabor@gabor_server on 2008/07/26 14:52:37

	- Reimplement --from-file and --to-file

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/diff/diff.c#14 edit

Differences ...

==== //depot/projects/soc2008/gabor_textproc/diff/diff.c#14 (text+ko) ====

@@ -135,7 +135,7 @@
 int
 main(int argc, char **argv)
 {
-	char	*ep, *fromfile = NULL, *tofile = NULL, **oargv;
+	char	*ep, *fromfile = NULL, *tofile = NULL, **oargv, *src, *dst;
 	int	 ch, lastch, gotstdin, prevoptind, newarg, flags = 0;
 
 	setlocale(LC_ALL, "");
@@ -320,19 +320,21 @@
 				errx(2, "%s", buf);
 		}
 	}
-	if (strcmp(argv[0], "-") == 0) {
+	src = fromfile ? fromfile : argv[0];
+	dst = fromfile ? argv[0] : (tofile ? tofile : argv[1]);
+	if (strcmp(src, "-") == 0) {
 		fstat(STDIN_FILENO, &stb1);
 		gotstdin = 1;
-	} else if (stat(argv[0], &stb1) != 0) {
+	} else if (stat(src, &stb1) != 0) {
 		if (uniflag)
 			flags |= D_EMPTY1;
 		else
 			err(2, "%s", argv[0]);
 	}
-	if (strcmp(argv[1], "-") == 0) {
+	if (strcmp(dst, "-") == 0) {
 		fstat(STDIN_FILENO, &stb2);
 		gotstdin = 1;
-	} else if (stat(argv[1], &stb2) != 0)
+	} else if (stat(dst, &stb2) != 0)
 		err(2, "%s", argv[1]);
 	if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode)))
 		errx(2, "can't compare - to a directory");
@@ -340,19 +342,19 @@
 	if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
 		if (format == D_IFDEF)
 			errx(2, "-D option not supported with directories");
-		diffdir(argv[0], argv[1]);
+		diffdir(src, dst);
 	} else {
 		if (S_ISDIR(stb1.st_mode)) {
-			argv[0] = splice(argv[0], argv[1]);
-			if (stat(argv[0], &stb1) < 0)
-				err(2, "%s", argv[0]);
+			src = splice(src, dst);
+			if (stat(src, &stb1) < 0)
+				err(2, "%s", src);
 		}
 		if (S_ISDIR(stb2.st_mode)) {
-			argv[1] = splice(argv[1], argv[0]);
-			if (stat(argv[1], &stb2) < 0)
-				err(2, "%s", argv[1]);
+			dst = splice(dst, src);
+			if (stat(dst, &stb2) < 0)
+				err(2, "%s", dst);
 		}
-		print_status(diffreg(argv[0], argv[1], flags), argv[0], argv[1],
+		print_status(diffreg(src, dst, flags), src, dst,
 		    NULL);
 	}
 	exit(status);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807261453.m6QErRl1001770>