~ubuntu-branches/debian/stretch/adabrowse/stretch

« back to all changes in this revision

Viewing changes to util-pathes.ads

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Brenta
  • Date: 2004-02-14 13:22:40 UTC
  • Revision ID: james.westby@ubuntu.com-20040214132240-cqumhiq1677pkvzo
Tags: upstream-4.0.2
ImportĀ upstreamĀ versionĀ 4.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-------------------------------------------------------------------------------
 
2
--
 
3
--  <STRONG>Copyright &copy; 2001, 2002 by Thomas Wolf.</STRONG>
 
4
--  <BLOCKQUOTE>
 
5
--    This piece of software is free software; you can redistribute it and/or
 
6
--    modify it under the terms of the  GNU General Public License as published
 
7
--    by the Free Software  Foundation; either version 2, or (at your option)
 
8
--    any later version. This software is distributed in the hope that it will
 
9
--    be useful, but <EM>without any warranty</EM>; without even the implied
 
10
--    warranty of <EM>merchantability or fitness for a particular purpose.</EM>
 
11
--    See the GNU General Public License for  more details. You should have
 
12
--    received a copy of the GNU General Public License with this distribution,
 
13
--    see file "<A HREF="GPL.txt">GPL.txt</A>". If not, write to the Free
 
14
--    Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
15
--    USA.
 
16
--  </BLOCKQUOTE>
 
17
--  <BLOCKQUOTE>
 
18
--    As a special exception from the GPL, if other files instantiate generics
 
19
--    from this unit, or you link this unit with other files to produce an
 
20
--    executable, this unit does not by itself cause the resulting executable
 
21
--    to be covered by the GPL. This exception does not however invalidate any
 
22
--    other reasons why the executable file might be covered by the GPL.
 
23
--  </BLOCKQUOTE>
 
24
--
 
25
--  <AUTHOR>
 
26
--    Thomas Wolf  (TW) <E_MAIL>
 
27
--  </AUTHOR>
 
28
--
 
29
--  <PURPOSE>
 
30
--    Operations for manipulating file names. The package is intended for
 
31
--    use on Windows or Unix systems. Upon elaboration, it tries to figure
 
32
--    out the host operating system by examining the @PATH@ environment
 
33
--    variable: if that contains Windows-looking pathes (i.e., a '\' is found
 
34
--    before a any '/'), it assumes it's being used on Windows. If, on the
 
35
--    other hand, it finds a '/' first, it assumes Unix. If it finds neither,
 
36
--    it uses @GNAT.Os_Lib.Directory_Separator@ as its directory separator.
 
37
--    (If you intend to use this package on a non-GNAT system, you'll have
 
38
--    to change the body of this package as appropriate.)
 
39
--
 
40
--    All operations in this package are pur string manipulation operations.
 
41
--    There are no file system operations involved.
 
42
--  </PURPOSE>
 
43
--
 
44
--  <NOT_TASK_SAFE>
 
45
--
 
46
--  <NO_STORAGE>
 
47
--
 
48
--  <HISTORY>
 
49
--    19-MAR-2002   TW  Initial version.
 
50
--    03-MAY-2002   TW  Added 'Drive' and 'Node'.
 
51
--  </HISTORY>
 
52
-------------------------------------------------------------------------------
 
53
 
 
54
pragma License (Modified_GPL);
 
55
 
 
56
package Util.Pathes is
 
57
 
 
58
   pragma Elaborate_Body;
 
59
 
 
60
   --  A @Full_Name@ can have a path component, and a file name. Both are
 
61
   --  optional, i.e., a @Full_Name@ can also be only a path, or only a
 
62
   --  file name. A @File_Name@ may or may not contain an extension. This
 
63
   --  package considers anything beyond the last '.' in a file name the
 
64
   --  extension, unless that last period is the first character of the file
 
65
   --  name, in which case the extension is the empty string (this handles
 
66
   --  names like "@.cshrc@" as they are common on Unix-like systems).
 
67
   --
 
68
   --  This package uses a purely syntactical distinction between file and
 
69
   --  directory names: if the @Full_Name@ terminates in a directory
 
70
   --  separator, it is considered a directory name; otherwise it is taken
 
71
   --  as a file name.
 
72
 
 
73
   Path_Error : exception;
 
74
 
 
75
   function Directory_Separator
 
76
     return Character;
 
77
   --  Returns the directory separator used. Returns whatever the package
 
78
   --  elaboration concluded was the directory separator on the host
 
79
   --  environment.
 
80
 
 
81
   function Extension
 
82
     (Full_Name : in String;
 
83
      Separator : in Character := Directory_Separator)
 
84
     return String;
 
85
   --  Returns the extension of @Full_Name@, which may be the empty string.
 
86
 
 
87
   function Name
 
88
     (Full_Name : in String;
 
89
      Separator : in Character := Directory_Separator)
 
90
     return String;
 
91
   --  Returns the file name component of @Full_Name@ including a possible
 
92
   --  extension. Returns the empty string if @Full_Name@ is a path only.
 
93
 
 
94
   function Base_Name
 
95
     (Full_Name : in String;
 
96
      Separator : in Character := Directory_Separator)
 
97
     return String;
 
98
   --  Returns the file name component of @Full_Name@ <EM>without</EM> a
 
99
   --  possible extension. Returns the empty string if @Full_Name@ is a path
 
100
   --  only.
 
101
 
 
102
   function Path
 
103
     (Full_Name : in String;
 
104
      Separator : in Character := Directory_Separator)
 
105
     return String;
 
106
   --  Returns "" if @Full_Name@ does not contain a path component; otherwise
 
107
   --  it returns the path component (absolute or relative) including the
 
108
   --  final directory separator.
 
109
 
 
110
   function Drive
 
111
     (Full_Name : in String;
 
112
      Separator : in Character := Directory_Separator)
 
113
     return String;
 
114
   --  Returns "" if @Full_Name@ does not contain a drive component; otherwise
 
115
   --  it returns the drive specification (ending in a colon).
 
116
 
 
117
   function Has_Drive
 
118
     (Full_Name : in String;
 
119
      Separator : in Character := Directory_Separator)
 
120
     return Boolean;
 
121
 
 
122
   function Node
 
123
     (Full_Name : in String;
 
124
      Separator : in Character := Directory_Separator)
 
125
     return String;
 
126
 
 
127
   function Has_Node
 
128
     (Full_Name : in String;
 
129
      Separator : in Character := Directory_Separator)
 
130
     return Boolean;
 
131
 
 
132
   function Normalize
 
133
     (Path      : in String;
 
134
      Separator : in Character := Directory_Separator)
 
135
     return String;
 
136
   --  @Path@ is assumed to be a path only.
 
137
   --  Returns <CODE>'.' & Separator</CODE> if @Path@ is empty, otherwise
 
138
   --  returns @Path@ terminated with a @Separator@.
 
139
 
 
140
   function Is_Absolute_Path
 
141
     (Name      : in String;
 
142
      Separator : in Character := Directory_Separator)
 
143
     return Boolean;
 
144
   --  Returns @True@ if the name given has an absolute path component.
 
145
 
 
146
   function Concat
 
147
     (Path      : in String;
 
148
      File_Name : in String;
 
149
      Separator : in Character := Directory_Separator)
 
150
     return String;
 
151
   --  Concatenates the @Path@ with the @File_Name@, which may contain a
 
152
   --  relative path. Returns @Path@ if @File_Name@ = "", and @File_Name@ if
 
153
   --  @Path@ = "". Otherwise, raises @Path_Error@ if @File_Name@ contains an
 
154
   --  <EM>absolute</EM> path component. Note that @File_Name@ not necessarily
 
155
   --  must contain a file name, it may also be a relative path.
 
156
 
 
157
   function Replace_File_Name
 
158
     (Full_Name : in String;
 
159
      File_Name : in String;
 
160
      Separator : in Character := Directory_Separator)
 
161
     return String;
 
162
   --  Equivalent to
 
163
   --  <CODE>Concat&nbsp;(Path&nbsp;(Full_Name, Separator), File_Name,
 
164
   --  Separator)</CODE>.
 
165
 
 
166
   function Replace_Extension
 
167
     (Full_Name : in String;
 
168
      Extension : in String;
 
169
      Separator : in Character := Directory_Separator)
 
170
     return String;
 
171
   --  Replaces the extension of @Full_Name@. @Extension@ should not include
 
172
   --  a leading period! If @Full_Name@ has a file name component, but no
 
173
   --  extension yet, a period and the @Extension@ is appended. Raises
 
174
   --  @Path_Error@ if @Full_Name@ doesn't have a file name component at all.
 
175
 
 
176
   function Parent
 
177
     (Path      : in String;
 
178
      Separator : in Character := Directory_Separator)
 
179
     return String;
 
180
   --  Tries to move up one directory in @Path@, which is interpreted as a
 
181
   --  path name even if it has no trailing @Separator@. Raises @Path_Error@
 
182
   --  if @Path@ is an absolute path and specifies a root directory. If
 
183
   --  @Path@ is a relative path, the result it may start with "../". the
 
184
   --  result has a trailing @Separator@.
 
185
 
 
186
   function Clean
 
187
     (Full_Name : in String;
 
188
      Separator : in Character := Directory_Separator)
 
189
     return String;
 
190
   --  Cleans up @Full_name@, which is interpreted as a path even if it has
 
191
   --  no trailing @Separator@. Removes all extraneous separators and "./"
 
192
   --  sequences, and also executes "../" components. Raises @Path_Error@ if
 
193
   --  the path is invalid, e.g. execution of "../" would go beyond the root
 
194
   --  directory, if @Full_Name@ is an absolute path. If @Full_Name@ is a
 
195
   --  relative path, the resulting path may start with "./" or a sequence
 
196
   --  of "../". The result has a trailing @Separator@, unless it is a
 
197
   --  Windows relative path name consisting only of a drive letter and a
 
198
   --  colon, in which case it ends with the colon.
 
199
 
 
200
private
 
201
 
 
202
   pragma Inline (Directory_Separator);
 
203
 
 
204
end Util.Pathes;