home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 276.img / FORUM21S.ZIP / SUBS1.PAS < prev    next >
Pascal/Delphi Source File  |  1988-02-15  |  13KB  |  601 lines

  1. {$R-,S-,I-,D-,T-,F-,V-,B-,N-,L+ }
  2. {$M 65500,0,0 }
  3.  
  4. unit subs1;
  5.  
  6. interface
  7.  
  8. uses crt,dos,
  9.      gensubs,gentypes,statret,configrt,modem;
  10.  
  11. var firstvariable:byte;
  12.  
  13.     local,online,chatmode,disconnected:boolean;
  14.  
  15.     unum,ulvl,baudrate:integer;
  16.     unam:mstr;
  17.     baudstr:sstr;
  18.     parity:boolean;
  19.     urec:userrec;
  20.  
  21.     logontime,logofftime,logonunum:integer;
  22.     laston:longint;
  23.  
  24.     dots,nochain,break,xpressed,
  25.     requestchat,requestcom,requestbreak,reqspecial,forcehangup,
  26.     modeminlock,modemoutlock,timelock,tempsysop,splitmode,
  27.     fromdoor,texttrap,printerecho,uselinefeeds,usecapsonly,
  28.     dontstop,nobreak,wordwrap,beginwithspacesok,sysnext,ingetstr:boolean;
  29.     regularlevel,numusers,curboardnum,lasty,
  30.     linecount,curattrib,
  31.     firstfree,lockedtime,iocode,buflen:integer;
  32.     screenseg:word;
  33.     cursection:configtype;
  34.     curboardname:sstr;
  35.     input,chainstr:anystr;
  36.     chatreason,lastprompt,errorparam,errorproc:lstr;
  37.     curboard:boardrec;
  38.     mes:message;
  39.     syslogdat:array [0..maxsyslogdat] of syslogdatrec;
  40.     numsyslogdat:integer;
  41.     returnto:char;
  42.  
  43.     lastvariable:byte;
  44.  
  45.     usr,direct,directin:text;
  46.  
  47. const numsysfiles=20;
  48. var tfile:file of buffer;
  49.     mapfile:file of integer;
  50.     ufile:file of userrec;
  51.     uhfile:file of mstr;
  52.     mfile:file of mailrec;
  53.     udfile:file of udrec;
  54.     afile:file of arearec;
  55.     bfile:file of bulrec;
  56.     bdfile:file of boardrec;
  57.     bifile:file of sstr;
  58.     ffile:file of filerec;
  59.     tofile:file of topicrec;
  60.     chfile:file of choicerec;
  61.     ddfile:file of baserec;
  62.     efile:file of entryrec;
  63.     dofile:file of doorrec;
  64.     gfile:file of grouprec;
  65.     logfile:file of logrec;
  66.     abfile:file of abrec;
  67.     usfile:file of userspecsrec;
  68.     sysfiles:array [1..numsysfiles] of file absolute tfile;
  69.     ttfile:text;
  70.  
  71.  
  72. procedure writelog (m,s:integer; prm:lstr);
  73. procedure files30;
  74. function ioerrorstr (num:integer):lstr;
  75. procedure error (errorstr,proc,param:lstr);
  76. procedure fileerror (procname,filename:mstr);
  77. procedure che;
  78. function timeleft:integer;
  79. function timetillevent:integer;
  80. procedure settimeleft (tl:integer);
  81. procedure tab (n:anystr; np:integer);
  82. function yes:boolean;
  83. function yesno (b:boolean):sstr;
  84. function timeontoday:integer;
  85. function isopen (var ff):boolean;
  86. procedure textclose (var f:text);
  87. procedure close (var ff);
  88. function withintime (t1,t2:sstr):boolean;
  89. function hungupon:boolean;
  90. function sysopisavail:boolean;
  91. function sysopavailstr:sstr;
  92. function singularplural (n:integer; m1,m2:mstr):mstr;
  93. function s (n:integer):sstr;
  94. function numthings (n:integer; m1,m2:mstr):lstr;
  95. procedure thereisare (n:integer);
  96. procedure thereare (n:integer; m1,m2:mstr);
  97. procedure assignbdfile;
  98. procedure openbdfile;
  99. procedure formatbdfile;
  100. procedure closebdfile;
  101. procedure opentempbdfile;
  102. procedure closetempbdfile;
  103. function keyhit:boolean;
  104. function bioskey:char;
  105. procedure readline (var xx);
  106. procedure writereturnbat;
  107. procedure ensureclosed;
  108. procedure clearbreak;
  109. procedure ansicolor (attrib:integer);
  110. procedure ansireset;
  111. procedure specialmsg (q:anystr);
  112. procedure writedataarea;
  113. procedure readdataarea;
  114.  
  115. implementation
  116.  
  117. procedure writelog (m,s:integer; prm:lstr);
  118. var n:integer;
  119.     l:logrec;
  120. begin
  121.   with l do begin
  122.     menu:=m;
  123.     subcommand:=s;
  124.     when:=now;
  125.     param:=copy(prm,1,41)
  126.   end;
  127.   seek (logfile,filesize(logfile));
  128.   write (logfile,l)
  129. end;
  130.  
  131. procedure files30;
  132. begin
  133.   writeln (usr,'You MUST put FILES=30 in your CONFIG.SYS!');
  134.   halt(4)
  135. end;
  136.  
  137. function ioerrorstr (num:integer):lstr;
  138. var tf:text;
  139.     tmp:lstr;
  140.     n,s:integer;
  141. begin
  142.   if num=243 then files30;
  143.   assign (tf,'Ioerror.lst');
  144.   reset (tf);
  145.   if ioresult<>0 then begin
  146.     ioerrorstr:='* Can''t open IOERROR.LST *';
  147.     exit
  148.   end;
  149.   while not eof(tf) do begin
  150.     readln (tf,tmp);
  151.     val (tmp,n,s);
  152.     if n=num then begin
  153.       ioerrorstr:=tmp;
  154.       close (tf);
  155.       exit
  156.     end
  157.   end;
  158.   close (tf);
  159.   ioerrorstr:='Unidentified I/O error '+strr(num)
  160. end;
  161.  
  162. procedure error (errorstr,proc,param:lstr);
  163. var p,n:integer;
  164.     pk:char;
  165.     tf:text;
  166. begin
  167.   n:=ioresult;
  168.   repeat
  169.     p:=pos('%',errorstr);
  170.     if p<>0 then begin
  171.       pk:=errorstr[p+1];
  172.       delete (errorstr,p,2);
  173.       case upcase(pk) of
  174.         '1':insert (param,errorstr,p);
  175.         'P':insert (proc,errorstr,p);
  176.         'I':insert (ioerrorstr(iocode),errorstr,p)
  177.       end
  178.     end
  179.   until p=0;
  180.   assign (tf,'ErrLog');
  181.   append (tf);
  182.   if ioresult<>0
  183.     then
  184.       begin
  185.         close (tf);
  186.         rewrite (tf)
  187.       end;
  188.   writeln (tf,unam,' was on-line on ',datestr(now),' at ',timestr(now),' when:');
  189.   writeln (tf,errorstr);
  190.   writeln (tf);
  191.   close (tf);
  192.   n:=ioresult;
  193.   writelog (0,4,errorstr);
  194.   writeln (errorstr)
  195. end;
  196.  
  197. procedure fileerror (procname,filename:mstr);
  198. begin
  199.   error ('%I accessing %1 in %P',procname,filename)
  200. end;
  201.  
  202. procedure che;
  203. var i:integer;
  204. begin
  205.   i:=ioresult;
  206.   case i of
  207.     0:;
  208.     4:files30;
  209.     else
  210.       begin
  211.         iocode:=i;
  212.         error ('Unexpected I/O error %I','','')
  213.       end
  214.   end
  215. end;
  216.  
  217. function timeleft:integer;
  218. var timeon:integer;
  219. begin
  220.   timeon:=timer-logontime;
  221.   if timeon<0 then timeon:=timeon+1440;
  222.   timeleft:=urec.timetoday-timeon
  223. end;
  224.  
  225. function timetillevent:integer;
  226. var n:integer;
  227. begin
  228.   if (length(eventtime)=0) or (length(eventbatch)=0) or
  229.     (timedeventdate=datestr(now))
  230.     then n:=1440
  231.     else n:=timeval(eventtime)-timer;
  232.   if n<0 then n:=n+1440;
  233.   timetillevent:=n
  234. end;
  235.  
  236. procedure settimeleft (tl:integer);
  237. begin
  238.   urec.timetoday:=timer+tl-logontime
  239. end;
  240.  
  241. procedure tab (n:anystr; np:integer);
  242. var cnt:integer;
  243. begin
  244.   write (n);
  245.   for cnt:=length(n) to np-1 do write (' ')
  246. end;
  247.  
  248. function yes:boolean;
  249. begin
  250.   if length(input)=0
  251.     then yes:=false
  252.     else yes:=upcase(input[1])='Y'
  253. end;
  254.  
  255. function yesno (b:boolean):sstr;
  256. begin
  257.   if b
  258.     then yesno:='Yes'
  259.     else yesno:='No'
  260. end;
  261.  
  262. function timeontoday:integer;
  263. var timeon:integer;
  264. begin
  265.   timeon:=timer-logontime;
  266.   if timeon<0 then timeon:=timeon+1440;
  267.   timeontoday:=timeon
  268. end;
  269.  
  270. function isopen (var ff):boolean;
  271. var fi:fib absolute ff;
  272. begin
  273.   isopen:=fi.handle<>0
  274. end;
  275.  
  276. procedure textclose (var f:text);
  277. var n:integer;
  278.     fi:fib absolute f;
  279. begin
  280.   if isopen(f)
  281.     then system.close (f);
  282.   fi.handle:=0;
  283.   n:=ioresult
  284. end;
  285.  
  286. procedure close (var ff);
  287. var f:file absolute ff;
  288.     fi:fib absolute ff;
  289.     n:integer;
  290. begin
  291.   if isopen(f)
  292.     then system.close (f);
  293.   fi.handle:=0;
  294.   n:=ioresult
  295. end;
  296.  
  297. function withintime (t1,t2:sstr):boolean;
  298. var t,a,u:integer;
  299. begin
  300.   t:=timer;
  301.   a:=timeval(t1);
  302.   u:=timeval(t2);
  303.   if a<=u
  304.     then withintime:=(t>=a) and (t<=u)
  305.     else withintime:=(t>=a) or (t<=u)
  306. end;
  307.  
  308. function hungupon:boolean;
  309. begin
  310.   hungupon:=forcehangup or
  311.                 (online and not (carrier or modeminlock or modemoutlock))
  312. end;
  313.  
  314. function sysopisavail:boolean;
  315. begin
  316.   case sysopavail of
  317.     available:sysopisavail:=true;
  318.     notavailable:sysopisavail:=false;
  319.     bytime:sysopisavail:=withintime (availtime,unavailtime)
  320.   end
  321. end;
  322.  
  323. function sysopavailstr:sstr;
  324. const strs:array [available..notavailable] of string[9]=
  325.         ('Yes','By time: ','No');
  326. var tstr:sstr;
  327.     tmp:availtype;
  328. begin
  329.   tstr:=strs[sysopavail];
  330.   if sysopavail=bytime
  331.     then
  332.       begin
  333.         if sysopisavail
  334.           then tmp:=available
  335.           else tmp:=notavailable;
  336.         tstr:=tstr+strs[tmp]
  337.       end;
  338.   sysopavailstr:=tstr
  339. end;
  340.  
  341. function singularplural (n:integer; m1,m2:mstr):mstr;
  342. begin
  343.   if n=1
  344.     then singularplural:=m1
  345.     else singularplural:=m2
  346. end;
  347.  
  348. function s (n:integer):sstr;
  349. begin
  350.   s:=singularplural (n,'','s')
  351. end;
  352.  
  353. function numthings (n:integer; m1,m2:mstr):lstr;
  354. begin
  355.   numthings:=strr(n)+' '+singularplural (n,m1,m2)
  356. end;
  357.  
  358. procedure thereisare (n:integer);
  359. begin
  360.   write ('There ');
  361.   if n=1
  362.     then write ('is 1 ')
  363.     else
  364.       begin
  365.         write ('are ');
  366.         if n=0
  367.           then write ('no ')
  368.           else write (n,' ')
  369.        end
  370. end;
  371.  
  372. procedure thereare (n:integer; m1,m2:mstr);
  373. begin
  374.   thereisare (n);
  375.   if n=1
  376.     then write (m1)
  377.     else write (m2);
  378.   writeln ('.')
  379. end;
  380.  
  381. procedure assignbdfile;
  382. begin
  383.   assign (bdfile,boarddir+'boarddir');
  384.   assign (bifile,boarddir+'bdindex')
  385. end;
  386.  
  387. procedure openbdfile;
  388. var i:integer;
  389. begin
  390.   closebdfile;
  391.   assignbdfile;
  392.   reset (bdfile);
  393.   i:=ioresult;
  394.   reset (bifile);
  395.   i:=i or ioresult;
  396.   if i<>0 then formatbdfile
  397. end;
  398.  
  399. procedure formatbdfile;
  400. begin
  401.   close (bdfile);
  402.   close (bifile);
  403.   assignbdfile;
  404.   rewrite (bdfile);
  405.   rewrite (bifile)
  406. end;
  407.  
  408. procedure closebdfile;
  409. begin
  410.   close (bdfile);
  411.   close (bifile)
  412. end;
  413.  
  414. var wasopen:boolean;
  415.  
  416. procedure opentempbdfile;
  417. begin
  418.   wasopen:=isopen(bdfile);
  419.   if not wasopen then openbdfile
  420. end;
  421.  
  422. procedure closetempbdfile;
  423. begin
  424.   if not wasopen then closebdfile
  425. end;
  426.  
  427. function keyhit:boolean;
  428. var r:registers;
  429. begin
  430.   r.ah:=1;
  431.   intr ($16,r);
  432.   keyhit:=(r.flags and 64)=0
  433. end;
  434.  
  435. function bioskey:char;
  436. var r:registers;
  437. begin
  438.   r.ah:=0;
  439.   intr ($16,r);
  440.   if r.al=0
  441.     then bioskey:=chr(r.ah+128)
  442.     else bioskey:=chr(r.al)
  443. end;
  444.  
  445. procedure readline (var xx);
  446. var a:anystr absolute xx;
  447.     l:byte absolute xx;
  448.     k:char;
  449.  
  450.   procedure backspace;
  451.   begin
  452.     if l>0 then begin
  453.       write (usr,^H,' ',^H);
  454.       l:=l-1
  455.     end
  456.   end;
  457.  
  458.   procedure eraseall;
  459.   begin
  460.     while l>0 do backspace
  461.   end;
  462.  
  463.   procedure addchar (k:char);
  464.   begin
  465.     if l<buflen then begin
  466.       l:=l+1;
  467.       a[l]:=k;
  468.       write (usr,k)
  469.     end
  470.   end;
  471.  
  472. begin
  473.   l:=0;
  474.   repeat
  475.     k:=bioskey;
  476.     case k of
  477.       #8:backspace;
  478.       #27:eraseall;
  479.       #32..#126:addchar(k)
  480.     end
  481.   until k=#13;
  482.   writeln (usr)
  483. end;
  484.  
  485. procedure writereturnbat;
  486. var tf:text;
  487.     bd:integer;
  488.     tmp:lstr;
  489. begin
  490.   assign (tf,'return.bat');
  491.   rewrite (tf);
  492.   getdir (0,tmp);
  493.   writeln (tf,'cd '+tmp);
  494.   if unum=0
  495.     then begin
  496.       writeln (tf,'PAUSE   ***  No one was logged in!');
  497.       writeln (tf,'keepup')
  498.     end else begin
  499.       if online then bd:=baudrate else bd:=0;
  500.       writeln (tf,'keepup ',unum,' ',bd,' ',ord(parity),' M')
  501.     end;
  502.   textclose (tf);
  503.   writeln (usr,'  ( Type  RETURN  to return to Forum-PC )')
  504. end;
  505.  
  506. procedure ensureclosed;
  507. var cnt,i:integer;
  508. begin
  509.   stoptimer (numminsidle);
  510.   stoptimer (numminsused);
  511.   writestatus;
  512.   textclose (ttfile);
  513.   i:=ioresult;
  514.   for cnt:=1 to numsysfiles do begin
  515.     close (sysfiles[cnt]);
  516.     i:=ioresult
  517.   end
  518. end;
  519.  
  520. procedure clearbreak;
  521. begin
  522.   break:=false;
  523.   xpressed:=false;
  524.   dontstop:=false;
  525.   nobreak:=false
  526. end;
  527.  
  528. procedure ansicolor (attrib:integer);
  529. var tc:integer;
  530. const colorid:array [0..7] of byte=(30,34,32,36,31,35,33,37);
  531. begin
  532.   if attrib=0 then begin
  533.     textcolor (7);
  534.     textbackground (0)
  535.   end else begin
  536.     textcolor (attrib and $8f);
  537.     textbackground ((attrib shr 4) and 7)
  538.   end;
  539.   if not (ansigraphics in urec.config) or (attrib=0) or (usecapsonly)
  540.      or (attrib=curattrib) or break then exit;
  541.   curattrib:=attrib;
  542.   write (direct,#27'[0');
  543.   tc:=attrib and 7;
  544.   if tc<>7 then write (direct,';',colorid[tc]);
  545.   tc:=(attrib shr 4) and 7;
  546.   if tc<>0 then write (direct,';',colorid[tc]+10);
  547.   if (attrib and 8)=8 then write (direct,';1');
  548.   if (attrib and 128)=128 then write (direct,';5');
  549.   write (direct,'m')
  550. end;
  551.  
  552. procedure ansireset;
  553. begin
  554.   textcolor (7);
  555.   textbackground (0);
  556.   if usecapsonly then exit;
  557.   if urec.regularcolor<>0 then begin
  558.     ansicolor (urec.regularcolor);
  559.     exit
  560.   end;
  561.   if (not (ansigraphics in urec.config)) or (curattrib=0) or break then exit;
  562.   write (direct,#27'[0m');
  563.   curattrib:=0
  564. end;
  565.  
  566. procedure specialmsg (q:anystr);
  567. begin
  568.   textcolor (outlockcolor);
  569.   textbackground (0);
  570.   writeln (usr,q);
  571.   if not modemoutlock then textcolor (normbotcolor)
  572. end;
  573.  
  574. procedure readdataarea;
  575. var f:file of byte;
  576. begin
  577.   assign (f,'Forum.dat');
  578.   reset (f);
  579.   if ioresult<>0
  580.     then unum:=-1
  581.     else begin
  582.       dos.filerec(f).recsize:=ofs(lastvariable)-ofs(firstvariable);
  583.       read (f,firstvariable);
  584.       close (f)
  585.     end
  586. end;
  587.  
  588. procedure writedataarea;
  589. var f:file of byte;
  590. begin
  591.   assign (f,'Forum.dat');
  592.   rewrite (f);
  593.   dos.filerec(f).recsize:=ofs(lastvariable)-ofs(firstvariable);
  594.   write (f,firstvariable);
  595.   close (f)
  596. end;
  597.  
  598.  
  599. begin
  600. end.
  601.