commit - 732e8ee0325715558a17b919a7f6a16bf64d66e3
commit + 527f2c8a94ec96cdf79504060f948ec88c070289
blob - 18dd0286fe53d332f4c991dc64386cf6d2a55003
blob + 1b73588ad91574f34bbc3bae3a71a2665b76aa8d
--- diff/diff.c
+++ diff/diff.c
#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);
}
{
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;
case 'w':
ignore_whitespace = true;
break;
+ case 'C':
+ context_lines = atoi(optarg);
+ break;
default:
usage();
}
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;
};
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;
#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);