1CTAGS(1P)                  POSIX Programmer's Manual                 CTAGS(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       ctags — create a tags file (DEVELOPMENT, FORTRAN)
13

SYNOPSIS

15       ctags [-a] [-f tagsfile] pathname...
16
17       ctags -x pathname...
18

DESCRIPTION

20       The ctags utility shall be provided on systems  that  support  the  the
21       Software Development Utilities option, and either or both of the C-Lan‐
22       guage Development Utilities option and  FORTRAN  Development  Utilities
23       option. On other systems, it is optional.
24
25       The ctags utility shall write a tagsfile or an index of objects from C-
26       language or FORTRAN source files specified by  the  pathname  operands.
27       The  tagsfile  shall  list  the  locators  of language-specific objects
28       within the source files. A locator consists of a  name,  pathname,  and
29       either  a search pattern or a line number that can be used in searching
30       for the object definition. The objects that  shall  be  recognized  are
31       specified in the EXTENDED DESCRIPTION section.
32

OPTIONS

34       The  ctags  utility  shall  conform  to  the Base Definitions volume of
35       POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
36
37       The following options shall be supported:
38
39       -a        Append to tagsfile.
40
41       -f tagsfile
42                 Write the object locator lists into tagsfile instead  of  the
43                 default file named tags in the current directory.
44
45       -x        Produce a list of object names, the line number, and filename
46                 in which each is defined, as well as the text of  that  line,
47                 and  write  this to the standard output. A tagsfile shall not
48                 be created when -x is specified.
49

OPERANDS

51       The following pathname operands are supported:
52
53       file.c    Files with basenames ending  with  the  .c  suffix  shall  be
54                 treated  as  C-language  source code. Such files that are not
55                 valid input to c99 produce unspecified results.
56
57       file.h    Files with basenames ending  with  the  .h  suffix  shall  be
58                 treated  as  C-language  source code. Such files that are not
59                 valid input to c99 produce unspecified results.
60
61       file.f    Files with basenames ending  with  the  .f  suffix  shall  be
62                 treated  as FORTRAN-language source code. Such files that are
63                 not valid input to fort77 produce unspecified results.
64
65       The handling of other files is implementation-defined.
66

STDIN

68       See the INPUT FILES section.
69

INPUT FILES

71       The input files shall be text files containing source code in the  lan‐
72       guage indicated by the operand filename suffixes.
73

ENVIRONMENT VARIABLES

75       The  following  environment  variables  shall  affect  the execution of
76       ctags:
77
78       LANG      Provide a default value for  the  internationalization  vari‐
79                 ables  that are unset or null. (See the Base Definitions vol‐
80                 ume of POSIX.1‐2017, Section 8.2, Internationalization  Vari‐
81                 ables  for  the  precedence of internationalization variables
82                 used to determine the values of locale categories.)
83
84       LC_ALL    If set to a non-empty string value, override  the  values  of
85                 all the other internationalization variables.
86
87       LC_COLLATE
88                 Determine  the  order  in  which  output is sorted for the -x
89                 option. The POSIX locale determines the order  in  which  the
90                 tagsfile is written.
91
92       LC_CTYPE  Determine  the  locale for the interpretation of sequences of
93                 bytes of text data as characters (for example, single-byte as
94                 opposed  to  multi-byte  characters  in  arguments  and input
95                 files). When processing C-language source code, if the locale
96                 is  not  compatible  with the C locale described by the ISO C
97                 standard, the results are unspecified.
98
99       LC_MESSAGES
100                 Determine the locale that should be used to affect the format
101                 and  contents  of  diagnostic  messages  written  to standard
102                 error.
103
104       NLSPATH   Determine the location of message catalogs for the processing
105                 of LC_MESSAGES.
106

ASYNCHRONOUS EVENTS

108       Default.
109

STDOUT

111       The  list of object name information produced by the -x option shall be
112       written to standard output in the following format:
113
114
115           "%s %d %s %s", <object-name>, <line-number>, <filename>, <text>
116
117       where <text> is the text of line <line-number> of file <filename>.
118

STDERR

120       The standard error shall be used only for diagnostic messages.
121

OUTPUT FILES

123       When the -x option is not specified, the  format  of  the  output  file
124       shall be:
125
126
127           "%s\t%s\t/%s/\n", <identifier>, <filename>, <pattern>
128
129       where  <pattern> is a search pattern that could be used by an editor to
130       find the defining instance of <identifier> in <filename> (where  defin‐
131       ing  instance  is  indicated by the declarations listed in the EXTENDED
132       DESCRIPTION).
133
134       An optional <circumflex> ('^') can be added as a prefix  to  <pattern>,
135       and  an optional <dollar-sign> can be appended to <pattern> to indicate
136       that the pattern is anchored to the beginning (end) of a line of  text.
137       Any <slash> or <backslash> characters in <pattern> shall be preceded by
138       a <backslash> character. The anchoring <circumflex>, <dollar-sign>, and
139       escaping  <backslash>  characters  shall  not be considered part of the
140       search pattern. All other characters in the  search  pattern  shall  be
141       considered literal characters.
142
143       An alternative format is:
144
145
146           "%s\t%s\t?%s?\n", <identifier>, <filename>, <pattern>
147
148       which  is  identical to the first format except that <slash> characters
149       in <pattern> shall not be preceded by escaping <backslash>  characters,
150       and <question-mark> characters in <pattern> shall be preceded by <back‐
151       slash> characters.
152
153       A second alternative format is:
154
155
156           "%s\t%s\t%d\n", <identifier>, <filename>, <lineno>
157
158       where <lineno> is a decimal line number that could be used by an editor
159       to find <identifier> in <filename>.
160
161       Neither  alternative  format shall be produced by ctags when it is used
162       as described by POSIX.1‐2008, but the standard utilities  that  process
163       tags  files shall be able to process those formats as well as the first
164       format.
165
166       In any of these formats, the file shall be sorted by identifier,  based
167       on the collation sequence in the POSIX locale.
168

EXTENDED DESCRIPTION

170       If  the  operand  identifies C-language source, the ctags utility shall
171       attempt to produce an output line for each of the following objects:
172
173        *  Function definitions
174
175        *  Type definitions
176
177        *  Macros with arguments
178
179       It may also produce output for any of the following objects:
180
181        *  Function prototypes
182
183        *  Structures
184
185        *  Unions
186
187        *  Global variable definitions
188
189        *  Enumeration types
190
191        *  Macros without arguments
192
193        *  #define statements
194
195        *  #line statements
196
197       Any #if and #ifdef statements shall produce no output. The tag main  is
198       treated  specially  in  C  programs. The tag formed shall be created by
199       prefixing M to the name of the file, with the trailing .c, and  leading
200       pathname components (if any) removed.
201
202       On  systems  that  do  not support the C-Language Development Utilities
203       option, ctags produces unspecified results for C-language  source  code
204       files.  It  should  write  to standard error a message identifying this
205       condition and cause a non-zero exit status to be produced.
206
207       If the operand identifies FORTRAN source, the ctags utility shall  pro‐
208       duce  an  output line for each function definition. It may also produce
209       output for any of the following objects:
210
211        *  Subroutine definitions
212
213        *  COMMON statements
214
215        *  PARAMETER statements
216
217        *  DATA and BLOCK DATA statements
218
219        *  Statement numbers
220
221       On systems that  do  not  support  the  FORTRAN  Development  Utilities
222       option,  ctags  produces  unspecified  results  for FORTRAN source code
223       files. It should write to standard error  a  message  identifying  this
224       condition and cause a non-zero exit status to be produced.
225
226       It  is  implementation-defined  what other objects (including duplicate
227       identifiers) produce output.
228

EXIT STATUS

230       The following exit values shall be returned:
231
232        0    Successful completion.
233
234       >0    An error occurred.
235

CONSEQUENCES OF ERRORS

237       Default.
238
239       The following sections are informative.
240

APPLICATION USAGE

242       The output with -x is meant to be a simple index that  can  be  written
243       out as an off-line readable function index. If the input files to ctags
244       (such as .c files) were not created using the same locale  as  that  in
245       effect when ctags -x is run, results might not be as expected.
246
247       The  description  of C-language processing says ``attempts to'' because
248       the C language can be greatly confused, especially through the  use  of
249       #defines,  and this utility would be of no use if the real C preproces‐
250       sor were run to identify them. The output from ctags may be fooled  and
251       incorrect for various constructs.
252

EXAMPLES

254       None.
255

RATIONALE

257       The option list was significantly reduced from that provided by histor‐
258       ical implementations. The -F option was omitted as redundant, since  it
259       is the default. The -B option was omitted as being of very limited use‐
260       fulness. The -t option was omitted since the recognition of typedefs is
261       now  required for C source files. The -u option was omitted because the
262       update function was judged to be not only inefficient, but also  rarely
263       needed.
264
265       An early proposal included a -w option to suppress warning diagnostics.
266       Since the types of such diagnostics could not be described, the  option
267       was omitted as being not useful.
268
269       The  text  for  LC_CTYPE about compatibility with the C locale acknowl‐
270       edges that the ISO C standard imposes requirements on the  locale  used
271       to  process  C source. This could easily be a superset of that known as
272       ``the C locale'' by way of implementation extensions, or one of  a  few
273       alternative  locales  for  systems  supporting  different  codesets. No
274       statement is made for FORTRAN because the ANSI X3.9‐1978 standard (FOR‐
275       TRAN  77)  does  not  (yet) define a similar locale concept. However, a
276       general rule in this volume of  POSIX.1‐2017  is  that  any  time  that
277       locales do not match (preparing a file for one locale and processing it
278       in another), the results are suspect.
279
280       The collation sequence of the tags file is not affected  by  LC_COLLATE
281       because it is typically not used by human readers, but only by programs
282       such as vi to locate the tag within the source files. Using  the  POSIX
283       locale  eliminates some of the problems of coordinating locales between
284       the ctags file creator and the vi file reader.
285
286       Historically, the tags file has been used only by ex and vi.   However,
287       the  format of the tags file has been published to encourage other pro‐
288       grams to use the tags in new ways. The format allows either patterns or
289       line  numbers  to find the identifiers because the historical vi recog‐
290       nizes either. The ctags utility does not produce the format using  line
291       numbers because it is not useful following any source file changes that
292       add or delete lines.  The documented search patterns  match  historical
293       practice.  It  should  be  noted  that  literal leading <circumflex> or
294       trailing <dollar-sign> characters  in  the  search  pattern  will  only
295       behave correctly if anchored to the beginning of the line or end of the
296       line by an additional <circumflex> or <dollar-sign> character.
297
298       Historical implementations also understand the objects used by the lan‐
299       guages Pascal and sometimes LISP, and they understand the C source out‐
300       put by lex and yacc.  The ctags utility is not required to  accommodate
301       these languages, although implementors are encouraged to do so.
302
303       The  following  historical  option  was not specified, as vgrind is not
304       included in this volume of POSIX.1‐2017:
305
306       -v        If the -v flag is given, an index of  the  form  expected  by
307                 vgrind  is produced on the standard output. This listing con‐
308                 tains the function name, filename, and page number  (assuming
309                 64-line pages). Since the output is sorted into lexicographic
310                 order, it may be desired to run the output through  sort  -f.
311                 Sample use:
312
313
314                     ctags -v files | sort -f > index vgrind -x index
315
316       The  special treatment of the tag main makes the use of ctags practical
317       in directories with more than one program.
318

FUTURE DIRECTIONS

320       None.
321

SEE ALSO

323       c99, fort77, vi
324
325       The Base Definitions volume of  POSIX.1‐2017,  Chapter  8,  Environment
326       Variables, Section 12.2, Utility Syntax Guidelines
327
329       Portions  of  this text are reprinted and reproduced in electronic form
330       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
331       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
332       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
333       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
334       event of any discrepancy between this version and the original IEEE and
335       The  Open Group Standard, the original IEEE and The Open Group Standard
336       is the referee document. The original Standard can be  obtained  online
337       at http://www.opengroup.org/unix/online.html .
338
339       Any  typographical  or  formatting  errors that appear in this page are
340       most likely to have been introduced during the conversion of the source
341       files  to  man page format. To report such errors, see https://www.ker
342       nel.org/doc/man-pages/reporting_bugs.html .
343
344
345
346IEEE/The Open Group                  2017                            CTAGS(1P)
Impressum