home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / SYSPC22.ZIP / SUBS1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-04-26  |  11.5 KB  |  560 lines

  1.     const chatnum:integer=0;
  2.           lastonda:string[8]='00/00/00';
  3.           lastonti:string[8]='00:00 xx';
  4.           usedit:boolean=false;
  5.           dogit:boolean=false;
  6.           echo:boolean=true;
  7.  
  8. var local,online,chatmode,disconnected:boolean;
  9.  
  10.     nnu,Shell_return_code,foreg,backg,unum,ulvl,baudrate:integer;
  11.     edit_user,senttol,replyt,replyguy,unam:mstr;
  12.     baudstr,timebefore,daybefore:sstr;
  13.     canon,sta,ns,nosys,imdone,validphone,telenet,feed,parity,fin,mnu:boolean;
  14.     urec:userrec;
  15.     logontime,logofftime,logonunum:integer;
  16.     laston:string[8];
  17.     sendtoistru,replyanon,ranon,dots,nochain,break,xpressed,requestchat,requestcom,reqspecial,
  18.     modeminlock,modemoutlock,timelock,tempsysop,splitmode,
  19.     fromdoor,texttrap,printerecho,uselinefeeds,usecapsonly,
  20.     dload,endp,dontstop,nobreak,wordwrap,sysnext:boolean;
  21.     regularlevel,numusers,curboardnum,lasty,
  22.     turbooutptr,turboinptr,devicestackptr,linecount,curattrib,
  23.     newups,newmsgs,reply,firstfree,lockedtime,screenseg,iocode:integer;
  24.     cursection:configtype;
  25.     curboardname:sstr;
  26.     messagemenunames,input,chainstr:anystr;
  27.     chatreason,lastprompt,errorparam,errorproc:lstr;
  28.     curboard:boardrec;
  29.     curdevice:ptr absolute dseg:$232;
  30.     devicestack:array [1..10] of ptr;
  31.     mes:message;
  32.     syslogdat:array [0..maxsyslogdat] of syslogdatrec;
  33.     numsyslogdat:integer;
  34.  
  35.  
  36. const numsysfiles=17;
  37. var tfile:file of buffer;
  38.     mapfile:file of integer;
  39.     ufile:file of userrec;
  40.     mfile:file of mailrec;
  41.     udfile:file of udrec;
  42.     afile:file of arearec;
  43.     bfile:file of bulrec;
  44.     bdfile:file of boardrec;
  45.     bifile:file of sstr;
  46.     ffile:file of filerec;
  47.     tofile:file of topicrec;
  48.     chfile:file of choicerec;
  49.     ddfile:file of baserec;
  50.     efile:file of entryrec;
  51.     dofile:file of doorrec;
  52.     gfile:file of grouprec;
  53.     logfile:file of logrec;
  54.     sysfiles:array [1..numsysfiles] of file absolute tfile;
  55.     ttfile:text;
  56.  
  57. function readchar:char; forward;
  58. function charready:boolean; forward;
  59. procedure writestr (s:anystr); forward;
  60. procedure writeturbo (k:char); forward;
  61. procedure breakout; forward;
  62. procedure chat (gotospecial:boolean); forward;
  63. procedure cls; forward;
  64. procedure disconnect; forward;
  65. procedure openbdfile; forward;
  66. procedure closebdfile; forward;
  67. procedure formatbdfile; forward;
  68. procedure opentempbdfile; forward;
  69. procedure closetempbdfile; forward;
  70. procedure setuseraccflag (var u:userrec; bn:integer; ac:accesstype); forward;
  71. procedure setalluserflags (var u:userrec; ac:accesstype); forward;
  72. procedure readurec; forward;
  73. procedure writeurec; forward;
  74.  
  75. procedure pushdevice;
  76. begin
  77.   if devicestackptr=10 then exit;
  78.   devicestackptr:=devicestackptr+1;
  79.   devicestack[devicestackptr]:=curdevice
  80. end;
  81.  
  82. procedure popdevice;
  83. begin
  84.   if devicestackptr<1 then exit;
  85.   curdevice:=devicestack[devicestackptr];
  86.   devicestackptr:=devicestackptr-1
  87. end;
  88.  
  89. function strr (n:integer):mstr;
  90. var q:mstr;
  91. begin
  92.   str (n,q);
  93.   strr:=q
  94. end;
  95.  
  96. function streal (r:real):mstr;
  97. var q:mstr;
  98. begin
  99.   str (r:0:0,q);
  100.   streal:=q
  101. end;
  102.  
  103. function valu (q:mstr):integer;
  104. var i,s,pu:integer;
  105.     r:real;
  106. begin
  107.   valu:=0;
  108.   if length(q)=0 then exit;
  109.   if not (q[1] in ['0'..'9','-']) then exit;
  110.   if length(q)>5 then exit;
  111.   val (q,r,s);
  112.   if s<>0 then exit;
  113.   if (r<=32767.0) and (r>=-32767.0)
  114.     then valu:=round(r)
  115. end;
  116.  
  117. procedure parse3 (s:lstr; var a,b,c:integer);
  118. var p:integer;
  119.  
  120.   procedure parse1 (var n:integer);
  121.   var ns:lstr;
  122.   begin
  123.     ns[0]:=#0;
  124.     while (p<=length(s)) and (s[p] in ['0'..'9']) do begin
  125.       ns:=ns+s[p];
  126.       p:=p+1
  127.     end;
  128.     if length(ns)=0
  129.       then n:=0
  130.       else n:=valu(ns);
  131.     if p<length(s) then p:=p+1
  132.   end;
  133.  
  134. begin
  135.   p:=1;
  136.   parse1 (a);
  137.   parse1 (b);
  138.   parse1 (c)
  139. end;
  140.  
  141. function realtime:real;
  142. var r:regs;
  143.     hu,s,m,h:byte;
  144. begin
  145.   r.ax:=$2c00;
  146.   intr ($21,r);
  147.   hu:=r.dx and 255;
  148.   s:=r.dx shr 8;
  149.   m:=r.cx and 255;
  150.   h:=r.cx shr 8;
  151.   realtime:=hu+100.0*s+100.0*60.0*m+100.0*60.0*60.0*h
  152. end;
  153.  
  154. function timestr:sstr;
  155. var h,h1,m:integer;
  156.     r:regs;
  157.     ms:sstr;
  158. begin
  159.   r.ax:=$2c00;
  160.   intr ($21,r);
  161.   h:=r.cx shr 8;
  162.   m:=r.cx and 255;
  163.   if h=0
  164.     then h1:=12
  165.     else if h<13
  166.       then h1:=h
  167.       else h1:=h-12;
  168.   ms:=strr(m);
  169.   if m<10 then ms:='0'+ms;
  170.   ms:=strr(h1)+':'+ms+' ';
  171.   if h>11
  172.     then timestr:=ms+'pm'
  173.     else timestr:=ms+'am'
  174. end;
  175.  
  176. function timeval (q:sstr):integer;
  177. var h,h1,m,t:integer;
  178.     k:char;
  179. begin
  180.   parse3 (q,h1,m,t);
  181.   k:=upcase(q[length(q)-1]);
  182.   if h1 in [1..11]
  183.     then
  184.       begin
  185.         h:=h1;
  186.         if k='P' then h:=h+12
  187.       end
  188.     else
  189.       if k='P'
  190.         then h:=12
  191.         else h:=0;
  192.   timeval:=h*60+m
  193. end;
  194.  
  195. function datestr:sstr;
  196. var r:regs;
  197. begin
  198.   r.ax:=$2a00;
  199.   intr ($21,r);
  200.   datestr:=strr(r.dx shr 8)+'/'+strr(r.dx and 255)+'/'+strr(r.cx-1900)
  201. end;
  202.  
  203. function later (d1,t1,d2,t2:sstr):boolean;
  204. var m1,da1,y1,m2,da2,y2:integer;
  205.  
  206.   function latertime (t1,t2:sstr):boolean;
  207.   var n1,n2:integer;
  208.   begin
  209.     latertime:=timeval(t1)>timeval(t2)
  210.   end;
  211.  
  212. begin
  213.   parse3 (d1,m1,da1,y1);
  214.   parse3 (d2,m2,da2,y2);
  215.   if y1=y2
  216.     then if m1=m2
  217.       then if da1=da2
  218.         then later:=timeval(t1) > timeval(t2)
  219.         else later:=da1>da2
  220.       else later:=m1>m2
  221.     else later:=y1>y2
  222. end;
  223.  
  224. function upstring (s:anystr):anystr;
  225. var cnt:integer;
  226. begin
  227.   for cnt:=1 to length(s) do s[cnt]:=upcase(s[cnt]);
  228.   upstring:=s
  229. end;
  230.  
  231. function lowstring (s:anystr):anystr;
  232. var cnt:integer;
  233.  
  234.  begin
  235.    for cnt:=1 to length(s) do begin
  236.    if s[cnt] in ['A'..'Z'] then s[cnt]:=chr(ord(s[cnt])+32);
  237.  end;
  238.   lowstring:=s;
  239.  end;
  240.  
  241. function match (s1,s2:anystr):boolean;
  242. var cnt:integer;
  243. begin
  244.   match:=false;
  245.   if length(s1)<>length(s2) then exit;
  246.   for cnt:=1 to length(s1) do
  247.     if upcase(s1[cnt])<>upcase(s2[cnt])
  248.       then exit;
  249.   match:=true
  250. end;
  251.  
  252. procedure writelog (m,s:integer; prm:lstr);
  253. var n:integer;
  254.     l:logrec;
  255. begin
  256.   with l do begin
  257.     menu:=m;
  258.     subcommand:=s;
  259.     date:=datestr;
  260.     time:=timestr;
  261.     param:=copy(prm,1,41)
  262.   end;
  263.   seek (logfile,filesize(logfile));
  264.   write (logfile,l)
  265. end;
  266.  
  267. procedure files30;
  268. begin
  269.   writeln (usr,'You MUST put FILES=30 in your CONFIG.SYS!');
  270.   halt(4)
  271. end;
  272.  
  273. function ioerrorstr (num:integer):lstr;
  274. var tf:text;
  275.     tmp:lstr;
  276.     n,s:integer;
  277. begin
  278.   if num=243 then files30;
  279.   assign (tf,'Ioerror.lst');
  280.   reset (tf);
  281.   if ioresult<>0 then begin
  282.     ioerrorstr:='* Can''t open IOERROR.LST *';
  283.     exit
  284.   end;
  285.   while not eof(tf) do begin
  286.     readln (tf,tmp);
  287.     val (tmp,n,s);
  288.     if n=num then begin
  289.       ioerrorstr:=tmp;
  290.       close (tf);
  291.       exit
  292.     end
  293.   end;
  294.   close (tf);
  295.   ioerrorstr:='Unidentified I/O error '+strr(num)
  296. end;
  297.  
  298. procedure error (errorstr,proc,param:lstr);
  299. var p,n:integer;
  300.     pk:char;
  301.     tf:text;
  302. label found;
  303. begin
  304.   n:=ioresult;
  305.   repeat
  306.     p:=pos('%',errorstr);
  307.     if p<>0 then begin
  308.       pk:=copy(errorstr,p+1,1);
  309.       delete (errorstr,p,2);
  310.       case upcase(pk) of
  311.         '1':insert (param,errorstr,p);
  312.         'P':insert (proc,errorstr,p);
  313.         'I':insert (ioerrorstr(iocode),errorstr,p)
  314.       end
  315.     end
  316.   until p=0;
  317.   pushdevice;
  318.   assign (tf,'ErrLog');
  319.   append (tf);
  320.   if ioresult<>0
  321.     then
  322.       begin
  323.         close (tf);
  324.         rewrite (tf)
  325.       end;
  326.   writeln (tf,unam,' was on-line on ',datestr,' at ',timestr,' when:');
  327.   writeln (tf,errorstr);
  328.   writeln (tf);
  329.   close (tf);
  330.   n:=ioresult;
  331.   writelog (0,4,errorstr);
  332.   popdevice;
  333.   writeln (errorstr)
  334. end;
  335.  
  336. procedure fileerror (procname,filename:mstr);
  337. begin
  338.   error ('%I accessing %1 in %P',procname,filename)
  339. end;
  340.  
  341. procedure che;
  342. var i:integer;
  343. begin
  344.   i:=ioresult;
  345.   case i of
  346.     0,255:;
  347.     243:files30;
  348.     else
  349.       begin
  350.         iocode:=i;
  351.         error ('Unexpected I/O error %I','','')
  352.       end
  353.   end
  354. end;
  355.  
  356. function timeleft:integer;
  357. var timeon:integer;
  358. begin
  359.   timeon:=timer-logontime;
  360.   if timeon<0 then timeon:=timeon+1440;
  361.   timeleft:=urec.timetoday-timeon
  362. end;
  363.  
  364. function timetillevent:integer;
  365. var n:integer;
  366. begin
  367.   if (length(eventtime)=0) or (length(eventbatch)=0) or
  368.     (timedeventdate=datestr)
  369.     then n:=1440
  370.     else n:=timeval(eventtime)-timer;
  371.   if n<0 then n:=n+1440;
  372.   timetillevent:=n
  373. end;
  374.  
  375. procedure settimeleft (tl:integer);
  376. begin
  377.   urec.timetoday:=timer+tl-logontime
  378. end;
  379.  
  380. function devicename (name:lstr):boolean;
  381. var f:file;
  382.     n:integer absolute f;
  383.     r:regs;
  384. begin
  385.   devicename:=false;
  386.   assign (f,name);
  387.   reset (f);
  388.   if ioresult<>0 then exit;
  389.   r.bx:=n;
  390.   r.ax:=$4400;
  391.   intr ($21,r);
  392.   devicename:=(r.dx and 128)=128;
  393.   close (f)
  394. end;
  395.  
  396. function exist (n:lstr):boolean;
  397. var f:file;
  398.     i:integer;
  399. begin
  400.   assign (f,n);
  401.   reset (f);
  402.   i:=ioresult;
  403.   exist:=i<>1;
  404.   close (f);
  405.   i:=ioresult
  406. end;
  407.  
  408. procedure appendfile (name:lstr; var q:text);
  409. var n:integer;
  410.     b:boolean;
  411.     f:file of char;
  412. begin
  413.   close (q);
  414.   n:=ioresult;
  415.   assign (q,name);
  416.   assign (f,name);
  417.   reset (f);
  418.   b:=(ioresult<>0) or (filesize(f)=0);
  419.   close (f);
  420.   n:=ioresult;
  421.   if b
  422.     then rewrite (q)
  423.     else append (q)
  424. end;
  425.  
  426. procedure tab (n:anystr; np:integer);
  427. var cnt:integer;
  428. begin
  429.   write (^B,n);
  430.   for cnt:=length(n) to np-1 do write (' ')
  431. end;
  432.  
  433. function yes:boolean;
  434. begin
  435.   if length(input)=0
  436.     then yes:=false
  437.     else yes:=upcase(input[1])='Y'
  438. end;
  439.  
  440. function yesno (b:boolean):sstr;
  441. begin
  442.   if b
  443.     then yesno:='Yes'
  444.     else yesno:='No'
  445. end;
  446.  
  447. function timeontoday:integer;
  448. var timeon:integer;
  449. begin
  450.   timeon:=timer-logontime;
  451.   if timeon<0 then timeon:=timeon+1440;
  452.   timeontoday:=timeon
  453. end;
  454.  
  455. function isopen (var ff):boolean;
  456. var fi:fib absolute ff;
  457. begin
  458.   isopen:=fi.handle<>-1
  459. end;
  460.  
  461. procedure textclose (var f:text);
  462. var n:integer;
  463. begin
  464.   if isopen(f)
  465.     then close (f);
  466.   n:=ioresult
  467. end;
  468.  
  469. procedure oldclose (var ff);
  470. var f:file absolute ff;
  471.     n:integer;
  472. begin
  473.   close (f);
  474.   n:=ioresult
  475. end;
  476.  
  477. procedure close (var ff);
  478. var f:file absolute ff;
  479. begin
  480.   if isopen(f)
  481.     then oldclose (f)
  482. end;
  483.  
  484. function withintime (t1,t2:sstr):boolean;
  485. var t,a,u:integer;
  486. begin
  487.   t:=timer;
  488.   a:=timeval(t1);
  489.   u:=timeval(t2);
  490.   if a<=u
  491.     then withintime:=(t>=a) and (t<=u)
  492.     else withintime:=(t>=a) or (t<=u)
  493. end;
  494.  
  495. function sysopisavail:boolean;
  496. begin
  497.   case sysopavail of
  498.     available:sysopisavail:=true;
  499.     notavailable:sysopisavail:=false;
  500.     bytime:sysopisavail:=withintime (availtime,unavailtime)
  501.   end
  502. end;
  503.  
  504. function sysopavailstr:sstr;
  505. const strs:array [available..notavailable] of string[9]=
  506.         ('Yes','By time: ','No');
  507. var tstr:sstr;
  508.     tmp:availtype;
  509. begin
  510.   tstr:=strs[sysopavail];
  511.   if sysopavail=bytime
  512.     then
  513.       begin
  514.         if sysopisavail
  515.           then tmp:=available
  516.           else tmp:=notavailable;
  517.         tstr:=tstr+strs[tmp]
  518.       end;
  519.   sysopavailstr:=tstr
  520. end;
  521.  
  522. function singularplural (n:integer; m1,m2:mstr):mstr;
  523. begin
  524.   if n=1
  525.     then singularplural:=m1
  526.     else singularplural:=m2
  527. end;
  528.  
  529. function s (n:integer):sstr;
  530. begin
  531.   s:=singularplural (n,'','s')
  532. end;
  533.  
  534. function numthings (n:integer; m1,m2:mstr):lstr;
  535. begin
  536.   numthings:=strr(n)+' '+singularplural (n,m1,m2)
  537. end;
  538.  
  539. procedure thereisare (n:integer);
  540. begin
  541.   write ('There ');
  542.   if n=1
  543.     then write ('is 1 ')
  544.     else
  545.       begin
  546.         write ('are ');
  547.         if n=0
  548.           then write ('no ')
  549.           else write (n,' ')
  550.        end
  551. end;
  552.  
  553. procedure thereare (n:integer; m1,m2:mstr);
  554. begin
  555.   thereisare (n);
  556.   if n=1
  557.     then write (m1)
  558.     else write (m2);
  559.   writeln ('.')
  560. end;