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