1 (* M2FileName.mod construct file names.
3 Copyright (C) 2001-2022 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 M2FileName ;
25 FROM ASCII IMPORT nul ;
26 FROM DynamicStrings IMPORT InitString, Mark, Slice, Dup, ConCatChar, ConCat, Length, Equal, Index ;
30 MaxFileName = 0 ; (* zero means no limits *)
36 currently there are no limits on filename length, this may
37 be incorrect on some systems.
42 CalculateFileName - calculates and returns a new string filename given a module
43 and an extension. String, Extension, is concatenated onto
44 Module and thus it is safe to `Mark' the extension for garbage
48 PROCEDURE CalculateFileName (Module, Extension: String) : String ;
52 RETURN( ConCat(ConCatChar(Slice(Module, 0, MaxFileName), '.'), Extension) )
54 RETURN( ConCat(ConCatChar(Slice(Module, 0, MaxFileName-Length(Extension)-1), '.'), Extension) )
56 END CalculateFileName ;
60 CalculateStemName - calculates the stem name for given a module.
61 This name length will be operating system and
65 PROCEDURE CalculateStemName (Module: String) : String ;
67 RETURN( Slice(Module, 0, MaxStemName) )
68 END CalculateStemName ;
72 ExtractExtension - given a, filename, return the filename without
76 PROCEDURE ExtractExtension (filename, ext: String) : String ;
78 IF Equal(ext, Mark(Slice(filename, -Length(ext), 0)))
80 RETURN( Slice(filename, 0, -Length(ext)) )
84 END ExtractExtension ;
88 ExtractModule - given a, filename, return the module name including any
89 extension. A new string is returned.
92 PROCEDURE ExtractModule (filename: String) : String ;
96 i := Index(filename, Directory, 0) ;
99 RETURN( Dup(filename) )
101 RETURN( Slice(filename, i+1, 0) )