summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Santolaria <xsa@cvs.openbsd.org>2007-03-27 07:21:22 +0000
committerXavier Santolaria <xsa@cvs.openbsd.org>2007-03-27 07:21:22 +0000
commit20512c914b245c89f355b9ba0ad94ddb4fb1bf71 (patch)
treec64d20d9b93c1d46d60fbc7c001decbd83e5fe37
parent1abe50d437d4807aa0ee60d579fb456fb450f569 (diff)
sync with espie@'s latest change to diff(1).
from src/usr.bin/diff/diffreg.c rev 1.67: improve -p for C++ code: classes definition often have public:/protected:/private: at the start of line. This lets the -p scanner just take note of the section and keep looking for the actual class definition. Also increase function name bufsize so it shows most of these pesky C++ decls... OK niallo@ espie@.
-rw-r--r--usr.bin/cvs/diff_internals.c29
-rw-r--r--usr.bin/rcs/diff.c29
2 files changed, 45 insertions, 13 deletions
diff --git a/usr.bin/cvs/diff_internals.c b/usr.bin/cvs/diff_internals.c
index 930e4fc0057..c5ee3302edd 100644
--- a/usr.bin/cvs/diff_internals.c
+++ b/usr.bin/cvs/diff_internals.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff_internals.c,v 1.4 2007/02/22 06:42:09 otto Exp $ */
+/* $OpenBSD: diff_internals.c,v 1.5 2007/03/27 07:21:21 xsa Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -226,7 +226,7 @@ static struct context_vec *context_vec_start;
static struct context_vec *context_vec_end;
static struct context_vec *context_vec_ptr;
-#define FUNCTION_CONTEXT_SIZE 41
+#define FUNCTION_CONTEXT_SIZE 55
static char lastbuf[FUNCTION_CONTEXT_SIZE];
static int lastline;
static int lastmatchline;
@@ -1164,6 +1164,8 @@ asciifile(FILE *f)
return (1);
}
+#define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0)
+
static char*
match_function(const long *f, int pos, FILE *fp)
{
@@ -1171,6 +1173,7 @@ match_function(const long *f, int pos, FILE *fp)
size_t nc;
int last = lastline;
char *p;
+ char *state = NULL;
lastline = pos;
while (pos > last) {
@@ -1185,10 +1188,24 @@ match_function(const long *f, int pos, FILE *fp)
if (p != NULL)
*p = '\0';
if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
- strlcpy(lastbuf, (const char *)buf,
- sizeof lastbuf);
- lastmatchline = pos;
- return lastbuf;
+ if (begins_with(buf, "private:")) {
+ if (!state)
+ state = " (private)";
+ } else if (begins_with(buf, "protected:")) {
+ if (!state)
+ state = " (protected)";
+ } else if (begins_with(buf, "public:")) {
+ if (!state)
+ state = " (public)";
+ } else {
+ strlcpy(lastbuf, (const char *)buf,
+ sizeof lastbuf);
+ if (state)
+ strlcat(lastbuf, state,
+ sizeof lastbuf);
+ lastmatchline = pos;
+ return lastbuf;
+ }
}
}
pos--;
diff --git a/usr.bin/rcs/diff.c b/usr.bin/rcs/diff.c
index 09d341a47a9..dee9330a61d 100644
--- a/usr.bin/rcs/diff.c
+++ b/usr.bin/rcs/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.12 2007/02/27 07:59:13 xsa Exp $ */
+/* $OpenBSD: diff.c,v 1.13 2007/03/27 07:21:21 xsa Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -229,7 +229,7 @@ static struct context_vec *context_vec_start;
static struct context_vec *context_vec_end;
static struct context_vec *context_vec_ptr;
-#define FUNCTION_CONTEXT_SIZE 41
+#define FUNCTION_CONTEXT_SIZE 55
static char lastbuf[FUNCTION_CONTEXT_SIZE];
static int lastline;
static int lastmatchline;
@@ -1175,6 +1175,8 @@ asciifile(FILE *f)
return (1);
}
+#define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0)
+
static char*
match_function(const long *f, int pos, FILE *fp)
{
@@ -1182,6 +1184,7 @@ match_function(const long *f, int pos, FILE *fp)
size_t nc;
int last = lastline;
char *p;
+ char *state = NULL;
lastline = pos;
while (pos > last) {
@@ -1196,11 +1199,23 @@ match_function(const long *f, int pos, FILE *fp)
if (p != NULL)
*p = '\0';
if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
- if (strlcpy(lastbuf, (const char *)buf,
- sizeof(lastbuf)) >= sizeof(lastbuf))
- errx(1, "match_function: strlcpy");
- lastmatchline = pos;
- return lastbuf;
+ if (begins_with(buf, "private:")) {
+ if (!state)
+ state = " (private)";
+ } else if (begins_with(buf, "protected:")) {
+ if (!state)
+ state = " (protected)";
+ } else if (begins_with(buf, "public:")) {
+ if (!state)
+ state = " (public)";
+ } else {
+ if (strlcpy(lastbuf, (const char *)buf,
+ sizeof(lastbuf)) >= sizeof(lastbuf))
+ errx(1,
+ "match_function: strlcpy");
+ lastmatchline = pos;
+ return lastbuf;
+ }
}
}
pos--;