6. Proposal
-----------
Use a comment after the {tagaddress} field. The format would be:
{tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}..]
{tagname} Any identifier, not containing white space..
<Tab> Exactly one TAB character (although many versions of Vi can handle any amount of white space).
{tagfile} The name of the file where {tagname} is defined, relative to the current directory
(or location of the tags file?).
{tagaddress} Any Ex command. When executed, it behaves like 'magic' was not set.
It may be restricted to a line number or a search pattern (Posix).
Optionally:
;" semicolon + doublequote: Ends the tagaddress in way that looks like the start of a comment to Vi.
{tagfield} See below.
A tagfield has a name, a colon, and a value: "name:value".
- The name consist only out of alphabetical characters. Upper and lower case are allowed.
Lower case is recommended. Case matters ("kind:" and "Kind: are different tagfields).
- The value may be empty.
It cannot contain a <Tab>.
When a value contains a "\t", this stands for a <Tab>.
When a value contains a "\r", this stands for a <CR>.
When a value contains a "\n", this stands for a <NL>.
When a value contains a "\\", this stands for a single '\' character.
Other use of the backslash character is reserved for future expansion.
Warning: When a tagfield value holds an MS-DOS file name, the backslashes must be doubled!
Proposed tagfield names:
FIELD-NAME DESCRIPTION
arity Number of arguments for a function tag.
class Name of the class for which this tag is a member or method.
enum Name of the enumeration in which this tag is an enumerator.
file Static (local) tag, with a scope of the specified file. When the value is empty, {tagfile} is used.
function Function in which this tag is defined. Useful for local variables (and functions).
When functions nest (e.g., in Pascal), the function names are concatenated, separated with
'/', so it looks like a path.
kind
Kind of tag. The value depends on the language. For C and
C++ these kinds are recommended:
c class name
d define (from #define XXX)
e enumerator
f function or method name
F File name
g enumeration name
m member (of structure or class data)
p function prototype
s structure name
t typedef
u union name
v variable
When this field is omitted, the kind of tag is undefined.
struct Name of the struct in which this tag is a member.
union Name of the union in which this tag is a member.
Note that these are mostly for C and C++. When tags programs are written for
other languages, this list should be extended to include the used field names.
This will help users to be independent of the tags program used.
Examples:
asdf sub.cc /^asdf()$/;" new_field:some\svalue file:
foo_t sub.h /^typedef foo_t$/;" kind:t
func3 sub.p /^func3()$/;" function:/func1/func2 file:
getflag sub.c /^getflag(arg)$/;" kind:f file:
inc sub.cc /^inc()$/;" file: class:PipeBuf
The name of the "kind:" field can be omitted. This is to reduce the size of
the tags file by about 15%. A program reading the tags file can recognize the
"kind:" field by the missing ':'. Examples:
foo_t sub.h /^typedef foo_t$/;" t
getflag sub.c /^getflag(arg)$/;" f file:
Additional remarks:
- When a tagfield appears twice in a tag line, only the last one is used.
Note about line separators:
Vi traditionally runs on Unix systems, where the line separator is a single
linefeed character <NL>. On MS-DOS and compatible systems <CR><NL> is the
standard line separator. To increase portability, this line separator is also
supported.
On the Macintosh a single <CR> is used for line separator. Supporting this on
Unix systems causes problems, because most fgets() implementation don't see
the <CR> as a line separator. Therefore the support for a <CR> as line
separator is limited to the Macintosh.
Summary:
line separator generated on accepted on
<LF> Unix Unix, MS-DOS, Macintosh
<CR> Macintosh Macintosh
<CR><LF> MS-DOS Unix, MS-DOS, Macintosh
The characters <CR> and <LF> cannot be used inside a tag line. This is not
mentioned elsewhere (because it's obvious).
Note about white space:
Vi allowed any white space to separate the tagname from the tagfile, and the
filename from the tagaddress. This would need to be allowed for backwards
compatibility. However, all known programs that generate tags use a single
<Tab> to separate fields.
There is a problem for using file names with embedded white space in the
tagfile field. To work around this, the same special characters could be used
as in the new fields, for example "\s". But, unfortunately, in MS-DOS the
backslash character is used to separate file names. The file name
"c:\vim\sap" contains "\s", but this is not a <Space>. The number of
backslashes could be doubled, but that will add a lot of characters, and make
parsing the tags file slower and clumsy.
To avoid these problems, we will only allow a <Tab> to separate fields, and
not support a file name or tagname that contains a <Tab> character. This
means that we are not 100% Vi compatible. However, there is no known tags
program that uses something else than a <Tab> to separate the fields. Only
when a user typed the tags file himself, or made his own program to generate a
tags file, we could run into problems. To solve this, the tags file should be
filtered, to replace the arbitrary white space with a single <Tab>. This Vi
command can be used:
:%s/^\([^ ^I]*\)[ ^I]*\([^ ^I]*\)[ ^I]*/\1^I\2^I/
(replace ^I with a real <Tab>).
TAG FILE INFORMATION:
Psuedo-tag lines can be used to encode information into the tag file regarding
details about its content (e.g. have the tags been sorted?, are the optional
tagfields present?), and regarding the program used to generate the tag file.
This information can be used both to optimize use of the tag file (e.g.
enable/disable binary searching) and provide general information (what version
of the generator was used).
The names of the tags used in these lines may be suitably chosen to ensure
that when sorted, they will always be located near the first lines of the tag
file. The use of "!_TAG_" is recommended. Note that a rare tag like "!"
can sort to before these lines. The program reading the tags file should be
smart enough to skip over these tags.
The lines described below have been chosen to convey a select set of
information.
Tag lines providing information about the content of the tag file:
!_TAG_FILE_FORMAT {version-number} /optional comment/
!_TAG_FILE_SORTED {0|1} /0=unsorted, 1=sorted/
The {version-number} used in the tag file format line reserves the value of
"1" for tag files complying with the original UNIX vi/ctags format, and
reserves the value "2" for tag files complying with this proposal. This value
may be used to determine if the extended features described in this proposal
are present.
Tag lines providing information about the program used to generate the tag
file, and provided solely for documentation purposes:
!_TAG_PROGRAM_AUTHOR {author-name} /{email-address}/
!_TAG_PROGRAM_NAME {program-name} /optional comment/
!_TAG_PROGRAM_URL {URL} /optional comment/
!_TAG_PROGRAM_VERSION {version-id} /optional comment/
[링크 :
http://ctags.sourceforge.net/FORMAT]
별다른 옵션을 주지 않고
으로 실행하면 tags 라는 파일이 생성됨
$more test.c
#include <stdio.h>
#define VERSION 1.00
typedef struct _point_
{
int x;
int y;
} POINT;
void main()
{
int a;
char str[] = "Hello world";
POINT pt;
printf("%s\n",str);
}
|
$ more tags
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.4 //
POINT test.c /^} POINT;$/;" t file:
VERSION test.c 2;" d file:
_point_ test.c /^typedef struct _point_$/;" s file:
main test.c /^void main()$/;" f
x test.c /^ int x;$/;" m struct:_point_ file:
y test.c /^
int y;$/;" m struct:_point_ file:
|
{tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}..] 가 기본 포맷인데
POINT test.c /^} POINT;$/;" t file: 를 보면
tagname - POINT
tagfile - test.c
tagaddress - /^} POINT;$/
tagfield - t
tagfield - file:
라는 의미를 지니게 된다. 아래의 POINT 구조체의 x, y 변수는 m(member)로 표기된다.