Skip to content

Latest commit

 

History

History
382 lines (355 loc) · 11.2 KB

menus2.pas

File metadata and controls

382 lines (355 loc) · 11.2 KB
 
Nov 18, 2000
Nov 18, 2000
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
(*****************************************************************************)
(*> <*)
(*> MENUS2 .PAS - Written by Eric Oman <*)
(*> <*)
(*> Other menu functions - generic, list, etc. <*)
(*> <*)
(*****************************************************************************)
{$A+,B+,D-,E+,F+,I+,L+,N-,O+,R-,S+,V-}
unit menus2;
interface
uses
crt, dos,
{rcg11172000 no overlay under Linux.}
{overlay,}
file4,
common;
procedure readin;
procedure showcmds(listtype:integer);
function oksecurity(i:integer; var cmdnothid:boolean):boolean;
procedure genericmenu(t:integer);
procedure showthismenu;
implementation
procedure readin;
var filv:text;
s,lcmdlistentry:astr;
i,j:integer;
b:boolean;
begin
cmdlist:='';
noc:=0;
assign(filv,curmenu);
{$I-} reset(filv); {$I-}
if (ioresult<>0) then begin
sysoplog('"'+curmenu+'" is MISSING.');
print('"'+curmenu+'" is MISSING. Please inform SysOp.');
print('Dropping back to fallback menu...');
curmenu:=systat.menupath+menur.fallback+'.mnu';
assign(filv,curmenu);
{$I-} reset(filv); {$I-}
if (ioresult<>0) then begin
sysoplog('"'+curmenu+'" is MISSING - Hung user up.');
print('Fallback menu is *also* MISSING. Please inform SysOp.');
nl;
print('Critical error; hanging up.');
hangup:=TRUE;
end;
end;
if (not hangup) then begin
with menur do begin
readln(filv,menuname[1]);
readln(filv,menuname[2]);
readln(filv,menuname[3]);
readln(filv,directive);
readln(filv,tutorial);
readln(filv,menuprompt);
readln(filv,acs);
readln(filv,password);
readln(filv,fallback);
readln(filv,forcehelplevel);
readln(filv,gencols);
for i:=1 to 3 do readln(filv,gcol[i]);
readln(filv,s);
s:=allcaps(s); menuflags:=[];
if (pos('C',s)<>0) then menuflags:=menuflags+[clrscrbefore];
if (pos('D',s)<>0) then menuflags:=menuflags+[dontcenter];
if (pos('N',s)<>0) then menuflags:=menuflags+[nomenuprompt];
if (pos('P',s)<>0) then menuflags:=menuflags+[forcepause];
if (pos('T',s)<>0) then menuflags:=menuflags+[autotime];
end;
repeat
inc(noc);
with cmdr[noc] do begin
readln(filv,ldesc);
readln(filv,sdesc);
readln(filv,ckeys);
readln(filv,acs);
readln(filv,cmdkeys);
readln(filv,mstring);
readln(filv,s);
s:=allcaps(s); commandflags:=[];
if (pos('H',s)<>0) then commandflags:=commandflags+[hidden];
if (pos('U',s)<>0) then commandflags:=commandflags+[unhidden];
end;
until (eof(filv));
close(filv);
mqarea:=FALSE; fqarea:=FALSE;
lcmdlistentry:=''; j:=0;
for i:=1 to noc do begin
if (cmdr[i].ckeys<>lcmdlistentry) then begin
b:=(aacs(cmdr[i].acs));
if (b) then inc(j);
(*
if (b) and (j<>1) then cmdlist:=cmdlist+',';
if (b) then cmdlist:=cmdlist+cmdr[i].ckeys;
*)
if (b) then begin
if ((cmdr[i].ckeys<>'FIRSTCMD') and (cmdr[i].ckeys<>'GTITLE')) then begin
if (j<>1) then cmdlist:=cmdlist+',';
cmdlist:=cmdlist+cmdr[i].ckeys;
end else dec(j);
end;
lcmdlistentry:=cmdr[i].ckeys;
end;
if (cmdr[i].cmdkeys='M#') then mqarea:=TRUE;
if (cmdr[i].cmdkeys='F#') then fqarea:=TRUE;
end;
end;
end;
procedure showcmds(listtype:integer);
var i,j,numrows:integer;
s,s1:astr;
abort,next:boolean;
function type1(i:integer):astr;
begin
type1:=mn(i,3)+mlnnomci(cmdr[i].ckeys,3)+mlnnomci(cmdr[i].cmdkeys,4)+
mlnnomci(cmdr[i].mstring,15);
end;
function sfl(b:boolean; c:char):char;
begin
if (b) then sfl:=c else sfl:='-';
end;
begin
abort:=FALSE; next:=FALSE;
if (noc<>0) then begin
case listtype of
0:begin
printacr(#3#0+'NN'+sepr2+'Command '+sepr2+'Fl'+sepr2+
'ACS '+sepr2+'Cmd'+sepr2+'MString',abort,next);
printacr(#3#4+'==:==============:==:==========:==:========================================',abort,next);
i:=1;
while (i<=noc) and (not abort) and (not hangup) do begin
printacr(#3#0+mn(i,2)+' '+#3#3+mlnnomci(cmdr[i].ckeys,14)+' '+
sfl(hidden in cmdr[i].commandflags,'H')+
sfl(unhidden in cmdr[i].commandflags,'U')+' '+
#3#9+mlnnomci(cmdr[i].acs,10)+' '+
#3#3+mlnnomci(cmdr[i].cmdkeys,2)+' '+
cmdr[i].mstring,abort,next);
inc(i);
end;
end;
1:begin
numrows:=(noc+2) div 3;
i:=1;
s:=#3#3+'NN:KK-Typ-MString ';
s1:=#3#4+'==:======================';
while (i<=numrows) and (i<3) do begin
s:=s+' NN:KK-Typ-MString ';
s1:=s1+' ==:======================';
inc(i);
end;
printacr(s,abort,next);
printacr(s1,abort,next);
i:=0;
repeat
inc(i);
s:=type1(i);
for j:=1 to 2 do
if i+(j*numrows)<=noc then
s:=s+' '+type1(i+(j*numrows));
printacr(#3#1+s,abort,next);
until ((i>=numrows) or (abort) or (hangup));
end;
end;
end
else print('**No Commands on this menu**');
end;
function oksecurity(i:integer; var cmdnothid:boolean):boolean;
begin
oksecurity:=FALSE;
if (unhidden in cmdr[i].commandflags) then cmdnothid:=TRUE;
if (not aacs(cmdr[i].acs)) then exit;
oksecurity:=TRUE;
end;
procedure genericmenu(t:integer);
var glin:array [1..maxmenucmds] of astr;
s,s1:astr;
gcolors:array [1..3] of byte;
onlin,i,j,colsiz,numcols,numglin,maxright:integer;
abort,next,b,cmdnothid:boolean;
function gencolored(keys,desc:astr; acc:boolean):astr;
begin
s:=desc;
j:=pos(allcaps(keys),allcaps(desc));
if (j<>0) and (pos(#3,desc)=0) then begin
insert(#3+chr(gcolors[3]),desc,j+length(keys)+1);
insert(#3+chr(gcolors[1]),desc,j+length(keys));
if (acc) then insert(#3+chr(gcolors[2]),desc,j);
if (j<>1) then
insert(#3+chr(gcolors[1]),desc,j-1);
end;
gencolored:=#3+chr(gcolors[3])+desc;
end;
function semicmd(s:string; x:integer):string;
var i,p:integer;
begin
i:=1;
while (i<x) and (s<>'') do begin
p:=pos(';',s);
if (p<>0) then s:=copy(s,p+1,length(s)-p) else s:='';
inc(i);
end;
while (pos(';',s)<>0) do s:=copy(s,1,pos(';',s)-1);
semicmd:=s;
end;
procedure newgcolors(s:string);
var s1:string;
begin
s1:=semicmd(s,1); if (s1<>'') then gcolors[1]:=value(s1);
s1:=semicmd(s,2); if (s1<>'') then gcolors[2]:=value(s1);
s1:=semicmd(s,3); if (s1<>'') then gcolors[3]:=value(s1);
end;
procedure gen_tuto;
var i,j:integer;
b:boolean;
begin
numglin:=0; maxright:=0; glin[1]:='';
for i:=1 to noc do begin
b:=oksecurity(i,cmdnothid);
if (((b) or (unhidden in cmdr[i].commandflags)) and
(not (hidden in cmdr[i].commandflags))) then
if (cmdr[i].ckeys='GTITLE') then begin
inc(numglin); glin[numglin]:=cmdr[i].ldesc;
j:=lenn(glin[numglin]); if (j>maxright) then maxright:=j;
if (cmdr[i].mstring<>'') then newgcolors(cmdr[i].mstring);
end else
if (cmdr[i].ldesc<>'') then begin
inc(numglin);
glin[numglin]:=gencolored(cmdr[i].ckeys,cmdr[i].ldesc,b);
j:=lenn(glin[numglin]); if (j>maxright) then maxright:=j;
end;
end;
end;
procedure stripc(var s1:astr);
var s:astr;
i:integer;
begin
s:=''; i:=1;
while (i<=length(s1)) do begin
if (s1[i]=#3) then inc(i) else s:=s+s1[i];
inc(i);
end;
s1:=s;
end;
procedure fixit(var s:astr; len:integer);
var s1:astr;
begin
s1:=s;
stripc(s1);
if (length(s1)<len) then
s:=s+copy(' ',1,len-length(s1))
else
if (length(s1)>len) then s:=s1;
end;
procedure gen_norm;
var s1:astr;
i,j:integer;
b:boolean;
begin
s1:=''; onlin:=0; numglin:=1; maxright:=0; glin[1]:='';
for i:=1 to noc do begin
b:=oksecurity(i,cmdnothid);
if (((b) or (unhidden in cmdr[i].commandflags)) and
(not (hidden in cmdr[i].commandflags))) then begin
if (cmdr[i].ckeys='GTITLE') then begin
if (onlin<>0) then inc(numglin);
glin[numglin]:=#2+cmdr[i].ldesc;
inc(numglin); glin[numglin]:='';
onlin:=0;
if (cmdr[i].mstring<>'') then newgcolors(cmdr[i].mstring);
end else begin
if (cmdr[i].sdesc<>'') then begin
inc(onlin); s1:=gencolored(cmdr[i].ckeys,cmdr[i].sdesc,b);
if (onlin<>numcols) then fixit(s1,colsiz);
glin[numglin]:=glin[numglin]+s1;
end;
if (onlin=numcols) then begin
j:=lenn(glin[numglin]); if (j>maxright) then maxright:=j;
inc(numglin); glin[numglin]:=''; onlin:=0;
end;
end;
end;
end;
if (onlin=0) then dec(numglin);
end;
function tcentered(c:integer; s:astr):astr;
const spacestr=' ';
begin
c:=(c div 2)-(lenn(s) div 2);
if (c<1) then c:=0;
tcentered:=copy(spacestr,1,c)+s;
end;
procedure dotitles;
var i:integer;
b:boolean;
begin
b:=FALSE;
if (clrscrbefore in menur.menuflags) then begin
cls;
nl; nl;
end;
for i:=1 to 3 do
if (menur.menuname[i]<>'') then begin
if (not b) then begin nl; b:=TRUE; end;
if (dontcenter in menur.menuflags) then
printacr(menur.menuname[i],abort,next)
else
printacr(tcentered(maxright,menur.menuname[i]),abort,next);
end;
nl;
end;
begin
for i:=1 to 3 do gcolors[i]:=menur.gcol[i];
numcols:=menur.gencols;
case numcols of
2:colsiz:=39; 3:colsiz:=25; 4:colsiz:=19;
5:colsiz:=16; 6:colsiz:=12; 7:colsiz:=11;
end;
if (numcols*colsiz>=thisuser.linelen) then
numcols:=thisuser.linelen div colsiz;
abort:=FALSE; next:=FALSE;
if (t=2) then gen_norm else gen_tuto;
dotitles;
for i:=1 to numglin do
if (glin[i]<>'') then
if (glin[i][1]<>#2) then
printacr(glin[i],abort,next)
else
printacr(tcentered(maxright,copy(glin[i],2,length(glin[i])-1)),
abort,next);
end;
procedure showthismenu;
var s:astr;
begin
case chelplevel of
2:begin
nofile:=TRUE; s:=menur.directive;
if (s<>'') then begin
if (pos('@S',s)<>0) then
printf(substall(s,'@S',cstr(thisuser.sl)));
if (nofile) then printf(substall(s,'@S',''));
end;
end;
3:begin
nofile:=TRUE; s:=menur.tutorial;
if (s<>'') then begin
if (pos('.',s)=0) then s:=s+'.tut';
if (pos('@S',s)<>0) then
printf(substall(s,'@S',cstr(thisuser.sl)));
if (nofile) then printf(substall(s,'@S',''));
end;
end;
end;
if ((nofile) and (chelplevel in [2,3])) then genericmenu(chelplevel);
end;
end.