aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHidetoshi Shimokawa <simokawa@FreeBSD.org>1999-01-18 07:32:38 +0000
committerHidetoshi Shimokawa <simokawa@FreeBSD.org>1999-01-18 07:32:38 +0000
commitf4a2ce54a010c5c8974bbe2210095b4d1eb5bcb9 (patch)
tree1b924e91970c96ea2a9de165dc36a033be612576
parent6ba7b1c961dd91c80782288f8c79c9c87b7eaa1b (diff)
downloadsrc-f4a2ce54a010c5c8974bbe2210095b4d1eb5bcb9.tar.gz
src-f4a2ce54a010c5c8974bbe2210095b4d1eb5bcb9.zip
Merge from verdor branch (v_3_4_2) and remove obsolete files.
Notes
Notes: svn path=/head/; revision=42791
-rw-r--r--contrib/global/PROBLEMS38
-rw-r--r--contrib/global/btreeop/btreeop.c139
-rw-r--r--contrib/global/gctags/C.c1151
-rw-r--r--contrib/global/gctags/ctags.c379
-rw-r--r--contrib/global/gctags/ctags.h123
-rw-r--r--contrib/global/gctags/fortran.c168
-rw-r--r--contrib/global/gctags/lisp.c105
-rw-r--r--contrib/global/gctags/print.c178
-rw-r--r--contrib/global/gctags/tree.c140
-rw-r--r--contrib/global/gctags/yacc.c151
-rw-r--r--contrib/global/global/global.c716
-rw-r--r--contrib/global/gtags.el58
-rw-r--r--contrib/global/gtags/gtags.c405
-rw-r--r--contrib/global/htags/htags.166
-rw-r--r--contrib/global/lib/dbio.c328
-rw-r--r--contrib/global/lib/dbio.h89
-rw-r--r--contrib/global/lib/dbname.c48
-rw-r--r--contrib/global/lib/dbname.h53
-rw-r--r--contrib/global/lib/find.c409
-rw-r--r--contrib/global/lib/find.h2
-rw-r--r--contrib/global/lib/getdbpath.c47
-rw-r--r--contrib/global/lib/gtagsopen.c100
-rw-r--r--contrib/global/lib/gtagsopen.h41
-rw-r--r--contrib/global/lib/locatestring.c33
-rw-r--r--contrib/global/lib/lookup.c64
-rw-r--r--contrib/global/lib/lookup.h50
-rw-r--r--contrib/global/lib/makepath.c33
-rw-r--r--contrib/global/lib/mgets.c55
-rw-r--r--contrib/global/lib/strop.c121
-rw-r--r--contrib/global/lib/strop.h52
-rw-r--r--contrib/global/lib/tab.c27
-rw-r--r--contrib/global/lib/tag.c85
-rw-r--r--contrib/global/lib/tag.h51
-rw-r--r--contrib/global/lib/test.c18
-rw-r--r--contrib/global/nvi-1.34.diff900
35 files changed, 1735 insertions, 4688 deletions
diff --git a/contrib/global/PROBLEMS b/contrib/global/PROBLEMS
deleted file mode 100644
index e30e7e0d3b1e..000000000000
--- a/contrib/global/PROBLEMS
+++ /dev/null
@@ -1,38 +0,0 @@
-GLOBAL cannot recognize following macros and functions.
-
-1. Macro which doesn't end with ';'.
-
- GLOBAL cannot recognize func() after M(a), because M(a) seems to be
- function definition.
-
- #define M(a) static char *string = a;
-
- M(a)
-
- func() {
- ...
- }
-
- It should be follows.
-
- #define M(a) static char *string = a
-
- M(a);
-
- func() {
- ...
- }
-
-2. Macro which is a renamed function.
-
- #define func _func
-
- _func() {
- ...
- }
- main() {
- func();
- }
-
- In fact, main() calls _func() instead of func() but GLOBAL cannot
- recognize it.
diff --git a/contrib/global/btreeop/btreeop.c b/contrib/global/btreeop/btreeop.c
index 18160fb8c714..2b21cfcde5e7 100644
--- a/contrib/global/btreeop/btreeop.c
+++ b/contrib/global/btreeop/btreeop.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,9 +28,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * btreeop.c 6-Nov-97
+ * btreeop.c 12-Nov-98
*
*/
+#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
@@ -38,21 +39,20 @@
#include <stdlib.h>
#include <string.h>
-#include "dbio.h"
#include "global.h"
-char *dbdefault = "btree"; /* default database name */
-char *progname = "btreeop"; /* command name */
+const char *dbdefault = "btree"; /* default database name */
+const char *progname = "btreeop"; /* command name */
static void usage __P((void));
void signal_setup __P((void));
void onintr __P((int));
-void main __P((int, char **));
-void dbwrite __P((DBIO *));
-void dbkey __P((DBIO *, char *, int));
-void dbscan __P((DBIO *, char *, int));
-void dbdel __P((DBIO *, char *, int));
-void dbbysecondkey __P((DBIO *, int, char *, int));
+int main __P((int, char **));
+void dbwrite __P((DBOP *));
+void dbkey __P((DBOP *, char *, int));
+void dbscan __P((DBOP *, char *, int));
+void dbdel __P((DBOP *, char *, int));
+void dbbysecondkey __P((DBOP *, int, char *, int));
#define F_KEY 0
#define F_DEL 1
@@ -61,7 +61,7 @@ static void
usage()
{
fprintf(stderr, "%s\n",
- "usage: btreeop [-A][-C][-D[n] key][-K[n] key][-L][-k prefix][dbname]");
+ "usage: btreeop [-A][-C][-D[n] key][-K[n] key][-L[2]][-k prefix][dbname]");
exit(1);
}
@@ -86,7 +86,7 @@ signal_setup()
signal(SIGTERM, onintr);
}
-void
+int
main(argc, argv)
int argc;
char *argv[];
@@ -94,11 +94,12 @@ char *argv[];
char command = 'R';
char *key = NULL;
int mode = 0;
- char *dbname;
- DBIO *dbio;
+ const char *db_name;
+ DBOP *dbop;
int i, c;
int secondkey = 0;
- char *prefix = (char *)0;
+ int keylist = 0;
+ char *prefix = NULL;
for (i = 1; i < argc && argv[i][0] == '-'; ++i) {
switch (c = argv[i][1]) {
@@ -106,22 +107,34 @@ char *argv[];
case 'K':
if (argv[i][2] && isdigit(argv[i][2]))
secondkey = atoi(&argv[i][2]);
- key = argv[++i];
+ if (++i < argc)
+ key = argv[i];
+ else
+ usage();
+ /* FALLTHROUGH */
case 'A':
case 'C':
case 'L':
if (command != 'R')
usage();
command = c;
+ if (command == 'L') {
+ keylist = 1;
+ if (argv[i][2] == '2')
+ keylist = 2;
+ }
break;
case 'k':
- prefix = argv[++i];
+ if (++i < argc)
+ prefix = argv[i];
+ else
+ usage();
break;
default:
usage();
}
}
- dbname = (i < argc) ? argv[i] : dbdefault;
+ db_name = (i < argc) ? argv[i] : dbdefault;
switch (command) {
case 'A':
case 'D':
@@ -136,27 +149,35 @@ char *argv[];
mode = 0;
break;
}
- dbio = db_open(dbname, mode, 0644, DBIO_DUP);
- if (dbio == NULL)
- die1("db_open failed (dbname = %s).", dbname);
-
+ dbop = dbop_open(db_name, mode, 0644, DBOP_DUP);
+ if (dbop == NULL) {
+ switch (mode) {
+ case 0:
+ case 2:
+ die1("cannot open '%s'.", db_name);
+ break;
+ case 1:
+ die1("cannot create '%s'.", db_name);
+ break;
+ }
+ }
switch (command) {
case 'A': /* Append records */
case 'C': /* Create database */
- dbwrite(dbio);
+ dbwrite(dbop);
break;
case 'D': /* Delete records */
- dbdel(dbio, key, secondkey);
+ dbdel(dbop, key, secondkey);
break;
case 'K': /* Keyed (indexed) read */
- dbkey(dbio, key, secondkey);
+ dbkey(dbop, key, secondkey);
break;
case 'R': /* sequencial Read */
case 'L': /* primary key List */
- dbscan(dbio, prefix, (command == 'L') ? 1 : 0);
+ dbscan(dbop, prefix, keylist);
break;
}
- db_close(dbio);
+ dbop_close(dbop);
if (exitflag)
exit(1);
exit(0);
@@ -164,11 +185,11 @@ char *argv[];
/*
* dbwrite: write to database
*
- * i) dbio database
+ * i) dbop database
*/
void
-dbwrite(dbio)
-DBIO *dbio;
+dbwrite(dbop)
+DBOP *dbop;
{
char *p;
char keybuf[MAXKEYLEN+1];
@@ -194,7 +215,7 @@ DBIO *dbio;
* +------------------
* | __.VERSION 2
*/
- while ((p = mgets(stdin, 0, NULL)) != NULL) {
+ while ((p = mgets(stdin, NULL, 0)) != NULL) {
if (exitflag)
break;
c = p;
@@ -215,89 +236,93 @@ DBIO *dbio;
if (*c == 0)
die("data part is null.");
entab(p);
- db_put(dbio, keybuf, p);
+ dbop_put(dbop, keybuf, p);
}
}
/*
* dbkey: Keyed search
*
- * i) dbio database
+ * i) dbop database
* i) skey key for search
* i) secondkey 0: primary key, >0: secondary key
*/
void
-dbkey(dbio, skey, secondkey)
-DBIO *dbio;
+dbkey(dbop, skey, secondkey)
+DBOP *dbop;
char *skey;
int secondkey;
{
char *p;
if (!secondkey) {
- for (p = db_first(dbio, skey, 0); p; p = db_next(dbio))
+ for (p = dbop_first(dbop, skey, 0); p; p = dbop_next(dbop))
detab(stdout, p);
return;
}
- dbbysecondkey(dbio, F_KEY, skey, secondkey);
+ dbbysecondkey(dbop, F_KEY, skey, secondkey);
}
/*
* dbscan: Scan records
*
- * i) dbio database
+ * i) dbop database
* i) prefix prefix of primary key
- * i) keylist 0: key and data, 1: primary key only
+ * i) keylist 0: data, 1: key, 2: key and data
*/
void
-dbscan(dbio, prefix, keylist)
-DBIO *dbio;
+dbscan(dbop, prefix, keylist)
+DBOP *dbop;
char *prefix;
int keylist;
{
char *p;
- int flags = DBIO_SKIPMETA;
+ int flags = 0;
if (prefix)
- flags |= DBIO_PREFIX;
+ flags |= DBOP_PREFIX;
if (keylist)
- flags |= DBIO_KEY;
+ flags |= DBOP_KEY;
- for (p = db_first(dbio, prefix, flags); p; p = db_next(dbio))
- detab(stdout, p);
+ for (p = dbop_first(dbop, prefix, flags); p; p = dbop_next(dbop)) {
+ if (keylist == 2)
+ fprintf(stdout, "%s %s\n", p, dbop->lastdat);
+ else
+ detab(stdout, p);
+ }
}
/*
* dbdel: Delete records
*
- * i) dbio database
+ * i) dbop database
* i) skey key for search
* i) secondkey 0: primary key, >0: secondary key
*/
void
-dbdel(dbio, skey, secondkey)
-DBIO *dbio;
+dbdel(dbop, skey, secondkey)
+DBOP *dbop;
char *skey;
int secondkey;
{
signal_setup();
if (!secondkey) {
- db_del(dbio, skey);
+ dbop_del(dbop, skey);
return;
}
- dbbysecondkey(dbio, F_DEL, skey, secondkey);
+ dbbysecondkey(dbop, F_DEL, skey, secondkey);
}
/*
* dbbysecondkey: proc by second key
*
- * i) dbio database
+ * i) dbop database
* i) func F_KEY, F_DEL
* i) skey
* i) secondkey
*/
void
-dbbysecondkey(dbio, func, skey, secondkey)
-DBIO *dbio;
+dbbysecondkey(dbop, func, skey, secondkey)
+DBOP *dbop;
int func;
char *skey;
int secondkey;
@@ -312,7 +337,7 @@ int secondkey;
for (c = skey+strlen(skey)-1; *c && isspace(*c); c--)
*c = 0;
- for (p = db_first(dbio, NULL, DBIO_SKIPMETA); p; p = db_next(dbio)) {
+ for (p = dbop_first(dbop, NULL, 0); p; p = dbop_next(dbop)) {
if (exitflag)
break;
c = p;
@@ -334,7 +359,7 @@ int secondkey;
detab(stdout, p);
break;
case F_DEL:
- db_del(dbio, NULL);
+ dbop_del(dbop, NULL);
break;
}
}
diff --git a/contrib/global/gctags/C.c b/contrib/global/gctags/C.c
index c2d59f1f5aed..17df1accd5d7 100644
--- a/contrib/global/gctags/C.c
+++ b/contrib/global/gctags/C.c
@@ -1,6 +1,5 @@
/*
- * Copyright (c) 1987, 1993, 1994
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -12,8 +11,7 @@
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
+ * This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
@@ -29,49 +27,52 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * C.c 12-Sep-98
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)C.c 8.4 (Berkeley) 4/2/94";
-#endif /* LIBC_SCCS and not lint */
-
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "ctags.h"
-#include "lookup.h"
+#include "C.h"
+#include "gctags.h"
+#include "defined.h"
+#include "die.h"
+#include "locatestring.h"
+#include "strbuf.h"
+#include "token.h"
-static int func_entry __P((void));
-static void hash_entry __P((void));
-static void skip_string __P((int));
-static int str_entry __P((int));
-#ifdef GLOBAL
-static int cmp __P((const void *, const void *));
-static int isstatement __P((char *));
-static void define_line __P((void));
-#endif
+static int function_definition __P((int));
+static void condition_macro __P((int));
+static int reserved __P((char *));
-#ifdef YACC
-extern int yaccfile; /* true when *.y file */
-#endif
/*
- * c_entries --
- * read .c and .h files and call appropriate routines
+ * #ifdef stack.
+ */
+static struct {
+ short start; /* level when #if block started */
+ short end; /* level when #if block end */
+ short if0only; /* #if 0 or notdef only */
+} stack[MAXPIFSTACK], *cur;
+static int piflevel; /* condition macro level */
+static int level; /* brace level */
+
+/*
+ * C: read C (includes .h, .y) file and pickup tag entries.
*/
void
-c_entries()
+C(yacc)
+ int yacc;
{
- int c; /* current character */
- int level; /* brace level */
- int token; /* if reading a token */
- int t_def; /* if reading a typedef */
- int t_level; /* typedef's brace level */
- char *sp; /* buffer pointer */
- char tok[MAXTOKEN]; /* token buffer */
-#ifdef YACC
+ int c, cc;
+ int savelevel;
+ int target;
+ int startmacro, startsharp;
+ const char *interested = "{}=;";
+ STRBUF *sb = stropen();
/*
* yacc file format is like the following.
*
@@ -82,805 +83,395 @@ c_entries()
* programs
*
*/
-#define DECLARATIONS 0
-#define RULES 1
-#define PROGRAMS 2
- int yaccstatus = (yaccfile) ? DECLARATIONS : PROGRAMS;
- int inyacc = (yaccfile) ? YES : NO; /* NO while C source */
-#endif
-
- lineftell = ftell(inf);
- sp = tok; token = t_def = NO; t_level = -1; level = 0; lineno = 1;
- while (GETC(!=, EOF)) {
- switch (c) {
- /*
- * Here's where it DOESN'T handle: {
- * foo(a)
- * {
- * #ifdef notdef
- * }
- * #endif
- * if (a)
- * puts("hello, world");
- * }
- */
- case '{':
-#ifdef YACC
+ int yaccstatus = (yacc) ? DECLARATIONS : PROGRAMS;
+ int inC = (yacc) ? 0 : 1; /* 1 while C source */
+
+ level = piflevel = 0;
+ savelevel = -1;
+ target = (sflag) ? SYM : (rflag) ? REF : DEF;
+ startmacro = startsharp = 0;
+ cmode = 1; /* allow token like '#xxx' */
+ crflag = 1; /* require '\n' as a token */
+ if (yacc)
+ ymode = 1; /* allow token like '%xxx' */
+
+ while ((cc = nexttoken(interested, reserved)) != EOF) {
+ switch (cc) {
+ case SYMBOL: /* symbol */
+ if (inC && peekc(0) == '('/* ) */) {
+ if (isnotfunction(token)) {
+ if (target == REF && defined(token))
+ PUT(token, lineno, sp);
+ } else if (level > 0 || startmacro) {
+ if (target == REF && defined(token))
+ PUT(token, lineno, sp);
+ } else if (level == 0 && !startmacro && !startsharp) {
+ char savetok[MAXTOKEN], *saveline;
+ int savelineno = lineno;
+
+ strcpy(savetok, token);
+ strstart(sb);
+ strnputs(sb, sp, strlen(sp) + 1);
+ saveline = strvalue(sb);
+ if (function_definition(target))
+ if (target == DEF)
+ PUT(savetok, savelineno, saveline);
+ }
+ } else {
+ if (target == SYM)
+ PUT(token, lineno, sp);
+ }
+ break;
+ case '{': /* } */
+ DBG_PRINT(level, "{"); /* } */
if (yaccstatus == RULES && level == 0)
- inyacc = NO;
-#endif
+ inC = 1;
++level;
- goto endtok;
+ if (bflag && atfirst) {
+ if (wflag && level != 1) /* { */
+ fprintf(stderr, "Warning: forced level 1 block start by '{' at column 0 [+%d %s].\n", lineno, curfile);
+ level = 1;
+ }
+ break;
+ /* { */
case '}':
- /*
- * if level goes below zero, try and fix
- * it, even though we've already messed up
- */
- if (--level < 0)
+ if (--level < 0) {
+ if (wflag)
+ fprintf(stderr, "Warning: missing left '{' [+%d %s].\n", lineno, curfile); /* } */
level = 0;
-#ifdef GLOBAL
- /*
- * -e flag force a function to end when a '}' appear
- * at column 0. If -e flag not specified, all functions
- * after funcA() would be lost.
- *
- * funcA() {
- * #ifdef A
- * if (a) {
- * ...
- * #else
- * if (nota) {
- * ...
- * #endif
- * }
- * }
- */
- if (eflag && ftell(inf) == lineftell+1) {
+ }
+ if (eflag && atfirst) {
+ if (wflag && level != 0) /* { */
+ fprintf(stderr, "Warning: forced level 0 block end by '}' at column 0 [+%d %s].\n", lineno, curfile);
level = 0;
}
-#endif
-#if YACC
if (yaccstatus == RULES && level == 0)
- inyacc = YES;
-#endif
- goto endtok;
-
+ inC = 0;
+ /* { */
+ DBG_PRINT(level, "}");
+ break;
case '\n':
- SETLINE;
- /*
- * the above 3 cases are similar in that they
- * are special characters that also end tokens.
- */
- endtok: if (sp > tok) {
- *sp = EOS;
- token = YES;
- sp = tok;
+ if (startmacro && level != savelevel) {
+ if (wflag)
+ fprintf(stderr, "Warning: different level before and after #define macro. reseted. [+%d %s].\n", lineno, curfile);
+ level = savelevel;
}
- else
- token = NO;
- continue;
-
- /*
- * We ignore quoted strings and character constants
- * completely.
- */
- case '"':
- case '\'':
- (void)skip_string(c);
+ startmacro = startsharp = 0;
break;
-
- /*
- * comments can be fun; note the state is unchanged after
- * return, in case we found:
- * "foo() XX comment XX { int bar; }"
- */
- case '/':
- if (GETC(==, '*')) {
- skip_comment();
- continue;
+ case YACC_SEP: /* %% */
+ if (level != 0) {
+ if (wflag)
+ fprintf(stderr, "Warning: forced level 0 block end by '%%' [+%d %s].\n", lineno, curfile);
+ level = 0;
}
- (void)ungetc(c, inf);
- c = '/';
- goto storec;
-
- /* hash marks flag #define's. */
- case '#':
- if (sp == tok) {
- hash_entry();
- break;
+ if (yaccstatus == DECLARATIONS) {
+ if (target == DEF)
+ PUT("yyparse", lineno, sp);
+ yaccstatus = RULES;
+ } else if (yaccstatus == RULES)
+ yaccstatus = PROGRAMS;
+ inC = (yaccstatus == PROGRAMS) ? 1 : 0;
+ break;
+ case YACC_BEGIN: /* %{ */
+ if (level != 0) {
+ if (wflag)
+ fprintf(stderr, "Warning: forced level 0 block end by '%%{' [+%d %s].\n", lineno, curfile);
+ level = 0;
}
- goto storec;
-
+ if (inC == 1 && wflag)
+ fprintf(stderr, "Warning: '%%{' appeared in C mode. [+%d %s].\n", lineno, curfile);
+ inC = 1;
+ break;
+ case YACC_END: /* %} */
+ if (level != 0) {
+ if (wflag)
+ fprintf(stderr, "Warning: forced level 0 block end by '%%}' [+%d %s].\n", lineno, curfile);
+ level = 0;
+ }
+ if (inC == 0 && wflag)
+ fprintf(stderr, "Warning: '%%}' appeared in Yacc mode. [+%d %s].\n", lineno, curfile);
+ inC = 0;
+ break;
/*
- * if we have a current token, parenthesis on
- * level zero indicates a function.
-#ifdef GLOBAL
- * in the case of rflag == 1, if we have a current token,
- * parenthesis on level > zero indicates a function reference.
-#endif
-#ifdef YACC
- * inyacc == NO while C source.
-#endif
+ * #xxx
*/
- case '(':
-#ifdef GLOBAL
- if (sflag)
- break;
-#endif
-#ifdef YACC
- if (inyacc == NO)
-#endif
-#ifdef GLOBAL
- if (!rflag && !level && token)
-#else
- if (!level && token)
-#endif
- {
- int curline;
-
- if (sp != tok)
- *sp = EOS;
- /*
- * grab the line immediately, we may
- * already be wrong, for example,
- * foo\n
- * (arg1,
- */
- getline();
- curline = lineno;
-#ifdef GLOBAL
- /* to make sure. */
- if (!isstatement(tok))
-#endif
- if (func_entry()) {
- ++level;
- pfnote(tok, curline);
- }
+ case CP_DEFINE:
+ startmacro = 1;
+ savelevel = level;
+ if ((c = nexttoken(interested, reserved)) != SYMBOL) {
+ pushbacktoken();
break;
}
-#ifdef GLOBAL
- else if (rflag && level && token) {
- if (sp != tok)
- *sp = EOS;
- if (!isstatement(tok) && lookup(tok)) {
- getline();
- pfnote(tok, lineno);
- }
- break;
+ if (peekc(1) == '('/* ) */) {
+ if (target == DEF)
+ PUT(token, lineno, sp);
+ while ((c = nexttoken("()", reserved)) != EOF && c != '\n' && c != /* ( */ ')')
+ if (c == SYMBOL && target == SYM)
+ PUT(token, lineno, sp);
+ if (c == '\n')
+ pushbacktoken();
}
-#endif
- goto storec;
-
- /*
- * semi-colons indicate the end of a typedef; if we find a
- * typedef we search for the next semi-colon of the same
- * level as the typedef. Ignoring "structs", they are
- * tricky, since you can find:
- *
- * "typedef long time_t;"
- * "typedef unsigned int u_int;"
- * "typedef unsigned int u_int [10];"
- *
- * If looking at a typedef, we save a copy of the last token
- * found. Then, when we find the ';' we take the current
- * token if it starts with a valid token name, else we take
- * the one we saved. There's probably some reasonable
- * alternative to this...
- */
- case ';':
- if (t_def && level == t_level) {
- t_def = NO;
- getline();
- if (sp != tok)
- *sp = EOS;
- pfnote(tok, lineno);
- break;
+ break;
+ case CP_INCLUDE:
+ case CP_ERROR:
+ case CP_LINE:
+ case CP_PRAGMA:
+ while ((c = nexttoken(interested, reserved)) != EOF && c != '\n')
+ ;
+ break;
+ case CP_IFDEF:
+ case CP_IFNDEF:
+ case CP_IF:
+ case CP_ELIF:
+ case CP_ELSE:
+ case CP_ENDIF:
+ case CP_UNDEF:
+ condition_macro(cc);
+ while ((c = nexttoken(interested, reserved)) != EOF && c != '\n') {
+ if (!((cc == CP_IF || cc == CP_ELIF) && !strcmp(token, "defined")))
+ continue;
+ if (c == SYMBOL && target == SYM)
+ PUT(token, lineno, sp);
}
- goto storec;
-
-#if YACC
- case '%':
- if (yaccstatus == DECLARATIONS || yaccstatus == RULES) {
- if (GETC(==, '%')) {
- level = 0;
- if (yaccstatus == DECLARATIONS) {
- if (!rflag) {
- getline();
- pfnote("yyparse", lineno);
- }
- yaccstatus = RULES;
- } else if (yaccstatus == RULES) {
- yaccstatus = PROGRAMS;
- }
- inyacc = (yaccstatus == PROGRAMS) ? NO : YES;
- } else if (c == '{') {
- level = 0;
- inyacc = NO;
- } else if (c == '}') {
- level = 0;
- inyacc = YES;
- } else {
- (void)ungetc(c, inf);
- }
+ break;
+ case CP_SHARP: /* ## */
+ (void)nexttoken(interested, reserved);
+ break;
+ case C_STRUCT:
+ c = nexttoken(interested, reserved);
+ if (c == '{' /* } */) {
+ pushbacktoken();
break;
}
- /* else fall throuth */
-#endif
- /*
- * store characters until one that can't be part of a token
- * comes along; check the current token against certain
- * reserved words.
- */
- default:
- /* ignore whitespace */
- if (c == ' ' || c == '\t') {
- int save = c;
- while (GETC(!=, EOF) && (c == ' ' || c == '\t'))
- ;
- if (c == EOF)
- return;
- (void)ungetc(c, inf);
- c = save;
- }
- storec: if (!intoken(c)) {
- if (sp == tok)
- break;
- *sp = EOS;
-#ifdef GLOBAL
- /* ignore assembler in C source */
- if (!memcmp(tok, "_asm",4)) {
- while (GETC(!=, EOF) && (c == ' ' || c == '\t'))
- ;
- if (c == EOF)
- return;
- if (c == '{') {
- while (GETC(!=, EOF) && c != '}') {
- if (c == '\n')
- SETLINE;
- }
- } else {
- while (GETC(!=, EOF) && c != '\n')
- ;
- if (c == '\n')
- SETLINE;
- }
- if (c == EOF)
- return;
- break;
- }
- if (sflag) {
- if (!isstatement(tok)) {
- getline();
- pfnote(tok, lineno);
- }
- break;
+ if (c == SYMBOL)
+ if (target == SYM)
+ PUT(token, lineno, sp);
+ break;
+ case C_EXTERN:
+ if (startmacro)
+ break;
+ while ((c = nexttoken(interested, reserved)) != EOF && c != ';') {
+ switch (c) {
+ case CP_IFDEF:
+ case CP_IFNDEF:
+ case CP_IF:
+ case CP_ELIF:
+ case CP_ELSE:
+ case CP_ENDIF:
+ case CP_UNDEF:
+ condition_macro(c);
+ continue;
}
- if (!memcmp(tok, "extern",7)) {
- while (GETC(!=, EOF) && c != ';') {
- if (c == '\n')
- SETLINE;
- }
- if (c == EOF)
- return;
+ if (startmacro && c == '\n')
break;
- }
-#endif
- if (tflag) {
- /* no typedefs inside typedefs */
- if (!t_def &&
- !memcmp(tok, "typedef",8)) {
- t_def = YES;
- t_level = level;
- break;
- }
- /* catch "typedef struct" */
- if ((!t_def || t_level < level)
- && (!memcmp(tok, "struct", 7)
- || !memcmp(tok, "union", 6)
- || !memcmp(tok, "enum", 5))) {
- /*
- * get line immediately;
- * may change before '{'
- */
- getline();
- if (str_entry(c))
- ++level;
- break;
- /* } */
- }
- }
- sp = tok;
- }
- else if (sp != tok || begtoken(c)) {
- *sp++ = c;
- token = YES;
- }
-#ifdef GLOBAL
- /* skip hex number */
- else if (sp == tok && c == '0') {
- if (GETC(==, 'x') || c == 'X') {
- while (GETC(!=, EOF) && isxdigit(c))
- ;
- if (c == EOF)
- return;
- }
- (void)ungetc(c, inf);
+ if (c == '{')
+ level++;
+ else if (c == '}')
+ level--;
+ else if (c == SYMBOL)
+ if (target == SYM)
+ PUT(token, lineno, sp);
}
-#endif
- continue;
- /* end of default */
- } /* end of switch */
- /*
- * 'break' statement in switch block come here.
- */
- sp = tok;
- token = NO;
- } /* end of while */
-}
-
-/*
- * func_entry --
- * handle a function reference
- */
-static int
-func_entry()
-{
- int c; /* current character */
- int level = 0; /* for matching '()' */
-
- /*
- * Find the end of the assumed function declaration.
- * Note that ANSI C functions can have type definitions so keep
- * track of the parentheses nesting level.
- */
- while (GETC(!=, EOF)) {
- switch (c) {
- case '\'':
- case '"':
- /* skip strings and character constants */
- skip_string(c);
- break;
- case '/':
- /* skip comments */
- if (GETC(==, '*'))
- skip_comment();
break;
- case '(':
- level++;
+ /* control statement check */
+ case C_BREAK:
+ case C_CASE:
+ case C_CONTINUE:
+ case C_DEFAULT:
+ case C_DO:
+ case C_ELSE:
+ case C_FOR:
+ case C_GOTO:
+ case C_IF:
+ case C_RETURN:
+ case C_SWITCH:
+ case C_WHILE:
+ if (wflag && !startmacro && level == 0)
+ fprintf(stderr, "Warning: Out of function. %8s [+%d %s]\n", token, lineno, curfile);
break;
- case ')':
- if (level == 0)
- goto fnd;
- level--;
- break;
- case '\n':
- SETLINE;
+ default:
}
}
- return (NO);
-fnd:
- /*
- * we assume that the character after a function's right paren
- * is a token character if it's a function and a non-token
- * character if it's a declaration. Comments don't count...
- */
- for (;;) {
- while (GETC(!=, EOF) && iswhite(c))
- if (c == '\n')
- SETLINE;
- if (intoken(c) || c == '{')
- break;
- if (c == '/' && GETC(==, '*'))
- skip_comment();
- else { /* don't ever "read" '/' */
- (void)ungetc(c, inf);
- return (NO);
- }
+ strclose(sb);
+ if (wflag) {
+ if (level != 0)
+ fprintf(stderr, "Warning: {} block unmatched. (last at level %d.)[+%d %s]\n", level, lineno, curfile);
+ if (piflevel != 0)
+ fprintf(stderr, "Warning: #if block unmatched. (last at level %d.)[+%d %s]\n", piflevel, lineno, curfile);
}
- if (c != '{')
- (void)skip_key('{');
- return (YES);
}
-
/*
- * hash_entry --
- * handle a line starting with a '#'
+ * function_definition: return if function definition or not.
+ *
+ * r) target type
*/
-static void
-hash_entry()
+static int
+function_definition(target)
+int target;
{
- int c; /* character read */
- int curline; /* line started on */
- char *sp; /* buffer pointer */
- char tok[MAXTOKEN]; /* storage buffer */
+ int c;
+ int brace_level, isdefine;
- /* ignore leading whitespace */
- while (GETC(!=, EOF) && (c == ' ' || c == '\t'))
- ;
- (void)ungetc(c, inf);
- curline = lineno;
- for (sp = tok;;) { /* get next token */
- if (GETC(==, EOF))
- return;
- if (iswhite(c))
- break;
- *sp++ = c;
- }
- *sp = EOS;
-#ifdef GLOBAL
- if (sflag && memcmp(tok, "include", 7)) {
- (void)ungetc(c, inf);
- define_line();
- return;
- }
-#endif
- if (memcmp(tok, "define", 6)) /* only interested in #define's */
- goto skip;
-
- for (;;) { /* this doesn't handle "#define \n" */
- if (GETC(==, EOF))
- return;
- if (!iswhite(c))
- break;
- }
- for (sp = tok;;) { /* get next token */
- *sp++ = c;
- if (GETC(==, EOF))
- return;
- /*
- * this is where it DOESN'T handle
- * "#define \n"
- */
- if (!intoken(c))
- break;
- }
- *sp = EOS;
-#ifdef GLOBAL
- if (rflag) {
- /*
- * #define XXX\n
- */
- if (c == '\n') {
- SETLINE;
- return;
+ brace_level = isdefine = 0;
+ while ((c = nexttoken("(,)", reserved)) != EOF) {
+ switch (c) {
+ case CP_IFDEF:
+ case CP_IFNDEF:
+ case CP_IF:
+ case CP_ELIF:
+ case CP_ELSE:
+ case CP_ENDIF:
+ case CP_UNDEF:
+ condition_macro(c);
+ continue;
}
- /*
- * v
- * #define XXX(X) XXXXXX
- */
- if (c == '(')
- (void)skip_key(')');
- /*
- * v
- * #define XXX(X) XXXXXX
- */
- while (GETC(!=, EOF)) {
- if (c != ' ' && c != '\t') {
- (void)ungetc(c, inf);
+ if (c == '('/* ) */)
+ brace_level++;
+ else if (c == /* ( */')') {
+ if (--brace_level == 0)
break;
- }
+ } else if (c == SYMBOL) {
+ if (target == SYM)
+ PUT(token, lineno, sp);
}
- /*
- * v
- * #define XXX(X) XXXXXX
- */
- define_line();
- return;
- }
-#endif
- if (dflag || c == '(') { /* only want macros */
- getline();
- pfnote(tok, curline);
- }
-skip: if (c == '\n') { /* get rid of rest of define */
- SETLINE
- if (*(sp - 1) != '\\')
- return;
}
- (void)skip_key('\n');
-}
-
-#ifdef GLOBAL
- /* sorted by alphabet */
-static struct words {
- char *name;
-} words[] = {
- {"__P"},
- {"auto"},
- {"break"},
- {"case"},
- {"char"},
- {"continue"},
- {"default"},
- {"do"},
- {"double"},
- {"else"},
- {"extern"},
- {"float"},
- {"for"},
- {"goto"},
- {"if"},
- {"int"},
- {"long"},
- {"register"},
- {"return"},
- {"short"},
- {"sizeof"},
- {"static"},
- {"struct"},
- {"switch"},
- {"typedef"},
- {"union"},
- {"unsigned"},
- {"void"},
- {"while"},
-};
-
-static int
-cmp(s1, s2)
- const void *s1, *s2;
-{
- return strcmp(((struct words *)s1)->name, ((struct words *)s2)->name);
-}
-
-static int
-isstatement(token)
- char *token;
-{
- struct words tmp;
-
- tmp.name = token;
- if (bsearch(&tmp, words, sizeof(words)/sizeof(struct words), sizeof(struct words), cmp))
- return YES;
- return NO;
-}
-
-static void
-define_line()
-{
- int c; /* character read */
- int level; /* brace level */
- int token; /* if reading a token */
- char *sp; /* buffer pointer */
- char tok[MAXTOKEN]; /* storage buffer */
-
- sp = tok; token = NO; level = 0;
- while (GETC(!=, EOF)) {
+ if (c == EOF)
+ return 0;
+ while ((c = nexttoken(",;{}=", reserved)) != EOF) {
switch (c) {
- case '{':
- ++level;
- goto endtok;
- case '}':
- if (--level < 0)
- level = 0;
- goto endtok;
-
- case '\\':
- if (GETC(==, '\n')) {
- SETLINE;
- }
- continue;
-
- case '\n':
- if (sflag && token) {
- if (sp != tok)
- *sp = EOS;
- if (!isstatement(tok)) {
- getline();
- pfnote(tok, lineno);
- }
- }
- SETLINE;
- return;
- endtok: if (sp > tok) {
- *sp = EOS;
- token = YES;
- sp = tok;
- }
- else
- token = NO;
- continue;
-
- case '"':
- case '\'':
- (void)skip_string(c);
- break;
-
- case '/':
- if (GETC(==, '*')) {
- skip_comment();
- continue;
- }
- (void)ungetc(c, inf);
- c = '/';
- goto storec;
-
- case '(':
- if (sflag)
- break;
- if (token) {
- if (sp != tok)
- *sp = EOS;
- getline();
- if (!isstatement(tok) && lookup(tok))
- pfnote(tok, lineno);
- break;
- }
- goto storec;
-
- case ';':
- goto storec;
-
- default:
-storec: if (!intoken(c)) {
- if (sp == tok)
- break;
- *sp = EOS;
- sp = tok;
- if (sflag) {
- if (!isstatement(tok)) {
- getline();
- pfnote(tok, lineno);
- }
- break;
- }
- }
- else if (sp != tok || begtoken(c)) {
- *sp++ = c;
- token = YES;
- }
+ case CP_IFDEF:
+ case CP_IFNDEF:
+ case CP_IF:
+ case CP_ELIF:
+ case CP_ELSE:
+ case CP_ENDIF:
+ case CP_UNDEF:
+ condition_macro(c);
continue;
}
-
- sp = tok;
- token = NO;
- }
-}
-#endif
-/*
- * str_entry --
- * handle a struct, union or enum entry
- */
-static int
-str_entry(c)
- int c; /* current character */
-{
- int curline; /* line started on */
- char *sp; /* buffer pointer */
- char tok[LINE_MAX]; /* storage buffer */
-
- curline = lineno;
- while (iswhite(c))
- if (GETC(==, EOF))
- return (NO);
- if (c == '{') /* it was "struct {" */
- return (YES);
- for (sp = tok;;) { /* get next token */
- *sp++ = c;
- if (GETC(==, EOF))
- return (NO);
- if (!intoken(c))
+ if (c == SYMBOL || IS_RESERVED(c))
+ isdefine = 1;
+ else if (c == ';' || c == ',') {
+ if (!isdefine)
+ break;
+ } else if (c == '{' /* } */) {
+ pushbacktoken();
+ return 1;
+ } else if (c == /* { */'}') {
break;
- }
- switch (c) {
- case '{': /* it was "struct foo{" */
- --sp;
+ } else if (c == '=')
break;
- case '\n': /* it was "struct foo\n" */
- SETLINE;
- /*FALLTHROUGH*/
- default: /* probably "struct foo " */
- while (GETC(!=, EOF))
- if (!iswhite(c))
- break;
- if (c != '{') {
- (void)ungetc(c, inf);
- return (NO);
- }
}
- *sp = EOS;
- pfnote(tok, curline);
- return (YES);
-}
-
-/*
- * skip_comment --
- * skip over comment
- */
-void
-skip_comment()
-{
- int c; /* character read */
- int star; /* '*' flag */
-
- for (star = 0; GETC(!=, EOF);)
- switch(c) {
- /* comments don't nest, nor can they be escaped. */
- case '*':
- star = YES;
- break;
- case '/':
- if (star)
- return;
- break;
- case '\n':
- SETLINE;
- /*FALLTHROUGH*/
- default:
- star = NO;
- break;
- }
+ return 0;
}
/*
- * skip_string --
- * skip to the end of a string or character constant.
+ * condition_macro:
+ *
+ * i) cc token
*/
static void
-skip_string(key)
- int key;
+condition_macro(cc)
+ int cc;
{
- int c,
- skip;
-
- for (skip = NO; GETC(!=, EOF); )
- switch (c) {
- case '\\': /* a backslash escapes anything */
- skip = !skip; /* we toggle in case it's "\\" */
- break;
- case '\n':
- SETLINE;
- /*FALLTHROUGH*/
- default:
- if (c == key && !skip)
- return;
- skip = NO;
+ cur = &stack[piflevel];
+ if (cc == CP_IFDEF || cc == CP_IFNDEF || cc == CP_IF) {
+ DBG_PRINT(piflevel, "#if");
+ if (++piflevel >= MAXPIFSTACK)
+ die1("#if stack over flow. [%s]", curfile);
+ ++cur;
+ cur->start = level;
+ cur->end = -1;
+ cur->if0only = 0;
+ if (peekc(0) == '0')
+ cur->if0only = 1;
+ else if ((cc = nexttoken(NULL, reserved)) == SYMBOL && !strcmp(token, "notdef"))
+ cur->if0only = 1;
+ else
+ pushbacktoken();
+ } else if (cc == CP_ELIF || cc == CP_ELSE) {
+ DBG_PRINT(piflevel - 1, "#else");
+ if (cur->end == -1)
+ cur->end = level;
+ else if (cur->end != level && wflag)
+ fprintf(stderr, "Warning: uneven level. [+%d %s]\n", lineno, curfile);
+ level = cur->start;
+ cur->if0only = 0;
+ } else if (cc == CP_ENDIF) {
+ if (cur->if0only)
+ level = cur->start;
+ else if (cur->end != -1) {
+ if (cur->end != level && wflag)
+ fprintf(stderr, "Warning: uneven level. [+%d %s]\n", lineno, curfile);
+ level = cur->end;
}
+ --piflevel;
+ DBG_PRINT(piflevel, "#endif");
+ }
}
+ /* sorted by alphabet */
+static struct words words[] = {
+ {"##", CP_SHARP},
+ {"#define", CP_DEFINE},
+ {"#elif", CP_ELIF},
+ {"#else", CP_ELSE},
+ {"#endif", CP_ENDIF},
+ {"#error", CP_ERROR},
+ {"#if", CP_IF},
+ {"#ifdef", CP_IFDEF},
+ {"#ifndef", CP_IFNDEF},
+ {"#include", CP_INCLUDE},
+ {"#line", CP_LINE},
+ {"#pragma", CP_PRAGMA},
+ {"#undef", CP_UNDEF},
+ {"%%", YACC_SEP},
+ {"%left", YACC_LEFT},
+ {"%nonassoc", YACC_NONASSOC},
+ {"%right", YACC_RIGHT},
+ {"%start", YACC_START},
+ {"%token", YACC_TOKEN},
+ {"%type", YACC_TYPE},
+ {"%{", YACC_BEGIN},
+ {"%}", YACC_END},
+ {"__P", C___P},
+ {"auto", C_AUTO},
+ {"break", C_BREAK},
+ {"case", C_CASE},
+ {"char", C_CHAR},
+ {"continue", C_CONTINUE},
+ {"default", C_DEFAULT},
+ {"do", C_DO},
+ {"double", C_DOUBLE},
+ {"else", C_ELSE},
+ {"extern", C_EXTERN},
+ {"float", C_FLOAT},
+ {"for", C_FOR},
+ {"goto", C_GOTO},
+ {"if", C_IF},
+ {"int", C_INT},
+ {"long", C_LONG},
+ {"register", C_REGISTER},
+ {"return", C_RETURN},
+ {"short", C_SHORT},
+ {"sizeof", C_SIZEOF},
+ {"static", C_STATIC},
+ {"struct", C_STRUCT},
+ {"switch", C_SWITCH},
+ {"typedef", C_TYPEDEF},
+ {"union", C_UNION},
+ {"unsigned", C_UNSIGNED},
+ {"void", C_VOID},
+ {"while", C_WHILE},
+};
-/*
- * skip_key --
- * skip to next char "key"
- */
-int
-skip_key(key)
- int key;
+static int
+reserved(word)
+ char *word;
{
- int c,
- skip,
- retval;
+ struct words tmp;
+ struct words *result;
- for (skip = retval = NO; GETC(!=, EOF);)
- switch(c) {
- case '\\': /* a backslash escapes anything */
- skip = !skip; /* we toggle in case it's "\\" */
- break;
- case ';': /* special case for yacc; if one */
- case '|': /* of these chars occurs, we may */
- retval = YES; /* have moved out of the rule */
- break; /* not used by C */
- case '\'':
- case '"':
- /* skip strings and character constants */
- skip_string(c);
- break;
- case '/':
- /* skip comments */
- if (GETC(==, '*')) {
- skip_comment();
- break;
- }
- (void)ungetc(c, inf);
- c = '/';
- goto norm;
- case '\n':
- SETLINE;
- /*FALLTHROUGH*/
- default:
- norm:
- if (c == key && !skip)
- return (retval);
- skip = NO;
- }
- return (retval);
+ tmp.name = word;
+ result = (struct words *)bsearch(&tmp, words, sizeof(words)/sizeof(struct words), sizeof(struct words), cmp);
+ return (result != NULL) ? result->val : SYMBOL;
}
diff --git a/contrib/global/gctags/ctags.c b/contrib/global/gctags/ctags.c
deleted file mode 100644
index d79a348ef4d4..000000000000
--- a/contrib/global/gctags/ctags.c
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * Copyright (c) 1987, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1987, 1993, 1994\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] =
- "$Id: ctags.c,v 1.1.1.2 1997/12/15 23:08:35 cwt Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "ctags.h"
-#ifdef GLOBAL
-#include "lookup.h"
-#include "die.h"
-#endif
-
-/*
- * ctags: create a tags file
- */
-
-NODE *head; /* head of the sorted binary tree */
-
- /* boolean "func" (see init()) */
-bool _wht[256], _etk[256], _itk[256], _btk[256], _gd[256];
-
-FILE *inf; /* ioptr for current input file */
-FILE *outf; /* ioptr for tags file */
-
-long lineftell; /* ftell after getc( inf ) == '\n' */
-
-int lineno; /* line number of current line */
-#ifdef GLOBAL
-int cflag; /* -c: compact index */
-#endif
-int dflag; /* -d: non-macro defines */
-#ifdef GLOBAL
-int eflag; /* -e: '{' at 0 column force function end */
-#endif
-int tflag; /* -t: create tags for typedefs */
-int vflag; /* -v: vgrind style index output */
-int wflag; /* -w: suppress warnings */
-int xflag; /* -x: cxref style output */
-#ifdef GLOBAL
-int Dflag; /* -D: allow duplicate entrys */
-int rflag; /* -r: function reference */
-int sflag; /* -s: collect symbols */
-#endif
-#ifdef YACC
-int yaccfile; /* yacc file */
-#endif
-
-char *curfile; /* current input file name */
-char searchar = '/'; /* use /.../ searches by default */
-char lbuf[LINE_MAX];
-char *progname = "gctags"; /* program name */
-
-void init __P((void));
-void find_entries __P((char *));
-void main __P((int, char **));
-static void usage __P((void));
-
-void
-main(argc, argv)
- int argc;
- char **argv;
-{
- static char *outfile = "tags"; /* output file */
- int aflag; /* -a: append to tags */
- int uflag; /* -u: update tags */
- int exit_val; /* exit value */
- int step; /* step through args */
- int ch; /* getopts char */
- char cmd[100]; /* too ugly to explain */
- extern char *optarg;
- extern int optind;
-
- aflag = uflag = NO;
-#ifdef GLOBAL
- while ((ch = getopt(argc, argv, "BDFacdef:rstuwvx")) != -1)
-#else
- while ((ch = getopt(argc, argv, "BFadf:tuwvx")) != -1)
-#endif
- switch(ch) {
- case 'B':
- searchar = '?';
- break;
-#ifdef GLOBAL
- case 'D':
- Dflag++;
- break;
-#endif
- case 'F':
- searchar = '/';
- break;
-#ifdef GLOBAL
- case 's':
- sflag++;
- break;
-#endif
- case 'a':
- aflag++;
- break;
-#ifdef GLOBAL
- case 'c':
- cflag++;
- break;
-#endif
- case 'd':
- dflag++;
- break;
-#ifdef GLOBAL
- case 'e':
- eflag++;
- break;
-#endif
- case 'f':
- outfile = optarg;
- break;
-#ifdef GLOBAL
- case 'r':
- rflag++;
- break;
-#endif
- case 't':
- tflag++;
- break;
- case 'u':
- uflag++;
- break;
- case 'w':
- wflag++;
- break;
- case 'v':
- vflag++;
- case 'x':
- xflag++;
- break;
- case '?':
- default:
- usage();
- }
- argv += optind;
- argc -= optind;
- if (!argc)
- usage();
-#ifdef GLOBAL
- if (sflag && rflag)
- die("-s and -r conflict.");
- if (rflag) {
- char *dbpath;
-
- if (!(dbpath = getenv("GTAGSDBPATH")))
- dbpath = ".";
- lookupopen(dbpath);
- }
-#endif
- init();
-
- for (exit_val = step = 0; step < argc; ++step)
- if (!(inf = fopen(argv[step], "r"))) {
- fprintf(stderr, "%s: %s cannot open\n", progname, argv[step]);
- exit_val = 1;
- }
- else {
- curfile = argv[step];
- find_entries(argv[step]);
- (void)fclose(inf);
- }
-
- if (head)
- if (xflag) {
- put_entries(head);
-#ifdef GLOBAL
- if (cflag)
- compact_print("", 0, "");/* flush last record */
-#endif
- } else {
- if (uflag) {
- for (step = 0; step < argc; step++) {
- (void)sprintf(cmd,
- "mv %s OTAGS; fgrep -v '\t%s\t' OTAGS >%s; rm OTAGS",
- outfile, argv[step],
- outfile);
- system(cmd);
- }
- ++aflag;
- }
- if (!(outf = fopen(outfile, aflag ? "a" : "w"))) {
- fprintf(stderr, "%s: %s cannot open\n", progname, outfile);
- exit(exit_val);
- }
- put_entries(head);
- (void)fclose(outf);
- if (uflag) {
- (void)sprintf(cmd, "sort -o %s %s",
- outfile, outfile);
- system(cmd);
- }
- }
-#ifdef GLOBAL
- if (rflag)
- lookupclose();
-#endif
- exit(exit_val);
-}
-
-static void
-usage()
-{
- (void)fprintf(stderr,
-#ifdef GLOBAL
- "usage: gctags [-BDFacderstuvwx] [-f tagsfile] file ...\n");
-#else
- "usage: ctags [-BFadtuwvx] [-f tagsfile] file ...\n");
-#endif
- exit(1);
-}
-
-/*
- * init --
- * this routine sets up the boolean psuedo-functions which work by
- * setting boolean flags dependent upon the corresponding character.
- * Every char which is NOT in that string is false with respect to
- * the pseudo-function. Therefore, all of the array "_wht" is NO
- * by default and then the elements subscripted by the chars in
- * CWHITE are set to YES. Thus, "_wht" of a char is YES if it is in
- * the string CWHITE, else NO.
- */
-void
-init()
-{
- int i;
- unsigned char *sp;
-
- for (i = 0; i < 256; i++) {
- _wht[i] = _etk[i] = _itk[i] = _btk[i] = NO;
- _gd[i] = YES;
- }
-#define CWHITE " \f\t\n"
- for (sp = (unsigned char *)CWHITE; *sp; sp++) /* white space chars */
- _wht[*sp] = YES;
-#define CTOKEN " \t\n\"'#()[]{}=-+%*/&|^~!<>;,.:?"
- for (sp = (unsigned char *)CTOKEN; *sp; sp++) /* token ending chars */
- _etk[*sp] = YES;
-#define CINTOK "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789"
- for (sp = (unsigned char *)CINTOK; *sp; sp++) /* valid in-token chars */
- _itk[*sp] = YES;
-#define CBEGIN "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
- for (sp = (unsigned char *)CBEGIN; *sp; sp++) /* token starting chars */
- _btk[*sp] = YES;
-#define CNOTGD ",;"
- for (sp = (unsigned char *)CNOTGD; *sp; sp++) /* invalid after-function chars */
- _gd[*sp] = NO;
-}
-
-/*
- * find_entries --
- * this routine opens the specified file and calls the function
- * which searches the file.
- */
-void
-find_entries(file)
- char *file;
-{
- char *cp;
-
- lineno = 0; /* should be 1 ?? KB */
- if ((cp = strrchr(file, '.')) != NULL) {
- if (cp[1] == 'l' && !cp[2]) {
- int c;
-
-#ifdef GLOBAL
- if (rflag)
- fprintf(stderr, "-r option is ignored in lisp file (Warning only)\n");
-#endif
- for (;;) {
- if (GETC(==, EOF))
- return;
- if (!iswhite(c)) {
- rewind(inf);
- break;
- }
- }
-#define LISPCHR ";(["
-/* lisp */ if (strchr(LISPCHR, c)) {
- l_entries();
- return;
- }
-/* lex */ else {
- /*
- * we search all 3 parts of a lex file
- * for C references. This may be wrong.
- */
- toss_yysec();
- (void)strcpy(lbuf, "%%$");
- pfnote("yylex", lineno);
- rewind(inf);
- }
- }
-/* yacc */ else if (cp[1] == 'y' && !cp[2]) {
-#ifdef YACC
- /*
- * we search all part of a yacc file for C references.
- * but ignore yacc rule tags.
- */
- yaccfile = YES;
- c_entries();
- return;
-#endif
- /*
- * we search only the 3rd part of a yacc file
- * for C references. This may be wrong.
- */
- toss_yysec();
- (void)strcpy(lbuf, "%%$");
- pfnote("yyparse", lineno);
- y_entries();
- }
-#ifdef GLOBAL
-/* assembler */ else if ((cp[1] == 's' || cp[1] == 'S') && !cp[2]) {
- asm_entries();
- return;
- }
-#endif
-/* fortran */ else if ((cp[1] != 'c' && cp[1] != 'h') && !cp[2]) {
-#ifdef GLOBAL
- if (rflag)
- fprintf(stderr, "-r option is ignored in fortran file (Warning only)\n");
-#endif
- if (PF_funcs())
- return;
- rewind(inf);
- }
- }
-#ifdef YACC
- yaccfile = NO;
-#endif
-/* C */ c_entries();
-}
diff --git a/contrib/global/gctags/ctags.h b/contrib/global/gctags/ctags.h
deleted file mode 100644
index e843032e4239..000000000000
--- a/contrib/global/gctags/ctags.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 1987, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)ctags.h 8.3 (Berkeley) 4/2/94
- */
-
-/* Definition for gctags */
-#define GLOBAL 1
-#define YACC 1
-
-#define bool char
-
-#define YES 1
-#define NO 0
-#define EOS '\0'
-
-#define ENDLINE 50 /* max length of pattern */
-#define MAXTOKEN 250 /* max size of single token */
-
-#ifndef LINE_MAX
-#define LINE_MAX 2048
-#endif
-
-#define SETLINE {++lineno;lineftell = ftell(inf);}
-#ifdef GLOBAL
-#define GETC(op,exp) ((((c = getc(inf)) == '\r') ? (c = getc(inf)) : c) op (int)exp)
-#else
-#define GETC(op,exp) ((c = getc(inf)) op (int)exp)
-#endif
-
-#define iswhite(arg) (_wht[(unsigned)arg]) /* T if char is white */
-#define begtoken(arg) (_btk[(unsigned)arg]) /* T if char can start token */
-#define intoken(arg) (_itk[(unsigned)arg]) /* T if char can be in token */
-#define endtoken(arg) (_etk[(unsigned)arg]) /* T if char ends tokens */
-#define isgood(arg) (_gd[(unsigned)arg]) /* T if char can be after ')' */
-
-typedef struct nd_st { /* sorting structure */
- struct nd_st *left,
- *right; /* left and right sons */
- char *entry, /* function or type name */
- *file, /* file name */
- *pat; /* search pattern */
- int lno; /* for -x option */
- bool been_warned; /* set if noticed dup */
-} NODE;
-
-extern char *curfile; /* current input file name */
-extern NODE *head; /* head of the sorted binary tree */
-extern FILE *inf; /* ioptr for current input file */
-extern FILE *outf; /* ioptr for current output file */
-extern long lineftell; /* ftell after getc( inf ) == '\n' */
-extern int lineno; /* line number of current line */
-#ifdef GLOBAL
-extern int cflag; /* -c: compact index */
-extern int eflag; /* -e: '{' at 0 column force function end */
-extern int Dflag; /* -D: allow duplicate entrys */
-extern int rflag; /* -r: function reference */
-extern int sflag; /* -s: collect symbols */
-#endif
-extern int dflag; /* -d: non-macro defines */
-extern int tflag; /* -t: create tags for typedefs */
-extern int vflag; /* -v: vgrind style index output */
-extern int wflag; /* -w: suppress warnings */
-extern int xflag; /* -x: cxref style output */
-extern bool _wht[], _etk[], _itk[], _btk[], _gd[];
-extern char lbuf[LINE_MAX];
-extern char *lbp;
-extern char searchar; /* ex search character */
-extern char *progname; /* program name */
-
-#ifndef __P
-#ifdef __STDC__
-#define __P(protos) protos
-#else
-#define __P(protos) ()
-#endif
-#endif
-
-int cicmp __P((char *));
-void getline __P((void));
-void pfnote __P((char *, int));
-int skip_key __P((int));
-void put_entries __P((NODE *));
-void toss_yysec __P((void));
-void l_entries __P((void));
-void y_entries __P((void));
-int PF_funcs __P((void));
-void c_entries __P((void));
-void skip_comment __P((void));
-#ifdef GLOBAL
-void asm_entries __P((void));
-void compact_print __P((char *, int, char *));
-int portable_getc __P((FILE *));
-#endif
diff --git a/contrib/global/gctags/fortran.c b/contrib/global/gctags/fortran.c
deleted file mode 100644
index 2a33aff1f2df..000000000000
--- a/contrib/global/gctags/fortran.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (c) 1987, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fortran.c 8.3 (Berkeley) 4/2/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <ctype.h>
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "ctags.h"
-
-static void takeprec __P((void));
-
-char *lbp; /* line buffer pointer */
-
-int
-PF_funcs()
-{
- bool pfcnt; /* pascal/fortran functions found */
- char *cp;
- char tok[MAXTOKEN];
-
- for (pfcnt = NO;;) {
- lineftell = ftell(inf);
- if (!fgets(lbuf, sizeof(lbuf), inf))
- return (pfcnt);
- ++lineno;
- lbp = lbuf;
- if (*lbp == '%') /* Ratfor escape to fortran */
- ++lbp;
- for (; isspace(*lbp); ++lbp)
- continue;
- if (!*lbp)
- continue;
- switch (*lbp | ' ') { /* convert to lower-case */
- case 'c':
- if (cicmp("complex") || cicmp("character"))
- takeprec();
- break;
- case 'd':
- if (cicmp("double")) {
- for (; isspace(*lbp); ++lbp)
- continue;
- if (!*lbp)
- continue;
- if (cicmp("precision"))
- break;
- continue;
- }
- break;
- case 'i':
- if (cicmp("integer"))
- takeprec();
- break;
- case 'l':
- if (cicmp("logical"))
- takeprec();
- break;
- case 'r':
- if (cicmp("real"))
- takeprec();
- break;
- }
- for (; isspace(*lbp); ++lbp)
- continue;
- if (!*lbp)
- continue;
- switch (*lbp | ' ') {
- case 'f':
- if (cicmp("function"))
- break;
- continue;
- case 'p':
- if (cicmp("program") || cicmp("procedure"))
- break;
- continue;
- case 's':
- if (cicmp("subroutine"))
- break;
- default:
- continue;
- }
- for (; isspace(*lbp); ++lbp)
- continue;
- if (!*lbp)
- continue;
- for (cp = lbp + 1; *cp && intoken(*cp); ++cp)
- continue;
- if (cp == lbp + 1)
- continue;
- *cp = EOS;
- (void)strcpy(tok, lbp);
- getline(); /* process line for ex(1) */
- pfnote(tok, lineno);
- pfcnt = YES;
- }
- /*NOTREACHED*/
-}
-
-/*
- * cicmp --
- * do case-independent strcmp
- */
-int
-cicmp(cp)
- char *cp;
-{
- int len;
- char *bp;
-
- for (len = 0, bp = lbp; *cp && (*cp &~ ' ') == (*bp++ &~ ' ');
- ++cp, ++len)
- continue;
- if (!*cp) {
- lbp += len;
- return (YES);
- }
- return (NO);
-}
-
-static void
-takeprec()
-{
- for (; isspace(*lbp); ++lbp)
- continue;
- if (*lbp == '*') {
- for (++lbp; isspace(*lbp); ++lbp)
- continue;
- if (!isdigit(*lbp))
- --lbp; /* force failure */
- else
- while (isdigit(*++lbp))
- continue;
- }
-}
diff --git a/contrib/global/gctags/lisp.c b/contrib/global/gctags/lisp.c
deleted file mode 100644
index ebf51841eb3b..000000000000
--- a/contrib/global/gctags/lisp.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 1987, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)lisp.c 8.3 (Berkeley) 4/2/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <ctype.h>
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "ctags.h"
-
-/*
- * lisp tag functions
- * just look for (def or (DEF
- */
-void
-l_entries()
-{
- int special;
- char *cp;
- char savedc;
- char tok[MAXTOKEN];
-
- for (;;) {
- lineftell = ftell(inf);
- if (!fgets(lbuf, sizeof(lbuf), inf))
- return;
- ++lineno;
- lbp = lbuf;
- if (!cicmp("(def"))
- continue;
- special = NO;
- switch(*lbp | ' ') {
- case 'm':
- if (cicmp("method"))
- special = YES;
- break;
- case 'w':
- if (cicmp("wrapper") || cicmp("whopper"))
- special = YES;
- }
- for (; !isspace(*lbp); ++lbp)
- continue;
- for (; isspace(*lbp); ++lbp)
- continue;
- for (cp = lbp; *cp && *cp != '\n'; ++cp)
- continue;
- *cp = EOS;
- if (special) {
- if (!(cp = strchr(lbp, ')')))
- continue;
- for (; cp >= lbp && *cp != ':'; --cp)
- continue;
- if (cp < lbp)
- continue;
- lbp = cp;
- for (; *cp && *cp != ')' && *cp != ' '; ++cp)
- continue;
- }
- else
- for (cp = lbp + 1;
- *cp && *cp != '(' && *cp != ' '; ++cp)
- continue;
- savedc = *cp;
- *cp = EOS;
- (void)strcpy(tok, lbp);
- *cp = savedc;
- getline();
- pfnote(tok, lineno);
- }
- /*NOTREACHED*/
-}
diff --git a/contrib/global/gctags/print.c b/contrib/global/gctags/print.c
deleted file mode 100644
index ff81a9b33cc1..000000000000
--- a/contrib/global/gctags/print.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (c) 1987, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)print.c 8.3 (Berkeley) 4/2/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "die.h"
-#include "ctags.h"
-
-/*
- * getline --
- * get the line the token of interest occurred on,
- * prepare it for printing.
- */
-void
-getline()
-{
- long saveftell;
- int c;
- int cnt;
- char *cp;
-
- saveftell = ftell(inf);
- (void)fseek(inf, lineftell, SEEK_SET);
- if (xflag)
- for (cp = lbuf; GETC(!=, EOF) && c != '\n'; *cp++ = c)
- continue;
- /*
- * do all processing here, so we don't step through the
- * line more than once; means you don't call this routine
- * unless you're sure you've got a keeper.
- */
- else for (cnt = 0, cp = lbuf; GETC(!=, EOF) && cnt < ENDLINE; ++cnt) {
- if (c == '\\') { /* backslashes */
- if (cnt > ENDLINE - 2)
- break;
- *cp++ = '\\'; *cp++ = '\\';
- ++cnt;
- }
- else if (c == (int)searchar) { /* search character */
- if (cnt > ENDLINE - 2)
- break;
- *cp++ = '\\'; *cp++ = c;
- ++cnt;
- }
- else if (c == '\n') { /* end of keep */
- *cp++ = '$'; /* can find whole line */
- break;
- }
- else
- *cp++ = c;
- }
- *cp = EOS;
- (void)fseek(inf, saveftell, SEEK_SET);
-}
-#ifdef GLOBAL
-void
-compact_print(entry, lno, file)
-char *entry;
-int lno;
-char *file;
-{
- static int first = 1;
- static char p_entry[128];
- static char p_file[1024];
- static int p_lno;
- static char *buf;
- static int bufsize = 512;
- static char *p;
-
- if (first) {
- if (!(buf = (char *)malloc(bufsize)))
- die("short of memory.");
- buf[0] = 0;
- p = buf;
- first = 0;
- }
- if (strcmp(p_entry, entry) || strcmp(p_file, file)) {
- if (buf[0])
- printf("%s\n", buf);
- if (!entry[0]) /* flush */
- return;
- strcpy(p_entry, entry);
- strcpy(p_file, file);
- p_lno = lno;
- buf[0] = 0;
- sprintf(buf, "%s %s %d", entry, file, lno);
- p = buf;
- p += strlen(p);
- } else {
- if (p_lno > lno)
- die("impossible!");
- if (p_lno < lno) {
- if (buf + bufsize < p + 10) {
- int offset = p - buf;
- bufsize *= 2;
- if (!(buf = (char *)realloc(buf, bufsize)))
- die("short of memory.");
- p = buf + offset;
- }
- sprintf(p, ",%d", lno);
- p += strlen(p);
- p_lno = lno;
- }
- }
-}
-#endif
-/*
- * put_entries --
- * write out the tags
- */
-void
-put_entries(node)
- NODE *node;
-{
-
- if (node->left)
- put_entries(node->left);
- if (vflag)
- printf("%s %s %d\n",
- node->entry, node->file, (node->lno + 63) / 64);
-#ifdef GLOBAL
- else if (xflag && cflag)
- compact_print(node->entry, node->lno, node->file);
-#endif
- else if (xflag)
-#ifdef GLOBAL
- /* separate 'entry' and 'lno' */
- if (strlen(node->entry) >= 16 && node->lno >= 1000)
- printf("%-16s %4d %-16s %s\n",
- node->entry, node->lno, node->file, node->pat);
- else /* for compatibility */
-#endif
- printf("%-16s%4d %-16s %s\n",
- node->entry, node->lno, node->file, node->pat);
- else
- fprintf(outf, "%s\t%s\t%c^%s%c\n",
- node->entry, node->file, searchar, node->pat, searchar);
- if (node->right)
- put_entries(node->right);
-}
diff --git a/contrib/global/gctags/tree.c b/contrib/global/gctags/tree.c
deleted file mode 100644
index 94362cd7a75e..000000000000
--- a/contrib/global/gctags/tree.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 1987, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)tree.c 8.3 (Berkeley) 4/2/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "die.h"
-#include "ctags.h"
-
-static void add_node __P((NODE *, NODE *));
-static void free_tree __P((NODE *));
-
-/*
- * pfnote --
- * enter a new node in the tree
- */
-void
-pfnote(name, ln)
- char *name;
- int ln;
-{
- NODE *np;
- char *fp;
- char nbuf[MAXTOKEN];
-
- /*NOSTRICT*/
- if (!(np = (NODE *)malloc(sizeof(NODE)))) {
- fprintf(stderr, "too many entries to sort\n");
- put_entries(head);
- free_tree(head);
- /*NOSTRICT*/
- if (!(head = np = (NODE *)malloc(sizeof(NODE))))
- die("out of space");
- }
- if (!xflag && !strcmp(name, "main")) {
- if (!(fp = strrchr(curfile, '/')))
- fp = curfile;
- else
- ++fp;
- (void)sprintf(nbuf, "M%s", fp);
- fp = strrchr(nbuf, '.');
- if (fp && !fp[2])
- *fp = EOS;
- name = nbuf;
- }
- if (!(np->entry = strdup(name)))
- die("out of space");
- np->file = curfile;
- np->lno = ln;
- np->left = np->right = 0;
- if (!(np->pat = strdup(lbuf)))
- die("out of space");
- if (!head)
- head = np;
- else
- add_node(np, head);
-}
-
-static void
-add_node(node, cur_node)
- NODE *node,
- *cur_node;
-{
- int dif;
-
- dif = strcmp(node->entry, cur_node->entry);
-#ifdef GLOBAL
- if (!Dflag && !dif) /* -D option allows duplicate entries. */
-#else
- if (!dif)
-#endif
- {
- if (node->file == cur_node->file) {
- if (!wflag)
- fprintf(stderr, "Duplicate entry in file %s, line %d: %s\nSecond entry ignored\n", node->file, lineno, node->entry);
- return;
- }
- if (!cur_node->been_warned)
- if (!wflag)
- fprintf(stderr, "Duplicate entry in files %s and %s: %s (Warning only)\n", node->file, cur_node->file, node->entry);
- cur_node->been_warned = YES;
- }
- else if (dif < 0)
- if (cur_node->left)
- add_node(node, cur_node->left);
- else
- cur_node->left = node;
- else if (cur_node->right)
- add_node(node, cur_node->right);
- else
- cur_node->right = node;
-}
-
-static void
-free_tree(node)
- NODE *node;
-{
- while (node) {
- if (node->right)
- free_tree(node->right);
- free(node);
- node = node->left;
- }
-}
diff --git a/contrib/global/gctags/yacc.c b/contrib/global/gctags/yacc.c
deleted file mode 100644
index 9dcdd5afc24a..000000000000
--- a/contrib/global/gctags/yacc.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright (c) 1987, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)yacc.c 8.3 (Berkeley) 4/2/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <ctype.h>
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "ctags.h"
-
-/*
- * y_entries:
- * find the yacc tags and put them in.
- */
-void
-y_entries()
-{
- int c;
- char *sp;
- bool in_rule;
- char tok[MAXTOKEN];
-
- in_rule = NO;
-
- while (GETC(!=, EOF))
- switch (c) {
- case '\n':
- SETLINE;
- /* FALLTHROUGH */
- case ' ':
- case '\f':
- case '\r':
- case '\t':
- break;
- case '{':
- if (skip_key('}'))
- in_rule = NO;
- break;
- case '\'':
- case '"':
- if (skip_key(c))
- in_rule = NO;
- break;
- case '%':
- if (GETC(==, '%'))
- return;
- (void)ungetc(c, inf);
- break;
- case '/':
- if (GETC(==, '*'))
- skip_comment();
- else
- (void)ungetc(c, inf);
- break;
- case '|':
- case ';':
- in_rule = NO;
- break;
- default:
- if (in_rule || (!isalpha(c) && c != '.' && c != '_'))
- break;
- sp = tok;
- *sp++ = c;
- while (GETC(!=, EOF) && (intoken(c) || c == '.'))
- *sp++ = c;
- *sp = EOS;
- getline(); /* may change before ':' */
- while (iswhite(c)) {
- if (c == '\n')
- SETLINE;
- if (GETC(==, EOF))
- return;
- }
- if (c == ':') {
- pfnote(tok, lineno);
- in_rule = YES;
- }
- else
- (void)ungetc(c, inf);
- }
-}
-
-/*
- * toss_yysec --
- * throw away lines up to the next "\n%%\n"
- */
-void
-toss_yysec()
-{
- int c; /* read character */
- int state;
-
- /*
- * state == 0 : waiting
- * state == 1 : received a newline
- * state == 2 : received first %
- * state == 3 : recieved second %
- */
- lineftell = ftell(inf);
- for (state = 0; GETC(!=, EOF);)
- switch (c) {
- case '\n':
- ++lineno;
- lineftell = ftell(inf);
- if (state == 3) /* done! */
- return;
- state = 1; /* start over */
- break;
- case '%':
- if (state) /* if 1 or 2 */
- ++state; /* goto 3 */
- break;
- default:
- state = 0; /* reset */
- break;
- }
-}
diff --git a/contrib/global/global/global.c b/contrib/global/global/global.c
index 4a92fa4d5dfc..a8dbb172a174 100644
--- a/contrib/global/global/global.c
+++ b/contrib/global/global/global.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,10 +28,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * global.c 7-Nov-97
+ * global.c 8-Dec-98
*
*/
+#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
@@ -43,64 +44,87 @@
#include "global.h"
-char *progname = "global"; /* command name */
+const char *progname = "global"; /* command name */
static void usage __P((void));
-void main __P((int, char **));
-char *outfilter __P((void));
-void completelist __P((char *, char *));
-void relative_filter __P((char *, char *, char *));
+static void setcom __P((int));
+int main __P((int, char **));
+void makefilter __P((char *));
+FILE *openfilter __P((void));
+void closefilter __P((FILE *));
+void completelist __P((char *, char *, char *));
+void relative_filter __P((STRBUF *, char *, char *));
void grep __P((char *));
-int printtag __P((FILE *, char *, char *, int));
-int regexp __P((char *));
+void pathlist __P((char *, char *));
+void parsefile __P((int, char **, char *, char *, char *, int));
+void printtag __P((FILE *, char *));
+int notnamechar __P((char *));
int search __P((char *, char *, char *, char *, int));
-char *extractpath __P((char *));
int includepath __P((char *, char *));
-char sortfilter[MAXCOMLINE+1]; /* sort filter */
-char pathfilter[MAXCOMLINE+1]; /* path convert filter */
-char local[MAXPATHLEN+1]; /* local prefix */
+char sortfilter[MAXFILLEN+1]; /* sort filter */
+char pathfilter[MAXFILLEN+1]; /* path convert filter */
char *localprefix; /* local prefix */
int aflag; /* [option] */
int cflag; /* command */
int fflag; /* command */
-int lflag; /* [option] */
int gflag; /* command */
int iflag; /* command */
+int lflag; /* [option] */
+int nflag; /* [option] */
int pflag; /* command */
+int Pflag; /* command */
int rflag; /* [option] */
int sflag; /* command */
+int tflag; /* [option] */
int vflag; /* [option] */
int xflag; /* [option] */
+int pfilter; /* undocumented command */
static void
usage()
{
- fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
- "global [-alrvx] pattern",
+ fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
+ "global [-alnrtvx] pattern",
"global -c [prefix]",
- "global -f[arx] file",
- "global -g[alvx] pattern",
+ "global -f[alnrtx] files",
+ "global -g[alntvx] pattern",
"global -i[v]",
- "global -p",
- "global -s[alvx] pattern");
+ "global -p[v]",
+ "global -P[alnt] [pattern]",
+ "global -s[alntvx] pattern");
exit(1);
}
-void
+static int command;
+static void
+setcom(c)
+int c;
+{
+ if (command == 0)
+ command = c;
+ else
+ usage();
+}
+int
main(argc, argv)
int argc;
char *argv[];
{
- char *p, *av;
+ char *av;
int count;
int db;
char cwd[MAXPATHLEN+1]; /* current directory */
char root[MAXPATHLEN+1]; /* root of source tree */
char dbpath[MAXPATHLEN+1]; /* dbpath directory */
- char comline[MAXCOMLINE+1];
while (--argc > 0 && (++argv)[0][0] == '-') {
+ char *p;
+
+ if (!strcmp(argv[0], "--filter")) {
+ pfilter++;
+ continue;
+ }
for (p = argv[0] + 1; *p; p++) {
switch (*p) {
case 'a':
@@ -108,27 +132,44 @@ char *argv[];
break;
case 'c':
cflag++;
+ setcom(*p);
break;
case 'f':
fflag++;
+ xflag++;
+ setcom(*p);
break;
case 'l':
lflag++;
break;
+ case 'n':
+ nflag++;
+ break;
case 'g':
gflag++;
+ setcom(*p);
break;
case 'i':
iflag++;
+ setcom(*p);
break;
case 'p':
pflag++;
+ setcom(*p);
+ break;
+ case 'P':
+ Pflag++;
+ setcom(*p);
break;
case 'r':
rflag++;
break;
case 's':
sflag++;
+ setcom(*p);
+ break;
+ case 't':
+ tflag++;
break;
case 'v':
vflag++;
@@ -141,44 +182,32 @@ char *argv[];
}
}
}
- av = (argc > 0) ? *argv : (char *)0;
+ av = (argc > 0) ? *argv : NULL;
/*
- * usage check.
+ * only -c, -i, -P and -p allows no argment.
*/
- {
- int commands, options;
-
- commands = cflag + fflag + gflag + iflag + pflag + sflag;
- options = aflag + lflag + rflag + xflag;
- /*
- * only -c, -i and -p allows no argment.
- */
- if (!av && !cflag && !iflag && !pflag)
- usage();
- /*
- * command cannot be duplicated.
- */
- if (commands > 1)
- usage();
- /*
- * -c and -i command allows only -v option.
- */
- if (cflag + iflag && options)
- usage();
- /*
- * -r is not valid for -g, -i and -s.
- */
- if (rflag && (gflag + iflag + sflag))
+ if (!av && !pfilter) {
+ switch (command) {
+ case 'c':
+ case 'i':
+ case 'p':
+ case 'P':
+ break;
+ default:
usage();
+ }
}
/*
+ * invalid options are just ignored.
+ */
+ /*
* remove leading blanks.
*/
if (av && !gflag)
for (; *av == ' ' || *av == '\t'; av++)
;
- if (cflag && av && regexp(av))
- die("regular expression not allowed with -c option.");
+ if (cflag && av && notnamechar(av))
+ die("only name char is allowed with -c option.");
/*
* get path of following directories.
* o current directory
@@ -187,6 +216,12 @@ char *argv[];
*
* if GTAGS not found, getdbpath doesn't return.
*/
+ if (pflag && vflag) {
+ char *gtagsdbpath = getenv("GTAGSDBPATH");
+ char *gtagsroot = getenv("GTAGSROOT");
+ if (gtagsdbpath && !gtagsroot)
+ fprintf(stdout, "warning: GTAGSDBPATH is ignored becase GTAGSROOT is not set.\n");
+ }
getdbpath(cwd, root, dbpath);
if (pflag) {
@@ -197,11 +232,18 @@ char *argv[];
* incremental update of tag files.
*/
if (iflag) {
+ STRBUF *sb = stropen();
+
if (chdir(root) < 0)
die1("cannot change directory to '%s'.", root);
- sprintf(comline, "gtags -i%s %s", (vflag) ? "v" : "", dbpath);
- if (system(comline))
+ strputs(sb, "gtags -i");
+ if (vflag)
+ strputc(sb, 'v');
+ strputc(sb, ' ');
+ strputs(sb, dbpath);
+ if (system(strvalue(sb)))
exit(1);
+ strclose(sb);
exit(0);
}
@@ -209,39 +251,62 @@ char *argv[];
* complete function name
*/
if (cflag) {
- completelist(dbpath, av);
+ completelist(dbpath, root, av);
exit(0);
}
/*
* make sort filter.
*/
if (sflag && xflag)
- *sortfilter = 0;
+ strcpy(sortfilter, "");
+ else if (tflag) /* ctags format */
+ strcpy(sortfilter, "sort +0 -1 +1 -2 +2n -3");
else if (fflag)
- sprintf(sortfilter, "sort +1n -2");
+ strcpy(sortfilter, "sort +2 -3 +1n -2");
else if (xflag) /* print details */
- sprintf(sortfilter, "sort +0 -1 +2 -3 +1n -2");
+ strcpy(sortfilter, "sort +0 -1 +2 -3 +1n -2");
else /* print just file name */
- sprintf(sortfilter, "sort | uniq");
+ strcpy(sortfilter, "sort | uniq");
/*
* make path filter.
*/
if (aflag) /* absolute path name */
sprintf(pathfilter, "sed -e 's!\\.!%s!'", root);
- else /* relative path name */
- relative_filter(root, cwd, pathfilter);
+ else { /* relative path name */
+ STRBUF *sb = stropen();
+
+ relative_filter(sb, root, cwd);
+ strcpy(pathfilter, strvalue(sb));
+ strclose(sb);
+ }
/*
* make local prefix.
*/
if (lflag) {
+ char *p = cwd + strlen(root);
+ STRBUF *sb = stropen();
/*
* getdbpath() assure follows.
* cwd != "/" and cwd includes root.
*/
- strcpy(local, cwd);
- strcat(local, "/");
- localprefix = local + strlen(root) - 1;
- *localprefix = '.';
+ strputc(sb, '.');
+ if (*p)
+ strputs(sb, p);
+ strputc(sb, '/');
+ localprefix = strdup(strvalue(sb));
+ if (!localprefix)
+ die("short of memory.");
+ strclose(sb);
+ }
+ /*
+ * print filter.
+ */
+ if (pfilter) {
+ char filter[MAXFILLEN+1];
+
+ makefilter(filter);
+ fprintf(stdout, "%s\n", filter);
+ exit(0);
}
/*
* grep the pattern in a source tree.
@@ -254,41 +319,19 @@ char *argv[];
grep(av);
exit(0);
}
+ /*
+ * locate the path including the pattern in a source tree.
+ */
+ if (Pflag) {
+ pathlist(dbpath, av);
+ exit(0);
+ }
db = (rflag) ? GRTAGS : ((sflag) ? GSYMS : GTAGS);
/*
* print function definitions.
*/
if (fflag) {
- struct stat sb;
- char pathbuf[MAXPATHLEN+1], *path;
- char *p;
- FILE *op;
- DBIO *dbio;
-
- /* av !~ /\.[chysS]$/) */
- p = av + strlen(av) - 1; /* last character */
- if (stat(av, &sb) || !S_ISREG(sb.st_mode))
- die1("file '%s' not found.", av);
- if (*(p - 1) != '.' || !locatestring("chysS", p, 0))
- die("accept only file name end with '.c .h .y .s .S'.");
- /*
- * convert path into relative from root directory of source tree.
- */
- path = realpath(av, pathbuf);
- if (*path != '/')
- die("realpath(3) is not compatible with BSD version.");
- if (strncmp(path, root, strlen(root)))
- die1("file '%s' is out of source tree.", path);
- path += strlen(root) - 1;
- *path = '.';
- if (!(op = popen(outfilter(), "w")))
- die("cannot open output pipe.");
- dbio = gtagsopen(dbpath, db, 0);
- for (p = db_first(dbio, NULL, DBIO_SKIPMETA); p; p = db_next(dbio))
- if (includepath(p, path))
- fprintf(op, "%s\n", p);
- db_close(dbio);
- pclose(op);
+ parsefile(argc, argv, cwd, root, dbpath, db);
exit(0);
}
/*
@@ -298,28 +341,30 @@ char *argv[];
/*
* search in library path.
*/
- if (count == 0 && !rflag && !sflag && !regexp(av) && getenv("GTAGSLIBPATH")) {
- char envbuf[MAXENVLEN+1];
+ if (count == 0 && !rflag && !sflag && !notnamechar(av) && getenv("GTAGSLIBPATH")) {
+ char buf[MAXENVLEN+1];
char libdbpath[MAXPATHLEN+1];
char *p, *lib;
- strcpy(envbuf, getenv("GTAGSLIBPATH"));
- p = envbuf;
+ strcpy(buf, getenv("GTAGSLIBPATH"));
+ p = buf;
while (p) {
lib = p;
- if ((p = locatestring(p, ":", 0)) != NULL)
+ if ((p = locatestring(p, ":", MATCH_FIRST)) != NULL)
*p++ = 0;
- if (!strncmp(lib, cwd, strlen(cwd)) || !strncmp(cwd, lib, strlen(lib)))
- continue;
if (!gtagsexist(lib, libdbpath))
continue;
if (!strcmp(dbpath, libdbpath))
continue;
if (aflag) /* absolute path name */
sprintf(pathfilter, "sed -e 's!\\.!%s!'", lib);
- else
- relative_filter(lib, cwd, pathfilter);
- count = search(av, cwd, lib, libdbpath, GTAGS);
+ else {
+ STRBUF *sb = stropen();
+ relative_filter(sb, lib, cwd);
+ strcpy(pathfilter, strvalue(sb));
+ strclose(sb);
+ }
+ count = search(av, cwd, lib, libdbpath, db);
if (count > 0) {
strcpy(dbpath, libdbpath);
break;
@@ -340,58 +385,91 @@ char *argv[];
exit(0);
}
/*
- * outfilter: return output filter.
+ * makefilter: make filter string.
+ *
+ * io) filter buffer
+ */
+void
+makefilter(filter)
+char *filter;
+{
+ if (nflag)
+ filter[0] = 0;
+ else if (sortfilter[0] == 0 && pathfilter[0] == 0)
+ filter[0] = 0;
+ else if (sortfilter[0] && pathfilter[0])
+ sprintf(filter, "%s | %s", sortfilter, pathfilter);
+ else if (sortfilter[0])
+ strcpy(filter, sortfilter);
+ else
+ strcpy(filter, pathfilter);
+}
+/*
+ * openfilter: open output filter.
*
* gi) pathfilter
* gi) sortfilter
* r) output filter
*/
-char *
-outfilter(void)
+FILE *
+openfilter(void)
{
- static char filter[MAXCOMLINE+1];
+ FILE *op;
+ char filter[MAXFILLEN+1];
- /*
- * make output filter
- */
- if (*sortfilter)
- sprintf(filter, "%s | %s", sortfilter, pathfilter);
+ makefilter(filter);
+ if (filter[0] == 0)
+ op = stdout;
else
- strcpy(filter, pathfilter);
- return filter;
+ op = popen(filter, "w");
+ return op;
+}
+void
+closefilter(op)
+FILE *op;
+{
+ if (op != stdout)
+ pclose(op);
}
/*
* completelist: print complete list of function
*
* i) dbpath dbpath directory
+ * i) root root directory
* i) prefix prefix of primary key
*/
void
-completelist(dbpath, prefix)
+completelist(dbpath, root, prefix)
char *dbpath;
+char *root;
char *prefix;
{
char *p;
- DBIO *dbio;
+ int flags = GTOP_KEY;
+ GTOP *gtop;
- dbio = gtagsopen(dbpath, GTAGS, 0);
- for (p = db_first(dbio, prefix, DBIO_KEY|DBIO_PREFIX|DBIO_SKIPMETA); p; p = db_next(dbio))
+ if (prefix && *prefix == 0) /* In the case global -c '' */
+ prefix = NULL;
+ if (prefix)
+ flags |= GTOP_PREFIX;
+ gtop = gtagsopen(dbpath, root, GTAGS, GTAGS_READ, 0);
+ for (p = gtagsfirst(gtop, prefix, flags); p; p = gtagsnext(gtop))
(void)fprintf(stdout, "%s\n", p);
- db_close(dbio);
+ gtagsclose(gtop);
}
/*
* relative_filter: make relative path filter
*
+ * i) sb string buffer
* i) root the root directory of source tree
- * i) argcwd current directory
- * o) bp result
- * relative path filter
+ * i) cwd current directory
+ * r) relative path filter
*/
void
-relative_filter(root, cwd, bp)
+relative_filter(sb, root, cwd)
+STRBUF *sb;
char *root;
char *cwd;
-char *bp;
{
char *p, *c, *branch;
@@ -404,38 +482,36 @@ char *bp;
branch = c;
if (*p == 0 && (*c == 0 || *c == '/'))
branch = c;
- if (*c == 0 && *p)
- die("illegal root.");
/*
* forward to root.
*/
- strcpy(bp, "sed -e 's!\\./!");
+ strputs(sb, "sed -e 's!\\./!");
for (c = branch; *c; c++)
if (*c == '/')
- strcat(bp, "../");
+ strputs(sb, "../");
p = root + (branch - cwd);
/*
* backward to leaf.
*/
if (*p) {
p++;
- strcat(bp, p);
- strcat(bp, "/");
+ strputs(sb, p);
+ strputc(sb, '/');
}
- strcat(bp, "!'");
+ strputs(sb, "!'");
/*
* remove redundancy.
*/
if (*branch) {
char unit[256];
- bp += strlen(bp);
p = unit;
for (c = branch + 1; ; c++) {
if (*c == 0 || *c == '/') {
*p = 0;
- sprintf(bp, " -e 's!\\.\\./%s/!!'", unit);
- bp += strlen(bp);
+ strputs(sb, " -e 's!\\.\\./");
+ strputs(sb, unit);
+ strputs(sb, "/!!'");
if (*c == 0)
break;
p = unit;
@@ -448,107 +524,66 @@ char *bp;
* printtag: print a tag's line
*
* i) op output stream
- * i) root root of source tree
* i) bp tag's line
- * i) compact 0: standard format, 1: compact format
- * r) output line count
*/
-int
-printtag(op, root, bp, compact)
+void
+printtag(op, bp)
FILE *op;
-char *root;
char *bp;
-int compact;
{
- int count = 0;
- char *tag, *file, *lno;
- int opened = 0;
- char path[MAXPATHLEN+1];
- char *buffer;
- int line = 0, tagline = 0;
- FILE *ip;
-
- if (!xflag) {
- fprintf(op, "%s\n", extractpath(bp));
- return 1;
- }
- if (compact) { /* compact format */
+ if (tflag) {
+ char buf[MAXBUFLEN+1];
+ char lno[20], *l = lno;
char *p = bp;
+ char *q = buf;
- tag = p; /* tag = $1 */
- for (; !isspace(*p) ; p++)
- ;
- *p++ = 0;
- for (; isspace(*p) ; p++)
+ while (*p && !isspace(*p))
+ *q++ = *p++;
+ *q++ = '\t';
+ for (; *p && isspace(*p); p++)
;
- file = p; /* file = $2 */
- for (; !isspace(*p) ; p++)
+ while (*p && isdigit(*p))
+ *l++ = *p++;
+ *l = 0;
+ for (; *p && isspace(*p); p++)
;
- *p++ = 0;
- for (; isspace(*p) ; p++)
- ;
- lno = p; /* lno = $3 */
- sprintf(path, "%s/%s", root, file + 2);
- if ((ip = fopen(path, "r")) != NULL) {
- opened = 1;
- buffer = mgets(ip, 0, NULL);
- line = 1;
- } else {
- buffer = "";
- }
- while (*lno) {
- /* get line number */
- for (tagline = 0; *lno >= '0' && *lno <= '9'; lno++)
- tagline = tagline * 10 + *lno - '0';
- if (*lno == ',')
- lno++;
- if (opened) {
- while (line < tagline) {
- if (!(buffer = mgets(ip, 0, NULL)))
- die1("unexpected end of file. '%s'", path);
- line++;
- }
- }
- if (strlen(tag) >= 16 && tagline >= 1000)
- fprintf(op, "%-16s %4d %-16s %s\n",
- tag, tagline, file, buffer);
- else
- fprintf(op, "%-16s%4d %-16s %s\n",
- tag, tagline, file, buffer);
- count++;
- }
- if (opened)
- fclose(ip);
- } else { /* standard format */
- /*
- * separater in key part must be ' ' to avoid sort(1)'s bug.
- */
+ while (*p && !isspace(*p))
+ *q++ = *p++;
+ *q++ = '\t';
+ l = lno;
+ while (*l)
+ *q++ = *l++;
+ *q = 0;
+ fprintf(op, "%s\n", buf);
+ } else if (!xflag) {
+ char *p = locatestring(bp, "./", MATCH_FIRST);
+
+ if (p == NULL)
+ die("illegal tag format (path not found).");
+ while (*p && *p != ' ' && *p != '\t')
+ (void)putc(*p++, op);
+ (void)putc('\n', op);
+ } else
detab(op, bp);
- count++;
- }
- return count;
}
/*
- * regexp: test whether regular expression included.
+ * notnamechar: test whether or not no name char included.
*
* i) s string
* r) 0: not included, 1: included
- *
- * This function cannot be used for generic purpose.
- * Any character except '[a-zA-Z_0-9]' is assumed RE char..
*/
int
-regexp(s)
+notnamechar(s)
char *s;
{
int c;
- while ((c = *s++) != NULL)
+ while ((c = *s++) != '\0')
if ( (c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
- (c == '_') )
+ (c == '-') || (c == '_'))
;
else
return 1;
@@ -566,42 +601,46 @@ char *pattern;
FILE *op, *fp;
char *path;
char edit[IDENTLEN+1];
- char *buffer, *p, *e;
+ char *buffer;
int linenum, count, editlen;
regex_t preg;
/*
* convert spaces into %FF format.
*/
- e = edit;
- for (p = pattern; *p; p++) {
- if (*p == '%' || *p == ' ' || *p == '\t') {
- sprintf(e, "%%%02x", *p);
- e += 3;
- } else
- *e++ = *p;
+ {
+ char *p, *e = edit;
+ for (p = pattern; *p; p++) {
+ if (*p == '%' || *p == ' ' || *p == '\t') {
+ sprintf(e, "%%%02x", *p);
+ e += 3;
+ } else
+ *e++ = *p;
+ }
+ *e = 0;
}
- *e = 0;
editlen = strlen(edit);
if (regcomp(&preg, pattern, REG_EXTENDED) != 0)
die("illegal regular expression.");
- if (!(op = popen(outfilter(), "w")))
- die("cannot open output pipe.");
+ if (!(op = openfilter()))
+ die("cannot open output filter.");
count = 0;
for (findopen(); (path = findread(NULL)) != NULL; ) {
if (!(fp = fopen(path, "r")))
die1("cannot open file '%s'.", path);
linenum = 0;
- while ((buffer = mgets(fp, 0, NULL)) != NULL) {
+ while ((buffer = mgets(fp, NULL, 0)) != NULL) {
linenum++;
if (regexec(&preg, buffer, 0, 0, 0) == 0) {
count++;
- if (xflag == 0) {
+ if (tflag)
+ fprintf(op, "%s\t%s\t%d\n",
+ edit, path, linenum);
+ else if (!xflag) {
fprintf(op, "%s\n", path);
break;
- }
- if (editlen >= 16 && linenum >= 1000)
+ } else if (editlen >= 16 && linenum >= 1000)
fprintf(op, "%-16s %4d %-16s %s\n",
edit, linenum, path, buffer);
else
@@ -612,7 +651,7 @@ char *pattern;
fclose(fp);
}
findclose();
- pclose(op);
+ closefilter(op);
if (vflag) {
if (count == 0)
fprintf(stderr, "object not found.\n");
@@ -622,7 +661,132 @@ char *pattern;
fprintf(stderr, "%d objects located.\n", count);
}
}
+/*
+ * pathlist: print candidate path list.
+ *
+ * i) dbpath
+ */
+void
+pathlist(dbpath, av)
+char *dbpath;
+char *av;
+{
+ FILE *op;
+ const char *tag = av;
+ char key[10], *path;
+ regex_t preg;
+ int i, lim;
+ if (av) {
+ if (regcomp(&preg, av, REG_EXTENDED) != 0)
+ die("illegal regular expression.");
+ } else
+ tag = "file";
+ if (!(op = openfilter()))
+ die("cannot open output filter.");
+ if (pathopen(dbpath, 0) < 0)
+ die("GPATH not found.");
+ lim = nextkey();
+ for (i = 0; i < lim; i++) {
+ sprintf(key, "%d", i);
+ if ((path = pathget(key)) == NULL)
+ continue;
+ if (lflag && !locatestring(path, localprefix, MATCH_AT_FIRST))
+ continue;
+ if (av && regexec(&preg, path + 2, 0, 0, 0) != 0)
+ continue;
+ if (tflag)
+ fprintf(op, "%s\t%s\t1\n", tag, path);
+ else
+ fprintf(op, "%s\n", path);
+ }
+ pathclose();
+ closefilter(op);
+}
+/*
+ * parsefile: parse file to pick up tags.
+ *
+ * i) db
+ * i) dbpath
+ * i) root
+ * i) cwd
+ * i) argc
+ * i) argv
+ */
+void
+parsefile(argc, argv, cwd, root, dbpath, db)
+int argc;
+char **argv;
+char *cwd;
+char *root;
+char *dbpath;
+int db;
+{
+ char buf[MAXPATHLEN+1], *path;
+ char *p;
+ FILE *ip, *op;
+ char *parser, *av;
+ STRBUF *sb = stropen();
+ STRBUF *com = stropen();
+
+ /*
+ * get parser.
+ */
+ if (!getconfs(dbname(db), sb))
+ die1("cannot get parser for %s.", dbname(db));
+ parser = strvalue(sb);
+
+ if (!(op = openfilter()))
+ die("cannot open output filter.");
+ if (pathopen(dbpath, 0) < 0)
+ die("GPATH not found.");
+ for (; argc > 0; argv++, argc--) {
+ av = argv[0];
+
+ if (test("d", av)) {
+ fprintf(stderr, "'%s' is a directory.\n", av);
+ continue;
+ }
+ if (!test("f", NULL)) {
+ fprintf(stderr, "'%s' not found.\n", av);
+ continue;
+ }
+ /*
+ * convert path into relative from root directory of source tree.
+ */
+ path = realpath(av, buf);
+ if (*path != '/')
+ die("realpath(3) is not compatible with BSD version.");
+ if (strncmp(path, root, strlen(root))) {
+ fprintf(stderr, "'%s' is out of source tree.\n", path);
+ continue;
+ }
+ path += strlen(root) - 1;
+ *path = '.';
+ if (!pathget(path)) {
+ fprintf(stderr, "'%s' not found in GPATH.\n", path);
+ continue;
+ }
+ if (chdir(root) < 0)
+ die1("cannot move to '%s' directory.", root);
+ /*
+ * make command line.
+ */
+ strstart(com);
+ makecommand(parser, path, com);
+ if (!(ip = popen(strvalue(com), "r")))
+ die1("cannot execute '%s'.", strvalue(com));
+ while ((p = mgets(ip, NULL, 0)) != NULL)
+ printtag(op, p);
+ pclose(ip);
+ if (chdir(cwd) < 0)
+ die1("cannot move to '%s' directory.", cwd);
+ }
+ pathclose();
+ closefilter(op);
+ strclose(com);
+ strclose(sb);
+}
/*
* search: search specified function
*
@@ -644,87 +808,79 @@ int db;
char *p;
int count = 0;
FILE *op;
- DBIO *dbio;
- int compact;
+ GTOP *gtop;
regex_t preg;
/*
* open tag file.
- * currently only GSYMS is compact format.
*/
- dbio = gtagsopen(dbpath, db, 0);
- compact = (db == GSYMS) ? 1 : 0;
- if (!(op = popen(outfilter(), "w")))
- die1("filter '%s' failed.", outfilter());
+ gtop = gtagsopen(dbpath, root, db, GTAGS_READ, 0);
+ if (!(op = openfilter()))
+ die("cannot open output filter.");
/*
* regular expression.
*/
- if (regexp(pattern) && regcomp(&preg, pattern, REG_EXTENDED) == 0) {
- char prefix_buf[IDENTLEN+1];
- char *prefix = (char *)0;
+ if (!strcmp(pattern, ".*")) {
+ for (p = gtagsfirst(gtop, NULL, 0); p; p = gtagsnext(gtop)) {
+ if (lflag) {
+ char *q;
+ /* locate start point of a path */
+ q = locatestring(p, "./", MATCH_FIRST);
+ if (!locatestring(q, localprefix, MATCH_AT_FIRST))
+ continue;
+ }
+ printtag(op, p);
+ count++;
+ }
+ } else if (notnamechar(pattern) && regcomp(&preg, pattern, REG_EXTENDED) == 0) {
if (*pattern == '^' && *(p = pattern + 1) && (isalpha(*p) || *p == '_')) {
- prefix = prefix_buf;
+ char buf[IDENTLEN+1];
+ char *prefix = buf;
+
*prefix++ = *p++;
while (*p && (isalpha(*p) || isdigit(*p) || *p == '_'))
*prefix++ = *p++;
*prefix = 0;
- prefix = prefix_buf;
- p = db_first(dbio, prefix, DBIO_SKIPMETA|DBIO_PREFIX);
+ prefix = buf;
+ p = gtagsfirst(gtop, prefix, GTOP_PREFIX);
} else {
- p = db_first(dbio, NULL, DBIO_SKIPMETA);
+ p = gtagsfirst(gtop, NULL, 0);
}
- for (; p; p = db_next(dbio)) {
- if (*p == ' ')
+ for (; p; p = gtagsnext(gtop)) {
+ /*
+ * search $1 of tag line (not key)
+ */
+ if (regexec(&preg, strmake(gtop->dbop->lastdat, " \t"), 0, 0, 0) != 0)
continue;
- if (regexec(&preg, dbio->lastkey, 0, 0, 0) == 0)
- count += printtag(op, root, p, compact);
+ if (lflag) {
+ char *q;
+ /* locate start point of a path */
+ q = locatestring(p, "./", MATCH_FIRST);
+ if (!locatestring(q, localprefix, MATCH_AT_FIRST))
+ continue;
+ }
+ printtag(op, p);
+ count++;
}
} else {
- for (p = db_first(dbio, pattern, 0); p; p = db_next(dbio)) {
+ for (p = gtagsfirst(gtop, pattern, 0); p; p = gtagsnext(gtop)) {
if (lflag) {
char *q;
/* locate start point of a path */
- q = locatestring(p, "./", 0);
- if (!locatestring(q, localprefix, 1))
+ q = locatestring(p, "./", MATCH_FIRST);
+ if (!locatestring(q, localprefix, MATCH_AT_FIRST))
continue;
}
- count += printtag(op, root, p, compact);
+ printtag(op, p);
+ count++;
}
}
- pclose(op);
- db_close(dbio);
+ closefilter(op);
+ gtagsclose(gtop);
return count;
}
/*
- * extractpath: extract path string of a tag line
- *
- * i) line tag line
- * r) path
- *
- * standard format: main 12 ./xxx/xxx/xxx.c main(argc, argv) {
- * compact format: main ./xxx/xxx/xxx.c 12,15,55,101
- */
-char *
-extractpath(line)
-char *line;
-{
- static char buf[MAXPATHLEN+1];
- char *p, *b;
- int c;
-
- if (!(p = locatestring(line, "./", 0)))
- die("illegal tag format (path not found).");
- b = buf;
- while ((c = *b++ = *p++) != NULL) {
- if (c == ' ' || c == '\t') {
- *(b - 1) = 0;
- break;
- }
- }
- return buf;
-}
-/*
* includepath: check if the path included in tag line or not.
*
* i) line tag line
@@ -739,7 +895,7 @@ char *path;
char *p;
int length;
- if (!(p = locatestring(line, "./", 0)))
+ if (!(p = locatestring(line, "./", MATCH_FIRST)))
die("illegal tag format (path not found).");
length = strlen(path);
if (strncmp(p, path, length))
diff --git a/contrib/global/gtags.el b/contrib/global/gtags.el
index 2a8de7950e56..22dcc9356315 100644
--- a/contrib/global/gtags.el
+++ b/contrib/global/gtags.el
@@ -1,7 +1,7 @@
;;; gtags.el --- gtags facility for Emacs
;;
-;; Copyright (c) 1997 Shigio Yamaguchi. All rights reserved.
+;; Copyright (c) 1997, 1998, 1999 Shigio Yamaguchi. All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
@@ -30,12 +30,12 @@
;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
;; SUCH DAMAGE.
;;
-;; gtags.el 31-Aug-97
+;; gtags.el 8-Jan-99
;;
;; This file is part of GLOBAL.
;; Author: Shigio Yamaguchi <shigio@wafu.netgate.net>
-;; Version: 1.1
+;; Version: 1.5
;; Keywords: tools
;;; Code
@@ -59,6 +59,7 @@
(define-key gtags-mode-map "\es" 'gtags-find-symbol)
(define-key gtags-mode-map "\eg" 'gtags-find-pattern)
(define-key gtags-mode-map "\C-]" 'gtags-find-tag-from-here)
+(define-key gtags-mode-map "\eh" 'gtags-display-browser)
(define-key gtags-mode-map "\C-t" 'gtags-pop-stack)
(define-key gtags-mode-map "\e." 'etags-style-find-tag)
(define-key gtags-mode-map [mouse-2] 'gtags-find-tag-by-event)
@@ -83,7 +84,7 @@
;;
;; utility
;;
-(defun match-string (n)
+(defun util-match-string (n)
(buffer-substring (match-beginning n) (match-end n)))
;; Return a default tag to search for, based on the text at point.
@@ -99,7 +100,7 @@
(if (and (bolp) (looking-at definition-regexp))
(goto-char (match-end 0)))
(if (looking-at symbol-regexp)
- (match-string 0) nil))
+ (util-match-string 0) nil))
;; push current context to stack
(defun push-context ()
@@ -132,18 +133,20 @@
;; is it a definition?
(defun is-definition ()
(save-excursion
- (if (bolp)
+ (if (and (string-match "\.java$" buffer-file-name) (looking-at "[^(]+([^)]*)[ \t]*{"))
t
- (forward-word -1)
- (cond
- ((looking-at "define")
- (forward-char -1)
- (while (and (not (bolp)) (looking-at "[ \t]"))
- (forward-char -1))
- (if (and (bolp) (looking-at "#"))
- t nil))
- ((looking-at "ENTRY\\|ALTENTRY")
- (if (bolp) t nil))))))
+ (if (bolp)
+ t
+ (forward-word -1)
+ (cond
+ ((looking-at "define")
+ (forward-char -1)
+ (while (and (not (bolp)) (looking-at "[ \t]"))
+ (forward-char -1))
+ (if (and (bolp) (looking-at "#"))
+ t nil))
+ ((looking-at "ENTRY\\|ALTENTRY")
+ (if (bolp) t nil)))))))
;;
;; interactive command
@@ -216,6 +219,18 @@
(push-context)
(gtags-goto-tag tagname flag))))
+(defun gtags-display-browser ()
+ "Display current screen on hypertext browser."
+ (interactive)
+ (let (lno)
+ (save-excursion
+ (end-of-line)
+ (if (equal (point-min) (point))
+ (setq lno 1)
+ (setq lno (count-lines (point-min) (point)))))
+ (message (number-to-string lno))
+ (call-process "gozilla" nil t nil (concat "+" (number-to-string lno)) buffer-file-name)))
+
(defun gtags-find-tag-by-event (event)
"Get the expression as a tagname around here and move there."
(interactive "e")
@@ -307,8 +322,8 @@
;; (if (not (looking-at "[A-Za-z_][A-Za-z_0-9]*[ \t]+\\([0-9]+\\)[ \t]\\([^ \t]+\\)[ \t]"))
(if (not (looking-at "[^ \t]+[ \t]+\\([0-9]+\\)[ \t]\\([^ \t]+\\)[ \t]"))
(pop-context)
- (setq line (string-to-number (match-string 1)))
- (setq file (match-string 2))
+ (setq line (string-to-number (util-match-string 1)))
+ (setq file (util-match-string 2))
(if delete (kill-buffer (current-buffer)))
;; move to the context
(if gtags-read-only (find-file-read-only file) (find-file file))
@@ -317,13 +332,15 @@
;; make complete list
(defun make-gtags-complete-list ()
+;; "Make tag name list for completion."
+;; (interactive)
(save-excursion
(setq gtags-complete-list (make-vector 63 0))
(set-buffer (generate-new-buffer "*Completions*"))
(call-process "global" nil t nil "-c")
(goto-char (point-min))
(while (looking-at symbol-regexp)
- (intern (match-string 0) gtags-complete-list)
+ (intern (util-match-string 0) gtags-complete-list)
(forward-line))
(kill-buffer (current-buffer))))
@@ -331,7 +348,8 @@
(defun gtags-mode ()
"Minor mode for browsing C source using GLOBAL."
(interactive)
- (make-gtags-complete-list)
+ (if (y-or-n-p "Do you use function name completion?")
+ (make-gtags-complete-list))
(use-local-map gtags-mode-map)
(run-hooks 'gtags-mode-hook))
diff --git a/contrib/global/gtags/gtags.c b/contrib/global/gtags/gtags.c
index bfd9aba0995c..7a88747e29ac 100644
--- a/contrib/global/gtags/gtags.c
+++ b/contrib/global/gtags/gtags.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,10 +28,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * gtags.c 12-Dec-97
+ * gtags.c 8-Oct-98
*
*/
-
+#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
@@ -43,46 +43,90 @@
#include "global.h"
-char *progname = "gtags"; /* command name */
+const char *progname = "gtags"; /* command name */
static void usage __P((void));
-void main __P((int, char **));
-int incremental __P((char *));
-void tagadd __P((int, char *));
-void createtags __P((char *, int));
-char *current __P((void));
+int main __P((int, char **));
+int incremental __P((char *, char *));
+void updatetags __P((char *, char *, char *, int));
+void createtags __P((char *, char *, int));
+int printconf __P((char *));
+char *now __P((void));
-static int iflag;
-static int oflag;
-static int vflag;
+int cflag; /* compact format */
+int iflag; /* incremental update */
+int oflag; /* suppress making GSYMS */
+int wflag; /* warning message */
+int vflag; /* verbose mode */
+int extractmethod = 0;
static void
usage()
{
- fprintf(stderr, "usage:\t%s [-i][-o][-v][dbpath]\n", progname);
+ fprintf(stderr, "usage:\t%s [-c][-i][-l][-o][-w][-v][dbpath]\n", progname);
exit(1);
}
-void
+int
main(argc, argv)
int argc;
char *argv[];
{
char dbpath[MAXPATHLEN+1];
+ char cwd[MAXPATHLEN+1];
char env[MAXENVLEN+1];
- char *p;
+ STRBUF *sb = stropen();
int db;
while (--argc > 0 && (++argv)[0][0] == '-') {
+ char *p;
+ /*
+ * Secret option for htags(1).
+ */
+ if (!strcmp(argv[0], "--config")) {
+ if (argc == 1)
+ fprintf(stdout, "%s\n", configpath());
+ else if (argc == 2) {
+ if (!printconf(argv[1]))
+ exit(1);
+ }
+ exit(0);
+ } else if (!strcmp(argv[0], "--find")) {
+ for (findopen(); (p = findread(NULL)) != NULL; )
+ fprintf(stdout, "%s\n", p);
+ findclose();
+ exit(0);
+ } else if (!strcmp(argv[0], "--expand")) {
+ FILE *ip;
+
+ ++argv; --argc;
+ if (argc && argv[0][0] == '-') {
+ settabs(atoi(&argv[0][1]));
+ ++argv; --argc;
+ }
+ ip = (argc) ? fopen(argv[0], "r") : stdin;
+ if (ip == NULL)
+ exit(1);
+ while ((p = mgets(ip, NULL, 0)) != NULL)
+ detab(stdout, p);
+ exit(0);
+ }
+
for (p = argv[0] + 1; *p; p++) {
switch (*p) {
+ case 'c':
+ cflag++;
+ break;
case 'i':
iflag++;
break;
case 'o':
oflag++;
break;
+ case 'w':
+ wflag++;
+ break;
case 'v':
vflag++;
break;
@@ -95,30 +139,48 @@ char *argv[];
}
}
}
- if (argc > 0) {
- strcpy(dbpath, *argv);
- } else {
- if (!getcwd(dbpath, MAXPATHLEN))
- die("cannot get current directory.");
- }
+ if (!getcwd(cwd, MAXPATHLEN))
+ die("cannot get current directory.");
+ if (argc > 0)
+ realpath(*argv,dbpath) ;
+ else
+ strcpy(dbpath, cwd);
if (!strcmp(dbpath, "/"))
die("It's root directory! What are you doing?");
if (!test("d", dbpath))
die1("directory '%s' not found.", dbpath);
if (vflag)
- fprintf(stderr, "[%s] Gtags started\n", current());
+ fprintf(stderr, "[%s] Gtags started\n", now());
+ /*
+ * load .gtagsrc or /etc/gtags.conf
+ */
+ openconf();
+ if (getconfb("extractmethod"))
+ extractmethod = 1;
+ strstart(sb);
+ if (getconfs("format", sb) && !strcmp(strvalue(sb), "compact"))
+ cflag++;
/*
* teach gctags(1) where is dbpath.
*/
sprintf(env, "GTAGSDBPATH=%s", dbpath);
putenv(env);
+ if (wflag) {
+ sprintf(env, "GTAGSWARNING=1");
+ putenv(env);
+ }
/*
* incremental update.
*/
if (iflag && test("f", makepath(dbpath, dbname(GTAGS))) &&
test("f", makepath(dbpath, dbname(GRTAGS))))
{
- (void)incremental(dbpath);
+ /* open for version check */
+ GTOP *gtop = gtagsopen(dbpath, cwd, GTAGS, GTAGS_MODIFY, 0);
+ gtagsclose(gtop);
+ if (!test("f", makepath(dbpath, "GPATH")))
+ die("Old version tag file found. Please remake it.");
+ (void)incremental(dbpath, cwd);
exit(0);
}
if (iflag && vflag)
@@ -127,32 +189,43 @@ char *argv[];
* create GTAGS, GRTAGS and GSYMS
*/
for (db = GTAGS; db < GTAGLIM; db++) {
+
if (oflag && db == GSYMS)
continue;
+ strstart(sb);
+ if (!getconfs(dbname(db), sb))
+ continue;
+ if (!usable(strmake(strvalue(sb), " \t")))
+ die1("Parser '%s' not found or not executable.", strmake(strvalue(sb), " \t"));
if (vflag)
- fprintf(stderr, "[%s] Creating '%s'.\n", current(), dbname(db));
- createtags(dbpath, db);
+ fprintf(stderr, "[%s] Creating '%s'.\n", now(), dbname(db));
+ createtags(dbpath, cwd, db);
}
if (vflag)
- fprintf(stderr, "[%s] Done.\n", current());
+ fprintf(stderr, "[%s] Done.\n", now());
+ closeconf();
exit(0);
}
/*
* incremental: incremental update
*
* i) dbpath dbpath directory
+ * i) root root directory of source tree
* r) 0: not updated, 1: updated
*/
int
-incremental(dbpath)
+incremental(dbpath, root)
char *dbpath;
+char *root;
{
- struct stat sb;
+ struct stat statp;
time_t gtags_mtime;
+ STRBUF *addlist = stropen();
+ STRBUF *updatelist = stropen();
+ STRBUF *deletelist = stropen();
int updated = 0;
char *path;
- int db;
if (vflag) {
fprintf(stderr, " Tag found in '%s'.\n", dbpath);
@@ -162,145 +235,255 @@ char *dbpath;
* get modified time of GTAGS.
*/
path = makepath(dbpath, dbname(GTAGS));
- if (stat(path, &sb) < 0)
+ if (stat(path, &statp) < 0)
die1("stat failed '%s'.", path);
- gtags_mtime = sb.st_mtime;
+ gtags_mtime = statp.st_mtime;
+ if (pathopen(dbpath, 0) < 0)
+ die("GPATH not found.");
+ /*
+ * make add list and update list.
+ */
for (findopen(); (path = findread(NULL)) != NULL; ) {
- if (stat(path, &sb) < 0)
+ if (stat(path, &statp) < 0)
die1("stat failed '%s'.", path);
- /*
- * only the path modified after GTAGS was modified.
- */
- if (gtags_mtime < sb.st_mtime) {
- updated = 1;
- if (vflag)
- fprintf(stderr, " Updating tags of '%s' ...", path + 2);
- for (db = GTAGS; db < GTAGLIM; db++) {
- if (db == GSYMS && !test("f", makepath(dbpath, dbname(db))))
- continue;
- if (vflag)
- fprintf(stderr, "%s", dbname(db));
- tagopen(dbpath, db, 2);
- /*
- * GTAGS needed to make GRTAGS.
- */
- if (db == GRTAGS)
- lookupopen(dbpath);
- tagdelete(path);
- if (vflag)
- fprintf(stderr, "..");
- tagadd(db, path);
- if (db == GRTAGS)
- lookupclose();
- tagclose();
- }
- if (vflag)
- fprintf(stderr, " Done.\n");
- }
+ if (!pathget(path))
+ strnputs(addlist, path, strlen(path) + 1);
+ else if (gtags_mtime < statp.st_mtime)
+ strnputs(updatelist, path, strlen(path) + 1);
}
findclose();
+ /*
+ * make delete list.
+ */
+ {
+ int i, limit = nextkey();
+
+ for (i = 0; i < limit; i++) {
+ if ((path = pathiget(i)) == NULL)
+ continue;
+ if (!test("f", path))
+ strnputs(deletelist, path, strlen(path) + 1);
+ }
+ }
+ pathclose();
+ if (strbuflen(addlist) + strbuflen(deletelist) + strbuflen(updatelist))
+ updated = 1;
+ /*
+ * execute updating.
+ */
+ if (strbuflen(updatelist) > 0) {
+ char *start = strvalue(updatelist);
+ char *end = start + strbuflen(updatelist);
+ char *p;
+
+ for (p = start; p < end; p += strlen(p) + 1)
+ updatetags(dbpath, root, p, 0);
+ updated = 1;
+ }
+ if (strbuflen(addlist) > 0) {
+ char *start = strvalue(addlist);
+ char *end = start + strbuflen(addlist);
+ char *p;
+
+ for (p = start; p < end; p += strlen(p) + 1)
+ updatetags(dbpath, root, p, 1);
+ updated = 1;
+ }
+ if (strbuflen(deletelist) > 0) {
+ char *start = strvalue(deletelist);
+ char *end = start + strbuflen(deletelist);
+ char *p;
+
+ for (p = start; p < end; p += strlen(p) + 1)
+ updatetags(dbpath, root, p, 2);
+
+ pathopen(dbpath, 2);
+ for (p = start; p < end; p += strlen(p) + 1)
+ pathdel(p);
+ pathclose();
+ updated = 1;
+ }
if (vflag) {
if (updated)
fprintf(stderr, " Global databases have been modified.\n");
else
fprintf(stderr, " Global databases are up to date.\n");
- fprintf(stderr, "[%s] Done.\n", current());
-
- fprintf(stderr, " Done.\n");
+ fprintf(stderr, "[%s] Done.\n", now());
}
+ strclose(addlist);
+ strclose(deletelist);
+ strclose(updatelist);
return updated;
}
/*
- * tagadd: add records which has specified path.
+ * updatetags: update tag file.
*
- * i) db 0: GTAGS, 1: GRTAGS, 2: GSYMS
- * i) path source file
+ * i) dbpath directory in which tag file exist
+ * i) root root directory of source tree
+ * i) path path which should be updated
+ * i) type 0:update, 1:add, 2:delete
*/
void
-tagadd(db, path)
-int db;
+updatetags(dbpath, root, path, type)
+char *dbpath;
+char *root;
char *path;
+int type;
{
- char *tagline, *p, *q;
- char key[IDENTLEN+1];
- FILE *ip;
+ GTOP *gtop;
+ STRBUF *sb = stropen();
+ int db;
+ const char *msg = NULL;
- stropen();
- /*
- * make command line.
- */
- strputs("gctags -Dex");
- if (db == GRTAGS)
- strputs("r");
- if (db == GSYMS)
- strputs("sc");
- strputc(' ');
- strputs(path);
- p = strclose();
- if (!(ip = popen(p, "r")))
- die1("cannot execute '%s'.", p);
- while ((tagline = mgets(ip, 0, NULL)) != NULL) {
- p = tagline;
- q = key;
- while (*p && !isspace(*p))
- *q++ = *p++;
- *q = 0;
- tagput(key, tagline);
+ switch (type) {
+ case 0: msg = "Updating"; break;
+ case 1: msg = "Adding"; break;
+ case 2: msg = "Deleting"; break;
+ }
+ if (vflag)
+ fprintf(stderr, " %s tags of '%s' ...", msg, path + 2);
+ for (db = GTAGS; db < GTAGLIM; db++) {
+ int flags = 0;
+
+ if (db == GSYMS && !test("f", makepath(dbpath, dbname(db))))
+ continue;
+ if (vflag)
+ fprintf(stderr, "%s", dbname(db));
+ /*
+ * get tag command.
+ */
+ strstart(sb);
+ if (!getconfs(dbname(db), sb))
+ die1("cannot get tag command. (%s)", dbname(db));
+ gtop = gtagsopen(dbpath, root, db, GTAGS_MODIFY, 0);
+ /*
+ * GTAGS needed to make GRTAGS.
+ */
+ if (db == GRTAGS && !test("f", makepath(dbpath, "GTAGS")))
+ die("GTAGS needed to create GRTAGS.");
+ if (type != 1)
+ gtagsdelete(gtop, path);
+ if (vflag)
+ fprintf(stderr, "..");
+ if (type != 2) {
+ if (db == GSYMS)
+ flags |= GTAGS_UNIQUE;
+ if (extractmethod)
+ flags |= GTAGS_EXTRACTMETHOD;
+ gtagsadd(gtop, strvalue(sb), path, flags);
+ }
+ gtagsclose(gtop);
}
- pclose(ip);
+ if (vflag)
+ fprintf(stderr, " Done.\n");
+ strclose(sb);
}
/*
* createtags: create tags file
*
* i) dbpath dbpath directory
+ * i) root root directory of source tree
* i) db GTAGS, GRTAGS, GSYMS
*/
void
-createtags(dbpath, db)
+createtags(dbpath, root, db)
char *dbpath;
+char *root;
int db;
{
char *path;
+ GTOP *gtop;
+ int flags;
+ char *comline;
+ STRBUF *sb = stropen();
/*
+ * get tag command.
+ */
+ if (!getconfs(dbname(db), sb))
+ die1("cannot get tag command. (%s)", dbname(db));
+ comline = strdup(strvalue(sb));
+ if (!comline)
+ die("short of memory.");
+ /*
* GTAGS needed to make GRTAGS.
*/
- if (db == GRTAGS)
- lookupopen(dbpath);
- tagopen(dbpath, db, 1);
+ if (db == GRTAGS && !test("f", makepath(dbpath, "GTAGS")))
+ die("GTAGS needed to create GRTAGS.");
+ flags = 0;
+ strstart(sb);
+ if (cflag) {
+ flags |= GTAGS_COMPACT;
+ flags |= GTAGS_PATHINDEX;
+ }
+ strstart(sb);
+ if (vflag > 1 && getconfs(dbname(db), sb))
+ fprintf(stderr, " using tag command '%s <path>'.\n", strvalue(sb));
+ gtop = gtagsopen(dbpath, root, db, GTAGS_CREATE, flags);
for (findopen(); (path = findread(NULL)) != NULL; ) {
+ int gflags = 0;
/*
* GSYMS doesn't treat asembler.
*/
- if (db == GSYMS) {
- char *p = path + strlen(path) - 1;
- if ((*p == 's' || *p == 'S') && *(p - 1) == '.')
+ if (db == GSYMS)
+ if (locatestring(path, ".s", MATCH_AT_LAST) != NULL ||
+ locatestring(path, ".S", MATCH_AT_LAST) != NULL)
continue;
- }
if (vflag)
fprintf(stderr, " extracting tags of %s.\n", path);
- tagadd(db, path);
+ if (db == GSYMS)
+ gflags |= GTAGS_UNIQUE;
+ if (extractmethod)
+ gflags |= GTAGS_EXTRACTMETHOD;
+ gtagsadd(gtop, comline, path, gflags);
}
findclose();
- tagclose();
- if (db == GRTAGS)
- lookupclose();
+ gtagsclose(gtop);
+ free(comline);
+ strclose(sb);
}
/*
- * current: current date and time
+ * now: current date and time
*
* r) date and time
*/
-char *
-current(void)
+char *
+now(void)
{
static char buf[80];
time_t tval;
if (time(&tval) == -1)
die("cannot get current time.");
- (void)strftime(buf, sizeof(buf), "%+", localtime(&tval));
-
+ (void)strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %Z %Y", localtime(&tval));
return buf;
}
+/*
+ * printconf: print configuration data.
+ *
+ * i) name label of config data
+ * r) exit code
+ */
+int
+printconf(name)
+char *name;
+{
+ STRBUF *sb;
+ int num;
+ int exist = 1;
+
+ if (getconfn(name, &num))
+ fprintf(stdout, "%d\n", num);
+ else if (getconfb(name))
+ fprintf(stdout, "1\n");
+ else {
+ sb = stropen();
+ if (getconfs(name, sb))
+ fprintf(stdout, "%s\n", strvalue(sb));
+ else
+ exist = 0;
+ strclose(sb);
+ }
+ return exist;
+}
diff --git a/contrib/global/htags/htags.1 b/contrib/global/htags/htags.1
index 2a9dea12265f..4c22448e6f02 100644
--- a/contrib/global/htags/htags.1
+++ b/contrib/global/htags/htags.1
@@ -1,5 +1,5 @@
.\"
-.\" Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+.\" Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -28,16 +28,18 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 28, 1997
+.Dd Oct 11, 1998
.Dt HTAGS 1
.Os BSD 4
.Sh NAME
.Nm htags
-.Nd generate hypertext from C and Yacc source code
+.Nd generate hypertext from C, Yacc and Java source code
.Sh SYNOPSIS
.Nm htags
.Op Fl a
+.Op Fl c
.Op Fl f
+.Op Fl h
.Op Fl l
.Op Fl n
.Op Fl v
@@ -47,47 +49,59 @@
.Op Ar dir
.Sh DESCRIPTION
.Nm Htags
-makes hypertext from C and Yacc source code using GLOBAL database (GTAGS, GRTAGS).
+makes hypertext from C, Yacc and Java source code using GLOBAL database (GTAGS, GRTAGS).
.Pp
In advance of using this command, you must execute
.Xr gtags 1
-at the root directory of the source tree.
+from the root directory of the source tree.
Then you can execute
.Nm htags
-at the same place.
+from the same place.
.Nm Htags
-makes HTML directory and generate hypertext in it.
+makes an HTML directory and generates hypertext in it.
.Pp
You can start browsing from 'HTML/index.html'.
-Once hypertext generated, you can move it anywhere and browse it
-by any browsers.
+Once the hypertext is generated, you can move it anywhere and browse it
+in any browsers.
.Pp
.br
.Bl -tag -width Ds
.It Fl a
-make an alphabetical function index. It's suitable for large project.
+Make an alphabetical function index, suitable for a large project.
+.It Fl c
+Compress html files by
+.Xr gzip 1 .
+You need to set up an HTTP server so that
+.Xr gzip 1
+is invoked for each compressed
+files. See skelton file 'HTML/.htaccess.skel' that is generated by htags.
.It Fl f
-support input form and dynamic index by CGI program.
-You need to setup HTTP server for it.
+Support an input form and a dynamic index with a CGI program.
+You need to set up an HTTP server for this.
+.It Fl h
+Add title header frame. By default, doesn't add this.
.It Fl l
-make name tag(<A NAME=line number>) for each line so that outer hypertext
-can point any line of this hypertext.
-By default, make it only for lines which have referred object.
+Make a name tag(<A NAME=line number>) for each line, so that other hypertext
+can link to any line of this hypertext.
+By default, htags makes it only for lines that are referred to by an object.
.It Fl n
-print line number. By default, doesn't print it.
+Print the line numbers (they are not printed by default).
.It Fl v
-verbose mode.
+Verbose mode.
.It Fl w
-print warning message.
+Print a warning message.
.It Fl d Ar tagdir
-the directory in which GTAGS and GRTAGS exist. Default is current directory.
+Specifies the directory in which GTAGS and GRTAGS exist. The default is the
+current directory.
.It Fl t Ar title
-Title of this hypertext. Default is the last component of current path.
+The title of this hypertext. Defaults to the last component of the current
+path.
.It Ar dir
-the directory in which hypertext generated. Default is current directory.
+The directory in which hypertext is generated. The default is the current
+directory.
.Sh EXAMPLES
% cd /usr/src/sys
- # gtags -se
+ # gtags -o
# htags -fnvat 'Welcom to FreeBSD kernel source tour!'
% lynx HTML/index.html
.Sh FILES
@@ -95,17 +109,17 @@ the directory in which hypertext generated. Default is current directory.
.It Pa HTML/index.html
Index file.
.It Pa GTAGS
-tags file for function definitions.
+Tags file for function definitions.
.It Pa GRTAGS
-tags file for function references.
+Tags file for function references.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of htags.
.Pp
.Bl -tag -width indent
.It Ev TMPDIR
-If this variable is set, its value is used as the directory to make temporary file.
-Default is /tmp.
+If this variable is set, its value is used as the directory to make temporary files.
+The default is /tmp.
.Sh DIAGNOSTICS
.Nm Htags
exits with a non 0 value if an error occurred, 0 otherwise.
diff --git a/contrib/global/lib/dbio.c b/contrib/global/lib/dbio.c
deleted file mode 100644
index c29a91477bdb..000000000000
--- a/contrib/global/lib/dbio.c
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redilogibution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redilogibutions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redilogibutions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the dilogibution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * dbio.c 14-Dec-97
- *
- */
-#include <sys/stat.h>
-
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "dbio.h"
-#include "die.h"
-#include "test.h"
-
-DBT key; /* key of record */
-DBT dat; /* data of record */
-/*
- * db_open: open db database.
- *
- * i) dbname database name
- * i) mode 0: read only, 1: write only, 2: read & write
- * i) perm file permission
- * i) flags
- * DBIO_DUP: allow duplicate records.
- * DBIO_REMOVE: remove on closed.
- * r) descripter for db_xxx()
- *
- * db_open leaves database permission 0600. please chmod(2) to make public.
- */
-DBIO *
-db_open(dbname, mode, perm, flags)
-char *dbname;
-int mode;
-int perm;
-int flags;
-{
- DB *db;
- int rw;
- BTREEINFO info;
- DBIO *dbio;
-
- /*
- * setup argments.
- */
- if (mode == 0)
- rw = O_RDONLY;
- else if (mode == 1)
- rw = O_RDWR|O_CREAT|O_TRUNC;
- else if (mode == 2)
- rw = O_RDWR;
- else
- die("db_open illegal mode.");
- info.flags = (flags & DBIO_DUP) ? R_DUP : 0;
- info.cachesize = 500000;
- info.maxkeypage = 0;
- info.minkeypage = 0;
- info.psize = 0;
- info.compare = NULL;
- info.prefix = NULL;
- info.lorder = LITTLE_ENDIAN;
-
- /*
- * if unlink do job normally, those who already open tag file can use
- * it until closing.
- */
- if (mode == 1 && test("f", dbname))
- (void)unlink(dbname);
- db = dbopen(dbname, rw, 0600, DB_BTREE, &info);
- if (!db)
- die1("db_open failed (dbname = %s).", dbname);
- if (!(dbio = (DBIO *)malloc(sizeof(DBIO))))
- die("short of memory.");
- strcpy(dbio->dbname, dbname);
- dbio->db = db;
- dbio->openflags = flags;
- dbio->perm = (mode == 1) ? perm : 0;
- dbio->lastkey = (char *)0;
- dbio->lastdat = (char *)0;
-
- return dbio;
-}
-/*
- * db_get: get data by a key.
- *
- * i) dbio descripter
- * i) k key
- * r) pointer to data
- */
-char *
-db_get(dbio, k)
-DBIO *dbio;
-char *k;
-{
- DB *db = dbio->db;
- int status;
-
- key.data = k;
- key.size = strlen(k)+1;
-
- status = (*db->get)(db, &key, &dat, 0);
- dbio->lastkey = (char *)key.data;
- dbio->lastdat = (char *)dat.data;
- switch (status) {
- case RET_SUCCESS:
- break;
- case RET_ERROR:
- die("db_get failed.");
- case RET_SPECIAL:
- return((char *)0);
- }
- return((char *)dat.data);
-}
-/*
- * db_put: put data by a key.
- *
- * i) dbio descripter
- * i) k key
- * i) d data
- */
-void
-db_put(dbio, k, d)
-DBIO *dbio;
-char *k;
-char *d;
-{
- DB *db = dbio->db;
- int status;
-
- if (strlen(k) > MAXKEYLEN)
- die("primary key too long.");
- key.data = k;
- key.size = strlen(k)+1;
- dat.data = d;
- dat.size = strlen(d)+1;
-
- status = (*db->put)(db, &key, &dat, 0);
- switch (status) {
- case RET_SUCCESS:
- break;
- case RET_ERROR:
- case RET_SPECIAL:
- die("db_put failed.");
- }
-}
-/*
- * db_del: delete record by a key.
- *
- * i) dbio descripter
- * i) k key
- */
-void
-db_del(dbio, k)
-DBIO *dbio;
-char *k;
-{
- DB *db = dbio->db;
- int status;
-
- if (k) {
- key.data = k;
- key.size = strlen(k)+1;
- status = (*db->del)(db, &key, 0);
- } else
- status = (*db->del)(db, &key, R_CURSOR);
- if (status == RET_ERROR)
- die("db_del failed.");
-}
-/*
- * db_first: get first record.
- *
- * i) dbio dbio descripter
- * i) k key
- * !=NULL: indexed read by key
- * ==NULL: sequential read
- * i) flags following db_next call take over this.
- * DBIO_KEY read key part
- * DBIO_PREFIX prefix read
- * DBIO_SKIPMETA skip META record
- * only valied when sequential read
- * r) data
- */
-char *
-db_first(dbio, k, flags)
-DBIO *dbio;
-char *k;
-int flags;
-{
- DB *db = dbio->db;
- int status;
-
- if (flags & DBIO_PREFIX && !k)
- flags &= ~DBIO_PREFIX;
- if (flags & DBIO_SKIPMETA && k)
- flags &= ~DBIO_SKIPMETA;
- if (k) {
- if (strlen(k) > MAXKEYLEN)
- die("primary key too long.");
- strcpy(dbio->key, k);
- key.data = k;
- key.size = strlen(k);
- /*
- * includes NULL character unless prefix read.
- */
- if (!(flags & DBIO_PREFIX))
- key.size++;
- dbio->keylen = key.size;
- status = (*db->seq)(db, &key, &dat, R_CURSOR);
- } else {
- dbio->keylen = dbio->key[0] = 0;
- for (status = (*db->seq)(db, &key, &dat, R_FIRST);
- status == RET_SUCCESS &&
- flags & DBIO_SKIPMETA &&
- *((char *)dat.data) == ' ';
- status = (*db->seq)(db, &key, &dat, R_NEXT))
- ;
- }
- dbio->lastkey = (char *)key.data;
- dbio->lastdat = (char *)dat.data;
- switch (status) {
- case RET_SUCCESS:
- break;
- case RET_ERROR:
- die("db_first failed.");
- case RET_SPECIAL:
- return ((char *)0);
- }
- dbio->ioflags = flags;
- if (flags & DBIO_PREFIX) {
- if (strncmp((char *)key.data, dbio->key, dbio->keylen))
- return (char *)0;
- } else if (dbio->keylen) {
- if (strcmp((char *)key.data, dbio->key))
- return (char *)0;
- }
- if (flags & DBIO_KEY) {
- strcpy(dbio->prev, (char *)key.data);
- return (char *)key.data;
- }
- return ((char *)dat.data);
-}
-/*
- * db_next: get next record.
- *
- * i) dbio dbio descripter
- * r) data
- */
-char *
-db_next(dbio)
-DBIO *dbio;
-{
- DB *db = dbio->db;
- int flags = dbio->ioflags;
- int status;
-
- while ((status = (*db->seq)(db, &key, &dat, R_NEXT)) == RET_SUCCESS) {
- if (flags & DBIO_SKIPMETA) {
- if (*((char *)dat.data) == ' ')
- continue;
- }
- if (flags & DBIO_KEY) {
- if (!strcmp(dbio->prev, (char *)key.data))
- continue;
- if (strlen((char *)key.data) > MAXKEYLEN)
- die("primary key too long.");
- strcpy(dbio->prev, (char *)key.data);
- }
- dbio->lastkey = (char *)key.data;
- dbio->lastdat = (char *)dat.data;
- if (flags & DBIO_PREFIX) {
- if (strncmp((char *)key.data, dbio->key, dbio->keylen))
- return (char *)0;
- } else if (dbio->keylen) {
- if (strcmp((char *)key.data, dbio->key))
- return (char *)0;
- }
- return (flags & DBIO_KEY) ? (char *)key.data : (char *)dat.data;
- }
- if (status == RET_ERROR)
- die("db_next failed.");
- return (char *)0;
-}
-/*
- * db_close: close db
- *
- * i) dbio dbio descripter
- */
-void
-db_close(dbio)
-DBIO *dbio;
-{
- DB *db = dbio->db;
- (void)db->close(db);
- if (dbio->openflags & DBIO_REMOVE)
- (void)unlink(dbio->dbname);
- else if (dbio->perm && chmod(dbio->dbname, dbio->perm) < 0)
- die("cannot change file mode.");
- (void)free(dbio);
-}
diff --git a/contrib/global/lib/dbio.h b/contrib/global/lib/dbio.h
deleted file mode 100644
index 7c1994e86d69..000000000000
--- a/contrib/global/lib/dbio.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redilogibution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redilogibutions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redilogibutions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the dilogibution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * dbio.h 14-Dec-97
- *
- */
-#ifndef _DBIO_H_
-#define _DBIO_H_
-
-#include <db.h>
-#include <sys/param.h>
-
-#ifndef LITTLE_ENDIAN
-#define LITTLE_ENDIAN 1234
-#endif
-#ifndef BIG_ENDIAN
-#define BIG_ENDIAN 4321
-#endif
-
-#define MAXKEYLEN 300
-
-typedef struct {
- DB *db; /* descripter of DB */
- char dbname[MAXPATHLEN+1]; /* dbname */
- char key[MAXKEYLEN+1]; /* key */
- int keylen; /* key length */
- char prev[MAXKEYLEN+1]; /* previous key value */
- char *lastkey; /* the key of last located record */
- char *lastdat; /* the data of last located record */
- int openflags; /* flags of db_open() */
- int ioflags; /* flags of db_first() */
- int perm; /* file permission */
-} DBIO;
-
-/*
- * openflags
- */
-#define DBIO_DUP 1 /* allow duplicate records */
-#define DBIO_REMOVE 2 /* remove file when closed */
-/*
- * ioflags
- */
-#define DBIO_KEY 1 /* read key part */
-#define DBIO_PREFIX 2 /* prefixed read */
-#define DBIO_SKIPMETA 4 /* skip META record */
-
-#ifndef __P
-#if defined(__STDC__)
-#define __P(protos) protos
-#else
-#define __P(protos) ()
-#endif
-#endif
-
-DBIO *db_open __P((char *, int, int, int));
-char *db_get __P((DBIO *, char *));
-void db_put __P((DBIO *, char *, char *));
-void db_del __P((DBIO *, char *));
-char *db_first __P((DBIO *, char *, int));
-char *db_next __P((DBIO *));
-void db_close __P((DBIO *));
-#endif /* _DBIO_H_ */
diff --git a/contrib/global/lib/dbname.c b/contrib/global/lib/dbname.c
deleted file mode 100644
index 1e68b3a2bf4a..000000000000
--- a/contrib/global/lib/dbname.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * dbname.c 20-Oct-97
- *
- */
-#include "dbname.h"
-
-static char *tagslist[] = {"GTAGS", "GRTAGS", "GSYMS"};
-/*
- * dbname: return db name
- *
- * i) db 0: GTAGS, 1: GRTAGS, 2: GSYMS
- * r) dbname
- */
-char *
-dbname(db)
-int db;
-{
- return tagslist[db];
-}
diff --git a/contrib/global/lib/dbname.h b/contrib/global/lib/dbname.h
deleted file mode 100644
index 17eba363eda4..000000000000
--- a/contrib/global/lib/dbname.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * dbname.h 16-Oct-97
- *
- */
-
-#ifndef _DBNAME_H_
-#define _DBNAME_H_
-
-#ifndef __P
-#if defined(__STDC__)
-#define __P(protos) protos
-#else
-#define __P(protos) ()
-#endif
-#endif
-
-#define GTAGS 0
-#define GRTAGS 1
-#define GSYMS 2
-#define GTAGLIM 3
-
-char *dbname __P((int));
-
-#endif /* ! _DBNAME_H_ */
diff --git a/contrib/global/lib/find.c b/contrib/global/lib/find.c
index 10a9bf1cde78..4682beec1d6d 100644
--- a/contrib/global/lib/find.c
+++ b/contrib/global/lib/find.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,115 +28,159 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * find.c 20-Oct-97
+ * find.c 1-May-98
*
*/
+/*
+ * USEFIND use find(1) to traverse directory tree.
+ * Otherwise, use dirent(3) library.
+ */
+#define USEFIND
+
+#include <sys/param.h>
+
+#include <assert.h>
+#include <ctype.h>
+#ifndef USEFIND
+#include <dirent.h>
+#ifndef BSD4_4
+#include <sys/stat.h>
+#endif
+#endif
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
+#include <stdlib.h>
+#include <strings.h>
#include <regex.h>
-#include <sys/param.h>
-#include "gparam.h"
-#include "find.h"
+
+#include "conf.h"
#include "die.h"
+#include "find.h"
+#include "gparam.h"
#include "locatestring.h"
+#include "makepath.h"
+#include "strbuf.h"
/*
* usage of findxxx()
*
- * findopen();
+ * findopen(db);
* while (path = findread(&length)) {
* ...
* }
* findclose();
*
*/
-static char *skippath[] = {
- "y.tab.c",
- "y.tab.h",
- "SCCS/",
- "RCS/",
-};
-static char *ext[] = {
- "c",
- "h",
- "y",
- "s",
- "S",
-};
-static char findcom[MAXCOMLINE+1];
static regex_t skip_area;
-static regex_t *skip;
-static FILE *ip;
+static regex_t *skip = &skip_area;
static int opened;
-int
-issource(path)
-char *path;
+static void trim __P((char *));
+
+/*
+ * trim: remove blanks and '\'.
+ */
+static void
+trim(s)
+char *s;
{
char *p;
- if (!(p = locatestring(path, ".", 2)))
- return 0;
- ++p;
- if (sizeof(ext) != 0) {
- int i, lim = sizeof(ext)/sizeof(char *);
- for (i = 0; i < lim; i++)
- if (*ext[i] == *p && !strcmp(ext[i], p))
- return 1;
+ for (p = s; *s; s++) {
+ if (isspace(*s))
+ continue;
+ if (*s == '\\' && *(s + 1))
+ s++;
+ *p++ = *s;
}
- return 0;
+ *p = 0;
}
+#ifdef USEFIND
+/*----------------------------------------------------------------------*/
+/* find command version */
+/*----------------------------------------------------------------------*/
+static FILE *ip;
void
-findopen(void)
+findopen()
{
- char edit[512], *p, *q;
- int i, lim;
+ char *findcom, *p, *q;
+ STRBUF *sb;
+ char *sufflist = NULL;
+ char *skiplist = NULL;
- if (opened)
- die("nested call to findopen.");
+ assert(opened == 0);
opened = 1;
- p = findcom;
- strcpy(p, "find . \\( -type f -o -type l \\) \\(");
- p += strlen(p);
- lim = sizeof(ext)/sizeof(char *);
- for (i = 0; i < lim; i++) {
- sprintf(p, " -name '*.%s'%s", ext[i], (i + 1 < lim) ? " -o" : "");
- p += strlen(p);
+
+ sb = stropen();
+ if (!getconfs("suffixes", sb))
+ die("cannot get suffixes data.");
+ sufflist = strdup(strvalue(sb));
+ if (!sufflist)
+ die("short of memory.");
+ trim(sufflist);
+ strstart(sb);
+ if (getconfs("skip", sb)) {
+ skiplist = strdup(strvalue(sb));
+ if (!skiplist)
+ die("short of memory.");
+ trim(skiplist);
+ }
+
+ strstart(sb);
+ strputs(sb, "find . \\( -type f -o -type l \\) \\(");
+ for (p = sufflist; p; ) {
+ char *suff = p;
+ if ((p = locatestring(p, ",", MATCH_FIRST)) != NULL)
+ *p++ = 0;
+ strputs(sb, " -name '*.");
+ strputs(sb, suff);
+ strputs(sb, "'");
+ if (p)
+ strputs(sb, " -o");
}
- sprintf(p, " \\) -print");
- if (sizeof(skippath) != 0) {
- int i, lim = sizeof(skippath)/sizeof(char *);
+ strputs(sb, " \\) -print");
+ findcom = strvalue(sb);
+
+ if (skiplist) {
+ char *reg;
+ STRBUF *sbb = stropen();
/*
* construct regular expression.
*/
- p = edit;
- *p++ = '(';
- for (i = 0; i < lim; i++) {
- *p++ = '/';
- for (q = skippath[i]; *q; q++) {
+ strputc(sbb, '('); /* ) */
+ for (p = skiplist; p; ) {
+ char *skipf = p;
+ if ((p = locatestring(p, ",", MATCH_FIRST)) != NULL)
+ *p++ = 0;
+ strputc(sbb, '/');
+ for (q = skipf; *q; q++) {
if (*q == '.')
- *p++ = '\\';
- *p++ = *q;
+ strputc(sbb, '\\');
+ strputc(sbb, *q);
}
if (*(q - 1) != '/')
- *p++ = '$';
- *p++ = '|';
+ strputc(sbb, '$');
+ if (p)
+ strputc(sbb, '|');
}
- *(p - 1) = ')';
- *p = 0;
+ strputc(sbb, ')');
+ reg = strvalue(sbb);
/*
* compile regular expression.
*/
- skip = &skip_area;
- if (regcomp(skip, edit, REG_EXTENDED|REG_NEWLINE) != 0)
+ if (regcomp(skip, reg, REG_EXTENDED|REG_NEWLINE) != 0)
die("cannot compile regular expression.");
+ strclose(sbb);
} else {
skip = (regex_t *)0;
}
if (!(ip = popen(findcom, "r")))
die("cannot execute find.");
+ strclose(sb);
+ if (sufflist)
+ free(sufflist);
+ if (skiplist)
+ free(skiplist);
}
char *
findread(length)
@@ -145,8 +189,12 @@ int *length;
static char path[MAXPATHLEN+1];
char *p;
+ assert(opened == 1);
while (fgets(path, MAXPATHLEN, ip)) {
if (!skip || regexec(skip, path, 0, 0, 0) != 0) {
+ /*
+ * chop(path)
+ */
p = path + strlen(path) - 1;
if (*p != '\n')
die("output of find(1) is wrong (findread).");
@@ -156,11 +204,242 @@ int *length;
return path;
}
}
- return (char *)0;
+ return NULL;
}
void
findclose(void)
{
+ assert(opened == 1);
pclose(ip);
opened = 0;
}
+#else /* USEFIND */
+/*----------------------------------------------------------------------*/
+/* dirent version findxxx() */
+/*----------------------------------------------------------------------*/
+#define STACKSIZE 50
+static char dir[MAXPATHLEN+1]; /* directory path */
+static struct {
+ STRBUF *sb;
+ char *dirp, *start, *end, *p;
+} stack[STACKSIZE], *topp, *curp; /* stack */
+
+static regex_t suff_area;
+static regex_t *suff = &suff_area;
+
+static int
+getdirs(dir, sb)
+char *dir;
+STRBUF *sb;
+{
+ DIR *dirp;
+ struct dirent *dp;
+#ifndef BSD4_4
+ struct stat st;
+#endif
+
+ if ((dirp = opendir(dir)) == NULL)
+ return -1;
+ while ((dp = readdir(dirp)) != NULL) {
+#ifdef BSD4_4
+ if (dp->d_namlen == 1 && dp->d_name[0] == '.')
+ continue;
+ if (dp->d_namlen == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')
+ continue;
+ if (dp->d_type == DT_DIR)
+ strputc(sb, 'd');
+ else if (dp->d_type == DT_REG)
+ strputc(sb, 'f');
+ else if (dp->d_type == DT_LNK)
+ strputc(sb, 'l');
+ else
+ strputc(sb, ' ');
+ strnputs(sb, dp->d_name, (int)dp->d_namlen);
+#else
+ if (stat(path, &st) < 0) {
+ fprintf(stderr, "cannot stat '%s'. (Ignored)\n", path);
+ continue;
+ }
+ if (S_ISDIR(st.st_mode))
+ strputc(sb, 'd');
+ else if (S_ISREG(st.st_mode))
+ strputc(sb, 'f');
+ else if (S_ISLNK(st.st_mode))
+ strputc(sb, 'l');
+ else
+ strputc(sb, ' ');
+ strputs(sb, dp->d_name);
+#endif /* BSD4_4 */
+ strputc(sb, '\0');
+ }
+ (void)closedir(dirp);
+ return 0;
+}
+void
+findopen()
+{
+ STRBUF *sb = stropen();
+ char *sufflist = NULL;
+ char *skiplist = NULL;
+
+ assert(opened == 0);
+ opened = 1;
+
+ /*
+ * setup stack.
+ */
+ curp = &stack[0];
+ topp = curp + STACKSIZE;
+ strcpy(dir, ".");
+
+ curp->dirp = dir + strlen(dir);
+ curp->sb = stropen();
+ if (getdirs(dir, curp->sb) < 0)
+ die("cannot open '.' directory.");
+ curp->start = curp->p = strvalue(curp->sb);
+ curp->end = curp->start + strbuflen(curp->sb);
+
+ /*
+ * preparing regular expression.
+ */
+ strstart(sb);
+ if (!getconfs("suffixes", sb))
+ die("cannot get suffixes data.");
+ sufflist = strdup(strvalue(sb));
+ if (!sufflist)
+ die("short of memory.");
+ trim(sufflist);
+ strstart(sb);
+ if (getconfs("skip", sb)) {
+ skiplist = strdup(strvalue(sb));
+ if (!skiplist)
+ die("short of memory.");
+ trim(skiplist);
+ }
+ {
+ char *p;
+
+ strstart(sb);
+ strputc(sb, '('); /* ) */
+ for (p = sufflist; p; ) {
+ char *suffp = p;
+ if ((p = locatestring(p, ",", MATCH_FIRST)) != NULL)
+ *p++ = 0;
+ strputs(sb, "\\.");
+ strputs(sb, suffp);
+ strputc(sb, '$');
+ if (p)
+ strputc(sb, '|');
+ }
+ strputc(sb, ')');
+ /*
+ * compile regular expression.
+ */
+ if (regcomp(suff, strvalue(sb), REG_EXTENDED) != 0)
+ die("cannot compile regular expression.");
+ }
+ if (skiplist) {
+ char *p, *q;
+ /*
+ * construct regular expression.
+ */
+ strstart(sb);
+ strputc(sb, '('); /* ) */
+ for (p = skiplist; p; ) {
+ char *skipf = p;
+ if ((p = locatestring(p, ",", MATCH_FIRST)) != NULL)
+ *p++ = 0;
+ strputc(sb, '/');
+ for (q = skipf; *q; q++) {
+ if (*q == '.')
+ strputc(sb, '\\');
+ strputc(sb, *q);
+ }
+ if (*(q - 1) != '/')
+ strputc(sb, '$');
+ if (p)
+ strputc(sb, '|');
+ }
+ strputc(sb, ')');
+ /*
+ * compile regular expression.
+ */
+ if (regcomp(skip, strvalue(sb), REG_EXTENDED) != 0)
+ die("cannot compile regular expression.");
+ } else {
+ skip = (regex_t *)0;
+ }
+ strclose(sb);
+ if (sufflist)
+ free(sufflist);
+ if (skiplist)
+ free(skiplist);
+}
+char *
+findread(length)
+int *length;
+{
+ static char val[MAXPATHLEN+1];
+
+ for (;;) {
+ while (curp->p < curp->end) {
+ char type = *(curp->p);
+ char *unit = curp->p + 1;
+
+ curp->p += strlen(curp->p) + 1;
+ if (type == 'f' || type == 'l') {
+ char *path = makepath(dir, unit);
+ if (regexec(suff, path, 0, 0, 0) != 0)
+ continue;
+ if (skip && regexec(skip, path, 0, 0, 0) == 0)
+ continue;
+ strcpy(val, path);
+ return val;
+ }
+ if (type == 'd') {
+ STRBUF *sb = stropen();
+ char *dirp = curp->dirp;
+
+ strcat(dirp, "/");
+ strcat(dirp, unit);
+ if (getdirs(dir, sb) < 0) {
+ fprintf(stderr, "cannot open directory '%s'. (Ignored)\n", dir);
+ strclose(sb);
+ *(curp->dirp) = 0;
+ continue;
+ }
+ /*
+ * Push stack.
+ */
+ if (++curp >= topp)
+ die("directory stack over flow.");
+ curp->dirp = dirp + strlen(dirp);
+ curp->sb = sb;
+ curp->start = curp->p = strvalue(sb);
+ curp->end = curp->start + strbuflen(sb);
+ }
+ }
+ strclose(curp->sb);
+ curp->sb = NULL;
+ if (curp == &stack[0])
+ break;
+ /*
+ * Pop stack.
+ */
+ curp--;
+ *(curp->dirp) = 0;
+ }
+ return NULL;
+}
+void
+findclose(void)
+{
+ assert(opened == 1);
+ for (curp = &stack[0]; curp < topp; curp++)
+ if (curp->sb != NULL)
+ strclose(curp->sb);
+ else
+ break;
+ opened = 0;
+}
+#endif /* !USEFIND */
diff --git a/contrib/global/lib/find.h b/contrib/global/lib/find.h
index bb140e05ddcb..ae16f7230872 100644
--- a/contrib/global/lib/find.h
+++ b/contrib/global/lib/find.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/contrib/global/lib/getdbpath.c b/contrib/global/lib/getdbpath.c
index 73f1a4f48055..4529988ed6c8 100644
--- a/contrib/global/lib/getdbpath.c
+++ b/contrib/global/lib/getdbpath.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,12 +41,10 @@
#include "die.h"
#include "getdbpath.h"
-#include "locatestring.h"
#include "test.h"
-static char *makeobjdirprefix; /* obj partition */
-static char *makeobjdir; /* obj directory */
-static int bsd; /* if BSD */
+static const char *makeobjdirprefix; /* obj partition */
+static const char *makeobjdir; /* obj directory */
/*
* gtagsexist: test whether GTAGS's existence.
@@ -67,17 +65,15 @@ char *dbpath;
strcpy(dbpath, candidate);
return 1;
}
- if (bsd) {
- sprintf(path, "%s/%s/GTAGS", candidate, makeobjdir);
- if (test("fr", path)) {
- sprintf(dbpath, "%s/%s", candidate, makeobjdir);
- return 1;
- }
- sprintf(path, "%s%s/GTAGS", makeobjdirprefix, candidate);
- if (test("fr", path)) {
- sprintf(dbpath, "%s%s", makeobjdirprefix, candidate);
- return 1;
- }
+ sprintf(path, "%s/%s/GTAGS", candidate, makeobjdir);
+ if (test("fr", path)) {
+ sprintf(dbpath, "%s/%s", candidate, makeobjdir);
+ return 1;
+ }
+ sprintf(path, "%s%s/GTAGS", makeobjdirprefix, candidate);
+ if (test("fr", path)) {
+ sprintf(dbpath, "%s%s", makeobjdirprefix, candidate);
+ return 1;
}
return 0;
}
@@ -110,17 +106,14 @@ char *dbpath;
if (!strcmp(cwd, "/"))
die("It's root directory! What are you doing?");
- if (getenv("OSTYPE") && locatestring(getenv("OSTYPE"), "BSD", 0)) {
- if ((p = getenv("MAKEOBJDIRPREFIX")) != NULL)
- makeobjdirprefix = p;
- else
- makeobjdirprefix = "/usr/obj";
- if ((p = getenv("MAKEOBJDIR")) != NULL)
- makeobjdir = p;
- else
- makeobjdir = "obj";
- bsd = 1;
- }
+ if ((p = getenv("MAKEOBJDIRPREFIX")) != NULL)
+ makeobjdirprefix = p;
+ else
+ makeobjdirprefix = "/usr/obj";
+ if ((p = getenv("MAKEOBJDIR")) != NULL)
+ makeobjdir = p;
+ else
+ makeobjdir = "obj";
if ((p = getenv("GTAGSROOT")) != NULL) {
if (*p != '/')
diff --git a/contrib/global/lib/gtagsopen.c b/contrib/global/lib/gtagsopen.c
deleted file mode 100644
index 90f0481603f5..000000000000
--- a/contrib/global/lib/gtagsopen.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * gtagsopen.c 20-Oct-97
- *
- */
-#include <sys/param.h>
-
-#include <ctype.h>
-#include <db.h>
-#include <fcntl.h>
-#include <stdlib.h>
-
-#include "dbio.h"
-#include "dbname.h"
-#include "die.h"
-#include "gtagsopen.h"
-#include "makepath.h"
-
-#define VERSIONKEY " __.VERSION"
-static int support_version = 1; /* accept this format version */
-
-/*
- * gtagsopen: open global database.
- *
- * i) dbpath dbpath directory
- * i) db GTAGS, GRTAGS, GSYMS
- * i) mode 0: read only
- * 1: write only
- * 2: read and write
- * r) DB structure
- *
- * when error occurred, gtagopen doesn't return.
- */
-DBIO *
-gtagsopen(dbpath, db, mode)
-char *dbpath;
-int db;
-int mode;
-{
- DBIO *dbio;
- int version_number;
- char *p;
-
- /*
- * allow duplicate records.
- */
- dbio = db_open(makepath(dbpath, dbname(db)), mode, 0644, DBIO_DUP);
- if (dbio == NULL) {
- if (mode == 1)
- die1("cannot make database (%s).", makepath(dbpath, dbname(db)));
- die1("database not found (%s).", makepath(dbpath, dbname(db)));
- }
- if (mode == 1) {
- /* nothing to do now */
- } else {
- /*
- * recognize format version of GTAGS. 'format version record'
- * is saved as a META record in GTAGS and GRTAGS.
- * if 'format version record' is not found, it's assumed
- * version 1.
- */
- if ((p = db_get(dbio, VERSIONKEY)) != NULL) {
- for (p += strlen(VERSIONKEY); *p && isspace(*p); p++)
- ;
- version_number = atoi(p);
- } else
- version_number = 1;
- if (version_number > support_version)
- die("GTAGS seems new format. Please install the latest GLOBAL.");
- }
- return dbio;
-}
diff --git a/contrib/global/lib/gtagsopen.h b/contrib/global/lib/gtagsopen.h
deleted file mode 100644
index 2afb2ab56892..000000000000
--- a/contrib/global/lib/gtagsopen.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * gtagsopen.h 16-Oct-97
- *
- */
-
-#ifndef _GTAGSOPEN_H_
-#define _GTAGSOPEN_H_
-#include "dbio.h"
-
-DBIO *gtagsopen __P((char *, int, int));
-
-#endif /* ! _GTAGSOPEN_H_ */
diff --git a/contrib/global/lib/locatestring.c b/contrib/global/lib/locatestring.c
index 230ccce5149a..76285994befb 100644
--- a/contrib/global/lib/locatestring.c
+++ b/contrib/global/lib/locatestring.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,7 +28,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * locatestring.c 20-Oct-97
+ * locatestring.c 25-Jul-98
*
*/
#include <string.h>
@@ -40,35 +40,36 @@
*
* i) string string
* i) pattern pattern
- * i) flag 0: match first
- * 1: match only at first column
- * 2: match last
- * 3: match only at last column
+ * i) flag MATCH_FIRST: match first
+ * MATCH_AT_FIRST: match only at first column
+ * MATCH_LAST: match last
+ * MATCH_AT_LAST: match only at last column
* r) pointer or NULL
*
* This function is made to avoid compatibility problems.
*/
char *
locatestring(string, pattern, flag)
-char *string;
-char *pattern;
+const char *string;
+const char *pattern;
int flag;
{
int c = *pattern;
- char *p = (char *)0;
+ int slen, plen;
+ const char *p = NULL;
- if (flag == 3 && strlen(string) > strlen(pattern)) {
- string += strlen(string) - strlen(pattern);
- }
+ plen = strlen(pattern);
+ if (flag == MATCH_AT_LAST && (slen = strlen(string)) > plen)
+ string += (slen - plen);
for (; *string; string++) {
if (*string == c)
- if (!strncmp(string, pattern, strlen(pattern))) {
+ if (!strncmp(string, pattern, plen)) {
p = string;
- if (flag == 0)
+ if (flag == MATCH_FIRST)
break;
}
- if (flag == 1 || flag == 3)
+ if (flag == MATCH_AT_FIRST || flag == MATCH_AT_LAST)
break;
}
- return p;
+ return (char *)p;
}
diff --git a/contrib/global/lib/lookup.c b/contrib/global/lib/lookup.c
deleted file mode 100644
index d317ba6f3434..000000000000
--- a/contrib/global/lib/lookup.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * lookup.c 20-Oct-97
- *
- */
-#include "gtagsopen.h"
-#include "lookup.h"
-#include "dbio.h"
-#include "die.h"
-#include "dbname.h"
-
-static DBIO *dbio;
-static int opened;
-
-void
-lookupopen(dbpath)
-char *dbpath;
-{
- if (opened)
- die("nested call to lookupopen.");
- opened = 1;
- dbio = gtagsopen(dbpath, GTAGS, 0);
-}
-int
-lookup(name)
-char *name;
-{
- char *p = db_get(dbio, name);
- return (p) ? 1 : 0;
-}
-void
-lookupclose(void)
-{
- db_close(dbio);
- opened = 0;
-}
diff --git a/contrib/global/lib/lookup.h b/contrib/global/lib/lookup.h
deleted file mode 100644
index 037102f53600..000000000000
--- a/contrib/global/lib/lookup.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * lookup.h 16-Oct-97
- *
- */
-
-#ifndef _LOOKUP_H_
-#define _LOOKUP_H_
-
-#ifndef __P
-#if defined(__STDC__)
-#define __P(protos) protos
-#else
-#define __P(protos) ()
-#endif
-#endif
-
-void lookupopen __P((char *));
-int lookup __P((char *));
-void lookupclose __P((void));
-
-#endif /* ! _LOOKUP_H_ */
diff --git a/contrib/global/lib/makepath.c b/contrib/global/lib/makepath.c
index 7efba18dd293..26de06532454 100644
--- a/contrib/global/lib/makepath.c
+++ b/contrib/global/lib/makepath.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,12 +28,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * makepath.c 20-Oct-97
+ * makepath.c 15-May-98
*
*/
#include <string.h>
#include <sys/param.h>
+#include "die.h"
#include "makepath.h"
+#include "strbuf.h"
+
+static STRBUF *sb;
/*
* makepath: make path from directory and file.
*
@@ -43,16 +47,21 @@
*/
char *
makepath(dir, file)
-char *dir;
-char *file;
+const char *dir;
+const char *file;
{
- static char path[MAXPATHLEN+1];
- char *p;
+ int length;
- strcpy(path, dir);
- p = path + strlen(path);
- if (*(p - 1) != '/')
- *p++ = '/';
- strcpy(p, file);
- return path;
+ if (sb == NULL)
+ sb = stropen();
+ strstart(sb);
+ if ((length = strlen(dir)) > MAXPATHLEN)
+ die1("path name too long. '%s'\n", dir);
+ strputs(sb, dir);
+ strunputc(sb, '/');
+ strputc(sb, '/');
+ strputs(sb, file);
+ if ((length = strlen(strvalue(sb))) > MAXPATHLEN)
+ die1("path name too long. '%s'\n", dir);
+ return strvalue(sb);
}
diff --git a/contrib/global/lib/mgets.c b/contrib/global/lib/mgets.c
index b30cae643936..6b9bb731f70c 100644
--- a/contrib/global/lib/mgets.c
+++ b/contrib/global/lib/mgets.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,17 +28,20 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * mgets.c 8-Nov-97
+ * mgets.c 29-Aug-98
*
*/
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "mgets.h"
#include "die.h"
+#include "mgets.h"
+
+#define EXPANDSIZE 127
+#define MINSIZE 16
-#define EXPANDSIZE 512
static int mbufsize = EXPANDSIZE;
static char *mbuf;
@@ -46,20 +49,21 @@ static char *mbuf;
* mgets: read whole record into allocated buffer
*
* i) ip input stream
+ * o) length record length
* i) flags flags
- * MGETS_CONT \\ + \n -> \n
+ * MGETS_CONT \\ + \n -> ''
* MGETS_SKIPCOM skip line which start with '#'.
- * o) length length of record
+ * MGETS_TAILCUT remove following blanks
* r) record buffer (NULL at end of file)
*
* Returned buffer has whole record.
* The buffer end with '\0' and doesn't include '\r' and '\n'.
*/
char *
-mgets(ip, flags, length)
+mgets(ip, length, flags)
FILE *ip;
-int flags;
int *length;
+int flags;
{
char *p;
@@ -73,27 +77,33 @@ int *length;
* read whole record.
*/
if (!fgets(mbuf, mbufsize, ip))
- return (char *)0;
+ return NULL;
if (flags & MGETS_SKIPCOM)
while (*mbuf == '#')
if (!fgets(mbuf, mbufsize, ip))
- return (char *)0;
+ return NULL;
p = mbuf + strlen(mbuf);
+
for (;;) {
/*
* get a line.
*/
while (*(p - 1) != '\n') {
/*
- * expand and read additionally.
+ * expand buffer and read additionally.
*/
int count = p - mbuf;
- mbufsize += EXPANDSIZE;
- if (!(mbuf = (char *)realloc(mbuf, mbufsize + 1)))
- die("short of memory.");
- p = mbuf + count;
- if (!fgets(p, mbufsize - count, ip))
- die("illegal end of file.");
+
+ if (mbufsize - count < MINSIZE) {
+ mbufsize += EXPANDSIZE;
+ if (!(mbuf = (char *)realloc(mbuf, mbufsize + 1)))
+ die("short of memory.");
+ p = mbuf + count;
+ }
+ if (!fgets(p, mbufsize - count, ip)) {
+ *p++ = '\n';
+ break;
+ }
p += strlen(p);
}
/*
@@ -110,6 +120,17 @@ int *length;
else
break;
}
+/*
+ if (flags & MGETS_SKIPCOM)
+ for (p = mbuf; *p; p++)
+ if (*p == '#') {
+ *p = 0;
+ break;
+ }
+*/
+ if (flags & MGETS_TAILCUT)
+ while (isspace(*(--p)))
+ *p = 0;
if (length)
*length = p - mbuf;
return mbuf;
diff --git a/contrib/global/lib/strop.c b/contrib/global/lib/strop.c
deleted file mode 100644
index b024abca8371..000000000000
--- a/contrib/global/lib/strop.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * strop.c 20-Oct-97
- *
- */
-#include <stdlib.h>
-#include <string.h>
-
-#include "die.h"
-#include "strop.h"
-
-/*
- * usage: string buffer
- *
- * stropen();
- * for (s = string; *s; s++)
- * strputc(*s);
- * s = strclose();
- */
-#define EXPANDSIZE 80
-static char *sbuf;
-static char *endp;
-static char *curp;
-static int sbufsize;
-static int opened;
-
-void
-stropen(void)
-{
- if (opened)
- die("nested call to stropen.");
- opened = 1;
- /*
- * allocate initial buffer.
- */
- if (!sbuf)
- if (!(sbuf = (char *)malloc(sbufsize + 1)))
- die("short of memory.");
- curp = sbuf;
- endp = sbuf + sbufsize;
- *curp = 0;
-}
-void
-strputs(s)
-char *s;
-{
- int length = strlen(s);
-
- strnputs(s, length);
-}
-void
-strnputs(s, length)
-char *s;
-int length;
-{
- if (curp + length > endp) {
- int count = curp - sbuf;
-
- sbufsize += (length > EXPANDSIZE) ? length : EXPANDSIZE;
- if (!(sbuf = (char *)realloc(sbuf, sbufsize + 1)))
- die("short of memory.");
- curp = sbuf + count;
- endp = sbuf + sbufsize;
- }
- strncpy(curp, s, length);
- curp += length;
- *curp = 0;
-}
-void
-strputc(c)
-int c;
-{
- if (curp + 1 > endp) {
- int count = curp - sbuf;
-
- sbufsize += EXPANDSIZE;
- if (!(sbuf = (char *)realloc(sbuf, sbufsize + 1)))
- die("short of memory.");
- curp = sbuf + count;
- endp = sbuf + sbufsize;
- }
- *curp++ = c;
- *curp = 0;
-}
-char *
-strclose(void)
-{
- opened = 0;
- /*
- * doesn't free area in current implementation.
- */
- return sbuf;
-}
diff --git a/contrib/global/lib/strop.h b/contrib/global/lib/strop.h
deleted file mode 100644
index 9289566d0097..000000000000
--- a/contrib/global/lib/strop.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * strop.h 16-Oct-97
- *
- */
-
-#ifndef _STROP_H_
-#define _STROP_H_
-
-#ifndef __P
-#if defined(__STDC__)
-#define __P(protos) protos
-#else
-#define __P(protos) ()
-#endif
-#endif
-
-void stropen __P((void));
-void strputs __P((char *));
-void strnputs __P((char *, int));
-void strputc __P((int));
-char *strclose __P((void));
-
-#endif /* ! _STROP_H_ */
diff --git a/contrib/global/lib/tab.c b/contrib/global/lib/tab.c
index d309386a2d41..1a9896ff8b26 100644
--- a/contrib/global/lib/tab.c
+++ b/contrib/global/lib/tab.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,14 +28,29 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * tab.c 20-Oct-97
+ * tab.c 8-Oct-98
*
*/
#include <stdio.h>
#include "tab.h"
-#define TABPOS(i) ((i)%8 == 0)
+static int tabs = 8;
+
+#define TABPOS(i) ((i)%tabs == 0)
+/*
+ * settabs: set default tab stop
+ *
+ * i) n tab stop
+ */
+void
+settabs(n)
+int n;
+{
+ if (n < 1 || n > 32)
+ return;
+ tabs = n;
+}
/*
* detab: convert tabs into spaces and print
*
@@ -84,7 +99,8 @@ char *buf;
blanks++; /* count blanks */
continue;
}
- buf[dst++] = '\t';
+ /* don't convert single blank into tab */
+ buf[dst++] = (blanks == 0) ? ' ' : '\t';
} else if (c == '\t') {
while (!TABPOS(++pos))
;
@@ -97,5 +113,8 @@ char *buf;
}
blanks = 0;
}
+ if (blanks > 0)
+ while (blanks--)
+ buf[dst++] = ' ';
buf[dst] = 0;
}
diff --git a/contrib/global/lib/tag.c b/contrib/global/lib/tag.c
deleted file mode 100644
index e80d634c2708..000000000000
--- a/contrib/global/lib/tag.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * tag.c 20-Oct-97
- *
- */
-#include <ctype.h>
-#include <string.h>
-
-#include "dbio.h"
-#include "die.h"
-#include "gtagsopen.h"
-#include "locatestring.h"
-#include "tab.h"
-#include "tag.h"
-
-
-static DBIO *dbio;
-static int opened;
-
-void
-tagopen(dbpath, db, mode)
-char *dbpath;
-int db;
-int mode;
-{
- if (opened)
- die("nested call to tagopen.");
- opened = 1;
- dbio = gtagsopen(dbpath, db, mode);
-}
-void
-tagput(entry, record)
-char *entry;
-char *record;
-{
- entab(record);
- db_put(dbio, entry, record);
-}
-void
-tagdelete(path)
-char *path;
-{
- char *p;
- int length = strlen(path);
-
- for (p = db_first(dbio, NULL, DBIO_SKIPMETA); p; p = db_next(dbio)) {
- p = locatestring(p, "./", 0);
- if (!strncmp(p, path, length) && isspace(*(p + length)))
- db_del(dbio, NULL);
- }
-}
-void
-tagclose(void)
-{
- db_close(dbio);
- opened = 0;
-}
diff --git a/contrib/global/lib/tag.h b/contrib/global/lib/tag.h
deleted file mode 100644
index 8bac2ac2f9b6..000000000000
--- a/contrib/global/lib/tag.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Shigio Yamaguchi.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * tag.h 16-Oct-97
- *
- */
-
-#ifndef _TAG_H_
-#define _TAG_H_
-
-#ifndef __P
-#if defined(__STDC__)
-#define __P(protos) protos
-#else
-#define __P(protos) ()
-#endif
-#endif
-
-void tagopen __P((char *, int, int));
-void tagput __P((char *, char *));
-void tagdelete __P((char *));
-void tagclose __P((void));
-
-#endif /* ! _TAG_H_ */
diff --git a/contrib/global/lib/test.c b/contrib/global/lib/test.c
index a3b5966e26a4..d5c940ea294c 100644
--- a/contrib/global/lib/test.c
+++ b/contrib/global/lib/test.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+ * Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -31,8 +31,8 @@
* test.c 12-Dec-97
*
*/
-#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
@@ -50,21 +50,23 @@
* "x" [ -x path ]
*
* i) path path
+ * if NULL then previous path.
* r) 0: no, 1: ok
*
* You can specify more than one character. It assumed 'and' test.
*/
int
test(flags, path)
-char *flags;
-char *path;
+const char *flags;
+const char *path;
{
- struct stat sb;
+ static struct stat sb;
int c;
- if (stat(path, &sb) < 0)
- return 0;
- while ((c = *flags++) != NULL) {
+ if (path != NULL)
+ if (stat(path, &sb) < 0)
+ return 0;
+ while ((c = *flags++) != 0) {
switch (c) {
case 'f':
if (!S_ISREG(sb.st_mode))
diff --git a/contrib/global/nvi-1.34.diff b/contrib/global/nvi-1.34.diff
deleted file mode 100644
index f289e9a8fa98..000000000000
--- a/contrib/global/nvi-1.34.diff
+++ /dev/null
@@ -1,900 +0,0 @@
-diff -c -r -N /usr/src/usr.bin/vi/USD.doc/vi.man/vi.1 ./USD.doc/vi.man/vi.1
-*** /usr/src/usr.bin/vi/USD.doc/vi.man/vi.1 Wed Aug 17 08:36:39 1994
---- ./USD.doc/vi.man/vi.1 Sat Dec 14 11:54:14 1996
-***************
-*** 39,59 ****
- .Nd text editors
- .Sh SYNOPSIS
- .Nm \&ex
-! .Op Fl eFRrsv
- .Op Fl c Ar cmd
- .Op Fl t Ar tag
- .Op Fl w Ar size
- .\".Op Fl X Ar \&aw
- .Op Ar "file ..."
- .Nm \&vi
-! .Op Fl eFRrv
- .Op Fl c Ar cmd
- .Op Fl t Ar tag
- .Op Fl w Ar size
- .\".Op Fl X Ar \&aw
- .Op Ar "file ..."
- .Nm view
-! .Op Fl eFRrv
- .Op Fl c Ar cmd
- .Op Fl t Ar tag
- .Op Fl w Ar size
---- 39,59 ----
- .Nd text editors
- .Sh SYNOPSIS
- .Nm \&ex
-! .Op Fl eFGRrsv
- .Op Fl c Ar cmd
- .Op Fl t Ar tag
- .Op Fl w Ar size
- .\".Op Fl X Ar \&aw
- .Op Ar "file ..."
- .Nm \&vi
-! .Op Fl eFGRrv
- .Op Fl c Ar cmd
- .Op Fl t Ar tag
- .Op Fl w Ar size
- .\".Op Fl X Ar \&aw
- .Op Ar "file ..."
- .Nm view
-! .Op Fl eFGRrv
- .Op Fl c Ar cmd
- .Op Fl t Ar tag
- .Op Fl w Ar size
-***************
-*** 124,129 ****
---- 124,131 ----
- Don't copy the entire file when first starting to edit.
- (The default is to make a copy in case someone else modifies
- the file during your edit session.)
-+ .It Fl G
-+ Start editing in gtags mode, as if the gtagsmode option was set.
- .It Fl R
- Start editing in read-only mode, as if the command name was
- .Nm view ,
-***************
-*** 377,382 ****
---- 379,385 ----
- Move the cursor down
- .Li count
- lines to the first nonblank character of that line.
-+ In gtags select mode, <control-M> select current line as a tag.
- .It Sy "[count] <control-P>"
- .It Sy "[count] k"
- Move the cursor up
-***************
-*** 402,408 ****
- .Nm \&ex
- commands or cancel partial commands.
- .It Sy "<control-]>"
-! Push a tag reference onto the tag stack.
- .It Sy "<control-^>"
- Switch to the most recently edited file.
- .It Sy "[count] <space>"
---- 405,412 ----
- .Nm \&ex
- commands or cancel partial commands.
- .It Sy "<control-]>"
-! Push a tag reference onto the tag stack. In gtagsmode, if at the first column
-! of line, locate function references otherwise function definitions.
- .It Sy "<control-^>"
- Switch to the most recently edited file.
- .It Sy "[count] <space>"
-***************
-*** 780,785 ****
---- 784,793 ----
- Grow or shrink the current screen.
- .It Sy "rew[ind][!]"
- Rewind the argument list.
-+ .It Sy "rta[g][!] tagstring"
-+ Edit the file refering the specified tag. (Only in gtagsmode)
-+ .It Sy "se[lect]"
-+ Select a tag from gtags list.
- .It Sy "se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]"
- Display or set editor options.
- .It Sy "sh[ell]"
-***************
-*** 901,906 ****
---- 909,916 ----
- style) expressions.
- .It Sy "flash [on]"
- Flash the screen instead of beeping the keyboard on error.
-+ .It Sy "gtagsmode, gt [off]"
-+ Use GTAGS and GRTAGS instead of tags.
- .It Sy "hardtabs, ht [8]"
- Set the spacing between hardware tab settings.
- .It Sy "ignorecase, ic [off]"
-diff -c -r -N /usr/src/usr.bin/vi/common/Makefile ./common/Makefile
-*** /usr/src/usr.bin/vi/common/Makefile Mon Sep 12 07:01:45 1994
---- ./common/Makefile Sat Dec 14 11:55:27 1996
-***************
-*** 9,15 ****
- LINKS+= ${BINDIR}/${VI} ${BINDIR}/view
- MAN1= ${.CURDIR}/../USD.doc/vi.man/vi.1
-
-! CFLAGS+=-I. -I${.CURDIR}
- DPADD+= ${LIBCURSES} ${LIBTERMCAP} ${LIBUTIL}
- LDADD+= -lcurses -ltermcap -lutil
-
---- 9,15 ----
- LINKS+= ${BINDIR}/${VI} ${BINDIR}/view
- MAN1= ${.CURDIR}/../USD.doc/vi.man/vi.1
-
-! CFLAGS+=-I. -I${.CURDIR} -DGTAGS
- DPADD+= ${LIBCURSES} ${LIBTERMCAP} ${LIBUTIL}
- LDADD+= -lcurses -ltermcap -lutil
-
-diff -c -r -N /usr/src/usr.bin/vi/common/exf.c ./common/exf.c
-*** /usr/src/usr.bin/vi/common/exf.c Tue May 30 15:35:44 1995
---- ./common/exf.c Sat Dec 14 11:54:15 1996
-***************
-*** 156,162 ****
---- 156,169 ----
- * Required FRP initialization; the only flag we keep is the
- * cursor information.
- */
-+ #ifdef GTAGS
-+ /*
-+ * we must keep gtagstmp information too.
-+ */
-+ F_CLR(frp, ~(FR_CURSORSET|FR_GTAGSTMP));
-+ #else
- F_CLR(frp, ~FR_CURSORSET);
-+ #endif
-
- /*
- * Required EXF initialization:
-***************
-*** 290,295 ****
---- 297,305 ----
- * an error.
- */
- if (rcv_name == NULL)
-+ #ifdef GTAGS
-+ if (!F_ISSET(frp, FR_GTAGSTMP))
-+ #endif
- switch (file_lock(oname,
- &ep->fcntl_fd, ep->db->fd(ep->db), 0)) {
- case LOCK_FAILED:
-diff -c -r -N /usr/src/usr.bin/vi/common/gs.h ./common/gs.h
-*** /usr/src/usr.bin/vi/common/gs.h Wed Aug 17 08:36:42 1994
---- ./common/gs.h Sat Dec 14 11:54:15 1996
-***************
-*** 48,53 ****
---- 48,56 ----
-
- sigset_t blockset; /* Signal mask. */
-
-+ #ifdef GTAGS
-+ char *gtagstmp; /* gtagstmp made by -t option */
-+ #endif
- #ifdef DEBUG
- FILE *tracefp; /* Trace file pointer. */
- #endif
-diff -c -r -N /usr/src/usr.bin/vi/common/main.c ./common/main.c
-*** /usr/src/usr.bin/vi/common/main.c Tue May 30 15:35:45 1995
---- ./common/main.c Sat Dec 14 11:54:15 1996
-***************
-*** 98,103 ****
---- 98,106 ----
- SCR *sp;
- u_int flags, saved_vi_mode;
- int ch, eval, flagchk, readonly, silent, snapshot;
-+ #ifdef GTAGS
-+ int gtags = 0;
-+ #endif
- char *excmdarg, *myname, *p, *tag_f, *trace_f, *wsizearg;
- char path[MAXPATHLEN];
-
-***************
-*** 134,140 ****
---- 137,147 ----
- excmdarg = tag_f = trace_f = wsizearg = NULL;
- silent = 0;
- snapshot = 1;
-+ #ifdef GTAGS
-+ while ((ch = getopt(argc, argv, "c:eFGRrsT:t:vw:X:")) != EOF)
-+ #else
- while ((ch = getopt(argc, argv, "c:eFRrsT:t:vw:X:")) != EOF)
-+ #endif
- switch (ch) {
- case 'c': /* Run the command. */
- excmdarg = optarg;
-***************
-*** 146,151 ****
---- 153,163 ----
- case 'F': /* No snapshot. */
- snapshot = 0;
- break;
-+ #ifdef GTAGS
-+ case 'G': /* gtags mode. */
-+ gtags = 1;
-+ break;
-+ #endif
- case 'R': /* Readonly. */
- readonly = 1;
- break;
-***************
-*** 245,250 ****
---- 257,266 ----
- goto err;
- if (readonly) /* Global read-only bit. */
- O_SET(sp, O_READONLY);
-+ #ifdef GTAGS
-+ if (gtags) /* Global gtags bit. */
-+ O_SET(sp, O_GTAGSMODE);
-+ #endif
- if (silent) { /* Ex batch mode. */
- O_CLR(sp, O_AUTOPRINT);
- O_CLR(sp, O_PROMPT);
-***************
-*** 515,520 ****
---- 531,539 ----
- LIST_INIT(&gp->cutq);
- LIST_INIT(&gp->seqq);
-
-+ #ifdef GTAGS
-+ gp->gtagstmp = NULL;
-+ #endif
- /* Set a flag if we're reading from the tty. */
- if (isatty(STDIN_FILENO))
- F_SET(gp, G_STDIN_TTY);
-***************
-*** 554,559 ****
---- 573,584 ----
- SCR *sp;
- char *tty;
-
-+ #ifdef GTAGS
-+ if (gp->gtagstmp) {
-+ if (!strncmp(gp->gtagstmp, _PATH_GTAGSTMP, strlen(_PATH_GTAGSTMP)))
-+ (void)unlink(gp->gtagstmp);
-+ }
-+ #endif
- /* Default buffer storage. */
- (void)text_lfree(&gp->dcb_store.textq);
-
-diff -c -r -N /usr/src/usr.bin/vi/common/msg.c ./common/msg.c
-*** /usr/src/usr.bin/vi/common/msg.c Thu Aug 18 10:10:54 1994
---- ./common/msg.c Sat Dec 14 11:54:15 1996
-***************
-*** 338,343 ****
---- 338,352 ----
- #else
- pid = "";
- #endif
-+ #ifdef GTAGS
-+ if (F_ISSET(sp->frp, FR_GTAGSTMP)) {
-+ if (file_lline(sp, ep, &last)) {
-+ return (1);
-+ }
-+ msgq(sp, M_INFO, "[GTAGS SELECT MODE] %d lines", last);
-+ return (0);
-+ }
-+ #endif
- /*
- * See nvi/exf.c:file_init() for a description of how and
- * when the read-only bit is set.
-diff -c -r -N /usr/src/usr.bin/vi/common/options.c ./common/options.c
-*** /usr/src/usr.bin/vi/common/options.c Tue May 30 15:35:46 1995
---- ./common/options.c Sat Dec 14 11:54:15 1996
-***************
-*** 103,108 ****
---- 103,112 ----
- {"extended", NULL, OPT_0BOOL, 0},
- /* O_FLASH HPUX */
- {"flash", NULL, OPT_1BOOL, 0},
-+ #ifdef GTAGS
-+ /* O_GTAGSMODE SPECIAL */
-+ {"gtagsmode", NULL, OPT_0BOOL, 0},
-+ #endif
- /* O_HARDTABS 4BSD */
- {"hardtabs", NULL, OPT_NUM, 0},
- /* O_IGNORECASE 4BSD */
-***************
-*** 228,233 ****
---- 232,240 ----
- {"eb", O_ERRORBELLS}, /* 4BSD */
- {"ed", O_EDCOMPATIBLE}, /* 4BSD */
- {"ex", O_EXRC}, /* System V (undocumented) */
-+ #ifdef GTAGS
-+ {"gt", O_GTAGSMODE}, /* Special */
-+ #endif
- {"ht", O_HARDTABS}, /* 4BSD */
- {"ic", O_IGNORECASE}, /* 4BSD */
- {"li", O_LINES}, /* 4.4BSD */
-diff -c -r -N /usr/src/usr.bin/vi/common/pathnames.h ./common/pathnames.h
-*** /usr/src/usr.bin/vi/common/pathnames.h Wed Aug 17 08:36:43 1994
---- ./common/pathnames.h Sat Dec 14 11:54:15 1996
-***************
-*** 43,45 ****
---- 43,48 ----
- #define _PATH_TAGS "tags"
- #define _PATH_TMP "/tmp"
- #define _PATH_TTY "/dev/tty"
-+ #ifdef GTAGS
-+ #define _PATH_GTAGSTMP "/var/tmp/gtags"
-+ #endif
-diff -c -r -N /usr/src/usr.bin/vi/common/screen.h ./common/screen.h
-*** /usr/src/usr.bin/vi/common/screen.h Wed Aug 17 08:36:43 1994
---- ./common/screen.h Sat Dec 14 11:54:15 1996
-***************
-*** 87,92 ****
---- 87,95 ----
- #define FR_TMPEXIT 0x100 /* Modified temporary file, no exit. */
- #define FR_TMPFILE 0x200 /* If file has no name. */
- #define FR_UNLOCKED 0x400 /* File couldn't be locked. */
-+ #ifdef GTAGS
-+ #define FR_GTAGSTMP 0x800 /* File is gtags temporary file. */
-+ #endif
- u_int16_t flags;
- };
-
-diff -c -r -N /usr/src/usr.bin/vi/ex/ex_tag.c ./ex/ex_tag.c
-*** /usr/src/usr.bin/vi/ex/ex_tag.c Thu Aug 18 10:13:20 1994
---- ./ex/ex_tag.c Sat Dec 14 11:54:15 1996
-***************
-*** 64,69 ****
---- 64,72 ----
- #include "vi.h"
- #include "excmd.h"
- #include "tag.h"
-+ #ifdef GTAGS
-+ #include "pathnames.h"
-+ #endif
-
- static char *binary_search __P((char *, char *, char *));
- static int compare __P((char *, char *, char *));
-***************
-*** 71,76 ****
---- 74,288 ----
- static int search __P((SCR *, char *, char *, char **));
- static int tag_get __P((SCR *, char *, char **, char **, char **));
-
-+ #ifdef DEBUG
-+ void
-+ trace(fp)
-+ FILE *fp;
-+ {
-+ SCR *sp;
-+ TAG *tp;
-+ FREF *frp;
-+ int scr, fref, tag;
-+
-+ fprintf(fp, "------------------------------------\n");
-+ scr = 0;
-+ for (sp = __global_list->dq.cqh_first; sp != (void *)&__global_list->dq; sp = sp->q.cqe_next) {
-+ fprintf(fp, "screen %d {\n", ++scr);
-+ fref = 0;
-+ for (frp = sp->frefq.cqh_first;
-+ frp != (FREF *)&sp->frefq; frp = frp->q.cqe_next) {
-+ fprintf(fp, " FREF %d ", ++fref);
-+ if (F_ISSET(frp, FR_GTAGSTMP))
-+ fprintf(fp, "<%s>\n", frp->name);
-+ else
-+ fprintf(fp, "%s\n", frp->name);
-+ }
-+ tag = 0;
-+ if (!EXP(sp))
-+ continue;
-+ fprintf(fp, " ................................\n");
-+ for (tp = EXP(sp)->tagq.tqh_first; tp != NULL; tp = tp->q.tqe_next) {
-+ fprintf(fp, " TAG %d ", ++tag);
-+ if (F_ISSET(tp->frp, FR_GTAGSTMP))
-+ fprintf(fp, "<%s>\n", tp->frp->name);
-+ else
-+ fprintf(fp, "%s\n", tp->frp->name);
-+ }
-+ fprintf(fp, "}\n");
-+ }
-+ fprintf(fp, "------------------------------------\n");
-+ }
-+ #endif
-+ #ifdef GTAGS
-+ /*
-+ * getentry --
-+ * get tag information from current line.
-+ *
-+ * gtags temporary file format.
-+ * <tag> <lineno> <file> <image>
-+ *
-+ * sample.
-+ * +------------------------------------------------
-+ * |main 30 main.c main(argc, argv)
-+ * |func 21 subr.c func(arg)
-+ */
-+ static int
-+ getentry(buf, tag, file, line)
-+ char *buf, *tag, *file, *line;
-+ {
-+ char *p;
-+
-+ p = tag;
-+ while (*buf && !isspace(*buf)) /* tag name */
-+ *p++ = *buf++;
-+ *p = 0;
-+ while (*buf && isspace(*buf)) /* skip blanks */
-+ buf++;
-+ p = line;
-+ while (*buf && !isspace(*buf)) /* line no */
-+ *p++ = *buf++;
-+ *p = 0;
-+ while (*buf && isspace(*buf)) /* skip blanks */
-+ buf++;
-+ p = file;
-+ while (*buf && !isspace(*buf)) /* file name */
-+ *p++ = *buf++;
-+ *p = 0;
-+
-+ /* value check */
-+ if (strlen(tag) && strlen(line) && strlen(file) && atoi(line) > 0)
-+ return 1; /* OK */
-+ return 0; /* ERROR */
-+ }
-+
-+ /*
-+ * gtag_get --
-+ * Get a gtag from the GTAGS files.
-+ */
-+ static int
-+ gtag_get(sp, ref, gtagselect, tag, tagp, filep, searchp)
-+ SCR *sp;
-+ int ref;
-+ int *gtagselect;
-+ char *tag, **tagp, **filep, **searchp;
-+ {
-+ static char name[80], file[200], line[10], gtagstmp[80];
-+ char command[200];
-+ char buf[BUFSIZ+1];
-+ FILE *fp;
-+
-+ sprintf(gtagstmp, "%s.XXXXXXXX", _PATH_GTAGSTMP);
-+ if (mktemp(gtagstmp) == 0) {
-+ msgq(sp, M_ERR, "cannot generate temporary file name");
-+ return (1);
-+ }
-+ sprintf(command, "global -%s '%s' > %s; chmod 600 %s",
-+ ref ? "rx" : "x", tag, gtagstmp, gtagstmp);
-+ if (system(command)) {
-+ msgq(sp, M_ERR, "cannot exec global");
-+ goto err;
-+ }
-+ if (!(fp = fopen(gtagstmp, "r"))) {
-+ msgq(sp, M_ERR, "tag file cannot open.");
-+ goto err;
-+ }
-+ if (!(fgets(buf, BUFSIZ, fp))) {
-+ msgq(sp, M_ERR, "%s: tag not found", tag);
-+ fclose(fp);
-+ goto err;
-+ }
-+
-+ if (getentry(buf, name, file, line) == 0) {
-+ msgq(sp, M_ERR, "%s: illegal tag entry", tag);
-+ fclose(fp);
-+ goto err;
-+ }
-+
-+ if (!(fgets(buf, BUFSIZ, fp))) { /* just one line */
-+ fclose(fp);
-+ (void)unlink(gtagstmp);
-+ *gtagselect = 0; /* go to user's file immediately */
-+ *tagp = strdup(name);
-+ *filep = file;
-+ *searchp = line;
-+ if (*tagp == NULL) {
-+ msgq(sp, M_SYSERR, NULL);
-+ return (1);
-+ }
-+ return (0);
-+ }
-+ fclose(fp);
-+ *gtagselect = 1; /* go to gtags select mode */
-+ *tagp = strdup(name);
-+ *filep = gtagstmp;
-+ *searchp = "1";
-+ if (*tagp == NULL) {
-+ msgq(sp, M_SYSERR, NULL);
-+ return (1);
-+ }
-+ return (0);
-+ err:
-+ (void)unlink(gtagstmp);
-+ return (1);
-+ }
-+
-+ /*
-+ * ex_gtagselect --
-+ * The tag code can be entered from gtag select mode.
-+ */
-+ int
-+ ex_gtagselect(sp, ep, cmdp)
-+ SCR *sp;
-+ EXF *ep;
-+ EXCMDARG *cmdp;
-+ {
-+ if (!F_ISSET(sp->frp, FR_GTAGSTMP)) {
-+ msgq(sp, M_ERR, "illegal tag entry");
-+ return (1);
-+ }
-+ cmdp->cmd = &cmds[C_TAG];
-+ cmdp->flags |= (E_GTAGSELECT|E_FORCE);
-+ return ex_tagpush(sp, ep, cmdp);
-+ }
-+
-+ /*
-+ * should_delete --
-+ * 1: should delete, 0: should not delete
-+ */
-+ int
-+ should_delete(gtagstmp)
-+ char *gtagstmp;
-+ {
-+ SCR *sp;
-+ TAG *tp;
-+ int tagcnt = 0;
-+
-+ /* make sure */
-+ if (strncmp(gtagstmp, _PATH_GTAGSTMP, strlen(_PATH_GTAGSTMP)))
-+ return 0;
-+ /* this gtag is generated by -t option. don't delete here */
-+ if (__global_list->gtagstmp && !strcmp(gtagstmp, __global_list->gtagstmp))
-+ return 0;
-+
-+ for (sp = __global_list->dq.cqh_first; sp != (void *)&__global_list->dq; sp = sp->q.cqe_next) {
-+ if (!EXP(sp))
-+ continue;
-+ for (tp = EXP(sp)->tagq.tqh_first; tp != NULL; tp = tp->q.tqe_next) {
-+ if (!tp->frp || !F_ISSET(tp->frp, FR_GTAGSTMP))
-+ continue;
-+ if (!strcmp(tp->frp->name, gtagstmp))
-+ ++tagcnt;
-+ }
-+ }
-+ if (tagcnt == 1)
-+ return 1;
-+ if (tagcnt > 1)
-+ return 0;
-+ /* IMPOSSIBLE */
-+ return 0;
-+ }
-+ #endif
-+
- /*
- * ex_tagfirst --
- * The tag code can be entered from main, i.e. "vi -t tag".
-***************
-*** 86,96 ****
---- 298,317 ----
- u_int flags;
- int sval;
- char *p, *tag, *name, *search;
-+ #ifdef GTAGS
-+ int gtagselect = 0;
-+ #endif
-
- /* Taglength may limit the number of characters. */
- if ((tl = O_VAL(sp, O_TAGLENGTH)) != 0 && strlen(tagarg) > tl)
- tagarg[tl] = '\0';
-
-+ #ifdef GTAGS
-+ if (O_ISSET(sp, O_GTAGSMODE)) {
-+ if (gtag_get(sp, 0, &gtagselect, tagarg, &tag, &name, &search))
-+ return (1);
-+ } else
-+ #endif
- /* Get the tag information. */
- if (tag_get(sp, tagarg, &tag, &name, &search))
- return (1);
-***************
-*** 106,111 ****
---- 327,336 ----
- * The historic tags file format (from a long, long time ago...)
- * used a line number, not a search string. I got complaints, so
- * people are still using the format.
-+ #ifdef GTAGS
-+ * Yes, gtags use the old format. Search string is very flexible
-+ * but is not suitable to treat duplicate entries.
-+ #endif
- */
- if (isdigit(search[0])) {
- m.lno = atoi(search);
-***************
-*** 132,137 ****
---- 357,371 ----
- frp->lno = m.lno;
- frp->cno = m.cno;
- F_SET(frp, FR_CURSORSET);
-+ #ifdef GTAGS
-+ if (gtagselect) {
-+ F_SET(frp, FR_GTAGSTMP);
-+ if (!(sp->gp->gtagstmp = strdup(name))) {
-+ msgq(sp, M_SYSERR, NULL);
-+ return (1);
-+ }
-+ }
-+ #endif
-
- /* Might as well make this the default tag. */
- if ((EXP(sp)->tlast = strdup(tagarg)) == NULL) {
-***************
-*** 142,153 ****
---- 376,399 ----
- }
-
- /* Free a tag or tagf structure from a queue. */
-+ #ifdef GTAGS
- #define FREETAG(tp) { \
-+ if (F_ISSET(tp->frp, FR_GTAGSTMP)) \
-+ if (should_delete(tp->frp->name)) \
-+ unlink(tp->frp->name); \
- TAILQ_REMOVE(&exp->tagq, (tp), q); \
- if ((tp)->search != NULL) \
- free((tp)->search); \
- FREE((tp), sizeof(TAGF)); \
- }
-+ #else
-+ #define FREETAG(tp) { \
-+ TAILQ_REMOVE(&exp->tagq, (tp), q); \
-+ if ((tp)->search != NULL) \
-+ free((tp)->search); \
-+ FREE((tp), sizeof(TAGF)); \
-+ }
-+ #endif
- #define FREETAGF(tfp) { \
- TAILQ_REMOVE(&exp->tagfq, (tfp), q); \
- free((tfp)->name); \
-***************
-*** 182,189 ****
---- 428,464 ----
- int sval;
- long tl;
- char *name, *p, *search, *tag;
-+ #ifdef GTAGS
-+ int gtagselect = 0;
-+ char *line;
-+ size_t len;
-+ char tagbuf[80], namebuf[200], linebuf[10];
-+ #endif
-
- exp = EXP(sp);
-+ #ifdef GTAGS
-+ /*
-+ * Enter from gtag select mode.
-+ * get tag information from current line.
-+ */
-+ if (F_ISSET(cmdp, E_GTAGSELECT)) {
-+ if ((line = file_gline(sp, ep, sp->lno, &len)) == NULL) {
-+ GETLINE_ERR(sp, sp->lno);
-+ return (1);
-+ }
-+ if (getentry(line, tagbuf, namebuf, linebuf) == 0) {
-+ msgq(sp, M_ERR, "illegal tag entry");
-+ return (1);
-+ }
-+ if (!(tag = strdup(tagbuf))) {
-+ msgq(sp, M_SYSERR, NULL);
-+ return (1);
-+ }
-+ name = namebuf;
-+ search = linebuf;
-+ goto getfref;
-+ }
-+ #endif
- switch (cmdp->argc) {
- case 1:
- if (exp->tlast != NULL)
-***************
-*** 207,216 ****
---- 482,504 ----
- if ((tl = O_VAL(sp, O_TAGLENGTH)) != 0 && strlen(exp->tlast) > tl)
- exp->tlast[tl] = '\0';
-
-+ #ifdef GTAGS
-+ if (O_ISSET(sp, O_GTAGSMODE)) {
-+ if (gtag_get(sp, F_ISSET(cmdp->cmd, E_REFERENCE), &gtagselect,
-+ exp->tlast, &tag, &name, &search))
-+ return (1);
-+ } else if (F_ISSET(cmdp->cmd, E_REFERENCE)) {
-+ msgq(sp, M_ERR, "Please set gtagsmode");
-+ return (1);
-+ } else
-+ #endif
- /* Get the tag information. */
- if (tag_get(sp, exp->tlast, &tag, &name, &search))
- return (1);
-
-+ #ifdef GTAGS
-+ getfref:
-+ #endif
- /* Get the (possibly new) FREF structure. */
- if ((frp = file_add(sp, name)) == NULL)
- goto err;
-***************
-*** 305,310 ****
---- 593,603 ----
- sp->cno = m.cno;
- break;
- }
-+ #ifdef GTAGS
-+ if (gtagselect) {
-+ F_SET(frp, FR_GTAGSTMP);
-+ }
-+ #endif
- return (0);
- }
-
-***************
-*** 490,495 ****
---- 783,793 ----
- for (cnt = 1, tp = exp->tagq.tqh_first; tp != NULL;
- ++cnt, tp = tp->q.tqe_next) {
- len = strlen(name = tp->frp->name); /* The original name. */
-+ #ifdef GTAGS
-+ if (F_ISSET(tp->frp, FR_GTAGSTMP)) {
-+ (void)ex_printf(EXCOOKIE, "%2d [GTAGS]\n", cnt);
-+ } else
-+ #endif
- if (len > maxlen || len + tp->slen > sp->cols)
- if (tp == NULL || tp->search == NULL)
- (void)ex_printf(EXCOOKIE,
-diff -c -r -N /usr/src/usr.bin/vi/ex/excmd.c ./ex/excmd.c
-*** /usr/src/usr.bin/vi/ex/excmd.c Thu Aug 18 10:13:29 1994
---- ./ex/excmd.c Sat Dec 14 11:54:15 1996
-***************
-*** 319,324 ****
---- 319,331 ----
- "!",
- "rew[ind][!]",
- "re-edit all the files in the file argument list"},
-+ #ifdef GTAGS
-+ /* C_RTAG */
-+ {"rtag", ex_tagpush, E_NOGLOBAL|E_REFERENCE,
-+ "!w1o",
-+ "rta[g][!] [string]",
-+ "edit the file containing the tag"},
-+ #endif
- /* C_SUBSTITUTE */
- {"substitute", ex_substitute, E_ADDR2|E_NORC,
- "s",
-***************
-*** 329,334 ****
---- 336,348 ----
- "!f1o",
- "sc[ript][!] [file]",
- "run a shell in a screen"},
-+ #ifdef GTAGS
-+ /* C_GTAGSELECT */
-+ {"select", ex_gtagselect, E_NOGLOBAL,
-+ "",
-+ "sel[ect]",
-+ "edit the file containing the tag"},
-+ #endif
- /* C_SET */
- {"set", ex_set, E_NOGLOBAL,
- "wN",
-diff -c -r -N /usr/src/usr.bin/vi/ex/excmd.h.stub ./ex/excmd.h.stub
-*** /usr/src/usr.bin/vi/ex/excmd.h.stub Wed Aug 17 08:36:28 1994
---- ./ex/excmd.h.stub Sat Dec 14 11:54:15 1996
-***************
-*** 69,74 ****
---- 69,79 ----
- #define E_NORC 0x0800000 /* Not from a .exrc or EXINIT. */
- #define E_ZERO 0x1000000 /* 0 is a legal addr1. */
- #define E_ZERODEF 0x2000000 /* 0 is default addr1 of empty files. */
-+
-+ #ifdef GTAGS
-+ #define E_REFERENCE 0x4000000 /* locate function references */
-+ #define E_GTAGSELECT 0x8000000 /* current line is gtags entry */
-+ #endif
- u_int32_t flags;
- char *syntax; /* Syntax script. */
- char *usage; /* Usage line. */
-***************
-*** 234,239 ****
---- 239,245 ----
- EXPROTO(ex_fg);
- EXPROTO(ex_file);
- EXPROTO(ex_global);
-+ EXPROTO(ex_gtagselect);
- EXPROTO(ex_help);
- EXPROTO(ex_insert);
- EXPROTO(ex_join);
-diff -c -r -N /usr/src/usr.bin/vi/svi/svi_refresh.c ./svi/svi_refresh.c
-*** /usr/src/usr.bin/vi/svi/svi_refresh.c Tue May 30 15:35:56 1995
---- ./svi/svi_refresh.c Sat Dec 14 11:54:16 1996
-***************
-*** 725,731 ****
---- 725,736 ----
- EXF *ep;
- {
- size_t cols, curlen, endpoint, len, midpoint;
-+ #ifdef GTAGS
-+ char *p, buf[30];
-+ recno_t last;
-+ #else
- char *p, buf[20];
-+ #endif
-
- /* Clear the mode line. */
- MOVE(sp, INFOLINE(sp), 0);
-***************
-*** 746,751 ****
---- 751,765 ----
-
- curlen = 0;
- if (sp->q.cqe_next != (void *)&sp->gp->dq) {
-+ #ifdef GTAGS
-+ if (F_ISSET(sp->frp, FR_GTAGSTMP)) {
-+ if (file_lline(sp, ep, &last)) {
-+ return (1);
-+ }
-+ sprintf(buf, "[GTAGS SELECT MODE] %d lines", last);
-+ p = buf;
-+ } else {
-+ #endif
- for (p = sp->frp->name; *p != '\0'; ++p);
- while (--p > sp->frp->name) {
- if (*p == '/') {
-***************
-*** 758,764 ****
- break;
- }
- }
-!
- MOVE(sp, INFOLINE(sp), 0);
- standout();
- for (; *p != '\0'; ++p)
---- 772,780 ----
- break;
- }
- }
-! #ifdef GTAGS
-! }
-! #endif
- MOVE(sp, INFOLINE(sp), 0);
- standout();
- for (; *p != '\0'; ++p)
-diff -c -r -N /usr/src/usr.bin/vi/vi/v_ex.c ./vi/v_ex.c
-*** /usr/src/usr.bin/vi/vi/v_ex.c Thu Aug 18 10:15:03 1994
---- ./vi/v_ex.c Sat Dec 14 11:54:16 1996
-***************
-*** 298,303 ****
---- 298,308 ----
- ARGS *ap[2], a;
- EXCMDARG cmd;
-
-+ #ifdef GTAGS
-+ if (O_ISSET(sp, O_GTAGSMODE) && vp->m_start.cno == 0)
-+ excmd(&cmd, C_RTAG, 0, OOBLNO, 0, 0, ap, &a, vp->keyword);
-+ else
-+ #endif
- excmd(&cmd, C_TAG, 0, OOBLNO, 0, 0, ap, &a, vp->keyword);
- return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
- }
-diff -c -r -N /usr/src/usr.bin/vi/vi/v_scroll.c ./vi/v_scroll.c
-*** /usr/src/usr.bin/vi/vi/v_scroll.c Thu Aug 18 10:15:15 1994
---- ./vi/v_scroll.c Sat Dec 14 11:54:16 1996
-***************
-*** 255,260 ****
---- 255,269 ----
- EXF *ep;
- VICMDARG *vp;
- {
-+ #ifdef GTAGS
-+ EXCMDARG cmd;
-+
-+ if (F_ISSET(sp->frp, FR_GTAGSTMP)) {
-+ memset(&cmd, 0, sizeof(EXCMDARG));
-+ cmd.cmd = &cmds[C_GTAGSELECT];
-+ return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
-+ }
-+ #endif
- /*
- * If it's a script window, exec the line,
- * otherwise it's the same as v_down().