Debian Codegraph @

CodeLite/readtags.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2008 by Eran Ifrah
5 // file name : readtags.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25 /*
26 * $Id: readtags.h,v 1.1 2005/11/21 18:00:11 eran Exp $
27 *
28 * Copyright (c) 1996-2003, Darren Hiebert
29 *
30 * This source code is released for the public domain.
31 *
32 * This file defines the public interface for looking up tag entries in tag
33 * files.
34 *
35 * The functions defined in this interface are intended to provide tag file
36 * support to a software tool. The tag lookups provided are sufficiently fast
37 * enough to permit opening a sorted tag file, searching for a matching tag,
38 * then closing the tag file each time a tag is looked up (search times are
39 * on the order of hundreths of a second, even for huge tag files). This is
40 * the recommended use of this library for most tool applications. Adhering
41 * to this approach permits a user to regenerate a tag file at will without
42 * the tool needing to detect and resynchronize with changes to the tag file.
43 * Even for an unsorted 24MB tag file, tag searches take about one second.
44 */
45 #ifndef CODELITE_READTAGS_H
46 #define CODELITE_READTAGS_H
47
48 /*
49 * MACROS
50 */
51
52 /** Options for tagsSetSortType() */
53 typedef enum {
54 TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED
55 } sortType ;
56
57 /* Options for tagsFind() */
58 #define TAG_FULLMATCH 0x0
59 #define TAG_PARTIALMATCH 0x1
60
61 #define TAG_OBSERVECASE 0x0
62 #define TAG_IGNORECASE 0x2
63
64 /*
65 * DATA DECLARATIONS
66 */
67
68 typedef enum { TagFailure = 0, TagSuccess = 1 } tagResult;
69
70 struct sTagFile;
71
72 typedef struct sTagFile tagFile;
73
74 /** This structure contains information about the tag file. */
75 typedef struct {
76
77 struct {
78 /** was the tag file successfully opened? */
79 int opened;
80
81 /** errno value when 'opened' is false */
82 int error_number;
83 } status;
84
85 /** information about the structure of the tag file */
86 struct {
87 /** format of tag file (1 = original, 2 = extended) */
88 short format;
89
90 /** how is the tag file sorted? */
91 sortType sort;
92 } file;
93
94
95 /** information about the program which created this tag file */
96 struct {
97 /** name of author of generating program (may be null) */
98 const char *author;
99
100 /** name of program (may be null) */
101 const char *name;
102
103 /** URL of distribution (may be null) */
104 const char *url;
105
106 /** program version (may be null) */
107 const char *version;
108 } program;
109
110 } tagFileInfo;
111
112 /** This structure contains information about an extension field for a tag.
113 * These exist at the end of the tag in the form "key:value").
114 */
115 typedef struct {
116
117 /** the key of the extension field */
118 const char *key;
119
120 /** the value of the extension field (may be an empty string) */
121 const char *value;
122
123 } tagExtensionField;
124
125 /** This structure contains information about a specific tag. */
126 typedef struct {
127
128 /** name of tag */
129 const char *name;
130
131 /** path of source file containing definition of tag */
132 const char *file;
133
134 /** address for locating tag in source file */
135 struct {
136 /** pattern for locating source line
137 * (may be NULL if not present) */
138 const char *pattern;
139
140 /** line number in source file of tag definition
141 * (may be zero if not known) */
142 unsigned long lineNumber;
143 } address;
144
145 /** kind of tag (may by name, character, or NULL if not known) */
146 const char *kind;
147
148 /** is tag of file-limited scope? */
149 short fileScope;
150
151 /** miscellaneous extension fields */
152 struct {
153 /** number of entries in `list' */
154 unsigned short count;
155
156 /** list of key value pairs */
157 tagExtensionField *list;
158 } fields;
159
160 } tagEntry;
161
162
163 /*
164 * FUNCTION PROTOTYPES
165 */
166
167 /**
168 * This function must be called before calling other functions in this
169 * library. It is passed the path to the tag file to read and a (possibly
170 * null) pointer to a structure which, if not null, will be populated with
171 * information about the tag file. If successful, the function will return a
172 * handle which must be supplied to other calls to read information from the
173 * tag file, and info.status.opened will be set to true. If unsuccessful,
174 * info.status.opened will be set to false and info.status.error_number will
175 * be set to the errno value representing the system error preventing the tag
176 * file from being successfully opened.
177 */
178 extern tagFile *tagsOpen (const char *const filePath, tagFileInfo *const info);
179
180 /**
181 * This function allows the client to override the normal automatic detection
182 * of how a tag file is sorted. Permissible values for `type' are
183 * TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED. Tag files in the new extended
184 * format contain a key indicating whether or not they are sorted. However,
185 * tag files in the original format do not contain such a key even when
186 * sorted, preventing this library from taking advantage of fast binary
187 * lookups. If the client knows that such an unmarked tag file is indeed
188 * sorted (or not), it can override the automatic detection. Note that
189 * incorrect lookup results will result if a tag file is marked as sorted when
190 * it actually is not. The function will return TagSuccess if called on an
191 * open tag file or TagFailure if not.
192 */
193 extern tagResult tagsSetSortType (tagFile *const file, const sortType type);
194
195 /**
196 * Reads the first tag in the file, if any. It is passed the handle to an
197 * opened tag file and a (possibly null) pointer to a structure which, if not
198 * null, will be populated with information about the first tag file entry.
199 * The function will return TagSuccess another tag entry is found, or
200 * TagFailure if not (i.e. it reached end of file).
201 */
202 extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry);
203
204 /**
205 * Step to the next tag in the file, if any. It is passed the handle to an
206 * opened tag file and a (possibly null) pointer to a structure which, if not
207 * null, will be populated with information about the next tag file entry. The
208 * function will return TagSuccess another tag entry is found, or TagFailure
209 * if not (i.e. it reached end of file). It will always read the first tag in
210 * the file immediately after calling tagsOpen().
211 */
212 extern tagResult tagsNext (tagFile *const file, tagEntry *const entry);
213
214 /**
215 * Retrieve the value associated with the extension field for a specified key.
216 * It is passed a pointer to a structure already populated with values by a
217 * previous call to tagsNext(), tagsFind(), or tagsFindNext(), and a string
218 * containing the key of the desired extension field. If no such field of the
219 * specified key exists, the function will return null.
220 */
221 extern const char *tagsField (const tagEntry *const entry, const char *const key);
222
223 /**
224 * Find the first tag matching `name'. The structure pointed to by `entry'
225 * will be populated with information about the tag file entry. If a tag file
226 * is sorted using the C locale, a binary search algorithm is used to search
227 * the tag file, resulting in very fast tag lookups, even in huge tag files.
228 * Various options controlling the matches can be combined by bit-wise or-ing
229 * certain values together. The available values are:
230 *
231 * - TAG_PARTIALMATCH
232 * Tags whose leading characters match `name' will qualify.
233 *
234 * - TAG_FULLMATCH
235 * Only tags whose full lengths match `name' will qualify.
236 *
237 * - TAG_IGNORECASE
238 * Matching will be performed in a case-insenstive manner. Note that
239 * this disables binary searches of the tag file.
240 *
241 * - TAG_OBSERVECASE
242 * Matching will be performed in a case-senstive manner. Note that
243 * this enables binary searches of the tag file.
244 *
245 * The function will return TagSuccess if a tag matching the name is found, or
246 * TagFailure if not.
247 */
248 extern tagResult tagsFind (tagFile *const file, tagEntry *const entry, const char *const name, const int options);
249
250 /**
251 * Find the next tag matching the name and options supplied to the most recent
252 * call to tagsFind() for the same tag file. The structure pointed to by
253 * `entry' will be populated with information about the tag file entry. The
254 * function will return TagSuccess if another tag matching the name is found,
255 * or TagFailure if not.
256 */
257 extern tagResult tagsFindNext (tagFile *const file, tagEntry *const entry);
258
259 /**
260 * Call tagsTerminate() at completion of reading the tag file, which will
261 * close the file and free any internal memory allocated. The function will
262 * return TagFailure is no file is currently open, TagSuccess otherwise.
263 */
264 extern tagResult tagsClose (tagFile *const file);
265
266
267 #endif /* CODELITE_READTAGS_H */
268
269 /* vi:set tabstop=8 shiftwidth=4: */