forked from MarkHofmann11/WWIVEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWEINPUT.BAK
488 lines (453 loc) · 10.5 KB
/
WEINPUT.BAK
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
UNIT WEInput;
{$I WEGLOBAL.PAS}
{ -- This is the Input Module of WWIVEdit 2.3
-- Last Modified: 4/15/92
-- Written By:
-- Adam Caldwell
--
-- This code is limited Public Domain (see WWIVEDIT.PAS for more details)
--
-- Purpose : Encapsulate as much of the input as possible
--
-- Known Errors : None
--
-- Planned Enhancements : None
-- }
INTERFACE
USES WEVars;
VAR
actual:boolean; {Very hacky way of doing something}
FUNCTION GetKey(QuickTimeout:BOOLEAN):char;
FUNCTION GetControlLine:String;
FUNCTION ReadSet(s:charset):char;
FUNCTION ReadSet1(s:charset):char;
FUNCTION GetArrow : Edfun;
FUNCTION GetFun(VAR s:string; VAR F:edfun; VAR any:boolean):boolean;
FUNCTION Yn : boolean;
PROCEDURE SimpleInput(VAR s:string;{ Allows user to input a string of }
maxlength:integer); { MaxLength Characters }
FUNCTION CheckAbort:boolean; { Returns True if SPACE is pressed, will }
{ pause if P or Ctrl-S is pressed }
PROCEDURE WWIVEditMacro(ch:char);
FUNCTION LineEditor(VAR l:Linetype;
x,y,cx,maxlen:integer;
AllowColorChange:boolean):boolean;
PROCEDURE pausescr;
IMPLEMENTATION
USES WETime, WEKbd, WEOutput, WEDos, WEString, WELine, WEChat, WEFunc,
WEMemory, WEMouse,WEEsm;
FUNCTION CheckAbort:Boolean;
VAR
cc:char;
BEGIN
IF KeyPressed THEN
BEGIN
cc:=upcase(ReadKey);
IF (cc = 'P') OR (cc = ^S) THEN
BEGIN
cc := readkey;
cc := #0;
END;
CheckAbort:=(CC=' ');
END
ELSE CheckAbort:=FALSE;
END;
PROCEDURE SimpleInput(VAR s : string; maxlength : integer);
VAR
ch : char;
BEGIN
s:='';
REPEAT
REPEAT
LocationOverride:=FALSE;
ch := GetKey(False);
UNTIL NOT LocationOverride;
IF (ch IN [#32..#255]-[#127]) AND (length(s)<=maxlength) THEN
BEGIN
s:=s+ch;
write(ch);
END
ELSE
CASE ch OF
#8,#127 : IF Length(s)>0 THEN
BEGIN
write(#8#32#8);
delete(s,length(s),1);
END;
^X, ^U : WHILE s<>'' DO
BEGIN
write(#8#32#8);
delete(s,length(s),1);
END;
END;
UNTIL (ch = #13);
nl;
END;
FUNCTION GetFun(VAR s:string; VAR F:edfun; VAR any:boolean):boolean;
VAR
i:integer;
c : integer;
l : integer;
p : integer;
BEGIN
c:=0;
any:=false;
l:=length(s);
p:=1;
f:=None;
FOR i:=1 to NBindings DO
BEGIN
IF s = copy(KeyBindingP(@KeyBindings^[p])^.keys,1,l) THEN
BEGIN
inc(c);
any:=true;
IF l = Length(KeyBindingP(@KeyBindings^[p])^.keys) THEN
BEGIN
F:=KeyBindingP(@KeyBindings^[p])^.Fun;
END
END;
p:=p+sizeof(EdFun)+Length(KeyBindingP(@KeyBindings^[p])^.keys)+1;
END;
IF Setting.mouse AND MouseInstalled AND LocationOverride THEN BEGIN
Any:=TRUE;
F:=Mouse;
c:=1;
END;
IF (any=FALSE) AND (l=1) THEN BEGIN
F:=InsertChar;
GetFun:=True;
END
ELSE IF (c=1) THEN GetFun:=True
ELSE GetFun:=False;
END;
procedure make_app_idle;
var regs : registers;
begin
regs.ax := $1680;
intr($2f,regs);
intr($2f,regs);
end;
FUNCTION GetKey(QuickTimeout:boolean):CHAR;
VAR
warned : boolean;
ch : char;
Ticks : integer;
Mouse,count,x,y : word;
BEGIN
IF NOT QuickTimeout THEN BeforeNext;
Ticks:=0;
mouse:=0;
actual:=true;
LastKey := timer;
Warned:=false;
count:=0;
make_app_idle;
IF NOT KeyPressed THEN
REPEAT
inc(ticks);
IF (Setting.ChatMask<>0) AND
((KeyStatusFlag AND Setting.ChatMask)=Setting.ChatMask) THEN
BEGIN
Chat(LineLen,ScreenHeight);
LastKey:=Timer;
Warned:=False;
END;
IF (Setting.DosMask<>0) AND
((KeyStatusFlag AND Setting.DosMask)=Setting.DOSMask) THEN
JumpDos;
IF LastKey>Timer THEN LastKey:=0; {Special case for midnight }
IF (Not warned) AND (setting.warntime>0) AND (Timer-Lastkey>Setting.WarnTime) THEN
BEGIN
warned := TRUE;
write(#7#7#7);
END;
IF Setting.Mouse AND MouseInstalled THEN Mouse:=MousePress(0,count,x,y);
make_app_idle;
UNTIL (KeyPressed) OR
(QuickTimeout AND (Ticks>ESC_ticks)) OR
(count<>0) OR (Mouse<>0) OR
(Setting.DisconnectTime>0) AND (Timer-Lastkey>Setting.DisconnectTime);
IF (count>0) OR (Mouse<>0) THEN BEGIN
IF (Mouse=1) AND (count=0) THEN
Mouse:=MousePosition(X,Y);
LocationOverride:=TRUE;
LocationOverride_X:=x;
LocationOverride_Y:=y;
GetKey:=screenbuff(Display^)[y][x].c;
END
ELSE IF KeyPressed THEN
GetKey:=ReadKey
ELSE IF QuickTimeout THEN
BEGIN
GetKey:=#0;
actual:=false;
END
ELSE BEGIN
clrscr;
XWriteln(55);
MemCleanup;
Halt
END;
IF NOT QuickTimeout THEN AfterNext;
END;
FUNCTION GetControlLine:String;
{ Allows user to input a line, and shows all "control" characters as inverted }
VAR
s:string;
ch:char;
BEGIN
s:='';
StatusLine2(C0);
REPEAT
ch:=GetKey(false);
IF not (ch in [^H,^Z]) THEN
BEGIN
s:=s+ch;
IF ch<#32
THEN WriteControl(ch)
ELSE write(ch);
END
ELSE IF (length(s)>0) AND (ch=^H) THEN
BEGIN
delete(s,length(s),1);
write(#8#32#8);
END;
UNTIL (ch=^Z) OR (length(s)=80);
GetControlLine:=s;
END;
FUNCTION ReadSet(s:charset):char;
{ Waits for a key from user, until user presses a key in the set S }
VAR
ch:char;
BEGIN
ch:=ReadSet1(s);
IF ch IN [#32..#127] THEN write(ch);
ReadSet:=ch;
END;
FUNCTION ReadSet1(s:charset):char;
{ Waits for a key from user, until user presses a key in the set S }
VAR
ch:char;
Mouse,count,x,y:word;
BEGIN
REPEAT
ch:=upcase(GetKey(false));
IF LocationOverride THEN
BEGIN
REPEAT
LocationOverride:=False;
Mouse:=MouseRelease(0,count,x,y);
UNTIL Count>0;
ch:=upcase(Screenbuff(Display^)[y][x].c)
END;
UNTIL Ch IN s;
ReadSet1:=ch;
END;
FUNCTION GetArrow:EdFun;
VAR
s:string;
ch:char;
Fun : Edfun;
any,done:boolean;
BEGIN
REPEAT
s:='';
REPEAT
IF (length(s)>0) AND (pos(s[1],Escaped)>0) THEN
BEGIN
ch:=GetKey(TRUE);
IF (Actual) then s:=s+ch;
Done:=GetFun(s,fun,any) OR ((NOT Actual) AND (Fun<>None));
END ELSE BEGIN
ch:=GetKey(FALSE);
s:=s+ch;
Done := GetFun(s,fun,any);
END;
IF (Not Any) THEN s:=''
UNTIL Done;
s:='';
UNTIL (NOT (Fun IN [InsertChar,None])) OR NOT Any AND ((ch='Q') or (ch='q'));
GetArrow:=Fun;
END;
FUNCTION yn : boolean;
VAR c : char;
BEGIN
ansic('1');
c:=ReadSet(['Y','N',#13]);
IF (c = 'Y') OR (c=#13) THEN
BEGIN
IF c='Y' THEN writeln('es') ELSE writeln('Yes');
yn := true;
END ELSE
BEGIN
writeln('o');
yn := false;
END;
END;
PROCEDURE pausescr;
VAR
ch:char;
mouse,count,x,y:word;
BEGIN
write(C3+PausePrompt);
MoveLeft(lengthw(PausePrompt));
ch:=GetKey(False);
IF LocationOverride THEN
REPEAT
LocationOverride:=False;
Mouse:=MouseRelease(0,count,x,y);
UNTIL Count>0;
clreol;
END;
PROCEDURE WWIVEditMacro(ch:char);
VAR
s,s1:string;
r:ExtTrans;
t,t1:text;
i:integer;
BEGIN
reset(transtable);
seek(transtable,ord(ch));
read(transtable,r);
close(transtable);
s:='';
IF r[1]<>#0 THEN
BEGIN
s:=s+r[1]+r[2]+r[3];
IF r[2]=#0 THEN s[0]:=#1
ELSE if r[3]=#0 THEN s[0]:=#2;
END;
IF s<>'' THEN
BEGIN
assign(t,StartupDir+'MACROS.LCL');
reset(t);
WHILE (NOT EOF(t)) AND (s1<>s+':') AND (s1<>s+';') AND (s1<>s+'"') DO
readln(t,s1);
IF s1=s+';' THEN
BEGIN
IF InitSwap THEN
BEGIN
assign(t1,'TEMP$$$$.BAT');
rewrite(t1);
readln(t,s1);
WHILE s1<>':'+s DO
BEGIN
writeln(t1,s1);
readln(t,s1);
END;
close(t1);
Execute('TEMP$$$$.BAT');
erase(t1);
EndSwap;
END;
END
ELSE IF s1=s+':' THEN
REPEAT
readln(t,s1);
IF (length(s1)>0) AND (s1[1]=^B) THEN BEGIN
s1[1]:='/';
system.insert('C:',s1,2)
END;
IF (length(s1)>0) AND (s1[1]='~') THEN
system.delete(s1,1,1);
IF s1[length(s1)]<>'~'
THEN s1:=s1+^M
ELSE system.delete(s1,length(s1),1);
FOR i:=1 TO length(s1) DO
CASE s1[i] OF
^C : s1[i]:=^P;
^H : s1[i]:=^N;
END;
IF s1<>':'+s+^M THEN StuffIn(s1);
UNTIL s1=':'+s+^M
ELSE IF s1=s+'"' THEN
REPEAT
readln(t,s1);
IF (length(s1)>0) AND (s1[1]='~') THEN
system.delete(s1,1,1);
IF s1[length(s1)]<>'~'
THEN s1:=s1+^M
ELSE system.delete(s1,length(s1),1);
IF s1<>':'+s+^M THEN
FOR i:=1 TO length(s1) DO
IF s1[i]<>^M THEN
DoFun(InsertChar,s1[i])
ELSE
DoFun(Enter,^M);
IF NOT Keypressed THEN redisplay;
UNTIL s1=':'+s+^M;
close(t);
END;
END;
FUNCTION LineEditor(VAR l:Linetype;
x,y,cx,maxlen:integer;
AllowColorChange:boolean):boolean;
VAR
s:string;
ch:char;
fun : edfun;
done, any : boolean;
tmp : LineType;
shorter : boolean;
i,p : integer;
cc : char;
scc : char;
BEGIN
scc:=currentcolor;
tmp:=l;
cc:='0';
ansic(cc);
CurrentColor:=cc;
REPEAT
IF (tmp.l<>l.l) OR (tmp.c<>l.c) THEN
BEGIN
shorter:=length(l.l)<length(tmp.l);
p:=FirstDiff(tmp,l);
FOR i:=p TO length(l.l) DO
IF (i>length(tmp.l)) OR (l.c[i]<>tmp.c[i]) OR (l.l[i]<>tmp.l[i]) THEN
BEGIN
IF wherex<>x+i-1 THEN gotoxy(x+i-1,y);
IF l.c[i]<>cc THEN BEGIN
cc:=l.c[i];
ansic(cc);
END;
write(l.l[i]);
END;
IF shorter THEN BEGIN
gotoxy(x+length(l.l),y);
ansic('0');
clreol;
ansic(cc);
END;
END;
IF cc<>CurrentColor THEN Ansic(CurrentColor);
cc:=CurrentColor;
tmp:=l;
gotoxy(x+cx-1,y);
s:='';
REPEAT
IF (length(s)>0) AND (pos(s[1],Escaped)>0) THEN
BEGIN
ch:=GetKey(TRUE);
IF (Actual) then s:=s+ch;
Done:=GetFun(s,fun,any) OR ((NOT Actual) AND (Fun<>None));
END ELSE BEGIN
ch:=GetKey(FALSE);
s:=s+ch;
Done := GetFun(s,fun,any);
END;
IF (Not Any) THEN
BEGIN
IF (s[1]=#0) AND Setting.WWIVEditMacrosOk
THEN WWIVEditMacro(s[2]);
s:=''
END
UNTIL Done;
s:='';
LineEdit(l,fun,ch,MaxLen,cx,AllowColorChange);
UNTIL fun IN [Enter,AbortPost,NormalExit];
currentcolor:=scc;
ansic(scc);
LineEditor:=fun=Enter; { Return True if Enter exited }
END;
END.