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

/tutorial/basic_directory/example4.e

http://github.com/tybor/Liberty
Specman e | 77 lines | 64 code | 7 blank | 6 comment | 7 complexity | f303079593bd62d2efad00d433dc4f7f MD5 | raw file
 1class EXAMPLE4
 2   --
 3   -- This example shows how to traverse recursively some readable
 4   -- directory (starting point is computed either from current working
 5   -- directory or from some directory path given as an argument).
 6   --
 7
 8insert
 9   ARGUMENTS
10
11create {ANY}
12   make
13
14feature {}
15   make
16      local
17         some_path: STRING; basic_directory: BASIC_DIRECTORY
18      do
19         if argument_count > 1 then
20            io.put_string("usage : example4 [<some_path>]%N")
21         elseif argument_count = 1 then
22            some_path := argument(1).twin
23            recursive_list_of(some_path)
24         else
25            basic_directory.connect_to_current_working_directory
26            if basic_directory.is_connected then
27               some_path := basic_directory.last_entry.twin
28               basic_directory.disconnect
29               recursive_list_of(some_path)
30            end
31         end
32         io.put_string("Total visited places count is ")
33         io.put_integer(already_visited_places.count)
34         io.put_string("%N.")
35      end
36
37   already_visited_places: ARRAY[STRING]
38      once
39         create Result.with_capacity(1, 32)
40      end
41
42   recursive_list_of (some_path: STRING)
43      local
44         file_tools: FILE_TOOLS
45         basic_directory: BASIC_DIRECTORY; some_entry, another_path: STRING
46      do
47         if not already_visited_places.has(some_path) then
48            io.put_string("Visiting %"")
49            io.put_string(some_path)
50            io.put_string("%"%N")
51            already_visited_places.add_last(some_path)
52            basic_directory.connect_to(some_path)
53            if basic_directory.is_connected then
54               from
55                  basic_directory.read_entry
56               until
57                  basic_directory.end_of_input
58               loop
59                  some_entry := basic_directory.last_entry.twin
60                  if some_entry.is_empty or else some_entry.first = '.' then
61                     -- skip
62                  else
63                     basic_directory.compute_subdirectory_with(some_path, some_entry)
64                     if not basic_directory.last_entry.is_empty and then file_tools.is_directory(basic_directory.last_entry) then
65                        another_path := basic_directory.last_entry.twin
66                        recursive_list_of(another_path)
67                     end
68                  end
69
70                  basic_directory.read_entry
71               end
72               basic_directory.disconnect
73            end
74         end
75      end
76
77end -- class EXAMPLE4