Template:Short description Template:More citations needed {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other Ctags is a programming tool that generates an index file (or tag file) of names found in source and header files of various programming languages to aid code comprehension. Depending on the language, functions, variables, class members, macros and so on may be indexed. These tags allow definitions to be quickly and easily located by a text editor, a code search engine, or other utility. Alternatively, there is also an output mode that generates a cross reference file, listing information about various names found in a set of language files in human-readable form.

The original Ctags was introduced in BSD Unix 2.0<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> and was written by Ken Arnold, with Fortran support by Jim Kleckner and Pascal support by Bill Joy. It is part of the initial release of Single Unix Specification and XPG4 of 1992.

Editors that support ctagsEdit

Tag index files are supported by many source code editors, including: Template:Div col start

|CitationClass=web }}</ref>

  • Cloud9 IDE (uses it internally but does not expose it)
  • CygnusEd<ref>{{#invoke:citation/CS1|citation

|CitationClass=web }}</ref>

Template:Div col end

Variants of ctagsEdit

There are a few other implementations of the ctags program:

EtagsEdit

GNU Emacs comes with two ctags utilities, etags and ctags, which are compiled from the same source code. Etags generates a tag table file for Emacs, while the ctags command is used to create a similar table in a format understood by vi. They have different sets of command line options: etags does not recognize and ignores options which only make sense for vi style tag files produced by the ctags command.<ref>Template:Man</ref>

Exuberant CtagsEdit

Exuberant Ctags, written and maintained by Darren Hiebert until 2009,<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> was initially distributed with Vim, but became a separate project upon the release of Vim 6. It includes support for Emacs and <syntaxhighlight lang="text" class="" style="" inline="1">etags</syntaxhighlight> compatibility.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>Template:Man</ref>

Exuberant Ctags includes support for over 40 programming languages with the ability to add support for even more using regular expressions.

Universal CtagsEdit

Universal Ctags is a fork of Exuberant Ctags, with the objective of continuing its development. A few parsers are rewritten to better support the languages.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Language-specificEdit

Template:Vanchor creates ctags compatible tag files for Haskell source files.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> It includes support for creating Emacs etags files.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Template:Vanchor is a ctags-compatible code indexing solution for JavaScript.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> It is specialized for JavaScript and uses the CommonJS packaging system. It outperforms Exuberant Ctags for JavaScript code, finding more tags than the latter.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Tags file formatsEdit

There are multiple tag file formats. Some of them are described below. In the following, Template:Mono represents the byte with hexadecimal representation Template:Mono. Every line ends with a line feed (LF, Template:Mono = Template:Mono).

Ctags and descendantsEdit

The original ctags and the Exuberant/Universal descendants have similar file formats:<ref name=exu-fmt>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

CtagsEdit

This is the format used by vi and various clones. The tags file is normally named "tags".

The tags file is a list of lines, each line in the format:

{tagname}\t{tagfile}\t{tagaddress}

The fields are specified as follows:

  • Template:Mono} – Any identifier, not containing white space
  • Template:Mono – Exactly one tab (Template:Mono) character, although many versions of vi can handle any amount of white space.
  • Template:Mono} – The name of the file where Template:Mono} is defined, relative to the current directory
  • Template:Mono} – An ex mode command that will take the editor to the location of the tag. For POSIX implementations of vi this may only be a search or a line number, providing added security against arbitrary command execution.

The tags file is sorted on the Template:Mono} field which allows for fast searching of the tags file.

Extended CtagsEdit

This is the format used by Vim's Exuberant Ctags and Universal Ctags. These programs can generate an original ctags file format or an extended format that attempts to retain backward compatibility.

The extended tags file is a list of lines, each line in the format:

{tagname}\t{tagfile}\t{tagaddress}[;"\t{tagfield...}]

The fields up to and including Template:Mono} are the same as for ctags above.

Optional additional fields are indicated by square brackets ("[...]") and include:

  • Template:Mono – semicolon + double quote: Ends the Template:Mono} in a way that looks like the start of a comment to vi or ex.
  • Template:Mono} – extension fields: tab separated "key:value" pairs for more information.

This format is compatible with non-POSIX vi as the additional data is interpreted as a comment. POSIX implementations of vi must be changed to support it, however.<ref name=exu-fmt/>

EtagsEdit

This is the format used by Emacs etags. The tags file is normally named "TAGS".

The etags files consists of multiple sections—one section per input source file. Sections are plain-text with several non-printable ascii characters used for special purposes. These characters are represented as underlined hexadecimal codes below.

A section starts with a two line header (the first two bytes make up a magic number):

\x0c
{src_file},{size_of_tag_definition_data_in_bytes}

The header is followed by tag definitions, one definition per line, with the format:

{tag_definition_text}\x7f{tagname}\x01{line_number},{byte_offset}

Template:Mono can be omitted if the name of the tag can be deduced from the text at the tag definition.

ExampleEdit

Given a single line test.c source code:

#define CCC(x)

The TAGS (etags) file would look like this:

\x0c
test.c,21
#define CCC(\x7fCCC\x011,0

The tags (ctags) file may look like:

CCC(	test.c	1

or more flexibly using a search:

CCC(	test.c	/^#define CCC(/

See alsoEdit

ReferencesEdit

Template:Reflist

External linksEdit

Template:Sister project

Template:Unix commands

fr:Ctags