/tutorial/basic_directory/example2.e

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

  1. class EXAMPLE2
  2. --
  3. -- This example shows how to list the contents of a directory
  4. -- using low level class BASIC_DIRECTORY.
  5. --
  6. insert
  7. ARGUMENTS
  8. create {ANY}
  9. make
  10. feature {}
  11. make
  12. do
  13. if argument_count /= 1 then
  14. io.put_string("usage : example2 <directory_name>%N")
  15. else
  16. list_directory(argument(1))
  17. end
  18. end
  19. list_directory (path: STRING)
  20. local
  21. basic_directory: BASIC_DIRECTORY
  22. do
  23. io.put_string("Trying to list %"")
  24. io.put_string(path)
  25. io.put_string("%".%N")
  26. basic_directory.connect_to(path)
  27. if basic_directory.is_connected then
  28. display_content_of(basic_directory)
  29. else
  30. io.put_string("Unable to open directory %"")
  31. io.put_string(path)
  32. io.put_string("%".%N")
  33. -- Attempt to connect to the parent directory of `path' :
  34. basic_directory.connect_with(path)
  35. if basic_directory.is_connected then
  36. io.put_string("Trying to list %"")
  37. io.put_string(basic_directory.last_entry)
  38. io.put_string("%".%N")
  39. display_content_of(basic_directory)
  40. end
  41. end
  42. end
  43. display_content_of (basic_directory: BASIC_DIRECTORY)
  44. require
  45. basic_directory.is_connected
  46. do
  47. from
  48. basic_directory.read_entry
  49. until
  50. basic_directory.end_of_input
  51. loop
  52. io.put_character('%T')
  53. io.put_string(basic_directory.last_entry)
  54. io.put_character('%N')
  55. basic_directory.read_entry
  56. end
  57. basic_directory.disconnect
  58. ensure
  59. not basic_directory.is_connected
  60. end
  61. end -- class EXAMPLE2