forked from universal-ctags/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag_file.e
479 lines (408 loc) · 10.5 KB
/
tag_file.e
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
indexing
description: "Abstraction of file containing tag records"
copyright: "Copyright 2002 Darren Hiebert and others"
license: "Eiffel Forum License, version 1"
class TAG_FILE
inherit
TAG_FILE_FORMATS
TAG_FILE_SORT_TYPES
EXTERNAL_ADDRESSING
export
{NONE} all
end
creation
make
feature -- Initialization
make (nm: STRING) is
-- Create from name of existing tag file
require
name_not_empty: nm /= Void and then not nm.is_empty
do
format := Format_extended
sort_type := Sort_case_sensitive
create tag_file_info_struct.make_filled ('%U', tag_file_info_size)
create tag_entry_struct.make_filled ('%U', tag_entry_size)
handle := c_tags_open (
string_to_c (nm), string_to_c (tag_file_info_struct))
open := handle /= default_pointer
if open then
path := nm
format := c_file_format (string_to_c (tag_file_info_struct))
sort_type := c_file_sort (string_to_c (tag_file_info_struct))
program_author := string_from_c (
c_program_author (string_to_c (tag_file_info_struct)))
program_name := string_from_c (
c_program_name (string_to_c (tag_file_info_struct)))
program_url := string_from_c (
c_program_url (string_to_c (tag_file_info_struct)))
program_version := string_from_c (
c_program_version (string_to_c (tag_file_info_struct)))
else
error_number := c_file_error_number (
string_to_c (tag_file_info_struct))
error_description := string_from_c (c_strerror (error_number))
end
ensure
opened: open or else (error_number > 0 and error_description /= Void)
end
feature -- Access
path: STRING
-- Path of tag file
program_author: STRING
-- Name of author of generating program (may be null)
program_name: STRING
-- Name of program (may be void)
program_url: STRING
-- URL of distribution (may be void)
program_version: STRING
-- Program version (may be void)
item: TAG_ENTRY
-- Current tag
feature -- Status report
open: BOOLEAN
-- Is the tag file open? If this is false, then the system "errno"
-- variable may be examined to determine the cause.
error_number: INTEGER
-- Value of errno of O/S when creation of `Current' fails
error_description: STRING
-- Value of strerror(errno) of O/S when creation of `Current' fails
off: BOOLEAN
-- Is there another tag after this one?
format: INTEGER
-- Format of tag file
sort_type: INTEGER
-- Type of sorting used on file.
partial_matching: BOOLEAN
-- Should searches find tags whose whose leading characters match
-- the supplied string?
ignoring_case: BOOLEAN
-- Should searches match without regard to case?
feature -- Status setting
set_sort_type (type: INTEGER) is
-- Force sort type of file (in case automatic detection does not
-- work).
require
open: open
valid_sort_type: valid_sort_type (type)
local
return_code: INTEGER
do
return_code := c_tags_set_sort_type (handle, type)
check no_error: return_code = Tag_success end
sort_type := type
ensure
sort_type_overridden: sort_type = type
end
ignore_case is
-- Disable recognition of case for searches
require
open: open
do
ignoring_case := True
ensure
searches_ignore_case: ignoring_case
end
observe_case is
-- Enable recognition of case for searches
require
open: open
do
ignoring_case := False
ensure
searches_observe_case: not ignoring_case
end
match_partial is
-- Enable partial matching for searches
require
open: open
do
partial_matching := True
ensure
searches_match_partial: partial_matching
end
match_full is
-- Enable full matching for searches
require
open: open
do
partial_matching := False
ensure
searches_match_full: not partial_matching
end
start is
-- Move to first tag in file
require
exists: open
do
read_tag (c_tags_first (handle, string_to_c (tag_entry_struct)))
ensure
item_found: not off implies item /= Void
end
forth is
-- Advance to next tag in file
require
exists: open
another_available: not off
do
read_tag (c_tags_next (handle, string_to_c (tag_entry_struct)))
ensure
item_found: not off implies item /= Void
end
search (name: STRING) is
-- Search from beginning of file for tag matching `name'.
-- Search affected by values of `partial_matching' and
-- `ignoring_case'.
require
open: open
name_supplied: name /= Void and then not name.is_empty
do
search_name := clone (name)
read_tag (c_tags_find (handle, string_to_c (tag_entry_struct),
string_to_c (name), search_options))
ensure
match:
not off implies (item /= Void and then not item.name.is_empty)
non_partial_match:
(not off and not partial_matching)
implies item.name.count = name.count
partial_match:
(not off and partial_matching)
implies item.name.count >= name.count
case_match:
(not off and not ignoring_case) implies
name.is_equal (item.name.substring (1, name.count))
case_ignore_match:
(not off and not ignoring_case) implies
name.as_upper.is_equal (
item.name.substring (1, name.count).as_upper)
end
continue_search is
-- Continue search initiated with `search' using same parameters
-- and options.
require
open: open
not off
do
read_tag (c_tags_find_next (handle, string_to_c (tag_entry_struct)))
ensure
match:
not off implies (item /= Void and then not item.name.is_empty)
non_partial_match:
(not off and not partial_matching)
implies item.name.count = search_name.count
partial_match:
(not off and partial_matching)
implies item.name.count >= search_name.count
case_match:
(not off and not ignoring_case) implies
search_name.is_equal (
item.name.substring (1, search_name.count))
case_ignore_match:
(not off and not ignoring_case) implies
search_name.as_upper.is_equal (
item.name.substring (1, search_name.count).as_upper)
end
close is
-- Close tag file
require
open: open
local
return_code: INTEGER
do
return_code := c_tags_close (handle)
check no_failure: return_code = Tag_success end
handle := default_pointer
ensure
handle_reset: handle = default_pointer
end
feature {NONE} -- Implementation
handle: POINTER
-- Handle to tag file
tag_file_info_struct: STRING
-- Buffer for tagFileInfo C structure
tag_entry_struct: STRING
-- Buffer for tagEntry C structure
search_name: STRING
-- Name used in `search'
search_options: INTEGER is
-- Bit representation of search options
do
if partial_matching then
Result := Tag_partial_match
end
if ignoring_case then
Result := Result + Tag_ignore_case
end
end
read_tag (return_code: INTEGER) is
do
if return_code = Tag_success then
create item.make_from_c (tag_entry_struct)
off := False
else
off := True
item := Void
end
end
feature {NONE} -- Externals
c_strerror (errnum: INTEGER): POINTER is
external
"C (int): char* | <errno.h>"
alias
"strerror"
end
tag_file_info_size: INTEGER is
external
"C [macro %"readtags.h%"] (): long"
alias
"sizeof (tagFileInfo)"
end
tag_entry_size: INTEGER is
external
"C [macro %"readtags.h%"] (): long"
alias
"sizeof (tagEntry)"
end
Tag_success: INTEGER is
external
"C [macro %"readtags.h%"] (): int"
alias
"TagSuccess"
end
Tag_failure: INTEGER is
external
"C [macro %"readtags.h%"] (): int"
alias
"TagFailure"
end
Tag_unsorted: INTEGER is
external
"C [macro %"readtags.h%"] (): int"
alias
"TAG_UNSORTED"
end
Tag_sorted: INTEGER is
external
"C [macro %"readtags.h%"] (): int"
alias
"TAG_SORTED"
end
Tag_fold_sorted: INTEGER is
external
"C [macro %"readtags.h%"] (): int"
alias
"TAG_FOLDSORTED"
end
Tag_partial_match: INTEGER is
external
"C [macro %"readtags.h%"] (): int"
alias
"TAG_PARTIALMATCH"
end
Tag_ignore_case: INTEGER is
external
"C [macro %"readtags.h%"] (): int"
alias
"TAG_IGNORECASE"
end
c_tags_open (file_path, info: POINTER): POINTER is
-- extern tagFile *tagsOpen (const char *filePath,
-- tagFileInfo *info);
external
"C (const char*, tagFileInfo*): tagFile* | %"readtags.h%""
alias
"tagsOpen"
end
c_tags_set_sort_type (h: POINTER; type: INTEGER): INTEGER is
-- extern tagResult tagsSetSortType (tagFile *file, sortType type);
external
"C (tagFile*, sortType): tagResult | %"readtags.h%""
alias
"tagsSetSortType"
end
c_tags_first (h, entry: POINTER): INTEGER is
external
"C (tagFile*, tagEntry*): tagResult | %"readtags.h%""
alias
"tagsFirst"
end
c_tags_next (h, entry: POINTER): INTEGER is
external
"C (tagFile*, tagEntry*): tagResult | %"readtags.h%""
alias
"tagsNext"
end
c_tags_find (h, entry, name: POINTER; options: INTEGER): INTEGER is
-- extern tagResult tagsFind (tagFile *file, tagEntry *entry,
-- const char *name, int options);
external
"C (tagFile*, tagEntry*, const char*, int): tagResult | %"readtags.h%""
alias
"tagsFind"
end
c_tags_find_next (h, entry: POINTER): INTEGER is
-- extern tagResult tagsFindNext (tagFile *file, tagEntry *entry);
external
"C (tagFile*, tagEntry*): tagResult | %"readtags.h%""
alias
"tagsFindNext"
end
c_tags_close (h: POINTER): INTEGER is
-- extern tagResult tagsClose (tagFile *file);
external
"C (tagFile*): tagResult | %"readtags.h%""
alias
"tagsClose"
end
c_file_opened (p: POINTER): BOOLEAN is
external
"C [struct %"readtags.h%"] (tagFileInfo): int"
alias
"status.opened"
end
c_file_error_number (p: POINTER): INTEGER is
external
"C [struct %"readtags.h%"] (tagFileInfo): int"
alias
"status.error_number"
end
c_file_format (p: POINTER): INTEGER is
external
"C [struct %"readtags.h%"] (tagFileInfo): short"
alias
"file.format"
end
c_file_sort (p: POINTER): INTEGER is
external
"C [struct %"readtags.h%"] (tagFileInfo): short"
alias
"file.sort"
end
c_program_author (p: POINTER): POINTER is
external
"C [struct %"readtags.h%"] (tagFileInfo): const char*"
alias
"program.author"
end
c_program_name (p: POINTER): POINTER is
external
"C [struct %"readtags.h%"] (tagFileInfo): const char*"
alias
"program.name"
end
c_program_url (p: POINTER): POINTER is
external
"C [struct %"readtags.h%"] (tagFileInfo): const char*"
alias
"program.url"
end
c_program_version (p: POINTER): POINTER is
external
"C [struct %"readtags.h%"] (tagFileInfo): const char*"
alias
"program.version"
end
invariant
valid_format: valid_format (format)
valid_sort_type: valid_sort_type (sort_type)
end