Import Global v3_4_2 sources.

Ok'd by: peter
Discussed with: msmith
This commit is contained in:
simokawa 1999-01-18 06:59:18 +00:00
parent 490818046d
commit cf4b2ca9b8
77 changed files with 8201 additions and 2521 deletions

View File

@ -1,15 +1,17 @@
@@@@@@@=
@= @=
@= @=
@= @= @@@@@= @@@@@@= @@= @=
@= F o r a l l h a c k e r s. @=@= @=
@= @@@@@@=@= @= @= @@@@@= @= @= @=
@= @= @= @= @= @= @= @@@@@= @=
@= @= @= @= @= @= @=@= @= @=
@@@@@@@@= @@@@= @@@@@= @@@@@@=@@@= @@@@= @@@@@@=
@@@@@@@=)))
@=))) @=))) @=)))
@=))) @=)))
@=))) @=))) @@@@@=)@@@@@@=))) @@=) @=)))
@=))F o r a l l)) h a c k e r s.))) @=@=))@=)))
@=))) @@@@@@=@=)))@=))) @=)@@@@@=)))@= @=))@=)))
@=))) @=))@=)))@=))) @=)@=)))@=)@@@@@=))@=)))
@=))) @=))@=)))@=))) @=)@=)))@=@=)))@=))@=)))
@@@@@@@@=)))@@@@=)@@@@@=)@@@@@@=@@@=)@@@@=)@@@@@@=)))
This software is covered by the following:
This software is covered by the followings:
Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
@ -40,7 +42,8 @@ This software is covered by the following:
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of gozilla(1) are covered by the following:
Portions of gozilla(1):
Copyright 1996 Netscape Communications Corporation, all rights reserved.
Created: Jamie Zawinski <jwz@netscape.com>, 24-Dec-94.

67
contrib/global/FAQ Normal file
View File

@ -0,0 +1,67 @@
Frequentry Asked Questions about GLOBAL.
----------------------------------------------------------------------------
Q1. Htags(1) aborts by short of memory. Why? Any workaround?
% htags
Out of memory!
% _
A1. It seems that Perl4 leaks memory. If you use that version of perl,
then you had better to use Perl5. This works well.
----------------------------------------------------------------------------
Q2. Global(1) and btreeop(1) sometimes core dumps when using a large tag file.
Any workaround?
A2. Btree(3) core dumps with a certain data set.
Please apply the patches in this package. See ./dbpatches/README.
----------------------------------------------------------------------------
Q3. GLOBAL skip some functions.
For example, GLOBAL skip the function 'func' in this example.
#define M(a) static char *string = a;
M(a)
func() { <= GLOBAL skip func().
...
}
A3. GLOBAL cannot recognize that pattern, because M(a) seems to be
a function definition.
It should be follows.
#define M(a) static char *string = a
M(a); <= end with ';'
func() {
...
}
Otherwise, you can tell gtags(1) that by listing the macros in
'.notfunction' file in current directory.
[.notfunction]
+---------------
|M
|...
----------------------------------------------------------------------------
Q4. I have set up 'global.conf' to use emacs's ctags command with GLOBAL
but I cannot use htags.
% gtags
% htags
htags: GTAGS and GRTAGS not found. Please make them.
% ls G*
GPATH GTAGS
A4. Emacs's ctags cannot locate function referencies. So, gtags cannot make
GRTAGS tag file with it. With the result that you cannot use htags and
global's -r option.
----------------------------------------------------------------------------

View File

@ -1,3 +1,4 @@
GLOBAL history
--------------
@ -5,6 +6,8 @@ version 1.0 Initial version [21-Apr-96]
global, gtags, btreeop, extended ctags.
Thanks to Sadaichi Hayashida. Generating relative path is his idea.
version 1.1 Only bugfix [2-May-96]
[fixed bug]
@ -217,8 +220,8 @@ version 2.1 Symbol search, incremental update and gozilla [20-Sep-97]
These options become default, so you need not to specify
them. Gtags accepts these options for compatibility but
no effect.
global - understand not only 'obj'(MAKEOBJDIR) directory but also
'/usr/obj'(MAKEOBJDIRPREFIX) directory of BSD build system.
global - understand 'obj'(MAKEOBJDIR) directory and '/usr/obj'
(MAKEOBJDIRPREFIX) directory of BSD build system.
Thanks to Jordan K. Hubbard. This is his idea.
@ -304,12 +307,12 @@ version 2.21 Bugfix and slightly modified [11-Dec-97]
- replace `lorder $(OBJS) | tsort -q` to already sorted list.
for S.u.S.E Linux 5.1.
Thanks to Christoph Conrad for his information.
Thanks to Christoph Conrad for his information.
gtags, lib/test.c
- some change for Solaris environment.
Thanks to Yamashita TAKAO for his information.
Thanks to Yamashita TAKAO for his information.
htags/Makefile, systags/Makefile
- ${DESTDIR}/usr/bin -> ${DESTDIR}${BINDIR}
@ -323,14 +326,14 @@ version 2.22 GRTAGS support for assembler source [26-Dec-97]
call EXT(xxx)
call _xxx
Thanks to Yamashita TAKAO for his idea.
Thanks to Yamashita TAKAO for his idea.
version 2.23 Bugfix and slightly modified [13-Jan-98]
[fixed bug]
gctags - GRTAGS support in version 2.22 doesn't work.
Thanks to Yamashita TAKAO for his bug report.
Thanks to Yamashita TAKAO for his bug report.
[changed]
gctags/Makefile, gctags/Makefile.generic
@ -347,11 +350,216 @@ version 2.24 Only bugfix [20-Jan-98]
global - generates wrong path name when GTAGSROOT includes symbolic
links.
Thanks to Wolfgang Helbig for his bug report.
Thanks to Wolfgang Helbig for his bug report.
htags - cannot treat path name which includes digit as the second
character like 'i386'. (In fact it was expand(1)'s bug.)
Thanks to Andrew Gallatin for his bug report.
Thanks to Andrew Gallatin for his bug report.
global - doesn't search 'obj' directory correctly.
version 3.0 configuration file and compact format. [25-Jun-98]
[fixed bug]
gozilla - leaks memory.
gctags - -s option pick up symbols which belongs to GTAGS or GRTAGS.
global - cannot treat file which doesn't end with '\n'.
gtags - incremental update cannot detect removed files.
(GPATH file added.)
- make corrupted tag files.
(dbpatches/README added.)
Thanks to Van Trinh for his bug report and information.
htags - cannot be viewed by IE 5.0 because illegal <NOFRAME> tag.
Thanks to Yoshida Masato for his bug report and fix patch.
[changed]
gctags - -c option removed. These code was moved to gtags.
(It was needed for supporting plugged-in parser.)
global - -f option excute tag command instead of reading tag file.
(It became very faster than previous version.)
gtags.el- check whether or not user want to use tag name completion.
htags - URL of GLOBAL home page changed.
systags - gtags's option changed from -v to -cov.
gtags.c - replace "%+" of strftime with "%a %b %e %H:%M:%S %Z %Y".
for Debian GNU linux 1.3.1.
[added]
gtags - -c option added. (compact format)
Thanks to Takeshi Hojo. Compact format is based on his concept.
htags - -c option added. (to make gzipped html file)
Thanks to Oliver Paukstadt. This option is his idea.
gtags, htags
- support configuration file.
(/etc/global.conf or $HOME/.globalrc)
gctags - -n option added.
--config option added. (It's undocumented.)
global - -t option added.
This option is to use with 'tagprg' and 'tagprgonce' command
in Elvis editor (2.1g-beta or later).
Thanks to Steve Kirkendall for his excellent editor and
refined command set.
version 3.01 Almost bugfix [5-Jul-98]
[fixed bug]
global - print file names in a line.
gozilla - assume html file as a source file.
btreeop - insufficient usage check.
htags - cannot treat path including "++".
[changed]
global - -f option became to accept multiple files.
all - fixed warning by -Wall -Wmissing-prototypes.
version 3.1 Support of Java language [4-Aug-98]
[fixed bug]
htags - locate main functions from the path which belongs
GTAGSLIBPATH when there is no main function in the local
source tree.
[added]
gtags, global, htags, gozilla, gtags.el
- java supprt added.
gtags - --find option added. (internal use only - undocumented)
- --expand option added. (internal use only - undocumented)
htags - -h option (title header frame) added.
Thanks to Shigeyuki Yamano. This is his idea.
- line comment('//') detection added.
gctags, systags
- GTAGSSPECIAL environment variable added to treat system
macros like 'SYSINIT' in FreeBSD.
global.conf, lib/conf.c
- 'CVS/' added to 'skip' parameter.
[deleted]
gtags.conf
- 'reserved_words' for htags(1) was deleted.
It is hard coded.
[changed]
htags.pl- print guide links in .h file too.
version 3.2 new patch for nvi-1.79(1.66) and multilingual nvi [31-Aug-98]
[fixed bug]
nvi-1.79.diff
- may have buffer overflow.
Thanks to David Brownlee for his advice.
- suppress error message 'GTAGS not found'.
[added]
nvi-1.79-m17n.diff
- patch for multilingual nvi which is included FreeBSD as
a ports.
nvi-1.66.diff
- patch for nvi-1.66 which is native command of NetBSD 1.3.2
[deleted]
nvi-1.34.diff
- it is old enough to support.
[changed]
gozilla/Imakefile
- make possible to build gozilla alone without building
libgloutil.a.
version 3.3 Rewriting gctags(1) and some bug fix. [13-Sep-98]
[fixed bug]
gctags - look over inner class in a method.(Java)
- cannot treat 'OBJECT.class' pattern correctly.(Java)
[changed]
Makefile*
- library name changed from libutil.a to libgloutil.a becase
that is already used.
- definition of MANDIR deleted.
global.conf
- comment fixed.
systags.sh
- additional support for NetBSD, OpenBSD, GNUmach and GNUhurd.
- doesn't use CGI form by default.
- use gtags -l and -h option by default.
- -g(gtags only), -f(form) and -c(compact) option added.
[deleted]
gctags - fortran and lisp language support were deleted, because
it was not supported in GLOBAL system.
- -a, -d, -f, -t, -u, -w, -v options were deleted,
because it was not used in GLOBAL system.
- -D, -x options were deleted. These options became default.
- GTAGSSPECIAL was deleted.
[added]
gctags - #if (#else #elif) #endif block parsing added.
- pick up #define in assembler source.
- can pick up object like 'definition\n\n() {'.
- -b, -n, -w options were added.
gtags.el- gtags-display-browser(ESC-h) command added.
INSTALL - explanation about formatting online manuals added.
Thanks to Bert Gijsbers for his investigation.
Extended ctags has been completely replaced with new gctags.
Thanks to Ken Arnold and the other people who developped BSD ctags(1).
Without it, GLOBAL had never been here.
version 3.4 Unlimited nested index of htags(1). [8-Nov-98]
[added]
global - --filter option added. (internal use only - undocumented)
htags - tabs parameter added in global.conf to change tab stop.
btreeop - '2' option added to the -L command.
[changed]
htags - unlimited nested index of files supported.
README, htags.1,
- statements fixed.
Thanks to Silas S. Brown for his fixing the statements.
Makefile.generic
- make sub makefiles inherit the macros from the root Makefile.
version 3.41 description added to README file. [10-Dec-98]
[added]
README - usage description added.
'5. Elvis using global'
'A.3. Incremental updating'
INSTALL - description about Elvis added.
[change]
global - -t option is available with -P command.
global - assume "global -c ''" as "global -c".
[deleted]
nvi-1.79-m17n.diff
- because it is difficult for me to maintain. Sorry.
version 3.42 a couple of bugs fixed. [8-Jan-99]
[fixed]
btreeop.c,gctags.c,global.c,gozilla.c,remote.c,gtags.c
- 'void main()' is not valid by the C spec.
Thanks to David Brownlee for his patch.
gtags.el- redefinition problem fixed.
(renamed match-string to util-match-string.)
Thanks to Daisuke Kawahara for his bug report.

View File

@ -1,7 +1,7 @@
Installation of GLOBAL
20-Jan-1998 Shigio Yamaguchi
6-Dec-1998 Shigio Yamaguchi
---------------------------------------------------------------------------
Guide line (C style)
---------------------------------------------------------------------------
@ -14,26 +14,30 @@ if (Your system == FreeBSD) {
case 2.0.5R:
case 2.1.0R:
case 2.1.5R:
There is no problem.
break;
case 2.1.6R:
case 2.1.7R:
I don't know. But it seems same with 2.1.5R.
break;
case 2.2.1R:
It is OK. But your native nvi is version 1.71.
Use 1.79 nvi available on the Internet.
There is no problem.
break;
case 2.2.2R:
case 2.2.5R:
Your system inlucdes GLOBAL 1.9. You can overwrite it
with this 2.2 package.
But skip procedure "3. Extended vi (OPTIONAL)", because
your /usr/bin/nvi is already extended nvi for GLOBAL.
case 2.2.6R:
case 2.2.7R:
Your system includes GLOBAL 1.9 or 2.24.
You can overwrite it with this package.
break;
default:
I don't know. But it seems to be little problem.
}
} else if (Your system == NetBSD 1.3.2) {
You are lucky!
You need not to do procedure "1. Preparation for generic UNIX"
and you can use nvi-1.66.diff for native nvi.
} else if (Your system == Debian GNU linux 1.3.1) {
You are lucky!
You can skip most of "1. Preparation for generic UNIX" except for
"a) Generic makefile".(It's very easy.)
} else {
You may some error messages to make GLOBAL.
But it seems not so difficult to clear it. If you make a patch for it,
@ -43,6 +47,8 @@ if (Your system == FreeBSD) {
Thank you in advance.
}
Please see ./dbpatches/README.
----------------------------------------------------------------------------
Install procedure
----------------------------------------------------------------------------
@ -56,31 +62,47 @@ Install procedure
1. Preparation for generic UNIX
If you are a FreeBSD (all version) user, nothing to do here.
Please go to "2. GLOBAL basic".
If you are a user of FreeBSD (all version) or NetBSD 1.3.2 then
nothing to do here. Please go to "2. GLOBAL basic".
Otherwise, you must install following items before you install GLOBAL.
Otherwise, you must check following items before you install GLOBAL.
a) Generic makefile
a) Generic makefile (necessary)
This package includes generic makefile. Please do the followings.
% make -f Makefile.generic gen
% vi Makefile <- check install directories (BINDIR, MANDIR)
% vi Makefile <- check variables like BINDIR, MANDIR, ...
b) BSD db library version 1.85
b) Some UNIX tools (necessary)
Find(1), sed(1), sort(1), uniq(1) are needed.
If your environment is UNIX, you have them. You can confirm it like this.
% which find
/usr/bin/find
%
c) POSIX regular expression (extension) library (necessary)
If you don't have it, you can use GNU's regex library (regex-0.12.tar.gz).
See following site.
http://www.gnu.org/order/ftp.html
d) BSD db library version 1.85 (necessary)
If you don't have it, you can fetch it from this site.
http://mongoose.bostic.com/db/packages/db.1.85.tar.gz
c) PERL version 4 or later
e) PERL version 4 or later (needed for htags)
If you don't have it, you can fetch it from this site.
ftp://ftp.cis.ufl.edu/pub/perl/CPAN/src/5.0/latest.tar.gz
d) Rewrite some files
f) Rewrite some files (needed for htags)
If you install GLOBAL into other than /usr/bin, you need rewrite
hard coded path in a program. You can find the place by this command.
@ -92,43 +114,33 @@ Install procedure
% grep '/usr/bin/perl' */*.pl
e) POSIX regular expression (extension) library
g) Groff (needed for formatting online manuals)
If you don't have it, you can use GNU's regex library.
Online manuals in GLOBAL are written with 'mandoc' macro which is a part
of GNU groff package. See following site:
f) Some UNIX tools
http://www.gnu.org/order/ftp.html
Find(1), sed(1), sort(1) are needed.
If your environment is UNIX, you have them.
You can format these manuals by following command line manually.
% groff -Wall -Tascii -mandoc global.1
If you replace your system's nroff(1) with GNU's one(nroff.sh) then
you can use man(1) to see GLOBAL's online manuals.
2. GLOBAL basic (NEEDED)
% make
# make install
3. Extended vi (OPTIONAL)
3. Extended nvi (OPTIONAL)
GLOBAL supports two version of nvi.
There is a little defference in behavior between them when a number of
functions located. (please see 'README'.)
Version 1.34 nvi is included by FreeBSD 2.0.5R, 2.1.0R and 2.1.5R.
Version 1.79 nvi is available on
If you use FreeBSD 2.2.2R or later, your nvi is already extended nvi.
Otherwise, please get nvi-1.79 at:
ftp://ftp.cs.berkeley.edu/ucb/4bsd/nvi-1.79.tar.gz.
ftp://ftp.cs.berkeley.edu/ucb/4bsd/nvi-1.79.tar.gz
If you don't have nvi-1.34, use nvi-1.79.
If you use version 1.34 nvi which is a native command in FreeBSD 2.0.5R,
2.1.0R or 2.1.5R then
% cp -r /usr/src/usr.bin/vi vi <- version 1.34 of nex/nvi
% cd vi
% patch -p < ../nvi-1.34.diff
% make
# make install
else if you use version 1.79 nvi which is the latest version then
fetch from ftp://ftp.cs.berkeley.edu/ucb/4bsd/nvi-1.79.tar.gz and
and do the followings.
% tar xzvf nvi-1.79.tar.gz
% cd nvi-1.79
@ -138,10 +150,7 @@ Install procedure
% make
# make install
Caution: If you use FreeBSD 2.2.2R or later, your nvi is already
extended vi. Don't patch with nvi-1.79.diff.
else we have no patch for it.
The patch for nvi-1.66 is also available for NetBSD 1.3.2 users.
4. Extended emacs (OPTIONAL)
@ -149,7 +158,7 @@ Install procedure
Mule 2.3 (= Emacs 19.28). Other emacs version seems to work well,
but I don't confirm it.
You can get it from
You can get it at:
Emacs 19.34b:
ftp://prep.ai.mit.edu/pub/gnu/emacs-19.34b.tar.gz
@ -165,7 +174,16 @@ Install procedure
+-----------------------------------------------
|(setq load-path (cons "~/lisp" load-path))
5. Gozilla (OPTIONAL)
5. Elvis (OPTIONAL)
You need Elvis 2.1. You can get it at:
ftp://ftp.cs.pdx.edu/pub/elvis/elvis-2.1.tar.gz
You need not any patch for it.
6. Gozilla (OPTIONAL)
You need X(1) to install gozilla.
@ -175,4 +193,29 @@ Install procedure
# make install
# make install.man
7. other parser (OPTIONAL)
If you want to use other tag command like etags (tag command for emacs)
as a parser, you need to write global.conf (or $HOME/.globalrc).
Sample gtags.conf has etags's entry. Try this.
a) Install parser.
% cd <emacs's source directory>/lib-src
% make ctags
...
# cp ctags /usr/local/bin/ctags-emacs
b) Select ctags-emacs for GLOBAL system.
% setenv GTAGSLABEL ctags-emacs
or
+------------------------------------------------
|default:\ <== gtags use 'default' entry by default.
| :include=ctags-emacs:include=htags:
Good luck!

View File

@ -1,21 +1,24 @@
COPYING Copyright notice.
FAQ Frequentry asked question.
HISTORY Histroy of GLOBAL.
INSTALL Installation method
MANIFEST This file.
Makefile Makefile for BSD.
Makefile.inc A part of Makefile for BSD.
Makefile.generic Makefile for generic UNIX(including BSD).
PROBLEMS Problem report.
README Readme (introduction and usage).
VERSION Version number.
btreeop/ Btreeop command directory.
global/ Global command directory.
gozilla/ Gozilla command directory.
dbpatches/ Patch files for DB(3).
gctags/ Extended ctags command directory.
global/ Global command directory.
global.conf Configuration file.
gozilla/ Gozilla command directory.
gtags/ Gtags command directory.
gzshrc Gzsh start up file.
htags/ Htags command directory.
systags/ Script for kernel.
lib/ library.
lib/ Private library.
gtags.el Gtags mode for Emacs.
nvi-1.34.diff Patch for nvi 1.34.
nvi-1.66.diff Patch for nvi 1.66.
nvi-1.79.diff Patch for nvi 1.79.

View File

@ -1,7 +1,16 @@
.if !defined(GLOBAL_MAKEFILE_INC_BEEN_HERE)
GLOBAL_MAKEFILE_INC_BEEN_HERE=yes
BINDIR?= /usr/bin
MANDIR?= /usr/share/man/man
.if exists(${.OBJDIR}/../lib)
LIBUTIL=${.OBJDIR}/../lib/libutil.a
LIBDESTDIR= ${.OBJDIR}/../lib
.else
LIBUTIL=${.CURDIR}/../lib/libutil.a
LIBDESTDIR= ${.CURDIR}/../lib
.endif
LDDESTDIR= -L${LIBDESTDIR}
LDADD= -lgloutil
DPADD= ${LIBDESTDIR}/libgloutil.a
CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../lib -O \
-Wall -Wwrite-strings -Wmissing-prototypes
.endif

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
2.24
3.42

View File

@ -1,6 +1,3 @@
PROG= btreeop
CFLAGS+=-I${.CURDIR}/../lib
LDADD= $(LIBUTIL)
DPADD= $(LIBUTIL)
.include <bsd.prog.mk>

View File

@ -28,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd Nov 26, 1997
.Dd Nov 3, 1998
.Dt BTREEOP 1
.Os BSD 4
.Sh NAME
@ -40,7 +40,7 @@
.Op Fl C
.Op Fl D[keyno] Ar key
.Op Fl K[keyno] Ar key
.Op Fl L
.Op Fl L[2]
.Op Fl k Ar prefix
.Op Ar dbname
.Sh DESCRIPTION
@ -66,21 +66,11 @@ create database and write records to it.
delete records by the key. By default, keyno is 0 (primary key).
.It Fl K[keyno] Ar key
search records by the key. By default, keyno is 0 (primary key).
.It Fl L
list all primary keys.
Following two command lines are identical except that the latter is much faster.
btreeop | awk '{print $1}' | uniq
btreeop -L
.It Fl L[2]
list all primary keys. If '2' is specified, list all the key and data pairs.
.It Fl k Ar prefix
scan records which have the prefix as a primary key.
This option is valid only with sequential read operation (-L command or non command).
Following two command lines are identical except that the latter is much faster.
btreeop | awk '$1 ~ /^fo/ {print }'
btreeop -k fo
.It Ar dbname
database name. default is 'btree'.
.Sh DATA FORMAT

View File

@ -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;
}
}

View File

@ -0,0 +1,37 @@
Patch for btree(3)
------------------
Btree(3) core dumps on certain data sets.
if (your system == FreeBSD 2.2.6R or former)
needs this patch.
else if (your system == Debian GNU/Linux 1.3.1)
needs this patch.
else
I don't know.
Please apply patch files in this directory.
1. patch your btree(3) source code
% ls
patch.1.2 patch.1.3 patch.1.4
% set dir=`pwd` <- set current directory
% cd /usr/src/lib/libc/db <- your db source code directory
% cd btree <- btree library
% patch < $dir/patch.1.2 <- it must be in this order.
.
.
% patch < $dir/patch.1.3
.
.
% patch < $dir/patch.1.4
.
.
2. remake and install your db(3) library.
3. remake GLOBAL.
4. remake tag files because tag files are already corrupted.
I derived these patches from 'http://www.sleepycat.com/update/'.
Information is found on 'http://www.sleepycat.com/update/patch.185.html'.

View File

@ -0,0 +1,19 @@
*** btree/bt_split.c Tue Jul 26 14:22:02 1994
--- btree/bt_split.c Sat Jan 4 14:38:55 1997
***************
*** 673,679 ****
* where we decide to try and copy too much onto the left page.
* Make sure that doesn't happen.
*/
! if (skip <= off && used + nbytes >= full) {
--off;
break;
}
--- 673,679 ----
* where we decide to try and copy too much onto the left page.
* Make sure that doesn't happen.
*/
! if (skip <= off && used + nbytes >= full || nxt == top - 1) {
--off;
break;
}

View File

@ -0,0 +1,37 @@
*** btree/bt_split.c.orig Sat Feb 8 10:14:10 1997
--- btree/bt_split.c Sat Feb 8 10:14:51 1997
***************
*** 673,679 ****
* where we decide to try and copy too much onto the left page.
* Make sure that doesn't happen.
*/
! if (skip <= off && used + nbytes >= full || nxt == top - 1) {
--off;
break;
}
--- 673,680 ----
* where we decide to try and copy too much onto the left page.
* Make sure that doesn't happen.
*/
! if (skip <= off &&
! used + nbytes + sizeof(indx_t) >= full || nxt == top - 1) {
--off;
break;
}
***************
*** 686,692 ****
memmove((char *)l + l->upper, src, nbytes);
}
! used += nbytes;
if (used >= half) {
if (!isbigkey || bigkeycnt == 3)
break;
--- 687,693 ----
memmove((char *)l + l->upper, src, nbytes);
}
! used += nbytes + sizeof(indx_t);
if (used >= half) {
if (!isbigkey || bigkeycnt == 3)
break;

View File

@ -0,0 +1,22 @@
*** btree/bt_page.c.orig Wed Jul 13 21:29:02 1994
--- btree/bt_page.c Wed Jun 11 20:14:43 1997
***************
*** 65,70 ****
--- 65,71 ----
h->prevpg = P_INVALID;
h->nextpg = t->bt_free;
t->bt_free = h->pgno;
+ F_SET(t, B_METADIRTY);
/* Make sure the page gets written back. */
return (mpool_put(t->bt_mp, h, MPOOL_DIRTY));
***************
*** 92,97 ****
--- 93,99 ----
(h = mpool_get(t->bt_mp, t->bt_free, 0)) != NULL) {
*npg = t->bt_free;
t->bt_free = h->nextpg;
+ F_SET(t, B_METADIRTY);
return (h);
}
return (mpool_new(t->bt_mp, npg));

File diff suppressed because it is too large Load Diff

92
contrib/global/gctags/C.h Normal file
View File

@ -0,0 +1,92 @@
/*
* 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
* 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 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.
*
* C.h 20-Aug-98
*/
#define DECLARATIONS 0
#define RULES 1
#define PROGRAMS 2
#define C___P 1001
#define C_AUTO 1002
#define C_BREAK 1003
#define C_CASE 1004
#define C_CHAR 1005
#define C_CONTINUE 1006
#define C_DEFAULT 1007
#define C_DO 1008
#define C_DOUBLE 1009
#define C_ELSE 1010
#define C_EXTERN 1011
#define C_FLOAT 1012
#define C_FOR 1013
#define C_GOTO 1014
#define C_IF 1015
#define C_INT 1016
#define C_LONG 1017
#define C_REGISTER 1018
#define C_RETURN 1019
#define C_SHORT 1020
#define C_SIZEOF 1021
#define C_STATIC 1022
#define C_STRUCT 1023
#define C_SWITCH 1024
#define C_TYPEDEF 1025
#define C_UNION 1026
#define C_UNSIGNED 1027
#define C_VOID 1028
#define C_WHILE 1029
#define CP_ELIF 2001
#define CP_ELSE 2002
#define CP_DEFINE 2003
#define CP_IF 2004
#define CP_IFDEF 2005
#define CP_IFNDEF 2006
#define CP_INCLUDE 2007
#define CP_PRAGMA 2008
#define CP_SHARP 2009
#define CP_ERROR 2010
#define CP_UNDEF 2011
#define CP_ENDIF 2012
#define CP_LINE 2013
#define YACC_SEP 3001
#define YACC_BEGIN 3002
#define YACC_END 3003
#define YACC_LEFT 3004
#define YACC_NONASSOC 3005
#define YACC_RIGHT 3006
#define YACC_START 3007
#define YACC_TOKEN 3008
#define YACC_TYPE 3009
#define IS_CTOKEN(c) (c > 1000 && c < 2001)
#define IS_CPTOKEN(c) (c > 2000 && c < 3001)
#define IS_YACCTOKEN(c) (c > 3000 && c < 4001)
#define MAXPIFSTACK 100

View File

@ -1,7 +1,4 @@
PROG= gctags
CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../lib
LDADD= $(LIBUTIL)
DPADD= $(LIBUTIL)
SRCS= C.c ctags.c fortran.c lisp.c print.c tree.c yacc.c assembler.c
SRCS= C.c assembler.c gctags.c java.c
.include <bsd.prog.mk>

View File

@ -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,80 +27,111 @@
* 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.
*
* assembler.c 20-Aug-98
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)assembler.c 8.3 (Berkeley) 6/6/97";
#endif /* LIBC_SCCS and not lint */
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "ctags.h"
#include "lookup.h"
#include "gctags.h"
#include "defined.h"
#include "token.h"
static int reserved __P((char *));
#define A_CALL 1001
#define A_DEFINE 1002
#define A_ENTRY 1003
#define A_EXT 1004
#define A_ALTENTRY 1005
#ifdef GLOBAL
void
asm_entries()
assembler()
{
char *lbp;
char tok[MAXTOKEN];
char *sp;
int c;
int target;
const char *interested = NULL; /* get all token */
int startline = 1;
int level; /* not used */
for (;;) {
lineftell = ftell(inf);
if (!fgets(lbuf, sizeof(lbuf), inf))
return;
++lineno;
if (rflag) {
/* extract only call EXT(xxx) or call _xxx */
lbp = lbuf;
while (*lbp && isspace(*lbp))
lbp++;
if (*lbp != 'c' || strncmp(lbp, "call", 4))
continue;
lbp += 4;
while (*lbp && isspace(*lbp))
lbp++;
sp = tok;
if (!strncmp(lbp, "EXT(" /* ) */, 4)) {
lbp += 4;
while (*lbp && intoken(*lbp))
*sp++ = *lbp++;
if (*lbp != /* ( */ ')')
continue;
*sp = EOS;
} else if (*lbp == '_') {
lbp++;
while (*lbp && intoken(*lbp))
*sp++ = *lbp++;
*sp = EOS;
} else
continue;
if (!lookup(tok))
continue;
} else {
/* extract only ENTRY() and ALTENTRY(). */
if (lbuf[0] != 'E' && lbuf[0] != 'A')
continue;
lbp = lbuf;
if (!strncmp(lbp, "ENTRY(", 6)) {
lbp += 6;
} else if (!strncmp(lbp, "ALTENTRY(", 9)) {
lbp += 9;
} else
continue;
sp = tok;
while (*lbp && intoken(*lbp))
*sp++ = *lbp++;
if (*lbp != /* ( */ ')')
continue;
*sp = EOS;
level = 0; /* to satisfy compiler */
/* symbol search doesn't supported. */
if (sflag)
return;
target = (rflag) ? REF : DEF;
cmode = 1;
crflag = 1;
while ((c = nexttoken(interested, reserved)) != EOF) {
switch (c) {
case '\n':
startline = 1;
continue;
case A_CALL:
if (!startline || target != REF)
break;
if ((c = nexttoken(interested, reserved)) == A_EXT) {
if ((c = nexttoken(interested, reserved)) == '('/* ) */)
if ((c = nexttoken(interested, reserved)) == SYMBOL)
if (defined(token))
PUT(token, lineno, sp);
} else if (c == SYMBOL && *token == '_') {
if (defined(&token[1]))
PUT(&token[1], lineno, sp);
}
break;
case A_ALTENTRY:
case A_ENTRY:
if (!startline || target != DEF)
break;
if ((c = nexttoken(interested, reserved)) == '('/* ) */)
if ((c = nexttoken(interested, reserved)) == SYMBOL)
if (peekc(1) == /* ( */ ')')
PUT(token, lineno, sp);
break;
case A_DEFINE:
if (!startline || target != DEF)
break;
if ((c = nexttoken(interested, reserved)) == SYMBOL) {
if (peekc(1) == '('/* ) */) {
PUT(token, lineno, sp);
while ((c = nexttoken(interested, reserved)) != EOF && c != '\n' && c != /* ( */ ')')
;
while ((c = nexttoken(interested, reserved)) != EOF && c != '\n')
;
}
}
default:
}
getline();
pfnote(tok, lineno);
startline = 0;
}
/*NOTREACHED*/
}
#endif
static int
reserved(word)
char *word;
{
switch (*word) {
case '#':
if (!strcmp(word, "#define"))
return A_DEFINE;
break;
case 'A':
if (!strcmp(word, "ALTENTRY"))
return A_ALTENTRY;
break;
case 'E':
if (!strcmp(word, "ENTRY"))
return A_ENTRY;
else if (!strcmp(word, "EXT"))
return A_EXT;
break;
case 'c':
if (!strcmp(word, "call"))
return A_CALL;
break;
}
return SYMBOL;
}

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1987, 1990, 1993
.\" 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
@ -11,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,109 +28,67 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)gctags.1 8.1 (Berkeley) 6/6/93
.\"
.Dd April 21, 1997
.Dd Aug 19, 1998
.Dt GCTAGS 1
.Os BSD 4
.Sh NAME
.Nm gctags
.Nd create a tags file (special command for GLOBAL)
.Nd print cross reference list for gtags.
.Sh SYNOPSIS
.Nm gctags
.Op Fl BDFacderstuvwx
.Op Fl f Ar tagsfile
.Ar name ...
.Op Fl b
.Op Fl e
.Op Fl n
.Op Fl r
.Op Fl s
.Op Fl w
.Ar file ...
.Sh DESCRIPTION
.Nm Gctags
makes a tags file for
.Xr ex 1
print cross reference list for
.Xr gtags 1
from the specified C,
Pascal, Fortran,
.Tn YACC ,
lex, lisp and assembler sources.
A tags file gives the locations of specified objects in a group of files.
Each line of the tags file contains the object name, the file in which it
is defined, and a search pattern for the object definition, separated by
.Tn JAVA ,
and assembler source to standard output.
Each line of output contains the object name, the line number which it appears,
the file in which it is defined, and a line image separated by
white-space.
Using the
.Ar tags
file,
.Xr ex 1
can quickly locate these object definitions.
It's same with the output of
.Xr ctags 1
with -x option.
.Pp
Depending upon the options provided to
.Nm gctags ,
objects will consist of subroutines, typedefs, defines, structs,
enums and unions.
objects will consist of function definitions, function references and other
symbols.
This command is the default parser of GLOBAL source code tag system.
.Bl -tag -width Ds
.It Fl B
use backward searching patterns
.Pq Li ?...? .
.It Fl D
allow duplicate object names.
.It Fl F
use forward searching patterns
.Pq Li /.../
(the default).
.It Fl a
append to
.Ar tags
file.
.It Fl c
print with compact format. It is valid only with -x option.
.It Fl d
create tags for
.Li #defines
that don't take arguments;
.Li #defines
that take arguments are tagged automatically.
.It Fl b
force level 1 block to begin when reach a '{' at the first column. (C only)
.It Fl e
force a function to end when reach a '}' at the first column. (C source only)
.It Fl f
place the tag descriptions in a file called
.Ar tagsfile .
The default behaviour is to place them in a file called
.Ar tags .
force level 1 block to end when reach a '}' at the first column. (C only)
.It Fl n
suppress output of tags. It is useful to use with
.Fl w
option.
.It Fl r
locate function references instead of function definitions. GTAGS file is
needed at the current directory. (C source only)
needed at the current directory. (C and Java source only)
By default, locate function definitions.
.It Fl s
collect symbols except for functions.
.It Fl t
create tags for typedefs, structs, unions, and enums.
.It Fl u
update the specified files in the
.Ar tags
file, that is, all
references to them are deleted, and the new values are appended to the
file. (Beware: this option is implemented in a way which is rather
slow; it is usually faster to simply rebuild the
.Ar tags
file.)
.It Fl v
An index of the form expected by
.Xr vgrind 1
is produced on the standard output. This listing
contains the object name, file name, and page number (assuming 64
line pages). Since the output will be sorted into lexicographic order,
it may be desired to run the output through
.Xr sort 1 .
Sample use:
.Bd -literal -offset indent
gctags \-v files \&| sort \-f > index
vgrind \-x index
.Ed
collect symbols other than functions. By default, locate function definitions.
.It Fl w
suppress warning diagnostics.
.It Fl x
.Nm gctags
produces a list of object
names, the line number and file name on which each is defined, as well
as the text of that line and prints this on the standard output. This
is a simple index which can be printed out as an off-line readable
function index.
print warning message.
.El
.Pp
The
.Fl r
and
.Fl s
options override each other; the last one specified determines the method used.
.Pp
Files whose names end in
.Nm \&.c
or
@ -144,47 +101,19 @@ are assumed to be
.Tn YACC
source files.
Files whose names end in
.Nm \&.l
are assumed to be lisp files if their
first non-blank character is `;', `(', or `[',
otherwise, they are
treated as lex files.
.Nm \&.java
are assumed to be Java source files.
Files whose names end in
.Nm \&.s
or
.Nm \&.S
are assumed to be Assembler
source files. Other files are first examined to see if they
contain any Pascal or Fortran routine definitions, and, if not, are
searched for C style definitions.
source files. Other files are searched for C style definitions.
.Pp
The tag
.Li main
is treated specially in C programs. The tag formed
is created by prepending
.Ar M
to the name of the file, with the
trailing
.Nm \&.c
and any leading pathname components removed. This
makes use of
.Nm gctags
practical in directories with more than one
program.
.Pp
Yacc and lex files each have a special tag.
Yacc files each have a special tag.
.Ar Yyparse
is the start
of the second section of the yacc file, and
.Ar yylex
is the start of
the second section of the lex file.
.Sh FILES
.Bl -tag -width tags -compact
.It Pa tags
default output tags file
.It Pa GTAGS
tags file for GLOBAL
of the second section of the yacc file.
.El
.Sh DIAGNOSTICS
.Nm Gctags
@ -199,42 +128,15 @@ Duplicate objects are not considered errors.
.Xr vi 1 .
.Sh BUGS
.Pp
Recognition of
.Nm functions ,
.Nm subroutines
and
.Nm procedures
for
.Tn FORTRAN
and Pascal is done is a very simpleminded way. No attempt
is made to deal with block structure; if you have two Pascal procedures
in different blocks with the same name you lose.
.Nm Gctags
doesn't
understand about Pascal types.
.Pp
The method of deciding whether to look for C, Pascal or
.Tn FORTRAN
functions is a hack.
.Pp
.Nm Gctags
relies on the input being well formed, and any syntactical
errors will completely confuse it. It also finds some legal syntax
confusing; for example, since it doesn't understand
.Li #ifdef Ns 's
(incidentally, that's a feature, not a bug), any code with unbalanced
braces inside
.Li #ifdef Ns 's
will cause it to become somewhat disoriented.
In a similar fashion, multiple line changes within a definition will
cause it to enter the last line of the object, rather than the first, as
the searching pattern. The last line of multiple line
.Li typedef Ns 's
will similarly be noted.
errors will completely confuse it.
.Pp
Assembler support is far from completeness. It extracts only ENTRY()
Assembler support is far from complete. It extracts only ENTRY()
and ALTENTRY() from source file. Probably valid only for FreeBSD and Linux
kernel source.
.Sh AUTHORS
Shigio Yamaguchi (shigio@wafu.netgate.net)
.Sh HISTORY
The
.Nm

View File

@ -0,0 +1,181 @@
/*
* Copyright (c) 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
* 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 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.
*
* gctags.c 13-Sep-98
*/
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "global.h"
#include "gctags.h"
int bflag; /* -b: force level 1 block start */
int dflag; /* -d: debug */
int eflag; /* -e: force level 1 block end */
int nflag; /* -n: doen't print tag */
int rflag; /* -r: function reference */
int sflag; /* -s: collect symbols */
int wflag; /* -w: warning message */
int yaccfile; /* yacc file */
const char *progname = "gctags"; /* program name */
char *notfunction;
int main __P((int, char **));
static void usage __P((void));
struct words *words;
static int tablesize;
int
main(argc, argv)
int argc;
char **argv;
{
char *p;
while (--argc > 0 && (++argv)[0][0] == '-') {
for (p = argv[0] + 1; *p; p++) {
switch(*p) {
case 'b':
bflag++;
break;
case 'd':
dflag++;
break;
case 'e':
eflag++;
break;
case 'n':
nflag++;
break;
case 'r':
rflag++;
sflag = 0;
break;
case 's':
sflag++;
rflag = 0;
break;
case 'w':
wflag++;
break;
default:
usage();
}
}
}
if (argc < 1)
usage();
if (getenv("GTAGSWARNING"))
wflag++;
if (test("r", NOTFUNCTION)) {
FILE *ip;
STRBUF *sb = stropen();
int i;
if ((ip = fopen(NOTFUNCTION, "r")) == 0)
die1("'%s' cannot read.", NOTFUNCTION);
for (tablesize = 0; (p = mgets(ip, NULL, 0)) != NULL; tablesize++)
strnputs(sb, p, strlen(p) + 1);
fclose(ip);
if ((words = malloc(sizeof(struct words) * tablesize)) == NULL)
die("short of memory.");
p = strvalue(sb);
for (i = 0; i < tablesize; i++) {
words[i].name = p;
p += strlen(p) + 1;
}
qsort(words, tablesize, sizeof(struct words), cmp);
/* don't call strclose(sb); */
}
for (; argc > 0; argv++, argc--) {
if (!opentoken(argv[0]))
die1("'%s' cannot open.", argv[0]);
if (locatestring(argv[0], ".y", MATCH_AT_LAST))
C(1);
else if (locatestring(argv[0], ".s", MATCH_AT_LAST) ||
locatestring(argv[0], ".S", MATCH_AT_LAST))
assembler();
else if (locatestring(argv[0], ".java", MATCH_AT_LAST))
java();
else
C(0);
closetoken();
}
exit(0);
}
static void
usage()
{
(void)fprintf(stderr, "usage: gctags [-benrsw] file ...\n");
exit(1);
}
int
cmp(s1, s2)
const void *s1, *s2;
{
return strcmp(((struct words *)s1)->name, ((struct words *)s2)->name);
}
int
isnotfunction(name)
char *name;
{
struct words tmp;
struct words *result;
if (words == NULL)
return 0;
tmp.name = name;
result = (struct words *)bsearch(&tmp, words, tablesize, sizeof(struct words), cmp);
return (result != NULL) ? 1 : 0;
}
#ifdef DEBUG
void
dbg_print(level, s)
int level;
const char *s;
{
if (!dflag)
return;
fprintf(stderr, "[%04d]", lineno);
for (; level > 0; level--)
fprintf(stderr, " ");
fprintf(stderr, "%s\n", s);
}
#endif

View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 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
* 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 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.
*
* gctags.h 17-Oct-98
*/
#include <sys/param.h>
#include "token.h"
/*
* target type.
*/
#define DEF 1
#define REF 2
#define SYM 3
#define NOTFUNCTION ".notfunction"
extern int bflag;
extern int dflag;
extern int eflag;
extern int nflag;
extern int rflag;
extern int sflag;
extern int wflag;
extern int yaccfile;
struct words {
const char *name;
int val;
};
#define PUT(tag, lno, line) { \
DBG_PRINT(level, line); \
if (!nflag) { \
if (strlen(tag) >= 16 && lno >= 1000) \
printf("%-16s %4d %-16s %s\n", \
tag, lno, curfile, line); \
else \
printf("%-16s%4d %-16s %s\n", \
tag, lno, curfile, line); \
} \
}
#define IS_RESERVED(a) ((a) > 255)
#ifndef __P
#ifdef __STDC__
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
#ifdef DEBUG
void dbg_print __P((int, const char *));
#define DBG_PRINT(level, a) dbg_print(level, a)
#else
#define DBG_PRINT(level, a)
#endif
int isnotfunction __P((char *));
int cmp __P((const void *, const void *));
void C __P((int));
void assembler __P((void));
void java __P((void));

View File

@ -0,0 +1,240 @@
/*
* Copyright (c) 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
* 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 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.
*
* java.c 2-Sep-98
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gctags.h"
#include "defined.h"
#include "die.h"
#include "java.h"
#include "token.h"
static int reserved __P((char *));
/*
* java: read java file and pickup tag entries.
*/
void
java()
{
int c;
int level; /* brace level */
int target;
int startclass, startthrows, startequal;
char classname[MAXTOKEN];
char completename[MAXCOMPLETENAME];
int classlevel;
struct {
char *classname;
char *terminate;
int level;
} stack[MAXCLASSSTACK];
const char *interested = "{}=;";
stack[0].terminate = completename;
stack[0].level = 0;
level = classlevel = 0;
target = (sflag) ? SYM : ((rflag) ? REF : DEF);
startclass = startthrows = startequal = 0;
while ((c = nexttoken(interested, reserved)) != EOF) {
switch (c) {
case SYMBOL: /* symbol */
for (; c == SYMBOL && peekc(1) == '.'; c = nexttoken(interested, reserved)) {
if (target == SYM)
PUT(token, lineno, sp);
}
if (c != SYMBOL)
break;
if (startclass || startthrows) {
if (target == REF && defined(token))
PUT(token, lineno, sp);
} else if (peekc(0) == '('/* ) */) {
if (target == DEF && level == stack[classlevel].level && !startequal)
/* ignore constructor */
if (strcmp(stack[classlevel].classname, token))
PUT(token, lineno, sp);
if (target == REF && (level > stack[classlevel].level || startequal) && defined(token))
PUT(token, lineno, sp);
} else {
if (target == SYM)
PUT(token, lineno, sp);
}
break;
case '{': /* } */
DBG_PRINT(level, "{"); /* } */
++level;
if (startclass) {
char *p = stack[classlevel].terminate;
char *q = classname;
if (++classlevel >= MAXCLASSSTACK)
die1("class stack over flow.[%s]", curfile);
if (classlevel > 1)
*p++ = '.';
stack[classlevel].classname = p;
while (*q)
*p++ = *q++;
stack[classlevel].terminate = p;
stack[classlevel].level = level;
*p++ = 0;
}
startclass = startthrows = 0;
break;
/* { */
case '}':
if (--level < 0) {
if (wflag)
fprintf(stderr, "Warning: missing left '{' (at %d).\n", lineno); /* } */
level = 0;
}
if (level < stack[classlevel].level)
*(stack[--classlevel].terminate) = 0;
/* { */
DBG_PRINT(level, "}");
break;
case '=':
startequal = 1;
break;
case ';':
startclass = startthrows = startequal = 0;
break;
case J_CLASS:
case J_INTERFACE:
if ((c = nexttoken(interested, reserved)) == SYMBOL) {
strcpy(classname, token);
startclass = 1;
if (target == DEF)
PUT(token, lineno, sp);
}
break;
case J_NEW:
case J_INSTANCEOF:
while ((c = nexttoken(interested, reserved)) == SYMBOL && peekc(1) == '.')
if (target == SYM)
PUT(token, lineno, sp);
if (c == SYMBOL)
if (target == REF && defined(token))
PUT(token, lineno, sp);
break;
case J_THROWS:
startthrows = 1;
break;
case J_BOOLEAN:
case J_BYTE:
case J_CHAR:
case J_DOUBLE:
case J_FLOAT:
case J_INT:
case J_LONG:
case J_SHORT:
case J_VOID:
if (peekc(1) == '.' && (c = nexttoken(interested, reserved)) != J_CLASS)
pushbacktoken();
break;
default:
}
}
}
/* sorted by alphabet */
static struct words words[] = {
{"abstract", J_ABSTRACT},
{"boolean", J_BOOLEAN},
{"break", J_BREAK},
{"byte", J_BYTE},
{"case", J_CASE},
{"catch", J_CATCH},
{"char", J_CHAR},
{"class", J_CLASS},
{"const", J_CONST},
{"continue", J_CONTINUE},
{"default", J_DEFAULT},
{"do", J_DO},
{"double", J_DOUBLE},
{"else", J_ELSE},
{"extends", J_EXTENDS},
{"false", J_FALSE},
{"final", J_FINAL},
{"finally", J_FINALLY},
{"float", J_FLOAT},
{"for", J_FOR},
{"goto", J_GOTO},
{"if", J_IF},
{"implements", J_IMPLEMENTS},
{"import", J_IMPORT},
{"instanceof", J_INSTANCEOF},
{"int", J_INT},
{"interface", J_INTERFACE},
{"long", J_LONG},
{"native", J_NATIVE},
{"new", J_NEW},
{"null", J_NULL},
{"package", J_PACKAGE},
{"private", J_PRIVATE},
{"protected", J_PROTECTED},
{"public", J_PUBLIC},
{"return", J_RETURN},
{"short", J_SHORT},
{"static", J_STATIC},
{"strictfp", J_STRICTFP},
{"super", J_SUPER},
{"switch", J_SWITCH},
{"synchronized",J_SYNCHRONIZED},
{"this", J_THIS},
{"throw", J_THROW},
{"throws", J_THROWS},
{"union", J_UNION},
{"transient", J_TRANSIENT},
{"true", J_TRUE},
{"try", J_TRY},
{"void", J_VOID},
{"volatile", J_VOLATILE},
{"while", J_WHILE},
{"widefp", J_WIDEFP},
};
static int
reserved(word)
char *word;
{
struct words tmp;
struct words *result;
tmp.name = word;
result = (struct words *)bsearch(&tmp, words, sizeof(words)/sizeof(struct words), sizeof(struct words), cmp);
return (result != NULL) ? result->val : SYMBOL;
}

View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 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
* 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 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.
*
* java.h 20-Aug-98
*/
/*
* java's reserved words.
*/
#define J_ABSTRACT 1001
#define J_BOOLEAN 1002
#define J_BREAK 1003
#define J_BYTE 1004
#define J_CASE 1005
#define J_CATCH 1006
#define J_CHAR 1007
#define J_CLASS 1008
#define J_CONST 1009
#define J_CONTINUE 1010
#define J_DEFAULT 1011
#define J_DO 1012
#define J_DOUBLE 1013
#define J_ELSE 1014
#define J_EXTENDS 1015
#define J_FALSE 1016
#define J_FINAL 1017
#define J_FINALLY 1018
#define J_FLOAT 1019
#define J_FOR 1020
#define J_GOTO 1021
#define J_IF 1022
#define J_IMPLEMENTS 1023
#define J_IMPORT 1024
#define J_INSTANCEOF 1025
#define J_INT 1026
#define J_INTERFACE 1027
#define J_LONG 1028
#define J_NATIVE 1029
#define J_NEW 1030
#define J_NULL 1031
#define J_PACKAGE 1032
#define J_PRIVATE 1033
#define J_PROTECTED 1034
#define J_PUBLIC 1035
#define J_RETURN 1036
#define J_SHORT 1037
#define J_STATIC 1038
#define J_SUPER 1039
#define J_SWITCH 1040
#define J_SYNCHRONIZED 1041
#define J_THIS 1042
#define J_THROW 1043
#define J_THROWS 1044
#define J_UNION 1045
#define J_TRANSIENT 1046
#define J_TRUE 1047
#define J_TRY 1048
#define J_VOID 1049
#define J_VOLATILE 1050
#define J_WHILE 1051
#define J_STRICTFP 1052
#define J_WIDEFP 1053
#define MAXCOMPLETENAME 1024 /* max size of complete name of class */
#define MAXCLASSSTACK 10 /* max size of class stack */

157
contrib/global/global.conf Normal file
View File

@ -0,0 +1,157 @@
#
# Copyright (c) 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
# 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.
#
# Configuration file for GLOBAL source code tag system.
#
# Copy this file as /etc/global.conf or $HOME/.globalrc and GLOBAL system
# use it.
#
# 'default' is default target.
# You can specify target with GTAGSLABEL environment variable.
#
# include:
# It's similar to 'tc=' in termcap but can be used anytime and anywhere.
# 8 level nested usage is allowed.
#
default:\
:include=gctags:include=htags:
#---------------------------------------------------------------------
#
# Configuration for gtags(1)
#
# format:
# Select 'standard' or 'compact'. By default, it assumes 'standard'.
# suffixes:
# Suffixes of target source file. By default, 'c,h,y,s,S,java'.
# skip:
# Skip files among the target files. If the name ends with '/',
# gtags skips all files under the directory.
# By default, 'y.tab.c,y.tab.h,SCCS/,RCS/,CVS/'.
# extractmethod:
# Please see source code of gtags(1).
# GTAGS:
# Tag command for definitions. Non of default value.
# GRTAGS:
# Tag command for references. Non of default value.
# GSYMS:
# Tag command for other symbols. Non of default value.
#
# Htags(1) needs both of GTAGS and GRTAGS. Global(1)'s -s option needs GSYMS.
#
#---------------------------------------------------------------------
common:\
:skip=y.tab.c,y.tab.h,SCCS/,RCS/,CVS/:\
:format=standard:
#
# [gctags]
#
# This command is distributed as part of GLOBAL.
#
gctags|tag command for GLOBAL:\
:include=common:\
:suffixes=c,h,y,s,S,java:\
:GTAGS=gctags %s:\
:GRTAGS=gctags -r %s:\
:GSYMS=gctags -s %s:
#
# [Emacs's ctags]
#
# This ctags is distributed as a part of Emacs editor.
#
# supported suffixes by etags.
#
# lisp: l,el,lsp,lisp,cl,clisp
# scheme: sm,scm,scheme,t,sch,ss,SM,SCM
# assembler: s,a,sa,asm,src,def,ins,inc
# C++: C,H,cpp,cxx,hxx,cc
# C*: cs,hs
# c,yacc: c,h,y
# pl,p,pas: pascal
# fortran: f,for
#
# [Installation]
# % cd <emacs source directory>/lib-src
# % make ctags
# # cp ctags /usr/local/bin/ctags-emacs
#
ctags-emacs|ctags based on etags|GNU Emacs ctags:\
:include=common:\
:suffixes=el,s,a,sa,asm,C,H,cpp,cxx,hxx,cc,c,h,y:\
:skip=ispell.el,canna.el,gnusutil.el:\
:extractmethod:\
:GTAGS=/usr/local/bin/ctags-emacs -x -d -T -w %s:
#
# [Exuberant Ctags]
#
# This ctags is distributed as a part of Vim editor.
#
# [Installation]
# % cd <Vim source directory>/src/ctags
# % make
# # cp ctags /usr/local/bin/ctags-exuberant
#
ctags-exuberant|Exuberant Ctags|ctags by Darren Hiebert:\
:include=common:\
:suffixes=s,a,sa,asm,C,H,cpp,cxx,hxx,cc,c,h,y:\
:extractmethod:\
:GTAGS=/usr/local/bin/ctags-exuberant -x %s | perl -ne '($name, $type, $no, $path, $line) = split(/[ \t]+/, $_, 5); printf(STDOUT "%-16s %4d %-16s %s", $name, $no, $path, $line);':
#---------------------------------------------------------------------
#
# Configuration for htags(1)
# Let's paint hypertext with your favorite colors!
#
# bgcolor,text,link,vlink,alink:
# attribute of <BODY>. (default is not set)
# title_begin,title_end:
# title tag
# comment_begin,comment_end:
# comment tag. (/* ... */, // ...)
# sharp_begin,sharp_end:
# macro tag. (#include, #define, ...)
# brace_begin,brace_end:
# brace tag. ('{', '}')
# reserved_begin,reserved_end:
# reserved word tag. (while, if, char, ...)
# ncol:
# columns of line number. (default = 4)
# tabs:
# tab stop. (default = 8)
# gzipped_suffix:
# suffix of compressed html file.
#
#---------------------------------------------------------------------
htags:\
:bgcolor=silver:text=black:link=blue:vlink=red:alink=cyan:\
:title_begin=<FONT COLOR=#cc0000>:title_end=</FONT>:\
:comment_begin=<I><FONT COLOR=green>:comment_end=</FONT></I>:\
:sharp_begin=<FONT COLOR=darkred>:sharp_end=</FONT>:\
:brace_begin=<FONT COLOR=blue>:brace_end=</FONT>:\
:reserved_begin=<B>:reserved_end=</B>:\
:ncol#4:tabs#8:gzipped_suffix=ghtml:

View File

@ -1,6 +1,3 @@
PROG= global
CFLAGS+=-I${.CURDIR}/../lib
LDADD= $(LIBUTIL)
DPADD= $(LIBUTIL)
.include <bsd.prog.mk>

View File

@ -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.
.\"
.Dd Nov 26, 1997
.Dd Dec 8, 1998
.Dt GLOBAL 1
.Os BSD 4
.Sh NAME
@ -36,26 +36,29 @@
.Nd print the locations of specified object.
.Sh SYNOPSIS
.Nm global
.Op Fl alrvx
.Op Fl alnrtvx
.Ar pattern
.Nm global -c
.Op Ar prefix
.Nm global
.Fl f[arx]
.Ar file
.Fl f[anrtx]
.Ar files
.Nm global
.Fl g[alvx]
.Fl g[alntvx]
.Ar pattern
.Nm global
.Fl i[v]
.Nm global
.Fl p
.Nm global
.Fl s[alvx]
.Fl P[alnt]
.Op Ar pattern
.Nm global
.Fl s[alntvx]
.Ar pattern
.Sh DESCRIPTION
.Nm Global
find the locations of specified object in C and Yacc source files.
find the locations of specified object in C, Yacc and Java source files.
.Nm Global
can treat a source tree, that is, a directory that has subdirectories and
source files.
@ -71,38 +74,53 @@ at the root directory of the source tree to make tag files.
Then you can execute
.Nm
at anywhere in the source tree.
.Pp
The following options are available:
.Sh COMMANDS
The following commands are available:
.Bl -tag -width Ds
.It Ar pattern
object pattern. It can include POSIX 1003.2 regular expression.
.It Fl a
print absolute path name. By default, print relative path name.
print object which match to the
.Ar pattern .
It can include POSIX 1003.2 regular expression.
.It Fl c Op Ar prefix
print candidate function names which start with specified
.Ar prefix .
If
.Ar prefix
is not specified, print all function names.
.It Fl f Ar file
.It Fl f Ar files
print all function definitions in the
.Ar file .
.Ar files .
This option implies -x option.
.It Fl g
print all lines which match to the pattern.
.It Fl g Ar pattern
print all lines which match to the
.Ar pattern .
It is similar to grep(1).
.It Fl i
reconstruct tags files incrementally.
.It Fl l
print objects which exist under the current directory.
.It Fl r
print the locations of function references. By default, print function
definitions.
locate tag files and reconstruct them incrementally.
.It Fl p
print the location of GTAGS.
.It Fl s
.It Fl P Op Ar pattern
print the path which match to the
.Ar pattern .
If no pattern specified, print all.
.It Fl s Ar pattern
print the locations of specified symbol other than function names.
You need GSYMS tags file. See
.Xr gtags 1 .
.Sh OPTIONS
The following options are available:
.Bl -tag -width Ds
.It Fl a
print absolute path name. By default, print relative path name.
.It Fl l
print just objects which exist under the current directory.
.It Fl n
suppress sort filter and path conversion filter.
.It Fl r
print the locations of object references. By default, print object
definitions.
.It Fl t
print with standard ctags format.
.It Fl x
In addition to the default output, produce the line number and
the line contents.
@ -114,6 +132,8 @@ tags file for function definitions.
tags file for function references.
.It Pa GSYMS
tags file for symbols other then functions.
.It Pa GPATH
path index. This is used for incremental updating and compact format.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of global.

File diff suppressed because it is too large Load Diff

View File

@ -2,11 +2,23 @@ XCOMM
XCOMM Imakefile for gozilla
XCOMM
LOCAL_LIBRARIES = XawClientLibs -L../lib -lutil
DEPLIBS = XawClientDepLibs ../lib/libutil.a
DEFINES = -DSTANDALONE -DGLOBAL -I../lib
INC = ../lib
LOCAL_LIBRARIES = XawClientLibs
DEPLIBS = XawClientDepLibs
DEFINES = -DSTANDALONE -DGLOBAL -I$(INC)
SRCS = gozilla.c remote.c
OBJS = gozilla.o remote.o
SRCS = gozilla.c remote.c test.c getdbpath.c strbuf.c conf.c \
mgets.c locatestring.c makepath.c strmake.c
OBJS = gozilla.o remote.o test.o getdbpath.o strbuf.o conf.o \
mgets.o locatestring.o makepath.o strmake.o
LinkSourceFile(test.c,$(INC))
LinkSourceFile(getdbpath.c,$(INC))
LinkSourceFile(strbuf.c,$(INC))
LinkSourceFile(conf.c,$(INC))
LinkSourceFile(mgets.c,$(INC))
LinkSourceFile(locatestring.c,$(INC))
LinkSourceFile(makepath.c,$(INC))
LinkSourceFile(strmake.c,$(INC))
ComplexProgramTarget(gozilla)

View File

@ -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.
*
* gozilla.c 27-Oct-97
* gozilla.c 17-Jul-98
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "global.h"
char *progname = "gozilla"; /* command name */
const char *progname = "gozilla"; /* command name */
static void usage __P((void));
void main __P((int, char **));
int main __P((int, char **));
int issource __P((char *));
int sendcommand __P((char *));
int bflag;
@ -54,17 +57,17 @@ usage()
exit(1);
}
void
int
main(argc, argv)
int argc;
char *argv[];
{
char c, *p, *q;
char *browser = (char *)0;
char *command = (char *)0;
char *arg = (char *)0;
char *browser = NULL;
char *command = NULL;
char *arg = NULL;
char URL[MAXPATHLEN+1];
char com[MAXCOMLINE+1];
char com[MAXFILLEN+1];
int linenumber = 0;
int status;
@ -101,16 +104,19 @@ char *argv[];
}
if (argc == 0)
usage();
if (locatestring(argv[0], "http:", 1) || locatestring(argv[0], "file:", 1))
if (locatestring(argv[0], "http:", MATCH_AT_FIRST) ||
locatestring(argv[0], "ftp:", MATCH_AT_FIRST) ||
locatestring(argv[0], "news:", MATCH_AT_FIRST) ||
locatestring(argv[0], "mail:", MATCH_AT_FIRST) ||
locatestring(argv[0], "file:", MATCH_AT_FIRST))
strcpy(URL, argv[0]);
else {
char *abspath;
char pathbuf[MAXPATHLEN+1];
char htmlpath[MAXPATHLEN+1];
char buf[MAXPATHLEN+1];
if (!test("f", argv[0]) && !test("d", argv[0]))
if (!test("f", argv[0]) && !test("d", NULL))
die1("path '%s' not found.", argv[0]);
if (!(abspath = realpath(argv[0], pathbuf)))
if (!(abspath = realpath(argv[0], buf)))
die1("cannot make absolute path name. realpath(%s) failed.", argv[0]);
if (*abspath != '/')
die("realpath(3) is not compatible with BSD version.");
@ -152,7 +158,7 @@ char *argv[];
/*
* execute generic browser.
*/
if (browser && !locatestring(browser, "netscape", 3)) {
if (browser && !locatestring(browser, "netscape", MATCH_AT_LAST)) {
sprintf(com, "%s '%s'", browser, URL);
system(com);
exit (0);
@ -171,7 +177,7 @@ char *argv[];
if ((pid = fork()) < 0) {
die("cannot execute netscape (fork).");
} else if (pid == 0) {
execlp("netscape", "netscape", URL, (char *)0);
execlp("netscape", "netscape", URL, NULL);
die("loading mozilla failed.");
}
exit(0);
@ -179,6 +185,34 @@ char *argv[];
exit(status);
}
int
issource(path)
char *path;
{
STRBUF *sb = stropen();
char *p;
char suff[MAXPATHLEN+1];
int retval = 0;
if (!getconfs("suffixes", sb)) {
strclose(sb);
return 0;
}
suff[0] = '.';
for (p = strvalue(sb); p; ) {
char *unit = p;
if ((p = locatestring(p, ",", MATCH_FIRST)) != NULL)
*p++ = 0;
strcpy(&suff[1], unit);
if (locatestring(path, suff, MATCH_AT_LAST)) {
retval = 1;
break;
}
}
strclose(sb);
return retval;
}
int
sendcommand(com)
char *com;
{
@ -188,7 +222,7 @@ char *com;
argv[0] = "netscape-remote";
argv[1] = "-remote";
argv[2] = com;
argv[3] = (char *)0;
argv[3] = NULL;
return netscape_remote(argc, argv);
}

View File

@ -139,3 +139,7 @@ can treat not only source file but also normal file, directory, HTML file
and even URL, because it is omnivorous.
.Sh AUTHORS
Shigio Yamaguchi (shigio@wafu.netgate.net)
.Sh HISTORY
The
.Nm
command appeared in FreeBSD 2.2.5.

View File

@ -586,7 +586,7 @@ usage (void)
int
netscape_remote(int argc, char **argv)
#else
void
int
main (int argc, char **argv)
#endif
{

View File

@ -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))

View File

@ -1,6 +1,3 @@
PROG= gtags
CFLAGS+=-I${.CURDIR}/../lib
LDADD= $(LIBUTIL)
DPADD= $(LIBUTIL)
.include <bsd.prog.mk>

View File

@ -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,26 +28,28 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd Sep 12, 1997
.Dd Oct 10, 1998
.Dt GTAGS 1
.Os BSD 4
.Sh NAME
.Nm gtags
.Nd create GTAGS, GRTAGS and GSYMS file
.Nd create tag files for global.
.Sh SYNOPSIS
.Nm gtags
.Op Fl c
.Op Fl i
.Op Fl o
.Op Fl w
.Op Fl v
.Op Ar dbpath
.Sh DESCRIPTION
.Nm Gtags
makes GTAGS, GRTAGS and GSYMS file for
makes GTAGS, GRTAGS, GSYMS and GPATH file for
.Xr global 1 .
.Nm Gtags
trace subdirectories, read source files,
locate symbols and save the information into tag files.
C, yacc and assembler source files are supported.
C, yacc, java and assembler source files are supported.
You should execute this command at the root of the source tree.
.Pp
If your source directory is on a read only device like CDROM, specify
@ -55,13 +57,16 @@ If your source directory is on a read only device like CDROM, specify
of the directory on which make tag files.
.Pp
.Bl -tag -width Ds
.It Fl c
make tag files with compact format.
.It Fl i
update tag files incrementally by files which modified after the tag files were
last updated.
update tag files incrementally.
.It Fl o
suppress making GSYMS file.
Use this option if you don't use -s option of
.Xr global 1 .
.It Fl w
print warning messages.
.It Fl v
verbose mode.
.Sh FILES
@ -72,6 +77,8 @@ tag file for function definitions.
tag file for function references.
.It Pa GSYMS
tag file for other symbols.
.It Pa GPATH
path index file which is used for incremental updating and compact format.
.El
.Sh DIAGNOSTICS
.Nm Gtags
@ -85,7 +92,7 @@ exits with a non 0 value if an error occurred, 0 otherwise.
GTAGS, GRTAGS and GSYMS are very large.
In advance of using this command, check the space of your disk.
.br
Assembler support is far from completeness. It extracts only ENTRY()
Assembler support is far from complete. It extracts only ENTRY()
and ALTENTRY() from source file. Probably valid only for FreeBSD and Linux
kernel source.
.br

View File

@ -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,60 +28,105 @@
* 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>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#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;
@ -94,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)
@ -126,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);
@ -161,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;
}
pclose(ip);
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);
}
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;
}

View File

@ -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
Tile 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.

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,9 @@
LIB= util
SRCS= tag.o tab.o strop.o mgets.o lookup.o gtagsopen.o getdbpath.o \
find.o dbname.o dbio.o test.o makepath.o locatestring.o
NOPROFILE= yes
install:
@echo -n
LIB= gloutil
SRCS= gtagsop.c tab.c strbuf.c mgets.c defined.c getdbpath.c \
find.c dbop.c test.c makepath.c locatestring.c pathop.c \
conf.c strmake.c usable.c token.c
NOPROFILE= noprofile
INTERNALLIB= true
INTERNALSTATICLIB= true
.include <bsd.lib.mk>

308
contrib/global/lib/conf.c Normal file
View File

@ -0,0 +1,308 @@
/*
* 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
* 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.
*
* conf.c 30-Jun-98
*
*/
#include <sys/param.h>
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "conf.h"
#include "die.h"
#include "gparam.h"
#include "locatestring.h"
#include "makepath.h"
#include "mgets.h"
#include "strbuf.h"
#include "strmake.h"
#include "test.h"
/*
* Access library for gtags.conf (.gtagsrc).
* File format is a subset of XXXcap (termcap, printcap) file.
*/
#define GTAGSCONF "/etc/global.conf"
#define GTAGSRC ".globalrc"
#define DEFAULTLABEL "default"
static FILE *fp;
static char *line;
static int allowed_nest_level = 8;
static int opened;
static void trim __P((char *));
static char *readrecord __P((const char *));
static void includelabel __P((STRBUF *, const char *, int));
static void
trim(l)
char *l;
{
char *f, *b;
int colon = 0;
for (f = b = l; *f; f++) {
if (colon && isspace(*f))
continue;
colon = 0;
if ((*b++ = *f) == ':')
colon = 1;
}
*b = 0;
}
static char *
readrecord(label)
const char *label;
{
char *p, *q;
rewind(fp);
while ((p = mgets(fp, NULL, MGETS_CONT|MGETS_SKIPCOM)) != NULL) {
trim(p);
for (;;) {
if ((q = strmake(p, "|:")) == NULL)
die1("illegal configuration file format (%s).", p);
if (!strcmp(label, q)) {
if (!(p = locatestring(p, ":", MATCH_FIRST)))
die("illegal configuration file format.");
p = strdup(p);
if (!p)
die("short of memory.");
return p;
}
p += strlen(q);
if (*p == ':')
break;
else if (*p == '|')
p++;
else
assert(0);
}
}
return NULL;
}
static void
includelabel(sb, label, level)
STRBUF *sb;
const char *label;
int level;
{
char *savep, *p, *q;
if (++level > allowed_nest_level)
die("nested include= (or tc=) over flow.");
if (!(savep = p = readrecord(label)))
die1("label '%s' not found.", label);
while ((q = locatestring(p, ":include=", MATCH_FIRST)) || (q = locatestring(p, ":tc=", MATCH_FIRST))) {
char inclabel[MAXPROPLEN+1], *c = inclabel;
strnputs(sb, p, q - p);
q = locatestring(q, "=", MATCH_FIRST) + 1;
while (*q && *q != ':')
*c++ = *q++;
*c = 0;
includelabel(sb, inclabel, level);
p = q;
}
strputs(sb, p);
free(savep);
}
/*
* configpath: get path of configuration file.
*/
char *
configpath() {
static char config[MAXPATHLEN+1];
char *p;
if ((p = getenv("GTAGSCONF")) != NULL) {
if (!test("r", p))
config[0] = 0;
else
strcpy(config, p);
} else if ((p = getenv("HOME")) && test("r", makepath(p, GTAGSRC)))
strcpy(config, makepath(p, GTAGSRC));
else if (test("r", GTAGSCONF))
strcpy(config, GTAGSCONF);
else
config[0] = 0;
return config;
}
/*
* openconf: load configuration file.
*
* go) line specified entry
*/
void
openconf()
{
const char *label, *config;
STRBUF *sb;
assert(opened == 0);
config = configpath();
/*
* if configuration file is not found, default values are set
* for upper compatibility.
*/
if (*config == 0) {
sb = stropen();
strputs(sb, "suffixes=c,h,y,s,S,java:");
strputs(sb, "skip=y.tab.c,y.tab.h,SCCS/,RCS/,CVS/:");
strputs(sb, "format=standard:");
strputs(sb, "extractmethod:");
strputs(sb, "GTAGS=gctags %s:");
strputs(sb, "GRTAGS=gctags -r %s:");
strputs(sb, "GSYMS=gctags -s %s:");
line = strdup(strvalue(sb));
if (!line)
die("short of memory.");
strclose(sb);
opened = 1;
return;
}
if ((label = getenv("GTAGSLABEL")) == NULL)
label = "default";
if (!(fp = fopen(config, "r")))
die1("cannot open '%s'.", config);
sb = stropen();
includelabel(sb, label, 0);
line = strdup(strvalue(sb));
strclose(sb);
fclose(fp);
opened = 1;
return;
}
/*
* getconfn: get property number
*
* i) name property name
* o) num value (if not NULL)
* r) 1: found, 0: not found
*/
int
getconfn(name, num)
const char *name;
int *num;
{
char *p;
char buf[MAXPROPLEN+1];
if (!opened)
openconf();
sprintf(buf, ":%s#", name);
if ((p = locatestring(line, buf, MATCH_FIRST)) != NULL) {
p += strlen(buf);
if (num != NULL)
*num = atoi(p);
return 1;
}
return 0;
}
/*
* getconfs: get property string
*
* i) name property name
* o) sb string buffer (if not NULL)
* r) 1: found, 0: not found
*/
int
getconfs(name, sb)
const char *name;
STRBUF *sb;
{
char *p;
char buf[MAXPROPLEN+1];
int all = 0;
int exist = 0;
if (!opened)
openconf();
if (!strcmp(name, "suffixes") || !strcmp(name, "skip") || !strcmp(name, "reserved_words"))
all = 1;
sprintf(buf, ":%s=", name);
p = line;
while ((p = locatestring(p, buf, MATCH_FIRST)) != NULL) {
if (exist && sb)
strputc(sb, ',');
exist = 1;
for (p += strlen(buf); *p && *p != ':'; p++)
if (sb)
strputc(sb, *p);
if (!all)
break;
}
/*
* It may be that these code should be moved to applications.
* But nothing cannot start without them.
*/
if (!exist) {
exist = 1;
if (!strcmp(name, "suffixes")) {
if (sb)
strputs(sb, "c,h,y,s,S,java");
} else if (!strcmp(name, "skip")) {
if (sb)
strputs(sb, "y.tab.c,y.tab.h,SCCS/,RCS/,CVS/");
} else
exist = 0;
}
return exist;
}
/*
* getconfb: get property bool value
*
* i) name property name
* r) 1: TRUE, 0: FALSE
*/
int
getconfb(name)
const char *name;
{
char *p;
char buf[MAXPROPLEN+1];
if (!opened)
openconf();
sprintf(buf, ":%s:", name);
if ((p = locatestring(line, buf, MATCH_FIRST)) != NULL)
return 1;
return 0;
}
void
closeconf()
{
if (!opened)
return;
free(line);
opened = 0;
}

54
contrib/global/lib/conf.h Normal file
View File

@ -0,0 +1,54 @@
/*
* 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
* 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.
*
* conf.h 16-Oct-97
*
*/
#ifndef _CONF_H_
#define _CONF_H_
#include "strbuf.h"
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
char *configpath __P((void));
void openconf __P((void));
int getconfn __P((const char *, int *));
int getconfs __P((const char *, STRBUF *));
int getconfb __P((const char *));
void closeconf __P((void));
#endif /* ! _CONF_H_ */

332
contrib/global/lib/dbop.c Normal file
View File

@ -0,0 +1,332 @@
/*
* Copyright (c) 1996, 1997, 1998 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.
*
* dbop.c 12-Nov-98
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dbop.h"
#include "die.h"
#include "test.h"
static DBT key; /* key of record */
static DBT dat; /* data of record */
/*
* dbop_open: open db database.
*
* i) dbname database name
* i) mode 0: read only, 1: create, 2: modify
* i) perm file permission
* i) flags
* DBOP_DUP: allow duplicate records.
* DBOP_REMOVE: remove on closed.
* r) descripter for dbop_xxx()
*/
DBOP *
dbop_open(dbname, mode, perm, flags)
const char *dbname;
int mode;
int perm;
int flags;
{
DB *db;
int rw = 0;
DBOP *dbop;
BTREEINFO info;
/*
* setup argments.
*/
switch (mode) {
case 0:
rw = O_RDONLY;
break;
case 1:
rw = O_RDWR|O_CREAT|O_TRUNC;
break;
case 2:
rw = O_RDWR;
break;
default:
assert(0);
}
memset(&info, 0, sizeof(info));
if (flags & DBOP_DUP)
info.flags |= R_DUP;
info.cachesize = 500000;
/*
* 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)
return NULL;
if (!(dbop = (DBOP *)malloc(sizeof(DBOP))))
die("short of memory.");
strcpy(dbop->dbname, dbname);
dbop->db = db;
dbop->openflags = flags;
dbop->perm = (mode == 1) ? perm : 0;
dbop->lastkey = NULL;
dbop->lastdat = NULL;
return dbop;
}
/*
* dbop_get: get data by a key.
*
* i) dbop descripter
* i) name name
* r) pointer to data
*/
char *
dbop_get(dbop, name)
DBOP *dbop;
const char *name;
{
DB *db = dbop->db;
int status;
key.data = (char *)name;
key.size = strlen(name)+1;
status = (*db->get)(db, &key, &dat, 0);
dbop->lastkey = (char *)key.data;
dbop->lastdat = (char *)dat.data;
switch (status) {
case RET_SUCCESS:
break;
case RET_ERROR:
die("cannot read from database.");
case RET_SPECIAL:
return (NULL);
}
return((char *)dat.data);
}
/*
* dbop_put: put data by a key.
*
* i) dbop descripter
* i) name key
* i) data data
*/
void
dbop_put(dbop, name, data)
DBOP *dbop;
const char *name;
const char *data;
{
DB *db = dbop->db;
int status;
if (strlen(name) > MAXKEYLEN)
die("primary key too long.");
key.data = (char *)name;
key.size = strlen(name)+1;
dat.data = (char *)data;
dat.size = strlen(data)+1;
status = (*db->put)(db, &key, &dat, 0);
switch (status) {
case RET_SUCCESS:
break;
case RET_ERROR:
case RET_SPECIAL:
die("cannot write to database.");
}
}
/*
* dbop_del: delete record by a key.
*
* i) dbop descripter
* i) name key
*/
void
dbop_del(dbop, name)
DBOP *dbop;
const char *name;
{
DB *db = dbop->db;
int status;
if (name) {
key.data = (char *)name;
key.size = strlen(name)+1;
status = (*db->del)(db, &key, 0);
} else
status = (*db->del)(db, &key, R_CURSOR);
if (status == RET_ERROR)
die("cannot delete record.");
}
/*
* dbop_first: get first record.
*
* i) dbop dbop descripter
* i) name key
* !=NULL: indexed read by key
* ==NULL: sequential read
* i) flags following dbop_next call take over this.
* DBOP_KEY read key part
* DBOP_PREFIX prefix read
* only valied when sequential read
* r) data
*/
char *
dbop_first(dbop, name, flags)
DBOP *dbop;
const char *name;
int flags;
{
DB *db = dbop->db;
int status;
if (flags & DBOP_PREFIX && !name)
flags &= ~DBOP_PREFIX;
if (name) {
if (strlen(name) > MAXKEYLEN)
die("primary key too long.");
strcpy(dbop->key, name);
key.data = (char *)name;
key.size = strlen(name);
/*
* includes NULL character unless prefix read.
*/
if (!(flags & DBOP_PREFIX))
key.size++;
dbop->keylen = key.size;
status = (*db->seq)(db, &key, &dat, R_CURSOR);
} else {
dbop->keylen = dbop->key[0] = 0;
/* skip META records */
for (status = (*db->seq)(db, &key, &dat, R_FIRST);
status == RET_SUCCESS;
status = (*db->seq)(db, &key, &dat, R_NEXT)) {
int c = (flags & DBOP_KEY) ? *((char *)key.data) : *((char *)dat.data);
if (c != ' ')
break;
}
}
dbop->lastkey = (char *)key.data;
dbop->lastdat = (char *)dat.data;
switch (status) {
case RET_SUCCESS:
break;
case RET_ERROR:
die("dbop_first failed.");
case RET_SPECIAL:
return (NULL);
}
dbop->ioflags = flags;
if (flags & DBOP_PREFIX) {
if (strncmp((char *)key.data, dbop->key, dbop->keylen))
return NULL;
} else if (dbop->keylen) {
if (strcmp((char *)key.data, dbop->key))
return NULL;
}
if (flags & DBOP_KEY) {
strcpy(dbop->prev, (char *)key.data);
return (char *)key.data;
}
return ((char *)dat.data);
}
/*
* dbop_next: get next record.
*
* i) dbop dbop descripter
* r) data
*
* Db_next always skip meta records.
*/
char *
dbop_next(dbop)
DBOP *dbop;
{
DB *db = dbop->db;
int flags = dbop->ioflags;
int status;
while ((status = (*db->seq)(db, &key, &dat, R_NEXT)) == RET_SUCCESS) {
assert(dat.data != NULL);
if (flags & DBOP_KEY && *((char *)key.data) == ' ')
continue;
else if (*((char *)dat.data) == ' ')
continue;
if (flags & DBOP_KEY) {
if (!strcmp(dbop->prev, (char *)key.data))
continue;
if (strlen((char *)key.data) > MAXKEYLEN)
die("primary key too long.");
strcpy(dbop->prev, (char *)key.data);
}
dbop->lastkey = (char *)key.data;
dbop->lastdat = (char *)dat.data;
if (flags & DBOP_PREFIX) {
if (strncmp((char *)key.data, dbop->key, dbop->keylen))
return NULL;
} else if (dbop->keylen) {
if (strcmp((char *)key.data, dbop->key))
return NULL;
}
return (flags & DBOP_KEY) ? (char *)key.data : (char *)dat.data;
}
if (status == RET_ERROR)
die("dbop_next failed.");
return NULL;
}
/*
* dbop_close: close db
*
* i) dbop dbop descripter
*/
void
dbop_close(dbop)
DBOP *dbop;
{
DB *db = dbop->db;
(void)db->close(db);
if (dbop->openflags & DBOP_REMOVE)
(void)unlink(dbop->dbname);
else if (dbop->perm && chmod(dbop->dbname, dbop->perm) < 0)
die("cannot change file mode.");
(void)free(dbop);
}

88
contrib/global/lib/dbop.h Normal file
View File

@ -0,0 +1,88 @@
/*
* Copyright (c) 1996, 1997, 1998 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.
*
* dbop.h 12-Nov-98
*
*/
#ifndef _DBOP_H_
#define _DBOP_H_
#include <sys/param.h>
#include <db.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 dbop_open() */
int ioflags; /* flags of dbop_first() */
int perm; /* file permission */
} DBOP;
/*
* openflags
*/
#define DBOP_DUP 1 /* allow duplicate records */
#define DBOP_REMOVE 2 /* remove file when closed */
/*
* ioflags
*/
#define DBOP_KEY 1 /* read key part */
#define DBOP_PREFIX 2 /* prefixed read */
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
DBOP *dbop_open __P((const char *, int, int, int));
char *dbop_get __P((DBOP *, const char *));
void dbop_put __P((DBOP *, const char *, const char *));
void dbop_del __P((DBOP *, const char *));
char *dbop_first __P((DBOP *, const char *, int));
char *dbop_next __P((DBOP *));
void dbop_close __P((DBOP *));
#endif /* _DBOP_H_ */

View File

@ -0,0 +1,66 @@
/*
* 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
* 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.
*
* defined.c 12-Nov-98
*
*/
#include <stdlib.h>
#include "die.h"
#include "dbop.h"
#include "defined.h"
#include "makepath.h"
static DBOP *dbop = NULL;
/*
* Tag command that supports referenced tag must call this function
* to decide whether or not the tag is defined.
*/
int
defined(name)
const char *name;
{
if (dbop == NULL) {
const char *dbpath;
/*
* gtags(1) set GTAGSDBPATH to the path GTAGS exist.
*/
if (!(dbpath = getenv("GTAGSDBPATH")))
dbpath = ".";
dbop = dbop_open(makepath(dbpath, "GTAGS"), 0, 0, 0);
if (dbop == NULL)
die1("GTAGS not found. (%s)", makepath(dbpath, "GTAGS"));
}
if (dbop_get(dbop, name))
return 1;
return 0;
}

View File

@ -0,0 +1,48 @@
/*
* 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
* 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.
*
* defined.h 2-May-98
*
*/
#ifndef _DEFINED_H_
#define _DEFINED_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
int defined __P((const char *));
#endif /* ! _DEFINED_H_ */

View File

@ -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
@ -35,7 +35,7 @@
#define _DIE_H_
#include <stdio.h>
extern char *progname;
extern const char *progname;
#define die(a) fprintf(stderr, "%s: ", progname),\
fprintf(stderr, a),\
@ -46,4 +46,8 @@ extern char *progname;
fprintf(stderr, a, b),\
fputs("\n", stderr),\
exit(1)
#define die2(a,b,c) fprintf(stderr, "%s: ", progname),\
fprintf(stderr, a, b, c),\
fputs("\n", stderr),\
exit(1)
#endif /* ! _DIE_H_ */

View File

@ -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,114 +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
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>
/*
* USEFIND use find(1) to traverse directory tree.
* Otherwise, use dirent(3) library.
*/
#define USEFIND
#include <sys/param.h>
#include "gparam.h"
#include "find.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 <stdlib.h>
#include <strings.h>
#include <regex.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);
}
sprintf(p, " \\) -print");
if (sizeof(skippath) != 0) {
int i, lim = sizeof(skippath)/sizeof(char *);
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");
}
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)
@ -144,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).");
@ -155,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 */

View File

@ -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

View File

@ -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
@ -40,12 +40,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.
@ -66,17 +64,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;
}
@ -109,17 +105,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 != '/')

View File

@ -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

View File

@ -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,27 +28,30 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* global.h 16-Oct-97
* global.h 2-May-98
*
*/
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
#include "gparam.h"
#include "dbname.h"
#include "makepath.h"
#include "dbio.h"
#include "locatestring.h"
#include "mgets.h"
#include "conf.h"
#include "dbop.h"
#include "defined.h"
#include "die.h"
#include "find.h"
#include "getdbpath.h"
#include "strop.h"
#include "gtagsopen.h"
#include "lookup.h"
#include "gparam.h"
#include "gtagsop.h"
#include "locatestring.h"
#include "makepath.h"
#include "mgets.h"
#include "pathop.h"
#include "strbuf.h"
#include "strmake.h"
#include "tab.h"
#include "tag.h"
#include "test.h"
#include "token.h"
#include "usable.h"
#endif /* ! _GLOBAL_H_ */

View File

@ -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,15 +28,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* gparam.h 16-Oct-97
* gparam.h 16-Jul-98
*
*/
#ifndef _GPARAM_H_
#define _GPARAM_H_
#define MAXCOMLINE 1024 /* max length of filter */
#define IDENTLEN 512 /* max length of ident */
#define MAXENVLEN 1024 /* max length of env */
#define MAXBUFLEN 1024 /* max length of buffer */
#define MAXFILLEN 1024 /* max length of filter */
#define IDENTLEN 512 /* max length of ident */
#define MAXENVLEN 1024 /* max length of env */
#define MAXBUFLEN 1024 /* max length of buffer */
#define MAXPROPLEN 1024 /* max length of property */
#define MAXARGLEN 512 /* max length of argment */
#endif /* ! _GPARAM_H_ */

View File

@ -0,0 +1,644 @@
/*
* 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
* 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.
*
* gtagsop.c 12-Nov-98
*
*/
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dbop.h"
#include "die.h"
#include "gtagsop.h"
#include "locatestring.h"
#include "makepath.h"
#include "mgets.h"
#include "pathop.h"
#include "strbuf.h"
#include "strmake.h"
#include "tab.h"
static char *genrecord __P((GTOP *));
static int belongto __P((GTOP *, char *, char *));
static int support_version = 2; /* acceptable format version */
static const char *tagslist[] = {"GTAGS", "GRTAGS", "GSYMS"};
/*
* dbname: return db name
*
* i) db 0: GTAGS, 1: GRTAGS, 2: GSYMS
* r) dbname
*/
const char *
dbname(db)
int db;
{
assert(db >= 0 && db < GTAGLIM);
return tagslist[db];
}
/*
* makecommand: make command line to make global tag file
*
* i) comline skelton command line
* i) path path name
* o) sb command line
*/
void
makecommand(comline, path, sb)
char *comline;
char *path;
STRBUF *sb;
{
char *p;
if (!(p = strmake(comline, "%")))
die1("'%%s' is needed in tag command line. (%s)\n", comline);
strputs(sb, p);
strputs(sb, path);
if (!(p = locatestring(comline, "%s", MATCH_FIRST)))
die1("'%%s' is needed in tag command line. (%s)\n", comline);
strputs(sb, p+2);
}
/*
* formatcheck: check format of tag command's output
*
* i) line input
* i) flags flag
* r) 0: normal
* -1: tag name
* -2: line number
* -3: path
*
* [example of right format]
*
* $1 $2 $3 $4
* ----------------------------------------------------
* main 83 ./ctags.c main(argc, argv)
*/
int
formatcheck(line, flags)
char *line;
int flags;
{
char *p, *q;
/*
* $1 = tagname: allowed any char except sepalator.
*/
p = q = line;
while (*p && !isspace(*p))
p++;
while (*p && isspace(*p))
p++;
if (p == q)
return -1;
/*
* $2 = line number: must be digit.
*/
q = p;
while (*p && !isspace(*p))
if (!isdigit(*p))
return -2;
else
p++;
if (p == q)
return -2;
while (*p && isspace(*p))
p++;
/*
* $3 = path:
* standard format: must start with './'.
* compact format: must be digit.
*/
if (flags & GTAGS_PATHINDEX) {
while (*p && !isspace(*p))
if (!isdigit(*p))
return -3;
else
p++;
} else {
if (!(*p == '.' && *(p + 1) == '/' && *(p + 2)))
return -3;
}
return 0;
}
/*
* gtagsopen: open global tag.
*
* i) dbpath dbpath directory
* i) root root directory (needed when compact format)
* i) db GTAGS, GRTAGS, GSYMS
* i) mode GTAGS_READ: read only
* GTAGS_CREATE: create tag
* GTAGS_MODIFY: modify tag
* i) flags GTAGS_COMPACT
* GTAGS_PATHINDEX
* r) GTOP structure
*
* when error occurred, gtagopen doesn't return.
* GTAGS_PATHINDEX needs GTAGS_COMPACT.
*/
GTOP *
gtagsopen(dbpath, root, db, mode, flags)
char *dbpath;
char *root;
int db;
int mode;
int flags;
{
GTOP *gtop;
int dbmode = 0;
if ((gtop = (GTOP *)calloc(sizeof(GTOP), 1)) == NULL)
die("short of memory.");
gtop->db = db;
gtop->mode = mode;
switch (gtop->mode) {
case GTAGS_READ:
dbmode = 0;
break;
case GTAGS_CREATE:
dbmode = 1;
break;
case GTAGS_MODIFY:
dbmode = 2;
break;
default:
assert(0);
}
/*
* allow duplicate records.
*/
gtop->dbop = dbop_open(makepath(dbpath, dbname(db)), dbmode, 0644, DBOP_DUP);
if (gtop->dbop == NULL) {
if (dbmode == 1)
die1("cannot make %s.", dbname(db));
die1("%s not found.", dbname(db));
}
/*
* decide format version.
*/
gtop->format_version = 1;
gtop->format = GTAGS_STANDARD;
/*
* This is a special case. GSYMS had compact format even if
* format version 1.
*/
if (db == GSYMS)
gtop->format |= GTAGS_COMPACT;
if (gtop->mode == GTAGS_CREATE) {
if (flags & GTAGS_COMPACT) {
char buf[80];
gtop->format_version = 2;
sprintf(buf, "%s %d", VERSIONKEY, gtop->format_version);
dbop_put(gtop->dbop, VERSIONKEY, buf);
gtop->format |= GTAGS_COMPACT;
dbop_put(gtop->dbop, COMPACTKEY, COMPACTKEY);
if (flags & GTAGS_PATHINDEX) {
gtop->format |= GTAGS_PATHINDEX;
dbop_put(gtop->dbop, PATHINDEXKEY, PATHINDEXKEY);
}
}
} 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.
*/
char *p;
if ((p = dbop_get(gtop->dbop, VERSIONKEY)) != NULL) {
for (p += strlen(VERSIONKEY); *p && isspace(*p); p++)
;
gtop->format_version = atoi(p);
}
if (gtop->format_version > support_version)
die("GTAGS seems new format. Please install the latest GLOBAL.");
if (gtop->format_version > 1) {
if (dbop_get(gtop->dbop, COMPACTKEY) != NULL)
gtop->format |= GTAGS_COMPACT;
if (dbop_get(gtop->dbop, PATHINDEXKEY) != NULL)
gtop->format |= GTAGS_PATHINDEX;
}
}
if (gtop->format & GTAGS_PATHINDEX || gtop->mode != GTAGS_READ) {
if (pathopen(dbpath, dbmode) < 0) {
if (dbmode == 1)
die("cannot create GPATH.");
else
die("GPATH not found.");
}
}
/*
* Stuff for compact format.
*/
if (gtop->format & GTAGS_COMPACT) {
assert(root != NULL);
strcpy(gtop->root, root);
if (gtop->mode != GTAGS_READ)
gtop->sb = stropen();
}
return gtop;
}
/*
* gtagsput: put tag record with packing.
*
* i) gtop descripter of GTOP
* i) tag tag name
* i) record ctags -x image
*/
void
gtagsput(gtop, tag, record)
GTOP *gtop;
char *tag;
char *record;
{
char *p, *q;
char lno[10];
char path[MAXPATHLEN+1];
if (gtop->format == GTAGS_STANDARD) {
entab(record);
dbop_put(gtop->dbop, tag, record);
return;
}
/*
* gtop->format & GTAGS_COMPACT
*/
p = record; /* ignore $1 */
while (*p && !isspace(*p))
p++;
while (*p && isspace(*p))
p++;
q = lno; /* lno = $2 */
while (*p && !isspace(*p))
*q++ = *p++;
*q = 0;
while (*p && isspace(*p))
p++;
q = path; /* path = $3 */
while (*p && !isspace(*p))
*q++ = *p++;
*q = 0;
/*
* First time, it occurs, because 'prev_tag' and 'prev_path' are NULL.
*/
if (strcmp(gtop->prev_tag, tag) || strcmp(gtop->prev_path, path)) {
if (gtop->prev_tag[0])
dbop_put(gtop->dbop, gtop->prev_tag, strvalue(gtop->sb));
strcpy(gtop->prev_tag, tag);
strcpy(gtop->prev_path, path);
/*
* Start creating new record.
*/
strstart(gtop->sb);
strputs(gtop->sb, strmake(record, " \t"));
strputc(gtop->sb, ' ');
strputs(gtop->sb, path);
strputc(gtop->sb, ' ');
strputs(gtop->sb, lno);
} else {
strputc(gtop->sb, ',');
strputs(gtop->sb, lno);
}
}
/*
* gtagsadd: add tags belonging to the path into tag file.
*
* i) gtop descripter of GTOP
* i) comline tag command line
* i) path source file
* i) flags GTAGS_UNIQUE, GTAGS_EXTRACTMETHOD
*/
void
gtagsadd(gtop, comline, path, flags)
GTOP *gtop;
char *comline;
char *path;
int flags;
{
char *tagline;
FILE *ip;
STRBUF *sb = stropen();
/*
* add path index if not yet.
*/
pathput(path);
/*
* make command line.
*/
makecommand(comline, path, sb);
/*
* Compact format.
*/
if (gtop->format & GTAGS_PATHINDEX) {
char *pno;
if ((pno = pathget(path)) == NULL)
die1("GPATH is corrupted.('%s' not found)", path);
strputs(sb, "| sed 's!");
strputs(sb, path);
strputs(sb, "!");
strputs(sb, pno);
strputs(sb, "!'");
}
if (gtop->format & GTAGS_COMPACT)
strputs(sb, "| sort +0 -1 +1n -2");
if (flags & GTAGS_UNIQUE)
strputs(sb, "| uniq");
if (!(ip = popen(strvalue(sb), "r")))
die1("cannot execute '%s'.", strvalue(sb));
while ((tagline = mgets(ip, NULL, MGETS_TAILCUT)) != NULL) {
char *tag, *p;
if (formatcheck(tagline, gtop->format) < 0)
die1("illegal parser output.\n'%s'", tagline);
tag = strmake(tagline, " \t"); /* tag = $1 */
/*
* extract method when class method definition.
*
* Ex: Class::method(...)
*
* key = 'method'
* data = 'Class::method 103 ./class.cpp ...'
*/
if (flags & GTAGS_EXTRACTMETHOD) {
if ((p = locatestring(tag, ".", MATCH_LAST)) != NULL)
tag = p + 1;
else if ((p = locatestring(tag, "::", MATCH_LAST)) != NULL)
tag = p + 2;
}
gtagsput(gtop, tag, tagline);
}
pclose(ip);
strclose(sb);
}
/*
* belongto: wheather or not record belongs to the path.
*
* i) gtop GTOP structure
* i) path path name (in standard format)
* path number (in compact format)
* i) p record
* r) 1: belong, 0: not belong
*/
static int
belongto(gtop, path, p)
GTOP *gtop;
char *path;
char *p;
{
char *q;
int length = strlen(path);
/*
* seek to path part.
*/
if (gtop->format & GTAGS_PATHINDEX) {
for (q = p; *q && !isspace(*q); q++)
;
if (*q == 0)
die1("illegal tag format. '%s'", p);
for (; *q && isspace(*q); q++)
;
} else
q = locatestring(p, "./", MATCH_FIRST);
if (*q == 0)
die1("illegal tag format. '%s'", p);
if (!strncmp(q, path, length) && isspace(*(q + length)))
return 1;
return 0;
}
/*
* gtagsdelete: delete records belong to path.
*
* i) gtop GTOP structure
* i) path path name
*/
void
gtagsdelete(gtop, path)
GTOP *gtop;
char *path;
{
char *p, *key;
int length;
/*
* In compact format, a path is saved as a file number.
*/
key = path;
if (gtop->format & GTAGS_PATHINDEX)
if ((key = pathget(path)) == NULL)
die1("GPATH is corrupted.('%s' not found)", path);
length = strlen(key);
/*
* read sequentially, because db(1) has just one index.
*/
for (p = dbop_first(gtop->dbop, NULL, 0); p; p = dbop_next(gtop->dbop))
if (belongto(gtop, key, p))
dbop_del(gtop->dbop, NULL);
/*
* don't delete from path index.
*/
}
/*
* gtagsfirst: return first record
*
* i) gtop GTOP structure
* i) tag tag name
* i) flags GTOP_PREFIX prefix read
* GTOP_KEY read key only
* r) record
*/
char *
gtagsfirst(gtop, tag, flags)
GTOP *gtop;
char *tag;
int flags;
{
int dbflags = 0;
char *line;
gtop->flags = flags;
if (flags & GTOP_PREFIX && tag != NULL)
dbflags |= DBOP_PREFIX;
if (flags & GTOP_KEY)
dbflags |= DBOP_KEY;
if ((line = dbop_first(gtop->dbop, tag, dbflags)) == NULL)
return NULL;
if (gtop->format == GTAGS_STANDARD || gtop->flags & GTOP_KEY)
return line;
/*
* Compact format.
*/
gtop->line = line; /* gtop->line = $0 */
gtop->opened = 0;
return genrecord(gtop);
}
/*
* gtagsnext: return followed record
*
* i) gtop GTOP structure
* r) record
* NULL end of tag
*/
char *
gtagsnext(gtop)
GTOP *gtop;
{
char *line;
/*
* If it is standard format or only key.
* Just return it.
*/
if (gtop->format == GTAGS_STANDARD || gtop->flags & GTOP_KEY)
return dbop_next(gtop->dbop);
/*
* gtop->format & GTAGS_COMPACT
*/
if ((line = genrecord(gtop)) != NULL)
return line;
/*
* read next record.
*/
if ((line = dbop_next(gtop->dbop)) == NULL)
return line;
gtop->line = line; /* gtop->line = $0 */
gtop->opened = 0;
return genrecord(gtop);
}
/*
* gtagsclose: close tag file
*
* i) gtop GTOP structure
*/
void
gtagsclose(gtop)
GTOP *gtop;
{
if (gtop->format & GTAGS_PATHINDEX || gtop->mode != GTAGS_READ)
pathclose();
if (gtop->sb && gtop->prev_tag[0])
dbop_put(gtop->dbop, gtop->prev_tag, strvalue(gtop->sb));
if (gtop->sb)
strclose(gtop->sb);
dbop_close(gtop->dbop);
free(gtop);
}
static char *
genrecord(gtop)
GTOP *gtop;
{
static char output[MAXBUFLEN+1];
char path[MAXPATHLEN+1];
static char buf[1];
char *buffer = buf;
char *lnop;
int tagline;
if (!gtop->opened) {
char *p, *q;
gtop->opened = 1;
p = gtop->line;
q = gtop->tag; /* gtop->tag = $1 */
while (!isspace(*p))
*q++ = *p++;
*q = 0;
for (; isspace(*p) ; p++)
;
if (gtop->format & GTAGS_PATHINDEX) { /* gtop->path = $2 */
char *name;
q = path;
while (!isspace(*p))
*q++ = *p++;
*q = 0;
if ((name = pathget(path)) == NULL)
die1("GPATH is corrupted.('%s' not found)", path);
strcpy(gtop->path, name);
} else {
q = gtop->path;
while (!isspace(*p))
*q++ = *p++;
*q = 0;
}
for (; isspace(*p) ; p++)
;
gtop->lnop = p; /* gtop->lnop = $3 */
if (gtop->root)
sprintf(path, "%s/%s", gtop->root, &gtop->path[2]);
else
sprintf(path, "%s", &gtop->path[2]);
if ((gtop->fp = fopen(path, "r")) != NULL) {
buffer = mgets(gtop->fp, NULL, MGETS_TAILCUT);
gtop->lno = 1;
}
}
lnop = gtop->lnop;
if (*lnop >= '0' && *lnop <= '9') {
/* get line number */
for (tagline = 0; *lnop >= '0' && *lnop <= '9'; lnop++)
tagline = tagline * 10 + *lnop - '0';
if (*lnop == ',')
lnop++;
gtop->lnop = lnop;
if (gtop->fp) {
if (gtop->lno == tagline)
return output;
while (gtop->lno < tagline) {
if (!(buffer = mgets(gtop->fp, NULL, MGETS_TAILCUT)))
die1("unexpected end of file. '%s'", path);
gtop->lno++;
}
}
if (strlen(gtop->tag) >= 16 && tagline >= 1000)
sprintf(output, "%-16s %4d %-16s %s",
gtop->tag, tagline, gtop->path, buffer);
else
sprintf(output, "%-16s%4d %-16s %s",
gtop->tag, tagline, gtop->path, buffer);
return output;
}
if (gtop->opened && gtop->fp != NULL) {
gtop->opened = 0;
fclose(gtop->fp);
}
return NULL;
}

View File

@ -0,0 +1,109 @@
/*
* 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
* 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.
*
* gtagsop.h 23-Dec-97
*
*/
#ifndef _GTOP_H_
#define _GTOP_H_
#include <stdio.h>
#include "dbop.h"
#include "gparam.h"
#include "strbuf.h"
#define VERSIONKEY " __.VERSION"
#define COMPACTKEY " __.COMPACT"
#define PATHINDEXKEY " __.PATHINDEX"
#define GTAGS 0
#define GRTAGS 1
#define GSYMS 2
#define GTAGLIM 3
#define GTAGS_READ 0
#define GTAGS_CREATE 1
#define GTAGS_MODIFY 2
/* gtagsopen() */
#define GTAGS_STANDARD 0 /* standard format */
#define GTAGS_COMPACT 1 /* compact format */
#define GTAGS_PATHINDEX 2 /* use path index */
/* gtagsadd() */
#define GTAGS_UNIQUE 1 /* compress duplicate lines */
#define GTAGS_EXTRACTMETHOD 2 /* extract method from class definition */
/* gtagsfirst() */
#define GTOP_KEY 1 /* read key part */
#define GTOP_PREFIX 2 /* prefixed read */
typedef struct {
DBOP *dbop; /* descripter of DBOP */
int format_version; /* format version */
int format; /* GTAGS_STANDARD, GTAGS_COMPACT */
int mode; /* mode */
int db; /* 0:GTAGS, 1:GRTAGS, 2:GSYMS */
int flags; /* flags */
char root[MAXPATHLEN+1]; /* root directory of source tree */
/*
* Stuff for compact format
*/
int opened; /* wether or not file opened */
char *line; /* current record */
char tag[IDENTLEN+1]; /* current tag */
char prev_tag[IDENTLEN+1]; /* previous tag */
char path[MAXPATHLEN+1]; /* current path */
char prev_path[MAXPATHLEN+1];/* previous path */
STRBUF *sb; /* string buffer */
FILE *fp; /* descriptor of 'path' */
char *lnop; /* current line number */
int lno; /* integer value of 'lnop' */
} GTOP;
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
const char *dbname __P((int));
void makecommand __P((char *, char *, STRBUF *));
int formatcheck __P((char *, int));
GTOP *gtagsopen __P((char *, char *, int, int, int));
void gtagsput __P((GTOP *, char *, char *));
char *gtagsget __P((GTOP *, char *));
void gtagsadd __P((GTOP *, char *, char *, int));
void gtagsdelete __P((GTOP *, char *));
char *gtagsfirst __P((GTOP *, char *, int));
char *gtagsnext __P((GTOP *));
void gtagsclose __P((GTOP *));
#endif /* ! _GTOP_H_ */

View File

@ -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;
}

View File

@ -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,13 +28,18 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* locatestring.h 16-Oct-97
* locatestring.h 25-Jul-98
*
*/
#ifndef _LOCATESTRING_H_
#define _LOCATESTRING_H_
#define MATCH_FIRST 0
#define MATCH_AT_FIRST 1
#define MATCH_LAST 2
#define MATCH_AT_LAST 3
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
@ -43,6 +48,6 @@
#endif
#endif
char *locatestring __P((char *, char *, int));
char *locatestring __P((const char *, const char *, int));
#endif /* ! _LOCATESTRING_H_ */

View File

@ -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,11 +28,15 @@
* 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 <sys/param.h>
#include "die.h"
#include "makepath.h"
#include "strbuf.h"
static STRBUF *sb;
/*
* makepath: make path from directory and file.
*
@ -42,16 +46,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);
}

View File

@ -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
@ -43,6 +43,6 @@
#endif
#endif
char *makepath __P((char *, char *));
char *makepath __P((const char *, const char *));
#endif /* ! _MAKEPATH_H_ */

View File

@ -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,19 @@
* 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 "mgets.h"
#include "die.h"
#include "mgets.h"
#define EXPANDSIZE 127
#define MINSIZE 16
#define EXPANDSIZE 512
static int mbufsize = EXPANDSIZE;
static char *mbuf;
@ -45,20 +48,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;
@ -72,27 +76,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);
}
/*
@ -109,6 +119,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;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
* Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
*
* Redilogibution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -37,6 +37,7 @@
#include <stdio.h>
#define MGETS_CONT 1
#define MGETS_SKIPCOM 2
#define MGETS_TAILCUT 4
#ifndef __P
#if defined(__STDC__)
@ -46,6 +47,6 @@
#endif
#endif
char *mgets __P((FILE *, int, int *));
char *mgets __P((FILE *, int *, int));
#endif /* ! _MGETS_H_ */

155
contrib/global/lib/pathop.c Normal file
View File

@ -0,0 +1,155 @@
/*
* 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
* 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.
*
* pathop.c 12-Nov-98
*
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "die.h"
#include "dbop.h"
#include "makepath.h"
#include "pathop.h"
static DBOP *dbop;
static const char *gpath = "GPATH";
static int _nextkey;
static int _mode;
static int opened;
static int created;
/*
* pathopen: open path dictionary tag.
*
* i) mode 0: read only
* 1: create
* 2: modify
* r) 0: normal
* -1: error
*/
int
pathopen(dbpath, mode)
char *dbpath;
int mode;
{
char *p;
assert(opened == 0);
/*
* We create GPATH just first time.
*/
_mode = mode;
if (mode == 1 && created)
mode = 0;
dbop = dbop_open(makepath(dbpath, gpath), mode, 0644, 0);
if (dbop == NULL)
return -1;
if (mode == 1)
_nextkey = 0;
else {
if (!(p = dbop_get(dbop, NEXTKEY)))
die("nextkey not found in GPATH.");
_nextkey = atoi(p);
}
opened = 1;
return 0;
}
void
pathput(path)
char *path;
{
char buf[10];
assert(opened == 1);
if (_mode == 1 && created)
return;
if (dbop_get(dbop, path) != NULL)
return;
sprintf(buf, "%d", _nextkey++);
dbop_put(dbop, path, buf);
dbop_put(dbop, buf, path);
}
char *
pathget(key)
char *key;
{
assert(opened == 1);
return dbop_get(dbop, key);
}
char *
pathiget(n)
int n;
{
char key[80];
assert(opened == 1);
sprintf(key, "%d", n);
return dbop_get(dbop, key);
}
void
pathdel(key)
char *key;
{
char *d;
assert(opened == 1);
assert(_mode == 2);
assert(key[0] == '.' && key[1] == '/');
d = dbop_get(dbop, key);
if (d == NULL)
return;
dbop_del(dbop, d);
dbop_del(dbop, key);
}
int
nextkey(void)
{
assert(_mode != 1);
return _nextkey;
}
void
pathclose(void)
{
char buf[10];
assert(opened == 1);
opened = 0;
if (_mode == 1 && created) {
dbop_close(dbop);
return;
}
sprintf(buf, "%d", _nextkey);
if (_mode == 1 || _mode == 2)
dbop_put(dbop, NEXTKEY, buf);
dbop_close(dbop);
if (_mode == 1)
created = 1;
}

View File

@ -0,0 +1,59 @@
/*
* 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
* 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.
*
* pathop.h 14-May-98
*
*/
#ifndef _PATHOP_H_
#define _PATHOP_H_
#include <stdio.h>
#include "dbop.h"
#include "gparam.h"
#define NEXTKEY " __.NEXTKEY"
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
int pathopen __P((char *, int));
char *pathget __P((char *));
char *pathiget __P((int));
void pathput __P((char *));
void pathdel __P((char *));
void pathclose __P((void));
int nextkey __P((void));
#endif /* ! _PATHOP_H_ */

137
contrib/global/lib/strbuf.c Normal file
View File

@ -0,0 +1,137 @@
/*
* 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
* 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.
*
* strbuf.c 5-Jul-98
*
*/
#include <stdlib.h>
#include <string.h>
#include "die.h"
#include "strbuf.h"
/*
* usage: string buffer
*
* sb = stropen();
* for (s = string; *s; s++)
* strputc(sb, *s);
* s = strvalue(sb);
* strstart(sb);
* strputs(sb, "hello");
* s = strvalue(sb);
* strclose(sb);
*/
/*
* expandbuf: expand buffer so that afford to the length data at least.
*
* i) sb STRBUF structure
* i) length required room
*/
void
expandbuf(sb, length)
STRBUF *sb;
int length;
{
int count = sb->curp - sb->sbuf;
sb->sbufsize += (length > EXPANDSIZE) ? length : EXPANDSIZE;
if (!(sb->sbuf = (char *)realloc(sb->sbuf, sb->sbufsize + 1)))
die("short of memory.");
sb->curp = sb->sbuf + count;
sb->endp = sb->sbuf + sb->sbufsize;
}
/*
* stropen: open string buffer.
*
* r) sb STRBUF structure
*/
STRBUF *
stropen(void)
{
STRBUF *sb = (STRBUF *)calloc(sizeof(STRBUF), 1);
if (sb == NULL)
die("short of memory.");
sb->sbufsize = INITIALSIZE;
if (!(sb->sbuf = (char *)malloc(sb->sbufsize + 1)))
die("short of memory.");
sb->curp = sb->sbuf;
sb->endp = sb->sbuf + sb->sbufsize;
return sb;
}
/*
* strstart: reset string buffer for new string.
*
* i) sb STRBUF structure
*/
void
strstart(sb)
STRBUF *sb;
{
sb->curp = sb->sbuf;
}
/*
* strbuflen: return the length of string buffer.
*
* i) sb STRBUF structure
*/
int
strbuflen(sb)
STRBUF *sb;
{
return sb->curp - sb->sbuf;
}
/*
* strvalue: return the content of string buffer.
*
* i) sb STRBUF structure
* r) string
*/
char *
strvalue(sb)
STRBUF *sb;
{
*sb->curp = 0;
return sb->sbuf;
}
/*
* strclose: close string buffer.
*
* i) sb STRBUF structure
*/
void
strclose(sb)
STRBUF *sb;
{
(void)free(sb->sbuf);
(void)free(sb);
}

View File

@ -0,0 +1,82 @@
/*
* 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
* 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.
*
* strbuf.h 5-Jul-98
*
*/
#ifndef _STRBUF_H
#define _STRBUF_H
#include <string.h>
#define INITIALSIZE 80
#define EXPANDSIZE 80
typedef struct {
char *sbuf;
char *endp;
char *curp;
int sbufsize;
} STRBUF;
#define strputc(sb,c) do {\
if (sb->curp + 1 > sb->endp)\
expandbuf(sb, 0);\
*sb->curp++ = c;\
} while (0)
#define strunputc(sb,c) do {\
if (sb->curp > sb->sbuf && *(sb->curp - 1) == c)\
sb->curp--;\
} while (0)
#define strnputs(sb, s, len) do {\
unsigned int _length = len;\
if (sb->curp + _length > sb->endp)\
expandbuf(sb, _length);\
strncpy(sb->curp, s, _length);\
sb->curp += _length;\
} while (0)
#define strputs(sb, s) strnputs(sb, s, strlen(s))
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
void expandbuf __P((STRBUF *, int));
STRBUF *stropen __P((void));
void strstart __P((STRBUF *));
int strbuflen __P((STRBUF *));
char *strvalue __P((STRBUF *));
void strclose __P((STRBUF *));
#endif /* ! _STRBUF_H */

View File

@ -0,0 +1,59 @@
/*
* 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
* 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.
*
* strmake.c 15-May-98
*
*/
#include <stdlib.h>
#include "strbuf.h"
#include "strmake.h"
static STRBUF *sb;
char *
strmake(p, lim)
const char *p;
const char *lim;
{
const char *c;
if (sb == NULL)
sb = stropen();
strstart(sb);
for (; *p; p++) {
for (c = lim; *c; c++)
if (*p == *c)
goto end;
strputc(sb,*p);
}
end:
return strvalue(sb);
}

View File

@ -0,0 +1,48 @@
/*
* 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
* 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.
*
* strmake.h 17-Apr-98
*
*/
#ifndef _STRMAKE_H_
#define _STRMAKE_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
char *strmake __P((const char *, const char *));
#endif /* ! _STRMAKE_H_ */

View File

@ -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;
}

View File

@ -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.
*
* tab.h 16-Oct-97
* tab.h 8-Oct-98
*
*/
@ -43,6 +43,7 @@
#endif
#endif
void settabs __P((int));
void detab __P((FILE *, char *));
void entab __P((char *));

View File

@ -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))

View File

@ -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
@ -43,6 +43,6 @@
#endif
#endif
int test __P((char *, char *));
int test __P((const char *, const char *));
#endif /* ! _TEST_H_ */

293
contrib/global/lib/token.c Normal file
View File

@ -0,0 +1,293 @@
/*
* Copyright (c) 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
* 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 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.
*
* token.c 14-Aug-98
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include "mgets.h"
#include "token.h"
/*
* File input method.
*/
int lineno;
char *sp, *cp, *lp;
int crflag; /* 1: return '\n', 0: doesn't return */
int cmode; /* allow token which start with '#' */
int ymode; /* allow token which start with '%' */
char token[MAXTOKEN];
char curfile[MAXPATHLEN];
static char ptok[MAXTOKEN];
static int lasttok;
static FILE *ip;
static void pushbackchar __P((void));
/*
* opentoken:
*/
int
opentoken(file)
char *file;
{
if ((ip = fopen(file, "r")) == NULL)
return 0;
strcpy(curfile, file);
sp = cp = lp = NULL; lineno = 0;
return 1;
}
/*
* closetoken:
*/
void
closetoken()
{
fclose(ip);
}
/*
* nexttoken: get next token
*
* i) interested interested special charactor
* if NULL then all charactor.
* i) reserved converter from token to token number
* if this is specified, nexttoken() return
* word number, else return symbol.
* r) EOF(-1) end of file
* ==0 symbol ('tok' has the value.)
* > 255 reserved word
* <=255 interested special charactor
*
* nexttoken() doesn't return followings.
*
* o comment
* o space (' ', '\t', '\f')
* o quoted string ("...", '.')
*/
int
nexttoken(interested, reserved)
const char *interested;
int (*reserved)(char *);
{
int c;
char *p;
int sharp = 0;
int percent = 0;
/* check push back buffer */
if (ptok[0]) {
strcpy(token, ptok);
ptok[0] = 0;
return lasttok;
}
for (;;) {
/* skip spaces */
if (!crflag)
while ((c = nextchar()) != EOF && isspace(c))
;
else
while ((c = nextchar()) != EOF && (c == ' ' || c == '\t' || c == '\f'))
;
if (c == EOF || c == '\n')
break;
if (c == '"' || c == '\'') { /* quoted string */
int quote = c;
while ((c = nextchar()) != EOF) {
if (c == quote)
break;
if (quote == '\'' && c == '\n')
break;
if (c == '\\' && (c = nextchar()) == EOF)
break;
}
} else if (c == '/') { /* comment */
if ((c = nextchar()) == '/') {
while ((c = nextchar()) != EOF)
if (c == '\n')
break;
} else if (c == '*') {
while ((c = nextchar()) != EOF) {
if (c == '*') {
if ((c = nextchar()) == '/')
break;
pushbackchar();
}
}
} else
pushbackchar();
} else if (c == '\\') {
(void)nextchar();
} else if (isdigit(c)) { /* digit */
while ((c = nextchar()) != EOF && (c == '.' || isdigit(c) || isalpha(c)))
;
pushbackchar();
} else if (c == '#' && cmode) {
/* recognize '##' as a token if it is reserved word. */
if (peekc(1) == '#') {
p = token;
*p++ = c;
*p++ = nextchar();
*p = 0;
if (reserved && (c = (*reserved)(token)) == 0)
break;
} else if (atfirst_exceptspace()) {
sharp = 1;
continue;
}
} else if (c == '%' && ymode) {
/* recognize '%%' as a token if it is reserved word. */
if (atfirst) {
p = token;
*p++ = c;
if ((c = peekc(1)) == '%' || c == '{' || c == '}') {
*p++ = nextchar();
*p = 0;
if (reserved && (c = (*reserved)(token)) != 0)
break;
} else if (!isspace(c)) {
percent = 1;
continue;
}
}
} else if (c & 0x80 || isalpha(c) || c == '_') {/* symbol */
p = token;
if (sharp) {
sharp = 0;
*p++ = '#';
} else if (percent) {
percent = 0;
*p++ = '%';
}
for (*p++ = c; (c = nextchar()) != EOF && (c & 0x80 || isalnum(c) || c == '_'); *p++ = c)
;
*p = 0;
if (c != EOF)
pushbackchar();
/* convert token string into token number */
if (reserved)
c = (*reserved)(token);
break;
} else { /* special char */
if (interested == NULL || strchr(interested, c))
break;
/* otherwise ignore it */
}
sharp = percent = 0;
}
return lasttok = c;
}
/*
* pushbacktoken: push back token
*
* following nexttoken() return same token again.
*/
void
pushbacktoken()
{
strcpy(ptok, token);
}
/*
* peekc: peek next char
*
* i) immediate 0: ignore blank, 1: include blank
*
* Peekc() read ahead following blanks but doesn't chage line.
*/
int
peekc(immediate)
int immediate;
{
int c;
long pos;
if (cp != NULL) {
if (immediate)
c = nextchar();
else
while ((c = nextchar()) != EOF && c != '\n' && isspace(c))
;
if (c != EOF)
pushbackchar();
if (c != '\n' || immediate)
return c;
}
pos = ftell(ip);
if (immediate)
c = getc(ip);
else
while ((c = getc(ip)) != EOF && isspace(c))
;
(void)fseek(ip, pos, SEEK_SET);
return c;
}
/*
* atfirst_exceptspace: return if current position is the first column
* except for space.
* | 1 0
* | v v
* | # define
*/
int
atfirst_exceptspace()
{
char *start = sp;
char *end = cp ? cp - 1 : lp;
while (start < end && *start && isspace(*start))
start++;
return (start == end) ? 1 : 0;
}
/*
* pushbackchar: push back charactor.
*
* following nextchar() return same charactor again.
*
*/
static void
pushbackchar()
{
if (sp == NULL)
return; /* nothing to do */
if (cp == NULL)
cp = lp;
else
--cp;
}

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 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
* 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 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.
*
* token.h 14-Aug-98
*/
#ifndef _TOKEN_H_
#define _TOKEN_H_
#include <sys/param.h>
#include "mgets.h"
#define MAXTOKEN 512
#define SYMBOL 0
extern char *sp, *cp, *lp;
extern int lineno;
extern int crflag;
extern int cmode;
extern int ymode;
extern char token[MAXTOKEN];
extern char curfile[MAXPATHLEN];
#define nextchar() \
(cp == NULL ? \
((sp = cp = mgets(ip, NULL, 0)) == NULL ? \
EOF : \
(lineno++, *cp == 0 ? \
lp = cp, cp = NULL, '\n' : \
*cp++)) : \
(*cp == 0 ? (lp = cp, cp = NULL, '\n') : *cp++))
#define atfirst (sp && sp == (cp ? cp - 1 : lp))
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
int opentoken __P((char *));
void closetoken __P((void));
int nexttoken __P((const char *, int (*)(char *)));
void pushbacktoken __P((void));
int peekc __P((int));
int atfirst_exceptspace __P((void));
#endif /* ! _TOKEN_H_ */

View File

@ -0,0 +1,70 @@
/*
* 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
* 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.
*
* usable.c 22-Jun-98
*
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "locatestring.h"
#include "gparam.h"
#include "makepath.h"
#include "test.h"
#include "usable.h"
/*
* usable: check executable or not about the command.
*
* i) command
* r) 1: executable
* 0: non executable
*/
int
usable(command)
char *command;
{
char buf[MAXENVLEN+1], *p, *dir;
if (*command == '/' || locatestring(command, "./", MATCH_AT_FIRST) || locatestring(command, "../", MATCH_AT_FIRST))
return test("fx", command);
strcpy(buf, getenv("PATH"));
p = buf;
while (p) {
dir = p;
if ((p = locatestring(p, ":", MATCH_FIRST)) != NULL)
*p++ = 0;
if (test("fx", makepath(dir, command)))
return 1;
}
return 0;
}

View File

@ -0,0 +1,48 @@
/*
* 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
* 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.
*
* usable.h 22-Jul-98
*
*/
#ifndef _USABLE_H_
#define _USABLE_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
int usable __P((char *));
#endif /* ! _USABLE_H_ */

View File

@ -0,0 +1,673 @@
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/build/Makefile ./build/Makefile
*** /usr/src/usr.bin/nvi-1.66.org/build/Makefile Tue May 5 15:57:21 1998
--- ./build/Makefile Sun Aug 16 03:22:53 1998
***************
*** 3,9 ****
# from: @(#)Makefile.in 8.56 (Berkeley) 5/18/96
WARNS= 0
! CPPFLAGS+=-I${.CURDIR} -I${.CURDIR}/../include
LDADD+= -lcurses -ltermcap
DPADD+= ${LIBCURSES} ${LIBTERMCAP}
--- 3,9 ----
# from: @(#)Makefile.in 8.56 (Berkeley) 5/18/96
WARNS= 0
! CPPFLAGS+=-I${.CURDIR} -I${.CURDIR}/../include -DGTAGS
LDADD+= -lcurses -ltermcap
DPADD+= ${LIBCURSES} ${LIBTERMCAP}
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/common/main.c ./common/main.c
*** /usr/src/usr.bin/nvi-1.66.org/common/main.c Tue May 5 15:57:26 1998
--- ./common/main.c Sun Aug 16 03:27:19 1998
***************
*** 63,68 ****
--- 63,71 ----
size_t len;
u_int flags;
int ch, fd, flagchk, lflag, startup, readonly, rval, silent;
+ #ifdef GTAGS
+ int gtags = 0;
+ #endif
char *tag_f, *wsizearg;
char path[256];
***************
*** 113,123 ****
--- 116,135 ----
/* Set the file snapshot flag. */
F_SET(gp, G_SNAPSHOT);
+ #ifdef GTAGS
+ #ifdef DEBUG
+ while ((ch = getopt(argc, argv, "c:D:eFGlRrsT:t:vw:")) != EOF)
+ #else
+ while ((ch = getopt(argc, argv, "c:eFGlRrst:vw:")) != EOF)
+ #endif
+ #else
#ifdef DEBUG
while ((ch = getopt(argc, argv, "c:D:eFlRrsT:t:vw:")) != EOF)
#else
while ((ch = getopt(argc, argv, "c:eFlRrst:vw:")) != EOF)
#endif
+ #endif
+
switch (ch) {
case 'c': /* Run the command. */
/*
***************
*** 167,172 ****
--- 179,189 ----
case 'F': /* No snapshot. */
F_CLR(gp, G_SNAPSHOT);
break;
+ #ifdef GTAGS
+ case 'G': /* gtags mode. */
+ gtags = 1;
+ break;
+ #endif
case 'l': /* Set lisp, showmatch options. */
lflag = 1;
break;
***************
*** 258,263 ****
--- 275,284 ----
{ int oargs[4], *oargp = oargs;
if (readonly) /* Command-line options. */
*oargp++ = O_READONLY;
+ #ifdef GTAGS
+ if (gtags)
+ *oargp++ = O_GTAGSMODE;
+ #endif
if (lflag) {
*oargp++ = O_LISP;
*oargp++ = O_SHOWMATCH;
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/common/options.c ./common/options.c
*** /usr/src/usr.bin/nvi-1.66.org/common/options.c Tue May 5 15:57:26 1998
--- ./common/options.c Sun Aug 16 03:29:51 1998
***************
*** 80,85 ****
--- 80,89 ----
{"filec", NULL, OPT_STR, 0},
/* O_FLASH HPUX */
{"flash", NULL, OPT_1BOOL, 0},
+ #ifdef GTAGS
+ /* O_GTAGSMODE FreeBSD, NetBSD */
+ {"gtagsmode", NULL, OPT_0BOOL, 0},
+ #endif
/* O_HARDTABS 4BSD */
{"hardtabs", NULL, OPT_NUM, 0},
/* O_ICLOWER 4.4BSD */
***************
*** 240,245 ****
--- 244,252 ----
{"eb", O_ERRORBELLS}, /* 4BSD */
{"ed", O_EDCOMPATIBLE}, /* 4BSD */
{"ex", O_EXRC}, /* System V (undocumented) */
+ #ifdef GTAGS
+ {"gt", O_GTAGSMODE}, /* FreeBSD, NetBSD */
+ #endif
{"ht", O_HARDTABS}, /* 4BSD */
{"ic", O_IGNORECASE}, /* 4BSD */
{"li", O_LINES}, /* 4.4BSD */
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/docs/USD.doc/vi.man/vi.1 ./docs/USD.doc/vi.man/vi.1
*** /usr/src/usr.bin/nvi-1.66.org/docs/USD.doc/vi.man/vi.1 Tue May 5 15:57:31 1998
--- ./docs/USD.doc/vi.man/vi.1 Sun Aug 16 03:34:12 1998
***************
*** 40,46 ****
.SH SYNOPSIS
.B ex
[\c
! .B -eFRrsv\c
] [\c
.BI -c " cmd"\c
] [\c
--- 40,46 ----
.SH SYNOPSIS
.B ex
[\c
! .B -eFGRrsv\c
] [\c
.BI -c " cmd"\c
] [\c
***************
*** 51,57 ****
.br
.B vi
[\c
! .B -eFlRrv\c
] [\c
.BI -c " cmd"\c
] [\c
--- 51,57 ----
.br
.B vi
[\c
! .B -eFGlRrv\c
] [\c
.BI -c " cmd"\c
] [\c
***************
*** 62,68 ****
.br
.B view
[\c
! .B -eFRrv\c
] [\c
.BI -c " cmd"\c
] [\c
--- 62,68 ----
.br
.B view
[\c
! .B -eFGRrv\c
] [\c
.BI -c " cmd"\c
] [\c
***************
*** 135,140 ****
--- 135,143 ----
(The default is to make a copy in case someone else modifies
the file during your edit session.)
.TP
+ .B \-G
+ Start editing in gtags mode, as if the gtagsmode option was set.
+ .TP
.B \-l
Start editing with the lisp and showmatch options set.
.TP
***************
*** 441,446 ****
--- 444,451 ----
.TP
.B "<control-]>"
Push a tag reference onto the tag stack.
+ In gtagsmode, if at the first column of line,
+ locate function references otherwise function definitions.
.TP
.B "<control-^>"
Switch to the most recently edited file.
***************
*** 952,957 ****
--- 957,965 ----
.B "rew[ind][!]"
Rewind the argument list.
.TP
+ .B "rta[g][!] tagstring"
+ Edit the file refering the specified tag. (Only in gtagsmode)
+ .TP
.B "se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]"
Display or set editor options.
.TP
***************
*** 1121,1126 ****
--- 1129,1137 ----
.TP
.B "flash [on]"
Flash the screen instead of beeping the keyboard on error.
+ .TP
+ .B "gtagsmode, gt [off]"
+ Use GTAGS and GRTAGS instead of tags.
.TP
.B "hardtabs, ht [8]"
Set the spacing between hardware tab settings.
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/ex/ex.h ./ex/ex.h
*** /usr/src/usr.bin/nvi-1.66.org/ex/ex.h Tue May 5 15:57:37 1998
--- ./ex/ex.h Sun Aug 16 03:35:58 1998
***************
*** 162,167 ****
--- 162,170 ----
#define E_NEWLINE 0x00800000 /* Found ending <newline>. */
#define E_USELASTCMD 0x01000000 /* Use the last command. */
#define E_VISEARCH 0x02000000 /* It's really a vi search command. */
+ #ifdef GTAGS
+ #define E_REFERENCE 0x04000000 /* locate function references */
+ #endif
u_int32_t flags; /* Current flags. */
};
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/ex/ex_cmd.c ./ex/ex_cmd.c
*** /usr/src/usr.bin/nvi-1.66.org/ex/ex_cmd.c Tue May 5 15:57:37 1998
--- ./ex/ex_cmd.c Sun Aug 16 03:38:03 1998
***************
*** 302,307 ****
--- 302,314 ----
"!",
"rew[ind][!]",
"re-edit all the files in the file argument list"},
+ #ifdef GTAGS
+ /* C_RTAG */
+ {"rtag", ex_rtag_push, E_NEWSCREEN,
+ "!w1o",
+ "rta[g][!] [string]",
+ "edit the file containing the tag"},
+ #endif
/*
* !!!
* Adding new commands starting with 's' may break the substitute command code
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/ex/ex_tag.c ./ex/ex_tag.c
*** /usr/src/usr.bin/nvi-1.66.org/ex/ex_tag.c Tue May 5 15:57:41 1998
--- ./ex/ex_tag.c Sun Aug 16 03:46:43 1998
***************
*** 46,51 ****
--- 46,55 ----
static int compare __P((char *, char *, char *));
static void ctag_file __P((SCR *, TAGF *, char *, char **, size_t *));
static int ctag_search __P((SCR *, char *, char *));
+ #ifdef GTAGS
+ static int getentry __P((char *, char **, char **, char **));
+ static TAGQ *gtag_slist __P((SCR *, char *, int));
+ #endif
static int ctag_sfile __P((SCR *, TAGF *, TAGQ *, char *));
static TAGQ *ctag_slist __P((SCR *, char *));
static char *linear_search __P((char *, char *, char *));
***************
*** 89,94 ****
--- 93,117 ----
return (0);
}
+ #ifdef GTAGS
+ /*
+ * ex_rtag_push -- ^]
+ * :rtag[!] [string]
+ *
+ * Enter a new TAGQ context based on a ctag string.
+ *
+ * PUBLIC: int ex_rtag_push __P((SCR *, EXCMD *));
+ */
+ int
+ ex_rtag_push(sp, cmdp)
+ SCR *sp;
+ EXCMD *cmdp;
+ {
+ F_SET(cmdp, E_REFERENCE);
+ return ex_tag_push(sp, cmdp);
+ }
+ #endif
+
/*
* ex_tag_push -- ^]
* :tag[!] [string]
***************
*** 138,143 ****
--- 161,172 ----
}
/* Get the tag information. */
+ #ifdef GTAGS
+ if (O_ISSET(sp, O_GTAGSMODE)) {
+ if ((tqp = gtag_slist(sp, exp->tag_last, F_ISSET(cmdp, E_REFERENCE))) == NULL)
+ return (1);
+ } else
+ #endif
if ((tqp = ctag_slist(sp, exp->tag_last)) == NULL)
return (1);
***************
*** 963,969 ****
--- 992,1120 ----
(void)nonblank(sp, sp->lno, &sp->cno);
return (0);
}
+ #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 = buf;
+
+ for (*tag = p; *p && !isspace(*p); p++) /* tag name */
+ ;
+ if (*p == 0)
+ goto err;
+ *p++ = 0;
+ for (; *p && isspace(*p); p++) /* (skip blanks) */
+ ;
+ if (*p == 0)
+ goto err;
+ *line = p; /* line no */
+ for (*line = p; *p && !isspace(*p); p++)
+ ;
+ if (*p == 0)
+ goto err;
+ *p++ = 0;
+ for (; *p && isspace(*p); p++) /* (skip blanks) */
+ ;
+ if (*p == 0)
+ goto err;
+ *file = p; /* file name */
+ for (*file = p; *p && !isspace(*p); p++)
+ ;
+ if (*p == 0)
+ goto err;
+ *p = 0;
+
+ /* value check */
+ if (strlen(*tag) && strlen(*line) && strlen(*file) && atoi(*line) > 0)
+ return 1; /* OK */
+ err:
+ return 0; /* ERROR */
+ }
+
+ /*
+ * gtag_slist --
+ * Search the list of tags files for a tag, and return tag queue.
+ */
+ static TAGQ *
+ gtag_slist(sp, tag, ref)
+ SCR *sp;
+ char *tag;
+ int ref;
+ {
+ EX_PRIVATE *exp;
+ TAGF *tfp;
+ TAGQ *tqp;
+ size_t len;
+ int echk;
+ TAG *tp;
+ char *name, *file, *line;
+ char command[BUFSIZ];
+ char buf[BUFSIZ];
+ FILE *fp;
+
+ /* Allocate and initialize the tag queue structure. */
+ len = strlen(tag);
+ CALLOC_GOTO(sp, tqp, TAGQ *, 1, sizeof(TAGQ) + len + 1);
+ CIRCLEQ_INIT(&tqp->tagq);
+ tqp->tag = tqp->buf;
+ memcpy(tqp->tag, tag, (tqp->tlen = len) + 1);
+
+ /*
+ * Find the tag, only display missing file messages once, and
+ * then only if we didn't find the tag.
+ */
+ snprintf(command, sizeof(command), "global -%s '%s' 2>/dev/null", ref ? "rx" : "x", tag);
+ if (fp = popen(command, "r")) {
+ while (fgets(buf, sizeof(buf), fp)) {
+ if (buf[strlen(buf)-1] == '\n') /* chop(buf) */
+ buf[strlen(buf)-1] = 0;
+ else
+ while (fgetc(fp) != '\n')
+ ;
+ if (getentry(buf, &name, &file, &line) == 0) {
+ echk = 1;
+ F_SET(tfp, TAGF_ERR);
+ break;
+ }
+ CALLOC_GOTO(sp, tp,
+ TAG *, 1, sizeof(TAG) + strlen(file) + 1 + strlen(line) + 1);
+ tp->fname = tp->buf;
+ strcpy(tp->fname, file);
+ tp->fnlen = strlen(file);
+ tp->search = tp->fname + tp->fnlen + 1;
+ strcpy(tp->search, line);
+ CIRCLEQ_INSERT_TAIL(&tqp->tagq, tp, q);
+ }
+ pclose(fp);
+ }
+
+ /* Check to see if we found anything. */
+ if (tqp->tagq.cqh_first == (void *)&tqp->tagq) {
+ msgq_str(sp, M_ERR, tag, "162|%s: tag not found");
+ free(tqp);
+ return (NULL);
+ }
+ tqp->current = tqp->tagq.cqh_first;
+ return (tqp);
+
+ alloc_err:
+ return (NULL);
+ }
+ #endif
/*
* ctag_slist --
* Search the list of tags files for a tag, and return tag queue.
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/include/ex_def.h ./include/ex_def.h
*** /usr/src/usr.bin/nvi-1.66.org/include/ex_def.h Tue May 5 15:57:42 1998
--- ./include/ex_def.h Sun Aug 16 03:49:40 1998
***************
*** 47,78 ****
#define C_RECOVER 46
#define C_RESIZE 47
#define C_REWIND 48
! #define C_SUBSTITUTE 49
! #define C_SCRIPT 50
! #define C_SET 51
! #define C_SHELL 52
! #define C_SOURCE 53
! #define C_STOP 54
! #define C_SUSPEND 55
! #define C_T 56
! #define C_TAG 57
! #define C_TAGNEXT 58
! #define C_TAGPOP 59
! #define C_TAGPREV 60
! #define C_TAGTOP 61
! #define C_TCLCMD 62
! #define C_UNDO 63
! #define C_UNABBREVIATE 64
! #define C_UNMAP 65
! #define C_V 66
! #define C_VERSION 67
! #define C_VISUAL_EX 68
! #define C_VISUAL_VI 69
! #define C_VIUSAGE 70
! #define C_WRITE 71
! #define C_WN 72
! #define C_WQ 73
! #define C_XIT 74
! #define C_YANK 75
! #define C_Z 76
! #define C_SUBTILDE 77
--- 47,79 ----
#define C_RECOVER 46
#define C_RESIZE 47
#define C_REWIND 48
! #define C_RTAG 49
! #define C_SUBSTITUTE 50
! #define C_SCRIPT 51
! #define C_SET 52
! #define C_SHELL 53
! #define C_SOURCE 54
! #define C_STOP 55
! #define C_SUSPEND 56
! #define C_T 57
! #define C_TAG 58
! #define C_TAGNEXT 59
! #define C_TAGPOP 60
! #define C_TAGPREV 61
! #define C_TAGTOP 62
! #define C_TCLCMD 63
! #define C_UNDO 64
! #define C_UNABBREVIATE 65
! #define C_UNMAP 66
! #define C_V 67
! #define C_VERSION 68
! #define C_VISUAL_EX 69
! #define C_VISUAL_VI 70
! #define C_VIUSAGE 71
! #define C_WRITE 72
! #define C_WN 73
! #define C_WQ 74
! #define C_XIT 75
! #define C_YANK 76
! #define C_Z 77
! #define C_SUBTILDE 78
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/include/ex_extern.h ./include/ex_extern.h
*** /usr/src/usr.bin/nvi-1.66.org/include/ex_extern.h Tue May 5 15:57:42 1998
--- ./include/ex_extern.h Sun Aug 16 03:50:24 1998
***************
*** 92,97 ****
--- 92,100 ----
char *, char **, size_t *, regex_t *, u_int));
void re_error __P((SCR *, int, regex_t *));
int ex_tag_first __P((SCR *, char *));
+ #ifdef GTAGS
+ int ex_rtag_push __P((SCR *, EXCMD *));
+ #endif
int ex_tag_push __P((SCR *, EXCMD *));
int ex_tag_next __P((SCR *, EXCMD *));
int ex_tag_prev __P((SCR *, EXCMD *));
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/include/options_def.h ./include/options_def.h
*** /usr/src/usr.bin/nvi-1.66.org/include/options_def.h Tue May 5 15:57:42 1998
--- ./include/options_def.h Sun Aug 16 03:54:45 1998
***************
*** 16,77 ****
#define O_EXTENDED 15
#define O_FILEC 16
#define O_FLASH 17
! #define O_HARDTABS 18
! #define O_ICLOWER 19
! #define O_IGNORECASE 20
! #define O_KEYTIME 21
! #define O_LEFTRIGHT 22
! #define O_LINES 23
! #define O_LISP 24
! #define O_LIST 25
! #define O_LOCKFILES 26
! #define O_MAGIC 27
! #define O_MATCHTIME 28
! #define O_MESG 29
! #define O_MODELINE 30
! #define O_MSGCAT 31
! #define O_NOPRINT 32
! #define O_NUMBER 33
! #define O_OCTAL 34
! #define O_OPEN 35
! #define O_OPTIMIZE 36
! #define O_PARAGRAPHS 37
! #define O_PRINT 38
! #define O_PROMPT 39
! #define O_READONLY 40
! #define O_RECDIR 41
! #define O_REDRAW 42
! #define O_REMAP 43
! #define O_REPORT 44
! #define O_RULER 45
! #define O_SCROLL 46
! #define O_SEARCHINCR 47
! #define O_SECTIONS 48
! #define O_SECURE 49
! #define O_SHELL 50
! #define O_SHELLMETA 51
! #define O_SHIFTWIDTH 52
! #define O_SHOWMATCH 53
! #define O_SHOWMODE 54
! #define O_SIDESCROLL 55
! #define O_SLOWOPEN 56
! #define O_SOURCEANY 57
! #define O_TABSTOP 58
! #define O_TAGLENGTH 59
! #define O_TAGS 60
! #define O_TERM 61
! #define O_TERSE 62
! #define O_TILDEOP 63
! #define O_TIMEOUT 64
! #define O_TTYWERASE 65
! #define O_VERBOSE 66
! #define O_W1200 67
! #define O_W300 68
! #define O_W9600 69
! #define O_WARN 70
! #define O_WINDOW 71
! #define O_WRAPLEN 72
! #define O_WRAPMARGIN 73
! #define O_WRAPSCAN 74
! #define O_WRITEANY 75
! #define O_OPTIONCOUNT 76
--- 16,78 ----
#define O_EXTENDED 15
#define O_FILEC 16
#define O_FLASH 17
! #define O_GTAGSMODE 18
! #define O_HARDTABS 19
! #define O_ICLOWER 20
! #define O_IGNORECASE 21
! #define O_KEYTIME 22
! #define O_LEFTRIGHT 23
! #define O_LINES 24
! #define O_LISP 25
! #define O_LIST 26
! #define O_LOCKFILES 27
! #define O_MAGIC 28
! #define O_MATCHTIME 29
! #define O_MESG 30
! #define O_MODELINE 31
! #define O_MSGCAT 32
! #define O_NOPRINT 33
! #define O_NUMBER 34
! #define O_OCTAL 35
! #define O_OPEN 36
! #define O_OPTIMIZE 37
! #define O_PARAGRAPHS 38
! #define O_PRINT 39
! #define O_PROMPT 40
! #define O_READONLY 41
! #define O_RECDIR 42
! #define O_REDRAW 43
! #define O_REMAP 44
! #define O_REPORT 45
! #define O_RULER 46
! #define O_SCROLL 47
! #define O_SEARCHINCR 48
! #define O_SECTIONS 49
! #define O_SECURE 50
! #define O_SHELL 51
! #define O_SHELLMETA 52
! #define O_SHIFTWIDTH 53
! #define O_SHOWMATCH 54
! #define O_SHOWMODE 55
! #define O_SIDESCROLL 56
! #define O_SLOWOPEN 57
! #define O_SOURCEANY 58
! #define O_TABSTOP 59
! #define O_TAGLENGTH 60
! #define O_TAGS 61
! #define O_TERM 62
! #define O_TERSE 63
! #define O_TILDEOP 64
! #define O_TIMEOUT 65
! #define O_TTYWERASE 66
! #define O_VERBOSE 67
! #define O_W1200 68
! #define O_W300 69
! #define O_W9600 70
! #define O_WARN 71
! #define O_WINDOW 72
! #define O_WRAPLEN 73
! #define O_WRAPMARGIN 74
! #define O_WRAPSCAN 75
! #define O_WRITEANY 76
! #define O_OPTIONCOUNT 77
diff -c -r -N /usr/src/usr.bin/nvi-1.66.org/vi/v_ex.c ./vi/v_ex.c
*** /usr/src/usr.bin/nvi-1.66.org/vi/v_ex.c Tue May 5 15:57:45 1998
--- ./vi/v_ex.c Sun Aug 16 03:55:38 1998
***************
*** 221,226 ****
--- 221,231 ----
ARGS *ap[2], a;
EXCMD cmd;
+ #ifdef GTAGS
+ if (O_ISSET(sp, O_GTAGSMODE) && vp->m_start.cno == 0)
+ ex_cinit(&cmd, C_RTAG, 0, OOBLNO, 0, 0, ap);
+ else
+ #endif
ex_cinit(&cmd, C_TAG, 0, OOBLNO, 0, 0, ap);
ex_cadd(&cmd, &a, VIP(sp)->keyw, strlen(VIP(sp)->keyw));
return (v_exec_ex(sp, vp, &cmd));

View File

@ -1,6 +1,6 @@
diff -c -r -N /usr/local/src/nvi-1.79/build/Makefile.in ./build/Makefile.in
*** /usr/local/src/nvi-1.79/build/Makefile.in Wed Oct 23 22:43:38 1996
--- ./build/Makefile.in Wed Apr 16 21:20:09 1997
--- ./build/Makefile.in Fri Aug 14 01:41:14 1998
***************
*** 3,9 ****
srcdir= @srcdir@/..
@ -20,7 +20,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/build/Makefile.in ./build/Makefile.in
PERLLIB=@vi_cv_perllib@
diff -c -r -N /usr/local/src/nvi-1.79/common/main.c ./common/main.c
*** /usr/local/src/nvi-1.79/common/main.c Sat Oct 12 07:28:28 1996
--- ./common/main.c Wed Apr 16 21:20:09 1997
--- ./common/main.c Fri Aug 14 01:41:14 1998
***************
*** 64,69 ****
--- 64,72 ----
@ -84,7 +84,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/common/main.c ./common/main.c
*oargp = -1; /* Options initialization. */
diff -c -r -N /usr/local/src/nvi-1.79/common/options.c ./common/options.c
*** /usr/local/src/nvi-1.79/common/options.c Tue Oct 15 03:56:29 1996
--- ./common/options.c Wed Apr 16 21:20:09 1997
--- ./common/options.c Fri Aug 14 01:41:14 1998
***************
*** 80,85 ****
--- 80,89 ----
@ -112,7 +112,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/common/options.c ./common/options.c
{"li", O_LINES}, /* 4.4BSD */
diff -c -r -N /usr/local/src/nvi-1.79/docs/USD.doc/vi.man/vi.1 ./docs/USD.doc/vi.man/vi.1
*** /usr/local/src/nvi-1.79/docs/USD.doc/vi.man/vi.1 Fri Oct 11 10:34:05 1996
--- ./docs/USD.doc/vi.man/vi.1 Wed Apr 16 21:20:09 1997
--- ./docs/USD.doc/vi.man/vi.1 Fri Aug 14 01:41:14 1998
***************
*** 17,23 ****
.SH SYNOPSIS
@ -213,7 +213,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/docs/USD.doc/vi.man/vi.1 ./docs/USD.doc/vi
Set the spacing between hardware tab settings.
diff -c -r -N /usr/local/src/nvi-1.79/ex/ex.h ./ex/ex.h
*** /usr/local/src/nvi-1.79/ex/ex.h Tue Aug 13 09:24:00 1996
--- ./ex/ex.h Wed Apr 16 21:20:09 1997
--- ./ex/ex.h Fri Aug 14 01:41:14 1998
***************
*** 152,157 ****
--- 152,160 ----
@ -228,7 +228,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/ex/ex.h ./ex/ex.h
diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_cmd.c ./ex/ex_cmd.c
*** /usr/local/src/nvi-1.79/ex/ex_cmd.c Wed Oct 23 22:31:01 1996
--- ./ex/ex_cmd.c Wed Apr 16 21:20:09 1997
--- ./ex/ex_cmd.c Fri Aug 14 01:41:14 1998
***************
*** 302,307 ****
--- 302,314 ----
@ -239,7 +239,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_cmd.c ./ex/ex_cmd.c
+ /* C_RTAG */
+ {"rtag", ex_rtag_push, E_NEWSCREEN,
+ "!w1o",
+ "[Rr]ta[g][!] [string]",
+ "rta[g][!] [string]",
+ "edit the file containing the tag"},
+ #endif
/*
@ -247,7 +247,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_cmd.c ./ex/ex_cmd.c
* Adding new commands starting with 's' may break the substitute command code
diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_tag.c ./ex/ex_tag.c
*** /usr/local/src/nvi-1.79/ex/ex_tag.c Mon Sep 16 05:02:43 1996
--- ./ex/ex_tag.c Wed Apr 16 21:20:09 1997
--- ./ex/ex_tag.c Fri Aug 14 01:53:35 1998
***************
*** 46,51 ****
--- 46,55 ----
@ -255,7 +255,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_tag.c ./ex/ex_tag.c
static void ctag_file __P((SCR *, TAGF *, char *, char **, size_t *));
static int ctag_search __P((SCR *, char *, size_t, char *));
+ #ifdef GTAGS
+ static int getentry __P((char *, char *, char *, char *));
+ static int getentry __P((char *, char **, char **, char **));
+ static TAGQ *gtag_slist __P((SCR *, char *, int));
+ #endif
static int ctag_sfile __P((SCR *, TAGF *, TAGQ *, char *));
@ -306,7 +306,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_tag.c ./ex/ex_tag.c
***************
*** 969,974 ****
--- 998,1116 ----
--- 998,1126 ----
return (0);
}
@ -325,30 +325,40 @@ diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_tag.c ./ex/ex_tag.c
+ */
+ static int
+ getentry(buf, tag, file, line)
+ char *buf, *tag, *file, *line;
+ char *buf, **tag, **file, **line;
+ {
+ char *p;
+ char *p = buf;
+
+ 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++;
+ for (*tag = p; *p && !isspace(*p); p++) /* tag name */
+ ;
+ if (*p == 0)
+ goto err;
+ *p++ = 0;
+ for (; *p && isspace(*p); p++) /* (skip blanks) */
+ ;
+ if (*p == 0)
+ goto err;
+ *line = p; /* line no */
+ for (*line = p; *p && !isspace(*p); p++)
+ ;
+ if (*p == 0)
+ goto err;
+ *p++ = 0;
+ for (; *p && isspace(*p); p++) /* (skip blanks) */
+ ;
+ if (*p == 0)
+ goto err;
+ *file = p; /* file name */
+ for (*file = p; *p && !isspace(*p); p++)
+ ;
+ if (*p == 0)
+ goto err;
+ *p = 0;
+
+ /* value check */
+ if (strlen(tag) && strlen(line) && strlen(file) && atoi(line) > 0)
+ if (strlen(*tag) && strlen(*line) && strlen(*file) && atoi(*line) > 0)
+ return 1; /* OK */
+ err:
+ return 0; /* ERROR */
+ }
+
@ -368,9 +378,9 @@ diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_tag.c ./ex/ex_tag.c
+ size_t len;
+ int echk;
+ TAG *tp;
+ static char name[80], file[200], line[10];
+ char command[200];
+ char buf[BUFSIZ+1];
+ char *name, *file, *line;
+ char command[BUFSIZ];
+ char buf[BUFSIZ];
+ FILE *fp;
+
+ /* Allocate and initialize the tag queue structure. */
@ -384,7 +394,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_tag.c ./ex/ex_tag.c
+ * Find the tag, only display missing file messages once, and
+ * then only if we didn't find the tag.
+ */
+ sprintf(command, "global -%s '%s'", ref ? "rx" : "x", tag);
+ snprintf(command, sizeof(command), "global -%s '%s' 2>/dev/null", ref ? "rx" : "x", tag);
+ if (fp = popen(command, "r")) {
+ while (fgets(buf, sizeof(buf), fp)) {
+ if (buf[strlen(buf)-1] == '\n') /* chop(buf) */
@ -392,7 +402,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_tag.c ./ex/ex_tag.c
+ else
+ while (fgetc(fp) != '\n')
+ ;
+ if (getentry(buf, name, file, line) == 0) {
+ if (getentry(buf, &name, &file, &line) == 0) {
+ echk = 1;
+ F_SET(tfp, TAGF_ERR);
+ break;
@ -428,7 +438,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/ex/ex_tag.c ./ex/ex_tag.c
* Search the list of tags files for a tag, and return tag queue.
diff -c -r -N /usr/local/src/nvi-1.79/include/ex_def.h ./include/ex_def.h
*** /usr/local/src/nvi-1.79/include/ex_def.h Wed Oct 23 22:53:09 1996
--- ./include/ex_def.h Wed Apr 16 21:20:09 1997
--- ./include/ex_def.h Fri Aug 14 01:41:14 1998
***************
*** 47,78 ****
#define C_RECOVER 46
@ -499,7 +509,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/include/ex_def.h ./include/ex_def.h
! #define C_SUBTILDE 78
diff -c -r -N /usr/local/src/nvi-1.79/include/ex_extern.h ./include/ex_extern.h
*** /usr/local/src/nvi-1.79/include/ex_extern.h Wed Oct 23 22:53:10 1996
--- ./include/ex_extern.h Wed Apr 16 21:20:09 1997
--- ./include/ex_extern.h Fri Aug 14 01:41:14 1998
***************
*** 89,94 ****
--- 89,95 ----
@ -512,7 +522,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/include/ex_extern.h ./include/ex_extern.h
int ex_tag_prev __P((SCR *, EXCMD *));
diff -c -r -N /usr/local/src/nvi-1.79/include/options_def.h ./include/options_def.h
*** /usr/local/src/nvi-1.79/include/options_def.h Wed Oct 23 22:53:10 1996
--- ./include/options_def.h Wed Apr 16 21:20:09 1997
--- ./include/options_def.h Fri Aug 14 01:41:14 1998
***************
*** 16,79 ****
#define O_EXTENDED 15
@ -647,7 +657,7 @@ diff -c -r -N /usr/local/src/nvi-1.79/include/options_def.h ./include/options_de
! #define O_OPTIONCOUNT 79
diff -c -r -N /usr/local/src/nvi-1.79/vi/v_ex.c ./vi/v_ex.c
*** /usr/local/src/nvi-1.79/vi/v_ex.c Mon Sep 16 05:03:02 1996
--- ./vi/v_ex.c Wed Apr 16 21:20:09 1997
--- ./vi/v_ex.c Fri Aug 14 01:41:14 1998
***************
*** 226,231 ****
--- 226,236 ----

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 1997 Shigio Yamaguchi. All rights reserved.
# Copyright (c) 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
@ -29,59 +29,219 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# systags.sh 7-Jul-97
# systags.sh 17-Aug-98
#
# script to make hypertext of kernel source.
# supporting FreeBSD and Linux.
# support OS: FreeBSD, NetBSD, OpenBSD, Linux, GNUmach, GNUhurd
#
case $1 in
-n) nflag=1; shift;;
esac
while case $1 in
-*)
if grep '[^-cfgn]' <<! >/dev/null 2>&1; then
$1
!
echo "usage: systags [-c][-f][-g][-n][dir]"
exit 1
fi
case $1 in
*c*) cflag=c;;
esac
case $1 in
*f*) fflag=f;;
esac
case $1 in
*g*) gflag=g;;
esac
case $1 in
*n*) nflag=n;;
esac
;;
*) false;;
esac
do
shift
done
case $1 in
"") dir=.;;
*) dir=$1;;
esac
if [ ! -d $dir -o ! -w $dir ]; then
echo "systags: '$dir' is not a directory or not writable."
exit 1
fi
tmpdir=$dir/systags_tmpdir_$$
#
# get release number from source tree.
#
if [ -f conf/newvers.sh ]; then
os=FreeBSD
release=`awk -F= '/^RELEASE=/ {print $2}' < conf/newvers.sh`
# (Free|Net|Open)BSD?
if ! mkdir $tmpdir 2>/dev/null; then
echo "systags: '$dir' is not writable."
exit 1
fi
cwd=`pwd`
(cd $tmpdir; sh $cwd/conf/newvers.sh)
os=`awk -F\" '/char[ \t]+ostype\[\][ \t]*=[ \t]*\"[^"]+\"/ {print $2}' < $tmpdir/vers.c`;
release=`awk -F\" '/char[ \t]+osrelease\[\][ \t]*=[ \t]*\"[^"]+\"/ {print $2}' < $tmpdir/vers.c`;
rm -rf $tmpdir
elif [ -f Makefile ] && grep '^vmlinux:' Makefile >/dev/null; then
# Linux?
os=Linux
version=`awk -F= '/^VERSION *=/ {print $2}' < Makefile`
patchlevel=`awk -F= '/^PATCHLEVEL *=/ {print $2}' < Makefile`
sublevel=`awk -F= '/^SUBLEVEL *=/ {print $2}' < Makefile`
release=`echo "$version.$patchlevel.$sublevel" | tr -d ' '`
elif [ -f version.c ]; then
# GNU mach?
version=`awk -F\" '/char[ \t]+version\[\][ \t]*=[ \t]*\"[^"]+\"/ {print $2}' < version.c`
os=`echo $version | awk '{print $1}'`
release=`echo $version | awk '{print $2}'`
elif [ -f version.h ]; then
# GNU hurd?
release=`awk -F\" '/^#define[ \t]+HURD_VERSION[ \t]+"[^"]+\"/ {print $2}' < version.h`
if [ ${release}X != X ]; then
os=GNUhurd
fi
fi
#
# remove old files
#
files=
for f in htags.log gtags.log GTAGS GRTAGS GSYMS GPATH HTML; do
files="$files $dir/$f";
done
com="rm -rf $files"
case $nflag in
1) echo "rm -rf $dir/htags.log $dir/gtags.log $dir/GTAGS $dir/GRTAGS $dir/GSYMS $dir/HTML";;
*) rm -rf $dir/htags.log $dir/gtags.log $dir/GTAGS $dir/GRTAGS $dir/GSYMS $dir/HTML;;
n) echo $com;;
*) eval $com;;
esac
#
# make global database(GTAGS, GRTAGS, GSYMS).
# FreeBSD System macros.
#
# These macros with argument are used out of function.
# gctags(1) knows these are not function by '.notfunction' list.
#
# kernel.h MAKE_SET,TEXT_SET,DATA_SET,BSS_SET,ABS_SET,
# SYSINIT,SYSINIT_KT,SYSINIT_KP,PSEUDO_SET
# sysctl.h SYSCTL_OID,SYSCTL_NODE,SYSCTL_STRING,SYSCTL_INT,SYSCTL_OPAQUE,
# SYSCTL_STRUCT,SYSCTL_PROC
# domain.h DOMAIN_SET
# mount.h VFS_SET
# lkm.h MOD_DECL,MOD_SYSCALL,MOD_VFS,MOD_DEV,MOD_EXEC,MOD_MISC
# vnode.h VNODEOP_SET
# spl.h GENSPL
# queue.h SLIST_HEAD,SLIST_ENTRY,SLIST_INIT,SLIST_INSERT_AFTER,
# SLIST_INSERT_HEAD,SLIST_REMOVE_HEAD,SLIST_REMOVE,STAILQ_HEAD,
# STAILQ_ENTRY,STAILQ_INIT,STAILQ_INSERT_HEAD,STAILQ_INSERT_TAIL,
# STAILQ_INSERT_AFTER,STAILQ_REMOVE_HEAD,STAILQ_REMOVE,
# LIST_HEAD,LIST_ENTRY,LIST_INIT,LIST_INSERT_AFTER,LIST_INSERT_BEFORE,
# LIST_INSERT_HEAD,LIST_REMOVE,TAILQ_HEAD,TAILQ_ENTRY,
# TAILQ_EMPTY,TAILQ_FIRST,TAILQ_LAST,TAILQ_NEXT,TAILQ_PREV,
# TAILQ_INIT,TAILQ_INSERT_HEAD,TAILQ_INSERT_TAIL,TAILQ_INSERT_AFTER,
# TAILQ_INSERT_BEFORE,TAILQ_REMOVE,CIRCLEQ_HEAD,CIRCLEQ_ENTRY,
# CIRCLEQ_INIT,CIRCLEQ_INSERT_AFTER,CIRCLEQ_INSERT_BEFORE,
# CIRCLEQ_INSERT_HEAD,CIRCLEQ_INSERT_TAIL,CIRCLEQ_REMOVE
#
case $os in
FreeBSD)
cat <<-! >.notfunction
MAKE_SET
TEXT_SET
DATA_SET
BSS_SET
ABS_SET
SYSINIT
SYSINIT_KT
SYSINIT_KP
PSEUDO_SET
SYSCTL_OID
SYSCTL_NODE
SYSCTL_STRING
SYSCTL_INT
SYSCTL_OPAQUE
SYSCTL_STRUCT
SYSCTL_PROC
DOMAIN_SET
VFS_SET
MOD_DECL
MOD_SYSCALL
MOD_VFS
MOD_DEV
MOD_EXEC
MOD_MISC
VNODEOP_SET
GENSPL
SLIST_HEAD
SLIST_ENTRY
SLIST_INIT
SLIST_INSERT_AFTER
SLIST_INSERT_HEAD
SLIST_REMOVE_HEAD
SLIST_REMOVE
STAILQ_HEAD
STAILQ_ENTRY
STAILQ_INIT
STAILQ_INSERT_HEAD
STAILQ_INSERT_TAIL
STAILQ_INSERT_AFTER
STAILQ_REMOVE_HEAD
STAILQ_REMOVE
LIST_HEAD
LIST_ENTRY
LIST_INIT
LIST_INSERT_AFTER
LIST_INSERT_BEFORE
LIST_INSERT_HEAD
LIST_REMOVE
TAILQ_HEAD
TAILQ_ENTRY
TAILQ_EMPTY
TAILQ_FIRST
TAILQ_LAST
TAILQ_NEXT
TAILQ_PREV
TAILQ_INIT
TAILQ_INSERT_HEAD
TAILQ_INSERT_TAIL
TAILQ_INSERT_AFTER
TAILQ_INSERT_BEFORE
TAILQ_REMOVE
CIRCLEQ_HEAD
CIRCLEQ_ENTRY
CIRCLEQ_INIT
CIRCLEQ_INSERT_AFTER
CIRCLEQ_INSERT_BEFORE
CIRCLEQ_INSERT_HEAD
CIRCLEQ_INSERT_TAIL
CIRCLEQ_REMOVE
!
esac
#
# make global database(GTAGS, GRTAGS).
#
com="gtags -owv $dir > $dir/gtags.log 2>&1"
case $nflag in
1) echo "gtags -v $dir > $dir/gtags.log 2>&1";;
*) gtags -v $dir > $dir/gtags.log 2>&1;;
n) echo $com;;
*) eval $com;;
esac
case $? in
0) ;;
*) exit 1;;
esac
case $gflag in
g) exit 0;;
esac
#
# make hypertext.
# (please replace this title with a suitable one.)
#
case $os$release in
"") program=`/bin/pwd | sed 's/.*\///'`
title="Welcome to $program source tour!";;
*) title="Welcome to $os $release kernel source tour!";;
esac
if [ ${os}X != X -a ${release}X != X ]; then
title="Welcome to $os $release kernel source tour!"
else
program=`/bin/pwd | sed 's/.*\///'`
title="Welcome to $program source tour!"
fi
com="htags -${cflag}${fflag}lhnvat '$title' -d $dir $dir > $dir/htags.log 2>&1"
case $nflag in
1) echo "htags -fnvat '$title' -d $dir $dir > $dir/htags.log 2>&1";;
*) htags -fnvat "$title" -d $dir $dir> $dir/htags.log 2>&1;;
n) echo $com;;
*) eval $com;;
esac