PageRenderTime 19ms CodeModel.GetById 8ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/src/lib/io/filesystem/path_name/cygwin_directory_notation.e

http://github.com/tybor/Liberty
Specman e | 188 lines | 132 code | 19 blank | 37 comment | 16 complexity | 4c934dc15e3e5744475dd4c9ce98a734 MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4class CYGWIN_DIRECTORY_NOTATION
  5   -- The Cygwin like file path notation looks like:
  6   --   //C/LibertyEiffel/sys/system.se
  7   --|*** I've never seen this notation. My cygwin uses plain old unix
  8   --|*** notation, windows drives are mapped to /cygdrive/c/ etc...
  9   --|*** <FM-23/03/2003>
 10   --|*** AFAIR that's the old b20 series <CAD 2005.11.18>
 11
 12inherit
 13   DIRECTORY_NOTATION
 14
 15feature {ANY}
 16   is_current_directory (path: STRING): BOOLEAN
 17      do
 18         if path.compare(once ".") = 0 or else path.compare(once "./") = 0 then
 19            Result := True
 20         else
 21            Result := path.occurrences('.') + path.occurrences('/') = path.count and not path.has_substring("..")
 22         end
 23      end
 24
 25   is_parent_directory (path: STRING): BOOLEAN
 26      local
 27         pos: INTEGER
 28      do
 29         if path.compare(once "..") = 0 or else path.compare(once "../") = 0 then
 30            Result := True
 31         else
 32            Result := path.occurrences('.') + path.occurrences('/') = path.count and path.has_substring("..")
 33            if Result then
 34               pos := path.first_substring_index("..")
 35               Result := Result and path.substring_index("..", pos + 2) = 0
 36            end
 37         end
 38      end
 39
 40   to_parent_directory (some_path: STRING)
 41      do
 42         --|*** "." and ".." are not handled correctly <FM-24/03/2005>
 43         from
 44            some_path.remove_last
 45         until
 46            some_path.is_empty or else some_path.last = '/' or else some_path.last = ':'
 47         loop
 48            some_path.remove_last
 49         end
 50         if some_path.is_empty then
 51         elseif some_path.first = '/' then
 52            if some_path.count = 2 then
 53               if some_path.item(2) = '/' then
 54                  some_path.remove_last
 55               end
 56            end
 57         end
 58         if not some_path.is_empty then
 59            some_path.extend_unless('/')
 60         end
 61      end
 62
 63   to_subdirectory_with (parent_path, entry_name: STRING)
 64      do
 65         if (once ".").is_equal(entry_name) then
 66            -- Because you would get the same directory as `parent_path' and
 67            -- not a new subdirectory as explained before.
 68            parent_path.clear_count
 69         elseif (once "..").is_equal(entry_name) then
 70            -- Because you would not get a subdirectory of `parent_path'.
 71            parent_path.clear_count
 72         else
 73            parent_path.extend_unless('/')
 74            if entry_name.first = '/' then
 75               parent_path.remove_last
 76            end
 77            parent_path.append(entry_name)
 78            parent_path.extend_unless('/')
 79         end
 80      end
 81
 82   to_file_path_with (parent_path, file_name: STRING)
 83      do
 84         parent_path.extend_unless('/')
 85         if file_name.first = '/' then
 86            parent_path.remove_last
 87         end
 88         parent_path.append(file_name)
 89      end
 90
 91   to_subpath_with (parent_path, subpath: STRING)
 92      do
 93         parent_path.extend_unless('/')
 94         parent_path.append(subpath)
 95      end
 96
 97   to_directory_path (path: STRING)
 98      do
 99         path.extend_unless('/')
100      end
101
102   to_short_name_in (buffer, path: STRING)
103      local
104         i: INTEGER
105      do
106         buffer.copy(path)
107         if buffer.last = '/' then
108            buffer.remove_last
109         end
110         i := buffer.last_index_of('/')
111         if i >= 0 then
112            buffer.shrink(i + 1, buffer.count)
113         end
114      end
115
116feature {ANY}
117   can_map_drive (source_notation: DIRECTORY_NOTATION; drive: STRING): BOOLEAN
118      do
119         --|*** We (c/sh)ould do better than nothing... <24/03/2005>
120      end
121
122   to_root (source_notation: DIRECTORY_NOTATION; drive: STRING)
123      do
124         check
125            False
126         end
127      end
128
129   to_default_root (directory: STRING)
130      do
131         directory.clear_count
132         directory.extend('/')
133      end
134
135   to_current_directory (directory: STRING)
136      do
137         directory.clear_count
138         directory.extend('.')
139      end
140
141feature {ANY}
142   is_case_sensitive: BOOLEAN True
143         --|*** Is it ? <FM-23/03/2003>
144
145   is_valid_path, is_valid_directory_path (path: STRING): BOOLEAN
146      do
147         --|*** Not nearly strict enough <FM-24/03/2003>
148         Result := not path.is_empty
149      end
150
151   is_valid_file_name (name: STRING): BOOLEAN
152      do
153         --|*** Not nearly strict enough <FM-24/03/2003>
154         Result := not name.is_empty
155      end
156
157   is_absolute_path (path: STRING): BOOLEAN
158      do
159         Result := path.first = '/'
160      end
161
162feature {DIRECTORY_NOTATION}
163   to_notation (path: STRING; destination_notation: DIRECTORY_NOTATION): STRING
164      do
165         not_yet_implemented
166      end
167
168end -- class CYGWIN_DIRECTORY_NOTATION
169--
170-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
171--
172-- Permission is hereby granted, free of charge, to any person obtaining a copy
173-- of this software and associated documentation files (the "Software"), to deal
174-- in the Software without restriction, including without limitation the rights
175-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
176-- copies of the Software, and to permit persons to whom the Software is
177-- furnished to do so, subject to the following conditions:
178--
179-- The above copyright notice and this permission notice shall be included in
180-- all copies or substantial portions of the Software.
181--
182-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
183-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
184-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
185-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
186-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
187-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
188-- THE SOFTWARE.