File: readtags.h

package info (click to toggle)
screem 0.12.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,728 kB
  • ctags: 8,333
  • sloc: ansic: 98,234; sh: 8,278; xml: 2,278; makefile: 1,054
file content (244 lines) | stat: -rw-r--r-- 8,192 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
*   $Id: readtags.h,v 1.1 2002/12/29 14:30:46 davek Exp $
*
*   Copyright (c) 1996-2002, 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 hundreths 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

/*
*  MACROS
*/

/* Options for tagsSetSortType() */
typedef enum {
    TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED
} sortType ;

/* 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;

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 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? */
		sortType 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 */
	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,
*  info.status.opened will be set to false and info.status.error_number will
*  be set to the errno value representing the system error preventing the tag
*  file from being successfully opened.
*/
tagFile *tagsOpen (const char *filePath, tagFileInfo *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.
*/
tagResult tagsSetSortType (tagFile *file, sortType 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).
*/
tagResult tagsFirst (tagFile *file, tagEntry *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().
*/
tagResult tagsNext (tagFile *file, tagEntry *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.
*/
const char *tagsField (const tagEntry *entry, const char *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-insenstive manner. Note that
*        this disables binary searches of the tag file.
*
*    TAG_OBSERVECASE
*        Matching will be performed in a case-senstive 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.
*/
tagResult tagsFind (tagFile *file, tagEntry *entry, const char *name, 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.
*/
tagResult tagsFindNext (tagFile *file, tagEntry *entry);

/*
*  Call tagsTerminate() at completion of reading the tag file, which will
*  close the file and free any internal memory allocated. The function will
*  return TagFailure is no file is currently open, TagSuccess otherwise.
*/
tagResult tagsClose (tagFile *file);

#endif

/* vi:set tabstop=8 shiftwidth=4: */