File: command.e

package info (click to toggle)
smarteiffel 1.1-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 12,288 kB
  • ctags: 40,785
  • sloc: ansic: 35,791; lisp: 4,036; sh: 1,783; java: 895; ruby: 613; python: 209; makefile: 115; csh: 78; cpp: 50
file content (137 lines) | stat: -rw-r--r-- 2,648 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
class COMMAND
   --
   -- To separate Handling of Keyboard Input.
   --

creation make

feature 

   arrival: BOOLEAN is
      do
         Result := (code = c_arrival)
      end

   departure: BOOLEAN is
      do
         Result := (code = c_departure)
      end
   
   level_count: BOOLEAN is
      do
         Result := (code = c_level_count)
      end
   
   hour_price: BOOLEAN is
      do
         Result := (code = c_hour_price)
      end
   
   add_time: BOOLEAN is
      do
         Result := (code = c_add_time)
      end
   
   clock: BOOLEAN is
      do
         Result := (code = c_clock)
      end
   
   quit: BOOLEAN is
      do
         Result := (code = c_quit)
      end
   
   help: BOOLEAN is
      do
         Result := (code = c_help)
      end
   
   arg_real: REAL is
      do
	 if cmd.is_real then
	    Result := cmd.to_real
	 else
	    io.put_string("Real expected: %"" + cmd + "%"%N")
	 end
      end
   
   arg_integer: INTEGER is
      do
	 if cmd.is_integer then
	    Result := cmd.to_integer
	 else
	    io.put_string("Integer expected: %"" + cmd + "%"%N")
	 end
      end
   
   count: BOOLEAN is
      do
         Result := (code = c_count)
      end
   
feature -- Modifications:

   make is
      do
      end
   
   get_command(sio: STD_INPUT_OUTPUT) is
      require
         sio /= Void
      local
         stop: BOOLEAN
      do
         sio.read_line
         cmd := sio.last_string
         from
            code := ' '
            stop := (cmd.count < 1)
         until
            stop
         loop
            code := cmd @ 1
            cmd.remove(1)
            stop := ((code /= ' ') and (code /= '%T')) or (cmd.count < 1)
         end
      end

   print_help_on(sio: STD_INPUT_OUTPUT) is
      require
         sio /= Void
      do
         sio.put_string("[
            Commands:
            -------------------
            q        Quit
            a        Arrival of a car
            d <i>    Departure of car number <i>
            l <i>    number of car at Level <i>
            h <x>    set Hour price with <x>
            c        total Count of cars
            t <i>    add Time <i> minutes
            T        current Time
            ?        help

                         ]")
      end
   
feature {COMMAND}
   
   c_arrival : CHARACTER is 'a'
   c_departure : CHARACTER is 'd'
   c_level_count : CHARACTER is 'l'
   c_hour_price : CHARACTER is 'h'
   c_add_time : CHARACTER is 't'
   c_clock : CHARACTER is 'T'
   c_quit : CHARACTER is 'q'
   c_count : CHARACTER is 'c'
   c_help : CHARACTER is '?'
   
   code : CHARACTER
   
feature {NONE}
   
   cmd: STRING
   
end -- COMMAND