-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctags.c
50 lines (41 loc) · 807 Bytes
/
ctags.c
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mem.h"
#include "ctags.h"
bool ctag_search(const char *ident, struct ctag_result *tag)
{
FILE *f = fopen("tags", "r");
if(!f)
return false;
bool found = false;
char buf[256];
while(fgets(buf, sizeof buf, f)){
char *end = strchr(buf, '\t');
if(!end || !end[1])
continue;
*end = '\0';
if(!strcmp(buf, ident)){
char *fname = end + 1;
end = strchr(end + 1, '\t');
if(!end || !end[1])
continue;
*end = '\0';
char *nl = strchr(end + 1, '\n');
if(nl)
*nl = '\0';
tag->fname = ustrdup(fname);
tag->line = ustrdup(end + 1);
found = true;
break;
}
}
fclose(f);
return found;
}
void ctag_free(struct ctag_result *r)
{
free(r->fname);
free(r->line);
memset(r, 0, sizeof *r);
}