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

/tutorial/directory/example1.e

http://github.com/tybor/Liberty
Specman e | 70 lines | 54 code | 7 blank | 9 comment | 3 complexity | 5df469a6c75f0ae74b63d738d5ebe9a0 MD5 | raw file
 1class EXAMPLE1
 2   --
 3   -- This example shows how to list the contents of a directory
 4   -- using class DIRECTORY.
 5   -- When no argument is given in the command line, the current working
 6   -- directory is listed.
 7   --
 8   --       compile -o run_it example1
 9   --       run_it some_directory_path
10   --
11
12insert
13   ARGUMENTS
14
15create {ANY}
16   make
17
18feature {}
19   make
20      local
21         directory: DIRECTORY; some_path: STRING
22      do
23         if argument_count > 1 then
24            io.put_string("usage : example1 [<some_path>]%N")
25         elseif argument_count = 1 then
26            some_path := argument(1)
27            create directory.scan(some_path)
28
29            if directory.exists then
30               list_directory(directory)
31            else
32               io.put_string("Unable to open directory %"")
33               io.put_string(some_path)
34               io.put_string("%".%N")
35            end
36         else
37            io.put_string("Scanning current working directory.%N")
38            create directory.scan_current_working_directory
39            list_directory(directory)
40         end
41      end
42
43   list_directory (directory: DIRECTORY)
44      local
45         i: INTEGER
46      do
47         io.put_string("Printing content of %"")
48         io.put_string(directory.path)
49         io.put_string("%".%N")
50         io.put_integer(directory.count)
51         io.put_string(" item(s) found:%N")
52         from
53            i := directory.lower
54         until
55            i > directory.count
56         loop
57            io.put_character('%T')
58            if directory.file_at(i).is_directory then
59               io.put_string(once "directory ")
60            else
61               io.put_string(once "file      ")
62            end
63
64            io.put_string(directory.item(i))
65            io.put_character('%N')
66            i := i + 1
67         end
68      end
69
70end -- class EXAMPLE1