Debian Codegraph @

w4/dbpath.c

raw
1 /* File: dbpath.c
2 * Author: Jean Thierry-Mieg ([email protected])
3 * Copyright (C) J Thierry-Mieg and R Durbin, 1992
4 * -------------------------------------------------------------------
5 * Acedb is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
19 * -------------------------------------------------------------------
20 * This file is part of the ACEDB genome database package, written by
21 * Richard Durbin (MRC LMB, UK) [email protected], and
22 * Jean Thierry-Mieg (CRBM du CNR, France) [email protected]
23 *
24 * Description:
25 * Utility functions for finding files needed by the database system
26 * HISTORY:
27 * Created: Fri Jan 14 11:19:27 2000 (srk)
28 *-------------------------------------------------------------------
29 */
30
31 #include "acedb.h"
32 #include "dbpath.h"
33 #ifdef __CYGWIN__
34 #include <windows.h>
35 #endif
36
37 static char *dbpath = NULL;
38 static char *commondir = NULL;
39
40 /* dbpath_from_command_line may be zero, in which case we use $ACEDB */
41 BOOL dbPathInit(char *dbpath_from_command_line)
42 {
43 char *cp;
44 if (dbpath)
45 messcrash("repeated call to dbPathInit");
46
47 if (!dbpath_from_command_line)
48 dbpath_from_command_line = getenv("ACEDB");
49
50 if (!dbpath_from_command_line)
51 return FALSE;
52
53 dbpath = filGetName(dbpath_from_command_line, "", "rd", 0);
54
55 if (!dbpath)
56 return FALSE;
57
58
59 /* We set $ACEDB to the (absolute, posix) path.
60 It then gets inherited in this for by all processes we spawn.
61 If we didn't do this $ACEDB would remain unset when using the command
62 line to specfy the database.
63 $ACEDB is used eg by scripts.
64 */
65 putenv(strnew(messprintf("ACEDB=%s", dbpath), 0));
66 /* Note: don't be tempted to use setenv() here: it's not portable
67 to Solaris or IRIX. */
68
69 if (getenv("ACEDB_COMMON"))
70 commondir = getenv("ACEDB_COMMON");
71 #ifdef __CYGWIN__
72 else
73 /* I think I've fundamentally missed the point of this API:
74 why can't I do something like
75 GetRegEntry("HKEY_LOCAL_MACHINE\SOFTWARE\Acedb.org\Acedb\4.x\InstallPath",
76 STRING, buffer, size);
77 */
78 {
79 HKEY software, acedb_org, acedb, four_x;
80 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
81 "SOFTWARE", 0L,
82 KEY_EXECUTE,
83 &software) == ERROR_SUCCESS)
84 {
85 if (RegOpenKeyEx(software,
86 "acedb.org", 0L,
87 KEY_EXECUTE,
88 &acedb_org) == ERROR_SUCCESS)
89 {
90 if (RegOpenKeyEx(acedb_org,
91 "Acedb", 0L,
92 KEY_EXECUTE,
93 &acedb) == ERROR_SUCCESS)
94 {
95 if (RegOpenKeyEx(acedb,
96 "4.x", 0L,
97 KEY_EXECUTE,
98 &four_x) == ERROR_SUCCESS)
99 {
100 DWORD buffsiz = 255;
101 char buff[256];
102 if (RegQueryValueEx(four_x,
103 "InstallPath",
104 NULL,
105 NULL,
106 buff,
107 &buffsiz) == ERROR_SUCCESS)
108 commondir = filGetName(buff, "", "rd", 0);
109 RegCloseKey(four_x);
110 }
111 RegCloseKey(acedb);
112 }
113 RegCloseKey(acedb_org);
114 }
115 RegCloseKey(software);
116 }
117 }
118 #elif defined(DARWIN)
119 /* Fink put packages under /sw */
120 else if (filCheckName("/sw/share/acedb", "", "rd"))
121 commondir = filGetName("/sw/share/acedb", "", "rd", 0);
122 #else
123 else if (filCheckName("/usr/share/acedb", "", "rd"))
124 commondir = filGetName("/usr/share/acedb", "", "rd", 0);
125 else if (filCheckName("/usr/local/acedb", "", "rd"))
126 commondir = filGetName("/usr/local/acedb", "", "rd", 0);
127 #endif
128
129 if (!getenv ("ACEDB_NO_BANNER"))
130 {
131 printf ("// Database directory: %s\n", dbpath) ;
132 if (commondir)
133 printf ("// Shared files: %s\n", commondir) ;
134 }
135
136 return TRUE;
137 }
138
139
140 /* Look for file in the database and common directories */
141 char *dbPathFilName (char *dir, char *name, char *ending,
142 char *spec, STORE_HANDLE handle)
143 {
144 Stack s = stackCreate(MAXPATHLEN);
145 char *ret;
146
147 if (!dbpath)
148 messcrash("called dbPathFilname before dbPathInit");
149
150 catText(s, dbpath);
151 if (dir && *dir)
152 {
153 catText(s, "/");
154 catText(s, dir);
155 }
156 if (name && *name)
157 {
158 catText(s, "/");
159 catText(s, name);
160 }
161
162 if (ret = filGetName(stackText(s, 0), ending, spec, handle))
163 {
164 stackDestroy(s);
165 return ret;
166 }
167
168 if (commondir)
169 {
170 stackClear(s);
171 catText(s, commondir);
172 if (dir && *dir)
173 {
174 catText(s, "/");
175 catText(s, dir);
176 }
177 if (name && *name)
178 {
179 catText(s, "/");
180 catText(s, name);
181 }
182
183 ret = filGetName(stackText(s, 0), ending, spec, handle);
184 stackDestroy(s);
185 return ret;
186 }
187
188 return 0;
189 }
190
191 /* Look for the file only in the database directory */
192 char *dbPathStrictFilName (char *dir, char *name, char *ending,
193 char *spec, STORE_HANDLE handle)
194 {
195 Stack s = stackCreate(MAXPATHLEN);
196 char *ret;
197
198 if (!dbpath)
199 messcrash("called dbPathStrictFilname before dbPathInit");
200
201 catText(s, dbpath);
202 if (dir && *dir)
203 {
204 catText(s, "/");
205 catText(s, dir);
206 }
207 if (name && *name)
208 {
209 catText(s, "/");
210 catText(s, name);
211 }
212
213 ret = filGetName(stackText(s, 0), ending, spec, handle);
214 stackDestroy(s);
215 return ret;
216 }
217
218 char *dbPathMakeFilName (char *dir, char *name, char *ending,
219 STORE_HANDLE handle)
220 {
221 Stack s = stackCreate(MAXPATHLEN);
222 char *ret;
223
224 if (!dbpath)
225 messcrash("called dbPathMakeFilname before dbPathInit");
226
227 catText(s, dbpath);
228 if (dir && *dir)
229 {
230 catText(s, "/");
231 catText(s, dir);
232 }
233 if (name && *name)
234 {
235 catText(s, "/");
236 catText(s, name);
237 }
238 if (ending && *ending)
239 {
240 catText(s, ".");
241 catText(s, ending);
242 }
243
244 ret = strnew(stackText(s, 0), handle);
245 stackDestroy(s);
246 return ret;
247 }
248
249
250
251
252
253
254
255
256