-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_io.adb
222 lines (164 loc) · 9.28 KB
/
my_io.adb
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with sim_bits; use sim_bits;
package body my_io is
-- These two variables are used to reset the cursor position
-- after displaying the line
oldCol : Positive_Count := 1;
oldRow : Positive_Count := 1;
dummy : character := ' ';
------------------------------------------------------------------------------
Task body Display is
begin
-- This procedure handles all the messages to the screen;
loop
select
accept CLS do
-- Clears the screen
Ada.Text_IO.Put (ASCII.ESC & "[2J");
oldCol := 1;
oldRow := 1;
end CLS;
or -- select
accept DisplayLogMsg (s : in string) do
-- Ada.Text_IO.Put_Line ("Debug : " & s);
Ada.Text_IO.Put ("");
end DisplayLogMsg;
or -- select
accept DisplayString (s : in string; row : in Positive_Count; col : in Positive_Count) do
-- Displays strings to the screen at the correct location.
-- Trace (my_io_stream, "DisplayString (Str : col : "+x+", row : "+y +")");
Ada.Text_IO.Set_Col (col);
Ada.Text_IO.Set_Line (row);
Ada.Text_IO.Put_Line (s);
end DisplayString;
or -- select
accept DisplayChar (c : in character; row : in Positive_Count; col : in Positive_Count) do
-- Displays characters to the screen at the correct location.
Ada.Text_IO.Set_Col (col);
Ada.Text_IO.Set_Line (row);
Ada.Text_IO.Put (c);
end DisplayChar;
or -- select
accept DisplayInt (i, len : in integer; row : in Positive_Count; col : in Positive_Count) do
-- Displays integers to the screen at the correct location.
Ada.Text_IO.Set_Col (col);
Ada.Text_IO.Set_Line (row);
Ada.Integer_Text_IO.Put (i); -- i is the number, len is the length - to avoid spurios spaces.
end DisplayInt;
or -- select
accept DisplayTime (h, m, s : in integer; row : in Positive_Count; col : in Positive_Count) do
-- Displays the time to the screen at the correct location.
oldCol := Ada.Text_IO.Col;
oldRow := Ada.Text_IO.Line;
Ada.Text_IO.Set_Col (col); -- Moves the cursor to the correct position that the clock will be displayed.
Ada.Text_IO.Set_Line (row);
if (h < 10) then -- if the hours are less than ten a zero is put in front of the digit
Ada.Text_IO.Put ("0"); -- else the hours are displayed as input - needed to achieve the
Ada.Integer_Text_IO.Put (h); -- correct format
else
Ada.Integer_Text_IO.Put (h);
end if;
Ada.Text_IO.Put (":");
if (m < 10) then -- if the minutes are less than ten a zero is put in front of the
Ada.Text_IO.Put ("0"); -- digit else the minutes are displayed as input - needed to achieve the
Ada.Integer_Text_IO.Put (m); -- correct format
else
Ada.Integer_Text_IO.Put (m);
end if;
Ada.Text_IO.Put (":");
if (m < 10) then -- if the seconds are less than ten a zero is put in front of the
Ada.Text_IO.Put ("0"); -- digit else the seconds are displayed as input - needed to achieve the
Ada.Integer_Text_IO.Put (s); -- correct format
else
Ada.Integer_Text_IO.Put (s);
end if;
Ada.Text_IO.Set_Col (oldCol);
Ada.Text_IO.Set_Line (oldRow);
end DisplayTime;
or -- select
accept Pause (s : in string; row : in Positive_Count; col : in Positive_Count) do
Ada.Text_IO.Set_Col (col);
Ada.Text_IO.Set_Line (row);
Ada.Text_IO.Put ( s);
Ada.Text_IO.Get (dummy);
end Pause;
or -- select
terminate;
end select;
end loop;
exception
when tasking_error => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put("Tasking Error in Display");
when program_error => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Program Error in Display");
when storage_error => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Storage Error in Display");
when numeric_error => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Numeric Error in Display");
-- when constraint_error => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Constraint Error in Display");
when others => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Other Error in Display");
end Display;
------------------------------------------------------------------------------
Task body Input is
begin
-- This procedure handles all the messages to the screen;
loop
select
accept InputString (s : out string; row : in Positive_Count; col : in Positive_Count) do
-- Inputs strings from the keyboard at the correct screen location.
Ada.Text_IO.Set_Col (col);
Ada.Text_IO.Set_Line (row);
s := Get_String;
end InputString;
or
terminate;
end select;
end loop;
exception
when tasking_error => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Tasking Error in Input");
when program_error => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Program Error in Input");
when storage_error => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Storage Error in Input");
when numeric_error => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Numeric Error in Input");
-- when constraint_error => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Constraint Error in Input ");
when others => Ada.Text_IO.Set_Col (1);Ada.Text_IO.Set_Line (24); Ada.Text_IO.Put ("Other Error in Input");
end Input;
-------------------------------------------------------------------------------
Task body FileInOut is
begin
loop
select
accept Create (file : in out File_Type ; s : in string) do
Ada.Text_IO.Create(File => file,
Mode => Out_File,
Name => s);
end Create;
or
accept Put_Str (file : in File_Type; s : in string) do
Ada.Text_IO.put (File => file, Item => s);
Ada.Text_IO.Flush;
end Put_Str;
or
accept Put_Int (file : in File_Type; i,len : in integer) do
Ada.Text_IO.put (File => file, Item => Integer'Image(i));
end Put_Int;
or
accept Put_Line (file : in File_Type) do
Ada.Text_IO.New_Line (File => file);
Ada.Text_IO.Flush;
end Put_Line;
or
accept Close (file : in out File_Type) do
Ada.Text_IO.Flush;
Ada.Text_IO.close (File => file);
end Close;
or
terminate;
end select;
end loop;
exception
when tasking_error => Ada.Text_IO.Set_Col (24);Ada.Text_IO.Set_Line (1); Ada.Text_IO.Put ("Tasking Error in FileInOut");
when program_error => Ada.Text_IO.Set_Col (24);Ada.Text_IO.Set_Line (1); Ada.Text_IO.Put ("Program Error in FileInOut");
when storage_error => Ada.Text_IO.Set_Col (24);Ada.Text_IO.Set_Line (1); Ada.Text_IO.Put ("Storage Error in FileInOut");
when numeric_error => Ada.Text_IO.Set_Col (24);Ada.Text_IO.Set_Line (1); Ada.Text_IO.Put ("Numeric Error in FileInOut");
-- when constraint_error => Ada.Text_IO.Set_Col (24);Ada.Text_IO.Set_Line (1); Ada.Text_IO.Put ("Constraint Error in FileInOut");
when others => Ada.Text_IO.Set_Col (24);Ada.Text_IO.Set_Line (1); Ada.Text_IO.Put ("Other Error in FileInOut");
end FileInOut;
------------------------------------------------------------------------------
end my_io;