Skip to content

Latest commit

 

History

History
345 lines (318 loc) · 9.88 KB

misc4.pas

File metadata and controls

345 lines (318 loc) · 9.88 KB
 
Nov 18, 2000
Nov 18, 2000
1
2
3
4
5
(*****************************************************************************)
(*> <*)
(*> MISC4 .PAS - InfoForm questionairre system. <*)
(*> <*)
(*****************************************************************************)
Nov 25, 2000
Nov 25, 2000
6
{$A+,B+,E+,F+,I+,L+,N-,O+,R-,S+,V-}
Nov 18, 2000
Nov 18, 2000
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
unit misc4;
interface
uses
crt, dos,
{rcg11172000 no overlay under Linux.}
{overlay,}
doors, misc3,
common;
procedure readq(filen:astr; infolevel:integer);
procedure readasw(usern:integer; fn:astr);
procedure readasw1(fn:astr);
implementation
procedure readq(filen:astr; infolevel:integer);
const level0name:string='';
var infile,outfile,outfile1:text;
outp,lin,s,mult,got,lastinp,ps,ns,es,infilename,outfilename:astr;
i:integer;
abort,next,plin:boolean;
c:char;
procedure gotolabel(got:astr);
var s:astr;
begin
got:=':'+allcaps(got);
reset(infile);
repeat
readln(infile,s);
until (eof(infile)) or (allcaps(s)=got);
end;
procedure dumptofile;
begin
{ output answers to *.ASW file, and delete temporary file }
reset(outfile1);
{$I-} append(outfile); {$I+}
if (ioresult<>0) then rewrite(outfile);
while (not eof(outfile1)) do begin
readln(outfile1,s);
writeln(outfile,s);
end;
close(outfile1); close(outfile);
erase(outfile1);
end;
begin
infilename:=filen;
if (not exist(infilename)) then begin
fsplit(infilename,ps,ns,es);
infilename:=ps+ns+'.INF';
if (not exist(infilename)) then begin
infilename:=systat.afilepath+ns+'.INF';
if (not exist(infilename)) then begin
sysoplog('** InfoForm not found: "'+filen);
print('** InfoForm not found: "'+filen);
exit;
end;
end;
end;
assign(infile,infilename);
{$I-} reset(infile); {$I+}
if (ioresult<>0) then begin
sysoplog('** InfoForm not found: "'+filen+'"');
print('** InfoForm not found: "'+filen+'"');
exit;
end;
fsplit(infilename,ps,ns,es);
outfilename:=systat.afilepath+ns+'.ASW';
assign(outfile1,systat.afilepath+'TEMP$'+cstr(infolevel)+'.ASW');
if (infolevel=0) then begin
level0name:=outfilename;
assign(outfile,outfilename);
sysoplog('** Answered InfoForm "'+filen+'"');
rewrite(outfile1);
writeln(outfile1,'User: '+nam);
writeln(outfile1,'Date: '+dat);
writeln(outfile1);
end else begin
sysoplog('**>> Answered InfoForm "'+filen+'"');
rewrite(outfile1);
assign(outfile,level0name);
end;
nl;
printingfile:=TRUE;
repeat
abort:=FALSE;
readln(infile,outp);
if (pos('*',outp)<>0) and (copy(outp,1,1)<>';') then outp:=';A'+outp;
if (length(outp)=0) then nl else
case outp[1] of
';':begin
if (pos('*',outp)<>0) then
if (outp[2]<>'D') then outp:=copy(outp,1,pos('*',outp)-1);
lin:=copy(outp,3,length(outp)-2);
i:=80-length(lin);
s:=copy(outp,1,2);
if (s[1]=';') then
case s[2] of
'C','D','G','I','K','L','Q','T',';':i:=1; { do nothing }
else
sprompt(lin);
end;
s:=#1#1#1;
case outp[2] of
'A':inputl(s,i);
'B':input(s,i);
'C':begin
mult:=''; i:=1;
s:=copy(outp,pos('"',outp),length(outp)-pos('"',outp));
repeat
mult:=mult+s[i];
inc(i);
until (s[i]='"') or (i>length(s));
lin:=copy(outp,i+3,length(s)-(i-1));
sprompt(lin);
onek(c,mult);
s:=c;
end;
'D':begin
dodoorfunc(outp[3],copy(outp,4,length(outp)-3));
s:=#0#0#0;
end;
'G':begin
got:=copy(outp,3,length(outp)-2);
gotolabel(got);
s:=#0#0#0;
end;
'H':hangup:=TRUE;
'I':begin
mult:=copy(outp,3,length(outp)-2);
i:=pos(',',mult);
if i<>0 then begin
got:=copy(mult,i+1,length(mult)-i);
mult:=copy(mult,1,i-1);
if allcaps(lastinp)=allcaps(mult) then
gotolabel(got);
end;
s:=#0#0#0;
end;
'K':begin
close(infile);
close(outfile1); erase(outfile1);
if (infolevel<>0) then begin
{$I-} append(outfile); {$I+}
if (ioresult<>0) then rewrite(outfile);
writeln(outfile,'** Aborted InfoForm: "'+filen+'"');
close(outfile);
end;
sysoplog('** Aborted InfoForm. Answers not saved.');
printingfile:=FALSE; cfilteron:=FALSE;
exit;
end;
'L':begin
writeln(outfile1,copy(outp,3,length(outp)-2));
s:=#0#0#0;
end;
'Q':begin
close(outfile1);
dumptofile;
readq(copy(outp,3,length(outp)-2),infolevel+1);
rewrite(outfile1);
s:=#0#0#0;
end;
'T':begin
s:=copy(outp,3,length(outp)-2);
printf(s);
s:=#0#0#0;
end;
'Y':if yn then s:='YES' else s:='NO';
';':s:=#0#0#0;
end;
if (s<>#1#1#1) then begin
outp:=lin+s;
lastinp:=s;
end;
if (s=#0#0#0) then outp:=#0#0#0;
end;
':':outp:=#0#0#0;
else
printacr(outp,abort,next);
end;
if (outp<>#0#0#0) then begin
if (pos('@7',outp)<>0) then delete(outp,pos('@7',outp),2);
writeln(outfile1,outp);
end;
until ((eof(infile)) or (hangup));
if (hangup) then begin
writeln(outfile1);
writeln(outfile1,'** HUNG UP **');
end;
close(outfile1);
dumptofile;
close(infile);
printingfile:=FALSE; cfilteron:=FALSE;
end;
procedure readasw(usern:integer; fn:astr);
var qf:text;
user:userrec;
qs,ps,ns,es:astr;
i,userntimes:integer;
abort,next,userfound,usernfound,ufo:boolean;
procedure exactmatch;
begin
reset(qf);
repeat
readln(qf,qs);
if (copy(qs,1,6)='User: ') then begin
i:=value(copy(qs,pos('#',qs)+1,length(qs)-pos('#',qs)));
if (i=usern) then begin
inc(userntimes); usernfound:=TRUE;
if (allcaps(qs)=allcaps('User: '+user.name+' #'+cstr(usern))) then
userfound:=TRUE;
end;
end;
if (not empty) then wkey(abort,next);
until (eof(qf)) or (userfound) or (abort);
end;
procedure usernmatch;
begin
sprompt(#3#7+'No exact user name matches; user number was found ');
if (userntimes=1) then sprompt('once')
else sprompt(cstr(userntimes)+' times');
sprint('.');
nl;
reset(qf);
repeat
readln(qf,qs);
if (copy(qs,1,6)='User: ') then begin
i:=value(copy(qs,pos('#',qs)+1,length(qs)-pos('#',qs)));
if (i=usern) then
if (userntimes=1) then userfound:=TRUE
else begin
sprompt(#3#4+'User: '+#3#3+copy(qs,7,length(qs)-6));
userfound:=pynq(' -- Is this right? ');
end;
end;
if (not empty) then wkey(abort,next);
until (eof(qf)) or (userfound) or (abort);
nl;
end;
begin
ufo:=(filerec(uf).mode<>fmclosed);
if (not ufo) then reset(uf);
if ((usern>=1) and (usern<=filesize(uf)-1)) then begin
seek(uf,usern); read(uf,user);
end else begin
print('Invalid user number: '+cstr(usern));
exit;
end;
if (not ufo) then close(uf);
nl;
abort:=FALSE; next:=FALSE;
fn:=allcaps(fn);
fsplit(fn,ps,ns,es);
fn:=allcaps(systat.afilepath+ns+'.ASW');
if (not exist(fn)) then begin
fn:=allcaps(systat.gfilepath+ns+'.ASW');
if (not exist(fn)) then begin
print('InfoForm answer file not found: "'+fn+'"');
exit;
end;
end;
assign(qf,fn);
{$I-} reset(qf); {$I+}
if (ioresult<>0) then print('"'+fn+'": unable to open.')
else begin
userfound:=FALSE; usernfound:=FALSE; userntimes:=0;
exactmatch;
if (not userfound) and (usernfound) and (not abort) then usernmatch;
if (not userfound) and (not abort) then
print('Questionairre answers not found.')
else begin
sprint(qs); (*(#3#4+'User: '+#3#3+caps(user.name)+' #'+cstr(usern));*)
repeat
readln(qf,qs);
if (copy(qs,1,6)<>'User: ') then printacr(qs,abort,next)
else userfound:=FALSE;
until eof(qf) or (not userfound) or (abort);
end;
close(qf);
end;
end;
procedure readasw1(fn:astr);
var ps,ns,es:astr;
usern:integer;
begin
nl;
print('Read InfoForm answers -');
nl;
if (fn='') then begin
prt('Enter filename: '); mpl(8); input(fn,8);
nl;
if (fn='') then exit;
end;
fsplit(fn,ps,ns,es);
fn:=allcaps(systat.gfilepath+ns+'.ASW');
if (not exist(fn)) then begin
fn:=allcaps(systat.afilepath+ns+'.ASW');
if (not exist(fn)) then begin
print('InfoForm answer file not found: "'+fn+'"');
exit;
end;
end;
print('Enter user number, user name, or partial search string:');
prt(':'); finduserws(usern);
if (usern<>0) then
readasw(usern,fn)
else begin
nl;
if pynq('List entire answer file? ') then begin
nl;
printf(ns+'.ASW');
end;
end;
end;
end.