home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / FORUM25C.ZIP / SUBS1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-02-11  |  12.4 KB  |  604 lines

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