-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon3.pas
348 lines (317 loc) · 8.31 KB
/
common3.pas
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
{$A+,B-,D-,E-,F+,I-,L-,N-,O+,R-,S-,V-,X-}
unit common3;
interface
uses crt, dos, myio, common;
procedure inputdefault(var s:string; v:string; l:integer; flags:str8; lf:boolean);
procedure inputformatted(var NewString:string; Format:string; abortable:boolean);
procedure inu(var i:integer);
procedure ini(var i:byte);
procedure inputwn1(var v:string; l:integer; flags:str8; var changed:boolean);
procedure inputwn(var v:string; l:integer; var changed:boolean);
procedure inputwnwc(var v:string; l:integer; var changed:boolean);
procedure inputmain(var s:string; ml:integer; flags:str8);
procedure inputwc(var s:string; ml:integer);
procedure input(var s:string; ml:integer);
procedure inputl(var s:string; ml:integer);
procedure inputcaps(var s:string; ml:integer);
implementation
uses
common1, common2;
procedure inputdefault(var s:string; v:string; l:integer; flags:str8; lf:boolean);
var c:char;
i:byte;
begin
mpl(l);
mciallowed := FALSE;
colorallowed := FALSE;
prompt(v);
colorallowed := TRUE;
mciallowed := TRUE;
c := char(getkey);
if (c <> #13) then
begin
for i:=1 to length(v) do backspace;
buf := c + buf;
inputmain(s,l,flags);
if (s = '') then
begin
s := v;
prompt(s);
end
else
if (s = ' ') then
s := '';
end
else
begin
s:=v;
if (pos('L',allcaps(flags)) = 0) then
nl;
end;
UserColor(1);
if lf then nl;
end;
procedure inputformatted(var NewString:string; Format:string; abortable:boolean);
var
i,farback:byte;
c:char;
procedure updatestring;
begin
while (not (Format[i] in ['#','@']) and (i <= length(Format))) do
begin
outkey(Format[i]);
NewString := NewString + Format[i];
inc(i);
end;
end;
begin
NewString := '';
mpl(length(Format));
i := 1;
updatestring;
farback := i;
repeat
c := char(getkey);
if (i <= length(Format)) then
if ((Format[i] = '@') and (c in ['a'..'z','A'..'Z'])) or
((Format[i] = '#') and (c in ['0'..'9'])) then
begin
c := upcase(c);
outkey(c);
NewString := NewString + c;
inc(i);
updatestring;
end;
if (c = ^H) then
begin
while ((i > farback) and not (Format[i - 1] in ['#','@'])) do
begin
backspace;
dec(NewString[0]);
dec(i);
end;
if (i > farback) then
begin
backspace;
dec(NewString[0]);
dec(i);
end;
end;
until hangup or
((i > length(Format)) or (abortable)) and (c=#13);
nl;
end;
procedure inu(var i:integer);
var s:string[5];
begin
badini:=FALSE;
input(s,5); i:=value(s);
if (s='') then badini:=TRUE;
end;
procedure ini(var i:byte);
var s:string[3];
begin
badini:=FALSE;
input(s,3); i:=value(s);
if s='' then badini:=TRUE;
end;
procedure inputwn1(var v:string; l:integer; flags:str8; var changed:boolean);
var s:string;
begin
s := v;
inputmain(s,l,flags);
if (s = '') then
s := v;
if (s = ' ') then
if pynq('Blank string? ') then
s := ''
else
s := v;
if (s <> v) then changed:=TRUE;
v := s;
end;
procedure inputwn(var v:string; l:integer; var changed:boolean);
begin
inputwn1(v,l,'',changed);
end;
procedure inputwnwc(var v:string; l:integer; var changed:boolean);
begin
inputwn1(v,l,'c',changed);
end;
(* flags: "U" - Uppercase only
"C" - Colors allowed
"L" - Linefeeds OFF - no linefeed after <CR> pressed
"D" - Display old if no change
"P" - Capitalize characters
"I" - Interactive editing
*) {"V" - Input NotVisible}
procedure inputmain(var s:string; ml:integer; flags:str8);
var os:string;
is:string[2];
cp,cl:byte;
c:word;
InsertMode,xxupperonly,xxcolor,xxnolf,xxredisp,xxcaps,xxvisible:boolean;
i:byte;
procedure prompt(s:string);
begin
SerialOut(s);
if (wantout) then
write(s);
end;
procedure cursor_left;
begin
if not okavatar then
SerialOut(#27'[D')
else
SerialOut(^V^E);
if (wantout) then
gotoxy(WhereX - 1, WhereY);
end;
procedure cursor_right;
begin
outkey(s[cp]);
inc(cp);
end;
procedure setcursor(InsertMode:boolean);assembler;
asm
cmp InsertMode, 0
je @turnon
mov ch, 0
mov cl, 7
jmp @goforit
@turnon:
mov ch, 6
mov cl, 7
@goforit:
mov ah,1
int 10h
end;
begin
flags := allcaps(flags);
xxupperonly := (pos('U', flags) > 0);
xxcolor := (pos('C', flags) > 0);
xxnolf := (pos('L', flags) > 0);
xxredisp := (pos('D', flags) > 0);
xxcaps := (pos('P', flags) > 0);
{xxvisible := (pos('V', flags) > 0);}
if (pos('I', flags) = 0) or not (Okansi or OkAvatar) then
begin
s := '';
cp := 1;
cl := 0;
end
else
begin
cp := length(s); cl := length(s);
if cp = 0 then cp := 1;
prompt(s);
if (length(s) > 0) then
begin
cursor_left;
if (cp < ml) then cursor_right;
end;
end;
os:=s;
InsertMode := FALSE;
repeat
mlc:=s;
setcursor(InsertMode);
c := getkey;
case c of
8:if (cp > 1) then
begin
dec(cl);
dec(cp);
delete(s, cp, 1);
backspace;
if (cp < cl) then
begin
prompt(copy(s, cp, 255) + ' ');
for i := cp to cl+1 do
cursor_left;
end;
end;
24:begin
for i := cp to cl do
outkey(' ');
for i := 1 to cl do
backspace;
cl := 0; cp := 1;
end;
32..255:
begin
if (xxupperonly) then c := ord(upcase(char(c)));
if (xxcaps) then
if (cp > 1) then begin
if (s[cp - 1] in [#32..#64]) then
c := ord(upcase(char(c)))
else
if (c in [ord('A')..ord('Z')]) then inc(c, 32);
end else
c := ord(upcase(char(c)));
if ((InsertMode) and (cl < ml)) or
((not InsertMode) and (cp <= ml)) then
begin
outkey(char(c));
if (InsertMode) then
begin
is := char(c);
prompt(copy(s, cp, 255));
insert(is, s, cp);
for i := cp to cl do
cursor_left;
end
else
s[cp]:= char(c);
if (InsertMode) or (cp - 1 = cl) then
inc(cl);
inc(cp);
if (trapping) then write(trapfile, char(c));
end;
end;
F_END:while (cp < cl + 1) and (cp <= ml) do
cursor_right;
F_HOME:while (cp > 1) do
begin
cursor_left;
dec(cp);
end;
F_LEFT:if (cp > 1) then
begin
cursor_left;
dec(cp);
end;
F_RIGHT:if (cp <= cl) then
cursor_right;
F_INS:begin
InsertMode := not InsertMode;
setcursor(InsertMode);
end;
F_DEL:if (cp > 0) and (cp <= cl) then
begin
dec(cl);
delete(s, cp, 1);
prompt(copy(s, cp, 255) + ' ');
for i := cp to cl+1 do
cursor_left;
end;
end;
s[0] := chr(cl);
until (c = 13) or (hangup);
if ((xxredisp) and (s = '')) then begin
s := os;
prompt(s);
end;
if (not xxnolf) then nl;
mlc := '';
setcursor(FALSE);
end;
procedure inputwc(var s:string; ml:integer);
begin inputmain(s,ml,'c'); end;
procedure input(var s:string; ml:integer);
begin inputmain(s,ml,'u'); end;
procedure inputl(var s:string; ml:integer);
begin inputmain(s,ml,''); end;
procedure inputcaps(var s:string; ml:integer);
begin inputmain(s,ml,'p'); end;
end.