]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/m2/gm2-compiler/M2FileName.mod
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / gm2-compiler / M2FileName.mod
CommitLineData
1eee94d3
GM
1(* M2FileName.mod construct file names.
2
83ffe9cd 3Copyright (C) 2001-2023 Free Software Foundation, Inc.
1eee94d3
GM
4Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6This file is part of GNU Modula-2.
7
8GNU Modula-2 is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GNU Modula-2 is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU Modula-2; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. *)
21
22IMPLEMENTATION MODULE M2FileName ;
23
24
25FROM ASCII IMPORT nul ;
26FROM DynamicStrings IMPORT InitString, Mark, Slice, Dup, ConCatChar, ConCat, Length, Equal, Index ;
27
28
29CONST
30 MaxFileName = 0 ; (* zero means no limits *)
31 MaxStemName = 0 ;
32 Directory = '/' ;
33
34
35(*
36 currently there are no limits on filename length, this may
37 be incorrect on some systems.
38*)
39
40
41(*
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
45 collection.
46*)
47
48PROCEDURE CalculateFileName (Module, Extension: String) : String ;
49BEGIN
50 IF MaxFileName=0
51 THEN
52 RETURN( ConCat(ConCatChar(Slice(Module, 0, MaxFileName), '.'), Extension) )
53 ELSE
54 RETURN( ConCat(ConCatChar(Slice(Module, 0, MaxFileName-Length(Extension)-1), '.'), Extension) )
55 END
56END CalculateFileName ;
57
58
59(*
60 CalculateStemName - calculates the stem name for given a module.
61 This name length will be operating system and
62 compiler specific.
63*)
64
65PROCEDURE CalculateStemName (Module: String) : String ;
66BEGIN
67 RETURN( Slice(Module, 0, MaxStemName) )
68END CalculateStemName ;
69
70
71(*
72 ExtractExtension - given a, filename, return the filename without
73 the extension, Ext.
74*)
75
76PROCEDURE ExtractExtension (filename, ext: String) : String ;
77BEGIN
78 IF Equal(ext, Mark(Slice(filename, -Length(ext), 0)))
79 THEN
80 RETURN( Slice(filename, 0, -Length(ext)) )
81 ELSE
82 RETURN( filename )
83 END
84END ExtractExtension ;
85
86
87(*
88 ExtractModule - given a, filename, return the module name including any
89 extension. A new string is returned.
90*)
91
92PROCEDURE ExtractModule (filename: String) : String ;
93VAR
94 i: INTEGER ;
95BEGIN
96 i := Index(filename, Directory, 0) ;
97 IF i=-1
98 THEN
99 RETURN( Dup(filename) )
100 ELSE
101 RETURN( Slice(filename, i+1, 0) )
102 END
103END ExtractModule ;
104
105
106END M2FileName.