home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / FORUM25C.ZIP / OVERRET2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-12-27  |  10.2 KB  |  446 lines

  1. {$R-,S-,I-,V-,B-,N-,L- }
  2. {$O+}
  3.  
  4. unit overret2;
  5.  
  6.  
  7. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  8.  
  9. interface
  10.  
  11. uses crt,
  12.      dos,
  13.      gentypes,
  14.      modem,
  15.      statret,
  16.      configrt,
  17.      gensubs,
  18.      subs1,
  19.      windows,
  20.      subs2;
  21.  
  22. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  23.  
  24.  
  25. Procedure validconfiguration;
  26. Procedure init (checkfiles30:boolean);
  27.  
  28.  
  29. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  30.  
  31. implementation
  32.  
  33. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  34.  
  35.  
  36. Procedure validconfiguration;
  37. VAR errs:integer;
  38.     cnt:integer;
  39.     flag:boolean;
  40.  
  41.   Procedure error (q:anystr);
  42.   begin
  43.     if errs=0 then writeln (usr,'Configuration Errors:');
  44.     errs:=errs+1;
  45.     writeln (usr,errs,'. ',q)
  46.   end;
  47.  
  48.   Procedure ispath (VAR x:lstr; name:lstr);
  49.   begin
  50.     if not exist(x+'con') then error (name+' path bad: '+x)
  51.   end;
  52.  
  53.   Procedure isstring (x:anystr; name:lstr);
  54.   VAR cnt:integer;
  55.   begin
  56.     if length(x)=0 then begin
  57.       error (name+' has not been set!');
  58.       exit
  59.     end;
  60.     for cnt:=1 to length(x) do if not (x[cnt] in [#32..#255])
  61.       then begin
  62.         error ('Bad '+name+' string');
  63.         exit
  64.       end
  65.   end;
  66.  
  67.   Procedure isinteger (n,r1,r2:integer; name:lstr);
  68.   begin
  69.     if (n<r1) or (n>r2) then error ('Bad '+name+' value: '+strr(n))
  70.   end;
  71.  
  72. begin
  73.   errs:=0;
  74.   isstring (sysopname,'Sysop name');
  75.   ispath (textdir,'Path to message base');
  76.   ispath (uploaddir,'Path to ASCII uploads');
  77.   ispath (boarddir,'Path to sub-board files');
  78.   ispath (textfiledir,'Path to text files');
  79.   ispath (doordir,'Path to door batch files');
  80.   isinteger (defbaudrate,110,9600,'default baud rate');
  81.   isinteger (usecom,1,2,'COM: port');
  82.   isinteger (mintimeout,1,maxint,'input time out');
  83.   isinteger (sysoplevel,1,maxint,'co-sysop level');
  84.   flag:=true;
  85.   for cnt:=1 to 100 do if flag and (usertime[cnt]<1) then begin
  86.     flag:=false;
  87.     error ('Time per day has non-positive entries')
  88.   end;
  89.   if errs>0 then halt(99)
  90. end;
  91.  
  92. Procedure init (checkfiles30:boolean);
  93.  
  94.   Procedure formatmfile;
  95.   VAR m:mailrec;
  96.   begin
  97.     rewrite (mfile);
  98.     fillchar (m,sizeof(m),255);
  99.     write (mfile,m)
  100.   end;
  101.  
  102.   Procedure openmfile;
  103.   VAR i:integer;
  104.   begin
  105.     close (mfile);
  106.     i:=ioresult;
  107.     assign (mfile,'Mail');
  108.     reset (mfile);
  109.     i:=ioresult;
  110.     if i<>0
  111.       then if i=2
  112.         then formatmfile
  113.         else begin
  114.           writeln (usr,'Fatal error: Unable to open mail file!');
  115.           halt (255)
  116.         end
  117.   end;
  118.  
  119.   Procedure closetfile;
  120.   VAR n:integer;
  121.   begin
  122.     close (tfile);
  123.     n:=ioresult;
  124.     close (mapfile);
  125.     n:=ioresult
  126.   end;
  127.  
  128.   Procedure formattfile;
  129.   VAR cnt,p:integer;
  130.       r:real;
  131.       buff:buffer;
  132.       x:string[1];
  133.   const dummystr:sstr='Blank!! ';
  134.   begin
  135.     write (usr,'Create new message base (y/n)? ');
  136.     buflen:=1;
  137.     readline (x);
  138.     if (length(x)=0) or (upcase(x[1])<>'Y') then halt (90);
  139.     rewrite (mapfile);
  140.     if ioresult<>0 then begin
  141.       writeln (usr,'Unable to create message base.');
  142.       halt (91)
  143.     end;
  144.     p:=-2;
  145.     for cnt:=0 to numsectors do write (mapfile,p);
  146.     p:=1;
  147.     for cnt:=1 to sectorsize do begin
  148.       buff[cnt]:=dummystr[p];
  149.       p:=p+1;
  150.       if p>length(dummystr) then p:=1
  151.     end;
  152.     rewrite (tfile);
  153.     if ioresult<>0 then begin
  154.       writeln (usr,'Unable to create message base.');
  155.       halt (91)
  156.     end;
  157.     for cnt:=0 to 5 do write (tfile,buff)
  158.   end;
  159.  
  160.   Procedure opentfile;
  161.   VAR i,j:integer;
  162.   begin
  163.     closetfile;
  164.     assign (tfile,textdir+'Text');
  165.     assign (mapfile,textdir+'BlockMap');
  166.     reset (tfile);
  167.     i:=ioresult;
  168.     reset (mapfile);
  169.     j:=ioresult;
  170.     if (i<>0) or (j<>0) then formattfile;
  171.     firstfree:=-1
  172.   end;
  173.  
  174.   Procedure openufile;
  175.   VAR u:userrec;
  176.       n,cnt:integer;
  177.   begin
  178.     close (ufile);
  179.     assign (ufile,'Users');
  180.     reset (ufile);
  181.     n:=ioresult;
  182.     if n=0 then begin
  183.       numusers:=filesize(ufile)-1;
  184.       exit
  185.     end;
  186.     close (ufile);
  187.     n:=ioresult;
  188.     rewrite (ufile);
  189.     fillchar (u,sizeof(u),0);
  190.     write (ufile,u);
  191.     u.handle:=sysopname;
  192.     u.password:='Sysop';
  193.     u.timetoday:=9999;
  194.     u.level:=sysoplevel+1;
  195.     u.udlevel:=10000;
  196.     u.udpoints:=10000;
  197.     u.config:=[lowercase,eightycols,linefeeds,postprompts];
  198.     u.emailannounce:=-1;
  199.     u.infoform:=-1;
  200.     u.displaylen:=24;
  201.     fillchar (u.access2,32,255);
  202.     if useconmode
  203.       then u.config:=u.config+[ansigraphics]
  204.       else u.config:=u.config+[asciigraphics];
  205.     write (ufile,u);
  206.     numusers:=1
  207.   end;
  208.  
  209.   Procedure initfile (VAR f:file);
  210.   VAR fi:fib absolute f;
  211.   begin
  212.     fi.handle:=0;
  213.     fi.name[0]:=chr(0)
  214.   end;
  215.  
  216.   Procedure openlogfile;
  217.  
  218.     Procedure autodeletesyslog;
  219.     VAR mx,cnt:integer;
  220.         l:logrec;
  221.     begin
  222.       dontanswer;
  223.       write (usr,'Autodeleting system log ... please stand by ... ');
  224.       mx:=filesize(logfile) div 2;
  225.       for cnt:=1 to mx do begin
  226.         seek (logfile,cnt+mx-1);
  227.         read (logfile,l);
  228.         seek (logfile,cnt-1);
  229.         write (logfile,l)
  230.       end;
  231.       seek (logfile,mx-1);
  232.       truncate (logfile);
  233.       writeln (usr,'Done.');
  234.       doanswer
  235.     end;
  236.  
  237.   begin
  238.     assign (logfile,'Syslog');
  239.     reset (logfile);
  240.     if ioresult<>0 then begin
  241.       rewrite (logfile);
  242.       if ioresult<>0 then begin
  243.         writeln (usr,'Unable to create log file');
  244.         halt (92)
  245.       end
  246.     end;
  247.     if filesize(logfile)>maxsyslogsize then autodeletesyslog
  248.   end;
  249.  
  250.   Procedure loadsyslogdat;
  251.   VAR tf:text;
  252.       q:lstr;
  253.       b1,b2,p,s,n:integer;
  254.   begin
  255.     numsyslogdat:=0;
  256.     with syslogdat[0] do begin
  257.       menu:=0;
  258.       subcommand:=0;
  259.       text:='SYSLOG.DAT entry not found: %'
  260.     end;
  261.     assign (tf,'syslog.dat');
  262.     reset (tf);
  263.     if ioresult=0 then begin
  264.       while not eof(tf) do begin
  265.         readln (tf,q);
  266.         p:=pos(' ',q);
  267.         if p<>0 then begin
  268.           val (copy(q,1,p-1),b1,s);
  269.           if s=0 then begin
  270.             delete (q,1,p);
  271.             p:=pos(' ',q);
  272.             if p<>0 then begin
  273.               val (copy(q,1,p-1),b2,s);
  274.               if s=0 then begin
  275.                 delete (q,1,p);
  276.                 if numsyslogdat=maxsyslogdat
  277.                   then writeln (usr,'Too many SYSLOG.DAT entries')
  278.                   else begin
  279.                     numsyslogdat:=numsyslogdat+1;
  280.                     with syslogdat[numsyslogdat] do begin
  281.                       menu:=b1;
  282.                       subcommand:=b2;
  283.                       text:=copy(q,1,30)
  284.                     end
  285.                   end
  286.               end
  287.             end
  288.           end
  289.         end
  290.       end;
  291.       textclose (tf)
  292.     end;
  293.     if numsyslogdat=0 then writeln (usr,'SYSLOG.DAT file missing or invalid')
  294.   end;
  295.  
  296.   Procedure doesfilesequal30;
  297.   VAR f:array [1..13] of file;
  298.       cnt,i:integer;
  299.   begin
  300.     for cnt := 1 to 13 do begin
  301.       assign (f[cnt],'CON');
  302.       reset (f[cnt]);
  303.       i:=ioresult;
  304.       if i<>0 then begin
  305.         
  306.         Ext_code := 2;
  307.         Halt(e_Extended_code)
  308.       end
  309.     end;
  310.     for cnt := 13 downto 1 do close(f[cnt])
  311.   end;
  312.  
  313. VAR k:char;
  314.     cnt:integer;
  315. begin
  316.   with textrec(system.output) do begin
  317.     openfunc:=@opendevice;
  318.     closefunc:=@closedevice;
  319.     flushfunc:=@writechars;
  320.     inoutfunc:=@writechars
  321.   end;
  322.   with textrec(system.input) do begin
  323.     inoutfunc:=@readcharfunc;
  324.     openfunc:=@ignorecommand;
  325.     closefunc:=@ignorecommand;
  326.     flushfunc:=@ignorecommand
  327.   end;
  328.   if checkfiles30 then doesfilesequal30;
  329.   if not driverpresent then
  330.     Begin
  331.      Ext_code := 1;
  332.      Halt(e_Extended_code);
  333.     End;
  334.   FillChar (urec,sizeof(urec),0);
  335.   urec.config:=[lowercase,eightycols,asciigraphics];
  336.   iocode:=0;
  337.   linecount:=0;
  338.   sysopavail:=bytime;
  339.   errorparam:='';
  340.   errorproc:='';
  341.   unam:='';
  342.   chainstr:='';
  343.   chatreason:='';
  344.   ulvl:=0;
  345.   unum:=-1;
  346.   logonunum:=-2;
  347.   break:=false;
  348.   nochain:=false;
  349.   nobreak:=false;
  350.   wordwrap:=false;
  351.   beginwithspacesok:=false;
  352.   dots:=false;
  353.   online:=false;
  354.   local:=true;
  355.   chatmode:=false;
  356.   texttrap:=false;
  357.   printerecho:=false;
  358.   fillchar (urec,sizeof(urec),0);
  359.   usecapsonly:=false;
  360.   uselinefeeds:=true;
  361.   curattrib:=0;
  362.   buflen:=80;
  363.   baudrate:=defbaudrate;
  364.   parity:=false;
  365.   timelock:=false;
  366.   ingetstr:=false;
  367.   modeminlock:=false;
  368.   modemoutlock:=false;
  369.   tempsysop:=false;
  370.   sysnext:=false;
  371.   forcehangup:=false;
  372.   requestbreak:=false;
  373.   disconnected:=false;
  374.   cursection:=mainsysop;
  375.   regularlevel:=0;
  376.   setparam (usecom,baudrate,parity);
  377.   doanswer;
  378.   initwinds;
  379.   for cnt:=1 to numsysfiles do initfile (sysfiles[cnt]);
  380.   cls;
  381.   loadsyslogdat;
  382.   readstatus;
  383.   openufile;
  384.   opentfile;
  385.   openlogfile;
  386.   openmfile
  387. end;
  388.  
  389. Procedure assignname (VAR t:text; nm:lstr);
  390. begin
  391.   with textrec(t) do begin
  392.     move (nm[1],name,length(nm));
  393.     name[length(nm)]:=#0
  394.   end
  395. end;
  396.  
  397.  
  398. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  399.  
  400. {initialization}
  401.  
  402. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  403.  
  404.  
  405. VAR r:registers;
  406.  
  407.  
  408. begin
  409.   textmode (bw80);
  410.   checkbreak:=false;
  411.   checkeof:=false;
  412.   directvideo:=directvideomode;
  413.   checksnow:=checksnowmode;
  414.   r.ah:=15;
  415.   intr ($10,r);
  416.  
  417.   if r.al=7
  418.     then screenseg:=$b000
  419.     else screenseg:=$b800;
  420.   textrec(system.input).mode:=fminput;
  421.   move (output,usr,sizeof(text));           { Set up device drivers }
  422.   move (output,direct,sizeof(text));
  423.   move (system.input,directin,sizeof(text));
  424.   with textrec(direct) do begin
  425.     openfunc:=@opendevice;
  426.     closefunc:=@closedevice;
  427.     flushfunc:=@directoutchars;
  428.     inoutfunc:=@directoutchars;
  429.     bufptr:=@buffer
  430.   end;
  431.   with textrec(directin) do begin
  432.     mode:=fminput;
  433.     inoutfunc:=@directinchars;
  434.     openfunc:=@ignorecommand;
  435.     flushfunc:=@ignorecommand;
  436.     closefunc:=@ignorecommand;
  437.     bufptr:=@buffer
  438.   end;
  439.   with textrec(usr) do bufptr:=@buffer;
  440.   assignname (usr,'USR');
  441.   assignname (direct,'DIRECT');
  442.   assignname (directin,'DIRECT-IN');
  443.   assignname (system.output,'OUTPUT');
  444.   assignname (system.input,'INPUT');
  445. End.
  446.