1 (* M2Search.mod provides a mechanism to search selected directories.
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. *)
22 IMPLEMENTATION MODULE M2Search ;
25 FROM M2FileName IMPORT CalculateFileName ;
26 FROM Assertion IMPORT Assert ;
27 FROM PathName IMPORT FindNamedPathFile ;
29 FROM DynamicStrings IMPORT InitString, InitStringChar,
30 KillString, ConCat, ConCatChar, Index, Slice,
31 Add, EqualArray, Dup, Mark,
32 PushAllocation, PopAllocationExemption,
33 InitStringDB, InitStringCharStarDB,
34 InitStringCharDB, MultDB, DupDB, SliceDB ;
38 GarbageDebugging = FALSE ;
39 DefaultDefExt = '.def' ;
40 DefaultModExt = '.mod' ;
45 (* Internal garbage collection debugging routines. *)
48 #define InitString(X) InitStringDB(X, __FILE__, __LINE__)
49 #define InitStringCharStar(X) InitStringCharStarDB(X, __FILE__, __LINE__)
50 #define InitStringChar(X) InitStringCharDB(X, __FILE__, __LINE__)
51 #define Mult(X,Y) MultDB(X, Y, __FILE__, __LINE__)
52 #define Dup(X) DupDB(X, __FILE__, __LINE__)
53 #define Slice(X,Y,Z) SliceDB(X, Y, Z, __FILE__, __LINE__)
58 doDSdbEnter - called when compiled with -fcpp to enable runtime garbage
63 PROCEDURE doDSdbEnter ;
71 doDSdbExit - called when compiled with -fcpp to enable runtime garbage
72 collection debugging. The parameter string s is exempt from
73 garbage collection analysis.
77 PROCEDURE doDSdbExit (s: String) ;
79 (* Check to see whether no strings have been lost since the PushAllocation. *)
80 Assert (PopAllocationExemption (TRUE, s) = s)
86 DSdbEnter - dummy nop entry code which the preprocessor replaces by
87 doDSsbEnter when debugging garbage collection at runtime.
97 DSdbExit - dummy nop exit code which the preprocessor replaces by
98 doDSsbExit when debugging garbage collection at runtime.
102 PROCEDURE DSdbExit (s: String) ;
113 #define DSdbEnter doDSdbEnter
114 #define DSdbExit doDSdbExit
119 FindSourceFile - attempts to locate the source file FileName.
120 If a file is found then TRUE is returned otherwise
122 The parameter FullPath is set indicating the
123 absolute location of source FileName.
124 FullPath will be totally overwritten and should
125 not be initialized by InitString before this function
127 FullPath is set to NIL if this function returns FALSE.
128 FindSourceFile sets FullPath to a new string if successful.
129 The string FileName is not altered.
132 PROCEDURE FindSourceFile (FileName: String;
133 VAR FullPath, named: String) : BOOLEAN ;
135 FullPath := FindNamedPathFile (FileName, named) ;
136 RETURN FullPath # NIL
141 FindSourceDefFile - attempts to find the definition module for
142 a module, Stem. If successful it returns
143 the full path and returns TRUE. If unsuccessful
144 then FALSE is returned and FullPath is set to NIL.
147 PROCEDURE FindSourceDefFile (Stem: String; VAR FullPath, named: String) : BOOLEAN ;
153 f := CalculateFileName (Stem, Def) ;
154 IF FindSourceFile (f, FullPath, named)
160 (* Try the GNU Modula-2 default extension. *)
161 f := CalculateFileName (Stem, Mark (InitString (DefaultDefExt))) ;
162 RETURN FindSourceFile (f, FullPath, named)
163 END FindSourceDefFile ;
167 FindSourceModFile - attempts to find the implementation module for
168 a module, Stem. If successful it returns
169 the full path and returns TRUE. If unsuccessful
170 then FALSE is returned and FullPath is set to NIL.
173 PROCEDURE FindSourceModFile (Stem: String; VAR FullPath, named: String) : BOOLEAN ;
179 f := CalculateFileName (Stem, Mod) ;
180 IF FindSourceFile (f, FullPath, named)
186 (* Try the GNU Modula-2 default extension. *)
187 f := CalculateFileName (Stem, Mark (InitString (DefaultModExt))) ;
188 RETURN FindSourceFile (f, FullPath, named)
189 END FindSourceModFile ;
193 SetDefExtension - sets the default extension for definition modules to, ext.
194 The string, ext, should be deallocated by the caller at
198 PROCEDURE SetDefExtension (ext: String) ;
200 Def := KillString (Def) ;
202 END SetDefExtension ;
206 SetModExtension - sets the default extension for implementation and program
207 modules to, ext. The string, ext, should be deallocated
208 by the caller at an appropriate time.
211 PROCEDURE SetModExtension (ext: String) ;
213 Mod := KillString (Mod) ;
215 END SetModExtension ;
219 Init - initializes the def and mod default string names to NIL.