From 1be756644f233cf92f54886fd260615c13927ed1 Mon Sep 17 00:00:00 2001 From: jkh Date: Tue, 22 Apr 1997 18:02:52 +0000 Subject: [PATCH] Update to version 1.9. Submitted by: Shigio Yamaguchi --- usr.bin/global/HISTORY | 32 ++++++++++- usr.bin/global/MANIFEST | 5 +- usr.bin/global/README | 12 ++-- usr.bin/global/VERSION | 2 +- usr.bin/global/btreeop/btreeop.1 | 46 +++++++++++---- usr.bin/global/btreeop/btreeop.c | 96 ++++++++++++++++++++++++++------ usr.bin/global/gctags/ctags.c | 2 + usr.bin/global/gctags/gctags.1 | 8 +-- usr.bin/global/global/global.1 | 8 ++- usr.bin/global/global/global.pl | 23 +++++++- usr.bin/global/gtags/Makefile | 4 +- usr.bin/global/gtags/gtags.1 | 6 +- usr.bin/global/gtags/gtags.sh | 2 +- usr.bin/global/htags/htags.1 | 22 +++++++- usr.bin/global/htags/htags.pl | 73 ++++++++++++++++++------ 15 files changed, 270 insertions(+), 71 deletions(-) diff --git a/usr.bin/global/HISTORY b/usr.bin/global/HISTORY index e591c7432d73..de9eb3cf7acf 100644 --- a/usr.bin/global/HISTORY +++ b/usr.bin/global/HISTORY @@ -80,7 +80,8 @@ version 1.7 make suitable for large project (mainly FreeBSD kernel) [17-Feb-97] function too. - works MUCH faster than previous version. [fixed bug] - htags - string 'param' follows '&' means specific charactor in hypertext. + htags - generate path name including '¶m'. (It means special + charactor in hypertertext.) So, changed internal separator from '&' to '|'. [added] gtags - -s option added. If specified, gtags extract ENTRY() and @@ -129,3 +130,32 @@ version 1.81 make global to understand 'obj' directory and bug fix. [14-Apr-97] [changed] global - can find tag file in obj directory. + +version 1.9 fix some bugs, add options and support of 1.79 nvi [21-Apr-97] + + [fixed bug] + htags - doesn't keep the code formatted correctly. + So, changed to convert tabs in source files into spaces. + (expand(1) needed) + + Thanks to Andy Newman. + + - cannot print error message correctly. + [changed] + gctags, btreeop + - modify for SunOS 4.1.3. + + Thanks to Yoshiharu Ito. + + [added] + btreeop - META record and 'format version record' is available. + (It will be used in the furture.) + - -A and -D option added. (It will be used in the future.) + htags - use temporary directory specified by TMPDIR environment + variable. + - -l option added. + + Thanks to Jeff Trawick. This option is his idea. + + nvi-1.79.diff + - patch for nvi 1.79 to make extended vi. diff --git a/usr.bin/global/MANIFEST b/usr.bin/global/MANIFEST index a03c42eae9ca..11e3b9eaacfa 100644 --- a/usr.bin/global/MANIFEST +++ b/usr.bin/global/MANIFEST @@ -1,9 +1,9 @@ HISTORY Histroy of GLOBAL. INSTALL Installation method MANIFEST This file. -Makefile Makefile for generic UNIX(including BSD). -Makefile.bsd Makefile for BSD. +Makefile Makefile for BSD. Makefile.inc A part of Makefile for BSD. +Makefile.generic Makefile for generic UNIX(including BSD). README Readme (introduction and usage). VERSION Version number. btreeop/ Btreeop command directory. @@ -14,3 +14,4 @@ htags/ Htags command directory. systags/ Script for kernel. nvi-1.34.diff Patch for nvi 1.34. nvi-1.76.diff Patch for nvi 1.76. +nvi-1.79.diff Patch for nvi 1.79. diff --git a/usr.bin/global/README b/usr.bin/global/README index 42596376e213..e69fba0ca6b0 100644 --- a/usr.bin/global/README +++ b/usr.bin/global/README @@ -3,13 +3,13 @@ @- @- @- @- @- @- @@@@@- @@@@@@- @@- @- - @- F o r a l l h a c h e r s. version 1.8 + @- F o r a l l h a c h e r s. version 1.9 @- @@@@@@-@- @- @- @@@@@- @- @- @- @- @- @- @- @- @- @- @@@@@- @- @- @- @- @- @- @- @-@- @- @- @@@@@@@@- @@@@- @@@@@- @@@@@@-@@@- @@@@- @@@@@@- - Shigio Yamaguchi 5-Apr-97 + Shigio Yamaguchi 21-Apr-97 Copyright 1996, 1997 Shigio Yamaguchi All right resereved. @@ -387,7 +387,7 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'. set gtagsmode set leftright - [Extended vi based 1.76 nvi] + [Extended vi based 1.79 nvi] Vi goes to the first tag. Then you can go to next tag by ':tagnext' or back by ':tagprev'. @@ -399,7 +399,7 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'. == WHY TWO STYLE EXIST ? == 1.34 nvi cannot treat duplicate tag entries, so I made 'GTAGS SELECT MODE' - in it. But 1.76 nvi (1.61 and later) can treat them, so I adapted GLOBAL + in it. But 1.79 nvi (1.61 and later) can treat them, so I adapted GLOBAL tags to nvi's tag structure. o command is available. @@ -481,7 +481,7 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'. source code(/usr/src/sys) 14MB tag database(GTAGS,GRTAGS) 9MB(!) - hypertext(HTML/*) 42MB(!!!) + hypertext(HTML/*) 45MB(!!!) Please do the followings. @@ -519,7 +519,7 @@ All the functions for GLOBAL are enabled only in 'gtagsmode'. You can use one level nested index and browse assembler source file too. Thank you for your reading of my poor english. -And of course, thank you Keith Bostic (the author of nvi(1) and db(3)). +And of course, I'm grateful to Keith Bostic for his excellent nvi(1) and db(3). ---------------------------------------------------------------------------- E-Mail: WWW: diff --git a/usr.bin/global/VERSION b/usr.bin/global/VERSION index ea3769f296ad..2e0e38c63a62 100644 --- a/usr.bin/global/VERSION +++ b/usr.bin/global/VERSION @@ -1 +1 @@ -1.81 +1.9 diff --git a/usr.bin/global/btreeop/btreeop.1 b/usr.bin/global/btreeop/btreeop.1 index b6baa6dd2f00..08bbf51c3b1a 100644 --- a/usr.bin/global/btreeop/btreeop.1 +++ b/usr.bin/global/btreeop/btreeop.1 @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd April 21, 1996 +.Dd April 21, 1997 .Dt BTREEOP 1 .Os BSD 4 .Sh NAME @@ -36,7 +36,9 @@ .Nd btree database maintenance tool .Sh SYNOPSIS .Nm btreeop +.Op Fl A .Op Fl C +.Op Fl D Ar key .Op Fl K Ar key .Op Fl b .Op Fl c Ar cashesize @@ -49,16 +51,21 @@ execute simple operations for .Xr btree 3 database. .Nm Btreeop -can create database and read (sequential or index) from it . +can create database, write record, read record (sequential or index) and +delete record from it. Duplicate entries are allowed. .Sh OPTIONS A capital letter means a command. If no command specified then it assume sequential read operation. .Bl -tag -width Ds +.It Fl A +append records. If database doesn't exist, btreeop creates it. .It Fl C -create database. +create database and write records to it. +.It Fl D Ar key +delete records by the key. .It Fl K Ar key -search data by the key. +search records by the key. .It Fl b assume BIG_ENDIAN byte order. default is LITTLE_ENDIAN. .It Fl c Ar cashesize @@ -74,7 +81,7 @@ of BTREEINFO. (see btree(3)) .It Ar dbname database name. default is 'btree'. .Sh DATA FORMAT -To creat database, +To creat (or append) database, .Nm btreeop read data from stdin. The format of the data is the following. @@ -96,6 +103,10 @@ Key cannot include blank. Data can include blank. .It 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). +Usage is unlimited by Btreeop. .El .Sh EXAMPLES Create database. @@ -103,11 +114,18 @@ Create database. % btreeop -C key1 data1 key2 data2 - key2 data2-2 key3 data3 ^D % +Append records. + + % btreeop -A + __.VERSION 2 + key2 data2-2 + ^D + % + Sequential read. % btreeop @@ -122,6 +140,14 @@ Indexed read. % btreeop -K key2 key2 data2-2 key2 data2 + % btreeop -K ' __.VERSION' + __.VERSION 2 + % + +Delete record. + + % btreeop -D ' __.VERSION' + % btreeop -K ' __.VERSION' % .Sh FILES @@ -133,10 +159,10 @@ default database name. .Nm Btreeop exits with a value of 1 if an error occurred, 0 otherwise. .Sh SEE ALSO -.Xr btree 3 , -.Sh BUGS -.Nm btreeop -cannot utilize all features of .Xr btree 3 .Sh AUTHOR Shigio Yamaguchi (shigio@wafu.netgate.net) +.Sh HISTORY +The +.Nm +command appeared in FreeBSD 2.2. diff --git a/usr.bin/global/btreeop/btreeop.c b/usr.bin/global/btreeop/btreeop.c index 1d2faeb98509..a202578895aa 100644 --- a/usr.bin/global/btreeop/btreeop.c +++ b/usr.bin/global/btreeop/btreeop.c @@ -28,7 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * btreeop.c 5-Apr-97 + * btreeop.c 21-Apr-97 * */ #include @@ -56,9 +56,12 @@ void die __P((char *)); void usage __P((void)); void entab __P((char *)); void main __P((int, char **)); -int dbcreate __P((DB *)); +int dbwrite __P((DB *)); int dbkey __P((DB *, char *)); int dbscan __P((DB *)); +int dbdel __P((DB *, char *)); +DB *db; +char *key; #ifndef LITTLE_ENDIAN #define LITTLE_ENDIAN 1234 @@ -78,7 +81,7 @@ char *s; void usage() { fprintf(stderr, - "usage: %s [-C][-K key][-b][-c cachesize][-l][-p psize][dbname]\n", + "usage: %s [-A][-C][-D key][-K key][-b][-c cachesize][-l][-p psize][dbname]\n", progname); exit(1); } @@ -126,11 +129,14 @@ main(argc, argv) int argc; char *argv[]; { - char command = 0; + char command = 'R'; char *key = NULL; DB *db; BTREEINFO info; int c; + int flags; + extern char *optarg; + extern int optind; info.flags = R_DUP; /* allow duplicate entries */ info.cachesize = 500000; @@ -141,11 +147,15 @@ char *argv[]; info.prefix = NULL; info.lorder = LITTLE_ENDIAN; - while ((c = getopt(argc, argv, "CK:bc:lp:")) != EOF) { + while ((c = getopt(argc, argv, "ACD:K:bc:lp:")) != EOF) { switch (c) { case 'K': + case 'D': key = optarg; + case 'A': case 'C': + if (command != 'R') + usage(); command = c; break; case 'b': @@ -166,21 +176,35 @@ char *argv[]; } dbname = (optind < argc) ? argv[optind] : dbdefault; - db = dbopen(dbname, command == 'C' ? - O_RDWR|O_CREAT|O_TRUNC : O_RDONLY, - 0644, DB_BTREE, &info); - + switch (command) { + case 'A': + case 'D': + flags = O_RDWR|O_CREAT; + break; + case 'C': + flags = O_RDWR|O_CREAT|O_TRUNC; + break; + case 'K': + case 'R': + flags = O_RDONLY; + break; + } + db = dbopen(dbname, flags, 0644, DB_BTREE, &info); if (db == NULL) { die("dbopen failed."); } switch (command) { + case 'A': /* Append records */ case 'C': /* Create database */ - dbcreate(db); + dbwrite(db); break; - case 'K': /* Keyed search */ + case 'D': /* Delete records */ + dbdel(db, key); + break; + case 'K': /* Keyed (indexed) read */ dbkey(db, key); break; - default: /* Scan all data */ + case 'R': /* sequencial Read */ dbscan(db); break; } @@ -190,13 +214,13 @@ char *argv[]; exit(0); } /* - * dbcreate: create database + * dbwrite: write to database * * i) db * r) 0: normal */ int -dbcreate(db) +dbwrite(db) DB *db; { DBT key, dat; @@ -216,6 +240,12 @@ DB *db; * - Key cannot include blank. * - Data can include blank. * - Null Data not allowed. + * + * META record: + * You can write meta record by making key start with a ' '. + * You can read this record only by indexed read ('-K' option). + * +------------------ + * | __.VERSION 2 */ while (fgets(buf, BUFSIZ, stdin)) { if (buf[strlen(buf)-1] == '\n') /* chop(buf) */ @@ -223,7 +253,12 @@ DB *db; else while (fgetc(stdin) != '\n') ; - for (c = buf; *c && !isspace(*c); c++) /* skip key part */ + c = buf; + if (*c == ' ') { /* META record */ + if (*++c == ' ') + die("illegal format."); + } + for (; *c && !isspace(*c); c++) /* skip key part */ ; if (*c == 0) die("data part not found."); @@ -277,14 +312,13 @@ char *skey; status = (*db->seq)(db, &key, &dat, R_NEXT)) { (void)fprintf(stdout, "%s\n", (char *)dat.data); } - if (status == RET_ERROR) die("db->seq failed."); return (0); } /* - * dbscan: Scan all data + * dbscan: Scan all records * * i) db * r) 0: normal @@ -300,9 +334,37 @@ DB *db; 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; (void)fprintf(stdout, "%s\n", (char *)dat.data); } if (status == RET_ERROR) die("db->seq failed."); return (0); } + +/* + * dbdel: Delete records + * + * i) db + * i) key key + * r) 0: normal + * 1: not found + */ +int +dbdel(db, skey) +DB *db; +char *skey; +{ + 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."); + return (0); +} diff --git a/usr.bin/global/gctags/ctags.c b/usr.bin/global/gctags/ctags.c index e0f042827ce0..f73a6bdf2276 100644 --- a/usr.bin/global/gctags/ctags.c +++ b/usr.bin/global/gctags/ctags.c @@ -100,6 +100,8 @@ main(argc, argv) int step; /* step through args */ int ch; /* getopts char */ char cmd[100]; /* too ugly to explain */ + extern char *optarg; + extern int optind; #ifndef lint copyright[0] = copyright[0]; /* to satisfy compiler */ diff --git a/usr.bin/global/gctags/gctags.1 b/usr.bin/global/gctags/gctags.1 index 927efc5ec429..dd0dc84fbf3a 100644 --- a/usr.bin/global/gctags/gctags.1 +++ b/usr.bin/global/gctags/gctags.1 @@ -31,7 +31,7 @@ .\" .\" @(#)gctags.1 8.1 (Berkeley) 6/6/93 .\" -.Dd June 6, 1993 +.Dd Apr 21, 1997 .Dt GCTAGS 1 .Os BSD 4 .Sh NAME @@ -220,9 +220,5 @@ the searching pattern. The last line of multiple line will similarly be noted. .Sh HISTORY The -.Nm Ctags -command appeared in -.Bx 3.0 . -The .Nm -command appeared in GLOBAL 1.6 . +command appeared in FreeBSD 2.2. diff --git a/usr.bin/global/global/global.1 b/usr.bin/global/global/global.1 index f86f40a6ccba..6f42bde1b25b 100644 --- a/usr.bin/global/global/global.1 +++ b/usr.bin/global/global/global.1 @@ -28,12 +28,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd Jul 28, 1996 +.Dd Apr 21, 1997 .Dt GLOBAL 1 .Os BSD 4 .Sh NAME .Nm global -.Nd print the locations of specified function in C and Yacc source files. +.Nd print the locations of specified function. .Sh SYNOPSIS .Nm global .Op Fl acrx @@ -128,3 +128,7 @@ exits with a non 0 value if an error occurred, 0 otherwise. .Xr btreeop 1 .Sh AUTHORS Shigio Yamaguchi (shigio@wafu.netgate.net) +.Sh HISTORY +The +.Nm +command appeared in FreeBSD 2.2. diff --git a/usr.bin/global/global/global.pl b/usr.bin/global/global/global.pl index f1e0cb9cd3fe..ff00340ff8da 100644 --- a/usr.bin/global/global/global.pl +++ b/usr.bin/global/global/global.pl @@ -29,7 +29,7 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# global.pl 14-Apr-97 +# global.pl 21-Apr-97 # sub getcwd { local($dir); @@ -51,7 +51,9 @@ while ($ARGV[0] =~ /^-/) { } if (@ARGV == 0) { die($usage) if (! $cflag); -} elsif ($ARGV[0] =~ /[][.*\^\$+?|(){}\\]/) { # include regular expression ? +} +$ARGV[0] =~ s/^[ \t]+//; # remove leading blanks +if ($ARGV[0] =~ /[][.*\^\$+?|(){}\\]/) { # include regular expression ? $regex = 1; } if ($cflag) { @@ -102,6 +104,23 @@ foreach $step (@step) { push(@com, "-e 's!\\.\\./$step/!!'"); } # +# 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. + $support_version = 1; # accept this format version +# +open(GTAGS, "btreeop -K ' __.VERSION' $dbpath/$gtagsname |") || die("$com: GTAGS not found.\n"); +$rec = ; +close(GTAGS); +if ($rec =~ /^ __\.VERSION[ \t]+([0-9]+)$/) { + $format_version = $1; +} else { + $format_version = 1; +} +if ($format_version > $support_version) { + die("$com: GTAGS seems new format. Please install the latest GLOBAL.\n"); +} +# # complete function name # if ($cflag) { diff --git a/usr.bin/global/gtags/Makefile b/usr.bin/global/gtags/Makefile index 53355f3b2439..cabb8903540c 100644 --- a/usr.bin/global/gtags/Makefile +++ b/usr.bin/global/gtags/Makefile @@ -3,7 +3,7 @@ MAN1= gtags.1 beforeinstall: - install -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ - ${.CURDIR}/gtags.sh ${DESTDIR}/${BINDIR}/gtags + ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ + ${.CURDIR}/gtags.sh ${DESTDIR}/usr/bin/gtags .include diff --git a/usr.bin/global/gtags/gtags.1 b/usr.bin/global/gtags/gtags.1 index dca7a42bfc99..4397544eaf85 100644 --- a/usr.bin/global/gtags/gtags.1 +++ b/usr.bin/global/gtags/gtags.1 @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd Feb 17, 1997 +.Dd Apr 21, 1997 .Dt GTAGS 1 .Os BSD 4 .Sh NAME @@ -79,3 +79,7 @@ and ALTENTRY() from source file. Probably valid only for FreeBSD and Linux kernel source. .Sh AUTHORS Shigio Yamaguchi (shigio@wafu.netgate.net) +.Sh HISTORY +The +.Nm +command appeared in FreeBSD 2.2. diff --git a/usr.bin/global/gtags/gtags.sh b/usr.bin/global/gtags/gtags.sh index 85458bc6d8a1..79f19bcfe980 100644 --- a/usr.bin/global/gtags/gtags.sh +++ b/usr.bin/global/gtags/gtags.sh @@ -29,7 +29,7 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# gtags.sh 17-Feb-97 +# gtags.sh 21-Apr-97 # com=`echo $0 | sed 's/.*\///'` # command name usage="usage: $com [-e][-s][dbpath]" diff --git a/usr.bin/global/htags/htags.1 b/usr.bin/global/htags/htags.1 index f82b37c9db6c..1a336eab7186 100644 --- a/usr.bin/global/htags/htags.1 +++ b/usr.bin/global/htags/htags.1 @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd Feb 17, 1997 +.Dd Apr 21, 1997 .Dt HTAGS 1 .Os BSD 4 .Sh NAME @@ -37,6 +37,7 @@ .Sh SYNOPSIS .Nm htags .Op Fl a +.Op Fl l .Op Fl v .Op Fl w .Op Fl d Ar tagdir @@ -44,7 +45,7 @@ .Op Ar dir .Sh DESCRIPTION .Nm Htags -makes hypertext from C and Yacc source code using GLOBAL database. +makes hypertext from C and Yacc source code using GLOBAL database (GTAGS, GRTAGS). .Pp In advance of using this command, you must execute .Xr gtags 1 @@ -62,7 +63,11 @@ by any browsers. .br .Bl -tag -width Ds .It Fl a -make alphabetical function index. It's suitable to large project. +make an alphabetical function index. It's suitable for large project. +.It Fl l +make name tag() for each line so that outer hypertext +can point any line of this hypertext. +By default, make it only for lines which have referred object. .It Fl v verbose mode. .It Fl w @@ -87,6 +92,13 @@ tags file for function definitions. .It Pa GRTAGS tags file for function references. .El +.Sh ENVIRONMENT +The following environment variables affect the execution of htags. +.Pp +.Bl -tag -width indent +.It Ev TMPDIR +If this variable is set, its value is used as the directory to make temporary file. +Default is /tmp. .Sh DIAGNOSTICS .Nm Htags exits with a value of 1 if an error occurred, 0 otherwise. @@ -97,3 +109,7 @@ exits with a value of 1 if an error occurred, 0 otherwise. Generated hypertext is VERY LARGE. In advance, check the space of your disk. .Sh AUTHORS Shigio Yamaguchi (shigio@wafu.netgate.net) +.Sh HISTORY +The +.Nm +command appeared in FreeBSD 2.2. diff --git a/usr.bin/global/htags/htags.pl b/usr.bin/global/htags/htags.pl index 9c1a275e7256..377a41c2cc6b 100755 --- a/usr.bin/global/htags/htags.pl +++ b/usr.bin/global/htags/htags.pl @@ -29,11 +29,11 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# htags.pl 5-Apr-97 +# htags.pl 21-Apr-97 # $com = $0; $com =~ s/.*\///; -$usage = "usage: $com [-a][-v][-w][-t title][-d tagdir][dir]"; +$usage = "usage: $com [-a][-l][-v][-w][-t title][-d tagdir][dir]"; #------------------------------------------------------------------------- # CONFIGURATION #------------------------------------------------------------------------- @@ -52,6 +52,9 @@ $reserved_end = ''; $reserved_words = "auto|break|case|char|continue|default|do|double|else|extern|float|for|goto|if|int|long|register|return|short|sizeof|static|struct|switch|typedef|union|unsigned|void|while"; # temporary directory $tmp = '/tmp'; +if (defined($ENV{'TMPDIR'}) && -d $ENV{'TMPDIR'}) { + $tmp = $ENV{'TMPDIR'}; +} #------------------------------------------------------------------------- # DEFINITION #------------------------------------------------------------------------- @@ -117,20 +120,31 @@ sub escape { local($c) = @_; '%' . sprintf("%x", ord($c)); } +sub usable { + local($com) = @_; + + foreach $path (split(/:/, $ENV{'PATH'})) { + if (-x "$path/$com") { + return 1; + } + } + return 0; +} #------------------------------------------------------------------------- # PROCESS START #------------------------------------------------------------------------- # # options check # -$aflag = $vflag = $wflag = $sflag = ''; # $sflag is set internally +$aflag = $lflag = $vflag = $wflag = $sflag = '';# $sflag is set internally while ($ARGV[0] =~ /^-/) { $opt = shift; - if ($opt =~ /[^-avwdt]/) { + if ($opt =~ /[^-alvwtd]/) { print STDERR "$usage\n"; exit 1; } if ($opt =~ /a/) { $aflag = 1; } + if ($opt =~ /l/) { $lflag = 1; } if ($opt =~ /v/) { $vflag = 1; } if ($opt =~ /w/) { $wflag = 1; } if ($opt =~ /t/) { @@ -153,6 +167,26 @@ if (!$dbpath) { unless (-r "$dbpath/GTAGS" && -r "$dbpath/GRTAGS") { &error("GTAGS and GRTAGS not found. please type 'gtags[RET]'\n"); } +# +# recognize format version +# if version record is not found, it's assumed version 1. +# + $support_version = 1; # understand this format version +# +open(GTAGS, "btreeop -K ' __.VERSION' $dbpath/GTAGS |") || die("$com: GTAGS not found.\n"); +$rec = ; +close(GTAGS); +if ($rec =~ /^ __\.VERSION[ \t]+([0-9]+)$/) { + $format_version = $1; +} else { + $format_version = 1; +} +if ($format_version != $support_version) { + die("$com: GTAGS format version unmatched. Please remake it.\n"); +} +# +# check directories +# $html = &getcwd() . '/HTML'; if ($ARGV[0]) { $cwd = &getcwd(); @@ -613,15 +647,16 @@ package convert; sub src2html { local($file, $html) = @_; local($ncol) = $'ncol; + local($expand) = &'usable('expand') ? 'expand' : 'cat'; - open(HTML, ">$html") || &error("cannot create file <$html>.\n"); + open(HTML, ">$html") || &'error("cannot create file <$html>.\n"); local($old) = select(HTML); # # load tags belonging to this file. # $file =~ s/^\.\///; &anchor'load($file); - open(C, $file) || &error("cannot open file <$file>.\n"); + open(C, "$expand '$file' |") || &'error("cannot open file <$file>.\n"); # # print the header # @@ -659,12 +694,16 @@ sub src2html { local($define_line) = 0; local(@links) = (); local($count) = 0; - local($first); + local($lno_printed) = 0; - for ($first = 1; int($LNO) == $.; ($LNO, $TAG, $TYPE) = &anchor'next()) { - if ($first) { - $first = 0; - print "" + if ($'lflag) { + print ""; + $lno_printed = 1; + } + for (; int($LNO) == $.; ($LNO, $TAG, $TYPE) = &anchor'next()) { + if (!$lno_printed) { + print ""; + $lno_printed = 1; } $define_line = $LNO if ($TYPE eq 'D'); $db = ($TYPE eq 'D') ? 'GRTAGS' : 'GTAGS'; @@ -689,7 +728,7 @@ sub src2html { print STDERR "Error: $file $LNO $TAG($TYPE) tag must exist.\n" if ($'wflag); } } else { - print STDERR "Warning: $file $LNO $TAG($TYPE) found but not refered.\n" if ($'wflag); + print STDERR "Warning: $file $LNO $TAG($TYPE) found but not referred.\n" if ($'wflag); } } # implant links @@ -831,10 +870,10 @@ package anchor; # sub create { $ANCH = "$'tmp/ANCH$$"; - open(ANCH, "| btreeop -C $ANCH") || &error("btreeop -C $ANCH failed.\n"); + open(ANCH, "| btreeop -C $ANCH") || &'error("btreeop -C $ANCH failed.\n"); 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.\n"); while () { local($tag, $lno, $filename) = split; print ANCH "$filename $lno $tag $type\n"; @@ -860,7 +899,7 @@ sub load { $file = './' . $file if ($file !~ /^\.\//); @ANCHORS = (); - open(ANCH, "btreeop -K $file $ANCH|") || &error("btreeop -K $file $ANCH failed.\n"); + open(ANCH, "btreeop -K $file $ANCH|") || &'error("btreeop -K $file $ANCH failed.\n"); $n = 0; while () { local($filename, $lno, $tag, $type) = split; @@ -870,7 +909,7 @@ $n = 0; 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: skip <$filename $lno $tag> because this is a macro which is defined in other C source.\n" if ($'wflag); + print STDERR "Information: $filename $lno $tag($type) skipped, because this is a macro which is defined in other C source.\n" if ($'wflag); next; } } @@ -1016,7 +1055,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.\n"); $cachesize = -1; } $CACH{$label.$tag} = $line;