/tutorial/basic_directory/example6.e

http://github.com/tybor/Liberty · Specman e · 58 lines · 49 code · 5 blank · 4 comment · 1 complexity · 18ce2440fad3acf73691cbd5db191f5d MD5 · raw file

  1. class EXAMPLE6
  2. --
  3. -- This example shows how to create a new directory, how to change
  4. -- the current working directory.
  5. --
  6. create {ANY}
  7. make
  8. feature {}
  9. make
  10. local
  11. directory_path: STRING; basic_directory: BASIC_DIRECTORY
  12. do
  13. basic_directory.connect_to_current_working_directory
  14. directory_path := basic_directory.last_entry.twin
  15. basic_directory.disconnect
  16. io.put_string("Initial working directory is %"")
  17. io.put_string(directory_path)
  18. io.put_string("%".%N")
  19. basic_directory.compute_parent_directory_of(directory_path)
  20. directory_path := basic_directory.last_entry.twin
  21. basic_directory.change_current_working_directory(directory_path)
  22. if basic_directory.last_entry.is_empty then
  23. io.put_string("Unable to change working directory to %"")
  24. io.put_string(directory_path)
  25. io.put_string("%".%N")
  26. die_with_code(exit_failure_code)
  27. end
  28. basic_directory.connect_to_current_working_directory
  29. directory_path := basic_directory.last_entry.twin
  30. io.put_string("New working directory is %"")
  31. io.put_string(directory_path)
  32. io.put_string("%".%N")
  33. display_content_of(basic_directory)
  34. end
  35. display_content_of (basic_directory: BASIC_DIRECTORY)
  36. require
  37. basic_directory.is_connected
  38. do
  39. from
  40. basic_directory.read_entry
  41. until
  42. basic_directory.end_of_input
  43. loop
  44. io.put_character('%T')
  45. io.put_string(basic_directory.last_entry)
  46. io.put_character('%N')
  47. basic_directory.read_entry
  48. end
  49. basic_directory.disconnect
  50. ensure
  51. not basic_directory.is_connected
  52. end
  53. end -- class EXAMPLE6