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
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
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/>. */
21 # if !defined (PROC_D)
23 typedef void (*PROC_t
) (void);
24 typedef struct { PROC_t proc
; } PROC
;
35 #if defined(__cplusplus)
41 #include "GmcSearch.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
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
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
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
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
);
126 static void doDSdbEnter (void);
132 static void doDSdbExit (DynamicStrings_String s
);
138 static void DSdbEnter (void);
144 static void DSdbExit (DynamicStrings_String s
);
147 Init - initializes the search path.
150 static void Init (void);
157 static void doDSdbEnter (void)
159 DynamicStrings_PushAllocation ();
167 static void doDSdbExit (DynamicStrings_String s
)
169 s
= DynamicStrings_PopAllocationExemption (true, s
);
177 static void DSdbEnter (void)
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
216 extern "C" void mcSearch_initSearchPath (DynamicStrings_String path
)
218 if (InitialPath
!= NULL
)
220 InitialPath
= DynamicStrings_KillString (InitialPath
);
227 prependSearchPath - prepends a new path to the initial search path.
230 extern "C" void mcSearch_prependSearchPath (DynamicStrings_String path
)
233 if (DynamicStrings_EqualArray (UserPath
, (const char *) "", 0))
235 UserPath
= DynamicStrings_KillString (UserPath
);
236 UserPath
= DynamicStrings_Dup (path
);
240 UserPath
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (UserPath
, ':'), path
);
247 findSourceFile - attempts to locate the source file FileName.
248 If a file is found then TRUE is returned otherwise
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
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
;
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);
275 completeSearchPath
= DynamicStrings_Dup (InitialPath
);
280 completeSearchPath
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (DynamicStrings_Dup (UserPath
), ':'), InitialPath
);
283 end
= DynamicStrings_Index (completeSearchPath
, ':', (unsigned int ) (start
));
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
);
297 newpath
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (newpath
, Directory
), FileName
);
299 if (SFIO_Exists (newpath
))
301 (*fullPath
) = newpath
;
302 completeSearchPath
= DynamicStrings_KillString (completeSearchPath
);
305 newpath
= DynamicStrings_KillString (newpath
);
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
);
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
;
334 f
= mcFileName_calculateFileName (stem
, Def
);
335 if (mcSearch_findSourceFile (f
, fullPath
))
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
;
362 f
= mcFileName_calculateFileName (stem
, Mod
);
363 if (mcSearch_findSourceFile (f
, fullPath
))
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
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
[])
407 extern "C" void _M2_mcSearch_fini (__attribute__((unused
)) int argc
, __attribute__((unused
)) char *argv
[], __attribute__((unused
)) char *envp
[])