home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 189.img / TCS120S.ZIP / SUBS1.PAS < prev    next >
Pascal/Delphi Source File  |  1989-04-01  |  14KB  |  634 lines

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