2 * $Id: readtags.h 2606 2006-08-16 21:13:34Z naba $
4 * Copyright (c) 1996-2003, Darren Hiebert
6 * This source code is released for the public domain.
8 * This file defines the public interface for looking up tag entries in tag
11 * The functions defined in this interface are intended to provide tag file
12 * support to a software tool. The tag lookups provided are sufficiently fast
13 * enough to permit opening a sorted tag file, searching for a matching tag,
14 * then closing the tag file each time a tag is looked up (search times are
15 * on the order of hundreths of a second, even for huge tag files). This is
16 * the recommended use of this library for most tool applications. Adhering
17 * to this approach permits a user to regenerate a tag file at will without
18 * the tool needing to detect and resynchronize with changes to the tag file.
19 * Even for an unsorted 24MB tag file, tag searches take about one second.
32 /* Options for tagsSetSortType() */
34 TAG_UNSORTED
, TAG_SORTED
, TAG_FOLDSORTED
37 /* Options for tagsFind() */
38 #define TAG_FULLMATCH 0x0
39 #define TAG_PARTIALMATCH 0x1
41 #define TAG_OBSERVECASE 0x0
42 #define TAG_IGNORECASE 0x2
48 typedef enum { TagFailure
= 0, TagSuccess
= 1 } tagResult
;
52 typedef struct sTagFile tagFile
;
54 /* This structure contains information about the tag file. */
58 /* was the tag file successfully opened? */
61 /* errno value when 'opened' is false */
65 /* information about the structure of the tag file */
67 /* format of tag file (1 = original, 2 = extended) */
70 /* how is the tag file sorted? */
75 /* information about the program which created this tag file */
77 /* name of author of generating program (may be null) */
80 /* name of program (may be null) */
83 /* URL of distribution (may be null) */
86 /* program version (may be null) */
92 /* This structure contains information about an extension field for a tag.
93 * These exist at the end of the tag in the form "key:value").
97 /* the key of the extension field */
100 /* the value of the extension field (may be an empty string) */
105 /* This structure contains information about a specific tag. */
111 /* path of source file containing definition of tag */
114 /* address for locating tag in source file */
116 /* pattern for locating source line
117 * (may be NULL if not present) */
120 /* line number in source file of tag definition
121 * (may be zero if not known) */
122 unsigned long lineNumber
;
125 /* kind of tag (may by name, character, or NULL if not known) */
128 /* is tag of file-limited scope? */
131 /* miscellaneous extension fields */
133 /* number of entries in `list' */
134 unsigned short count
;
136 /* list of key value pairs */
137 tagExtensionField
*list
;
144 * FUNCTION PROTOTYPES
148 * This function must be called before calling other functions in this
149 * library. It is passed the path to the tag file to read and a (possibly
150 * null) pointer to a structure which, if not null, will be populated with
151 * information about the tag file. If successful, the function will return a
152 * handle which must be supplied to other calls to read information from the
153 * tag file, and info.status.opened will be set to true. If unsuccessful,
154 * info.status.opened will be set to false and info.status.error_number will
155 * be set to the errno value representing the system error preventing the tag
156 * file from being successfully opened.
158 extern tagFile
*tagsOpen (const char *const filePath
, tagFileInfo
*const info
);
162 * The same as tagsOpen () but you can pass here a FILE* already opened.
163 * fd won't be closed after operations.
165 extern tagFile
*tagsOpen_1 (const FILE *fd
, tagFileInfo
*const info
);
168 * This function allows the client to override the normal automatic detection
169 * of how a tag file is sorted. Permissible values for `type' are
170 * TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED. Tag files in the new extended
171 * format contain a key indicating whether or not they are sorted. However,
172 * tag files in the original format do not contain such a key even when
173 * sorted, preventing this library from taking advantage of fast binary
174 * lookups. If the client knows that such an unmarked tag file is indeed
175 * sorted (or not), it can override the automatic detection. Note that
176 * incorrect lookup results will result if a tag file is marked as sorted when
177 * it actually is not. The function will return TagSuccess if called on an
178 * open tag file or TagFailure if not.
180 extern tagResult
tagsSetSortType (tagFile
*const file
, const sortType type
);
183 * Reads the first tag in the file, if any. It is passed the handle to an
184 * opened tag file and a (possibly null) pointer to a structure which, if not
185 * null, will be populated with information about the first tag file entry.
186 * The function will return TagSuccess another tag entry is found, or
187 * TagFailure if not (i.e. it reached end of file).
189 extern tagResult
tagsFirst (tagFile
*const file
, tagEntry
*const entry
);
192 * Step to the next tag in the file, if any. It is passed the handle to an
193 * opened tag file and a (possibly null) pointer to a structure which, if not
194 * null, will be populated with information about the next tag file entry. The
195 * function will return TagSuccess another tag entry is found, or TagFailure
196 * if not (i.e. it reached end of file). It will always read the first tag in
197 * the file immediately after calling tagsOpen().
199 extern tagResult
tagsNext (tagFile
*const file
, tagEntry
*const entry
);
202 * Retrieve the value associated with the extension field for a specified key.
203 * It is passed a pointer to a structure already populated with values by a
204 * previous call to tagsNext(), tagsFind(), or tagsFindNext(), and a string
205 * containing the key of the desired extension field. If no such field of the
206 * specified key exists, the function will return null.
208 extern const char *tagsField (const tagEntry
*const entry
, const char *const key
);
211 * Find the first tag matching `name'. The structure pointed to by `entry'
212 * will be populated with information about the tag file entry. If a tag file
213 * is sorted using the C locale, a binary search algorithm is used to search
214 * the tag file, resulting in very fast tag lookups, even in huge tag files.
215 * Various options controlling the matches can be combined by bit-wise or-ing
216 * certain values together. The available values are:
219 * Tags whose leading characters match `name' will qualify.
222 * Only tags whose full lengths match `name' will qualify.
225 * Matching will be performed in a case-insenstive manner. Note that
226 * this disables binary searches of the tag file.
229 * Matching will be performed in a case-senstive manner. Note that
230 * this enables binary searches of the tag file.
232 * The function will return TagSuccess if a tag matching the name is found, or
235 extern tagResult
tagsFind (tagFile
*const file
, tagEntry
*const entry
, const char *const name
, const int options
);
238 * Find the next tag matching the name and options supplied to the most recent
239 * call to tagsFind() for the same tag file. The structure pointed to by
240 * `entry' will be populated with information about the tag file entry. The
241 * function will return TagSuccess if another tag matching the name is found,
242 * or TagFailure if not.
244 extern tagResult
tagsFindNext (tagFile
*const file
, tagEntry
*const entry
);
247 * Call tagsTerminate() at completion of reading the tag file, which will
248 * close the file and free any internal memory allocated. The function will
249 * return TagFailure is no file is currently open, TagSuccess otherwise.
251 extern tagResult
tagsClose (tagFile
*const file
);
259 /* vi:set tabstop=4 shiftwidth=4: */