2 Editor C-code navigation via tags.
3 make TAGS file via command:
4 $ find . -type f -name "*.[ch]" | etags -l c --declarations -
6 or, if etags utility not installed:
7 $ find . -type f -name "*.[ch]" | ctags --c-kinds=+p --fields=+iaS --extra=+q -e -L-
9 Copyright (C) 2009, 2011
10 The Free Software Foundation, Inc.
13 Ilia Maslakov <il.smind@gmail.com>, 2009
14 Slava Zanko <slavazanko@gmail.com>, 2009
16 This file is part of the Midnight Commander.
18 The Midnight Commander is free software: you can redistribute it
19 and/or modify it under the terms of the GNU General Public License as
20 published by the Free Software Foundation, either version 3 of the License,
21 or (at your option) any later version.
23 The Midnight Commander is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program. If not, see <http://www.gnu.org/licenses/>.
40 #include "lib/global.h"
41 #include "lib/util.h" /* canonicalize_pathname() */
45 /*** global variables ****************************************************************************/
47 /*** file scope macro definitions ****************************************************************/
49 /*** file scope type declarations ****************************************************************/
51 /*** file scope variables ************************************************************************/
53 /*** file scope functions ************************************************************************/
54 /* --------------------------------------------------------------------------------------------- */
57 parse_define (char *buf
, char **long_name
, char **short_name
, long *line
)
64 in_shortname_first_char
,
66 } def_state
= in_longname
;
69 static char longdef
[LONG_DEF_LEN
];
70 static char shortdef
[SHORT_DEF_LEN
];
71 static char linedef
[LINE_DEF_LEN
];
77 while (!(c
== '\0' || c
== '\n'))
88 def_state
= in_shortname
;
92 if (nlong
< LONG_DEF_LEN
- 1)
98 case in_shortname_first_char
:
111 if (nshort
< SHORT_DEF_LEN
- 1)
113 shortdef
[nshort
++] = c
;
114 def_state
= in_shortname
;
129 if (nshort
< SHORT_DEF_LEN
- 1)
131 shortdef
[nshort
++] = c
;
136 if (c
== ',' || c
== '\n')
140 else if (isdigit (c
))
142 if (nline
< LINE_DEF_LEN
- 1)
144 linedef
[nline
++] = c
;
149 longdef
[nlong
] = '\0';
150 shortdef
[nshort
] = '\0';
151 linedef
[nline
] = '\0';
152 *long_name
= longdef
;
153 *short_name
= shortdef
;
154 *line
= atol (linedef
);
166 /* --------------------------------------------------------------------------------------------- */
167 /*** public functions ****************************************************************************/
168 /* --------------------------------------------------------------------------------------------- */
171 etags_set_definition_hash (const char *tagfile
, const char *start_path
,
172 const char *match_func
, etags_hash_t
* def_hash
)
184 static char buf
[BUF_LARGE
];
186 char *chekedstr
= NULL
;
188 int num
= 0; /* returned value */
190 char *filename
= NULL
;
192 if (!match_func
|| !tagfile
)
195 /* open file with positions */
196 f
= fopen (tagfile
, "r");
200 while (fgets (buf
, sizeof (buf
), f
))
211 pos
= strcspn (buf
, ",");
213 filename
= g_malloc (pos
+ 2);
214 g_strlcpy (filename
, (char *) buf
, pos
+ 1);
223 /* check if the filename matches the define pos */
224 chekedstr
= strstr (buf
, match_func
);
227 char *longname
= NULL
;
228 char *shortname
= NULL
;
231 parse_define (chekedstr
, &longname
, &shortname
, &line
);
232 if (num
< MAX_DEFINITIONS
- 1)
234 def_hash
[num
].filename_len
= strlen (filename
);
235 def_hash
[num
].fullpath
=
236 mc_build_filename (start_path
, filename
, (char *) NULL
);
238 canonicalize_pathname (def_hash
[num
].fullpath
);
239 def_hash
[num
].filename
= g_strdup (filename
);
242 def_hash
[num
].short_define
= g_strdup (shortname
);
246 def_hash
[num
].short_define
= g_strdup (longname
);
248 def_hash
[num
].line
= line
;
261 /* --------------------------------------------------------------------------------------------- */