etags - Unix, Linux Command

ctags [-aCdgImRVh] [-BtTuvwx] [-l language]

[-o tagfile] [-r regexp]

[--append] [--backward-search]
[--cxref] [--defines] [--forward-search]
[--globals] [--ignore-indentation]
[--language=language] [--members]
[--output=tagfile] [--regex=regexp]
[--ignore-case-regex=regexp]
[--typedefs] [--typedefs-and-c++]
[--update] [--no-warn]
[--help] [--version]
file ...




where tagregexp is used to match the lines that must be tagged.
It should not match useless characters.  If the match is
such that more characters than needed are unavoidably matched by
tagregexp, it may be useful to add a nameregexp, to
narrow down the tag scope.  ctags ignores regexps without a
nameregexp.  The syntax of regexps is the same as in emacs,
augmented with intervals of the form \{m,n\}, as in ed or
grep.

Here are some examples.  All the regexps are quoted to protect them
from shell interpretation.


Tag the DEFVAR macros in the emacs source files:

--regex\=’/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"\/’


Tag VHDL files (this example is a single long line, broken here for
formatting reasons):

--language\=none --regex=’/[ \t]*\(ARCHITECTURE\|\
CONFIGURATION\) +[^ ]* +OF/’ --regex\=’/[ \t]*\
\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\( BODY\)?\
\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/’


Tag TCL files (this last example shows the usage of a tagregexp):

--lang\=none --regex\=’/proc[ \t]+\([^ \t]+\)/\1/’


A regexp can be preceded by {lang}, thus restricting it to match
lines of files of the specified language.  Use etags --help to obtain
a list of the recognised languages.  This feature is particularly useful inside
regex files.  A regex file contains one regex per line.  Empty lines,
and those lines beginning with space or tab are ignored.  Lines beginning
with @ are references to regex files whose name follows the @ sign.  Other
lines are considered regular expressions like those following --regex.

For example, the command

etags --regex=@regex.file *.c

reads the regexes contained in the file regex.file.



Navigating the source code using vi or emacs editor could be quite a task especially if the code has multiple files.
gctags utility can be quite handy in such a situation. Using gctags vi can be converted into a beautiful source code browser.
Example given below is for C program but same can be applied for other languages like C++, java, Perl, etc. Type gctags --h for to see supported languages.
Consider below source code: gctags_example.c
#include <stdio.h>
// Function Declarations
int areaRectangle(int length, int breadth);
float areaCircle(int radius);
int square(int num);
void dummy();
#define PI 3.14
typedef struct {
        int memberInt;
        float memberFloat;
        char memberChar;
} myStruct;
int rectangle;
float circle;
int areaRectangle(int length, int breadth)
{
        return(length * breadth);
}
float areaCircle(int radius)
{
        return(PI * square(radius));
}
int square(int num)
{
        return(num * num);
}
int main()
{
        rectangle = areaRectangle(10, 5);
        circle = areaCircle(20);
        printf("Area of rectangle: %f", rectangle);
        printf("Area of circle: %f", circle);
        return(0);
}

$ gctags --declarations --defines --global --members --output=example.tags --no-warn gctags_example.c

$ ls
example.tags  gctags_example.c

$ cat example.tags
Mgctags_example gctags_example.c        /^int main()$/
PI      gctags_example.c        9
areaCircle      gctags_example.c        /^float areaCircle(int radius);$/
areaRectangle   gctags_example.c        /^int areaRectangle(int length, int breadth);$/
circle  gctags_example.c        18
dummy   gctags_example.c        /^void dummy();$/
memberChar      gctags_example.c        14
memberFloat     gctags_example.c        13
memberInt       gctags_example.c        12
myStruct        gctags_example.c        15
rectangle       gctags_example.c        17
square  gctags_example.c        /^int square(int num);$/

$ gctags -R --declarations --defines --global --members --output=example.tags --no-warn *.c *.hae

:set tags=<path to tags>


    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page