diff --git a/usr.bin/diff/diff.1 b/usr.bin/diff/diff.1 --- a/usr.bin/diff/diff.1 +++ b/usr.bin/diff/diff.1 @@ -396,8 +396,8 @@ With unified and context diffs, show with each change the first 40 characters of the last line before the context beginning with a letter, an underscore or a dollar sign. -For C source code following standard layout conventions, this will -show the prototype of the function the change applies to. +For C and Objective-C source code following standard layout conventions, this +will show the prototype of the function the change applies to. .It Fl T -initial-tab Print a tab rather than a space before the rest of the line for the normal, context or unified output formats. diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1419,7 +1419,8 @@ strlcpy(lastbuf, buf, sizeof(lastbuf)); lastmatchline = pos; return (lastbuf); - } else if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') { + } else if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$' + || buf[0] == '-' || buf[0] == '+') { if (begins_with(buf, "private:")) { if (!state) state = " (private)"; diff --git a/usr.bin/diff/tests/Makefile b/usr.bin/diff/tests/Makefile --- a/usr.bin/diff/tests/Makefile +++ b/usr.bin/diff/tests/Makefile @@ -27,7 +27,14 @@ header_ns.out \ ifdef.out \ group-format.out \ - strip_o.out + strip_o.out \ + functionname.in \ + functionname_c.in \ + functionname_c.out \ + functionname_objcclassm.in \ + functionname_objcclassm.out \ + functionname_objcm.in \ + functionname_objcm.out NETBSD_ATF_TESTS_SH+= netbsd_diff_test diff --git a/usr.bin/diff/tests/diff_test.sh b/usr.bin/diff/tests/diff_test.sh --- a/usr.bin/diff/tests/diff_test.sh +++ b/usr.bin/diff/tests/diff_test.sh @@ -19,6 +19,7 @@ atf_test_case report_identical atf_test_case non_regular_file atf_test_case binary +atf_test_case functionname simple_body() { @@ -278,6 +279,23 @@ atf_check -o inline:"176c\nx\n.\n" -s exit:1 diff -ae A B } +functionname_body() +{ + atf_check -o empty -x "which diff" + + atf_check -o file:$(atf_get_srcdir)/functionname_c.out -s exit:1 \ + diff -u -p -L functionname.in -L functionname_c.in \ + "$(atf_get_srcdir)/functionname.in" "$(atf_get_srcdir)/functionname_c.in" + + atf_check -o file:$(atf_get_srcdir)/functionname_objcm.out -s exit:1 \ + diff -u -p -L functionname.in -L functionname_objcm.in \ + "$(atf_get_srcdir)/functionname.in" "$(atf_get_srcdir)/functionname_objcm.in" + + atf_check -o file:$(atf_get_srcdir)/functionname_objcclassm.out -s exit:1 \ + diff -u -p -L functionname.in -L functionname_objcclassm.in \ + "$(atf_get_srcdir)/functionname.in" "$(atf_get_srcdir)/functionname_objcclassm.in" +} + atf_init_test_cases() { atf_add_test_case simple @@ -299,4 +317,5 @@ atf_add_test_case report_identical atf_add_test_case non_regular_file atf_add_test_case binary + atf_add_test_case functionname } diff --git a/usr.bin/diff/tests/functionname.in b/usr.bin/diff/tests/functionname.in new file mode 100644 --- /dev/null +++ b/usr.bin/diff/tests/functionname.in @@ -0,0 +1,29 @@ +static void +doSomethingThenPrintHello(int test) +{ + test = test << 4; + if (test % 8 == 6) { + return; + } + + print("goodbye\n"); +} + + +- (long) readOffset:(FILE*)file +{ + if( version >= 11){ + long offset; + fread(&offset, sizeof(long), 1, file); + return offset; + } else { + int offset; + fread(&offset, sizeof(int), 1, file); + return offset; + } +} + ++ (BOOL) isEdible:(NSString *)mushroom +{ + return TRUE; +} diff --git a/usr.bin/diff/tests/functionname_c.in b/usr.bin/diff/tests/functionname_c.in new file mode 100644 --- /dev/null +++ b/usr.bin/diff/tests/functionname_c.in @@ -0,0 +1,29 @@ +static void +doSomethingThenPrintHello(int test) +{ + test = test << 4; + if (test % 8 == 6) { + return; + } + + print("hello\n"); +} + + +- (long) readOffset:(FILE*)file +{ + if( version >= 11){ + long offset; + fread(&offset, sizeof(long), 1, file); + return offset; + } else { + int offset; + fread(&offset, sizeof(int), 1, file); + return offset; + } +} + ++ (BOOL) isEdible:(NSString *)mushroom +{ + return TRUE; +} diff --git a/usr.bin/diff/tests/functionname_c.out b/usr.bin/diff/tests/functionname_c.out new file mode 100644 --- /dev/null +++ b/usr.bin/diff/tests/functionname_c.out @@ -0,0 +1,11 @@ +--- functionname.in ++++ functionname_c.in +@@ -6,7 +6,7 @@ doSomethingThenPrintHello(int test) + return; + } + +- print("goodbye\n"); ++ print("hello\n"); + } + + diff --git a/usr.bin/diff/tests/functionname_objcclassm.in b/usr.bin/diff/tests/functionname_objcclassm.in new file mode 100644 --- /dev/null +++ b/usr.bin/diff/tests/functionname_objcclassm.in @@ -0,0 +1,31 @@ +static void +doSomethingThenPrintHello(int test) +{ + test = test << 4; + if (test % 8 == 6) { + return; + } + + print("goodbye\n"); +} + + +- (long) readOffset:(FILE*)file +{ + if( version >= 11){ + long offset; + fread(&offset, sizeof(long), 1, file); + return offset; + } else { + int offset; + fread(&offset, sizeof(int), 1, file); + return offset; + } +} + ++ (BOOL) isEdible:(NSString *)mushroom +{ + /* With a solid guide book (such as Phillips 2006) assume we can't eat + * the fungus */ + return FALSE; +} diff --git a/usr.bin/diff/tests/functionname_objcclassm.out b/usr.bin/diff/tests/functionname_objcclassm.out new file mode 100644 --- /dev/null +++ b/usr.bin/diff/tests/functionname_objcclassm.out @@ -0,0 +1,11 @@ +--- functionname.in ++++ functionname_objcclassm.in +@@ -25,5 +25,7 @@ + (BOOL) isEdible:(NSString *)mushroom + + + (BOOL) isEdible:(NSString *)mushroom + { +- return TRUE; ++ /* With a solid guide book (such as Phillips 2006) assume we can't eat ++ * the fungus */ ++ return FALSE; + } diff --git a/usr.bin/diff/tests/functionname_objcm.in b/usr.bin/diff/tests/functionname_objcm.in new file mode 100644 --- /dev/null +++ b/usr.bin/diff/tests/functionname_objcm.in @@ -0,0 +1,29 @@ +static void +doSomethingThenPrintHello(int test) +{ + test = test << 4; + if (test % 8 == 6) { + return; + } + + print("goodbye\n"); +} + + +- (long) readOffset:(FILE*)file +{ + if( version >= 11){ + long offset; + fread(&offset, sizeof(long), 1, file); + return offset; + } else { + int offset; + fread(&offset-1, sizeof(int), 1, file); + return offset; + } +} + ++ (BOOL) isEdible:(NSString *)mushroom +{ + return TRUE; +} diff --git a/usr.bin/diff/tests/functionname_objcm.out b/usr.bin/diff/tests/functionname_objcm.out new file mode 100644 --- /dev/null +++ b/usr.bin/diff/tests/functionname_objcm.out @@ -0,0 +1,11 @@ +--- functionname.in ++++ functionname_objcm.in +@@ -18,7 +18,7 @@ - (long) readOffset:(FILE*)file + return offset; + } else { + int offset; +- fread(&offset, sizeof(int), 1, file); ++ fread(&offset-1, sizeof(int), 1, file); + return offset; + } + }