/tutorial/basic_directory/example3.e

http://github.com/tybor/Liberty · Specman e · 56 lines · 45 code · 6 blank · 5 comment · 3 complexity · dce05798b696ab71c424a7434ff696e5 MD5 · raw file

  1. class EXAMPLE3
  2. --
  3. -- This example shows how to compute parent directories path starting
  4. -- from some given path as an argument or from the current working
  5. -- directory.
  6. --
  7. insert
  8. ARGUMENTS
  9. create {ANY}
  10. make
  11. feature {}
  12. basic_directory: BASIC_DIRECTORY
  13. make
  14. local
  15. some_path: STRING
  16. do
  17. if argument_count > 1 then
  18. io.put_string("usage : example3 [<some_path>]%N")
  19. elseif argument_count = 1 then
  20. some_path := argument(1).twin
  21. go_up_from(some_path)
  22. else
  23. basic_directory.connect_to_current_working_directory
  24. if basic_directory.is_connected then
  25. some_path := basic_directory.last_entry.twin
  26. basic_directory.disconnect
  27. go_up_from(some_path)
  28. end
  29. end
  30. end
  31. go_up_from (some_path: STRING)
  32. local
  33. stop: BOOLEAN
  34. do
  35. from
  36. until
  37. stop
  38. loop
  39. io.put_string("%"")
  40. io.put_string(some_path)
  41. io.put_string("%"%N")
  42. basic_directory.compute_parent_directory_of(some_path)
  43. if basic_directory.last_entry.is_empty then
  44. stop := True
  45. else
  46. some_path.copy(basic_directory.last_entry)
  47. end
  48. end
  49. end
  50. end -- class EXAMPLE3