/* * Copyright (c) 1996-2003, Darren Hiebert * * This source code is released for the public domain. * * This file defines the public interface for looking up tag entries in tag * files. * * The functions defined in this interface are intended to provide tag file * support to a software tool. The tag lookups provided are sufficiently fast * enough to permit opening a sorted tag file, searching for a matching tag, * then closing the tag file each time a tag is looked up (search times are * on the order of hundredths of a second, even for huge tag files). This is * the recommended use of this library for most tool applications. Adhering * to this approach permits a user to regenerate a tag file at will without * the tool needing to detect and resynchronize with changes to the tag file. * Even for an unsorted 24MB tag file, tag searches take about one second. */ #ifndef READTAGS_H #define READTAGS_H #ifdef __cplusplus extern "C" { #endif /* * MACROS */ /* Options for tagsSetSortType() */ typedef enum { TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED } tagSortType ; /* For source code level compatibility, sortType is defined here. * Define TAG_NO_COMPAT_SORT_TYPE if you want to avoid namespace pollution. */ #ifndef TAG_NO_COMPAT_SORT_TYPE #define sortType tagSortType #endif /* Options for tagsFind() */ #define TAG_FULLMATCH 0x0 #define TAG_PARTIALMATCH 0x1 #define TAG_OBSERVECASE 0x0 #define TAG_IGNORECASE 0x2 /* * DATA DECLARATIONS */ typedef enum { TagFailure = 0, TagSuccess = 1 } tagResult; typedef enum { TagErrnoUnexpectedSortedMethod = -1, /* Unexpected sorted method */ TagErrnoUnexpectedFormat = -2, /* Unexpected format number */ TagErrnoUnexpectedLineno = -3, /* Unexpected value for line: field * (Zero or a positive integer is expected.) */ TagErrnoInvalidArgument = -4, /* Unexpected argument passed to the API * function */ TagErrnoFileMaybeTooBig = -5, /* Maybe the tags file is too big */ } tagErrno; struct sTagFile; typedef struct sTagFile tagFile; /* This structure contains information about the tag file. */ typedef struct { struct { /* was the tag file successfully opened? */ int opened; /* errno value or tagErrno typed value when 'opened' is false */ int error_number; } status; /* information about the structure of the tag file */ struct { /* format of tag file (1 = original, 2 = extended) */ short format; /* how is the tag file sorted? */ tagSortType sort; } file; /* information about the program which created this tag file */ struct { /* name of author of generating program (may be null) */ const char *author; /* name of program (may be null) */ const char *name; /* URL of distribution (may be null) */ const char *url; /* program version (may be null) */ const char *version; } program; } tagFileInfo; /* This structure contains information about an extension field for a tag. * These exist at the end of the tag in the form "key:value"). */ typedef struct { /* the key of the extension field */ const char *key; /* the value of the extension field (may be an empty string) */ const char *value; } tagExtensionField; /* This structure contains information about a specific tag. */ typedef struct { /* name of tag */ const char *name; /* path of source file containing definition of tag. For a broken tags file, this can be NULL. */ const char *file; /* address for locating tag in source file */ struct { /* pattern for locating source line * (may be NULL if not present) */ const char *pattern; /* line number in source file of tag definition * (may be zero if not known) */ unsigned long lineNumber; } address; /* kind of tag (may by name, character, or NULL if not known) */ const char *kind; /* is tag of file-limited scope? */ short fileScope; /* miscellaneous extension fields */ struct { /* number of entries in `list' */ unsigned short count; /* list of key value pairs */ tagExtensionField *list; } fields; } tagEntry; /* * FUNCTION PROTOTYPES */ /* * This function must be called before calling other functions in this * library. It is passed the path to the tag file to read and a (possibly * null) pointer to a structure which, if not null, will be populated with * information about the tag file. If successful, the function will return a * handle which must be supplied to other calls to read information from the * tag file, and info.status.opened will be set to true. * If unsuccessful, the function will return NULL, and * info.status.opened will be set to false and * info.status.error_number will be set to either the errno value * representing the system error preventing the tag file from being * successfully opened, or the tagErrno typed value representing the * library level error. The error_number will be ENOMEM if the memory * allocation for the handle is failed. */ extern tagFile *tagsOpen (const char *const filePath, tagFileInfo *const info); /* * This function allows the client to override the normal automatic detection * of how a tag file is sorted. Permissible values for `type' are * TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED. Tag files in the new extended * format contain a key indicating whether or not they are sorted. However, * tag files in the original format do not contain such a key even when * sorted, preventing this library from taking advantage of fast binary * lookups. If the client knows that such an unmarked tag file is indeed * sorted (or not), it can override the automatic detection. Note that * incorrect lookup results will result if a tag file is marked as sorted when * it actually is not. The function will return TagSuccess if called on an * open tag file or TagFailure if not. */ extern tagResult tagsSetSortType (tagFile *const file, const tagSortType type); /* * Reads the first tag in the file, if any. It is passed the handle to an * opened tag file and a (possibly null) pointer to a structure which, if not * null, will be populated with information about the first tag file entry. * The function will return TagSuccess another tag entry is found, or * TagFailure if not (i.e. it reached end of file). */ extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry); /* * Step to the next tag in the file, if any. It is passed the handle to an * opened tag file and a (possibly null) pointer to a structure which, if not * null, will be populated with information about the next tag file entry. The * function will return TagSuccess another tag entry is found, or TagFailure * if not (i.e. it reached end of file). It will always read the first tag in * the file immediately after calling tagsOpen(). */ extern tagResult tagsNext (tagFile *const file, tagEntry *const entry); /* * Retrieve the value associated with the extension field for a specified key. * It is passed a pointer to a structure already populated with values by a * previous call to tagsNext(), tagsFind(), or tagsFindNext(), and a string * containing the key of the desired extension field. If no such field of the * specified key exists, the function will return null. */ extern const char *tagsField (const tagEntry *const entry, const char *const key); /* * Find the first tag matching `name'. The structure pointed to by `entry' * will be populated with information about the tag file entry. If a tag file * is sorted using the C locale, a binary search algorithm is used to search * the tag file, resulting in very fast tag lookups, even in huge tag files. * Various options controlling the matches can be combined by bit-wise or-ing * certain values together. The available values are: * * TAG_PARTIALMATCH * Tags whose leading characters match `name' will qualify. * * TAG_FULLMATCH * Only tags whose full lengths match `name' will qualify. * * TAG_IGNORECASE * Matching will be performed in a case-insensitive manner. Note that * this disables binary searches of the tag file. * * TAG_OBSERVECASE * Matching will be performed in a case-sensitive manner. Note that * this enables binary searches of the tag file. * * The function will return TagSuccess if a tag matching the name is found, or * TagFailure if not. */ extern tagResult tagsFind (tagFile *const file, tagEntry *const entry, const char *const name, const int options); /* * Find the next tag matching the name and options supplied to the most recent * call to tagsFind() for the same tag file. The structure pointed to by * `entry' will be populated with information about the tag file entry. The * function will return TagSuccess if another tag matching the name is found, * or TagFailure if not. */ extern tagResult tagsFindNext (tagFile *const file, tagEntry *const entry); /* * Does the same as tagsFirst(), but is specialized to pseudo tags. * If tagFileInfo doesn't contain pseudo tags you are interested in, read * them sequentially with this function and tagsNextPseudoTag(). */ extern tagResult tagsFirstPseudoTag (tagFile *const file, tagEntry *const entry); /* * Does the same as tagsNext(), but is specialized to pseudo tags. Use with * tagsFirstPseudoTag(). */ extern tagResult tagsNextPseudoTag (tagFile *const file, tagEntry *const entry); /* * Call tagsClose() at completion of reading the tag file, which will * close the file and free any internal memory allocated. The function will * return TagFailure if no file is currently open, TagSuccess otherwise. */ extern tagResult tagsClose (tagFile *const file); /* * Get the error status set in the last API call. * Much of the API functions return TagFailure because (1) no tag is * found, or (2) an error occurs. tagsGetErrno() is for distinguishing * (1) or (2). This function will return 0 for (1). The errno value * representing the system error or tagErrno value for (2). * * This function does not deal with the results of tagsOpen(), * tagsClose(), and tagsField(). */ extern int tagsGetErrno (tagFile *const file); #ifdef __cplusplus }; #endif #endif