18 static int tag_load(void)
26 tagpath
= getenv("TAGPATH") ? getenv("TAGPATH") : "tags";
27 if ((fd
= open(tagpath
, O_RDONLY
)) < 0)
30 while ((nr
= read(fd
, buf
, sizeof(buf
))) > 0)
31 sbuf_mem(sb
, buf
, nr
);
33 taglen
= sbuf_len(sb
);
45 static char *copypart(char *dst
, int dstlen
, char *src
)
49 while (*end
&& *end
!= '\t' && *end
!= '\n')
53 memcpy(dst
, src
, len
);
55 return *end
? end
+ 1 : end
;
58 static char *tag_next(char *s
, int dir
)
61 if ((s
= strchr(s
+ 1, '\n')) != NULL
)
64 if (dir
< 0 && s
> tag
) {
66 while (s
> tag
&& s
[-1] != '\n')
73 int tag_find(char *name
, int *pos
, int dir
, char *path
, int pathlen
, char *cmd
, int cmdlen
)
76 int len
= strlen(name
);
81 s
= dir
!= 0 ? tag_next(tag
+ *pos
, dir
) : tag
+ *pos
;
83 if (!strncmp(name
, s
, len
) && s
[len
] == '\t') {
84 char *r
= copypart(path
, pathlen
, s
+ len
+ 1);
85 copypart(cmd
, cmdlen
, r
);