1 (* Copyright (C) 2015-2022 Free Software Foundation, Inc. *)
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 along
15 with gm2; see the file COPYING. If not, write to the Free Software
16 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
18 IMPLEMENTATION MODULE mcFileName ;
21 FROM ASCII IMPORT nul ;
22 FROM DynamicStrings IMPORT InitString, Mark, Slice, Dup, ConCatChar, ConCat, Length, Equal, Index ;
26 MaxFileName = 0 ; (* zero means no limits *)
32 currently there are no limits on filename length, this may
33 be incorrect on some systems.
38 calculateFileName - calculates and returns a new string filename given a module
39 and an extension. String, Extension, is concatenated onto
40 Module and thus it is safe to `Mark' the extension for garbage
44 PROCEDURE calculateFileName (module, extension: String) : String ;
48 RETURN ConCat (ConCatChar (Slice (module, 0, MaxFileName), '.'), extension)
50 RETURN ConCat (ConCatChar (Slice (module, 0, MaxFileName-Length (extension)-1), '.'), extension)
52 END calculateFileName ;
56 calculateStemName - calculates the stem name for given a module.
57 This name length will be operating system and
61 PROCEDURE calculateStemName (module: String) : String ;
63 RETURN Slice (module, 0, MaxStemName)
64 END calculateStemName ;
68 extractExtension - given a, filename, return the filename without
72 PROCEDURE extractExtension (filename, ext: String) : String ;
74 IF Equal (ext, Mark (Slice (filename, -Length (ext), 0)))
76 RETURN Slice (filename, 0, -Length (ext))
80 END extractExtension ;
84 extractModule - given a, filename, return the module name including any
85 extension. A new string is returned.
88 PROCEDURE extractModule (filename: String) : String ;
92 i := Index (filename, Directory, 0) ;
97 RETURN Slice (filename, i+1, 0)