Commit Diff


commit - 732e8ee0325715558a17b919a7f6a16bf64d66e3
commit + 527f2c8a94ec96cdf79504060f948ec88c070289
blob - 18dd0286fe53d332f4c991dc64386cf6d2a55003
blob + 1b73588ad91574f34bbc3bae3a71a2665b76aa8d
--- diff/diff.c
+++ diff/diff.c
@@ -43,17 +43,18 @@ static const char *getprogname()
 #endif
 
 __dead void	 usage(void);
-int		 diffreg(char *, char *, bool, bool);
+int		 diffreg(char *, char *, bool, bool, int);
 int		 openfile(const char *, char **, struct stat *);
 
 __dead void
 usage(void)
 {
 	fprintf(stderr,
-		"usage: %s [-pw] file1 file2\n"
+		"usage: %s [-pw] [-C n] file1 file2\n"
 		"\n"
 		"  -p   Use Patience Diff (slower but often nicer)\n"
 		"  -w   Ignore Whitespace\n"
+		"  -C n Number of Context Lines\n"
 		, getprogname());
 	exit(1);
 }
@@ -63,8 +64,9 @@ main(int argc, char *argv[])
 {
 	int ch, rc;
 	bool do_patience = false, ignore_whitespace = false;
+	int context_lines = 3;
 
-	while ((ch = getopt(argc, argv, "pw")) != -1) {
+	while ((ch = getopt(argc, argv, "pwC:")) != -1) {
 		switch (ch) {
 		case 'p':
 			do_patience = true;
@@ -72,6 +74,9 @@ main(int argc, char *argv[])
 		case 'w':
 			ignore_whitespace = true;
 			break;
+		case 'C':
+			context_lines = atoi(optarg);
+			break;
 		default:
 			usage();
 		}
@@ -83,7 +88,8 @@ main(int argc, char *argv[])
 	if (argc != 2)
 		usage();
 
-	rc = diffreg(argv[0], argv[1], do_patience, ignore_whitespace);
+	rc = diffreg(argv[0], argv[1], do_patience, ignore_whitespace,
+	    context_lines);
 	if (rc != DIFF_RC_OK) {
 		fprintf(stderr, "diff: %s\n", strerror(rc));
 		return 1;
@@ -135,7 +141,8 @@ const struct diff_config diff_config_patience = {
 };
 
 int
-diffreg(char *file1, char *file2, bool do_patience, bool ignore_whitespace)
+diffreg(char *file1, char *file2, bool do_patience, bool ignore_whitespace,
+    int context_lines)
 {
 	char *str1, *str2;
 	int fd1, fd2;
@@ -158,7 +165,7 @@ diffreg(char *file1, char *file2, bool do_patience, bo
 #if 0
 	rc = diff_output_plain(stdout, &info, result);
 #else
-	rc = diff_output_unidiff(stdout, &info, result, 3);
+	rc = diff_output_unidiff(stdout, &info, result, context_lines);
 #endif
 	diff_result_free(result);