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
223
224
225
|
include "display/curses.h"
include "screen.h"
# BOOL_PROMPT -- Get a yes or no response from the user
bool procedure bool_prompt (msg)
char msg[ARB] # i: message to print in the prompt area
#--
int index
pointer sp, resp, msg2
string yorn "|yes|no|"
int strdic()
begin
# Allocate memory for temporary strings
call smark (sp)
call salloc (resp, SZ_FNAME, TY_CHAR)
call salloc (msg2, SZ_LINE, TY_CHAR)
# Prompt the user for a response
call read_prompt (msg, Memc[resp], SZ_FNAME)
call strlwr (Memc[resp])
# See if the response is yes or no,
# if it isn't, keep asking
index = strdic (Memc[resp], Memc[resp], SZ_FNAME, yorn)
while (index == 0) {
call strcpy ("Please answer yes or no. ", Memc[msg2], SZ_LINE)
call strcat (msg, Memc[msg2], SZ_LINE)
call read_prompt (Memc[msg2], Memc[resp], SZ_FNAME)
call strlwr (Memc[resp])
index = strdic (Memc[resp], Memc[resp], SZ_FNAME, yorn)
}
# Convert result into boolean value
call sfree (sp)
return (index == 1)
end
# CLEAR_PROMPT -- Clear the prompt window
procedure clear_prompt (scr)
pointer scr # i: Currently active screen
#--
int win
int prompt_window()
begin
win = prompt_window ()
call werase (win)
if (scr != NULL)
call focus_window (TED_WINDOW(scr))
end
# ERR1_PROMPT -- Write an error message in the prompt area of the screen
procedure err1_prompt (msg)
char msg[ARB] # i: Message to write
#--
begin
call eprintf ("\r\n")
call error (1, msg)
end
# ERR2_PROMPT -- Write two error messages in the prompt area of the screen
procedure err2_prompt (msg1, msg2)
char msg1[ARB] # i: First message to write
char msg2[ARB] # i: Second message to write
#--
pointer msg
begin
call salloc (msg, SZ_LINE, TY_CHAR)
call sprintf (Memc[msg], SZ_LINE, "%s (%s)")
call pargstr (msg1)
call pargstr (msg2)
call eprintf ("\r\n")
call error (1, Memc[msg])
end
# HELP_PROMPT -- Write help message in prompt area
procedure help_prompt (scr, bell)
pointer scr # i: Screen descriptor
int bell # i: Ring the bell after printing message?
#--
pointer sp, exit, msg
string helpfmt "Type %s quit to leave editor, %s help for help."
begin
call smark (sp)
call salloc (exit, SZ_FNAME, TY_CHAR)
call salloc (msg, SZ_LINE, TY_CHAR)
call k_eseq ("EXIT_UPDATE", Memc[exit], SZ_FNAME)
call sprintf (Memc[msg], SZ_LINE, helpfmt)
call pargstr (Memc[exit])
call pargstr (Memc[exit])
call write_prompt (scr, bell, Memc[msg])
call sfree (sp)
end
# READ_PROMPT -- Read a string from the prompt area of the screen
procedure read_prompt (msg, str, maxch)
char msg[ARB] # i: Prompt message
char str[ARB] # o: Output string
int maxch[ARB] # i: Maximum length of output string
#--
char blank
int win
data blank / ' ' /
int prompt_window()
begin
# Write message in prompt window
win = prompt_window ()
call werase (win)
call wmove (win, 2, 1)
call waddstr (win, msg)
call waddch (win, blank)
# Read string from prompt window
call wgetstr (win, str, maxch)
call werase (win)
end
# WARN1_PROMPT -- Write a warning message in the prompt area of the screen
procedure warn1_prompt (scr, msg)
pointer scr # i: Currently active screen
char msg[ARB] # i: Message to write
#--
begin
call write_prompt (scr, YES, msg)
end
# WARN2_PROMPT -- Write two warning messages in the prompt area of the screen
procedure warn2_prompt (scr, msg1, msg2)
pointer scr # i: Currently active screen
char msg1[ARB] # i: First message to write
char msg2[ARB] # i: Second message to write
#--
pointer sp, msg
begin
call smark (sp)
call salloc (msg, SZ_LINE, TY_CHAR)
call sprintf (Memc[msg], SZ_LINE, "%s (%s)")
call pargstr (msg1)
call pargstr (msg2)
call write_prompt (scr, YES, Memc[msg])
call sfree (sp)
end
# WRITE_PROMPT -- Write a message in the prompt area of the screen
procedure write_prompt (scr, bell, msg)
pointer scr # i: Currently active screen
int bell # i: Ring bell after writing message?
char msg[ARB] # i: Message to write
#--
int win
int prompt_window()
begin
# Write message in prompt window
win = prompt_window ()
call werase (win)
call wmove (win, 2, 1)
call waddstr (win, msg)
# Ring the bell to wake up the user
if (bell == YES)
call ring_bell
# Restore cursor to original screen position
if (scr != NULL)
call focus_window (TED_WINDOW(scr))
end
|