1 |
/* |
/* |
2 |
* Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002 |
* Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2005 |
3 |
* Tama Communications Corporation |
* Tama Communications Corporation |
4 |
* |
* |
5 |
* This file is part of GNU GLOBAL. |
* This file is part of GNU GLOBAL. |
37 |
#include "gtagsop.h" |
#include "gtagsop.h" |
38 |
#include "makepath.h" |
#include "makepath.h" |
39 |
#include "gpathop.h" |
#include "gpathop.h" |
40 |
|
#include "strbuf.h" |
41 |
#include "strlimcpy.h" |
#include "strlimcpy.h" |
42 |
|
|
43 |
static DBOP *dbop; |
static DBOP *dbop; |
47 |
static int created; |
static int created; |
48 |
|
|
49 |
/* |
/* |
50 |
|
* get_flag: get flag value |
51 |
|
*/ |
52 |
|
static const char * |
53 |
|
get_flag(DBOP *dbop) |
54 |
|
{ |
55 |
|
int size; |
56 |
|
const char *dat = dbop_lastdat(dbop, &size); |
57 |
|
const char *flag = ""; |
58 |
|
/* |
59 |
|
* Dat format is like follows. |
60 |
|
* dat 'xxxxxxx\0ffff\0' |
61 |
|
* (data) (flag) |
62 |
|
*/ |
63 |
|
if (dat) { |
64 |
|
int i = strlen(dat) + 1; |
65 |
|
if (size > i) |
66 |
|
flag = dat + i; |
67 |
|
} |
68 |
|
return flag; |
69 |
|
} |
70 |
|
/* |
71 |
* gpath_open: open gpath tag file |
* gpath_open: open gpath tag file |
72 |
* |
* |
73 |
* i) dbpath GTAGSDBPATH |
* i) dbpath GTAGSDBPATH |
93 |
if (mode == 1) |
if (mode == 1) |
94 |
_nextkey = 1; |
_nextkey = 1; |
95 |
else { |
else { |
96 |
const char *p = dbop_get(dbop, NEXTKEY); |
const char *path = dbop_get(dbop, NEXTKEY); |
97 |
|
|
98 |
if (p == NULL) |
if (path == NULL) |
99 |
die("nextkey not found in GPATH."); |
die("nextkey not found in GPATH."); |
100 |
_nextkey = atoi(p); |
_nextkey = atoi(path); |
101 |
} |
} |
102 |
opened = 1; |
opened = 1; |
103 |
return 0; |
return 0; |
106 |
* gpath_put: put path name |
* gpath_put: put path name |
107 |
* |
* |
108 |
* i) path path name |
* i) path path name |
109 |
|
* i) other 0: source file, 1: other file |
110 |
*/ |
*/ |
111 |
void |
void |
112 |
gpath_put(const char *path) |
gpath_put(const char *path, int other) |
113 |
{ |
{ |
114 |
char fid[32]; |
char fid[32]; |
115 |
|
STATIC_STRBUF(sb); |
116 |
|
|
117 |
assert(opened == 1); |
assert(opened == 1); |
118 |
if (_mode == 1 && created) |
if (_mode == 1 && created) |
119 |
return; |
return; |
120 |
if (dbop_get(dbop, path) != NULL) |
if (dbop_get(dbop, path) != NULL) |
121 |
return; |
return; |
122 |
|
/* |
123 |
|
* generate new file id for the path. |
124 |
|
*/ |
125 |
snprintf(fid, sizeof(fid), "%d", _nextkey++); |
snprintf(fid, sizeof(fid), "%d", _nextkey++); |
126 |
dbop_put(dbop, path, fid); |
/* |
127 |
dbop_put(dbop, fid, path); |
* path => fid mapping. |
128 |
|
*/ |
129 |
|
strbuf_clear(sb); |
130 |
|
strbuf_puts0(sb, fid); |
131 |
|
if (other) |
132 |
|
strbuf_puts0(sb, "o"); |
133 |
|
dbop_put_withlen(dbop, path, strbuf_value(sb), strbuf_getlen(sb)); |
134 |
|
/* |
135 |
|
* fid => path mapping. |
136 |
|
*/ |
137 |
|
strbuf_clear(sb); |
138 |
|
strbuf_puts0(sb, path); |
139 |
|
if (other) |
140 |
|
strbuf_puts0(sb, "o"); |
141 |
|
dbop_put_withlen(dbop, fid, strbuf_value(sb), strbuf_getlen(sb)); |
142 |
} |
} |
143 |
/* |
/* |
144 |
* gpath_path2fid: convert path into id |
* gpath_path2fid: convert path into id |
145 |
* |
* |
146 |
* i) path path name |
* i) path path name |
147 |
|
* o) type path type |
148 |
|
* 0: source file |
149 |
|
* 1: other file |
150 |
* r) file id |
* r) file id |
151 |
*/ |
*/ |
152 |
const char * |
const char * |
153 |
gpath_path2fid(const char *path) |
gpath_path2fid(const char *path, int *type) |
154 |
{ |
{ |
155 |
|
const char *fid = dbop_get(dbop, path); |
156 |
assert(opened == 1); |
assert(opened == 1); |
157 |
return dbop_get(dbop, path); |
if (fid && type) { |
158 |
|
char *flag = get_flag(dbop); |
159 |
|
*type = (*flag == 'o') ? 1 : 0; |
160 |
|
|
161 |
|
} |
162 |
|
return fid; |
163 |
} |
} |
164 |
/* |
/* |
165 |
* gpath_fid2path: convert id into path |
* gpath_fid2path: convert id into path |
166 |
* |
* |
167 |
* i) fid file id |
* i) fid file id |
168 |
|
* o) type path type |
169 |
|
* 0: source file |
170 |
|
* 1: other file |
171 |
* r) path name |
* r) path name |
172 |
*/ |
*/ |
173 |
const char * |
const char * |
174 |
gpath_fid2path(const char *fid) |
gpath_fid2path(const char *fid, int *type) |
175 |
{ |
{ |
176 |
return dbop_get(dbop, fid); |
const char *path = dbop_get(dbop, fid); |
177 |
|
assert(opened == 1); |
178 |
|
if (path && type) { |
179 |
|
char *flag = get_flag(dbop); |
180 |
|
*type = (*flag == 'o') ? 1 : 0; |
181 |
|
} |
182 |
|
return path; |
183 |
} |
} |
184 |
/* |
/* |
185 |
* gpath_delete: delete specified path record |
* gpath_delete: delete specified path record |
243 |
static DBOP *gfind_dbop; |
static DBOP *gfind_dbop; |
244 |
static int gfind_opened; |
static int gfind_opened; |
245 |
static int gfind_first; |
static int gfind_first; |
246 |
|
static int gfind_other; |
247 |
static char gfind_prefix[MAXPATHLEN+1]; |
static char gfind_prefix[MAXPATHLEN+1]; |
248 |
|
|
249 |
/* |
/* |
250 |
* gfind_open: start iterator using GPATH. |
* gfind_open: start iterator using GPATH. |
251 |
*/ |
*/ |
252 |
void |
void |
253 |
gfind_open(const char *dbpath, const char *local) |
gfind_open(const char *dbpath, const char *local, int other) |
254 |
{ |
{ |
255 |
assert(gfind_opened == 0); |
assert(gfind_opened == 0); |
256 |
assert(gfind_first == 0); |
assert(gfind_first == 0); |
260 |
strlimcpy(gfind_prefix, (local) ? local : "./", sizeof(gfind_prefix)); |
strlimcpy(gfind_prefix, (local) ? local : "./", sizeof(gfind_prefix)); |
261 |
gfind_opened = 1; |
gfind_opened = 1; |
262 |
gfind_first = 1; |
gfind_first = 1; |
263 |
|
gfind_other = other; |
264 |
} |
} |
265 |
/* |
/* |
266 |
* gfind_read: read path without GPATH. |
* gfind_read: read path using GPATH. |
267 |
* |
* |
268 |
* r) path |
* r) path |
269 |
*/ |
*/ |
270 |
const char * |
const char * |
271 |
gfind_read(void) |
gfind_read(void) |
272 |
{ |
{ |
273 |
|
const char *path, *flag; |
274 |
|
|
275 |
assert(gfind_opened == 1); |
assert(gfind_opened == 1); |
276 |
if (gfind_first) { |
for (;;) { |
277 |
gfind_first = 0; |
if (gfind_first) { |
278 |
return dbop_first(gfind_dbop, gfind_prefix, NULL, DBOP_KEY | DBOP_PREFIX); |
gfind_first = 0; |
279 |
|
path = dbop_first(gfind_dbop, gfind_prefix, NULL, DBOP_KEY | DBOP_PREFIX); |
280 |
|
} else { |
281 |
|
path = dbop_next(gfind_dbop); |
282 |
|
} |
283 |
|
if (path == NULL || gfind_other) |
284 |
|
break; |
285 |
|
/* |
286 |
|
* if gfind_other == 0, return only source files. |
287 |
|
* *flag == 'o' means 'other files' like README. |
288 |
|
*/ |
289 |
|
flag = get_flag(gfind_dbop); |
290 |
|
if (*flag != 'o') |
291 |
|
break; |
292 |
} |
} |
293 |
return dbop_next(gfind_dbop); |
return path; |
294 |
} |
} |
295 |
/* |
/* |
296 |
* gfind_close: close iterator. |
* gfind_close: close iterator. |