forked from MarkHofmann11/WWIVEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WESETUP.PAS
436 lines (397 loc) · 10 KB
/
WESETUP.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
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
UNIT WESetup;
{$DEFINE CAN_OVERLAY}
{$I WEGLOBAL.PAS}
INTERFACE
CONST
verbose : BOOLEAN = FALSE;
PROCEDURE Compile_DEF(Filename:string);
PROCEDURE Compile_KEY(Filename:string);
IMPLEMENTATION
USES WeString, WEVars,DOS,WEMemory,WEESM;
TYPE Keyarray=ARRAY[1..1000] OF KeyBinding;
VAR
LinesRead : integer;
KeyBindings : ^KeyArray;
FUNCTION Param(s:string):string;
BEGIN
Param:=Copy(s,pos('[',s)+1,pos(']',s)-pos('[',s)-1);
END;
FUNCTION GetLine(VAR t:text):string;
VAR s:string;
BEGIN
inc(LinesRead);
readln(t,s);
GetLine:=s;
END;
FUNCTION Trans(s:string):string;
VAR
out:string;
t:string;
BEGIN
out:='';
WHILE s<>'' DO
BEGIN
IF s[1]='^' THEN
BEGIN
out:=out+chr(ord(upcase(s[2]))-ord('@'));
delete(s,1,2);
END
ELSE IF s[1]='#' THEN
BEGIN
t:='';
delete(s,1,1);
WHILE (s<>'') AND (s[1] IN ['0'..'9']) DO
BEGIN
t:=t+s[1];
delete(s,1,1);
END;
out:=out+chr(value(t));
END
ELSE BEGIN
out:=out+s[1];
delete(s,1,1);
END;
END;
Trans:=out;
END;
FUNCTION FindFun(s:string):edfun;
{ This may look ugly, but its actually a little more speed effiecient
than my first attempt, and a lot more space efficient. }
VAR
f:edfun;
BEGIN
f:=0;
WHILE (f<=LastDefined) AND (GetS(f)<>s) DO
inc(f);
IF f>LastDefined THEN f:=None;
FindFun:=f;
END;
PROCEDURE Handle(VAR t:text; name:string);
VAR
s:string;
fun:edfun;
Special:string;
i:integer;
BEGIN
fun:=FindFun(TransformString(name));
IF (fun=none) AND (TransformString(name)<>'NONE') THEN
BEGIN
writeln('Error in Definition file.');
writeln('Error on Line ',linesread,' Invalid descriptor :',name);
writeln('Ignoring it.');
exit;
END;
IF verbose THEN write('Handling : ',name,' ');
IF Pos('[',name)>0 THEN
BEGIN
Special:=Trans(Param(name));
IF verbose THEN write('Param [',param(name),'] ');
END;
i:=1;
REPEAT
s:=Trans(Getline(t));
IF Length(s)>BindingMaxLength THEN
BEGIN
writeln('Error! Definition too long on line ',linesread);
writeln('Under heading of ',Name);
writeln('Program halted.');
MemCleanup;
halt(1);
END;
IF s<>'' THEN
BEGIN
IF verbose THEN write(i,'...');
inc(i);
inc(nbindings);
KeyBindings^[nbindings].keys:=s;
KeyBindings^[nbindings].fun:=fun;
END;
UNTIL s='';
IF verbose THEN writeln;
END;
FUNCTION Ok(s:string):boolean;
BEGIN
Ok:=(Param(s)='1') OR (TransformString(Param(s))='Y');
END;
FUNCTION KeyBiosCheck(s:string):boolean;
VAR
r:registers;
BEGIN
KeyBiosCheck:=(Param(s)='1') OR (TransformString(s)='Y');
IF Param(s)='2' { gotta auto detect } THEN
BEGIN
r.ah:=5;
r.cx:=1;
intr($16,r);
r.ah:=$b;
msdos(r);
KeyBiosCheck:=(r.al=$ff);
IF r.al=$ff THEN
BEGIN
r.ah:=$07;
msdos(r);
END
END;
END;
FUNCTION Int(s:string):integer;
BEGIN
int:=value(param(s));
END;
FUNCTION StripChar(VAR s:string):char;
VAR s1:string;
BEGIN
IF s[1]='#' THEN BEGIN
delete(s,1,1);
s1:='';
WHILE (s<>'') AND (s[1] IN ['0'..'9']) DO
BEGIN
s1:=s1+s[1];
delete(s,1,1);
END;
StripChar:=chr(value(s1));
END ELSE BEGIN
StripChar:=s[1];
delete(s,1,1);
END;
END;
FUNCTION GetNext(VAR s:string):string;
VAR p:byte;
BEGIN
p:=pos(',',s);
IF p=0 THEN p:=length(s)+1;
GetNext:=copy(s,1,p-1);
delete(s,1,p);
END;
PROCEDURE HandleSet(VAR cset:charset; s:string);
VAR ch,rs,re:char;
BEGIN
WHILE s<>'' DO
BEGIN
rs:=StripChar(s);
IF s[1]='-' THEN BEGIN
delete(s,1,1);
re:=StripChar(s)
END
ELSE
re:=rs;
FOR ch:=rs TO re DO
setting.colors:=Cset+[ch];
IF (s<>'') AND (s[1]=',') THEN
delete(s,1,1);
END;
END;
PROCEDURE SetDefaults;
VAR
i : integer;
ch : char;
BEGIN
FillChar(Setting,Sizeof(setting),#0);
WITH Setting DO
BEGIN
IF Mem[0:$449]=7 THEN Mono:=1 ELSE Mono:=0;
MCI := [];
Mouse := TRUE;
DisableUserTag := FALSE;
AllowColorChangeInTitle:=TRUE;
KeyBios := FALSE;
DisableBBSTag :=FALSE;
Colors:=[];
AddSL := 30;
Version:=VER_ID;
WarnTime:=90;
DisconnectTime:=180;
END
END;
PROCEDURE HandleLines(s:string);
VAR
t : string;
i : integer;
BEGIN
FOR i:=1 TO 11 DO
BEGIN
IF s='' THEN BEGIN
writeln('LINES setting requires 11 parameters exactly');
MemCleanup;
halt(1);
END;
Setting.Lines[i]:=value(getnext(s));
IF Verbose THEN
write(setting.lines[i],'...');
END;
IF s<>'' THEN BEGIN
writeln('LINES setting requires 11 parameters exactly');
MemCleanup;
halt(1);
END;
END;
PROCEDURE Get_Escaped(s:string);
BEGIN
s:=param(s);
with key_description do
WHILE s<>'' DO BEGIN
inc(nescaped);
Escaped_keys[nescaped]:=stripchar(s);
IF (s<>'') AND (s[1]=',') THEN delete(s,1,1);
END;
END;
FUNCTION HandleMaskKeys(s:string):byte;
CONST
Mask = 'RLCA';
VAR
i : integer;
msk : byte;
BEGIN
s:=transformstring(s);
msk:=0;
FOR i:=1 TO Length(s) DO
BEGIN
IF pos(s[i],mask)=0 THEN BEGIN
writeln('Error in parameter:');
writeln(S[i],' is not a valid choice, ignoring.');
END
ELSE
Msk:=Msk OR (1 shl (pos(s[i],mask)-1));
END;
IF msk=0 THEN msk:=$ff;
IF verbose THEN writeln('=',msk);
HandleMaskKeys := Msk;
END;
PROCEDURE HandleSetting(s:string);
VAR
Name : string;
p:integer;
BEGIN
p:=pos(';',s);
IF p>0 THEN delete(s,p,length(s)-p+1);
Name := TransformString(copy(s,1,pos(':',s)-1));
IF Name='' THEN Exit;
IF verbose THEN writeln('Handling "',Name,'" - Param [',param(s),']');
WITH Setting DO
IF Name='ABORTTIME' THEN DisconnectTime := int(s)
ELSE IF Name='BBS' THEN BBS:=int(s)
ELSE IF Name='ADDSL' THEN AddSL:=Int(s)
ELSE IF Name='BBSTAG' THEN DisableBBSTag:=ok(s)
ELSE IF Name='BBSDISABLE' THEN BoardEditDisable:=int(s)
ELSE IF Name='CHATKEY' THEN ChatMask:=HandleMaskKeys(Param(s))
ELSE IF Name='COLORS' THEN HandleSet(Setting.Colors,Param(s))
ELSE IF Name='COLORTITLE' THEN AllowColorChangeInTitle:=ok(s)
ELSE IF Name='COMPORT' THEN Comport:=Int(s)
ELSE IF Name='CURSOR' THEN ChangeCursor := ok(s)
ELSE IF Name='FOSSIL' THEN Fossil:=ok(s)
ELSE IF Name='DICTDIR' THEN DictDir:=Param(s)
ELSE IF Name='DIRECTVIDEO' THEN DirectVideo:=ok(s)
ELSE IF Name='DIVIDER' THEN Divider:=Param(s)
ELSE IF Name='DOSKEY' THEN DosMask:=HandleMaskKeys(Param(s))
ELSE IF Name='ESCTICKS' THEN Ticks := int(s)
ELSE IF Name='INSDIR' THEN InsertDir:=Param(s)
ELSE IF Name='KEYBOARD' THEN KeyBios:=KeyBiosCheck(s)
ELSE IF Name='NOPERSON' THEN NoTagPersonal:=Param(s)
ELSE IF Name='NOTAG' THEN NoTagBBS:=Param(s)
ELSE IF Name='MCI' THEN HandleSet(Setting.Colors,Param(s))
ELSE IF Name='LINES' THEN HandleLines(Param(s))
ELSE IF Name='LOCAL' THEN Local:=ok(s)
ELSE IF Name='MONO' THEN BEGIN IF int(s)<>2 THEN Mono:=int(s); END
ELSE IF Name='PERSONALDICT' THEN PersonalDicAllowed := ok(s)
ELSE IF Name='PREFIX' THEN BEGIN
s:=Param(s);
IF length(s)>10 THEN writeln('Prefix too long... 10 char max.')
ELSE Prefix:=s;
END
ELSE IF Name='QUOTER' THEN Quoter := int(s)
ELSE IF Name='REPLY' THEN ReplyType:=int(s)
ELSE IF Name='RESULT' THEN ResultType:=Int(s)
ELSE IF Name='SCROLL' THEN SmoothScroll:=ok(s)
ELSE IF Name='SETUP' THEN SetupType:=int(s)
ELSE IF Name='TABSTOP' THEN TabStop:=int(s)
ELSE IF Name='TAG' THEN DisableUserTag:=ok(s)
ELSE IF Name='WARNTIME' THEN WarnTime :=int(s)
ELSE IF Name='WWIVEDITMACROS' THEN WWIVEditMacrosOk := ok(s)
ELSE IF Name='CHATMODE' THEN Chatmode:=int(s)
ELSE IF Name='MOUSE' THEN Mouse:=OK(s)
ELSE BEGIN
writeln('ERROR! Unknown Setting "',Name,'"');
writeln('Ignoring it.');
END;
END;
PROCEDURE Compile_DEF(Filename:string);
VAR
t:text;
i:integer;
s:string;
ch : char;
f:file;
BEGIN
IF Verbose THEN
writeln('Loading Defaults...');
setdefaults;
assign(t,ConfigDir+Filename+DefExt);
reset(t);
WHILE Not EOF(t) DO
BEGIN
s:=getline(t);
IF pos(':',s)<>0 THEN
HandleSetting(s);
END;
close(t);
assign(f,ConfigDir+Filename+SettingExt);
rewrite(f,1);
blockwrite(f,Setting,sizeof(setting));
close(f);
END;
PROCEDURE Compile_KEY(Filename:string);
VAR
t:text;
i,size:integer;
s,s1:string;
ch : char;
f:file;
BEGIN
FillChar(Key_Description,sizeof(Key_Description),#0);
New(KeyBindings);
nbindings:=0;
IF Verbose THEN
writeln('Loading key bindings...');
ASSIGN(t,ConfigDir+Filename+BindingExt);
reset(t);
WHILE NOT Eof(t) DO
BEGIN
REPEAT
s:=getline(t);
UNTIL EOF(t) OR (s<>'') AND (s[1]<>'#');
IF (copy(s,1,1)=':') AND (copy(s,length(s),1)=':') THEN
handle(t,copy(s,2,length(s)-2))
ELSE IF pos(':',s)>0 THEN BEGIN
s1:=TransformString(copy(s,1,pos(':',s)-1));
IF s1='DESCRIPTION' THEN Key_Description.Description:=Param(s)
ELSE IF s1='ESCAPED_KEYS' THEN Get_Escaped(s)
ELSE IF s1='LOCALONLY' THEN Key_Description.local_only:=ok(s)
ELSE IF s1='MINSL' THEN Key_Description.min_sl:=value(param(s))
ELSE BEGIN
writeln('Error in key bindings file.');
writeln('Unknown configurable parameter "',s1,'"');
writeln('Ignoring...');
END;
END;
END;
IF Verbose THEN
writeln('Saving bindings...');
assign(f,ConfigDir+Filename+KeyExt);
rewrite(f,1);
blockwrite(f,Key_Description,Sizeof(Key_Description));
blockwrite(f,nbindings,sizeof(integer));
size:=0;
FOR i:=1 TO NBindings DO
size:=size+sizeof(edfun)+length(KeyBindings^[i].keys)+1;
blockwrite(f,size,sizeof(integer));
FOR i:=1 TO NBindings DO
blockwrite(f,KeyBindings^[i],sizeof(edfun)+length(KeyBindings^[i].keys)+1);
IF Verbose THEN
BEGIN
writeln(' Total Bindings: ',nbindings);
writeln(' Size: ',Size);
END;
close(f);
Dispose(KeyBindings);
NBindings:=0;
END;
END.