1 |
/* |
/* |
2 |
* Copyright (c) 1996, 1997, 1998, 1999 |
* Copyright (c) 1996, 1997, 1998, 1999 |
3 |
* Shigio Yamaguchi. All rights reserved. |
* Shigio Yamaguchi. All rights reserved. |
4 |
* Copyright (c) 1999, 2000 |
* Copyright (c) 1999, 2000, 2001 |
5 |
* Tama Communications Corporation. All rights reserved. |
* Tama Communications Corporation. All rights reserved. |
6 |
* |
* |
7 |
* This file is part of GNU GLOBAL. |
* This file is part of GNU GLOBAL. |
49 |
/* |
/* |
50 |
* gpath_open: open gpath tag file |
* gpath_open: open gpath tag file |
51 |
* |
* |
52 |
|
* i) dbpath GTAGSDBPATH |
53 |
* i) mode 0: read only |
* i) mode 0: read only |
54 |
* 1: create |
* 1: create |
55 |
* 2: modify |
* 2: modify |
56 |
|
* i) flags DBOP_POSTGRES |
57 |
* r) 0: normal |
* r) 0: normal |
58 |
* -1: error |
* -1: error |
59 |
*/ |
*/ |
60 |
int |
int |
61 |
gpath_open(dbpath, mode) |
gpath_open(dbpath, mode, flags) |
62 |
const char *dbpath; |
const char *dbpath; |
63 |
int mode; |
int mode; |
64 |
|
int flags; |
65 |
{ |
{ |
66 |
char *p; |
char *p; |
67 |
|
|
72 |
_mode = mode; |
_mode = mode; |
73 |
if (mode == 1 && created) |
if (mode == 1 && created) |
74 |
mode = 0; |
mode = 0; |
75 |
dbop = dbop_open(makepath(dbpath, dbname(GPATH), NULL), mode, 0644, 0); |
p = strdup(makepath(dbpath, dbname(GPATH), NULL)); |
76 |
|
if (p == NULL) |
77 |
|
die("short of memory."); |
78 |
|
dbop = dbop_open(p, mode, 0644, flags); |
79 |
|
free(p); |
80 |
if (dbop == NULL) |
if (dbop == NULL) |
81 |
return -1; |
return -1; |
82 |
if (mode == 1) |
if (mode == 1) |
98 |
gpath_put(path) |
gpath_put(path) |
99 |
const char *path; |
const char *path; |
100 |
{ |
{ |
101 |
char buf[10]; |
char fid[32]; |
102 |
|
|
103 |
assert(opened == 1); |
assert(opened == 1); |
104 |
if (_mode == 1 && created) |
if (_mode == 1 && created) |
105 |
return; |
return; |
106 |
if (dbop_get(dbop, path) != NULL) |
if (dbop_get(dbop, path) != NULL) |
107 |
return; |
return; |
108 |
snprintf(buf, sizeof(buf), "%d", _nextkey++); |
snprintf(fid, sizeof(fid), "%d", _nextkey++); |
109 |
dbop_put(dbop, path, buf, 0); |
#ifdef USE_POSTGRES |
110 |
dbop_put(dbop, buf, path, 0); |
if (dbop->openflags & DBOP_POSTGRES) { |
111 |
|
dbop_put(dbop, path, fid, fid); |
112 |
|
} else { |
113 |
|
#endif |
114 |
|
dbop_put(dbop, path, fid, "0"); |
115 |
|
dbop_put(dbop, fid, path, "0"); |
116 |
|
#ifdef USE_POSTGRES |
117 |
|
} |
118 |
|
#endif |
119 |
} |
} |
120 |
/* |
/* |
121 |
* gpath_path2ids: convert path into id |
* gpath_path2fid: convert path into id |
122 |
* |
* |
123 |
* i) path path name |
* i) path path name |
124 |
* r) path id |
* r) file id |
125 |
*/ |
*/ |
126 |
char * |
char * |
127 |
gpath_path2ids(path) |
gpath_path2fid(path) |
128 |
const char *path; |
const char *path; |
129 |
{ |
{ |
130 |
char *id; |
char *id; |
133 |
return dbop_get(dbop, path); |
return dbop_get(dbop, path); |
134 |
} |
} |
135 |
/* |
/* |
136 |
* gpath_ids2path: convert id into path |
* gpath_fid2path: convert id into path |
137 |
* |
* |
138 |
* i) ids path id |
* i) fid file id |
139 |
* r) path name |
* r) path name |
140 |
*/ |
*/ |
141 |
char * |
char * |
142 |
gpath_ids2path(ids) |
gpath_fid2path(fid) |
143 |
const char *ids; |
const char *fid; |
144 |
{ |
{ |
145 |
return dbop_get(dbop, ids); |
#ifdef USE_POSTGRES |
146 |
} |
if (dbop->openflags & DBOP_POSTGRES) |
147 |
/* |
return dbop_getkey_by_fid(dbop, fid); |
148 |
* gpath_id2path: convert id into path |
#endif |
149 |
* |
return dbop_get(dbop, fid); |
|
* i) id path id |
|
|
* r) path name |
|
|
*/ |
|
|
char * |
|
|
gpath_id2path(id) |
|
|
int id; |
|
|
{ |
|
|
char ids[80]; |
|
|
assert(opened == 1); |
|
|
snprintf(ids, sizeof(ids), "%d", id); |
|
|
return gpath_ids2path(ids); |
|
150 |
} |
} |
151 |
/* |
/* |
152 |
* gpath_delete: delete specified path record |
* gpath_delete: delete specified path record |
157 |
gpath_delete(path) |
gpath_delete(path) |
158 |
const char *path; |
const char *path; |
159 |
{ |
{ |
160 |
char *id; |
char *fid; |
161 |
|
|
162 |
assert(opened == 1); |
assert(opened == 1); |
163 |
assert(_mode == 2); |
assert(_mode == 2); |
164 |
assert(path[0] == '.' && path[1] == '/'); |
assert(path[0] == '.' && path[1] == '/'); |
165 |
id = dbop_get(dbop, path); |
fid = dbop_get(dbop, path); |
166 |
if (id == NULL) |
if (fid == NULL) |
167 |
return; |
return; |
168 |
dbop_delete(dbop, id); |
#ifdef USE_POSTGRES |
169 |
dbop_delete(dbop, path); |
if (dbop->openflags & DBOP_POSTGRES) { |
170 |
|
dbop_delete_by_fid(dbop, fid); |
171 |
|
} else { |
172 |
|
#endif |
173 |
|
dbop_delete(dbop, fid); |
174 |
|
dbop_delete(dbop, path); |
175 |
|
#ifdef USE_POSTGRES |
176 |
|
} |
177 |
|
#endif |
178 |
} |
} |
179 |
/* |
/* |
180 |
* gpath_nextkey: return next key |
* gpath_nextkey: return next key |
203 |
} |
} |
204 |
snprintf(buf, sizeof(buf), "%d", _nextkey); |
snprintf(buf, sizeof(buf), "%d", _nextkey); |
205 |
if (_mode == 1 || _mode == 2) |
if (_mode == 1 || _mode == 2) |
206 |
dbop_put(dbop, NEXTKEY, buf, 0); |
dbop_update(dbop, NEXTKEY, buf, "0"); |
207 |
dbop_close(dbop); |
dbop_close(dbop); |
208 |
if (_mode == 1) |
if (_mode == 1) |
209 |
created = 1; |
created = 1; |