PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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