1 --Copyright: Matra Datavision 1992,1993
4 -- Created: Tue Feb 18 10:54:35 1992
5 -- Author: Stephan GARNAUD (ARM)
7 -- Modified by LD on Dec 15 1995
8 -- Methode SetSystemName added
14 --Purpose: Manage a system independent path.
15 -- It is possible to give this object a complete
16 -- path including VMS possibilities such as
17 -- Node"Username Password"::Disk:[path1.path2]
18 -- This system dependent syntax is avoided with the
21 uses Environment, SysType, Error, AsciiString from TCollection
22 raises ConstructionError, NullObject, OSDError, NumericError, ProgramError
26 ---Purpose: Creates a Path object initialized to an empty string.
27 -- i.e. current directory.
30 Create (aDependentName : AsciiString; aSysType : SysType=OSD_Default) returns Path
31 ---Purpose: Creates a Path object initialized by dependant path.
32 -- ex: OSD_Path me ("/usr/bin/myprog.sh",OSD_UnixBSD);
34 -- OSD_Path me ("sys$common:[syslib]cc.exe",OSD_OSF) will
35 -- raise a ProgramError due to invalid name for this
37 -- In order to avoid a 'ProgramError' , use IsValid(...)
38 -- to ensure you the validity of <aDependentName>.
39 -- Raises ConstructionError when the path is either null
40 -- or contains characters not in range of ' '...'~'.
42 raises ConstructionError;
44 Create (aNode,aUsername,aPassword,aDisk,aTrek,aName,anExtension: in AsciiString) returns Path;
45 ---Purpose: Initializes a system independent path.
46 -- By default , the Path conversion will be assumed using
47 -- currently used system.
48 -- A special syntax is used to specify a "aTrek" in an
49 -- independent manner :
50 -- a "|" represents directory separator
51 -- a "^" means directory above (father)
53 -- "|usr|bin" - On UNIX -> "/usr/bin"
54 -- - On VMS -> "[usr.bin]"
55 -- - On MSDOS-> "\usr\bin"
56 -- - On MacOs-> ": usr : bin"
58 -- "^|rep" - On UNIX -> "../rep"
59 -- - On VMS -> "[-.rep]"
60 -- - On MSDOS -> "..\rep"
61 -- - On MacOS-> ":: rep"
63 -- "subdir|" - On UNIX -> "subdir/"
64 -- - On VMS -> "[.subdir.]"
66 ---Example: Create("amelix", "sga", "toto", "dk$22", "|bin|usr",myFile,"")
67 -- will give internaly
68 -- On MS-DOS/OS2 \DK22\BIN\USR\MYFILE
69 -- On UNIX sga"toto"@amelix:/dk22/bin/usr/myFile
70 -- On VMS AMELIX"SGA TOTO"::DK$22:[BIN.USR]MYFILE
71 -- On MacOs dk$22 : bin : usr : myFile
73 -- As you can see, "aDisk" is used under UNIX.
74 -- This is possible when one 'mounts' a directory from another system.
75 -- However, the syntax of <aDisk> can slightly change on several systems.
76 -- So "DK$22" on VMS becomes "dk22" on UNIX and Windows NT.
77 -- for instance when you mount a VMS directory under UNIX this gives:
79 -- lucide:/dk22/mydirectory mounted on /vms/mydirectory
83 Values (me ; aNode,aUsername,aPassword,aDisk,aTrek,aName,anExtension :
84 out AsciiString) is static;
85 ---Purpose: Gets each component of a path.
88 SetValues (me : in out;
89 aNode,aUsername,aPassword,aDisk,aTrek,aName,anExtension : in AsciiString)
90 ---Purpose: Sets each component of a path.
92 raises ConstructionError is static;
94 SystemName(me ; FullName : out AsciiString ; aType : SysType=OSD_Default)
96 ---Purpose: Returns system dependent path
97 -- <aType> is one among Unix,VMS ...
98 -- This function is not private because you may need to
99 -- display system dependent path on a front-end.
100 -- It can be useful when communicating with another system.
101 -- For instance when you want to communicate between VMS and Unix
102 -- to transfer files, or to do a remote procedure call
105 -- OSD_Path myPath ("sparc4", "sga", "secret_passwd",
106 -- "$5$dkb100","|users|examples");
107 -- Internal ( Dependent_name );
108 -- On UNIX sga"secret_passwd"@sparc4:/users/examples
109 -- On VMS sparc4"sga secret_passwd"::$5$dkb100:[users.examples]
112 -- SetSystemName(me : in out ; aDependentName : AsciiString; aSysType : SysType=OSD_Default)
113 ---Purpose: Sets each component of a Path giving its system dependent name.
115 -- raises ConstructionError is static;
117 ExpandedName(me : in out; aName : out AsciiString)
119 ---Purpose: Returns system dependent path resolving logical symbols.
121 IsValid (me ; aDependentName : AsciiString; aSysType : SysType=OSD_Default)
122 returns Boolean is static;
123 ---Purpose: Returns TRUE if <aDependentName> is valid for this SysType.
127 UpTrek (me : in out) is static;
128 ---Purpose: This removes the last directory name in <aTrek>
129 -- and returns result.
130 -- ex: me = "|usr|bin|todo.sh"
131 -- me.UpTrek() gives me = "|usr|todo.sh"
132 -- if <me> contains "|", me.UpTrek() will give again "|"
133 -- without any error.
136 DownTrek(me : in out; aName : AsciiString) is static;
137 ---Purpose: This appends a directory name into the Trek.
138 -- ex: me = "|usr|todo.sh"
139 -- me.DownTrek("bin") gives me = "|usr|bin|todo.sh".
142 TrekLength(me) returns Integer is static;
143 ---Purpose: Returns number of components in Trek of <me>.
144 -- ex: me = "|usr|sys|etc|bin"
145 -- me.TrekLength() returns 4.
148 RemoveATrek(me : in out; where : Integer)
149 ---Purpose: This removes a component of Trek in <me> at position <where>.
150 -- The first component of Trek is numbered 1.
151 -- ex: me = "|usr|bin|"
152 -- me.RemoveATrek(1) gives me = "|bin|"
153 -- To avoid a 'NumericError' because of a bad <where>, use
154 -- TrekLength() to know number of components of Trek in <me>.
156 raises NumericError is static;
158 RemoveATrek(me : in out; aName : AsciiString) is static;
159 ---Purpose: This removes <aName> from <me> in Trek.
160 -- No error is raised if <aName> is not in <me>.
161 -- ex: me = "|usr|sys|etc|doc"
162 -- me.RemoveATrek("sys") gives me = "|usr|etc|doc".
165 TrekValue(me ; where : Integer) returns AsciiString
166 ---Purpose: Returns component of Trek in <me> at position <where>.
167 -- ex: me = "|usr|bin|sys|"
168 -- me.TrekValue(2) returns "bin"
169 raises NumericError is static;
172 InsertATrek(me : in out; aName : AsciiString; where : Integer)
173 ---Purpose: This inserts <aName> at position <where> into Trek of <me>.
174 -- ex: me = "|usr|etc|"
175 -- me.InsertATrek("sys",2) gives me = "|usr|sys|etc"
176 raises NumericError is static;
179 Node (me) returns AsciiString is static;
180 ---Purpose: Returns Node of <me>.
183 UserName (me) returns AsciiString is static;
184 ---Purpose: Returns UserName of <me>.
187 Password (me) returns AsciiString is static;
188 ---Purpose: Returns Password of <me>.
191 Disk(me) returns AsciiString is static;
192 ---Purpose: Returns Disk of <me>.
195 Trek(me) returns AsciiString is static;
196 ---Purpose: Returns Trek of <me>.
199 Name (me) returns AsciiString is static;
200 ---Purpose: Returns file name of <me>.
201 -- If <me> hasn't been initialized, it returns an empty AsciiString.
204 Extension (me) returns AsciiString is static;
205 ---Purpose: Returns my extension name.
206 -- This returns an empty string if path contains no file name.
209 SetNode (me : in out; aName : AsciiString) is static;
210 ---Purpose: Sets Node of <me>.
213 SetUserName (me : in out; aName : AsciiString) is static;
214 ---Purpose: Sets UserName of <me>.
217 SetPassword (me : in out; aName : AsciiString) is static;
218 ---Purpose: Sets Password of <me>.
221 SetDisk(me : in out; aName : AsciiString) is static;
222 ---Purpose: Sets Disk of <me>.
225 SetTrek(me : in out; aName : AsciiString) is static;
226 ---Purpose: Sets Trek of <me>.
229 SetName (me : in out; aName : AsciiString) is static;
230 ---Purpose: Sets file name of <me>.
231 -- If <me> hasn't been initialized, it returns an empty AsciiString.
234 SetExtension (me : in out; aName : AsciiString) is static;
235 ---Purpose: Sets my extension name.
238 LocateExecFile(me : in out; aPath: out Path from OSD )
239 returns Boolean from Standard ;
240 ---Purpose: Finds the full path of an executable file, like the
241 -- "which" Unix utility. Uses the path environment variable.
242 -- Returns False if executable file not found.
245 RelativePath(myclass; DirPath, AbsFilePath : AsciiString from TCollection)
246 returns AsciiString from TCollection ;
247 ---Purpose: Returns the relative file path between the absolute directory
248 --- path <DirPath> and the absolute file path <AbsFilePath>.
249 --- If <DirPath> starts with "/", pathes are handled as
250 --- on Unix, if it starts with a letter followed by ":", as on
251 --- WNT. In particular on WNT directory names are not key sensitive.
252 --- If handling fails, an empty string is returned.
256 AbsolutePath(myclass; DirPath, RelFilePath : AsciiString from TCollection)
257 returns AsciiString from TCollection ;
258 ---Purpose: Returns the absolute file path from the absolute directory path
259 --- <DirPath> and the relative file path returned by RelativePath().
260 --- If the RelFilePath is an absolute path, it is returned and the
261 --- directory path is ignored.
262 --- If handling fails, an empty string is returned.
266 myNode : AsciiString;
267 myUserName : AsciiString;
268 myPassword : AsciiString;
269 myDisk : AsciiString;
270 myTrek : AsciiString;
271 myName : AsciiString;
272 myExtension : AsciiString;
273 myUNCFlag : Boolean ;
274 SysDep : SysType; -- To allow system specific use