home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim45os2.zip / vim-4.5 / doc / ctags.man < prev    next >
Text File  |  1996-10-15  |  21KB  |  529 lines

  1.  
  2.  
  3.  
  4. CTAGS(1)                                                 CTAGS(1)
  5.  
  6.  
  7. NAME
  8.        ctags - Generate C language tag files for use with vi(1)
  9.  
  10. SYNOPSIS
  11.        ctags [ -aBdFnNsStTuwWx ] [ -f tagfile ] [ -h list ]
  12.              [ -i types ] [ -I ignorelist ] [ -L listfile ]
  13.              [ -o tagfile ] [ --help ] [ file(s) ]
  14.  
  15. DESCRIPTION
  16.        Ctags  generates  an  index  (or "tag") file of C language
  17.        objects found in file(s) that allows  these  items  to  be
  18.        quickly and easily located by a text editor or other util-
  19.        ity. A "tag" signifies a C language object  for  which  an
  20.        index  entry  is  available  (or, alternatively, the index
  21.        entry created for that object).
  22.  
  23.        Alternatively, ctags can generate a cross  reference  file
  24.        which lists, in human readable form, information about the
  25.        various objects found in a set of C language files.
  26.  
  27.        Tag index files are supported by the vi(1) editor and  its
  28.        derivatives  (such as vim, elvis, stevie, and xvi) through
  29.        the use of the ":ta" command,  which  locates  the  object
  30.        associated  with  a  name  appearing  in a source file and
  31.        jumps to the file and line which  defines  the  name.  The
  32.        following types of tags are supported by ctags:
  33.  
  34.            macro definitions (i.e. names created by #define)
  35.            enumerated values (i.e. the values inside enum{...})
  36.            function definitions
  37.            function prototypes or declarations (optional)
  38.            class, enum, struct and union tags
  39.            typedefs
  40.            variables
  41.  
  42.        Ctags  only  generates  tags for objects which have global
  43.        scoping (file-wide visibility). This means that, with  the
  44.        exception  of macro definitions, only objects defined out-
  45.        side of brace enclosed function blocks are candidates  for
  46.        a  tag.  For  every one of the qualified objects which are
  47.        discovered in the source files supplied to ctags, a  sepa-
  48.        rate  line is added to the tags file in the following for-
  49.        mat:
  50.  
  51.            1.  tag name (a C language identifier)
  52.            2.  a single tab character
  53.            3.  the name of the file in which the  object  associ-
  54.                ated with the tag is located
  55.            4.  a single tab character
  56.            5.  an  Ex  command to locate the tag within the file;
  57.                generally either a search  pattern  (either  /pat-
  58.                tern/ or ?pattern?) or line number
  59.  
  60.        Note  that,  unless changed via -n or -N, line numbers are
  61.  
  62.  
  63.  
  64. Darren Hiebert            5 October 1996                        1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. CTAGS(1)                                                 CTAGS(1)
  71.  
  72.  
  73.        only used for tags from macro definitions, while  patterns
  74.        are used for all other tags.
  75.  
  76.        Note that the name of each source file will be recorded in
  77.        the tag file exactly as it appears on  the  command  line.
  78.        Therefore,  if  the path you specified on the command line
  79.        was relative to some directory, then it will  be  recorded
  80.        in that same manner in the tag file.
  81.  
  82.        This  version of ctags imposes no formatting requirements.
  83.        Other versions of ctags tended to rely upon  certain  for-
  84.        matting  assumptions  in  order  to help it resolve coding
  85.        dilemmas caused by preprocessor conditionals.
  86.  
  87.        In general, ctags tries to be smart about conditional pre-
  88.        processor  directives.  If  a  preprocessor conditional is
  89.        encountered within a statement which defines a tag,  ctags
  90.        follows  only the first branch of that conditional (except
  91.        in the special case of "#if 0", in which case  it  follows
  92.        only the last branch). The reason for this is that failing
  93.        to pursue only one branch can result in ambiguous  syntax,
  94.        as in the following example:
  95.  
  96.               #ifdef TWO_ALTERNATIVES
  97.               struct {
  98.               #else
  99.               union {
  100.               #endif
  101.                   short a;
  102.                   long b;
  103.               }
  104.  
  105.        Both  branches cannot be followed, or braces become unbal-
  106.        anced and ctags would be unable to make sense of the  syn-
  107.        tax.
  108.  
  109.        If  the  application  of  this heuristic fails to properly
  110.        parse a file, generally due to complicated  and  inconsis-
  111.        tent pairing within the conditionals, ctags will retry the
  112.        file using a different heuristic  which  does  not  selec-
  113.        tively   follow  conditional  preprocessor  branches,  but
  114.        instead falls back to relying upon a closing  brace  ("}")
  115.        in  column  1  as  indicating  the end of a block once any
  116.        brace imbalance is detected within a #if conditional.
  117.  
  118.        Ctags will also try to specially  handle  arguments  lists
  119.        enclosed  in double sets of parentheses in order to accept
  120.        the following conditional construct:
  121.  
  122.               extern void foo __ARGS((int one, char two));
  123.  
  124.        Any name immediately preceding the "((" will be  automati-
  125.        cally ignored and the previous name will be used.
  126.  
  127.  
  128.  
  129.  
  130. Darren Hiebert            5 October 1996                        2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. CTAGS(1)                                                 CTAGS(1)
  137.  
  138.  
  139.        After  creating or appending to the tag file, it is sorted
  140.        by the tag name, removing identical tag lines.
  141.  
  142.        Note that the path recorded for filenames in the tag  file
  143.        and  utilized by the editor to search for tags are identi-
  144.        cal to the paths specified  for  file(s)  on  the  command
  145.        line. This means the if you want the paths for files to be
  146.        relative to some directory, you must invoke ctags with the
  147.        same pathnames for file(s).
  148.  
  149. OPTIONS
  150.        Note  that spaces separating options from their parameters
  151.        are optional.
  152.  
  153.        --help
  154.             Prints to standard output a detailed  usage  descrip-
  155.             tion.
  156.  
  157.        -a   Append the tags to an existing tag file.
  158.  
  159.        -B   Use backward searching patterns (?...?).
  160.  
  161.        -d   Include macro definitions in the output file. This is
  162.             equivalent to -i+d and is supported  only  for  back-
  163.             wards compatibility with other versions of ctags. Use
  164.             of -i is preferred.
  165.  
  166.        -f tagfile
  167.             Output  tags  to  the  specified  file  (default   is
  168.             "tags"). If tagfile is specified as "-", then the tag
  169.             file is written to standard  output  instead.   Ctags
  170.             will  stubbornly  refuse  to  take  orders if tagfile
  171.             exists and its first line  contains  something  other
  172.             than  a valid tags line.  This will save your neck if
  173.             you mistakenly type "ctags -o *.c", which would  oth-
  174.             erwise overwrite your first C file with the tags gen-
  175.             erated by the rest!
  176.  
  177.        -F   Use forward searching patterns (/.../) (default).
  178.  
  179.        -h list
  180.             Specifies a list of file extensions used for headers,
  181.             separated  by  either  periods or commas. The default
  182.             list is ".h.H.hpp.hxx.h++".
  183.  
  184.        -i types
  185.             Specifies the list of tag types  to  include  in  the
  186.             output file.  Types is a group of letters designating
  187.             the types of tags affected. Each letter or  group  of
  188.             letters   may  be  preceded  by  either  a  '+'  sign
  189.             (default, if omitted) to  add  it  to  those  already
  190.             included,  a  '-'  sign  to  exclude it from the list
  191.             (e.g.  to exclude a default tag type), or an '=' sign
  192.             to   include   its  corresponding  tag  type  at  the
  193.  
  194.  
  195.  
  196. Darren Hiebert            5 October 1996                        3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. CTAGS(1)                                                 CTAGS(1)
  203.  
  204.  
  205.             exclusion of those  not  listed.  The  following  tag
  206.             types are supported:
  207.                d   macro definitions
  208.                e   enumerated values (values inside enum{...})
  209.                f   function and method definitions
  210.                g   enum/struct/union tags (or new C++ types)
  211.                p   external function prototypes
  212.                t   typedefs
  213.                v   variable declarations
  214.             In   addition,   the   following  two  modifiers  are
  215.             accepted:
  216.                P   Prefix static tags (if included)  in  the  tag
  217.                    file  with  the filename in which they appear,
  218.                    followed by a colon (Elvis style;  not  widely
  219.                    supported).
  220.                S   Include static tags (those not visible outside
  221.                    of a single source file).  Function and  vari-
  222.                    able  definitions  are  considered static only
  223.                    when their definitions are preceded  with  the
  224.                    "static"  keyword. All other types of tags are
  225.                    considered static when they appear in  a  non-
  226.                    header file (see the -h option).
  227.             The  default value of list is "=defgtvS" (i.e all tag
  228.             types except for function prototypes; include  static
  229.             tags but do not prefix them).
  230.  
  231.        -I ignorelist
  232.             Reads  a  list of names which are to be ignored while
  233.             generating tags for the source files. The list may be
  234.             supplied  directly  on the command line or found in a
  235.             separate file. Normally, the parameter ignorelist  is
  236.             a  list of names to be ignored, each separated with a
  237.             comma, a semicolon, or white space (in which case the
  238.             list  should be quoted to keep the entire list as one
  239.             command line argument). The parameter ignorelist will
  240.             be  interpreted  as a filename if its first character
  241.             is given as either a '.' or a pathname separator ('/'
  242.             or '\'). In order to specify a file found in the cur-
  243.             rent directory, use "./filename".
  244.  
  245.             This feature is useful when preprocessor  macros  are
  246.             used  in  such a way that they cause syntactic confu-
  247.             sion due to their presence. Some examples will illus-
  248.             trate this point.
  249.  
  250.               /*  creates  a  global  version string in module */
  251.               MODULE_VERSION("$Revision: 1.25 $")
  252.  
  253.             In this example, the macro invocation looks  to  much
  254.             like a function definition because it is not followed
  255.             by a semicolon (indeed, it could even be followed  by
  256.             a  global variable definition that would look exactly
  257.             like a K&R style function parameter declaration).  In
  258.             fact,  this  seeming function definition would likely
  259.  
  260.  
  261.  
  262. Darren Hiebert            5 October 1996                        4
  263.  
  264.  
  265.  
  266.  
  267.  
  268. CTAGS(1)                                                 CTAGS(1)
  269.  
  270.  
  271.             cause the rest of the file to be skipped  over  while
  272.             trying  to  complete  the  definition. Ignoring "MOD-
  273.             ULE_ID" would avoid such a problem.
  274.  
  275.               int foo ARGDECL2(void *, ptr, long int, nbytes)
  276.  
  277.             In this example, the macro "ARGDECL2" would  be  mis-
  278.             takenly  interpreted  to  be the name of the function
  279.             instead of the correct name of  "foo".  Ignoring  the
  280.             name "ARGDECL2" results in the correct behavior.
  281.  
  282.        -L listfile
  283.             Read  from  listfile  a  list of file names for which
  284.             tags should be generated. If listfile is specified as
  285.             "-", then file names are read from standard input.
  286.  
  287.        -n   Places  into  the tag file line numbers in the source
  288.             file where tags are located rather than  patterns  to
  289.             be searched for. This has three advantages:
  290.             1.  Significantly  reduces  the size of the resulting
  291.                 tag file.
  292.             2.  Eliminates failures to find tags because the line
  293.                 defining the tag has changed, causing the pattern
  294.                 match to fail (note that some  editors,  such  as
  295.                 vim, are able to recover in many such instances).
  296.             3.  Eliminates finding identical matching, but incor-
  297.                 rect, source lines (see BUGS, below).
  298.             However,  this  option  has one significant drawback:
  299.             changes to the source files can cause the  line  num-
  300.             bers recorded in the tag file to no longer correspond
  301.             to the lines in the source  file,  causing  jumps  to
  302.             some  tags  to  miss  the target definition by one or
  303.             more lines. Basically, this option is best used  when
  304.             the source code to which it is applied is not subject
  305.             to change.  See also the -N  option.  Selecting  this
  306.             option  causes  the  following options to be ignored:
  307.             -F, -B and -N.
  308.  
  309.        -N   Uses search patterns for all tags,  rather  than  the
  310.             line numbers usually used for macro definitions. This
  311.             has the advantage of not  referencing  obsolete  line
  312.             numbers  when  lines have been added or removed since
  313.             the tag file was generated. See also the  -n  option.
  314.             Selecting this option causes the following options to
  315.             be ignored: -F, -B and -n.
  316.  
  317.        -o tagfile
  318.             Alternative for -f.
  319.  
  320.        -s   Include static tags in the output file, each prefixed
  321.             with  the  name  of the file in which it appears fol-
  322.             lowed by a colon. This is equivalent to -i+SP and  is
  323.             supported only for backwards compatibility with other
  324.             versions of ctags. Use of -i is preferred.
  325.  
  326.  
  327.  
  328. Darren Hiebert            5 October 1996                        5
  329.  
  330.  
  331.  
  332.  
  333.  
  334. CTAGS(1)                                                 CTAGS(1)
  335.  
  336.  
  337.        -S   Include static tags in the output file,  but  do  not
  338.             prefix  them,  thereby making them appear the same as
  339.             global tags. This is equivalent to -i+S-P and is sup-
  340.             ported  only  for  backwards compatibility with other
  341.             versions of ctags. Use of -i is preferred.
  342.  
  343.        -t   Include typedefs in the output file. This is  equiva-
  344.             lent to -i+t and is supported only for backwards com-
  345.             patibility with other versions of ctags. Use of -i is
  346.             preferred.
  347.  
  348.        -T   Include  typedefs and class/enum/struct/union tags in
  349.             the output file.  This is equivalent to -i+tg and  is
  350.             supported only for backwards compatibility with other
  351.             versions of ctags. Use of -i is preferred.
  352.  
  353.        -u   Unsorted; do not sort the tags. Please note that this
  354.             disables the warning messages normally enabled by -W,
  355.             because sorted tags  are  used  to  detect  duplicate
  356.             tags. Note also that vi(1) requires sorted tags.
  357.  
  358.        -w   Exclude warnings about duplicate tags (default).
  359.  
  360.        -W   Generate warnings about duplicate tags.
  361.  
  362.        -x   Print   a  tabular,  human-readable  cross  reference
  363.             (xref) file to standard output. The information  con-
  364.             tained  in the output includes: the tag name; the tag
  365.             type; the line number, file  name,  and  source  line
  366.             (with  extra white space condensed) of the file which
  367.             defines the tag. No tag file is written and the  fol-
  368.             lowing options will be ignored: -a, -f, -i+P, -n, -o,
  369.             -B and -F.  Example applications for this feature are
  370.             generating  a  listing  of  all  functions (including
  371.             statics) located in a source file (e.g.  ctags -xi=fS
  372.             file), or generating a list of all externally visible
  373.             global variables  located  in  a  source  file  (e.g.
  374.             ctags -xi=v file).
  375.  
  376. ENVIRONMENT VARIABLES
  377.        CTAGS   If found, this variable will be assumed to contain
  378.                a set of custom default  options  which  are  read
  379.                when  ctags  starts,  but  before any command line
  380.                options are read. Options in this variable  should
  381.                be  in the same form as those on the command line.
  382.                Command line options will override options  speci-
  383.                fied  in this variable. Only options may be speci-
  384.                fied with this variable; no source file names  are
  385.                read from its value.
  386.  
  387. HOW TO USE WITH VI
  388.        Vi  will, by default, expect a tag file by the name "tags"
  389.        in the current directory. Once the tag file is build,  the
  390.        following  vi  commands  take  exercise  the  tag indexing
  391.  
  392.  
  393.  
  394. Darren Hiebert            5 October 1996                        6
  395.  
  396.  
  397.  
  398.  
  399.  
  400. CTAGS(1)                                                 CTAGS(1)
  401.  
  402.  
  403.        feature:
  404.  
  405.        vi -t tag   Start vi and position the cursor at  the  file
  406.                    and line where "tag" is defined.
  407.  
  408.        Control-]   Find the tag under the cursor.
  409.  
  410.        :ta tag     Find a tag.
  411.  
  412.        Control-T   Return to previous location before jump to tag
  413.                    (not widely implemented).
  414.  
  415. BUGS
  416.        Support for C++ features is quite limited.
  417.  
  418.        Because ctags does not look inside brace enclosed function
  419.        blocks, local declarations of class/enum/struct/union tags
  420.        and enumeration values within a  function  will  not  have
  421.        tags generated for them.
  422.  
  423.        Note that because ctags generates search patterns for non-
  424.        macro tags, it is entirely possible that  the  wrong  line
  425.        may be found by your editor if there exists another, iden-
  426.        tical, line (whose context prevents it from  generating  a
  427.        tag)  which  is  identical to the line containing the tag.
  428.        The following example demonstrates this condition:
  429.  
  430.               int variable;
  431.  
  432.               /* ... */
  433.               void foo(variable)
  434.               int variable;
  435.               {
  436.                   /* ... */
  437.               }
  438.  
  439.        Depending upon which editor you use and where in the  code
  440.        you  happen  to be, it is possible that the search pattern
  441.        may locate the local parameter declaration in foo() before
  442.        it  finds the actual global variable definition, since the
  443.        lines (and therefore their search patterns are identical).
  444.        This can be avoided by use of the -n option.
  445.  
  446.        Because  ctags  is  neither a preprocessor nor a compiler,
  447.        some complex or obscure constructs  can  fool  ctags  into
  448.        either  missing a tag or improperly generating an inappro-
  449.        priate tag. In particular, the use  of  preprocessor  con-
  450.        structs  which  alter  the  textual  syntax  of C can fool
  451.        ctags, as demonstrated by the following example:
  452.  
  453.               #ifdef GLOBAL
  454.               #define EXTERN
  455.               #define INIT(assign)  assign
  456.               #else
  457.  
  458.  
  459.  
  460. Darren Hiebert            5 October 1996                        7
  461.  
  462.  
  463.  
  464.  
  465.  
  466. CTAGS(1)                                                 CTAGS(1)
  467.  
  468.  
  469.               #define EXTERN extern
  470.               #define INIT(assign)
  471.               #endif
  472.  
  473.               EXTERN BUF *firstbuf INIT(= NULL);
  474.  
  475.        This looks too much like  a  declaration  for  a  function
  476.        called  "INIT",  which  returns  a  pointer  to  a typedef
  477.        "firstbuf", rather than  the  actual  variable  definition
  478.        that it is, since this distinction can only be resolved by
  479.        the preprocessor. The moral of the story: don't do this if
  480.        you  want  a tag generated for it, or use the -I option to
  481.        specify "INIT" as a keyword to be ignored.
  482.  
  483. FILES
  484.        tags      The default tag file created by ctags.
  485.  
  486. SEE ALSO
  487.        The official Exuberant Ctags web site at:
  488.  
  489.            http://fly.hiwaay.net/~darren/ctags.html
  490.  
  491.        Also ex(1), vi(1), elvis, or, better yet, vim,  the  offi-
  492.        cial  editor  of  ctags.  For more information on vim, see
  493.        the VIM Pages web site at:
  494.  
  495.            http://www.math.fu-berlin.de/~guckes/vim/
  496.  
  497. AUTHOR
  498.        Darren  Hiebert,   (darren@sirsi.com,   darren@hiwaay.net,
  499.        http://fly.hiwaay.net/~darren)
  500.  
  501. MOTIVATION
  502.        "Think  ye at all times of rendering some service to every
  503.        member of the human race."
  504.  
  505.        "All effort and exertion put forth by man from  the  full-
  506.        ness  of  his  heart  is worship, if it is prompted by the
  507.        highest motives and the will to do service to humanity."
  508.  
  509.                  -- From the Baha'i Writings
  510.  
  511. CREDITS
  512.        This version of ctags is derived from and inspired by  the
  513.        ctags  program  by  Steve Kirkendall (kirkenda@cs.pdx.edu)
  514.        that comes with the Elvis vi clone (though almost none  of
  515.        the original code remains).
  516.  
  517.        Credit  is also due Bram Moolenaar, the author of vim, who
  518.        has devoted so much of his time and energy both to  devel-
  519.        oping  the  editor  as a service to others, and to helping
  520.        the orphans of Uganda.
  521.  
  522.  
  523.  
  524.  
  525.  
  526. Darren Hiebert            5 October 1996                        8
  527.  
  528.  
  529.