PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/basic_directory/example5.e

http://github.com/tybor/Liberty
Specman e | 102 lines | 90 code | 8 blank | 4 comment | 5 complexity | 592f566e40eae09886649dbd0fd1f4d9 MD5 | raw file
  1class EXAMPLE5
  2   --
  3   -- This example shows how to create a new directory, how to add files
  4   -- in this new created directory and finally how to remove it.
  5   --
  6
  7create {ANY}
  8   make
  9
 10feature {}
 11   make
 12      local
 13         directory_path, file_path: STRING; basic_directory: BASIC_DIRECTORY; text_file_write: TEXT_FILE_WRITE
 14      do
 15         basic_directory.connect_to_current_working_directory
 16         directory_path := basic_directory.last_entry.twin
 17         basic_directory.disconnect
 18         basic_directory.compute_subdirectory_with(directory_path, "foo")
 19         directory_path := basic_directory.last_entry.twin
 20         io.put_string("Trying to create a new directory (%"")
 21         io.put_string(directory_path)
 22         io.put_string("%").%N")
 23         basic_directory.connect_to(directory_path)
 24         if basic_directory.is_connected then
 25            io.put_string("This directory already exists (sorry).%N")
 26            basic_directory.disconnect
 27            die_with_code(exit_failure_code)
 28         end
 29
 30         if not basic_directory.create_new_directory(directory_path) then
 31            io.put_string("Unable to create this directory.%N")
 32            die_with_code(exit_failure_code)
 33         end
 34
 35         basic_directory.compute_file_path_with(directory_path, "bar")
 36         file_path := basic_directory.last_entry.twin
 37         io.put_string("Try to create a new file (%"")
 38         io.put_string(file_path)
 39         io.put_string("%").%N")
 40         create text_file_write.connect_to(file_path)
 41         if text_file_write.is_connected then
 42            text_file_write.disconnect
 43            io.put_string("File created.%N")
 44         else
 45            io.put_string("Unable to create this file.%N")
 46            die_with_code(exit_failure_code)
 47         end
 48
 49         list_directory(directory_path)
 50         io.put_string("Removing file %"")
 51         io.put_string(file_path)
 52         io.put_string("%".%N")
 53         (create {FILE_TOOLS}).delete(file_path)
 54         if basic_directory.remove_directory(directory_path) then
 55            io.put_string("Directory %"")
 56            io.put_string(directory_path)
 57            io.put_string("%" is removed.%N")
 58         else
 59            io.put_string("Unable to remove directory %"")
 60            io.put_string(directory_path)
 61            io.put_string("%".%N")
 62         end
 63      end
 64
 65   list_directory (path: STRING)
 66      local
 67         basic_directory: BASIC_DIRECTORY
 68      do
 69         io.put_string("Trying to list %"")
 70         io.put_string(path)
 71         io.put_string("%".%N")
 72         basic_directory.connect_to(path)
 73         if basic_directory.is_connected then
 74            display_content_of(basic_directory)
 75         else
 76            io.put_string("Unable to open directory %"")
 77            io.put_string(path)
 78            io.put_string("%".%N")
 79            die_with_code(exit_failure_code)
 80         end
 81      end
 82
 83   display_content_of (basic_directory: BASIC_DIRECTORY)
 84      require
 85         basic_directory.is_connected
 86      do
 87         from
 88            basic_directory.read_entry
 89         until
 90            basic_directory.end_of_input
 91         loop
 92            io.put_character('%T')
 93            io.put_string(basic_directory.last_entry)
 94            io.put_character('%N')
 95            basic_directory.read_entry
 96         end
 97         basic_directory.disconnect
 98      ensure
 99         not basic_directory.is_connected
100      end
101
102end -- class EXAMPLE5