/tutorial/basic_directory/example4.e

http://github.com/tybor/Liberty · Specman e · 77 lines · 64 code · 7 blank · 6 comment · 7 complexity · f303079593bd62d2efad00d433dc4f7f MD5 · raw file

  1. class EXAMPLE4
  2. --
  3. -- This example shows how to traverse recursively some readable
  4. -- directory (starting point is computed either from current working
  5. -- directory or from some directory path given as an argument).
  6. --
  7. insert
  8. ARGUMENTS
  9. create {ANY}
  10. make
  11. feature {}
  12. make
  13. local
  14. some_path: STRING; basic_directory: BASIC_DIRECTORY
  15. do
  16. if argument_count > 1 then
  17. io.put_string("usage : example4 [<some_path>]%N")
  18. elseif argument_count = 1 then
  19. some_path := argument(1).twin
  20. recursive_list_of(some_path)
  21. else
  22. basic_directory.connect_to_current_working_directory
  23. if basic_directory.is_connected then
  24. some_path := basic_directory.last_entry.twin
  25. basic_directory.disconnect
  26. recursive_list_of(some_path)
  27. end
  28. end
  29. io.put_string("Total visited places count is ")
  30. io.put_integer(already_visited_places.count)
  31. io.put_string("%N.")
  32. end
  33. already_visited_places: ARRAY[STRING]
  34. once
  35. create Result.with_capacity(1, 32)
  36. end
  37. recursive_list_of (some_path: STRING)
  38. local
  39. file_tools: FILE_TOOLS
  40. basic_directory: BASIC_DIRECTORY; some_entry, another_path: STRING
  41. do
  42. if not already_visited_places.has(some_path) then
  43. io.put_string("Visiting %"")
  44. io.put_string(some_path)
  45. io.put_string("%"%N")
  46. already_visited_places.add_last(some_path)
  47. basic_directory.connect_to(some_path)
  48. if basic_directory.is_connected then
  49. from
  50. basic_directory.read_entry
  51. until
  52. basic_directory.end_of_input
  53. loop
  54. some_entry := basic_directory.last_entry.twin
  55. if some_entry.is_empty or else some_entry.first = '.' then
  56. -- skip
  57. else
  58. basic_directory.compute_subdirectory_with(some_path, some_entry)
  59. if not basic_directory.last_entry.is_empty and then file_tools.is_directory(basic_directory.last_entry) then
  60. another_path := basic_directory.last_entry.twin
  61. recursive_list_of(another_path)
  62. end
  63. end
  64. basic_directory.read_entry
  65. end
  66. basic_directory.disconnect
  67. end
  68. end
  69. end
  70. end -- class EXAMPLE4