-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pathnames.def
116 lines (96 loc) · 5.41 KB
/
Pathnames.def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
(*!m2r10*) (* Copyright (c) 2015 B.Kowarsch. All rights reserved. *)
DEFINITION MODULE Pathnames;
(* Pathname Parser Interface for Modula-2 R10 Core Compiler *)
TYPE Status =
( Success,
InvalidPath,
InvalidFilename,
InvalidReference,
AllocationFailed );
(* Operations *)
(* --------------------------------------------------------------------------
* function isValidPathname(path)
* --------------------------------------------------------------------------
* Returns TRUE if path is a valid pathname, otherwise FALSE.
* --------------------------------------------------------------------------
*)
PROCEDURE isValidPathname ( CONST path : ARRAY OF CHAR ) : BOOLEAN;
(* --------------------------------------------------------------------------
* procedure SplitPathname (path, dirpath, filename, charsProcessed, status)
* --------------------------------------------------------------------------
* Verifies path against the host system's prevailing pathname grammar and
* returns a status code. If path is valid, its directory path component and
* filename component are copied to newly allocated NUL terminated C strings
* and passed back in out-parameters dirpath and filename respectively. If
* path does not contain a directory path component, NULL is passed back in
* dirpath. If path does not contain a filename component, NULL is passed
* back in filename. However, if NIL is passed in for an out-parameter,
* the out-parameter is ignored and no value is passed back in it. The index
* of the last processed character is passed back in charsProcessed. Upon
* success it represents the length of path. Upon failure, it represents
* the index of the first offending character found in path.
* --------------------------------------------------------------------------
*)
PROCEDURE SplitPathname
( CONST path : ARRAY OF CHAR; (* in, may not be empty *)
VAR dirpath : ARRAY OF CHAR; (* out, pass NIL to ignore *)
VAR filename : ARRAY OF CHAR; (* out, pass NIL to ignore *)
VAR charsProcessed : CARDINAL; (* out, pass NIL to ignore *)
VAR status : Status ); (* out, pass NIL to ignore *)
(* --------------------------------------------------------------------------
* function isValidFilename(filename)
* --------------------------------------------------------------------------
* Returns TRUE if filename is a valid filename, otherwise FALSE.
* --------------------------------------------------------------------------
*)
PROCEDURE isValidFilename ( CONST filename : ARRAY OF CHAR ) : BOOLEAN;
(* --------------------------------------------------------------------------
* function splitFilename(filename, basename, suffix, charsProcessed, status)
* --------------------------------------------------------------------------
* Verifies filename against the host system's prevailing pathname grammar
* and returns a status code. If filename is valid, its basename and suffix
* components are copied to newly allocated NUL terminated C strings and
* passed back in out-parameters basename and suffix respectively. If
* filename does not contain a suffix component, NIL is passed back in
* suffix. However, if NIL is passed in for an out-parameter, the out-
* parameter is ignored and no value is passed back in it. The index of the
* last processed character is passed back in charsProcessed. Upon success
* it represents the length of filename. Upon failure, it represents the
* index of the first offending character found in filename.
* --------------------------------------------------------------------------
*)
PROCEDURE SplitFilename
( CONST filename : ARRAY OF CHAR; (* in, may not be empty *)
VAR basename : ARRAY OF CHAR; (* out, pass NIL to ignore *)
VAR suffix : ARRAY OF CHAR; (* out, pass NIL to ignore *)
VAR charsProcessed : CARDINAL; (* out, pass NIL to ignore *)
VAR status : Status ); (* out, pass NIL to ignore *)
(* --------------------------------------------------------------------------
* function isDefSuffix(suffix)
* --------------------------------------------------------------------------
* Returns TRUE if suffix is ".def" or ".DEF", otherwise FALSE.
* --------------------------------------------------------------------------
*)
PROCEDURE isDefSuffix ( CONST suffix : ARRAY OF CHAR ) : BOOLEAN;
(* --------------------------------------------------------------------------
* function isModSuffix(suffix)
* --------------------------------------------------------------------------
* Returns TRUE if suffix is ".mod" or ".MOD", otherwise FALSE.
* --------------------------------------------------------------------------
*)
PROCEDURE isModSuffix ( CONST suffix : ARRAY OF CHAR ) : BOOLEAN;
(* --------------------------------------------------------------------------
* function newPathFromComponents(dirpath, basename, suffix)
* --------------------------------------------------------------------------
* Returns a newly allocated NUL terminated C string containing a pathname
* composed of components dirpath, basename and file suffix. Returns NIL
* if any of dirpath or basename is NIL or empty or if allocation failed.
* --------------------------------------------------------------------------
*)
PROCEDURE newPathFromComponents
( VAR newPath : ARRAY OF CHAR;
CONST dirpath : ARRAY OF CHAR;
CONST basename : ARRAY OF CHAR;
CONST suffix : ARRAY OF CHAR;
VAR status : Status ):
END Pathnames.