Special support for bash is available.
First, do the preparation of global. See section 2.1 Preparation.. And you can invoke bash(1) with --rcfile option.
$ bash --rcfile /usr/local/share/gtags/globash.rc
You will see a prompt like this:
[/usr/src/sys]/kern _
This prompt means that the current directory is '/usr/src/sys/kern' and the root of the source tree is '/usr/src/sys'. Tag and marker are valid only in a project.
When you get out of the project, globash warns like:
[/usr/src/sys] cd .. You are going to get out of current project. Tag stack and marker will be removed. Sure? ([y]/n)_
If you answer 'y' and RET or just RET in above example then tag stack and marker will be removed.
If you need help then please type 'ghelp'.
[/usr/src/sys] x fork <- (global -x fork) > 1 fork 94 kern/kern_fork.c fork(p, uap) [/usr/src/sys] r <- (global -xr fork) > 1 fork 85 alpha/linux/linux_machdep.c 2 fork 184 i386/linux/linux_machdep.c [/usr/src/sys] s lbolt <- (global -xs lbolt) > 1 lbolt 1210 i386/isa/wd_cd.c tsleep((cad 2 lbolt 1211 i386/isa/wd_cd.c tsleep((cad 3 lbolt 709 i386/isa/wfd.c tsleep ((caddr ... [/usr/src/sys] g <- (global -xg lbolt) > 1 lbolt 1210 i386/isa/wd_cd.c tsleep((cad ... [/usr/src/sys] P init <- (global -xP init) > 1 path 1 dev/hea/eni_init.c 2 path 1 dev/hfa/fore_init.c 3 path 1 i386/i386/initcpu.c 4 path 1 kern/init_main.c 5 path 1 kern/init_sysent.c 6 path 1 kern/vfs_init.c 7 path 1 vm/vm_init.c [/usr/src/sys] _If no tag name is specified then it is assumed the latest tag name.
[/usr/src/sys] x main > 1 main 70 alpha/alpha/gensetdefs.c main(in 2 main 1500 alpha/alpha/ieee_float.c main(i 3 main 227 boot/alpha/boot1/boot1.c main() .... [/usr/src/sys] show 3 (Load editor and show boot/alpha/boot1/boot1.c at line 227.)The default editor is vi(1) but you can specify it statically by
EDITOR
environment variable or temporarily by option.
[/usr/src/sys] show -e 3 (Preloaded emacs show boot/alpha/boot1/boot1.c at line 227.) [/usr/src/sys] show -l 3 (Load less and show boot/alpha/boot1/boot1.c at line 227.) [/usr/src/sys] show -g 3 (Preloaded mozilla show boot/alpha/boot1/boot1.c at line 227.)
[/usr/src/sys] x main > 1 main 70 alpha/alpha/gensetdefs.c main(in 2 main 1500 alpha/alpha/ieee_float.c main(i 3 main 227 boot/alpha/boot1/boot1.c main() .... [/usr/src/sys] show 3 (Load editor and show boot/alpha/boot1/boot1.c at line 227.) [/usr/src/sys] x fork <- push new tag on tag stack. > 1 fork 94 kern/kern_fork.c fork(p, uap) [/usr/src/sys] pop <- pop tag stack. [/usr/src/sys] show (Load editor and show boot/alpha/boot1/boot1.c at line 227.)
[/usr/src/sys] x fork > 1 fork 94 kern/kern_fork.c fork(p, uap) [/usr/src/sys] mark [/usr/src/sys] x main > 1 main 70 alpha/alpha/gensetdefs.c main(in 2 main 1500 alpha/alpha/ieee_float.c main(i 3 main 227 boot/alpha/boot1/boot1.c main() .... [/usr/src/sys] mark -l <- show marker list. 1 fork 94 kern/kern_fork.c fork(p, uap) [/usr/src/sys] mark 1 <- select a marker. (Load editor and show kern/kern_fork.c at line 227.) [/usr/src/sys] list > 1 main 70 alpha/alpha/gensetdefs.c main(in 2 main 1500 alpha/alpha/ieee_float.c main(i 3 main 227 boot/alpha/boot1/boot1.c main() ....Marked tags are valid until you get out of current project or quit current bash session.
[/usr/src/sys] cookie <- drop cookie. [/usr/src/sys] cd kern [/usr/src/sys]/kern cookie <- drop cookie again. [/usr/src/sys]/kern cd ../i386 [/usr/src/sys]/i386 cookie -l <- show cookie list. 1 /usr/src/sys/kern 2 /usr/src/sys [/usr/src/sys]/i386 warp 2 <- warp to selected cookie. [/usr/src/sys] _Cookie directories are valid until you delete them.
You can use GLOBAL as a tag system of less instead of ctags.
First, do the preparation of global. See section 2.1 Preparation..
Second, to use global from less, you need to set environment variable
LESSGLOBALTAGS
to "global".
$ export LESSGLOBALTAGS=global
$ less -t func1Please note that if `tags' exist then less use it. If you want to use `GTAGS' even if `tags' exist then please specify tag file explicitly like this.
$ less -TGTAGS -t func1
$ less -TGRTAGS -t func1In the same way, you can use `GTAGS', `GRTAGS', `GSYMS', `GPATH' as tag file.
t
T
$ global -x func | less -T-In the same way, you can use following command lines.
# pattern match with grep(1). $ global -xg 'lseek(.*)' | less -T- # pattern match with id-utils(1). $ global -xI func | less -T- # all objects definitions in *.c. $ global -f *.c | less -T- # all files includes 'init' in its path. $ global -Px init | less -T-
# invoke less $ less -t main main(int argc, char **argv) { int i; ..... [xxx/main.c (tag 1 of 55)] # type 'v'(vi) command in less session. v # load vi and show the same position. ..... main((int argc, char **argv) { int i; ..... [xxx/main.c 313 lines, 7783 char] # type 'ZZ' command in vi session. ZZ # exit vi and back to less session. main(int argc, char **argv) { int i; ..... [xxx/main.c (tag 1 of 55)]
You can use GLOBAL as a tag system of Nvi editor instead of ctags.
First, do the preparation of global. See section 2.1 Preparation..
Second, to use global from nvi, you need to get into gtagsmode. There are several ways to do this:
$ nvi -G file.c
set gtagsmode
.
$ nvi file.c ~ ~ ~ :set gtagsmode
$HOME/.exrc +---------------------------- |set gtagsmodeYou must start nvi under the source tree described in section 2.1 Preparation..
:tag func1It seemes the same as original nvi, but extended nvi use `GTAGS' instead of `tags'.
:tag -r func1Extended nvi use `GRTAGS'.
Suggested .nexrc: set gtagsmode map ^N :tagnext^M map ^P :tagprev^M
:tag -s patExtended nvi use `GSYMS'.
:tag -g pat
CTL-T
:tagpop
:tagtop
:display tags
$ nvi -G -t mainYou can browse all commands sequentially.
$ nvi -G -t '^[sg]et'Of course, the following command is also available:
:tag ^[sg]et
$ mkdir /var/dbpath # directory for the tag file $ cd /cdrom/src # the root of the source tree $ gtags /var/dbpath # make tag files in /var/dbpath $ export GTAGSROOT=`pwd` $ export GTAGSDBPATH=/var/dbpath $ nvi -G -t main
$ cd /usr/src/lib $ gtags # probably as a root $ cd /usr/src/sys $ gtags $ export GTAGSLIBPATH=/usr/src/lib:/usr/src/sys
$ cd /usr/src/usr.bin/vi $ gtags $ nvi -G -t mainYou can start from nvi and browse the whole unix world as if you were using hypertext.
You can use GLOBAL as a tag system of Nvi editor instead of ctags.
First, do the preparation of global. See section 2.1 Preparation..
Second, to use global from nvi, you need write to `.nexrc' like this: It assumed that gtags.pl is put on `$HOME/perl'.
$HOME/.nexrc +---------------------------- |perl use lib "$ENV{'HOME'}/perl" |perl require 'gtags.pl' |map ^P :tagprev^M |map ^N :tagnext^M |map ^] :perl tag^M |ab gtag perl tag qw( |ab gta perl tag qw( |ab gt perl tag qw(
You must start nvi under the source tree described in section 2.1 Preparation..
:perl tag qw(func1)
Suggested .nexrc: ab gtag perl tag qw( ab gta perl tag qw( ab gt perl tag qw(
:perl tag qw(-r func1)
Suggested .nexrc: map ^N :tagnext^M map ^P :tagprev^M
Suggested .nexrc: map ^] :perl tag^MIt is similar to CTL-] command.
:perl tag qw(-s pat)
:perl tag qw(-g pat)
:perl tag qw(^[sg]et)
CTL-T
:tagpop
:tagtop
:display tags
Elvis 2.1 has new tagprg
and tagprgonce
variables for
running an external tag search program. You can use them with GLOBAL.
First, do the preparation of global. See section 2.1 Preparation..
Second, start elvis and execute set tagprg="global -t $1"
like this.
$ elvis ~ ~ ~ ~ ~ ~ :set tagprg="global -t $1"
:tag func1It seemes the same as original elvis, but elvis execute
global -t func1
internally and read it instead of tags file.
:tag -r func1Elvis executes command like
global -t -r func1
internally.
:tag -s lbolt
:tag -g Copyright
:browse -r forkIt brings a following selection list. You can select tag and go to the point.
Browse -r fork (2 matches) +----------------+----------------+-------------------- | TAG NAME | SOURCE FILE | SOURCE LINE +----------------+----------------+-------------------- |fork |ux/linux_misc.c | (line 565) |fork |ern/init_main.c | (line 191) +----------------+----------------+--------------------
:browse -f main.c <- locate definitions in main.c
CTL-]
CTL-T
:tag
:pop
:stack
:stag
:sbrowse
:tag ^put_ <- locate objects start with 'put_' :browse -g 'fseek(.*L_SET)' <- locate fseek() using L_SET argument
:browse -f *.c <- locate objects in *.c
:browse -P /vm/ <- under vm/ directory :browse -P \.h$ <- all include files :browse -P init <- path including 'init'
+----------------+----------------+-------------------- | TAG NAME | SOURCE FILE | SOURCE LINE +----------------+----------------+-------------------- |fork |ux/linux_misc.c | (line 565) |fork |ern/init_main.c | (line 191) +----------------+----------------+--------------------Please select tag name with mouse cursor and double click on the left button and you go to the tag's point. In source screen, also select an object name and double click on the left button and you can go to the point that the object is defined. To come back, double click on the right button.
In vim 6.2 or later, you can use gtags.vim script.
First, do the preparation of global. See section 2.1 Preparation..
Second, copy `gtags.vim' to your plugin directory or source it from your vimrc.
$ cp /usr/local/share/gtags/gtags.vim $HOME/.vim/plugin
:Gtags mainVim execute
global -t main
, parse the output, list located
objects in quickfix window and load the first entry.
The quickfix windows is like this:
gctags/gctags.c|119| main global/global.c|154| main gozilla/gozilla.c|156| main gtags/gtags.c|199| main libglibc/getopt.c|701| main libglibc/getopt1.c|93| main [Error List]You can go to any entry using quickfix command.
:cn
:cp
:ccN
:cl
:h quickfix
:Gtags -r func1vim executes command like
global -t -r func1
internally.
:Gtags -s lbolt
:Gtags -g Copyright
:Gtags -f main.c <- locate objects in main.cIf you are editing `main.c' itself, you can use '%' instead.
:Gtags -f % <- locate objects in main.c
:Gtags ^put_ <- locate objects start with 'put_' :Gtags -g fseek(.*SEEK_SET) <- locate fseek() using SEEK_SET
:Gtags -P /vm/ <- under vm/ directory :Gtags -P \.h$ <- all include files :Gtags -P init <- path including 'init'
:Gtags -gi paTtern <- match to both 'PATTERN' and 'pattern'.About the other options, See section 5.1 global - print the locations of specified object..
:GtagsCursor
Suggested map: map <C-]> :GtagsCursor<CR>
:Gozilla
Suggested map: map <C-g> :Gozilla<CR>
$ vim '+Gtags main'
You can use GLOBAL as a tag system of Emacs editor instead of etags.
First, do the preparation of global. See section 2.1 Preparation..
Second, to use global from emacs, you need to load the `gtags.el' and execute gtags-mode function in it.
load-path
.
$HOME/.emacs +------------------------------------------------------ |(setq load-path (cons "/home/owner/global" load-path)) |(autoload 'gtags-mode "gtags" "" t) $ emacs | |J_:-----Mule: *scratch* (Lisp Interaction)--L16--All---- |M-x gtags-mode[RET] +------------------------------------------------------If you want to get into gtags-mode on c-mode then you can append followings into the `$HOME/.emacs'.
(setq c-mode-hook '(lambda () (gtags-mode 1) ))
gtags-visit-rootdir
.
If you have tag files in /usr/src/sys then please do like this:
Visit root directory: /usr/src/sys
gtags-find-tag
and you can see a prompt in mini-buffer. Then input the tag name.
Find tag: func1 <- 'Find tag: ' is a prompt
gtags-find-rtag
.
Find tag (reference): func1
gtags-make-complete-list
command before it.
Find tag: fuTAB Find tag: func1 <- 'nc1' is appended by emacs
+------------------------------------------------------------- |main 347 i386/isa/ultra14f.c main() |main 128 kern/init_main.c main(framep) |main 104 netiso/clnp_debug.c main() |main 164 netiso/xebec/main.c main(argc, argv) | | | | | |J_:--%*-Mule: *scratch* (Gtags Select)--L1--All---- |[GTAGS SELECT MODE] 4 lines +-------------------------------------------------------------You can select a tag line by using any emacs command and pressing RET, and you can go to the tag's point. When you want to go to the next or the previous tag, you can return to 'GTAGS SELECT MODE' with
gtags-pop-stack
and reselect.
gtags-find-tag-from-here
command is available.
If current token is a definition, it is equivalent to
Find tag (reference): current tokenRET,
otherwise it is equivalent to Find tag: current tokenRET.
(This facility is supported only in C language.
GLOBAL decides this intelligentlly, but may sometimes misunderstand.)
gtags-find-symbol
.
Find symbol: lbolt <- 'Find symbol:' is a prompt
gtags-find-with-grep
.
Find pattern: Copyright
Find tag: ^put_ <- locate tags start with 'put_'
$ mkdir /var/dbpath # directory for the tag file $ cd /cdrom/src # the root of the source tree $ gtags /var/dbpath # make tag files in /var/dbpath $ export GTAGSROOT=`pwd` $ export GTAGSDBPATH=/var/dbpath $ emacs -f gtags-mode
$ cd /usr/src/lib $ gtags <- probably as a root $ cd /usr/src/sys $ gtags $ export GTAGSLIBPATH=/usr/src/lib:/usr/src/sys $ emacs -f gtags-mode
You can use GLOBAL's facilities from WWW browser.
At first, you must ensure that you have a lot of disk space. Hypertext needs a great amount of disk space. For example, the source code of FreeBSD kernel needs:
source code(/usr/src/sys) 14.0MB GTAGS 1.5MB GRTAGS 8.0MB GSYMS 12.0MB HTML/ 55MB(!!!) ------------------------------------------------- total 77MB
Please invoke gtags(1)(see section 5.2 gtags - create tag files for global.) and htags(1)(see section 5.3 htags - generate hypertext from source code.) in order like this:
(at your source directory) $ gtags # make the tag database(GTAGS,GRTAGS,GSYMS) $ htags # make the hypertext(HTML/)
Then you will find an `HTML' subdirectory in the current directory.
Please start a web browser like this:
$ lynx HTML/index.html
You will understand the usage by looking at the examples.
You can move the HTML directory to anywhere. It is independent of the source code.
Using mozilla, you can also utilize hypertext from your command line like this:
$ mozilla # load mozilla $ global -x main main 10 main.c main(int argc, char *argv[]) { $ gozilla +10 main.c # usage is similar to vi editor. (show main.c at 10 on mozilla's screen.)
But in this case, you must not move HTML directory from the source directory.
You can use GLOBAL as a source browser of Doxygen.
Doxygen Release 1.4.3 or later includs config option USE_HTAGS. When enabled in combination with SOURCE_BROWSER=YES, htags(1) is used as the source browser instead of doxygen's own.
Here is an example.
(in source directory) $ doxygen -g $ vi Doxyfile +--------------------------------- |... |INPUT = . |RECURSIVE = YES |SOURCE_BROWSER = YES |USE_HTAGS = YES |... $ doxygen $ lynx html/index.html