Daily bump.
[official-gcc.git] / gcc / m2 / mc-boot / GmcSearch.cc
blobe1a2aa63e29d99ff6df0db90998a1a3cb6b895f1
1 /* do not edit automatically generated by mc from mcSearch. */
2 /* This file is part of GNU Modula-2.
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 3, or (at your option) any later
7 version.
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3. If not see
16 <http://www.gnu.org/licenses/>. */
18 #include "config.h"
19 #include "system.h"
20 #include <stdbool.h>
21 # if !defined (PROC_D)
22 # define PROC_D
23 typedef void (*PROC_t) (void);
24 typedef struct { PROC_t proc; } PROC;
25 # endif
27 # if !defined (TRUE)
28 # define TRUE (1==1)
29 # endif
31 # if !defined (FALSE)
32 # define FALSE (1==0)
33 # endif
35 #if defined(__cplusplus)
36 # undef NULL
37 # define NULL 0
38 #endif
39 #define _mcSearch_C
41 #include "GmcSearch.h"
42 # include "GSFIO.h"
43 # include "GmcFileName.h"
44 # include "GDynamicStrings.h"
46 # define Directory '/'
47 static DynamicStrings_String Def;
48 static DynamicStrings_String Mod;
49 static DynamicStrings_String UserPath;
50 static DynamicStrings_String InitialPath;
53 initSearchPath - assigns the search path to Path.
54 The string Path may take the form:
56 Path ::= IndividualPath { ":" IndividualPath }
57 IndividualPath ::= "." | DirectoryPath
58 DirectoryPath ::= [ "/" ] Name { "/" Name }
59 Name ::= Letter { (Letter | Number) }
60 Letter ::= A..Z | a..z
61 Number ::= 0..9
64 extern "C" void mcSearch_initSearchPath (DynamicStrings_String path);
67 prependSearchPath - prepends a new path to the initial search path.
70 extern "C" void mcSearch_prependSearchPath (DynamicStrings_String path);
73 findSourceFile - attempts to locate the source file FileName.
74 If a file is found then TRUE is returned otherwise
75 FALSE is returned.
76 The parameter fullPath is set indicating the
77 absolute location of source FileName.
78 fullPath will be totally overwritten and should
79 not be initialized by InitString before this function
80 is called.
81 fullPath is set to NIL if this function returns FALSE.
82 findSourceFile sets fullPath to a new string if successful.
83 The string, FileName, is not altered.
86 extern "C" bool mcSearch_findSourceFile (DynamicStrings_String FileName, DynamicStrings_String *fullPath);
89 findSourceDefFile - attempts to find the definition module for
90 a module, stem. If successful it returns
91 the full path and returns TRUE. If unsuccessful
92 then FALSE is returned and fullPath is set to NIL.
95 extern "C" bool mcSearch_findSourceDefFile (DynamicStrings_String stem, DynamicStrings_String *fullPath);
98 findSourceModFile - attempts to find the implementation module for
99 a module, stem. If successful it returns
100 the full path and returns TRUE. If unsuccessful
101 then FALSE is returned and fullPath is set to NIL.
104 extern "C" bool mcSearch_findSourceModFile (DynamicStrings_String stem, DynamicStrings_String *fullPath);
107 setDefExtension - sets the default extension for definition modules to, ext.
108 The string, ext, should be deallocated by the caller at
109 an appropriate time.
112 extern "C" void mcSearch_setDefExtension (DynamicStrings_String ext);
115 setModExtension - sets the default extension for implementation and program
116 modules to, ext. The string, ext, should be deallocated
117 by the caller at an appropriate time.
120 extern "C" void mcSearch_setModExtension (DynamicStrings_String ext);
123 doDSdbEnter -
126 static void doDSdbEnter (void);
129 doDSdbExit -
132 static void doDSdbExit (DynamicStrings_String s);
135 DSdbEnter -
138 static void DSdbEnter (void);
141 DSdbExit -
144 static void DSdbExit (DynamicStrings_String s);
147 Init - initializes the search path.
150 static void Init (void);
154 doDSdbEnter -
157 static void doDSdbEnter (void)
159 DynamicStrings_PushAllocation ();
164 doDSdbExit -
167 static void doDSdbExit (DynamicStrings_String s)
169 s = DynamicStrings_PopAllocationExemption (true, s);
174 DSdbEnter -
177 static void DSdbEnter (void)
183 DSdbExit -
186 static void DSdbExit (DynamicStrings_String s)
192 Init - initializes the search path.
195 static void Init (void)
197 UserPath = DynamicStrings_InitString ((const char *) "", 0);
198 InitialPath = DynamicStrings_InitStringChar ('.');
199 Def = static_cast<DynamicStrings_String> (NULL);
200 Mod = static_cast<DynamicStrings_String> (NULL);
205 initSearchPath - assigns the search path to Path.
206 The string Path may take the form:
208 Path ::= IndividualPath { ":" IndividualPath }
209 IndividualPath ::= "." | DirectoryPath
210 DirectoryPath ::= [ "/" ] Name { "/" Name }
211 Name ::= Letter { (Letter | Number) }
212 Letter ::= A..Z | a..z
213 Number ::= 0..9
216 extern "C" void mcSearch_initSearchPath (DynamicStrings_String path)
218 if (InitialPath != NULL)
220 InitialPath = DynamicStrings_KillString (InitialPath);
222 InitialPath = path;
227 prependSearchPath - prepends a new path to the initial search path.
230 extern "C" void mcSearch_prependSearchPath (DynamicStrings_String path)
232 DSdbEnter ();
233 if (DynamicStrings_EqualArray (UserPath, (const char *) "", 0))
235 UserPath = DynamicStrings_KillString (UserPath);
236 UserPath = DynamicStrings_Dup (path);
238 else
240 UserPath = DynamicStrings_ConCat (DynamicStrings_ConCatChar (UserPath, ':'), path);
242 DSdbExit (UserPath);
247 findSourceFile - attempts to locate the source file FileName.
248 If a file is found then TRUE is returned otherwise
249 FALSE is returned.
250 The parameter fullPath is set indicating the
251 absolute location of source FileName.
252 fullPath will be totally overwritten and should
253 not be initialized by InitString before this function
254 is called.
255 fullPath is set to NIL if this function returns FALSE.
256 findSourceFile sets fullPath to a new string if successful.
257 The string, FileName, is not altered.
260 extern "C" bool mcSearch_findSourceFile (DynamicStrings_String FileName, DynamicStrings_String *fullPath)
262 DynamicStrings_String completeSearchPath;
263 int start;
264 int end;
265 DynamicStrings_String newpath;
267 if (DynamicStrings_EqualArray (UserPath, (const char *) "", 0))
269 if (DynamicStrings_EqualArray (InitialPath, (const char *) "", 0))
271 completeSearchPath = DynamicStrings_InitString ((const char *) ".", 1);
273 else
275 completeSearchPath = DynamicStrings_Dup (InitialPath);
278 else
280 completeSearchPath = DynamicStrings_ConCat (DynamicStrings_ConCatChar (DynamicStrings_Dup (UserPath), ':'), InitialPath);
282 start = 0;
283 end = DynamicStrings_Index (completeSearchPath, ':', (unsigned int ) (start));
284 do {
285 if (end == -1)
287 end = 0;
289 newpath = DynamicStrings_Slice (completeSearchPath, start, end);
290 if (DynamicStrings_EqualArray (newpath, (const char *) ".", 1))
292 newpath = DynamicStrings_KillString (newpath);
293 newpath = DynamicStrings_Dup (FileName);
295 else
297 newpath = DynamicStrings_ConCat (DynamicStrings_ConCatChar (newpath, Directory), FileName);
299 if (SFIO_Exists (newpath))
301 (*fullPath) = newpath;
302 completeSearchPath = DynamicStrings_KillString (completeSearchPath);
303 return true;
305 newpath = DynamicStrings_KillString (newpath);
306 if (end != 0)
308 start = end+1;
309 end = DynamicStrings_Index (completeSearchPath, ':', (unsigned int ) (start));
311 } while (! (end == 0));
312 (*fullPath) = static_cast<DynamicStrings_String> (NULL);
313 newpath = DynamicStrings_KillString (newpath);
314 completeSearchPath = DynamicStrings_KillString (completeSearchPath);
315 return false;
316 /* static analysis guarentees a RETURN statement will be used before here. */
317 __builtin_unreachable ();
322 findSourceDefFile - attempts to find the definition module for
323 a module, stem. If successful it returns
324 the full path and returns TRUE. If unsuccessful
325 then FALSE is returned and fullPath is set to NIL.
328 extern "C" bool mcSearch_findSourceDefFile (DynamicStrings_String stem, DynamicStrings_String *fullPath)
330 DynamicStrings_String f;
332 if (Def != NULL)
334 f = mcFileName_calculateFileName (stem, Def);
335 if (mcSearch_findSourceFile (f, fullPath))
337 return true;
339 f = DynamicStrings_KillString (f);
341 /* and try the GNU Modula-2 default extension */
342 f = mcFileName_calculateFileName (stem, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "def", 3)));
343 return mcSearch_findSourceFile (f, fullPath);
344 /* static analysis guarentees a RETURN statement will be used before here. */
345 __builtin_unreachable ();
350 findSourceModFile - attempts to find the implementation module for
351 a module, stem. If successful it returns
352 the full path and returns TRUE. If unsuccessful
353 then FALSE is returned and fullPath is set to NIL.
356 extern "C" bool mcSearch_findSourceModFile (DynamicStrings_String stem, DynamicStrings_String *fullPath)
358 DynamicStrings_String f;
360 if (Mod != NULL)
362 f = mcFileName_calculateFileName (stem, Mod);
363 if (mcSearch_findSourceFile (f, fullPath))
365 return true;
367 f = DynamicStrings_KillString (f);
369 /* and try the GNU Modula-2 default extension */
370 f = mcFileName_calculateFileName (stem, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "mod", 3)));
371 return mcSearch_findSourceFile (f, fullPath);
372 /* static analysis guarentees a RETURN statement will be used before here. */
373 __builtin_unreachable ();
378 setDefExtension - sets the default extension for definition modules to, ext.
379 The string, ext, should be deallocated by the caller at
380 an appropriate time.
383 extern "C" void mcSearch_setDefExtension (DynamicStrings_String ext)
385 Def = DynamicStrings_KillString (Def);
386 Def = DynamicStrings_Dup (ext);
391 setModExtension - sets the default extension for implementation and program
392 modules to, ext. The string, ext, should be deallocated
393 by the caller at an appropriate time.
396 extern "C" void mcSearch_setModExtension (DynamicStrings_String ext)
398 Mod = DynamicStrings_KillString (Mod);
399 Mod = DynamicStrings_Dup (ext);
402 extern "C" void _M2_mcSearch_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
404 Init ();
407 extern "C" void _M2_mcSearch_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])