File indexing completed on 2024-05-05 05:51:39
0001 /* 0002 * 0003 * SPDX-FileCopyrightText: 1996-2003 Darren Hiebert <dhiebert at users dot sourceforge dot net> 0004 * 0005 * This source code is released for the public domain. 0006 * 0007 * This file defines the public interface for looking up tag entries in tag 0008 * files. 0009 * 0010 * The functions defined in this interface are intended to provide tag file 0011 * support to a software tool. The tag lookups provided are sufficiently fast 0012 * enough to permit opening a sorted tag file, searching for a matching tag, 0013 * then closing the tag file each time a tag is looked up (search times are 0014 * on the order of hundredths of a second, even for huge tag files). This is 0015 * the recommended use of this library for most tool applications. Adhering 0016 * to this approach permits a user to regenerate a tag file at will without 0017 * the tool needing to detect and resynchronize with changes to the tag file. 0018 * Even for an unsorted 24MB tag file, tag searches take about one second. 0019 */ 0020 #pragma once 0021 0022 #ifdef __cplusplus 0023 extern "C" { 0024 #endif 0025 0026 /* 0027 * MACROS 0028 */ 0029 0030 /* Options for tagsSetSortType() */ 0031 typedef enum { TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED } sortType; 0032 0033 /* Options for tagsFind() */ 0034 #define TAG_FULLMATCH 0x0 0035 #define TAG_PARTIALMATCH 0x1 0036 0037 #define TAG_OBSERVECASE 0x0 0038 #define TAG_IGNORECASE 0x2 0039 0040 /* 0041 * DATA DECLARATIONS 0042 */ 0043 0044 typedef enum { TagFailure = 0, TagSuccess = 1 } tagResult; 0045 0046 struct sTagFile; 0047 0048 typedef struct sTagFile tagFile; 0049 0050 /* This structure contains information about the tag file. */ 0051 typedef struct { 0052 struct { 0053 /* was the tag file successfully opened? */ 0054 int opened; 0055 0056 /* errno value when 'opened' is false */ 0057 int error_number; 0058 } status; 0059 0060 /* information about the structure of the tag file */ 0061 struct { 0062 /* format of tag file (1 = original, 2 = extended) */ 0063 short format; 0064 0065 /* how is the tag file sorted? */ 0066 sortType sort; 0067 } file; 0068 0069 /* information about the program which created this tag file */ 0070 struct { 0071 /* name of author of generating program (may be null) */ 0072 const char *author; 0073 0074 /* name of program (may be null) */ 0075 const char *name; 0076 0077 /* URL of distribution (may be null) */ 0078 const char *url; 0079 0080 /* program version (may be null) */ 0081 const char *version; 0082 } program; 0083 0084 } tagFileInfo; 0085 0086 /* This structure contains information about an extension field for a tag. 0087 * These exist at the end of the tag in the form "key:value"). 0088 */ 0089 typedef struct { 0090 /* the key of the extension field */ 0091 const char *key; 0092 0093 /* the value of the extension field (may be an empty string) */ 0094 const char *value; 0095 0096 } tagExtensionField; 0097 0098 /* This structure contains information about a specific tag. */ 0099 typedef struct { 0100 /* name of tag */ 0101 const char *name; 0102 0103 /* path of source file containing definition of tag */ 0104 const char *file; 0105 0106 /* address for locating tag in source file */ 0107 struct { 0108 /* pattern for locating source line 0109 * (may be NULL if not present) */ 0110 const char *pattern; 0111 0112 /* line number in source file of tag definition 0113 * (may be zero if not known) */ 0114 unsigned long lineNumber; 0115 } address; 0116 0117 /* kind of tag (may by name, character, or NULL if not known) */ 0118 const char *kind; 0119 0120 /* is tag of file-limited scope? */ 0121 short fileScope; 0122 0123 /* miscellaneous extension fields */ 0124 struct { 0125 /* number of entries in `list' */ 0126 unsigned short count; 0127 0128 /* list of key value pairs */ 0129 tagExtensionField *list; 0130 } fields; 0131 0132 } tagEntry; 0133 0134 /* 0135 * FUNCTION PROTOTYPES 0136 */ 0137 0138 /* 0139 * This function must be called before calling other functions in this 0140 * library. It is passed the path to the tag file to read and a (possibly 0141 * null) pointer to a structure which, if not null, will be populated with 0142 * information about the tag file. If successful, the function will return a 0143 * handle which must be supplied to other calls to read information from the 0144 * tag file, and info.status.opened will be set to true. If unsuccessful, 0145 * info.status.opened will be set to false and info.status.error_number will 0146 * be set to the errno value representing the system error preventing the tag 0147 * file from being successfully opened. 0148 */ 0149 extern tagFile *tagsOpen(const char *const filePath, tagFileInfo *const info); 0150 0151 /* 0152 * This function allows the client to override the normal automatic detection 0153 * of how a tag file is sorted. Permissible values for `type' are 0154 * TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED. Tag files in the new extended 0155 * format contain a key indicating whether or not they are sorted. However, 0156 * tag files in the original format do not contain such a key even when 0157 * sorted, preventing this library from taking advantage of fast binary 0158 * lookups. If the client knows that such an unmarked tag file is indeed 0159 * sorted (or not), it can override the automatic detection. Note that 0160 * incorrect lookup results will result if a tag file is marked as sorted when 0161 * it actually is not. The function will return TagSuccess if called on an 0162 * open tag file or TagFailure if not. 0163 */ 0164 extern tagResult tagsSetSortType(tagFile *const file, const sortType type); 0165 0166 /* 0167 * Reads the first tag in the file, if any. It is passed the handle to an 0168 * opened tag file and a (possibly null) pointer to a structure which, if not 0169 * null, will be populated with information about the first tag file entry. 0170 * The function will return TagSuccess another tag entry is found, or 0171 * TagFailure if not (i.e. it reached end of file). 0172 */ 0173 extern tagResult tagsFirst(tagFile *const file, tagEntry *const entry); 0174 0175 /* 0176 * Step to the next tag in the file, if any. It is passed the handle to an 0177 * opened tag file and a (possibly null) pointer to a structure which, if not 0178 * null, will be populated with information about the next tag file entry. The 0179 * function will return TagSuccess another tag entry is found, or TagFailure 0180 * if not (i.e. it reached end of file). It will always read the first tag in 0181 * the file immediately after calling tagsOpen(). 0182 */ 0183 extern tagResult tagsNext(tagFile *const file, tagEntry *const entry); 0184 0185 /* 0186 * Retrieve the value associated with the extension field for a specified key. 0187 * It is passed a pointer to a structure already populated with values by a 0188 * previous call to tagsNext(), tagsFind(), or tagsFindNext(), and a string 0189 * containing the key of the desired extension field. If no such field of the 0190 * specified key exists, the function will return null. 0191 */ 0192 extern const char *tagsField(const tagEntry *const entry, const char *const key); 0193 0194 /* 0195 * Find the first tag matching `name'. The structure pointed to by `entry' 0196 * will be populated with information about the tag file entry. If a tag file 0197 * is sorted using the C locale, a binary search algorithm is used to search 0198 * the tag file, resulting in very fast tag lookups, even in huge tag files. 0199 * Various options controlling the matches can be combined by bit-wise or-ing 0200 * certain values together. The available values are: 0201 * 0202 * TAG_PARTIALMATCH 0203 * Tags whose leading characters match `name' will qualify. 0204 * 0205 * TAG_FULLMATCH 0206 * Only tags whose full lengths match `name' will qualify. 0207 * 0208 * TAG_IGNORECASE 0209 * Matching will be performed in a case-insensitive manner. Note that 0210 * this disables binary searches of the tag file. 0211 * 0212 * TAG_OBSERVECASE 0213 * Matching will be performed in a case-sensitive manner. Note that 0214 * this enables binary searches of the tag file. 0215 * 0216 * The function will return TagSuccess if a tag matching the name is found, or 0217 * TagFailure if not. 0218 */ 0219 extern tagResult tagsFind(tagFile *const file, tagEntry *const entry, const char *const name, const int options); 0220 0221 /* 0222 * Find the next tag matching the name and options supplied to the most recent 0223 * call to tagsFind() for the same tag file. The structure pointed to by 0224 * `entry' will be populated with information about the tag file entry. The 0225 * function will return TagSuccess if another tag matching the name is found, 0226 * or TagFailure if not. 0227 */ 0228 extern tagResult tagsFindNext(tagFile *const file, tagEntry *const entry); 0229 0230 /* 0231 * Call tagsTerminate() at completion of reading the tag file, which will 0232 * close the file and free any internal memory allocated. The function will 0233 * return TagFailure is no file is currently open, TagSuccess otherwise. 0234 */ 0235 extern tagResult tagsClose(tagFile *const file); 0236 0237 #ifdef __cplusplus 0238 } 0239 #endif 0240 0241 /* vi:set tabstop=8 shiftwidth=4: */