Import of virgin Global v2_2_1 sources

This commit is contained in:
Chris Timmons 1997-12-15 23:08:46 +00:00
parent 43c4a137c1
commit dde39e507a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/global/dist/; revision=31750
74 changed files with 5575 additions and 696 deletions

View file

@ -3,6 +3,8 @@ GLOBAL history
version 1.0 initial version [21-Apr-96]
global, gtags, btreeop, extended ctags.
version 1.1 only bugfix [2-May-96]
[fixed bug]
@ -72,6 +74,12 @@ version 1.6 support of 1.76 nvi and reconstruction for other OS [21-Jan-97]
now GLOBAL includes BSD ctags in it. so no longer has
patch file (ctags.diff).
(I brought original ctags from FreeBSD 2.1.5R)
Thanks to
Gary Kline
Hideki Mori
for their advice.
global - -a option added.
version 1.7 make suitable for large project (mainly FreeBSD kernel) [17-Feb-97]
@ -143,14 +151,14 @@ version 1.9 support of 1.79 nvi and some additional options [21-Apr-97]
So, changed to convert tabs in source files into spaces.
(expand(1) needed)
Thanks to Andy Newman.
Thanks to Andy Newman for his bug report and fix method.
- cannot print error message correctly.
[changed]
gctags, btreeop
- modify for SunOS 4.1.3.
Thanks to Yoshiharu Ito.
Thanks to Yoshiharu Ito for his information.
[added]
btreeop - META record is available.
@ -192,12 +200,116 @@ version 2.0 Support of Emacs and CGI Form [7-Jul-97]
[deleted]
nvi-1.76.diff
[added]
gtags.el- added emacs support (emulation of 1.34 nvi)
htags - added hyperlink for include files.
- added checking if GTAGS is the latest one.
gtags.el- emacs support (emulation of 1.34 nvi) added.
htags - hyperlink for include files added.
- check if GTAGS is the latest one.
- -f option added.
With this option, you can use input form and dynamic
index. (You need to setup httpd server for it.)
- -n option added.
global - -f option added.
btreeop - -L option added.
version 2.1 Symbol search, incremental update and gozilla [20-Sep-97]
[changed]
gtags - -e option and -s option were deleted.
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.
Thanks to Jordan K. Hubbard. This is his idea.
gctags, btreeop
- remove <err.h> for portability. (Sorry, Philippe...)
btreeop - output procedure rewritten.
detab() + fprintf -> detab_print()
gtags, htags, global
- don't restrict PATH to '/bin:/usr/bin' like version 1.9
and the former.
[fixed bug]
gctags - cannot treat files which include '\r'.
Thanks to Christoph Conrad for his bug report.
- is disturbed by '_asm' statement.
- write buffer beyoned the end when source file doesn't
end with '\n'. It brings segmentation fault.
gtags.el- ESC-r command doesn't work.
htags - has a security hole in global.cgi.
btreeop - corrupt database when interrupted.
all command
- description of exit code in online manual is fixed.
[added]
gozilla
- new command.
gtags, gctags, global
- can locate specified symbol other than function name
using GSYMS tag file.
btreeop - support secondary key.
Optional key number added to -K option and -D option.
- -k option added.(prefix read)
global
- -g option added.(grep pattern)
Thanks to Hideaki Okada for his advice.
- -s option added.(symbol search)
- -i option added.(incremental update)
- -l option added.(search only under current directory)
- -v option added.(verbose mode)
gtags - -i option added.(incremental update)
- -v option added.(verbose mode)
- -o option added.(stop making GSYMS tag file)
gtags.el- gtags-find-symbol command (ESC-s) added.
It is equal to global's -s option.
- gtags-find-pattern command (ESC-g) added.
It is equal to global's -g option.
version 2.11 only bugfix [7-Nov-97]
[fixed bug]
htags, gtags
- cannot treat symbolic link.
Thanks to Yoshiharu Ito for his bug report.
Makefile.generic
- doens't work on Debian GNU/Linux.
Thanks to Y.Yoshinaga for his patch.
version 2.2 Rewritten with C for performance [7-Dec-97]
[changed]
gtags, global, gozilla
- rewritten with C.
global - adopted POSIX regular expression (extension) instead of
perl's one.
htags - shape up anchor database.
btreeop - some options (-b, -c, -l, -p) were deleted.
version 2.21 bugfix and slightly modified [11-Dec-97]
[fixed bug]
gtags, global
- doesn't skip RCS, SCCS, y.tab.c, y.tab.h.
global - generates illegal path name when using GTAGSLIBPATH
with -a option.
[changed]
lib/Makefile.generic
- MANDIR = /usr/share/man -> MANDIR = /usr/man
- replace `lorder $(OBJS) | tsort -q` to already sorted list.
for S.u.S.E Linux 5.1.
Thanks to Christoph Conrad for his information.
gtags, lib/test.c
- some change for Solaris environment.
Thanks to Yamashita TAKAO for his information.
htags/Makefile, systags/Makefile
- ${DESTDIR}/usr/bin -> ${DESTDIR}${BINDIR}

View file

@ -1,7 +1,7 @@
Installation of GLOBAL 2.0
Installation of GLOBAL 2.21
3-Jul-1997 Shigio Yamaguchi
11-Dec-1997 Shigio Yamaguchi
---------------------------------------------------------------------------
Guide line (C style)
---------------------------------------------------------------------------
@ -25,16 +25,17 @@ if (Your system == FreeBSD) {
Use 1.79 nvi available on the Internet.
break;
case 2.2.2R:
case 2.2.5R:
Your system inlucdes GLOBAL 1.9. You can overwrite it
with this 2.0 package.
with this 2.2 package.
But skip procedure "3. Extended vi (OPTIONAL)", because
your /usr/bin/nvi is already extended nvi for GLOBAL.
break;
default:
I don't know. But it semms to be little problem.
I don't know. But it seems to be little problem.
}
} else {
You may some error message to make GLOBAL.
You may some error messages to make GLOBAL.
But it seems not so difficult to clear it. If you make a patch for it,
please let me know. I would like to include your patch into new
version of GLOBAL.
@ -48,8 +49,8 @@ Install procedure
0. Extracting
% tar xzvf global-2.0.tar.gz
% cd global-2.0
% tar xzvf global-2.21.tar.gz
% cd global-2.21
1. Preparation for generic UNIX
@ -77,10 +78,26 @@ Install procedure
ftp://ftp.cis.ufl.edu/pub/perl/CPAN/src/5.0/latest.tar.gz
If you install perl into other than /usr/bin, please rewrite the header
of following commnads.
d) Rewrite some files
gtags/gtags.pl global/global.pl htags/htags.pl
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.
% grep '/usr/bin/global' */*.pl
If you install perl to other than /usr/bin, please rewrite hard coded
path in some programs. You can find the places by this command.
% grep '/usr/bin/perl' */*.pl
e) POSIX regular expression (extension) library
If you don't have it, you can use GNU's regex library.
f) Some UNIX tools
Find(1), sed(1), sort(1) are needed.
If your environment is UNIX, you have them.
2. GLOBAL basic (NEEDED)
@ -89,8 +106,9 @@ Install procedure
3. Extended vi (OPTIONAL)
GLOBAL supports two version of nvi. There is a little defference between
them when a number of functions located. (please see 'README' file.)
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
@ -132,17 +150,27 @@ Install procedure
You can get it from
Emacs 19.34b:
prep.ai.mit.edu/pub/gnu/emacs-19.34b.tar.gz
ftp://prep.ai.mit.edu/pub/gnu/emacs-19.34b.tar.gz
Mule 2.3:
ftp://ftp.cs.buffalo.edu/pub/mule/mule-2.3.tar.gz
If you are a FreeBSD user, install it from package.
If you are a FreeBSD user, install it from 'package' (see pkg_add(1)).
If you have installed it, to use extended emacs, copy gtags.el
in this package to the emacs lisp library directory or place the file
in a directory (for example "~/lisp") and write $HOME/.emacs like this.
If you have installed it then copy gtags.el in this package to the emacs
lisp library directory or place the file in a directory
(for example "~/lisp") and write $HOME/.emacs like this.
+-----------------------------------------------
|(setq load-path (cons "~/lisp" load-path))
5. Gozilla (OPTIONAL)
You need X(1) to install gozilla.
% cd gozilla
% xmkmf
% make
# make install
# make install.man
Good luck!

View file

@ -4,15 +4,16 @@ 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.
gctags/ Gctags command directory (extended ctags).
global/ Global command directory.
gozilla/ Gozilla command directory.
gtags/ Gtags command directory.
htags/ Htags command directory.
include/ include files for non BSD system.
systags/ Script for kernel.
gtags.el Gtags mode for Emacs
lib/ library.
gtags.el Gtags mode for Emacs.
nvi-1.34.diff Patch for nvi 1.34.
nvi-1.79.diff Patch for nvi 1.79.

View file

@ -1,3 +1,3 @@
SUBDIR= gctags global gtags btreeop htags systags
SUBDIR= lib global gtags gctags btreeop htags systags
.include <bsd.subdir.mk>

View file

@ -1,29 +1,22 @@
# @(#)Makefile 1-Mar-97
SUBDIR= gctags global gtags btreeop htags systags
SUBDIR= lib global gtags gctags btreeop htags systags
BINDIR= /usr/bin # EDIT THIS
MANDIR= /usr/share/man # EDIT THIS
# For FreeBSD contrib
CONTRIBDIR= /tmp/global
RMFILES=INSTALL Makefile.generic nvi-1.34.diff nvi-1.79.diff \
*/Makefile.generic */err.c include
MANDIR= /usr/man # EDIT THIS
all:
@for d in $(SUBDIR); do \
set -e; (cd $$d; echo '===>' $$d; make $(MFLAGS)) \
set -e; (cd $$d; echo '===>' $$d; make $(MFLAGS)) ;\
done
install:
@for d in $(SUBDIR); do \
set -e; (cd $$d; echo '===>' $$d; make $(MFLAGS) BINDIR=$(BINDIR) MANDIR=$(MANDIR) install) \
set -e; (cd $$d; echo '===>' $$d; make $(MFLAGS) BINDIR=$(BINDIR) MANDIR=$(MANDIR) install) ;\
done
gen:
@if [ ! -f Makefile.generic ]; then \
echo "Error: generic makefile not found."; exit 1; \
fi
mv Makefile Makefile.bsd; mv Makefile.generic Makefile
mv Makefile Makefile.bsd && mv Makefile.generic Makefile
for d in $(SUBDIR); do \
(cd $$d; mv Makefile Makefile.bsd; mv Makefile.generic Makefile) \
(cd $$d && mv Makefile Makefile.bsd && mv Makefile.generic Makefile) ;\
done
bsd:
@if [ ! -f Makefile.bsd ]; then \
@ -31,13 +24,10 @@ bsd:
fi
mv Makefile Makefile.generic; mv Makefile.bsd Makefile
for d in $(SUBDIR); do \
(cd $$d; mv Makefile Makefile.generic; mv Makefile.bsd Makefile) \
(cd $$d && mv Makefile Makefile.generic && mv Makefile.bsd Makefile) ;\
done
bsdcontrib: clean
rm -rf $(CONTRIBDIR)
mkdir $(CONTRIBDIR) && cp -r . $(CONTRIBDIR)
cd $(CONTRIBDIR) && rm -rf $(RMFILES)
clean:
@for d in $(SUBDIR); do \
(cd $$d; echo '===>' $$d; make $(MFLAGS) clean) \
(cd $$d; echo '===>' $$d; make $(MFLAGS) clean) ;\
done

View file

@ -1 +1,7 @@
BINDIR?= /usr/bin
MANDIR?= /usr/share/man/man
.if exists(${.OBJDIR}/../lib)
LIBUTIL=${.OBJDIR}/../lib/libutil.a
.else
LIBUTIL=${.CURDIR}/../lib/libutil.a
.endif

38
contrib/global/PROBLEMS Normal file
View file

@ -0,0 +1,38 @@
GLOBAL cannot recognize following macros and functions.
1. Macro which doesn't end with ';'.
GLOBAL cannot recognize func() after M(a), because M(a) seems to be
function definition.
#define M(a) static char *string = a;
M(a)
func() {
...
}
It should be follows.
#define M(a) static char *string = a
M(a);
func() {
...
}
2. Macro which is a renamed function.
#define func _func
_func() {
...
}
main() {
func();
}
In fact, main() calls _func() instead of func() but GLOBAL cannot
recognize it.

View file

@ -3,19 +3,30 @@
@= @=
@= @=
@= @= @@@@@= @@@@@@= @@= @=
@= F o r a l l h a c h e r s. version 2.0
@= F o r a l l h a c k e r s. version 2.21
@= @@@@@@=@= @= @= @@@@@= @= @= @=
@= @= @= @= @= @= @= @@@@@= @=
@= @= @= @= @= @= @=@= @= @=
@@@@@@@@= @@@@= @@@@@= @@@@@@=@@@= @@@@= @@@@@@=
Shigio Yamaguchi 7-Jul-97
Shigio Yamaguchi 11-Dec-97
Copyright 1996, 1997 Shigio Yamaguchi All right resereved.
----------------------------------------------------------
Note:
This version of GLOBAL makes 'GSYMS' tag file for
searching symbols other than functions.
(Try global(1) with -s option.)
But the tag file is very large. If you hope not to
make the file, please use gtags with -o (old) option.
Htags(1) doesn't use 'GSYMS'.
----------------------------------------------------------
GLOBAL is a browsing system for C and Yacc source code.
It brings benefits to all hackers. Enjoy!
Contents
--------------------------------
0. Introduction
@ -40,6 +51,7 @@ It brings benefits to all hackers. Enjoy!
3.2. Preparation
3.3. Usage
3.4. To make hypertext of kernel
3.5. Gozilla
4. Extended emacs using global
@ -64,7 +76,7 @@ It supports following environments.
o emacs editor(see '4. Emacs using global')
GLOBAL is consist of global(1), gtags(1), btreeop(1), gctags(1), htags(1),
extended vi(1) and gtags.el.
extended vi(1), gtags.el and gozilla(1).
* 'extended' means being entended for GLOBAL.
@ -85,7 +97,7 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'.
o Global allows duplicate entries.
o Global can treat a source tree containing subdirectories and you can
get relative path of objects from anywhere within the tree.
o Global can understand perl's regular expression.
o Global can understand POSIX 1003.2 regular expression (extension).
o Global can search in not only a source tree but also library paths.
o Global can treat yacc source file.
@ -109,9 +121,6 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'.
GTAGS - database for function definition
GRTAGS - database for function reference
If you cannot find functions that should exist, please try -e option.
% gtags -e
1.3. Basic usage
@ -162,7 +171,7 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'.
% global -r func2
../DIR1/fileA.c <- func2() is referred from fileA.c
You can use perl's regular expression.
You can use POSIX regular expression (extension).
% cd ROOT
% global 'func[1-3]'
@ -182,6 +191,11 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'.
% global -a func1
/home/user/ROOT/DIR1/fileB.c
-s option locates any symbols other than function.
% global -xs X
X 1 DIR2/fileC.c #ifdef X
You can edit files including specified function directly like this.
% vi `global func1` <- edit fileB.c
@ -319,8 +333,8 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'.
o Tag function of extended vi can locate not only function definitions
but also function references.
o Extended vi allows duplicate tag entries.
o Extended vi can understand perl's regular expression as a tag name
for search.
o Extended vi can understand POSIX regular expression (extension)
as a tag name for search.
o Extended vi is completely upper compatible with original one.
Above functions are available only in 'gtags mode'.
@ -488,15 +502,20 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'.
disk space. For example, the source code of FreeBSD kernel needs the
following disk space.
source code(/usr/src/sys) 14MB
tag database(GTAGS,GRTAGS) 9MB(!)
hypertext(HTML/*) 45MB(!!!)
source code(/usr/src/sys) 14.0MB
GTAGS 1.5MB
GRTAGS 8.0MB
GSYMS 12.0MB
HTML/ 55MB(!!!)
-------------------------------------------------
total 77MB
Please do the followings.
(at your source directory)
% gtags <- make tag database
% htags <- make hypertext
% gtags <- make tag database(GTAGS,GRTAGS,GSYMS)
% htags <- make hypertext(HTML/)
Then you will find 'HTML' directory in the current directory.
@ -535,6 +554,41 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'.
Of course, you can use above functions without systags.
Please see gtags(1), htags(1).
3.5. Gozilla
If you use Netscape Navigator, you can control the browser from command
line by gozilla(1).
% gtags
% htags
% global -x fork
fork 60 kern/kern_fork.c fork(p, uap, retval)
% gozilla +60 kern/kern_fork.c
%
Then you can see the hypertext about fork function directly on Netscape
Navigator. If the browser has not been loaded, gozilla loads it.
If you use another browser like lynx, try this.
% gozilla -b lynx +60 kern/kern_fork.c
or
% setenv BROWSER lynx
% gozilla +60 kern/kern_fork.c
You can send remote command to Netscape Navigator too. Try this.
% gozilla -C pagedown
% gozilla -C pageup
The remote commands are undocumented, but you can see the hint in the
resource file. (Netscape.ad file)
NOTES:
Netscape Navigator is a registered trademark of Netscape Communications
Corporation in the United States and other countries.
4. Extended emacs using global
@ -646,9 +700,18 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'.
":rtag <current token>[RETURN]", otherwise ":tag <current token>[RETURN]".
(GLOBAL decides this intelligentlly, but may sometimes misunderstand.)
o To go to any symbols other than function, try 'ESC-s'.
Find symbol: lbolt
~~~~~
o To go to any strings other than symbol, try 'ESC-g'.
Find pattern: Copyright
~~~~~~~~~
4.4. Applied usage
o You can use perl's regular expression.
o You can use POSIX regular expression (extension).
:tag ^put_ # locate tags start with 'put_'.

View file

@ -1 +1 @@
2.0
2.21

View file

@ -1,5 +1,6 @@
# @(#)Makefile 1.0 (Berkeley) 4/21/96
PROG= btreeop
CFLAGS+=-I${.CURDIR}/../lib
LDADD= $(LIBUTIL)
DPADD= $(LIBUTIL)
.include <bsd.prog.mk>

View file

@ -1,17 +1,15 @@
# @(#)Makefile 29-Dec-96
PROG = btreeop
CC = gcc
#WARN = -Wall -Wparentheses -Wstrict-prototypes -Wmissing-prototypes
LIBS = -ldb
CFLAGS = -O -I../include
OBJS = btreeop.o err.o
LIBS = -L../lib -lutil -ldb
CFLAGS = -O -I../lib -I/usr/include/db
DEPLIBS= ../lib/libutil.a
OBJS = btreeop.o
BINDIR = /usr/bin
MANDIR = /usr/share/man
MANDIR = /usr/man
all: $(PROG)
$(PROG): $(OBJS)
$(PROG): $(OBJS) $(DEPLIBS)
$(CC) -o $(PROG) $(OBJS) $(LIBS)
install:
cp $(PROG) $(BINDIR)
@ -19,4 +17,4 @@ install:
cp $(PROG).1 $(MANDIR)/man1
chmod 644 $(MANDIR)/man1/$(PROG).1
clean:
rm -f $(PROG) $(OBJS) GTAGS GRTAGS
rm -f $(PROG) $(OBJS)

View file

@ -28,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd July 4, 1997
.Dd Nov 26, 1997
.Dt BTREEOP 1
.Os BSD 4
.Sh NAME
@ -38,13 +38,10 @@
.Nm btreeop
.Op Fl A
.Op Fl C
.Op Fl D Ar key
.Op Fl K Ar key
.Op Fl D[keyno] Ar key
.Op Fl K[keyno] Ar key
.Op Fl L
.Op Fl b
.Op Fl c Ar cashesize
.Op Fl l
.Op Fl p Ar psize
.Op Fl k Ar prefix
.Op Ar dbname
.Sh DESCRIPTION
.Nm Btreeop
@ -52,9 +49,11 @@ execute simple operations for
.Xr btree 3
database.
.Nm Btreeop
can create database, write record, read record (sequential or index) and
can create database, write record, read record (sequential or indexed) and
delete record from it.
Duplicate entries are allowed.
Multi-key is available but only primary key can use index of
.Xr btree 3 .
.Sh OPTIONS
A capital letter means a command. If no command specified
then it assume sequential read operation.
@ -63,26 +62,25 @@ then it assume sequential read operation.
append records. If database doesn't exist, btreeop creates it.
.It Fl C
create database and write records to it.
.It Fl D Ar key
delete records by the key.
.It Fl K Ar key
search records by the key.
.It Fl D[keyno] Ar key
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 keys. It is identical to following command line.
list all primary keys.
Following two command lines are identical except that the latter is much faster.
btreeop | awk '{print $1}' | sort | uniq
.It Fl b
assume BIG_ENDIAN byte order. default is LITTLE_ENDIAN.
.It Fl c Ar cashesize
specify cashesize. It's identical to
.Nm info.cachesize
of BTREEINFO. (see btree(3))
.It Fl l
assume LITTLE_ENDIAN byte order. (the default)
.It Fl p Ar psize
specify page size. It's identical to
.Nm info.psize
of BTREEINFO. (see btree(3))
btreeop | awk '{print $1}' | uniq
btreeop -L
.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
@ -91,8 +89,11 @@ To creat (or append) database,
read data from stdin.
The format of the data is the following.
Key Data\\n
Key Data\\n
Primary-key Secondary-key-1 Secondary-key-2 Data
(keyno = 0) (keyno = 1) (keyno = 2)
--------------------------------------------------------------
main 246 main.c main (){\\n
func 120 library.c func(a1, a2)\\n
.
.
.
@ -101,16 +102,16 @@ The format of the data is the following.
.Bl -enum -offset indent
.It
Key and Data are separated by blank('\\t' or ' ').
All key and data are separated by blank('\\t' or ' ').
.It
Key cannot include blank.
.It
Data can include blank.
.It
Null Data not allowed.
Null data not allowed.
.It
Additionally, META record is available. META record has a key that start with
a blank. You can read this record only by indexed search (with -K option).
a blank. You can read this record only by indexed read operation (-K option).
Usage is unlimited by btreeop.
.El
.Sh EXAMPLES
@ -149,7 +150,7 @@ Indexed read.
__.VERSION 2
%
List kyes.
List primary keys.
% btreeop -L
key1
@ -170,7 +171,7 @@ default database name.
.El
.Sh DIAGNOSTICS
.Nm Btreeop
exits with a value of 1 if an error occurred, 0 otherwise.
exits with a non 0 value if an error occurred, 0 otherwise.
.Sh SEE ALSO
.Xr btree 3
.Sh AUTHOR
@ -178,4 +179,4 @@ Shigio Yamaguchi (shigio@wafu.netgate.net)
.Sh HISTORY
The
.Nm
command appeared in FreeBSD 2.2.
command appeared in FreeBSD 2.2.2.

View file

@ -28,132 +28,58 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* btreeop.c 6-Jul-97
* btreeop.c 6-Nov-97
*
*/
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <ctype.h>
#include <db.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <signal.h>
#include "global.h"
char *dbdefault = "btree"; /* default database name */
char *dbname;
char buf[BUFSIZ+1];
char out[BUFSIZ+1];
char *progname = "btreeop"; /* command name */
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
void die __P((char *));
static void usage __P((void));
void entab __P((char *));
void detab __P((char *, char *));
void signal_setup __P((void));
void onintr __P((int));
void main __P((int, char **));
void dbwrite __P((DB *));
void dbkey __P((DB *, char *));
void dbscan __P((DB *, int));
void dbdel __P((DB *, char *));
DB *db;
char *key;
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));
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234
#endif
#ifndef BIG_ENDIAN
#define BIG_ENDIAN 4321
#endif
void
die(s)
char *s;
{
errx(1, "%s", s);
}
#define F_KEY 0
#define F_DEL 1
static void
usage()
{
fprintf(stderr, "%s\n%s\n",
"usage: btreeop [-A][-C][-D key][-K key][-L][-b][-c cachesize]",
" [-l][-p psize][dbname]");
fprintf(stderr, "%s\n",
"usage: btreeop [-A][-C][-D[n] key][-K[n] key][-L][-k prefix][dbname]");
exit(1);
}
#define TABPOS(i) ((i)%8 == 0)
/*
* entab: convert spaces into tabs
*
* io) buf string buffer
* Btreeop catch signal even if the parent ignore it.
*/
void
entab(buf)
char *buf;
{
int blanks = 0;
int pos, src, dst;
char c;
int exitflag = 0;
pos = src = dst = 0;
while ((c = buf[src++]) != 0) {
if (c == ' ') {
if (!TABPOS(++pos)) {
blanks++; /* count blanks */
continue;
}
buf[dst++] = '\t';
} else if (c == '\t') {
while (!TABPOS(++pos))
;
buf[dst++] = '\t';
} else {
++pos;
while (blanks--)
buf[dst++] = ' ';
buf[dst++] = c;
}
blanks = 0;
}
buf[dst] = 0;
}
/*
* detab: convert tabs into spaces
*
* i) buf string including tabs
* o) out output
*/
void
detab(buf, out)
char *buf;
char *out;
onintr(signo)
int signo;
{
int src, dst;
char c;
src = dst = 0;
while ((c = buf[src++]) != 0) {
if (c == '\t') {
do {
out[dst++] = ' ';
} while (!TABPOS(dst));
} else {
out[dst++] = c;
}
}
out[dst] = 0;
exitflag = 1;
}
void
signal_setup()
{
signal(SIGHUP, onintr);
signal(SIGINT, onintr);
signal(SIGQUIT, onintr);
signal(SIGTERM, onintr);
}
#include <errno.h>
void
main(argc, argv)
int argc;
@ -161,27 +87,20 @@ char *argv[];
{
char command = 'R';
char *key = NULL;
DB *db;
BTREEINFO info;
int c;
int flags = 0;
extern char *optarg;
extern int optind;
int mode;
char *dbname;
DBIO *dbio;
int i, c;
int secondkey = 0;
char *prefix = (char *)0;
info.flags = R_DUP; /* allow duplicate entries */
info.cachesize = 500000;
info.maxkeypage = 0;
info.minkeypage = 0;
info.psize = 0;
info.compare = NULL;
info.prefix = NULL;
info.lorder = LITTLE_ENDIAN;
while ((c = getopt(argc, argv, "ACD:K:Lbc:lp:")) != -1) {
switch (c) {
case 'K':
for (i = 1; i < argc && argv[i][0] == '-'; ++i) {
switch (c = argv[i][1]) {
case 'D':
key = optarg;
case 'K':
if (argv[i][2] && isdigit(argv[i][2]))
secondkey = atoi(&argv[i][2]);
key = argv[++i];
case 'A':
case 'C':
case 'L':
@ -189,89 +108,79 @@ char *argv[];
usage();
command = c;
break;
case 'b':
info.lorder = BIG_ENDIAN;
break;
case 'c':
info.cachesize = atoi(optarg);
break;
case 'l':
info.lorder = LITTLE_ENDIAN;
break;
case 'p':
info.psize = atoi(optarg);
case 'k':
prefix = argv[++i];
break;
default:
usage();
}
}
dbname = (optind < argc) ? argv[optind] : dbdefault;
dbname = (i < argc) ? argv[i] : dbdefault;
switch (command) {
case 'A':
case 'D':
flags = O_RDWR|O_CREAT;
mode = 2;
break;
case 'C':
flags = O_RDWR|O_CREAT|O_TRUNC;
mode = 1;
break;
case 'K':
case 'L':
case 'R':
flags = O_RDONLY;
mode = 0;
break;
}
db = dbopen(dbname, flags, 0644, DB_BTREE, &info);
if (db == NULL) {
die("dbopen failed.");
}
dbio = db_open(dbname, mode, 0644, DBIO_DUP);
if (dbio == NULL)
die1("db_open failed (dbname = %s).", dbname);
switch (command) {
case 'A': /* Append records */
case 'C': /* Create database */
dbwrite(db);
dbwrite(dbio);
break;
case 'D': /* Delete records */
dbdel(db, key);
dbdel(dbio, key, secondkey);
break;
case 'K': /* Keyed (indexed) read */
dbkey(db, key);
dbkey(dbio, key, secondkey);
break;
case 'R': /* sequencial Read */
case 'L': /* key's List */
dbscan(db, (command == 'L') ? 1 : 0);
case 'L': /* primary key List */
dbscan(dbio, prefix, (command == 'L') ? 1 : 0);
break;
}
if (db->close(db)) {
die("db->close failed.");
}
db_close(dbio);
if (exitflag)
exit(1);
exit(0);
}
/*
* dbwrite: write to database
*
* i) db
* i) dbio database
*/
void
dbwrite(db)
DB *db;
dbwrite(dbio)
DBIO *dbio;
{
DBT key, dat;
int status;
#define IDENTLEN 80
char keybuf[IDENTLEN+1];
char *p;
char keybuf[MAXKEYLEN+1];
char *c;
signal_setup();
/*
* Input file format:
* +------------------
* |Key Data\n
* |Key Data\n
* +--------------------------------------------------
* |Primary-key secondary-key-1 secondary-key-2 Data\n
* |Primary-key secondary-key-1 secondary-key-2 Data\n
* .
* .
* - Key and Data are separated by blank('\t' or ' ').
* - Key cannot include blank.
* - Keys and Data are separated by blank('\t' or ' ').
* - Keys cannot include blank.
* - Data can include blank.
* - Null Data not allowed.
* - Null record not allowed.
* - Secondary-key is assumed as a part of data by db(3).
*
* META record:
* You can write meta record by making key start with a ' '.
@ -279,127 +188,151 @@ DB *db;
* +------------------
* | __.VERSION 2
*/
while (fgets(buf, BUFSIZ, stdin)) {
if (buf[strlen(buf)-1] == '\n') /* chop(buf) */
buf[strlen(buf)-1] = 0;
else
while (fgetc(stdin) != '\n')
;
c = buf;
while (p = mgets(stdin, 0, NULL)) {
if (exitflag)
break;
c = p;
if (*c == ' ') { /* META record */
if (*++c == ' ')
die("illegal format.");
die("key cannot include blanks.");
}
for (; *c && !isspace(*c); c++) /* skip key part */
;
if (*c == 0)
die("data part not found.");
if (c - buf > IDENTLEN)
die("key too long.");
strncpy(keybuf, buf, c - buf); /* make key string */
keybuf[c - buf] = 0;
if (c - p > MAXKEYLEN)
die("primary key too long.");
strncpy(keybuf, p, c - p); /* make key string */
keybuf[c - p] = 0;
for (; *c && isspace(*c); c++) /* skip blanks */
;
if (*c == 0)
die("data part is null.");
entab(buf);
key.data = keybuf;
key.size = strlen(keybuf)+1;
dat.data = buf;
dat.size = strlen(buf)+1;
status = (db->put)(db, &key, &dat, 0);
switch (status) {
case RET_SUCCESS:
break;
case RET_ERROR:
case RET_SPECIAL:
die("db->put: failed.");
}
entab(p);
db_put(dbio, keybuf, p);
}
}
/*
* dbkey: Keyed search
*
* i) db
* i) skey
* i) dbio database
* i) skey key for search
* i) secondkey 0: primary key, >0: secondary key
*/
void
dbkey(db, skey)
DB *db;
dbkey(dbio, skey, secondkey)
DBIO *dbio;
char *skey;
int secondkey;
{
DBT dat, key;
int status;
char *p;
key.data = skey;
key.size = strlen(skey)+1;
for (status = (*db->seq)(db, &key, &dat, R_CURSOR);
status == RET_SUCCESS && !strcmp(key.data, skey);
status = (*db->seq)(db, &key, &dat, R_NEXT)) {
detab((char *)dat.data, out);
(void)fprintf(stdout, "%s\n", out);
if (!secondkey) {
for (p = db_first(dbio, skey, 0); p; p = db_next(dbio))
detab(stdout, p);
return;
}
if (status == RET_ERROR)
die("db->seq failed.");
dbbysecondkey(dbio, F_KEY, skey, secondkey);
}
/*
* dbscan: Scan all records
* dbscan: Scan records
*
* i) db
* i) keylist
* i) dbio database
* i) prefix prefix of primary key
* i) keylist 0: key and data, 1: primary key only
*/
void
dbscan(db, keylist)
DB *db;
dbscan(dbio, prefix, keylist)
DBIO *dbio;
char *prefix;
int keylist;
{
DBT dat, key;
int status;
char prev[IDENTLEN+1];
char *p;
int flags = DBIO_SKIPMETA;
prev[0] = 0;
for (status = (*db->seq)(db, &key, &dat, R_FIRST);
status == RET_SUCCESS;
status = (*db->seq)(db, &key, &dat, R_NEXT)) {
/* skip META record */
if (*(char *)key.data == ' ')
continue;
if (keylist) {
if (!strcmp(prev, (char *)key.data))
continue;
strcpy(prev, (char *)key.data);
(void)fprintf(stdout, "%s\n", (char *)key.data);
continue;
}
detab((char *)dat.data, out);
(void)fprintf(stdout, "%s\n", out);
}
if (status == RET_ERROR)
die("db->seq failed.");
if (prefix)
flags |= DBIO_PREFIX;
if (keylist)
flags |= DBIO_KEY;
for (p = db_first(dbio, prefix, flags); p; p = db_next(dbio))
detab(stdout, p);
}
/*
* dbdel: Delete records
*
* i) db
* i) skey key
* i) dbio database
* i) skey key for search
* i) secondkey 0: primary key, >0: secondary key
*/
void
dbdel(db, skey)
DB *db;
dbdel(dbio, skey, secondkey)
DBIO *dbio;
char *skey;
int secondkey;
{
DBT key;
int status;
key.data = skey;
key.size = strlen(skey)+1;
status = (*db->del)(db, &key, 0);
if (status == RET_ERROR)
die("db->del failed.");
signal_setup();
if (!secondkey) {
db_del(dbio, skey);
return;
}
dbbysecondkey(dbio, F_DEL, skey, secondkey);
}
/*
* dbbysecondkey: proc by second key
*
* i) dbio database
* i) func F_KEY, F_DEL
* i) skey
* i) secondkey
*/
void
dbbysecondkey(dbio, func, skey, secondkey)
DBIO *dbio;
int func;
char *skey;
int secondkey;
{
char *c, *p;
int i;
/* trim skey */
for (c = skey; *c && isspace(*c); c++)
;
skey = c;
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)) {
if (exitflag)
break;
c = p;
/* reach to specified key */
for (i = secondkey; i; i--) {
for (; *c && !isspace(*c); c++)
;
if (*c == 0)
die("specified key not found.");
for (; *c && isspace(*c); c++)
;
if (*c == 0)
die("specified key not found.");
}
i = strlen(skey);
if (!strncmp(c, skey, i) && (*(c+i) == 0 || isspace(*(c+i)))) {
switch (func) {
case F_KEY:
detab(stdout, p);
break;
case F_DEL:
db_del(dbio, NULL);
break;
}
}
if (exitflag)
break;
}
}

View file

@ -46,7 +46,7 @@ static int func_entry __P((void));
static void hash_entry __P((void));
static void skip_string __P((int));
static int str_entry __P((int));
#ifdef GTAGS
#ifdef GLOBAL
static int cmp __P((const void *, const void *));
static int isstatement __P((char *));
static void define_line __P((void));
@ -116,7 +116,7 @@ c_entries()
*/
if (--level < 0)
level = 0;
#ifdef GTAGS
#ifdef GLOBAL
/*
* -e flag force a function to end when a '}' appear
* at column 0. If -e flag not specified, all functions
@ -192,7 +192,7 @@ c_entries()
/*
* if we have a current token, parenthesis on
* level zero indicates a function.
#ifdef GTAGS
#ifdef GLOBAL
* in the case of rflag == 1, if we have a current token,
* parenthesis on level > zero indicates a function reference.
#endif
@ -201,10 +201,14 @@ c_entries()
#endif
*/
case '(':
#ifdef GLOBAL
if (sflag)
break;
#endif
#ifdef YACC
if (inyacc == NO)
#endif
#ifdef GTAGS
#ifdef GLOBAL
if (!rflag && !level && token)
#else
if (!level && token)
@ -222,7 +226,7 @@ c_entries()
*/
getline();
curline = lineno;
#ifdef GTAGS
#ifdef GLOBAL
/* to make sure. */
if (!isstatement(tok))
#endif
@ -232,13 +236,14 @@ c_entries()
}
break;
}
#ifdef GTAGS
#ifdef GLOBAL
else if (rflag && level && token) {
if (sp != tok)
*sp = EOS;
getline();
if (!isstatement(tok) && isdefined(tok))
if (!isstatement(tok) && lookup(tok)) {
getline();
pfnote(tok, lineno);
}
break;
}
#endif
@ -305,13 +310,7 @@ c_entries()
* reserved words.
*/
default:
#ifdef BUGFIX
/*
* to treat following function.
* func (arg) {
* ....
* }
*/
/* ignore whitespace */
if (c == ' ' || c == '\t') {
int save = c;
while (GETC(!=, EOF) && (c == ' ' || c == '\t'))
@ -321,12 +320,39 @@ c_entries()
(void)ungetc(c, inf);
c = save;
}
#endif
storec: if (!intoken(c)) {
if (sp == tok)
break;
*sp = EOS;
#ifdef GTAGS
#ifdef GLOBAL
/* ignore assembler in C source */
if (!memcmp(tok, "_asm",4)) {
while (GETC(!=, EOF) && (c == ' ' || c == '\t'))
;
if (c == EOF)
return;
if (c == '{') {
while (GETC(!=, EOF) && c != '}') {
if (c == '\n')
SETLINE;
}
} else {
while (GETC(!=, EOF) && c != '\n')
;
if (c == '\n')
SETLINE;
}
if (c == EOF)
return;
break;
}
if (sflag) {
if (!isstatement(tok)) {
getline();
pfnote(tok, lineno);
}
break;
}
if (!memcmp(tok, "extern",7)) {
while (GETC(!=, EOF) && c != ';') {
if (c == '\n')
@ -367,6 +393,18 @@ c_entries()
*sp++ = c;
token = YES;
}
#ifdef GLOBAL
/* skip hex number */
else if (sp == tok && c == '0') {
if (GETC(==, 'x') || c == 'X') {
while (GETC(!=, EOF) && isxdigit(c))
;
if (c == EOF)
return;
}
(void)ungetc(c, inf);
}
#endif
continue;
/* end of default */
} /* end of switch */
@ -454,15 +492,10 @@ hash_entry()
char *sp; /* buffer pointer */
char tok[MAXTOKEN]; /* storage buffer */
#ifdef BUGFIX
/*
* to treat following macro.
* # macro(arg) ....
*/
/* ignore leading whitespace */
while (GETC(!=, EOF) && (c == ' ' || c == '\t'))
;
(void)ungetc(c, inf);
#endif
curline = lineno;
for (sp = tok;;) { /* get next token */
if (GETC(==, EOF))
@ -472,8 +505,16 @@ hash_entry()
*sp++ = c;
}
*sp = EOS;
#ifdef GLOBAL
if (sflag && memcmp(tok, "include", 7)) {
(void)ungetc(c, inf);
define_line();
return;
}
#endif
if (memcmp(tok, "define", 6)) /* only interested in #define's */
goto skip;
for (;;) { /* this doesn't handle "#define \n" */
if (GETC(==, EOF))
return;
@ -492,12 +533,12 @@ hash_entry()
break;
}
*sp = EOS;
#ifdef GTAGS
#ifdef GLOBAL
if (rflag) {
/*
* #define XXX\n
*/
if (c == '\n' || (c == '\r' && GETC(==, '\n'))) {
if (c == '\n') {
SETLINE;
return;
}
@ -531,19 +572,13 @@ hash_entry()
}
skip: if (c == '\n') { /* get rid of rest of define */
SETLINE
#ifdef MODIFY
if (*(sp - 1) == '\r') {
if (*(sp - 2) != '\\')
return;
} else
#endif
if (*(sp - 1) != '\\')
return;
}
(void)skip_key('\n');
}
#ifdef GTAGS
#ifdef GLOBAL
/* sorted by alphabet */
static struct words {
char *name;
@ -619,12 +654,20 @@ define_line()
goto endtok;
case '\\':
if (GETC(==, '\n') || (c == '\r' && GETC(==, '\n'))) {
if (GETC(==, '\n')) {
SETLINE;
}
continue;
case '\n':
if (sflag && token) {
if (sp != tok)
*sp = EOS;
if (!isstatement(tok)) {
getline();
pfnote(tok, lineno);
}
}
SETLINE;
return;
endtok: if (sp > tok) {
@ -651,11 +694,13 @@ define_line()
goto storec;
case '(':
if (sflag)
break;
if (token) {
if (sp != tok)
*sp = EOS;
getline();
if (!isstatement(tok) && isdefined(tok))
if (!isstatement(tok) && lookup(tok))
pfnote(tok, lineno);
break;
}
@ -670,6 +715,13 @@ storec: if (!intoken(c)) {
break;
*sp = EOS;
sp = tok;
if (sflag) {
if (!isstatement(tok)) {
getline();
pfnote(tok, lineno);
}
break;
}
}
else if (sp != tok || begtoken(c)) {
*sp++ = c;
@ -774,10 +826,6 @@ skip_string(key)
case '\\': /* a backslash escapes anything */
skip = !skip; /* we toggle in case it's "\\" */
break;
#ifdef MODIFY
case '\r':
break;
#endif
case '\n':
SETLINE;
/*FALLTHROUGH*/
@ -823,10 +871,6 @@ skip_key(key)
(void)ungetc(c, inf);
c = '/';
goto norm;
#ifdef MODIFY
case '\r':
break;
#endif
case '\n':
SETLINE;
/*FALLTHROUGH*/

View file

@ -1,7 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= gctags
CFLAGS+=-I${.CURDIR} -DGTAGS -DBUGFIX -DMODIFY -DYACC
CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../lib -DGLOBAL -DYACC
LDADD= $(LIBUTIL)
DPADD= $(LIBUTIL)
SRCS= C.c ctags.c fortran.c lisp.c print.c tree.c yacc.c assembler.c
.include <bsd.prog.mk>

View file

@ -1,14 +1,11 @@
# @(#)Makefile 29-Dec-96
PROG = gctags
DEFS = -DGTAGS -DBUGFIX -DMODIFY -DYACC
DEFS = -DGLOBAL -DYACC
CC = gcc
#WARN = -Wall -Wparentheses -Wstrict-prototypes -Wmissing-prototypes
CFLAGS = -O $(DEFS) -I../include
LIBS = -ldb
OBJS = C.o ctags.o fortran.o lisp.o print.o tree.o yacc.o assembler.o err.o
CFLAGS = -O $(DEFS) -I../lib -I/usr/include/db
LIBS = -L../lib -lutil -ldb
OBJS = C.o assembler.o ctags.o fortran.o lisp.o print.o tree.o yacc.o
BINDIR = /usr/bin
MANDIR = /usr/share/man
MANDIR = /usr/man
all: $(PROG)
@ -20,4 +17,4 @@ install:
cp $(PROG).1 $(MANDIR)/man1
chmod 644 $(MANDIR)/man1/$(PROG).1
clean:
rm -f $(PROG) $(OBJS) GTAGS GRTAGS
rm -f $(PROG) $(OBJS)

View file

@ -39,7 +39,7 @@ static char sccsid[] = "@(#)assembler.c 8.3 (Berkeley) 6/6/97";
#include <string.h>
#include "ctags.h"
#ifdef GTAGS
#ifdef GLOBAL
void
asm_entries()
{

View file

@ -42,7 +42,6 @@ static const char rcsid[] =
"$Id: ctags.c,v 1.3 1997/07/10 06:43:40 charnier Exp $";
#endif /* LIBC_SCCS and not lint */
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
@ -50,6 +49,10 @@ static const char rcsid[] =
#include <unistd.h>
#include "ctags.h"
#ifdef GLOBAL
#include "lookup.h"
#include "die.h"
#endif
/*
* ctags: create a tags file
@ -66,17 +69,21 @@ FILE *outf; /* ioptr for tags file */
long lineftell; /* ftell after getc( inf ) == '\n' */
int lineno; /* line number of current line */
#ifdef GLOBAL
int cflag; /* -c: compact index */
#endif
int dflag; /* -d: non-macro defines */
#ifdef GTAGS
#ifdef GLOBAL
int eflag; /* -e: '{' at 0 column force function end */
#endif
int tflag; /* -t: create tags for typedefs */
int vflag; /* -v: vgrind style index output */
int wflag; /* -w: suppress warnings */
int xflag; /* -x: cxref style output */
#ifdef GTAGS
#ifdef GLOBAL
int Dflag; /* -D: allow duplicate entrys */
int rflag; /* -r: function reference */
int sflag; /* -s: collect symbols */
#endif
#ifdef YACC
int yaccfile; /* yacc file */
@ -85,6 +92,7 @@ int yaccfile; /* yacc file */
char *curfile; /* current input file name */
char searchar = '/'; /* use /.../ searches by default */
char lbuf[LINE_MAX];
char *progname = "gctags"; /* program name */
void init __P((void));
void find_entries __P((char *));
@ -107,8 +115,8 @@ main(argc, argv)
extern int optind;
aflag = uflag = NO;
#ifdef GTAGS
while ((ch = getopt(argc, argv, "BDFadef:rtuwvxy")) != -1)
#ifdef GLOBAL
while ((ch = getopt(argc, argv, "BDFacdef:rstuwvx")) != -1)
#else
while ((ch = getopt(argc, argv, "BFadf:tuwvx")) != -1)
#endif
@ -116,7 +124,7 @@ main(argc, argv)
case 'B':
searchar = '?';
break;
#ifdef GTAGS
#ifdef GLOBAL
case 'D':
Dflag++;
break;
@ -124,13 +132,23 @@ main(argc, argv)
case 'F':
searchar = '/';
break;
#ifdef GLOBAL
case 's':
sflag++;
break;
#endif
case 'a':
aflag++;
break;
#ifdef GLOBAL
case 'c':
cflag++;
break;
#endif
case 'd':
dflag++;
break;
#ifdef GTAGS
#ifdef GLOBAL
case 'e':
eflag++;
break;
@ -138,7 +156,7 @@ main(argc, argv)
case 'f':
outfile = optarg;
break;
#ifdef GTAGS
#ifdef GLOBAL
case 'r':
rflag++;
break;
@ -165,15 +183,22 @@ main(argc, argv)
argc -= optind;
if (!argc)
usage();
#ifdef GTAGS
if (rflag)
gtagopen();
#ifdef GLOBAL
if (sflag && rflag)
die("-s and -r conflict.");
if (rflag) {
char *dbpath;
if (!(dbpath = getenv("GTAGSDBPATH")))
dbpath = ".";
lookupopen(dbpath);
}
#endif
init();
for (exit_val = step = 0; step < argc; ++step)
if (!(inf = fopen(argv[step], "r"))) {
warnx("%s cannot open", argv[step]);
fprintf(stderr, "%s: %s cannot open\n", progname, argv[step]);
exit_val = 1;
}
else {
@ -183,9 +208,13 @@ main(argc, argv)
}
if (head)
if (xflag)
if (xflag) {
put_entries(head);
else {
#ifdef GLOBAL
if (cflag)
compact_print("", 0, "");/* flush last record */
#endif
} else {
if (uflag) {
for (step = 0; step < argc; step++) {
(void)sprintf(cmd,
@ -197,7 +226,7 @@ main(argc, argv)
++aflag;
}
if (!(outf = fopen(outfile, aflag ? "a" : "w"))) {
warnx("%s cannot open", outfile);
fprintf(stderr, "%s: %s cannot open\n", progname, outfile);
exit(exit_val);
}
put_entries(head);
@ -208,9 +237,9 @@ main(argc, argv)
system(cmd);
}
}
#ifdef GTAGS
#ifdef GLOBAL
if (rflag)
gtagclose();
lookupclose();
#endif
exit(exit_val);
}
@ -219,10 +248,10 @@ static void
usage()
{
(void)fprintf(stderr,
#ifdef GTAGS
"usage: gctags [-BDFadrtuwvx] [-f tagsfile] file ...\n");
#ifdef GLOBAL
"usage: gctags [-BDFacderstuvwx] [-f tagsfile] file ...\n");
#else
"usage: gctags [-BFadtuwvx] [-f tagsfile] file ...\n");
"usage: ctags [-BFadtuwvx] [-f tagsfile] file ...\n");
#endif
exit(1);
}
@ -280,7 +309,7 @@ find_entries(file)
if (cp[1] == 'l' && !cp[2]) {
int c;
#ifdef GTAGS
#ifdef GLOBAL
if (rflag)
fprintf(stderr, "-r option is ignored in lisp file (Warning only)\n");
#endif
@ -327,14 +356,14 @@ find_entries(file)
pfnote("yyparse", lineno);
y_entries();
}
#ifdef GTAGS
#ifdef GLOBAL
/* assembler */ else if ((cp[1] == 's' || cp[1] == 'S') && !cp[2]) {
asm_entries();
return;
}
#endif
/* fortran */ else if ((cp[1] != 'c' && cp[1] != 'h') && !cp[2]) {
#ifdef GTAGS
#ifdef GLOBAL
if (rflag)
fprintf(stderr, "-r option is ignored in fortran file (Warning only)\n");
#endif
@ -348,63 +377,3 @@ find_entries(file)
#endif
/* C */ c_entries();
}
#ifdef GTAGS
#include <db.h>
DB *db;
void
gtagopen()
{
BTREEINFO info;
char *env;
char dbname[200];
strcpy(dbname, ".");
if ((env = getenv("GTAGDBPATH"))) {
strcpy(dbname, env);
}
strcat(dbname, "/GTAGS");
info.flags = 0;
info.cachesize = 500000;
info.maxkeypage = 0;
info.minkeypage = 0;
info.psize = 0;
info.compare = 0;
info.prefix = 0;
info.lorder = 0;
#define O_RDONLY 0x0000 /* open for reading only */
db = dbopen(dbname, O_RDONLY, 0, DB_BTREE, &info);
if (db == 0)
errx(1, "GTAGS file needed");
}
int
isdefined(skey)
char *skey;
{
DBT dat, key;
int status;
key.data = skey;
key.size = strlen(skey)+1;
status = (*db->get)(db, &key, &dat, 0);
switch (status) {
case RET_SUCCESS:
return(1); /* exist */
case RET_ERROR:
errx(1, "db->get failed");
case RET_SPECIAL: /* not exist */
break;
}
return 0;
}
void
gtagclose()
{
if (db->close(db))
errx(1, "GTAGS cannot close.(dbclose)");
}
#endif

View file

@ -47,7 +47,11 @@
#endif
#define SETLINE {++lineno;lineftell = ftell(inf);}
#ifdef GLOBAL
#define GETC(op,exp) ((((c = getc(inf)) == '\r') ? (c = getc(inf)) : c) op (int)exp)
#else
#define GETC(op,exp) ((c = getc(inf)) op (int)exp)
#endif
#define iswhite(arg) (_wht[(unsigned)arg]) /* T if char is white */
#define begtoken(arg) (_btk[(unsigned)arg]) /* T if char can start token */
@ -71,11 +75,13 @@ extern FILE *inf; /* ioptr for current input file */
extern FILE *outf; /* ioptr for current output file */
extern long lineftell; /* ftell after getc( inf ) == '\n' */
extern int lineno; /* line number of current line */
#ifdef GTAGS
#ifdef GLOBAL
extern int cflag; /* -c: compact index */
extern int eflag; /* -e: '{' at 0 column force function end */
extern int Dflag; /* -D: allow duplicate entrys */
extern int rflag; /* -r: function reference */
#endif /* GTAGS */
extern int sflag; /* -s: collect symbols */
#endif
extern int dflag; /* -d: non-macro defines */
extern int tflag; /* -t: create tags for typedefs */
extern int vflag; /* -v: vgrind style index output */
@ -85,6 +91,7 @@ extern bool _wht[], _etk[], _itk[], _btk[], _gd[];
extern char lbuf[LINE_MAX];
extern char *lbp;
extern char searchar; /* ex search character */
extern char *progname; /* program name */
#ifndef __P
#ifdef __STDC__
@ -105,9 +112,7 @@ void y_entries __P((void));
int PF_funcs __P((void));
void c_entries __P((void));
void skip_comment __P((void));
#ifdef GTAGS
#ifdef GLOBAL
void asm_entries __P((void));
void gtagopen __P((void));
int isdefined __P((char *));
void gtagclose __P((void));
int portable_getc __P((FILE *));
#endif

View file

@ -39,7 +39,7 @@
.Nd create a tags file (special command for GLOBAL)
.Sh SYNOPSIS
.Nm gctags
.Op Fl BDFadertuwvx
.Op Fl BDFacderstuvwx
.Op Fl f Ar tagsfile
.Ar name ...
.Sh DESCRIPTION
@ -77,6 +77,8 @@ use forward searching patterns
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
@ -88,11 +90,13 @@ 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 behavior is to place them in a file called
The default behaviour is to place them in a file called
.Ar tags .
.It Fl r
locate function references instead of function definitions. GTAGS file is
needed at the current directory. (C source only)
.It Fl s
collect symbols except for functions.
.It Fl t
create tags for typedefs, structs, unions, and enums.
.It Fl u
@ -184,7 +188,7 @@ tags file for GLOBAL
.El
.Sh DIAGNOSTICS
.Nm Gctags
exits with a value of 1 if an error occurred, 0 otherwise.
exits with a non 0 value if an error occurred, 0 otherwise.
Duplicate objects are not considered errors.
.Sh SEE ALSO
.Xr btreeop 1 ,
@ -234,4 +238,4 @@ kernel source.
.Sh HISTORY
The
.Nm
command appeared in FreeBSD 2.2.
command appeared in FreeBSD 2.2.2.

View file

@ -41,6 +41,7 @@ static char sccsid[] = "@(#)print.c 8.3 (Berkeley) 4/2/94";
#include <string.h>
#include <unistd.h>
#include "die.h"
#include "ctags.h"
/*
@ -59,7 +60,7 @@ getline()
saveftell = ftell(inf);
(void)fseek(inf, lineftell, SEEK_SET);
if (xflag)
for (cp = lbuf; GETC(!=, '\n'); *cp++ = c)
for (cp = lbuf; GETC(!=, EOF) && c != '\n'; *cp++ = c)
continue;
/*
* do all processing here, so we don't step through the
@ -89,7 +90,58 @@ getline()
*cp = EOS;
(void)fseek(inf, saveftell, SEEK_SET);
}
#ifdef GLOBAL
void
compact_print(entry, lno, file)
char *entry;
int lno;
char *file;
{
static int first = 1;
static char p_entry[128];
static char p_file[1024];
static int p_lno;
static char *buf;
static int bufsize = 512;
static char *p;
if (first) {
if (!(buf = (char *)malloc(bufsize)))
die("short of memory.");
buf[0] = 0;
p = buf;
first = 0;
}
if (strcmp(p_entry, entry) || strcmp(p_file, file)) {
if (buf[0])
printf("%s\n", buf);
if (!entry[0]) /* flush */
return;
strcpy(p_entry, entry);
strcpy(p_file, file);
p_lno = lno;
buf[0] = 0;
sprintf(buf, "%s %s %d", entry, file, lno);
p = buf;
p += strlen(p);
} else {
if (p_lno > lno)
die("impossible!");
if (p_lno < lno) {
if (buf + bufsize < p + 10) {
int offset = p - buf;
bufsize *= 2;
if (!(buf = (char *)realloc(buf, bufsize)))
die("short of memory.");
p = buf + offset;
}
sprintf(p, ",%d", lno);
p += strlen(p);
p_lno = lno;
}
}
}
#endif
/*
* put_entries --
* write out the tags
@ -104,8 +156,12 @@ put_entries(node)
if (vflag)
printf("%s %s %d\n",
node->entry, node->file, (node->lno + 63) / 64);
#ifdef GLOBAL
else if (xflag && cflag)
compact_print(node->entry, node->lno, node->file);
#endif
else if (xflag)
#ifdef MODIFY
#ifdef GLOBAL
/* separate 'entry' and 'lno' */
if (strlen(node->entry) >= 16 && node->lno >= 1000)
printf("%-16s %4d %-16s %s\n",

View file

@ -35,12 +35,12 @@
static char sccsid[] = "@(#)tree.c 8.3 (Berkeley) 4/2/94";
#endif /* LIBC_SCCS and not lint */
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "die.h"
#include "ctags.h"
static void add_node __P((NODE *, NODE *));
@ -61,12 +61,12 @@ pfnote(name, ln)
/*NOSTRICT*/
if (!(np = (NODE *)malloc(sizeof(NODE)))) {
warnx("too many entries to sort");
fprintf(stderr, "too many entries to sort\n");
put_entries(head);
free_tree(head);
/*NOSTRICT*/
if (!(head = np = (NODE *)malloc(sizeof(NODE))))
errx(1, "out of space");
die("out of space");
}
if (!xflag && !strcmp(name, "main")) {
if (!(fp = strrchr(curfile, '/')))
@ -80,12 +80,12 @@ pfnote(name, ln)
name = nbuf;
}
if (!(np->entry = strdup(name)))
errx(1, "out of space");
die("out of space");
np->file = curfile;
np->lno = ln;
np->left = np->right = 0;
if (!(np->pat = strdup(lbuf)))
errx(1, "out of space");
die("out of space");
if (!head)
head = np;
else
@ -100,7 +100,7 @@ add_node(node, cur_node)
int dif;
dif = strcmp(node->entry, cur_node->entry);
#ifdef GTAGS
#ifdef GLOBAL
if (!Dflag && !dif) /* -D option allows duplicate entries. */
#else
if (!dif)

View file

@ -1,9 +1,6 @@
# @(#)Makefile 1.0 (Berkeley) 4/21/96
MAN1= global.1
beforeinstall:
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${.CURDIR}/global.pl ${DESTDIR}/usr/bin/global
PROG= global
CFLAGS+=-I${.CURDIR}/../lib
LDADD= $(LIBUTIL)
DPADD= $(LIBUTIL)
.include <bsd.prog.mk>

View file

@ -1,13 +1,20 @@
# @(#)Makefile 29-Dec-96
PROG = global
CC = gcc
LIBS = -L../lib -lutil -ldb
CFLAGS = -O -I../lib -I/usr/include/db
DEPLIBS= ../lib/libutil.a
OBJS = global.o
BINDIR = /usr/bin
MANDIR = /usr/share/man
MANDIR = /usr/man
all:
all: $(PROG)
$(PROG): $(OBJS) $(DEPLIBS)
$(CC) -o $(PROG) $(OBJS) $(LIBS)
install:
cp $(PROG).pl $(BINDIR)/$(PROG)
cp $(PROG) $(BINDIR)
chmod 755 $(BINDIR)/$(PROG)
cp $(PROG).1 $(MANDIR)/man1
chmod 644 $(MANDIR)/man1/$(PROG).1
clean:
rm -f $(PROG) $(OBJS)

View file

@ -28,66 +28,92 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd April 21, 1997
.Dd Nov 26, 1997
.Dt GLOBAL 1
.Os BSD 4
.Sh NAME
.Nm global
.Nd print the locations of specified function.
.Nd print the locations of specified object.
.Sh SYNOPSIS
.Nm global
.Op Fl arx
.Ar name
.Op Fl alrvx
.Ar pattern
.Nm global -c
.Op Ar name
.Op Ar prefix
.Nm global
.Op Fl a
.Fl f
.Fl f[arx]
.Ar file
.Nm global
.Fl g[alvx]
.Ar pattern
.Nm global
.Fl i[v]
.Nm global
.Fl p
.Nm global
.Fl s[alvx]
.Ar pattern
.Sh DESCRIPTION
.Nm Global
find the locations of specified function in C and Yacc source files.
find the locations of specified object in C and Yacc source files.
.Nm Global
can treat a source tree, that is, a directory that has subdirectories and
source files.
You can get the relative path of objects from anywhere within the tree.
.Nm Global
can locate not only function definitions but also function references and
allow duplicate entries too.
other symbols.
Duplicate entries are allowed.
.Pp
In advance of using this command, you must execute
.Xr gtags 1
at the root directory of the source tree.
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:
.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.
.It Fl c Op Ar name
.It Fl c Op Ar prefix
print candidate function names which start with specified
.Ar name .
.Ar prefix .
If
.Ar name
.Ar prefix
is not specified, print all function names.
.It Fl f Ar file
print all function definitions in the
.Ar file .
This option implies -x option.
.It Fl g
print all lines which match to the pattern.
.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.
.It Fl p
print the location of GTAGS.
.It Fl s
print the locations of specified symbol other than function names.
You need GSYMS tags file. See
.Xr gtags 1 .
.It Fl x
In addition to the default output, produce the line number and
the line contents.
.It Ar name
function name. It can include perl's regular expression.
.Sh FILES
.Bl -tag -width tags -compact
.It Pa GTAGS
tags file for function definitions.
.It Pa GRTAGS
tags file for function references.
.It Pa GSYMS
tags file for symbols other then functions.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of global.
@ -138,12 +164,12 @@ global search in these path too.
exits with a non 0 value if an error occurred, 0 otherwise.
.Sh SEE ALSO
.Xr btreeop 1 ,
.Xr gctags 1 ,
.Xr gtags 1 ,
.Xr htags 1 .
.Xr htags 1 ,
.Xr vi 1 .
.Sh AUTHORS
Shigio Yamaguchi (shigio@wafu.netgate.net)
.Sh HISTORY
The
.Nm
command appeared in FreeBSD 2.2.
command appeared in FreeBSD 2.2.2.

View file

@ -0,0 +1,746 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* global.c 7-Nov-97
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <regex.h>
#include "global.h"
char *progname = "global"; /* command name */
static void usage __P((void));
void main __P((int, char **));
char *outfilter __P(());
void completelist __P((char *, char *));
void relative_filter __P((char *, char *, char *));
void grep __P((char *));
int printtag __P((FILE *, char *, char *, int));
int regexp __P((char *));
int search __P((char *, char *, char *, char *, int));
char *extractpath __P((char *));
int includepath __P((char *, char *));
char sortfilter[MAXCOMLINE+1]; /* sort filter */
char pathfilter[MAXCOMLINE+1]; /* path convert filter */
char local[MAXPATHLEN+1]; /* local prefix */
char *localprefix; /* local prefix */
int aflag; /* [option] */
int cflag; /* command */
int fflag; /* command */
int lflag; /* [option] */
int gflag; /* command */
int iflag; /* command */
int pflag; /* command */
int rflag; /* [option] */
int sflag; /* command */
int vflag; /* [option] */
int xflag; /* [option] */
static void
usage()
{
fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
"global [-alrvx] pattern",
"global -c [prefix]",
"global -f[arx] file",
"global -g[alvx] pattern",
"global -i[v]",
"global -p",
"global -s[alvx] pattern");
exit(1);
}
void
main(argc, argv)
int argc;
char *argv[];
{
char *p, *av;
int count;
int db;
char cwd[MAXPATHLEN+1]; /* current directory */
char root[MAXPATHLEN+1]; /* root of source tree */
char dbpath[MAXPATHLEN+1]; /* dbpath directory */
char comline[MAXCOMLINE+1];
while (--argc > 0 && (++argv)[0][0] == '-') {
for (p = argv[0] + 1; *p; p++) {
switch (*p) {
case 'a':
aflag++;
break;
case 'c':
cflag++;
break;
case 'f':
fflag++;
break;
case 'l':
lflag++;
break;
case 'g':
gflag++;
break;
case 'i':
iflag++;
break;
case 'p':
pflag++;
break;
case 'r':
rflag++;
break;
case 's':
sflag++;
break;
case 'v':
vflag++;
break;
case 'x':
xflag++;
break;
default:
usage();
}
}
}
av = (argc > 0) ? *argv : (char *)0;
/*
* usage check.
*/
{
int commands, options;
commands = cflag + fflag + gflag + iflag + pflag + sflag;
options = aflag + lflag + rflag + xflag;
/*
* only -c, -i and -p allows no argment.
*/
if (!av && !cflag && !iflag && !pflag)
usage();
/*
* command cannot be duplicated.
*/
if (commands > 1)
usage();
/*
* -c and -i command allows only -v option.
*/
if (cflag + iflag && options)
usage();
/*
* -r is not valid for -g, -i and -s.
*/
if (rflag && (gflag + iflag + sflag))
usage();
}
/*
* remove leading blanks.
*/
if (av && !gflag)
for (; *av == ' ' || *av == '\t'; av++)
;
if (cflag && av && regexp(av))
die("regular expression not allowed with -c option.");
/*
* get path of following directories.
* o current directory
* o root of source tree
* o dbpath directory
*
* if GTAGS not found, getdbpath doesn't return.
*/
getdbpath(cwd, root, dbpath);
if (pflag) {
fprintf(stdout, "%s\n", dbpath);
exit(0);
}
/*
* incremental update of tag files.
*/
if (iflag) {
if (chdir(root) < 0)
die1("cannot change directory to '%s'.", root);
sprintf(comline, "gtags -i%s %s", (vflag) ? "v" : "", dbpath);
if (system(comline))
exit(1);
exit(0);
}
/*
* complete function name
*/
if (cflag) {
completelist(dbpath, av);
exit(0);
}
/*
* make sort filter.
*/
if (sflag && xflag)
*sortfilter = 0;
else if (fflag)
sprintf(sortfilter, "sort +1n -2");
else if (xflag) /* print details */
sprintf(sortfilter, "sort +0 -1 +2 -3 +1n -2");
else /* print just file name */
sprintf(sortfilter, "sort | uniq");
/*
* make path filter.
*/
if (aflag) /* absolute path name */
sprintf(pathfilter, "sed -e 's!\\.!%s!'", root);
else /* relative path name */
relative_filter(root, cwd, pathfilter);
/*
* make local prefix.
*/
if (lflag) {
/*
* getdbpath() assure follows.
* cwd != "/" and cwd includes root.
*/
strcpy(local, cwd);
strcat(local, "/");
localprefix = local + strlen(root) - 1;
*localprefix = '.';
}
/*
* grep the pattern in a source tree.
*/
if (gflag) {
if (!lflag)
chdir(root);
else if (!aflag)
sprintf(pathfilter, "sed -e 's!\\./!!'");
grep(av);
exit(0);
}
db = (rflag) ? GRTAGS : ((sflag) ? GSYMS : GTAGS);
/*
* print function definitions.
*/
if (fflag) {
struct stat sb;
char pathbuf[MAXPATHLEN+1], *path;
char *p;
FILE *op;
DBIO *dbio;
/* av !~ /\.[chysS]$/) */
p = av + strlen(av) - 1; /* last character */
if (stat(av, &sb) || !S_ISREG(sb.st_mode))
die1("file '%s' not found.", av);
if (*(p - 1) != '.' || !locatestring("chysS", p, 0))
die("accept only file name end with '.c .h .y .s .S'.");
/*
* convert path into relative from root directory of source tree.
*/
path = realpath(av, pathbuf);
if (*path != '/')
die("realpath(3) is not compatible with BSD version.");
if (strncmp(path, root, strlen(root)))
die1("file '%s' is out of source tree.", path);
path += strlen(root) - 1;
*path = '.';
if (!(op = popen(outfilter(), "w")))
die("cannot open output pipe.");
dbio = gtagsopen(dbpath, db, 0);
for (p = db_first(dbio, NULL, DBIO_SKIPMETA); p; p = db_next(dbio))
if (includepath(p, path))
fprintf(op, "%s\n", p);
db_close(dbio);
pclose(op);
exit(0);
}
/*
* search in current source tree.
*/
count = search(av, cwd, root, dbpath, db);
/*
* search in library path.
*/
if (count == 0 && !rflag && !sflag && !regexp(av) && getenv("GTAGSLIBPATH")) {
char envbuf[MAXENVLEN+1];
char libdbpath[MAXPATHLEN+1];
char *p, *lib;
strcpy(envbuf, getenv("GTAGSLIBPATH"));
p = envbuf;
while (p) {
lib = p;
if (p = locatestring(p, ":", 0))
*p++ = 0;
if (!strncmp(lib, cwd, strlen(cwd)) || !strncmp(cwd, lib, strlen(lib)))
continue;
if (!gtagsexist(lib, libdbpath))
continue;
if (!strcmp(dbpath, libdbpath))
continue;
if (aflag) /* absolute path name */
sprintf(pathfilter, "sed -e 's!\\.!%s!'", lib);
else
relative_filter(lib, cwd, pathfilter);
count = search(av, cwd, lib, libdbpath, GTAGS);
if (count > 0) {
strcpy(dbpath, libdbpath);
break;
}
}
}
if (vflag) {
if (count) {
if (count == 1)
fprintf(stderr, "%d object located", count);
if (count > 1)
fprintf(stderr, "%d objects located", count);
fprintf(stderr, " (using '%s').\n", makepath(dbpath, dbname(db)));
} else {
fprintf(stderr, "'%s' not found.\n", av);
}
}
exit(0);
}
/*
* outfilter: return output filter.
*
* gi) pathfilter
* gi) sortfilter
* r) output filter
*/
char *
outfilter()
{
static char filter[MAXCOMLINE+1];
/*
* make output filter
*/
if (*sortfilter)
sprintf(filter, "%s | %s", sortfilter, pathfilter);
else
strcpy(filter, pathfilter);
return filter;
}
/*
* completelist: print complete list of function
*
* i) dbpath dbpath directory
* i) prefix prefix of primary key
*/
void
completelist(dbpath, prefix)
char *dbpath;
char *prefix;
{
char *p;
DBIO *dbio;
dbio = gtagsopen(dbpath, GTAGS, 0);
for (p = db_first(dbio, prefix, DBIO_KEY|DBIO_PREFIX|DBIO_SKIPMETA); p; p = db_next(dbio))
(void)fprintf(stdout, "%s\n", p);
db_close(dbio);
}
/*
* relative_filter: make relative path filter
*
* i) root the root directory of source tree
* i) argcwd current directory
* o) bp result
* relative path filter
*/
void
relative_filter(root, cwd, bp)
char *root;
char *cwd;
char *bp;
{
char *p, *c, *branch;
/*
* get branch point.
*/
branch = cwd;
for (p = root, c = cwd; *p && *c && *p == *c; p++, c++)
if (*c == '/')
branch = c;
if (*p == 0 && (*c == 0 || *c == '/'))
branch = c;
if (*c == 0 && *p)
die("illegal root.");
/*
* forward to root.
*/
strcpy(bp, "sed -e 's!\\./!");
for (c = branch; *c; c++)
if (*c == '/')
strcat(bp, "../");
p = root + (branch - cwd);
/*
* backward to leaf.
*/
if (*p) {
p++;
strcat(bp, p);
strcat(bp, "/");
}
strcat(bp, "!'");
/*
* remove redundancy.
*/
if (*branch) {
char unit[256];
bp += strlen(bp);
p = unit;
for (c = branch + 1; ; c++) {
if (*c == 0 || *c == '/') {
*p = 0;
sprintf(bp, " -e 's!\\.\\./%s/!!'", unit);
bp += strlen(bp);
if (*c == 0)
break;
p = unit;
} else
*p++ = *c;
}
}
}
/*
* printtag: print a tag's line
*
* i) op output stream
* i) root root of source tree
* i) bp tag's line
* i) compact 0: standard format, 1: compact format
* r) output line count
*/
int
printtag(op, root, bp, compact)
FILE *op;
char *root;
char *bp;
int compact;
{
int count = 0;
char *tag, *file, *lno;
int opened = 0;
char path[MAXPATHLEN+1];
char *buffer;
int line, tagline;
FILE *ip;
if (!xflag) {
fprintf(op, "%s\n", extractpath(bp));
return 1;
}
if (compact) { /* compact format */
char *p = bp;
tag = p; /* tag = $1 */
for (; !isspace(*p) ; p++)
;
*p++ = 0;
for (; isspace(*p) ; p++)
;
file = p; /* file = $2 */
for (; !isspace(*p) ; p++)
;
*p++ = 0;
for (; isspace(*p) ; p++)
;
lno = p; /* lno = $3 */
sprintf(path, "%s/%s", root, file + 2);
if (ip = fopen(path, "r")) {
opened = 1;
buffer = mgets(ip, 0, NULL);
line = 1;
} else {
buffer = "";
}
while (*lno) {
/* get line number */
for (tagline = 0; *lno >= '0' && *lno <= '9'; lno++)
tagline = tagline * 10 + *lno - '0';
if (*lno == ',')
lno++;
if (opened) {
while (line < tagline) {
if (!(buffer = mgets(ip, 0, NULL)))
die1("unexpected end of file. '%s'", path);
line++;
}
}
if (strlen(tag) >= 16 && tagline >= 1000)
fprintf(op, "%-16s %4d %-16s %s\n",
tag, tagline, file, buffer);
else
fprintf(op, "%-16s%4d %-16s %s\n",
tag, tagline, file, buffer);
count++;
}
if (opened)
fclose(ip);
} else { /* standard format */
/*
* separater in key part must be ' ' to avoid sort(1)'s bug.
*/
detab(op, bp);
count++;
}
return count;
}
/*
* regexp: test whether regular expression included.
*
* i) s string
* r) 0: not included, 1: included
*
* This function cannot be used for generic purpose.
* Any character except '[a-zA-Z_0-9]' is assumed RE char..
*/
int
regexp(s)
char *s;
{
int c;
while (c = *s++)
if ( (c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
(c == '_') )
;
else
return 1;
return 0;
}
/*
* grep: grep pattern
*
* i) pattern POSIX regular expression
*/
void
grep(pattern)
char *pattern;
{
FILE *ip, *op, *fp;
char *path;
char edit[IDENTLEN+1];
char *buffer, *p, *e;
int linenum, count, editlen;
regex_t preg;
/*
* convert spaces into %FF format.
*/
e = edit;
for (p = pattern; *p; p++) {
if (*p == '%' || *p == ' ' || *p == '\t') {
sprintf(e, "%%%02x", *p);
e += 3;
} else
*e++ = *p;
}
*e = 0;
editlen = strlen(edit);
if (regcomp(&preg, pattern, REG_EXTENDED) != 0)
die("illegal regular expression.");
if (!(op = popen(outfilter(), "w")))
die("cannot open output pipe.");
count = 0;
for (findopen(); path = findread(NULL); ) {
if (!(fp = fopen(path, "r")))
die1("cannot open file '%s'.", path);
linenum = 0;
while (buffer = mgets(fp, 0, NULL)) {
linenum++;
if (regexec(&preg, buffer, 0, 0, 0) == 0) {
count++;
if (xflag == 0) {
fprintf(op, "%s\n", path);
break;
}
if (editlen >= 16 && linenum >= 1000)
fprintf(op, "%-16s %4d %-16s %s\n",
edit, linenum, path, buffer);
else
fprintf(op, "%-16s%4d %-16s %s\n",
edit, linenum, path, buffer);
}
}
fclose(fp);
}
findclose();
pclose(op);
if (vflag) {
if (count == 0)
fprintf(stderr, "object not found.\n");
if (count == 1)
fprintf(stderr, "%d object located.\n", count);
if (count > 1)
fprintf(stderr, "%d objects located.\n", count);
}
}
/*
* search: search specified function
*
* i) pattern search pattern
* i) cwd current directory
* i) root root of source tree
* i) dbpath database directory
* i) db GTAGS,GRTAGS,GSYMS
* r) count of output lines
*/
int
search(pattern, cwd, root, dbpath, db)
char *pattern;
char *cwd;
char *root;
char *dbpath;
int db;
{
char *p;
int count = 0;
FILE *op;
DBIO *dbio;
int compact;
regex_t preg;
/*
* open tag file.
* currently only GSYMS is compact format.
*/
dbio = gtagsopen(dbpath, db, 0);
compact = (db == GSYMS) ? 1 : 0;
if (!(op = popen(outfilter(), "w")))
die1("filter '%s' failed.", outfilter());
/*
* regular expression.
*/
if (regexp(pattern) && regcomp(&preg, pattern, REG_EXTENDED) == 0) {
char prefix_buf[IDENTLEN+1];
char *prefix = (char *)0;
int presize;
if (*pattern == '^' && *(p = pattern + 1) && (isalpha(*p) || *p == '_')) {
prefix = prefix_buf;
*prefix++ = *p++;
while (*p && (isalpha(*p) || isdigit(*p) || *p == '_'))
*prefix++ = *p++;
*prefix = 0;
prefix = prefix_buf;
p = db_first(dbio, prefix, DBIO_SKIPMETA|DBIO_PREFIX);
} else {
p = db_first(dbio, NULL, DBIO_SKIPMETA);
}
for (; p; p = db_next(dbio)) {
if (*p == ' ')
continue;
if (regexec(&preg, dbio->lastkey, 0, 0, 0) == 0)
count += printtag(op, root, p, compact);
}
} else {
for (p = db_first(dbio, pattern, 0); p; p = db_next(dbio)) {
if (lflag) {
char *q;
/* locate start point of a path */
q = locatestring(p, "./", 0);
if (!locatestring(q, localprefix, 1))
continue;
}
count += printtag(op, root, p, compact);
}
}
pclose(op);
db_close(dbio);
return count;
}
/*
* extractpath: extract path string of a tag line
*
* i) line tag line
* r) path
*
* standard format: main 12 ./xxx/xxx/xxx.c main(argc, argv) {
* compact format: main ./xxx/xxx/xxx.c 12,15,55,101
*/
char *
extractpath(line)
char *line;
{
static char buf[MAXPATHLEN+1];
char *p, *b;
int c;
if (!(p = locatestring(line, "./", 0)))
die("illegal tag format (path not found).");
b = buf;
while (c = *b++ = *p++) {
if (c == ' ' || c == '\t') {
*(b - 1) = 0;
break;
}
}
return buf;
}
/*
* includepath: check if the path included in tag line or not.
*
* i) line tag line
* i) path path
* r) 0: doesn't included, 1: included
*/
int
includepath(line, path)
char *line;
char *path;
{
char *p;
int length;
if (!(p = locatestring(line, "./", 0)))
die("illegal tag format (path not found).");
length = strlen(path);
if (strncmp(p, path, length))
return 0;
p += length;
if (*p == ' ' || *p == '\t')
return 1;
return 0;
}

View file

@ -0,0 +1,12 @@
XCOMM
XCOMM Imakefile for gozilla
XCOMM
LOCAL_LIBRARIES = XawClientLibs -L../lib -lutil
DEPLIBS = XawClientDepLibs ../lib/libutil.a
DEFINES = -DSTANDALONE -DGLOBAL -I../lib
SRCS = gozilla.c remote.c
OBJS = gozilla.o remote.o
ComplexProgramTarget(gozilla)

View file

@ -0,0 +1,194 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* gozilla.c 27-Oct-97
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "global.h"
char *progname = "gozilla"; /* command name */
static void usage __P((void));
void main __P((int, char **));
int sendcommand __P((char *));
int bflag;
int pflag;
int Cflag;
static void
usage()
{
fprintf(stderr, "usage:\t%s\n\t%s\n",
"gozilla [+no] [-b browser] [-p] file",
"gozilla -C command");
exit(1);
}
void
main(argc, argv)
int argc;
char *argv[];
{
char c, *p, *q;
char *browser = (char *)0;
char *command = (char *)0;
char *arg = (char *)0;
char URL[MAXPATHLEN+1];
char com[MAXCOMLINE+1];
int linenumber = 0;
int status;
while (--argc > 0 && (c = (++argv)[0][0]) == '-' || c == '+') {
if (c == '+') {
linenumber = atoi(argv[0] + 1);
continue;
}
p = argv[0] + 1;
switch (*p) {
case 'b':
browser = argv[1];
--argc; ++argv;
break;
case 'p':
pflag++;
break;
case 'C':
command = argv[1];
--argc; ++argv;
break;
default:
usage();
}
}
if (!browser && getenv("BROWSER"))
browser = getenv("BROWSER");
if (command) {
if (browser)
die("-C option is valid only for mozilla.");
if (sendcommand(command) == -1)
die("mozilla not found.");
exit(0);
}
if (argc == 0)
usage();
if (locatestring(argv[0], "http:", 1) || locatestring(argv[0], "file:", 1))
strcpy(URL, argv[0]);
else {
char *abspath;
char pathbuf[MAXPATHLEN+1];
char htmlpath[MAXPATHLEN+1];
if (!test("f", argv[0]) && !test("d", argv[0]))
die1("path '%s' not found.", argv[0]);
if (!(abspath = realpath(argv[0], pathbuf)))
die1("cannot make absolute path name. realpath(%s) failed.", argv[0]);
if (*abspath != '/')
die("realpath(3) is not compatible with BSD version.");
if (issource(abspath)) {
char cwd[MAXPATHLEN+1];
char root[MAXPATHLEN+1];
char dbpath[MAXPATHLEN+1];
char htmldir[MAXPATHLEN+1];
/*
* get current, root and dbpath directory.
* if GTAGS not found, getdbpath doesn't return.
*/
getdbpath(cwd, root, dbpath);
if (test("d", makepath(dbpath, "HTML")))
strcpy(htmldir, makepath(dbpath, "HTML"));
else if (test("d", makepath(root, "HTML")))
strcpy(htmldir, makepath(root, "HTML"));
else
die("hypertext not found. See htags(1).");
/*
* convert path into hypertext.
*/
p = abspath + strlen(root);
for (q = ++p; *q; q++)
if (*q == '/')
*q = ' ';
if (linenumber)
sprintf(URL, "file:%s/S/%s.html#%d", htmldir, p, linenumber);
else
sprintf(URL, "file:%s/S/%s.html", htmldir, p);
} else {
sprintf(URL, "file:%s", abspath);
}
}
if (pflag) {
fprintf(stdout, "%s\n", URL);
exit(0);
}
/*
* execute generic browser.
*/
if (browser && !locatestring(browser, "netscape", 3)) {
sprintf(com, "%s '%s'", browser, URL);
system(com);
exit (0);
}
/*
* send a command to mozilla.
*/
sprintf(com, "openURL(%s)", URL);
status = sendcommand(com);
/*
* load mozilla if not found.
*/
if (status != 0) {
int pid;
if ((pid = fork()) < 0) {
die("cannot execute netscape (fork).");
} else if (pid == 0) {
execlp("netscape", "netscape", URL, (char *)0);
die("loading mozilla failed.");
}
exit(0);
}
exit(status);
}
int
sendcommand(com)
char *com;
{
int argc = 3;
char *argv[4];
argv[0] = "netscape-remote";
argv[1] = "-remote";
argv[2] = com;
argv[3] = (char *)0;
return netscape_remote(argc, argv);
}

View file

@ -0,0 +1,141 @@
.\"
.\" Copyright (c) 1997 Shigio Yamaguchi. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by Shigio Yamaguchi.
.\" 4. Neither the name of the author nor the names of any co-contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd Sep 17, 1997
.Dt GOZILLA 1
.Os BSD 4
.Sh NAME
.Nm gozilla
.Nd force mozilla to display specified source file
.Sh SYNOPSIS
\fBgozilla\fP [\fB+\fP\fIno\fP]
.Op Fl b Ar browser
.Op Fl p
.Ar file
.Nm gozilla
.Fl C Ar command
.Sh DESCRIPTION
First form:
.br
.Nm Gozilla
force mozilla (Netscape Navigator) to display specified source file
as a hypertext.
If mozilla has not loaded then
.Nm
loads it.
.Pp
In advance of using this command, you must execute
.Xr gtags 1
and
.Xr htags 1
at the root directory of the source tree to make tag files.
Then you can execute
.Nm
at anywhere in the source tree.
.br
You can specify source file and the line number optionally.
.Pp
Second form:
.br
.Nm Gozilla
send
.Ar command
to mozilla directly.
.Ar Command
is undocumented. But the hint is in the resource file of mozilla.
.Pp
The following options are available:
.Bl -tag -width Ds
.It Ar \fB+\fP\fIno\fP
line number. It must be a line on which function definition or function
reference is exist.
If you execute
.Xr htags 1
with -l option, you can specify any line.
.It Fl b Ar browser
browser to use. By default, assumes mozilla.
If you specify another browser,
.Nm
waits for exiting of the browser.
.It Fl p
just print generated target URL.
.It Ar file
path of source file.
.It Fl C Ar command
send
.Ar command
to mozilla directly.
.El
.Sh FILES
.Bl -tag -width tags -compact
.It Pa HTML/
hypertext of source tree.
.It Pa GTAGS
tags file for function definitions.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of gozilla.
.Pp
.Bl -tag -width indent
.It Ev GTAGSROOT
The directory which is the root of source tree.
.It Ev GTAGSDBPATH
The directory on which HTML directory exist. This value is ignored
when GTAGSROOT is not defined.
.It Ev BROWSER
browser to use. By default, assumes mozilla.
.El
.Sh EXAMPLES
% global -x main
main 82 ctags.c main(argc, argv)
% gozilla +82 ctags.c
% gozilla -C pageDown
% gozilla -C back
.Sh DIAGNOSTICS
.Nm Gozilla
exits with a non 0 value if an error occurred, 0 otherwise.
.Sh SEE ALSO
.Xr global 1 ,
.Xr gtags 1 ,
.Xr htags 1 .
.Sh NOTES
Netscape Navigator is a registered trademark of Netscape Communications Corporation
in the United States and other countries.
.Pp
.Nm Gozilla
means 'Global for mozilla'.
.Sh BUGS
.Nm Gozilla
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)

View file

@ -0,0 +1,717 @@
/* -*- Mode:C; tab-width: 8 -*-
* remote.c --- remote control of Netscape Navigator for Unix.
* version 1.1.3, for Netscape Navigator 1.1 and newer.
*
* Copyright © 1996 Netscape Communications Corporation, all rights reserved.
* Created: Jamie Zawinski <jwz@netscape.com>, 24-Dec-94.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*
* To compile:
*
* cc -o netscape-remote remote.c -DSTANDALONE -lXmu -lX11
*
* To use:
*
* netscape-remote -help
*
* Documentation for the protocol which this code implements may be found at:
*
* http://home.netscape.com/newsref/std/x-remote.html
*
* Bugs and commentary to x_cbug@netscape.com.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xmu/WinUtil.h> /* for XmuClientWindow() */
/* vroot.h is a header file which lets a client get along with `virtual root'
window managers like swm, tvtwm, olvwm, etc. If you don't have this header
file, you can find it at "http://home.netscape.com/newsref/std/vroot.h".
If you don't care about supporting virtual root window managers, you can
comment this line out.
*/
#include "vroot.h"
#ifdef STANDALONE
#ifdef GLOBAL
extern char *progname;
#else
static const char *progname = 0;
#endif
static const char *expected_mozilla_version = "1.1";
#else /* !STANDALONE */
extern const char *progname;
extern const char *expected_mozilla_version;
#endif /* !STANDALONE */
#define MOZILLA_VERSION_PROP "_MOZILLA_VERSION"
#define MOZILLA_LOCK_PROP "_MOZILLA_LOCK"
#define MOZILLA_COMMAND_PROP "_MOZILLA_COMMAND"
#define MOZILLA_RESPONSE_PROP "_MOZILLA_RESPONSE"
static Atom XA_MOZILLA_VERSION = 0;
static Atom XA_MOZILLA_LOCK = 0;
static Atom XA_MOZILLA_COMMAND = 0;
static Atom XA_MOZILLA_RESPONSE = 0;
static void
mozilla_remote_init_atoms (Display *dpy)
{
if (! XA_MOZILLA_VERSION)
XA_MOZILLA_VERSION = XInternAtom (dpy, MOZILLA_VERSION_PROP, False);
if (! XA_MOZILLA_LOCK)
XA_MOZILLA_LOCK = XInternAtom (dpy, MOZILLA_LOCK_PROP, False);
if (! XA_MOZILLA_COMMAND)
XA_MOZILLA_COMMAND = XInternAtom (dpy, MOZILLA_COMMAND_PROP, False);
if (! XA_MOZILLA_RESPONSE)
XA_MOZILLA_RESPONSE = XInternAtom (dpy, MOZILLA_RESPONSE_PROP, False);
}
static Window
mozilla_remote_find_window (Display *dpy)
{
int i;
Window root = RootWindowOfScreen (DefaultScreenOfDisplay (dpy));
Window root2, parent, *kids;
unsigned int nkids;
Window result = 0;
Window tenative = 0;
unsigned char *tenative_version = 0;
if (! XQueryTree (dpy, root, &root2, &parent, &kids, &nkids))
{
fprintf (stderr, "%s: XQueryTree failed on display %s\n", progname,
DisplayString (dpy));
exit (2);
}
/* root != root2 is possible with virtual root WMs. */
if (! (kids && nkids))
{
fprintf (stderr, "%s: root window has no children on display %s\n",
progname, DisplayString (dpy));
exit (2);
}
for (i = nkids-1; i >= 0; i--)
{
Atom type;
int format;
unsigned long nitems, bytesafter;
unsigned char *version = 0;
Window w = XmuClientWindow (dpy, kids[i]);
int status = XGetWindowProperty (dpy, w, XA_MOZILLA_VERSION,
0, (65536 / sizeof (long)),
False, XA_STRING,
&type, &format, &nitems, &bytesafter,
&version);
if (! version)
continue;
if (strcmp ((char *) version, expected_mozilla_version) &&
!tenative)
{
tenative = w;
tenative_version = version;
continue;
}
XFree (version);
if (status == Success && type != None)
{
result = w;
break;
}
}
if (result && tenative)
{
#ifndef GLOBAL
fprintf (stderr,
"%s: warning: both version %s (0x%x) and version\n"
"\t%s (0x%x) are running. Using version %s.\n",
progname, tenative_version, (unsigned int) tenative,
expected_mozilla_version, (unsigned int) result,
expected_mozilla_version);
#endif
XFree (tenative_version);
return result;
}
else if (tenative)
{
#ifndef GLOBAL
fprintf (stderr,
"%s: warning: expected version %s but found version\n"
"\t%s (0x%x) instead.\n",
progname, expected_mozilla_version,
tenative_version, (unsigned int) tenative);
#endif
XFree (tenative_version);
return tenative;
}
else if (result)
{
return result;
}
else
{
#ifdef GLOBAL
return 0;
#else
fprintf (stderr, "%s: not running on display %s\n", progname,
DisplayString (dpy));
exit (1);
#endif
}
}
static void
mozilla_remote_check_window (Display *dpy, Window window)
{
Atom type;
int format;
unsigned long nitems, bytesafter;
unsigned char *version = 0;
int status = XGetWindowProperty (dpy, window, XA_MOZILLA_VERSION,
0, (65536 / sizeof (long)),
False, XA_STRING,
&type, &format, &nitems, &bytesafter,
&version);
if (status != Success || !version)
{
fprintf (stderr, "%s: window 0x%x is not a Netscape window.\n",
progname, (unsigned int) window);
exit (6);
}
else if (strcmp ((char *) version, expected_mozilla_version))
{
fprintf (stderr,
"%s: warning: window 0x%x is Netscape version %s;\n"
"\texpected version %s.\n",
progname, (unsigned int) window,
version, expected_mozilla_version);
}
XFree (version);
}
static char *lock_data = 0;
static void
mozilla_remote_obtain_lock (Display *dpy, Window window)
{
Bool locked = False;
Bool waited = False;
if (! lock_data)
{
lock_data = (char *) malloc (255);
sprintf (lock_data, "pid%d@", getpid ());
if (gethostname (lock_data + strlen (lock_data), 100))
{
perror ("gethostname");
exit (-1);
}
}
do
{
int result;
Atom actual_type;
int actual_format;
unsigned long nitems, bytes_after;
unsigned char *data = 0;
XGrabServer (dpy); /* ################################# DANGER! */
result = XGetWindowProperty (dpy, window, XA_MOZILLA_LOCK,
0, (65536 / sizeof (long)),
False, /* don't delete */
XA_STRING,
&actual_type, &actual_format,
&nitems, &bytes_after,
&data);
if (result != Success || actual_type == None)
{
/* It's not now locked - lock it. */
#ifdef DEBUG_PROPS
fprintf (stderr, "%s: (writing " MOZILLA_LOCK_PROP
" \"%s\" to 0x%x)\n",
progname, lock_data, (unsigned int) window);
#endif
XChangeProperty (dpy, window, XA_MOZILLA_LOCK, XA_STRING, 8,
PropModeReplace, (unsigned char *) lock_data,
strlen (lock_data));
locked = True;
}
XUngrabServer (dpy); /* ################################# danger over */
XSync (dpy, False);
if (! locked)
{
/* We tried to grab the lock this time, and failed because someone
else is holding it already. So, wait for a PropertyDelete event
to come in, and try again. */
fprintf (stderr, "%s: window 0x%x is locked by %s; waiting...\n",
progname, (unsigned int) window, data);
waited = True;
while (1)
{
XEvent event;
XNextEvent (dpy, &event);
if (event.xany.type == DestroyNotify &&
event.xdestroywindow.window == window)
{
fprintf (stderr, "%s: window 0x%x unexpectedly destroyed.\n",
progname, (unsigned int) window);
exit (6);
}
else if (event.xany.type == PropertyNotify &&
event.xproperty.state == PropertyDelete &&
event.xproperty.window == window &&
event.xproperty.atom == XA_MOZILLA_LOCK)
{
/* Ok! Someone deleted their lock, so now we can try
again. */
#ifdef DEBUG_PROPS
fprintf (stderr, "%s: (0x%x unlocked, trying again...)\n",
progname, (unsigned int) window);
#endif
break;
}
}
}
if (data)
XFree (data);
}
while (! locked);
if (waited)
fprintf (stderr, "%s: obtained lock.\n", progname);
}
static void
mozilla_remote_free_lock (Display *dpy, Window window)
{
int result;
Atom actual_type;
int actual_format;
unsigned long nitems, bytes_after;
unsigned char *data = 0;
#ifdef DEBUG_PROPS
fprintf (stderr, "%s: (deleting " MOZILLA_LOCK_PROP
" \"%s\" from 0x%x)\n",
progname, lock_data, (unsigned int) window);
#endif
result = XGetWindowProperty (dpy, window, XA_MOZILLA_LOCK,
0, (65536 / sizeof (long)),
True, /* atomic delete after */
XA_STRING,
&actual_type, &actual_format,
&nitems, &bytes_after,
&data);
if (result != Success)
{
fprintf (stderr, "%s: unable to read and delete " MOZILLA_LOCK_PROP
" property\n",
progname);
return;
}
else if (!data || !*data)
{
fprintf (stderr, "%s: invalid data on " MOZILLA_LOCK_PROP
" of window 0x%x.\n",
progname, (unsigned int) window);
return;
}
else if (strcmp ((char *) data, lock_data))
{
fprintf (stderr, "%s: " MOZILLA_LOCK_PROP
" was stolen! Expected \"%s\", saw \"%s\"!\n",
progname, lock_data, data);
return;
}
if (data)
XFree (data);
}
static int
mozilla_remote_command (Display *dpy, Window window, const char *command,
Bool raise_p)
{
int result;
Bool done = False;
char *new_command = 0;
/* The -noraise option is implemented by passing a "noraise" argument
to each command to which it should apply.
*/
if (! raise_p)
{
char *close;
new_command = (char *) malloc (strlen (command) + 20);
strcpy (new_command, command);
close = strrchr (new_command, ')');
if (close)
strcpy (close, ", noraise)");
else
strcat (new_command, "(noraise)");
command = new_command;
}
#ifdef DEBUG_PROPS
fprintf (stderr, "%s: (writing " MOZILLA_COMMAND_PROP " \"%s\" to 0x%x)\n",
progname, command, (unsigned int) window);
#endif
XChangeProperty (dpy, window, XA_MOZILLA_COMMAND, XA_STRING, 8,
PropModeReplace, (unsigned char *) command,
strlen (command));
while (!done)
{
XEvent event;
XNextEvent (dpy, &event);
if (event.xany.type == DestroyNotify &&
event.xdestroywindow.window == window)
{
/* Print to warn user...*/
fprintf (stderr, "%s: window 0x%x was destroyed.\n",
progname, (unsigned int) window);
result = 6;
goto DONE;
}
else if (event.xany.type == PropertyNotify &&
event.xproperty.state == PropertyNewValue &&
event.xproperty.window == window &&
event.xproperty.atom == XA_MOZILLA_RESPONSE)
{
Atom actual_type;
int actual_format;
unsigned long nitems, bytes_after;
unsigned char *data = 0;
result = XGetWindowProperty (dpy, window, XA_MOZILLA_RESPONSE,
0, (65536 / sizeof (long)),
True, /* atomic delete after */
XA_STRING,
&actual_type, &actual_format,
&nitems, &bytes_after,
&data);
#ifdef DEBUG_PROPS
if (result == Success && data && *data)
{
fprintf (stderr, "%s: (server sent " MOZILLA_RESPONSE_PROP
" \"%s\" to 0x%x.)\n",
progname, data, (unsigned int) window);
}
#endif
if (result != Success)
{
fprintf (stderr, "%s: failed reading " MOZILLA_RESPONSE_PROP
" from window 0x%0x.\n",
progname, (unsigned int) window);
result = 6;
done = True;
}
else if (!data || strlen((char *) data) < 5)
{
fprintf (stderr, "%s: invalid data on " MOZILLA_RESPONSE_PROP
" property of window 0x%0x.\n",
progname, (unsigned int) window);
result = 6;
done = True;
}
else if (*data == '1') /* positive preliminary reply */
{
fprintf (stderr, "%s: %s\n", progname, data + 4);
/* keep going */
done = False;
}
#if 1
else if (!strncmp ((char *)data, "200", 3)) /* positive completion */
{
result = 0;
done = True;
}
#endif
else if (*data == '2') /* positive completion */
{
fprintf (stderr, "%s: %s\n", progname, data + 4);
result = 0;
done = True;
}
else if (*data == '3') /* positive intermediate reply */
{
fprintf (stderr, "%s: internal error: "
"server wants more information? (%s)\n",
progname, data);
result = 3;
done = True;
}
else if (*data == '4' || /* transient negative completion */
*data == '5') /* permanent negative completion */
{
fprintf (stderr, "%s: %s\n", progname, data + 4);
result = (*data - '0');
done = True;
}
else
{
fprintf (stderr,
"%s: unrecognised " MOZILLA_RESPONSE_PROP
" from window 0x%x: %s\n",
progname, (unsigned int) window, data);
result = 6;
done = True;
}
if (data)
XFree (data);
}
#ifdef DEBUG_PROPS
else if (event.xany.type == PropertyNotify &&
event.xproperty.window == window &&
event.xproperty.state == PropertyDelete &&
event.xproperty.atom == XA_MOZILLA_COMMAND)
{
fprintf (stderr, "%s: (server 0x%x has accepted "
MOZILLA_COMMAND_PROP ".)\n",
progname, (unsigned int) window);
}
#endif /* DEBUG_PROPS */
}
DONE:
if (new_command)
free (new_command);
return result;
}
int
mozilla_remote_commands (Display *dpy, Window window, char **commands)
{
Bool raise_p = True;
int status = 0;
mozilla_remote_init_atoms (dpy);
if (window == 0)
window = mozilla_remote_find_window (dpy);
else
mozilla_remote_check_window (dpy, window);
#ifdef GLOBAL
if (window == 0)
return -1;
#endif
XSelectInput (dpy, window, (PropertyChangeMask|StructureNotifyMask));
mozilla_remote_obtain_lock (dpy, window);
while (*commands)
{
if (!strcmp (*commands, "-raise"))
raise_p = True;
else if (!strcmp (*commands, "-noraise"))
raise_p = False;
else
status = mozilla_remote_command (dpy, window, *commands, raise_p);
if (status != 0)
break;
commands++;
}
/* When status = 6, it means the window has been destroyed */
/* It is invalid to free the lock when window is destroyed. */
if ( status != 6 )
mozilla_remote_free_lock (dpy, window);
return status;
}
#ifdef STANDALONE
static void
usage (void)
{
fprintf (stderr, "usage: %s [ options ... ]\n\
where options include:\n\
\n\
-help to show this message.\n\
-display <dpy> to specify the X server to use.\n\
-remote <remote-command> to execute a command in an already-running\n\
Netscape process. See the manual for a\n\
list of valid commands.\n\
-id <window-id> the id of an X window to which the -remote\n\
commands should be sent; if unspecified,\n\
the first window found will be used.\n\
-raise whether following -remote commands should\n\
cause the window to raise itself to the top\n\
(this is the default.)\n\
-noraise the opposite of -raise: following -remote\n\
commands will not auto-raise the window.\n\
",
progname);
}
#ifdef GLOBAL
int
netscape_remote(int argc, char **argv)
#else
void
main (int argc, char **argv)
#endif
{
Display *dpy;
char *dpy_string = 0;
char **remote_commands = 0;
int remote_command_count = 0;
int remote_command_size = 0;
unsigned long remote_window = 0;
Bool sync_p = False;
int i;
progname = strrchr (argv[0], '/');
if (progname)
progname++;
else
progname = argv[0];
/* Hack the -help and -version arguments before opening the display. */
for (i = 1; i < argc; i++)
{
if (!strcasecmp (argv [i], "-h") ||
!strcasecmp (argv [i], "-help"))
{
usage ();
exit (0);
}
else if (!strcmp (argv [i], "-d") ||
!strcmp (argv [i], "-dpy") ||
!strcmp (argv [i], "-disp") ||
!strcmp (argv [i], "-display"))
{
i++;
dpy_string = argv [i];
}
else if (!strcmp (argv [i], "-sync") ||
!strcmp (argv [i], "-synchronize"))
{
sync_p = True;
}
else if (!strcmp (argv [i], "-remote"))
{
if (remote_command_count == remote_command_size)
{
remote_command_size += 20;
remote_commands =
(remote_commands
? realloc (remote_commands,
remote_command_size * sizeof (char *))
: calloc (remote_command_size, sizeof (char *)));
}
i++;
if (!argv[i] || *argv[i] == '-' || *argv[i] == 0)
{
fprintf (stderr, "%s: invalid `-remote' option \"%s\"\n",
progname, argv[i] ? argv[i] : "");
usage ();
exit (-1);
}
remote_commands [remote_command_count++] = argv[i];
}
else if (!strcmp (argv [i], "-raise") ||
!strcmp (argv [i], "-noraise"))
{
char *r = argv [i];
if (remote_command_count == remote_command_size)
{
remote_command_size += 20;
remote_commands =
(remote_commands
? realloc (remote_commands,
remote_command_size * sizeof (char *))
: calloc (remote_command_size, sizeof (char *)));
}
remote_commands [remote_command_count++] = r;
}
else if (!strcmp (argv [i], "-id"))
{
char c;
if (remote_command_count > 0)
{
fprintf (stderr,
"%s: the `-id' option must preceed all `-remote' options.\n",
progname);
usage ();
exit (-1);
}
else if (remote_window != 0)
{
fprintf (stderr, "%s: only one `-id' option may be used.\n",
progname);
usage ();
exit (-1);
}
i++;
if (argv[i] &&
1 == sscanf (argv[i], " %ld %c", &remote_window, &c))
;
else if (argv[i] &&
1 == sscanf (argv[i], " 0x%lx %c", &remote_window, &c))
;
else
{
fprintf (stderr, "%s: invalid `-id' option \"%s\"\n",
progname, argv[i] ? argv[i] : "");
usage ();
exit (-1);
}
}
}
dpy = XOpenDisplay (dpy_string);
if (! dpy)
exit (-1);
if (sync_p)
XSynchronize (dpy, True);
#ifdef GLOBAL
return mozilla_remote_commands (dpy, (Window) remote_window,
remote_commands);
#else
exit (mozilla_remote_commands (dpy, (Window) remote_window,
remote_commands));
#endif
}
#endif /* STANDALONE */

View file

@ -0,0 +1,119 @@
/*****************************************************************************/
/** Copyright 1991 by Andreas Stolcke **/
/** Copyright 1990 by Solbourne Computer Inc. **/
/** Longmont, Colorado **/
/** **/
/** All Rights Reserved **/
/** **/
/** Permission to use, copy, modify, and distribute this software and **/
/** its documentation for any purpose and without fee is hereby **/
/** granted, provided that the above copyright notice appear in all **/
/** copies and that both that copyright notice and this permis- **/
/** sion notice appear in supporting documentation, and that the **/
/** name of Solbourne not be used in advertising **/
/** in publicity pertaining to distribution of the software without **/
/** specific, written prior permission. **/
/** **/
/** ANDREAS STOLCKE AND SOLBOURNE COMPUTER INC. DISCLAIMS ALL WARRANTIES **/
/** WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF **/
/** MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ANDREAS STOLCKE **/
/** OR SOLBOURNE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL **/
/** DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/
/** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/
/** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/
/** OR PERFORMANCE OF THIS SOFTWARE. **/
/*****************************************************************************/
/*
* vroot.h -- Virtual Root Window handling header file
*
* This header file redefines the X11 macros RootWindow and DefaultRootWindow,
* making them look for a virtual root window as provided by certain `virtual'
* window managers like swm and tvtwm. If none is found, the ordinary root
* window is returned, thus retaining backward compatibility with standard
* window managers.
* The function implementing the virtual root lookup remembers the result of
* its last invocation to avoid overhead in the case of repeated calls
* on the same display and screen arguments.
* The lookup code itself is taken from Tom LaStrange's ssetroot program.
*
* Most simple root window changing X programs can be converted to using
* virtual roots by just including
*
* #include <X11/vroot.h>
*
* after all the X11 header files. It has been tested on such popular
* X clients as xphoon, xfroot, xloadimage, and xaqua.
* It also works with the core clients xprop, xwininfo, xwd, and editres
* (and is necessary to get those clients working under tvtwm).
* It does NOT work with xsetroot; get the xsetroot replacement included in
* the tvtwm distribution instead.
*
* Andreas Stolcke <stolcke@ICSI.Berkeley.EDU>, 9/7/90
* - replaced all NULL's with properly cast 0's, 5/6/91
* - free children list (suggested by Mark Martin <mmm@cetia.fr>), 5/16/91
* - include X11/Xlib.h and support RootWindowOfScreen, too 9/17/91
*/
#ifndef _VROOT_H_
#define _VROOT_H_
#include <X11/X.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
static Window
VirtualRootWindowOfScreen(screen)
Screen *screen;
{
static Screen *save_screen = (Screen *)0;
static Window root = (Window)0;
if (screen != save_screen) {
Display *dpy = DisplayOfScreen(screen);
Atom __SWM_VROOT = None;
int i;
Window rootReturn, parentReturn, *children;
unsigned int numChildren;
root = RootWindowOfScreen(screen);
/* go look for a virtual root */
__SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
if (XQueryTree(dpy, root, &rootReturn, &parentReturn,
&children, &numChildren)) {
for (i = 0; i < numChildren; i++) {
Atom actual_type;
int actual_format;
unsigned long nitems, bytesafter;
Window *newRoot = (Window *)0;
if (XGetWindowProperty(dpy, children[i],
__SWM_VROOT, 0, 1, False, XA_WINDOW,
&actual_type, &actual_format,
&nitems, &bytesafter,
(unsigned char **) &newRoot) == Success
&& newRoot) {
root = *newRoot;
break;
}
}
if (children)
XFree((char *)children);
}
save_screen = screen;
}
return root;
}
#undef RootWindowOfScreen
#define RootWindowOfScreen(s) VirtualRootWindowOfScreen(s)
#undef RootWindow
#define RootWindow(dpy,screen) VirtualRootWindowOfScreen(ScreenOfDisplay(dpy,screen))
#undef DefaultRootWindow
#define DefaultRootWindow(dpy) VirtualRootWindowOfScreen(DefaultScreenOfDisplay(dpy))
#endif /* _VROOT_H_ */

View file

@ -30,12 +30,12 @@
;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
;; SUCH DAMAGE.
;;
;; gtags.el 6-Jul-97
;; gtags.el 31-Aug-97
;;
;; This file is part of GLOBAL.
;; Author: Shigio Yamaguchi <shigio@wafu.netgate.net>
;; Version: 1.0
;; Version: 1.1
;; Keywords: tools
;;; Code
@ -56,6 +56,8 @@
"Keymap used in gtags mode.")
(define-key gtags-mode-map "\et" 'gtags-find-tag)
(define-key gtags-mode-map "\er" 'gtags-find-rtag)
(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 "\C-t" 'gtags-pop-stack)
(define-key gtags-mode-map "\e." 'etags-style-find-tag)
@ -69,13 +71,17 @@
(define-key gtags-select-mode-map "\C-m" 'gtags-select-tag)
(define-key gtags-select-mode-map " " 'scroll-up)
(define-key gtags-select-mode-map "\^?" 'scroll-down)
(define-key gtags-select-mode-map "\C-f" 'scroll-up)
(define-key gtags-select-mode-map "\C-b" 'scroll-down)
(define-key gtags-select-mode-map "n" 'next-line)
(define-key gtags-select-mode-map "p" 'previous-line)
(define-key gtags-select-mode-map "j" 'next-line)
(define-key gtags-select-mode-map "k" 'previous-line)
(define-key gtags-select-mode-map [mouse-2] 'gtags-select-tag-by-event)
(define-key gtags-select-mode-map [mouse-3] 'gtags-pop-stack)
;;
;; utirity
;; utility
;;
(defun match-string (n)
(buffer-substring (match-beginning n) (match-end n)))
@ -114,6 +120,15 @@
(defun exist-in-stack (buffer)
(memq buffer gtags-buffer-stack))
;; is it a function?
(defun is-function ()
(save-excursion
(while (and (not (eolp)) (looking-at "[0-9A-Za-z_]"))
(forward-char 1))
(while (and (not (eolp)) (looking-at "[ \t]"))
(forward-char 1))
(if (looking-at "(") t nil)))
;; is it a definition?
(defun is-definition ()
(save-excursion
@ -139,7 +154,7 @@
(let (tagname)
(setq tagname (completing-read ":tag " gtags-complete-list))
(push-context)
(gtags-goto-tag tagname t)))
(gtags-goto-tag tagname "")))
(defun etags-style-find-tag ()
"Input tag name and move to the definition.(etags style)"
@ -152,7 +167,33 @@
(setq input (completing-read prompt gtags-complete-list))
(if (not (equal "" input)) (setq tagname input))
(push-context)
(gtags-goto-tag tagname t)))
(gtags-goto-tag tagname "")))
(defun gtags-find-symbol ()
"Input symbol and move to the locations."
(interactive)
(let (tagname prompt input)
(setq tagname (gtags-current-token))
(if tagname
(setq prompt (concat "Find symbol: (default " tagname ") "))
(setq prompt "Find symbol: "))
(setq input (read-string prompt))
(if (not (equal "" input)) (setq tagname input))
(push-context)
(gtags-goto-tag tagname "s")))
(defun gtags-find-pattern ()
"Input pattern and move to the locations."
(interactive)
(let (tagname prompt input)
(setq tagname (gtags-current-token))
(if tagname
(setq prompt (concat "Find pattern: (default " tagname ") "))
(setq prompt "Find pattern: "))
(setq input (read-string prompt))
(if (not (equal "" input)) (setq tagname input))
(push-context)
(gtags-goto-tag tagname "g")))
(defun gtags-find-rtag ()
"Input tag name and move to the referenced point."
@ -160,17 +201,20 @@
(let (tagname)
(setq tagname (completing-read ":rtag " gtags-complete-list))
(push-context)
(gtags-goto-tag tagname nil)))
(gtags-goto-tag tagname "r")))
(defun gtags-find-tag-from-here ()
"Get the expression as a tagname around here and move there."
(interactive)
(let (tagname)
(let (tagname flag)
(setq tagname (gtags-current-token))
(if (is-function)
(if (is-definition) (setq flag "r") (setq flag ""))
(setq flag "s"))
(if (not tagname)
nil
(push-context)
(gtags-goto-tag tagname (not (is-definition))))))
(gtags-goto-tag tagname flag))))
(defun gtags-find-tag-by-event (event)
"Get the expression as a tagname around here and move there."
@ -178,16 +222,17 @@
(select-window (posn-window (event-end event)))
(set-buffer (window-buffer (posn-window (event-end event))))
(goto-char (posn-point (event-end event)))
(let (tagname definition)
(setq definition nil)
(let (tagname flag)
(if (= 0 (count-lines (point-min) (point-max)))
(setq tagname "main")
(progn (setq tagname "main") (setq flag ""))
(setq tagname (gtags-current-token))
(setq definition (is-definition)))
(if (is-function)
(if (is-definition) (setq flag "r") (setq flag ""))
(setq flag "s")))
(if (not tagname)
nil
(push-context)
(gtags-goto-tag tagname (not definition)))))
(gtags-goto-tag tagname flag))))
(defun gtags-select-tag ()
"Select a tagname in [GTAGS SELECT MODE] and move there."
@ -223,16 +268,22 @@
;;
;; goto tag's point
(defun gtags-goto-tag (tagname definition)
(let (save flags buffer lines)
(defun gtags-goto-tag (tagname flag)
(let (save prefix buffer lines)
(setq save (current-buffer))
(if definition
(setq flags "") (setq flags "-r"))
(cond
((equal flag "g")
(setq prefix "(G)"))
((equal flag "s")
(setq prefix "(S)"))
((equal flag "r")
(setq prefix "(R)"))
(t (setq prefix "(D)")))
;; load tag
(setq buffer (generate-new-buffer (generate-new-buffer-name (concat (if (equal flags "") "(D)" "(R)") tagname))))
(setq buffer (generate-new-buffer (generate-new-buffer-name (concat prefix tagname))))
(set-buffer buffer)
(if (not (= 0 (call-process "global" nil t nil (concat "-ax" flags) tagname)))
(progn (message "cannot execute global.")
(if (not (= 0 (call-process "global" nil t nil (concat "-ax" flag) tagname)))
(progn (message (buffer-substring (point-min)(1- (point-max))))
(pop-context))
(goto-char (point-min))
(setq lines (count-lines (point-min) (point-max)))
@ -253,7 +304,8 @@
(let (line file)
;; get context from current tag line
(beginning-of-line)
(if (not (looking-at "[A-Za-z_][A-Za-z_0-9]*[ \t]+\\([0-9]+\\)[ \t]\\([^ \t]+\\)[ \t]"))
;; (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))

View file

@ -1,9 +1,6 @@
# @(#)Makefile 1.0 (Berkeley) 4/21/96
MAN1= gtags.1
beforeinstall:
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${.CURDIR}/gtags.pl ${DESTDIR}/usr/bin/gtags
PROG= gtags
CFLAGS+=-I${.CURDIR}/../lib -DGLOBAL -DYACC
LDADD= $(LIBUTIL)
DPADD= $(LIBUTIL)
.include <bsd.prog.mk>

View file

@ -1,13 +1,20 @@
# @(#)Makefile 29-Dec-96
PROG = gtags
CC = gcc
LIBS = -L../lib -lutil -ldb
CFLAGS = -O -I../lib -I/usr/include/db
DEPLIBS= ../lib/libutil.a
OBJS = gtags.o
BINDIR = /usr/bin
MANDIR = /usr/share/man
MANDIR = /usr/man
all:
all: $(PROG)
$(PROG): $(OBJS) $(DEPLIBS)
$(CC) -o $(PROG) $(OBJS) $(LIBS)
install:
cp $(PROG).pl $(BINDIR)/$(PROG)
cp $(PROG) $(BINDIR)
chmod 755 $(BINDIR)/$(PROG)
cp $(PROG).1 $(MANDIR)/man1
chmod 644 $(MANDIR)/man1/$(PROG).1
clean:
rm -f $(PROG) $(OBJS)

View file

@ -28,59 +28,71 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd April 21, 1997
.Dd Sep 12, 1997
.Dt GTAGS 1
.Os BSD 4
.Sh NAME
.Nm gtags
.Nd create GTAGS, GRTAGS file
.Nd create GTAGS, GRTAGS and GSYMS file
.Sh SYNOPSIS
.Nm gtags
.Op Fl e
.Op Fl s
.Op Fl i
.Op Fl o
.Op Fl v
.Op Ar dbpath
.Sh DESCRIPTION
.Nm Gtags
makes GTAGS, GRTAGS files for global(1).
makes GTAGS, GRTAGS and GSYMS file for
.Xr global 1 .
.Nm Gtags
trace subdirectories, read source files,
locate the functions and save the information into tag files.
locate symbols and save the information into tag files.
C, yacc 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
.Ar dbpath
of the directory on which make tags files.
of the directory on which make tag files.
.Pp
.Bl -tag -width Ds
.It Fl e
force a function to end when reach a '}' at the first column in C source file.
.It Fl s
treat assembler source file (*.s, *.S).
.It Fl i
update tag files incrementally by files which modified after the tag files were
last updated.
.It Fl o
suppress making GSYMS file.
Use this option if you don't use -s option of
.Xr global 1 .
.It Fl v
verbose mode.
.Sh FILES
.Bl -tag -width tags -compact
.It Pa GTAGS
tags file for function definitions.
tag file for function definitions.
.It Pa GRTAGS
tags file for function references.
tag file for function references.
.It Pa GSYMS
tag file for other symbols.
.El
.Sh DIAGNOSTICS
.Nm Gtags
exits with a value of 1 if an error occurred, 0 otherwise.
exits with a non 0 value if an error occurred, 0 otherwise.
.Sh SEE ALSO
.Xr btreeop 1 ,
.Xr gctags 1 ,
.Xr global 1 ,
.Xr htags 1 .
.Xr htags 1 ,
.Xr vi 1 .
.Sh BUG
GTAGS, GRTAGS are very large. In advance, check the space of your disk.
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()
and ALTENTRY() from source file. Probably valid only for FreeBSD and Linux
kernel source.
.br
There is no concurrency control about tag files.
.Sh AUTHORS
Shigio Yamaguchi (shigio@wafu.netgate.net)
.Sh HISTORY
The
.Nm
command appeared in FreeBSD 2.2.
command appeared in FreeBSD 2.2.2.

View file

@ -0,0 +1,302 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* gtags.c 12-Dec-97
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "global.h"
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(());
static int iflag;
static int oflag;
static int vflag;
static int Dflag;
static int Rflag;
static void
usage()
{
fprintf(stderr, "usage:\t%s [-i][-o][-v][dbpath]\n", progname);
exit(1);
}
void
main(argc, argv)
int argc;
char *argv[];
{
char dbpath[MAXPATHLEN+1];
char env[MAXENVLEN+1];
char *path, *p;
FILE *ip;
int db;
while (--argc > 0 && (++argv)[0][0] == '-') {
for (p = argv[0] + 1; *p; p++) {
switch (*p) {
case 'i':
iflag++;
break;
case 'o':
oflag++;
break;
case 'v':
vflag++;
break;
/* for compatibility */
case 's':
case 'e':
break;
default:
usage();
}
}
}
if (argc > 0) {
strcpy(dbpath, *argv);
} else {
if (!getcwd(dbpath, MAXPATHLEN))
die("cannot get current directory.");
}
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());
/*
* teach gctags(1) where is dbpath.
*/
sprintf(env, "GTAGSDBPATH=%s", dbpath);
putenv(env);
/*
* incremental update.
*/
if (iflag && test("f", makepath(dbpath, dbname(GTAGS))) &&
test("f", makepath(dbpath, dbname(GRTAGS))))
{
(void)incremental(dbpath);
exit(0);
}
if (iflag && vflag)
fprintf(stderr, " GTAGS and GRTAGS not found. -i option ignored.\n");
/*
* create GTAGS, GRTAGS and GSYMS
*/
for (db = GTAGS; db < GTAGLIM; db++) {
if (oflag && db == GSYMS)
continue;
if (vflag)
fprintf(stderr, "[%s] Creating '%s'.\n", current(), dbname(db));
createtags(dbpath, db);
}
if (vflag)
fprintf(stderr, "[%s] Done.\n", current());
exit(0);
}
/*
* incremental: incremental update
*
* i) dbpath dbpath directory
* r) 0: not updated, 1: updated
*/
int
incremental(dbpath)
char *dbpath;
{
struct stat sb;
time_t gtags_mtime;
int updated = 0;
char *path;
int db;
if (vflag) {
fprintf(stderr, " Tag found in '%s'.\n", dbpath);
fprintf(stderr, " Incremental update.\n");
}
/*
* get modified time of GTAGS.
*/
path = makepath(dbpath, dbname(GTAGS));
if (stat(path, &sb) < 0)
die1("stat failed '%s'.", path);
gtags_mtime = sb.st_mtime;
for (findopen(); path = findread(NULL); ) {
if (stat(path, &sb) < 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");
}
}
findclose();
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");
}
return updated;
}
/*
* tagadd: add records which has specified path.
*
* i) db 0: GTAGS, 1: GRTAGS, 2: GSYMS
* i) path source file
*/
void
tagadd(db, path)
int db;
char *path;
{
char *tagline, *p, *q;
char key[IDENTLEN+1];
FILE *ip;
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)) {
p = tagline;
q = key;
while (*p && !isspace(*p))
*q++ = *p++;
*q = 0;
tagput(key, tagline);
}
pclose(ip);
}
/*
* createtags: create tags file
*
* i) dbpath dbpath directory
* i) db GTAGS, GRTAGS, GSYMS
*/
void
createtags(dbpath, db)
char *dbpath;
int db;
{
char *path;
/*
* GTAGS needed to make GRTAGS.
*/
if (db == GRTAGS)
lookupopen(dbpath);
tagopen(dbpath, db, 1);
for (findopen(); path = findread(NULL); ) {
/*
* GRTAGS and GSYMS doesn't treat asembler.
*/
if (db != GTAGS) {
char *p = path + strlen(path) - 1;
if ((*p == 's' || *p == 'S') && *(p - 1) == '.')
continue;
}
if (vflag)
fprintf(stderr, " extracting tags of %s.\n", path);
tagadd(db, path);
}
findclose();
tagclose();
if (db == GRTAGS)
lookupclose();
}
/*
* current: current date and time
*
* r) date and time
*/
#include <time.h>
char *
current()
{
static char buf[80];
time_t tval;
if (time(&tval) == -1)
die("cannot get current time.");
(void)strftime(buf, sizeof(buf), "%+", localtime(&tval));
return buf;
}

View file

@ -1,9 +1,7 @@
# @(#)Makefile 1.0 (Berkeley) 4/21/96
MAN1= htags.1
beforeinstall:
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${.CURDIR}/htags.pl ${DESTDIR}/usr/bin/htags
${.CURDIR}/htags.pl ${DESTDIR}${BINDIR}/htags
.include <bsd.prog.mk>

View file

@ -1,8 +1,6 @@
# @(#)Makefile 29-Dec-96
PROG = htags
BINDIR = /usr/bin
MANDIR = /usr/share/man
MANDIR = /usr/man
all:
install:

View file

@ -108,10 +108,9 @@ If this variable is set, its value is used as the directory to make temporary fi
Default is /tmp.
.Sh DIAGNOSTICS
.Nm Htags
exits with a value of 1 if an error occurred, 0 otherwise.
exits with a non 0 value if an error occurred, 0 otherwise.
.Sh SEE ALSO
.Xr btreeop 1 ,
.Xr gctags 1 ,
.Xr global 1 ,
.Xr gtags 1 .
.Sh BUG
@ -121,4 +120,4 @@ Shigio Yamaguchi (shigio@wafu.netgate.net)
.Sh HISTORY
The
.Nm
command appeared in FreeBSD 2.2.
command appeared in FreeBSD 2.2.2.

View file

@ -29,12 +29,11 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# htags.pl 7-Jul-97
# htags.pl 31-Oct-97
#
$com = $0;
$com =~ s/.*\///;
$usage = "usage: $com [-a][-f][-l][-n][-v][-w][-t title][-d tagdir][dir]";
$ENV{'PATH'} = '/bin:/usr/bin';
$usage = "usage: $com [-a][-f][-l][-n][-v][-w][-t title][-d tagdir][dir]\n";
#-------------------------------------------------------------------------
# CONFIGURATION
#-------------------------------------------------------------------------
@ -95,6 +94,7 @@ $rewrite_href_files =
#-------------------------------------------------------------------------
# UTIRITIES
#-------------------------------------------------------------------------
$findcom = "find . \\( -type f -o -type l \\) -name '*.[chysS]' -print";
sub getcwd {
local($dir) = `/bin/pwd`;
chop($dir);
@ -106,9 +106,9 @@ sub date {
$date;
}
sub error {
local($msg) = @_;
&clean();
die "$com: " . $msg;
printf STDERR "$com: $_[0]\n";
exit 1;
}
sub clean {
&anchor'finish();
@ -120,19 +120,14 @@ sub escape {
}
sub usable {
local($com) = @_;
foreach $path (split(/:/, $ENV{'PATH'})) {
if (-x "$path/$com") {
return 1;
}
foreach (split(/:/, $ENV{'PATH'})) {
return 1 if (-x "$_/$com");
}
return 0;
}
sub copy {
local($from, $to) = @_;
local($ret);
$ret = system("cp $from $to");
local($ret) = system("cp $from $to");
$ret = $ret / 256;
$ret = ($ret == 0) ? 1 : 0;
$ret;
@ -141,21 +136,21 @@ sub copy {
# PROCESS START
#-------------------------------------------------------------------------
#
# options check ($sflag is set internally)
# options check.
#
$aflag = $cflag = $fflag = $lflag = $nflag = $vflag = $wflag = $sflag = '';
$aflag = $fflag = $lflag = $nflag = $vflag = $wflag = '';
while ($ARGV[0] =~ /^-/) {
$opt = shift;
if ($opt =~ /[^-aflnvwtd]/) {
print STDERR "$usage\n";
print STDERR $usage;
exit 1;
}
if ($opt =~ /a/) { $aflag = 1; }
if ($opt =~ /f/) { $fflag = 1; }
if ($opt =~ /l/) { $lflag = 1; }
if ($opt =~ /n/) { $nflag = 1; }
if ($opt =~ /v/) { $vflag = 1; }
if ($opt =~ /w/) { $wflag = 1; }
if ($opt =~ /a/) { $aflag = 'a'; }
if ($opt =~ /f/) { $fflag = 'f'; }
if ($opt =~ /l/) { $lflag = 'l'; }
if ($opt =~ /n/) { $nflag = 'n'; }
if ($opt =~ /v/) { $vflag = 'v'; }
if ($opt =~ /w/) { $wflag = 'w'; }
if ($opt =~ /t/) {
$opt = shift;
last if ($opt eq '');
@ -170,11 +165,9 @@ if (!$title) {
@cwd = split('/', &getcwd);
$title = $cwd[$#cwd];
}
if (!$dbpath) {
$dbpath = &getcwd();
}
$dbpath = &getcwd() if (!$dbpath);
unless (-r "$dbpath/GTAGS" && -r "$dbpath/GRTAGS") {
&error("GTAGS and GRTAGS not found. please type 'gtags[RET]'\n");
&error("GTAGS and GRTAGS not found. please type 'gtags[RET]'");
}
#
# recognize format version
@ -182,7 +175,7 @@ unless (-r "$dbpath/GTAGS" && -r "$dbpath/GRTAGS") {
#
$support_version = 1; # I can understand this format version
#
open(GTAGS, "btreeop -K ' __.VERSION' $dbpath/GTAGS |") || die "$com: GTAGS not found.\n";
open(GTAGS, "btreeop -K ' __.VERSION' $dbpath/GTAGS |") || &error("GTAGS not found.");
$rec = <GTAGS>;
close(GTAGS);
if ($rec =~ /^ __\.VERSION[ \t]+([0-9]+)$/) {
@ -191,7 +184,7 @@ if ($rec =~ /^ __\.VERSION[ \t]+([0-9]+)$/) {
$format_version = 1;
}
if ($format_version != $support_version) {
die "$com: GTAGS format version unmatched. Please remake it.\n";
&error("GTAGS format version unmatched. Please remake it.");
}
#
# check directories
@ -200,36 +193,23 @@ $html = &getcwd() . '/HTML';
if ($ARGV[0]) {
$cwd = &getcwd();
unless (-w $ARGV[0]) {
&error("$ARGV[0] is not writable directory.\n");
&error("'$ARGV[0]' is not writable directory.");
}
chdir($ARGV[0]) || &error("directory $ARGV[0] not found.\n");
chdir($ARGV[0]) || &error("directory '$ARGV[0]' not found.");
$html = &getcwd() . '/HTML';
chdir($cwd) || &error("cannot return directory.\n");
chdir($cwd) || &error("cannot return to original directory.");
}
#
# set sflag if *.[sS] are included.
#
open(CHECK, "btreeop $dbpath/GTAGS |") || &error("btreeop $dbpath/GTAGS failed.\n");
while (<CHECK>) {
local($tag, $lno, $filename) = split;
if ($filename =~ /\.[sS]$/) {
$'sflag = 1;
last;
}
}
close(CHECK);
#
# check if GTAGS, GRTAGS is the latest.
#
$gtags_ctime = (stat("$dbpath/GTAGS"))[10];
open(FIND, "find . -type f -name '*.[chysS]' -print |") || &error("cannot exec find.\n");
open(FIND, "$findcom |") || &error("cannot exec find.");
while (<FIND>) {
chop;
next if /(y\.tab\.c|y\.tab\.h)$/;
next if (!$'sflag && /\.[sS]$/);
next if /(\/SCCS\/|\/RCS\/)/;
if ($gtags_ctime < (stat($_))[10]) {
print STDERR "Caution: GTAGS is not the latest one. You had better make new one.\n";
&error("GTAGS is not the latest one. Please remake it.");
}
}
close(FIND);
@ -253,24 +233,24 @@ print STDERR "[", &date, "] ", "Htags started\n" if ($vflag);
#
# (0) make directories
#
print STDERR "[", &date, "] ", "(1) making directories ...\n" if ($vflag);
mkdir($html, 0777) || &error("cannot make directory <$html>.\n") if (! -d $html);
print STDERR "[", &date, "] ", "(0) making directories ...\n" if ($vflag);
mkdir($html, 0777) || &error("cannot make directory '$html'.") if (! -d $html);
foreach $d ($SRCS, $INCS, $DEFS, $REFS, files, funcs) {
mkdir("$html/$d", 0775) || &error("cannot make HTML directory\n") if (! -d "$html/$d");
mkdir("$html/$d", 0775) || &error("cannot make HTML directory") if (! -d "$html/$d");
}
if ($fflag) {
mkdir("$html/cgi-bin", 0775) || &error("cannot make cgi-bin directory\n") if (! -d "$html/cgi-bin");
mkdir("$html/cgi-bin", 0775) || &error("cannot make cgi-bin directory") if (! -d "$html/cgi-bin");
}
#
# (1) make CGI program
#
if ($fflag) {
print STDERR "[", &date, "] ", "(1) making CGI program ...\n" if ($vflag);
&makeprogram("$html/cgi-bin/global.cgi") || &error("cannot make CGI program.\n");
chmod(0755, "$html/cgi-bin/global.cgi") || &error("cannot chmod CGI program.\n");
&makeprogram("$html/cgi-bin/global.cgi") || &error("cannot make CGI program.");
chmod(0755, "$html/cgi-bin/global.cgi") || &error("cannot chmod CGI program.");
unlink("$html/cgi-bin/GTAGS", "$html/cgi-bin/GRTAGS");
link("$dbpath/GTAGS", "$html/cgi-bin/GTAGS") || &copy("$dbpath/GTAGS", "$html/cgi-bin/GTAGS") || &error("cannot copy GTAGS.\n");;
link("$dbpath/GRTAGS", "$html/cgi-bin/GRTAGS") || &copy("$dbpath/GRTAGS", "$html/cgi-bin/GRTAGS") || &error("cannot copy GRTAGS.\n");;
link("$dbpath/GTAGS", "$html/cgi-bin/GTAGS") || &copy("$dbpath/GTAGS", "$html/cgi-bin/GTAGS") || &error("cannot copy GTAGS.");
link("$dbpath/GRTAGS", "$html/cgi-bin/GRTAGS") || &copy("$dbpath/GRTAGS", "$html/cgi-bin/GRTAGS") || &error("cannot copy GRTAGS.");
}
#
# (2) make help file
@ -342,7 +322,7 @@ exit 0;
sub makeprogram {
local($file) = @_;
open(PROGRAM, ">$file") || &error("cannot make CGI program.\n");
open(PROGRAM, ">$file") || &error("cannot make CGI program.");
$program = <<'END_OF_SCRIPT';
#!/usr/bin/perl
#------------------------------------------------------------------
@ -377,6 +357,7 @@ $flag = ($form{'type'} eq 'definition') ? '' : 'r';
$words = ($form{'type'} eq 'definition') ? 'definitions' : 'referencies';
print "<H1><FONT COLOR=#cc0000>\"$pattern\"</FONT></H1>\n";
print "Following $words are matched to above pattern.<HR>\n";
$pattern =~ s/'//g; # to shut security hole
unless (open(PIPE, "/usr/bin/global -x$flag '$pattern' |")) {
print "<H3>Cannot execute global. <A HREF=../mains.html>[return]</A></H3>\n";
print "</HTML>\n";
@ -415,7 +396,7 @@ END_OF_SCRIPT
sub makehelp {
local($file) = @_;
open(HELP, ">$file") || &error("cannot make help file.\n");
open(HELP, ">$file") || &error("cannot make help file.");
print HELP "<HTML>\n<HEAD><TITLE>HELP</TITLE></HEAD>\n<BODY>\n";
print HELP "<H2>Usage of Links</H2>\n";
print HELP "<PRE>/* [&lt;][&gt;][^][v] [top][bottom][index][help] */</PRE>\n";
@ -458,7 +439,7 @@ sub makedupindex {
local($writing) = 0;
$count = 0;
open(LIST, "btreeop $dbpath/$db | sort +0 -1 +2 -3 +1n -2|") || &error("btreeop $dbpath/$db | sort +0 -1 +2 -3 +1n -2 failed.\n");
open(LIST, "btreeop $dbpath/$db | sort +0 -1 +2 -3 +1n -2|") || &error("btreeop $dbpath/$db | sort +0 -1 +2 -3 +1n -2 failed.");
while (<LIST>) {
chop;
local($tag, $lno, $filename) = split;
@ -481,7 +462,7 @@ sub makedupindex {
if ($first_line) {
&cache'put($db, $tag, '');
local($type) = ($db eq 'GTAGS') ? $DEFS : $REFS;
open(FILE, ">$html/$type/$tag.html") || &error("cannot make file <$html/$type/$tag.html>.\n");
open(FILE, ">$html/$type/$tag.html") || &error("cannot make file '$html/$type/$tag.html'.");
$writing = 1;
print FILE "<HTML>\n<HEAD><TITLE>$tag</TITLE></HEAD>\n<BODY>\n";
print FILE "<PRE>\n";
@ -516,13 +497,13 @@ sub makefuncindex {
local($file, $total) = @_;
local($count) = 0;
open(FUNCTIONS, ">$file") || &error("cannot make function index <$file>.\n");
open(FUNCTIONS, ">$file") || &error("cannot make function index '$file'.");
print FUNCTIONS "<HTML>\n<HEAD><TITLE>FUNCTION INDEX</TITLE>\n";
print FUNCTIONS "$begin_script$defaultview$end_script</HEAD>\n<BODY>\n";
print FUNCTIONS "<H2>FUNCTION INDEX</H2>\n";
print FUNCTIONS "<OL>\n" if (!$aflag);
local($old) = select(FUNCTIONS);
open(TAGS, "btreeop -L $dbpath/GTAGS |") || &error("btreeop -L $dbpath/GTAGS failed.\n");
open(TAGS, "btreeop -L $dbpath/GTAGS |") || &error("btreeop -L $dbpath/GTAGS failed.");
local($alpha) = '';
@funcs = (); # [A][B][C]...
while (<TAGS>) {
@ -540,7 +521,7 @@ sub makefuncindex {
}
$alpha = substr($tag, 0, 1);
push(@funcs, "<A HREF=funcs/$alpha.html TARGET=_self>[$alpha]</A>\n");
open(ALPHA, ">$html/funcs/$alpha.html") || &error("cannot make alphabetical function index.\n");
open(ALPHA, ">$html/funcs/$alpha.html") || &error("cannot make alphabetical function index.");
print ALPHA "<HTML>\n<HEAD><TITLE>$alpha</TITLE>\n";
print ALPHA "$begin_script$defaultview$end_script";
print ALPHA "</HEAD>\n<BODY>\n<H2>[$alpha]</H2>\n";
@ -586,18 +567,17 @@ sub makefileindex {
local($file, $incdir) = @_;
local($count) = 0;
open(FILES, ">$file") || &error("cannot make file <$file>.\n");
open(FILES, ">$file") || &error("cannot make file '$file'.");
print FILES "<HTML>\n<HEAD><TITLE>FILES</TITLE>\n";
print FILES "$begin_script$defaultview$end_script";
print FILES "</HEAD>\n<BODY>\n<H2>FILE INDEX</H2>\n";
print FILES "<OL>\n";
local($old) = select(FILES);
open(FIND, "find . -type f -name '*.[chysS]' -print | sort |") || &error("cannot exec find.\n");
open(FIND, "$findcom | sort |") || &error("cannot exec find.");
local($lastdir) = '';
@files = ();
while (<FIND>) {
next if /(y\.tab\.c|y\.tab\.h)$/;
next if (!$'sflag && /\.[sS]$/);
next if /(\/SCCS\/|\/RCS\/)/;
$count++;
@ -623,7 +603,7 @@ sub makefileindex {
}
if ($dir) {
push(@files, "<LI><A HREF=files/$dir.html TARGET=_self>$dir/</A>\n");
open(DIR, ">$html/files/$dir.html") || &error("cannot make directory index.\n");
open(DIR, ">$html/files/$dir.html") || &error("cannot make directory index.");
print DIR "<HTML>\n<HEAD><TITLE>$dir/</TITLE>\n";
print DIR "$begin_script$defaultview$end_script";
print DIR "</HEAD>\n<BODY>\n<H2>$dir/</H2>\n";
@ -668,7 +648,7 @@ sub makefileindex {
foreach $last (keys %includes) {
local(@incs) = split(/\n/, $includes{$last});
if (@incs > 1) {
open(INCLUDE, ">$incdir/$last.html") || &error("cannot open file '$incdir/$last.html'.\n");
open(INCLUDE, ">$incdir/$last.html") || &error("cannot open file '$incdir/$last.html'.");
print INCLUDE "<HTML>\n<HEAD><TITLE>$last</TITLE></HEAD>\n<BODY>\n<PRE>\n";
foreach $filename (@incs) {
local($path) = $filename;
@ -715,7 +695,7 @@ sub makecommonpart {
}
$index .= "<H2>MAINS</H2>\n";
$index .= "<PRE>\n";
open(PIPE, "btreeop -K main $dbpath/GTAGS | sort +0 -1 +2 -3 +1n -2|") || &error("btreeop -K main $dbpath/GTAGS failed.\n");
open(PIPE, "btreeop -K main $dbpath/GTAGS | sort +0 -1 +2 -3 +1n -2|") || &error("btreeop -K main $dbpath/GTAGS failed.");
while (<PIPE>) {
local($nouse, $lno, $filename) = split;
$nouse = ''; # to make perl quiet
@ -751,7 +731,7 @@ sub makecommonpart {
sub makeindex {
local($file, $title, $index) = @_;
open(FRAME, ">$file") || &error("cannot open file <$file>.\n");
open(FRAME, ">$file") || &error("cannot open file '$file'.");
print FRAME "<HTML>\n<HEAD><TITLE>$title</TITLE></HEAD>\n";
print FRAME "<FRAMESET COLS='200,*'>\n";
print FRAME "<NOFRAME>\n$index</NOFRAME>\n";
@ -773,7 +753,7 @@ sub makeindex {
sub makemainindex {
local($file, $index) = @_;
open(INDEX, ">$file") || &error("cannot create file <$file>.\n");
open(INDEX, ">$file") || &error("cannot create file '$file'.");
print INDEX "<HTML>\n<HEAD><TITLE>MAINS</TITLE></HEAD>\n";
print INDEX "<BODY>\n$index</BODY>\n</HTML>\n";
close(INDEX);
@ -787,10 +767,9 @@ sub makehtml {
local($total) = @_;
local($count) = 0;
open(FIND, "find . -type f -name '*.[chysS]' -print|") || &error("cannot exec find.\n");
open(FIND, "$findcom |") || &error("cannot exec find.");
while (<FIND>) {
next if /y\.tab\.c|y\.tab\.h/;
next if (!$'sflag && /\.[sS]$/);
next if /(\/SCCS\/|\/RCS\/)/;
$count++;
@ -821,14 +800,14 @@ sub src2html {
local($expand) = &'usable('expand') ? 'expand' : 'cat';
local(%ctab) = ('&', '&amp;', '<', '&lt;', '>', '&gt;');
open(HTML, ">$html") || &'error("cannot create file <$html>.\n");
open(HTML, ">$html") || &'error("cannot create file '$html'.");
local($old) = select(HTML);
#
# load tags belonging to this file.
#
$file =~ s/^\.\///;
&anchor'load($file);
open(C, "$expand '$file' |") || &'error("cannot open file <$file>.\n");
open(C, "$expand '$file' |") || &'error("cannot open file '$file'.");
#
# print the header
#
@ -1053,18 +1032,26 @@ package anchor;
#
# create: create anchors temporary database
#
# go) %PATHLIST
#
sub create {
$ANCH = "$'tmp/ANCH$$";
open(ANCH, ">$ANCH") || &'error("cannot create file $ANCH.\n");
open(ANCH, ">$ANCH") || &'error("cannot create file '$ANCH'.");
close(ANCH);
chmod ($ANCH, 0600);
open(ANCH, "| btreeop -C $ANCH") || &'error("btreeop -C $ANCH failed.\n");
open(ANCH, "| btreeop -C $ANCH") || &'error("btreeop -C $ANCH failed.");
local($fcount) = 1;
local($fnumber);
foreach $db ('GTAGS', 'GRTAGS') {
local($type) = ($db eq 'GTAGS') ? 'D' : 'R';
open(PIPE, "btreeop $'dbpath/$db |") || &'error("btreeop $'dbpath/$db failed.\n");
open(PIPE, "btreeop $'dbpath/$db |") || &'error("btreeop $'dbpath/$db failed.");
while (<PIPE>) {
local($tag, $lno, $filename) = split;
print ANCH "$filename $lno $tag $type\n";
$fnumber = $PATHLIST{$filename};
if (!$fnumber) {
$PATHLIST{$filename} = $fnumber = $fcount++;
}
print ANCH "$fnumber $lno $tag $type\n";
}
close(PIPE);
}
@ -1080,25 +1067,31 @@ sub finish {
# load: load anchors in a file from database
#
# i) $file source file
# gi) %PATHLIST
# go) FIRST first definition
# go) LAST last definition
#
sub load {
local($file) = @_;
$file = './' . $file if ($file !~ /^\.\//);
local($fnumber);
@ANCHORS = ();
open(ANCH, "btreeop -K $file $ANCH |") || &'error("btreeop -K $file $ANCH failed.\n");
$FIRST = $LAST = 0;
$file = './' . $file if ($file !~ /^\.\//);
if (!($fnumber = $PATHLIST{$file})) {
return;
}
open(ANCH, "btreeop -K $fnumber $ANCH |") || &'error("btreeop -K $file $ANCH failed.");
$n = 0;
while (<ANCH>) {
local($filename, $lno, $tag, $type) = split;
local($fnumber, $lno, $tag, $type) = split;
local($line);
# don't refer to macros which is defined in other C source.
if ($type eq 'R' && ($line = &cache'get('GTAGS', $tag))) {
local($nouse1, $nouse2, $f, $def) = split(/[ \t]+/, $line);
if ($f !~ /\.h$/ && $f !~ $filename && $def =~ /^#/) {
print STDERR "Information: $filename $lno $tag($type) skipped, because this is a macro which is defined in other C source.\n" if ($'wflag);
if ($f !~ /\.h$/ && $f !~ $file && $def =~ /^#/) {
print STDERR "Information: $file $lno $tag($type) skipped, because this is a macro which is defined in other C source.\n" if ($'wflag);
next;
}
}
@ -1112,7 +1105,6 @@ $n = 0;
sub compare { $keys[$a] <=> $keys[$b]; }
@ANCHORS = @ANCHORS[sort compare 0 .. $#keys];
local($c);
$FIRST = $LAST = 0;
for ($c = 0; $c < @ANCHORS; $c++) {
local($lno, $tag, $type) = split(/,/, $ANCHORS[$c]);
if ($type eq 'D') {
@ -1244,7 +1236,7 @@ sub put {
$cachecount++;
if ($cachesize >= 0 && $cachecount > $cachesize) {
$CACH = "$'tmp/CACH$$";
dbmopen(%CACH, $CACH, 0600) || &'error("make cache database.\n");
dbmopen(%CACH, $CACH, 0600) || &'error("make cache database.");
$cachesize = -1;
}
$CACH{$label.$tag} = $line;

View file

@ -0,0 +1,8 @@
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
.include <bsd.lib.mk>

View file

@ -0,0 +1,14 @@
LIB = libutil.a
CC = gcc
AR = ar
CFLAGS = -O -I../lib -I/usr/include/db
OBJS = 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
all: $(LIB)
$(LIB): $(OBJS)
$(AR) cq $(LIB) $(OBJS)
install:
@echo -n
clean:
rm -f $(LIB) $(OBJS)

322
contrib/global/lib/dbio.c Normal file
View file

@ -0,0 +1,322 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redilogibution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redilogibutions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redilogibutions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the dilogibution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* dbio.c 14-Dec-97
*
*/
#include <stdlib.h>
#include <fcntl.h>
#include "dbio.h"
#include "die.h"
DBT key; /* key of record */
DBT dat; /* data of record */
/*
* db_open: open db database.
*
* i) dbname database name
* i) mode 0: read only, 1: write only, 2: read & write
* i) perm file permission
* i) flags
* DBIO_DUP: allow duplicate records.
* DBIO_REMOVE: remove on closed.
* r) descripter for db_xxx()
*
* db_open leaves database permission 0600. please chmod(2) to make public.
*/
DBIO *
db_open(dbname, mode, perm, flags)
char *dbname;
int mode;
int perm;
int flags;
{
DB *db;
int rw;
BTREEINFO info;
DBIO *dbio;
/*
* setup argments.
*/
if (mode == 0)
rw = O_RDONLY;
else if (mode == 1)
rw = O_RDWR|O_CREAT|O_TRUNC;
else if (mode == 2)
rw = O_RDWR;
else
die("db_open illegal mode.");
info.flags = (flags & DBIO_DUP) ? R_DUP : 0;
info.cachesize = 500000;
info.maxkeypage = 0;
info.minkeypage = 0;
info.psize = 0;
info.compare = NULL;
info.prefix = NULL;
info.lorder = LITTLE_ENDIAN;
/*
* if unlink do job normally, those who already open tag file can use
* it until closing.
*/
if (mode == 1 && test("f", dbname))
(void)unlink(dbname);
db = dbopen(dbname, rw, 0600, DB_BTREE, &info);
if (!db)
die1("db_open failed (dbname = %s).", dbname);
if (!(dbio = (DBIO *)malloc(sizeof(DBIO))))
die("short of memory.");
strcpy(dbio->dbname, dbname);
dbio->db = db;
dbio->openflags = flags;
dbio->perm = (mode == 1) ? perm : 0;
dbio->lastkey = (char *)0;
dbio->lastdat = (char *)0;
return dbio;
}
/*
* db_get: get data by a key.
*
* i) dbio descripter
* i) k key
* r) pointer to data
*/
char *
db_get(dbio, k)
DBIO *dbio;
char *k;
{
DB *db = dbio->db;
int status;
key.data = k;
key.size = strlen(k)+1;
status = (*db->get)(db, &key, &dat, 0);
dbio->lastkey = (char *)key.data;
dbio->lastdat = (char *)dat.data;
switch (status) {
case RET_SUCCESS:
break;
case RET_ERROR:
die("db_get failed.");
case RET_SPECIAL:
return((char *)0);
}
return((char *)dat.data);
}
/*
* db_put: put data by a key.
*
* i) dbio descripter
* i) k key
* i) d data
*/
void
db_put(dbio, k, d)
DBIO *dbio;
char *k;
char *d;
{
DB *db = dbio->db;
int status;
if (strlen(k) > MAXKEYLEN)
die("primary key too long.");
key.data = k;
key.size = strlen(k)+1;
dat.data = d;
dat.size = strlen(d)+1;
status = (*db->put)(db, &key, &dat, 0);
switch (status) {
case RET_SUCCESS:
break;
case RET_ERROR:
case RET_SPECIAL:
die("db_put failed.");
}
}
/*
* db_del: delete record by a key.
*
* i) dbio descripter
* i) k key
*/
void
db_del(dbio, k)
DBIO *dbio;
char *k;
{
DB *db = dbio->db;
int status;
if (k) {
key.data = k;
key.size = strlen(k)+1;
status = (*db->del)(db, &key, 0);
} else
status = (*db->del)(db, &key, R_CURSOR);
if (status == RET_ERROR)
die("db_del failed.");
}
/*
* db_first: get first record.
*
* i) dbio dbio descripter
* i) k key
* !=NULL: indexed read by key
* ==NULL: sequential read
* i) flags following db_next call take over this.
* DBIO_KEY read key part
* DBIO_PREFIX prefix read
* DBIO_SKIPMETA skip META record
* only valied when sequential read
* r) data
*/
char *
db_first(dbio, k, flags)
DBIO *dbio;
char *k;
int flags;
{
DB *db = dbio->db;
int status;
if (flags & DBIO_PREFIX && !k)
flags &= ~DBIO_PREFIX;
if (flags & DBIO_SKIPMETA && k)
flags &= ~DBIO_SKIPMETA;
if (k) {
if (strlen(k) > MAXKEYLEN)
die("primary key too long.");
strcpy(dbio->key, k);
key.data = k;
key.size = strlen(k);
/*
* includes NULL character unless prefix read.
*/
if (!(flags & DBIO_PREFIX))
key.size++;
dbio->keylen = key.size;
status = (*db->seq)(db, &key, &dat, R_CURSOR);
} else {
dbio->keylen = dbio->key[0] = 0;
for (status = (*db->seq)(db, &key, &dat, R_FIRST);
status == RET_SUCCESS &&
flags & DBIO_SKIPMETA &&
*((char *)dat.data) == ' ';
status = (*db->seq)(db, &key, &dat, R_NEXT))
;
}
dbio->lastkey = (char *)key.data;
dbio->lastdat = (char *)dat.data;
switch (status) {
case RET_SUCCESS:
break;
case RET_ERROR:
die("db_first failed.");
case RET_SPECIAL:
return ((char *)0);
}
dbio->ioflags = flags;
if (flags & DBIO_PREFIX) {
if (strncmp((char *)key.data, dbio->key, dbio->keylen))
return (char *)0;
} else if (dbio->keylen) {
if (strcmp((char *)key.data, dbio->key))
return (char *)0;
}
if (flags & DBIO_KEY) {
strcpy(dbio->prev, (char *)key.data);
return (char *)key.data;
}
return ((char *)dat.data);
}
/*
* db_next: get next record.
*
* i) dbio dbio descripter
* r) data
*/
char *
db_next(dbio)
DBIO *dbio;
{
DB *db = dbio->db;
int flags = dbio->ioflags;
int status;
while ((status = (*db->seq)(db, &key, &dat, R_NEXT)) == RET_SUCCESS) {
if (flags & DBIO_SKIPMETA) {
if (*((char *)dat.data) == ' ')
continue;
}
if (flags & DBIO_KEY) {
if (!strcmp(dbio->prev, (char *)key.data))
continue;
if (strlen((char *)key.data) > MAXKEYLEN)
die("primary key too long.");
strcpy(dbio->prev, (char *)key.data);
}
dbio->lastkey = (char *)key.data;
dbio->lastdat = (char *)dat.data;
if (flags & DBIO_PREFIX) {
if (strncmp((char *)key.data, dbio->key, dbio->keylen))
return (char *)0;
} else if (dbio->keylen) {
if (strcmp((char *)key.data, dbio->key))
return (char *)0;
}
return (flags & DBIO_KEY) ? (char *)key.data : (char *)dat.data;
}
if (status == RET_ERROR)
die("db_next failed.");
return (char *)0;
}
/*
* db_close: close db
*
* i) dbio dbio descripter
*/
void
db_close(dbio)
DBIO *dbio;
{
DB *db = dbio->db;
(void)db->close(db);
if (dbio->openflags & DBIO_REMOVE)
(void)unlink(dbio->dbname);
else if (dbio->perm && chmod(dbio->dbname, dbio->perm) < 0)
die("cannot change file mode.");
(void)free(dbio);
}

89
contrib/global/lib/dbio.h Normal file
View file

@ -0,0 +1,89 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redilogibution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redilogibutions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redilogibutions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the dilogibution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* dbio.h 14-Dec-97
*
*/
#ifndef _DBIO_H_
#define _DBIO_H_
#include <db.h>
#include <sys/param.h>
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234
#endif
#ifndef BIG_ENDIAN
#define BIG_ENDIAN 4321
#endif
#define MAXKEYLEN 300
typedef struct {
DB *db; /* descripter of DB */
char dbname[MAXPATHLEN+1]; /* dbname */
char key[MAXKEYLEN+1]; /* key */
int keylen; /* key length */
char prev[MAXKEYLEN+1]; /* previous key value */
char *lastkey; /* the key of last located record */
char *lastdat; /* the data of last located record */
int openflags; /* flags of db_open() */
int ioflags; /* flags of db_first() */
int perm; /* file permission */
} DBIO;
/*
* openflags
*/
#define DBIO_DUP 1 /* allow duplicate records */
#define DBIO_REMOVE 2 /* remove file when closed */
/*
* ioflags
*/
#define DBIO_KEY 1 /* read key part */
#define DBIO_PREFIX 2 /* prefixed read */
#define DBIO_SKIPMETA 4 /* skip META record */
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
DBIO *db_open __P((char *, int, int, int));
char *db_get __P((DBIO *, char *));
void db_put __P((DBIO *, char *, char *));
void de_del __P((DBIO *, char *));
char *db_first __P((DBIO *, char *, int));
char *db_next __P((DBIO *));
void db_close __P((DBIO *));
#endif /* _DBIO_H_ */

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* dbname.c 20-Oct-97
*
*/
#include "dbname.h"
static char *tagslist[] = {"GTAGS", "GRTAGS", "GSYMS"};
/*
* dbname: return db name
*
* i) db 0: GTAGS, 1: GRTAGS, 2: GSYMS
* r) dbname
*/
char *
dbname(db)
int db;
{
return tagslist[db];
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* dbname.h 16-Oct-97
*
*/
#ifndef _DBNAME_H_
#define _DBNAME_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
#define GTAGS 0
#define GRTAGS 1
#define GSYMS 2
#define GTAGLIM 3
char *dbname __P((int));
#endif /* ! _DBNAME_H_ */

49
contrib/global/lib/die.h Normal file
View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* die.h 16-Oct-97
*
*/
#ifndef _DIE_H_
#define _DIE_H_
#include <stdio.h>
extern char *progname;
#define die(a) fprintf(stderr, "%s: ", progname),\
fprintf(stderr, a),\
fputs("\n", stderr),\
exit(1)
#define die1(a,b) fprintf(stderr, "%s: ", progname),\
fprintf(stderr, a, b),\
fputs("\n", stderr),\
exit(1)
#endif /* ! _DIE_H_ */

165
contrib/global/lib/find.c Normal file
View file

@ -0,0 +1,165 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* find.c 20-Oct-97
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>
#include <sys/param.h>
#include "gparam.h"
#include "find.h"
#include "die.h"
#include "locatestring.h"
/*
* usage of findxxx()
*
* findopen();
* 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 int opened;
int
issource(path)
char *path;
{
char c, *p, *q;
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;
}
return 0;
}
void
findopen()
{
char edit[512], *p, *q;
int i, lim;
if (opened)
die("nested call to findopen.");
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);
}
sprintf(p, " \\) -print");
if (sizeof(skippath) != 0) {
int i, lim = sizeof(skippath)/sizeof(char *);
/*
* construct regular expression.
*/
p = edit;
*p++ = '(';
for (i = 0; i < lim; i++) {
*p++ = '/';
for (q = skippath[i]; *q; q++) {
if (*q == '.')
*p++ = '\\';
*p++ = *q;
}
if (*(q - 1) != '/')
*p++ = '$';
*p++ = '|';
}
*(p - 1) = ')';
*p = 0;
/*
* compile regular expression.
*/
skip = &skip_area;
if (regcomp(skip, edit, REG_EXTENDED|REG_NEWLINE) != 0)
die("cannot compile regular expression.");
} else {
skip = (regex_t *)0;
}
if (!(ip = popen(findcom, "r")))
die("cannot execute find.");
}
char *
findread(length)
int *length;
{
static char path[MAXPATHLEN+1];
char *p;
while (fgets(path, MAXPATHLEN, ip)) {
if (!skip || regexec(skip, path, 0, 0, 0) != 0) {
p = path + strlen(path) - 1;
if (*p != '\n')
die("output of find(1) is wrong (findread).");
*p = 0;
if (length)
*length = p - path;
return path;
}
}
return (char *)0;
}
void
findclose()
{
pclose(ip);
opened = 0;
}

51
contrib/global/lib/find.h Normal file
View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* find.h 16-Oct-97
*
*/
#ifndef _FIND_H_
#define _FIND_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
int issource __P((char *));
void findopen __P(());
char *findread __P((int *));
void findclose __P(());
#endif /* ! _FIND_H_ */

View file

@ -0,0 +1,154 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* getdbpath.c 20-Oct-97
*
*/
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include "die.h"
#include "locatestring.h"
static char *makeobjdirprefix; /* obj partition */
static char *makeobjdir; /* obj directory */
static int bsd; /* if BSD */
/*
* gtagsexist: test whether GTAGS's existence.
*
* i) candidate candidate root directory
* o) dbpath directory which GTAGS exist
* r) 0: not found, 1: found
*/
int
gtagsexist(candidate, dbpath)
char *candidate;
char *dbpath;
{
char path[MAXPATHLEN+1];
sprintf(path, "%s/GTAGS", candidate);
if (test("fr", path)) {
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;
}
}
return 0;
}
/*
* getdbpath: get dbpath directory
*
* o) cwd current directory
* o) root root of source tree
* o) dbpath directory which GTAGS exist
*
* root and dbpath assumed as
* char cwd[MAXPATHLEN+1];
* char root[MAXPATHLEN+1];
* char dbpath[MAXPATHLEN+1];
*/
void
getdbpath(cwd, root, dbpath)
char *cwd;
char *root;
char *dbpath;
{
struct stat sb;
char *p;
if (!getcwd(cwd, MAXPATHLEN))
die("cannot get current directory.");
/*
* GLOBAL never think '/' is the root of source tree.
*/
if (!strcmp(cwd, "/"))
die("It's root directory! What are you doing?");
if (getenv("OSTYPE") && locatestring(getenv("OSTYPE"), "BSD", 0)) {
if (p = getenv("MAKEOBJDIRPREFIX"))
makeobjdirprefix = p;
else
makeobjdirprefix = "/usr/obj";
if (p = getenv("MAKEOBJDIR"))
makeobjdir = p;
else
makeobjdir = "obj";
bsd = 1;
}
if (p = getenv("GTAGSROOT")) {
if (*p != '/')
die("GTAGSROOT must be an absolute path.");
if (stat(p, &sb) || !S_ISDIR(sb.st_mode))
die1("directory '%s' not found.", p);
strcpy(root, p);
/*
* GTAGSDBPATH is meaningful only when GTAGSROOT exist.
*/
if (p = getenv("GTAGSDBPATH")) {
if (*p != '/')
die("GTAGSDBPATH must be an absolute path.");
if (stat(p, &sb) || !S_ISDIR(sb.st_mode))
die1("directory '%s' not found.", p);
strcpy(dbpath, getenv("GTAGSDBPATH"));
} else {
if (!gtagsexist(root, dbpath))
die("GTAGS not found.");
}
} else {
/*
* start from current directory to '/' directory.
*/
strcpy(root, cwd);
p = root + strlen(root);
while (!gtagsexist(root, dbpath)) {
while (*--p != '/')
;
*p = 0;
if (root == p) /* reached root directory */
break;
}
if (*root == 0)
die("GTAGS not found.");
}
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* getdbpath.h 16-Oct-97
*
*/
#ifndef _GETDBPATH_H_
#define _GETDBPATH_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
int gtagsexist __P((char *, char *));
void getdbpath __P((char *, char *, char *));
#endif /* ! _GETDBPATH_H_ */

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* global.h 16-Oct-97
*
*/
#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 "die.h"
#include "find.h"
#include "getdbpath.h"
#include "strop.h"
#include "gtagsopen.h"
#include "lookup.h"
#include "tab.h"
#include "tag.h"
#include "test.h"
#endif /* ! _GLOBAL_H_ */

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* gparam.h 16-Oct-97
*
*/
#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 */
#endif /* ! _GPARAM_H_ */

View file

@ -0,0 +1,95 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* gtagsopen.c 20-Oct-97
*
*/
#include <sys/param.h>
#include <fcntl.h>
#include <db.h>
#include "dbio.h"
#include "die.h"
#include "makepath.h"
#include "dbname.h"
#define VERSIONKEY " __.VERSION"
static int support_version = 1; /* accept this format version */
/*
* gtagsopen: open global database.
*
* i) dbpath dbpath directory
* i) db GTAGS, GRTAGS, GSYMS
* i) mode 0: read only
* 1: write only
* 2: read and write
* r) DB structure
*
* when error occurred, gtagopen doesn't return.
*/
DBIO *
gtagsopen(dbpath, db, mode)
char *dbpath;
int db;
int mode;
{
DBIO *dbio;
int version_number;
char *p;
/*
* allow duplicate records.
*/
dbio = db_open(makepath(dbpath, dbname(db)), mode, 0644, DBIO_DUP);
if (dbio == NULL) {
if (mode == 1)
die1("cannot make database (%s).", makepath(dbpath, dbname(db)));
die1("database not found (%s).", makepath(dbpath, dbname(db)));
}
if (mode == 1) {
/* nothing to do now */
} else {
/*
* recognize format version of GTAGS. 'format version record'
* is saved as a META record in GTAGS and GRTAGS.
* if 'format version record' is not found, it's assumed
* version 1.
*/
if (p = db_get(dbio, VERSIONKEY)) {
for (p += strlen(VERSIONKEY); *p && isspace(*p); p++)
;
version_number = atoi(p);
} else
version_number = 1;
if (version_number > support_version)
die("GTAGS seems new format. Please install the latest GLOBAL.");
}
return dbio;
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* gtagsopen.h 16-Oct-97
*
*/
#ifndef _GTAGSOPEN_H_
#define _GTAGSOPEN_H_
#include "dbio.h"
DBIO *gtagsopen __P((char *, int, int));
#endif /* ! _GTAGSOPEN_H_ */

View file

@ -0,0 +1,70 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* locatestring.c 20-Oct-97
*
*/
/*
* locatestring: locate pattern from string
*
* 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
* r) pointer or NULL
*
* This function is made to avoid compatibility problems.
*/
char *
locatestring(string, pattern, flag)
char *string;
char *pattern;
int flag;
{
int c = *pattern;
char *p = (char *)0;
if (flag == 3 && strlen(string) > strlen(pattern)) {
string += strlen(string) - strlen(pattern);
}
for (; *string; string++) {
if (*string == c)
if (!strncmp(string, pattern, strlen(pattern))) {
p = string;
if (flag == 0)
break;
}
if (flag == 1 || flag == 3)
break;
}
return p;
}

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* locatestring.h 16-Oct-97
*
*/
#ifndef _LOCATESTRING_H_
#define _LOCATESTRING_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
char *locatestring __P((char *, char *, int));
#endif /* ! _LOCATESTRING_H_ */

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* lookup.c 20-Oct-97
*
*/
#include "gtagsopen.h"
#include "lookup.h"
#include "dbio.h"
#include "die.h"
#include "dbname.h"
static DBIO *dbio;
static int opened;
void
lookupopen(dbpath)
char *dbpath;
{
if (opened)
die("nested call to lookupopen.");
opened = 1;
dbio = gtagsopen(dbpath, GTAGS, 0);
}
int
lookup(name)
char *name;
{
char *p = db_get(dbio, name);
return (p) ? 1 : 0;
}
void
lookupclose()
{
db_close(dbio);
opened = 0;
}

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* lookup.h 16-Oct-97
*
*/
#ifndef _LOOKUP_H_
#define _LOOKUP_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
void lookupopen __P((char *));
int lookup __P((char *));
void lookupclose __P(());
#endif /* ! _LOOKUP_H_ */

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* makepath.c 20-Oct-97
*
*/
#include <sys/param.h>
#include "makepath.h"
/*
* makepath: make path from directory and file.
*
* i) dir directory
* i) file file
* r) path
*/
char *
makepath(dir, file)
char *dir;
char *file;
{
static char path[MAXPATHLEN+1];
char *p;
strcpy(path, dir);
p = path + strlen(path);
if (*(p - 1) != '/')
*p++ = '/';
strcpy(p, file);
return path;
}

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* makepath.h 16-Oct-97
*
*/
#ifndef _MAKEPATH_H_
#define _MAKEPATH_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
char *makepath __P((char *, char *));
#endif /* ! _MAKEPATH_H_ */

113
contrib/global/lib/mgets.c Normal file
View file

@ -0,0 +1,113 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* mgets.c 8-Nov-97
*
*/
#include <stdio.h>
#include "mgets.h"
#include "die.h"
#define EXPANDSIZE 512
static int mbufsize = EXPANDSIZE;
static char *mbuf;
/*
* mgets: read whole record into allocated buffer
*
* i) ip input stream
* i) flags flags
* MGETS_CONT \\ + \n -> \n
* MGETS_SKIPCOM skip line which start with '#'.
* o) length length of record
* 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)
FILE *ip;
int flags;
int *length;
{
char *p;
/*
* allocate initial buffer.
*/
if (!mbuf)
if (!(mbuf = (char *)malloc(mbufsize + 1)))
die("short of memory.");
/*
* read whole record.
*/
if (!fgets(mbuf, mbufsize, ip))
return (char *)0;
if (flags & MGETS_SKIPCOM)
while (*mbuf == '#')
if (!fgets(mbuf, mbufsize, ip))
return (char *)0;
p = mbuf + strlen(mbuf);
for (;;) {
/*
* get a line.
*/
while (*(p - 1) != '\n') {
/*
* expand 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.");
p += strlen(p);
}
/*
* chop(mbuf)
*/
*(--p) = 0;
if (*(p - 1) == '\r')
*(--p) = 0;
/*
* continue?
*/
if ((flags & MGETS_CONT) && *(p - 1) == '\\')
*(--p) = 0;
else
break;
}
if (length)
*length = p - mbuf;
return mbuf;
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redilogibution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redilogibutions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redilogibutions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the dilogibution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* mgets.h 20-Oct-97
*
*/
#ifndef _MGETS_H_
#define _MGETS_H_
#include <stdio.h>
#define MGETS_CONT 1
#define MGETS_SKIPCOM 2
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
char *mgets __P((FILE *, int, int *));
#endif /* ! _MGETS_H_ */

117
contrib/global/lib/strop.c Normal file
View file

@ -0,0 +1,117 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* strop.c 20-Oct-97
*
*/
#include "strop.h"
#include "die.h"
/*
* usage: string buffer
*
* stropen();
* for (s = string; *s; s++)
* strputc(*s);
* s = strclose();
*/
#define EXPANDSIZE 80
static char *sbuf;
static char *endp;
static char *curp;
static int sbufsize;
static int opened;
void
stropen()
{
if (opened)
die("nested call to stropen.");
opened = 1;
/*
* allocate initial buffer.
*/
if (!sbuf)
if (!(sbuf = (char *)malloc(sbufsize + 1)))
die("short of memory.");
curp = sbuf;
endp = sbuf + sbufsize;
*curp = 0;
}
void
strputs(s)
char *s;
{
int length = strlen(s);
strnputs(s, length);
}
void
strnputs(s, length)
char *s;
int length;
{
if (curp + length > endp) {
int count = curp - sbuf;
sbufsize += (length > EXPANDSIZE) ? length : EXPANDSIZE;
if (!(sbuf = (char *)realloc(sbuf, sbufsize + 1)))
die("short of memory.");
curp = sbuf + count;
endp = sbuf + sbufsize;
}
strncpy(curp, s, length);
curp += length;
*curp = 0;
}
void
strputc(c)
int c;
{
if (curp + 1 > endp) {
int count = curp - sbuf;
sbufsize += EXPANDSIZE;
if (!(sbuf = (char *)realloc(sbuf, sbufsize + 1)))
die("short of memory.");
curp = sbuf + count;
endp = sbuf + sbufsize;
}
*curp++ = c;
*curp = 0;
}
char *
strclose()
{
opened = 0;
/*
* doesn't free area in current implementation.
*/
return sbuf;
}

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* strop.h 16-Oct-97
*
*/
#ifndef _STROP_H_
#define _STROP_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
void stropen __P(());
void strputs __P((char *));
void strnputs __P((char *, int));
void strputc __P((int));
char *strclose __P(());
#endif /* ! _STROP_H_ */

99
contrib/global/lib/tab.c Normal file
View file

@ -0,0 +1,99 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* tab.c 20-Oct-97
*
*/
#include <stdio.h>
#define TABPOS(i) ((i)%8 == 0)
/*
* detab: convert tabs into spaces and print
*
* i) op FILE *
* i) buf string including tabs
*/
void
detab(op, buf)
FILE *op;
char *buf;
{
int src, dst;
char c;
src = dst = 0;
while ((c = buf[src++]) != 0) {
if (c == '\t') {
do {
(void)putc(' ', op);
dst++;
} while (!TABPOS(dst));
} else {
(void)putc(c, op);
dst++;
}
}
(void)putc('\n', op);
}
/*
* entab: convert spaces into tabs
*
* io) buf string buffer
*/
void
entab(buf)
char *buf;
{
int blanks = 0;
int pos, src, dst;
char c;
pos = src = dst = 0;
while ((c = buf[src++]) != 0) {
if (c == ' ') {
if (!TABPOS(++pos)) {
blanks++; /* count blanks */
continue;
}
buf[dst++] = '\t';
} else if (c == '\t') {
while (!TABPOS(++pos))
;
buf[dst++] = '\t';
} else {
++pos;
while (blanks--)
buf[dst++] = ' ';
buf[dst++] = c;
}
blanks = 0;
}
buf[dst] = 0;
}

49
contrib/global/lib/tab.h Normal file
View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* tab.h 16-Oct-97
*
*/
#ifndef _TAB
#define _TAB_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
void detab __P((FILE *, char *));
void entab __P((char *));
#endif /* ! _TAB_H_ */

80
contrib/global/lib/tag.c Normal file
View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* tag.c 20-Oct-97
*
*/
#include "dbio.h"
#include "die.h"
#include "gtagsopen.h"
#include "tag.h"
#include "locatestring.h"
static DBIO *dbio;
static int opened;
void
tagopen(dbpath, db, mode)
char *dbpath;
int db;
int mode;
{
if (opened)
die("nested call to tagopen.");
opened = 1;
dbio = gtagsopen(dbpath, db, mode);
}
void
tagput(entry, record)
char *entry;
char *record;
{
entab(record);
db_put(dbio, entry, record);
}
void
tagdelete(path)
char *path;
{
char *p;
int length = strlen(path);
for (p = db_first(dbio, NULL, DBIO_SKIPMETA); p; p = db_next(dbio)) {
p = locatestring(p, "./", 0);
if (!strncmp(p, path, length) && isspace(*(p + length)))
db_del(dbio, NULL);
}
}
void
tagclose()
{
db_close(dbio);
opened = 0;
}

51
contrib/global/lib/tag.h Normal file
View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* tag.h 16-Oct-97
*
*/
#ifndef _TAG_H_
#define _TAG_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
void tagopen __P((char *, int, int));
void tagput __P((char *, char *));
void tagdelete __P((char *));
void tagclose __P(());
#endif /* ! _TAG_H_ */

90
contrib/global/lib/test.c Normal file
View file

@ -0,0 +1,90 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* test.c 12-Dec-97
*
*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
/*
* test:
*
* i) flags file flags
*
* "f" [ -f path ]
* "d" [ -d path ]
* "r" [ -r path ]
* "w" [ -w path ]
* "x" [ -x path ]
*
* i) path 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;
{
struct stat sb;
int c;
if (stat(path, &sb) < 0)
return 0;
while (c = *flags++) {
switch (c) {
case 'f':
if (!S_ISREG(sb.st_mode))
return 0;
break;
case 'd':
if (!S_ISDIR(sb.st_mode))
return 0;
break;
case 'r':
if (access(path, R_OK) < 0)
return 0;
break;
case 'w':
if (access(path, W_OK) < 0)
return 0;
break;
case 'x':
if (access(path, X_OK) < 0)
return 0;
break;
default:
break;
}
}
return 1;
}

48
contrib/global/lib/test.h Normal file
View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Shigio Yamaguchi.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* test.h 16-Oct-97
*
*/
#ifndef _TEST_H_
#define _TEST_H_
#ifndef __P
#if defined(__STDC__)
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
int test __P((char *, char *));
#endif /* ! _TEST_H_ */

View file

@ -1,7 +1,5 @@
# @(#)Makefile 1.0 (Berkeley) 4/21/96
beforeinstall:
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${.CURDIR}/systags.sh ${DESTDIR}/usr/bin/systags
${.CURDIR}/systags.sh ${DESTDIR}${BINDIR}/systags
.include <bsd.prog.mk>

View file

@ -1,5 +1,3 @@
# @(#)Makefile 29-Dec-96
PROG = systags
BINDIR = /usr/bin

View file

@ -58,15 +58,15 @@ fi
# remove old files
#
case $nflag in
1) echo "rm -rf $dir/htags.log $dir/GTAGS $dir/GRTAGS $dir/HTML";;
*) rm -rf $dir/htags.log $dir/GTAGS $dir/GRTAGS $dir/HTML;;
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;;
esac
#
# make global database(GTAGS, GRTAGS).
# make global database(GTAGS, GRTAGS, GSYMS).
#
case $nflag in
1) echo "gtags -se $dir";;
*) gtags -se $dir;;
1) echo "gtags -v $dir > $dir/gtags.log 2>&1";;
*) gtags -v $dir > $dir/gtags.log 2>&1;;
esac
case $? in
0) ;;