Index: diff.c =================================================================== --- diff.c (revision 357993) +++ diff.c (working copy) @@ -100,6 +100,7 @@ }; void usage(void) __dead2; +void conflicting_format(void) __dead2; void push_excludes(char *); void push_ignore_pats(char *); void read_excludes_file(char *file); @@ -141,6 +142,8 @@ break; case 'C': case 'c': + if (diff_format != D_NORMAL) + conflicting_format(); cflag = 1; diff_format = D_CONTEXT; if (optarg != NULL) { @@ -154,13 +157,19 @@ dflags |= D_MINIMAL; break; case 'D': + if (diff_format != D_NORMAL) + conflicting_format(); diff_format = D_IFDEF; ifdefname = optarg; break; case 'e': + if (diff_format != D_NORMAL) + conflicting_format(); diff_format = D_EDIT; break; case 'f': + if (diff_format != D_NORMAL) + conflicting_format(); diff_format = D_REVERSE; break; case 'H': @@ -193,10 +202,12 @@ Nflag = 1; break; case 'n': + if (diff_format != D_NORMAL) + conflicting_format(); diff_format = D_NREVERSE; break; case 'p': - if (diff_format == 0) + if (diff_format == D_NORMAL) diff_format = D_CONTEXT; dflags |= D_PROTOTYPE; break; @@ -207,6 +218,8 @@ rflag = 1; break; case 'q': + if (diff_format != D_NORMAL) + conflicting_format(); diff_format = D_BRIEF; break; case 'S': @@ -223,6 +236,8 @@ break; case 'U': case 'u': + if (diff_format != D_NORMAL) + conflicting_format(); diff_format = D_UNIFIED; if (optarg != NULL) { l = strtol(optarg, &ep, 10); @@ -249,9 +264,13 @@ push_excludes(optarg); break; case 'y': + if (diff_format != D_NORMAL) + conflicting_format(); diff_format = D_SIDEBYSIDE; break; case OPT_CHANGED_GROUP_FORMAT: + if (diff_format != D_NORMAL) + conflicting_format(); diff_format = D_GFORMAT; group_format = optarg; break; @@ -491,3 +510,10 @@ exit(2); } + +void +conflicting_format(void) +{ + fprintf(stderr, "error: conflicting output format options.\n"); + usage(); +} Index: tests/diff_test.sh =================================================================== --- tests/diff_test.sh (revision 357993) +++ tests/diff_test.sh (working copy) @@ -11,6 +11,7 @@ atf_test_case b230049 atf_test_case Bflag atf_test_case tabsize +atf_test_case conflicting_format simple_body() { @@ -49,8 +50,6 @@ { atf_check -o file:$(atf_get_srcdir)/unified_p.out -s eq:1 \ diff -up -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" - atf_check -o file:$(atf_get_srcdir)/unified_c9999.out -s eq:1 \ - diff -u -c9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" atf_check -o file:$(atf_get_srcdir)/unified_9999.out -s eq:1 \ diff -u9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" } @@ -175,6 +174,18 @@ diff -t --tabsize 1 A B } +conflicting_format_body() +{ + printf "\tA\n" > A + printf "\tB\n" > B + + atf_check -s exit:2 -e ignore diff -c -u A B + atf_check -s exit:2 -e ignore diff -e -f A B + atf_check -s exit:2 -e ignore diff -y -q A B + atf_check -s exit:2 -e ignore diff -q -u A B + atf_check -s exit:2 -e ignore diff -q -c A B +} + atf_init_test_cases() { atf_add_test_case simple @@ -188,4 +199,5 @@ atf_add_test_case b230049 atf_add_test_case Bflag atf_add_test_case tabsize + atf_add_test_case conflicting_format }