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

  1. {$R-,S-,I-,V-,B-,N-,L- }
  2. {$O-}
  3.  
  4. unit overret1;
  5.  
  6.  
  7. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  8.  
  9. interface
  10.  
  11. uses crt,
  12.      gentypes,modem,configrt,gensubs,subs1,subs2,userret,textret,flags,mainr1;
  13.  
  14. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  15.  
  16.  
  17. Procedure help (fn:mstr);
  18. Procedure edituser (eunum:integer);
  19. Procedure printnews;
  20. Procedure sendmodemstr (ss:anystr; endifcarrier:boolean);
  21. Function getlastcaller:mstr;
  22. Procedure showlastcallers;
  23. Procedure infoform;
  24. Function selectspecs (VAR us:userspecsrec):boolean; { True if user aborts }
  25. Procedure editoldspecs;
  26.  
  27.  
  28. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  29.  
  30. implementation
  31.  
  32. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  33.  
  34.  
  35. Procedure help (fn:mstr);
  36. VAR tf:text;
  37.     htopic,cnt:integer;
  38. begin
  39.   fn:=textfiledir+fn+'.HLP';
  40.   assign (tf,fn);
  41.   reset (tf);
  42.   if ioresult<>0 then begin
  43.     writestr ('Sorry, no help is availiable!');
  44.     if issysop then begin
  45.       writeln ('Sysop: To make help, create a file called ',fn+'.HLP');
  46.       writeln ('Group the lines into blocks separated by periods.');
  47.       writeln ('The first group is the topic menu; the second is the');
  48.       writeln ('help for topic 1; the third for topic 2; etc.')
  49.     end;
  50.     exit
  51.   end;
  52.   repeat
  53.     textclose (tf);
  54.     assign (tf,fn);
  55.     reset (tf);
  56.     writeln (^M);
  57.     printtexttopoint (tf);
  58.     repeat
  59.       writestr (^M'Topic number [CR quits]:');
  60.       if hungupon or (length(input)=0) then
  61.         begin
  62.           textclose (tf);
  63.           exit
  64.         end;
  65.       htopic:=valu (input)
  66.     until (htopic>0);
  67.     for cnt:=2 to htopic do
  68.       if not eof(tf)
  69.         then skiptopoint (tf);
  70.     if eof(tf)
  71.       then writestr ('Sorry, no help on that topic!')
  72.       else printtexttopoint (tf)
  73.   until 0=1
  74. end;
  75.  
  76. Procedure edituser (eunum:integer);
  77. VAR eurec:userrec;
  78.     ca:integer;
  79.     k:char;
  80. const sysopstr:array [false..true] of string[6]=('Normal','Sysop');
  81.       sectionnames:array [udsysop..databasesysop] of string[20]=
  82.         ('File transfer','Bulletin section','Voting booths',
  83.          'E-mail section','Doors','Main menu','Databases');
  84.  
  85.   Procedure truesysops;
  86.   begin
  87.     writeln ('Sorry, you may not do that without true sysop access!');
  88.     writelog (18,17,'')
  89.   end;
  90.  
  91.   Function truesysop:boolean;
  92.   begin
  93.     truesysop:=ulvl>=sysoplevel
  94.   end;
  95.  
  96.   Procedure eustatus;
  97.   VAR cnt:integer;
  98.       k:char;
  99.       c:configtype;
  100.   begin
  101.     writehdr ('Status');
  102.     with eurec do begin
  103.       write (^M'Number:    '^S,eunum,
  104.              ^M'Name:      '^S,handle,
  105.              ^M'Phone #:   '^S,phonenum,
  106.              ^M'Pwd:       '^S);
  107.       if truesysop
  108.         then write (password)
  109.         else write ('Classified');
  110.       write (^M'Level:     '^S,level,
  111.              ^M'Last on:   '^S,datestr(laston),', at ',timestr(laston),
  112.              ^M'Posts:     '^S,nbu,
  113.              ^M'Uploads:   '^S,nup,
  114.              ^M'Downloads: '^S,ndn,
  115.              ^M'Wanted:    '^S,yesno(wanted in config),
  116.              ^M'File xfer',
  117.              ^M'  Level:   '^S,udlevel,
  118.              ^M'  Points:  '^S,udpoints,
  119.              ^M'  Uploads: '^S,uploads,
  120.              ^M'  Dnloads: '^S,downloads,
  121.            ^M^M'Time on system:  '^S,totaltime:0:0,
  122.              ^M'Number of calls: '^S,numon,
  123.              ^M'Voting record:   '^S);
  124.       for cnt:=1 to maxtopics do begin
  125.         if cnt<>1 then write (',');
  126.         write (voted[cnt])
  127.       end;
  128.       writeln (^M);
  129.       for c:=udsysop to databasesysop do
  130.         if c in eurec.config
  131.           then writeln (^B'Sysop of the '^S,sectionnames[c]);
  132.       writeln
  133.     end;
  134.     writelog (18,13,'')
  135.   end;
  136.  
  137.   Procedure getmstr (t:mstr; VAR mm);
  138.   VAR m:mstr absolute mm;
  139.   begin
  140.     writeln ('Old ',t,': '^S,m);
  141.     writestr ('New '+t+'? *');
  142.     if length(input)>0 then m:=input
  143.   end;
  144.  
  145.   Procedure getsstr (t:mstr; VAR s:sstr);
  146.   VAR m:mstr;
  147.   begin
  148.     m:=s;
  149.     getmstr (t,m);
  150.     s:=m
  151.   end;
  152.  
  153.   Procedure getint (t:mstr; VAR i:integer);
  154.   VAR m:mstr;
  155.   begin
  156.     m:=strr(i);
  157.     getmstr (t,m);
  158.     i:=valu(m)
  159.   end;
  160.  
  161.   Procedure euwanted;
  162.   begin
  163.     writestr ('Wanted status: '^S+yesno(wanted in eurec.config));
  164.     writestr ('New wanted status:');
  165.     if yes
  166.       then eurec.config:=eurec.config+[wanted]
  167.       else eurec.config:=eurec.config-[wanted];
  168.     writelog (18,1,yesno(wanted in eurec.config))
  169.   end;
  170.  
  171.   Procedure eudel;
  172.   begin
  173.     writestr ('Delete user --- confirm:');
  174.     if yes then begin
  175.       deleteuser (eunum);
  176.       seek (ufile,eunum);
  177.       read (ufile,eurec);
  178.       writelog (18,9,'')
  179.     end
  180.   end;
  181.  
  182.   Procedure euname;
  183.   VAR m:mstr;
  184.   begin
  185.     m:=eurec.handle;
  186.     getmstr ('name',m);
  187.     if not match (m,eurec.handle) then
  188.       if lookupuser (m)<>0 then begin
  189.         writestr ('Already exists!  Are you sure? *');
  190.         if not yes then exit
  191.       end;
  192.     eurec.handle:=m;
  193.     writelog (18,6,m)
  194.   end;
  195.  
  196.   Procedure eupassword;
  197.   begin
  198.     if not truesysop
  199.       then truesysops
  200.       else begin
  201.         getsstr ('password',eurec.password);
  202.         writelog (18,8,'')
  203.       end
  204.   end;
  205.  
  206.   Procedure eulevel;
  207.   VAR n:integer;
  208.   begin
  209.     n:=eurec.level;
  210.     getint ('level',n);
  211.     if (n>=sysoplevel) and (not truesysop)
  212.       then truesysops
  213.       else begin
  214.         eurec.level:=n;
  215.         writelog (18,15,strr(n))
  216.       end
  217.   end;
  218.  
  219.   Procedure euphone;
  220.   VAR m:mstr;
  221.       p:integer;
  222.   begin
  223.     m:=eurec.phonenum;
  224.     buflen:=15;
  225.     getmstr ('phone number',m);
  226.     p:=1;
  227.     while p<=length(m) do
  228.       if (m[p] in ['0'..'9'])
  229.         then p:=p+1
  230.         else delete (m,p,1);
  231.     if length(m)>7 then begin
  232.       eurec.phonenum:=m;
  233.       writelog (18,16,m)
  234.     end
  235.   end;
  236.  
  237.   Procedure boardflags;
  238.   VAR quit:boolean;
  239.  
  240.     Procedure listflags;
  241.     VAR bd:boardrec;
  242.         cnt:integer;
  243.     begin
  244.       seek (bdfile,0);
  245.       for cnt:=0 to filesize(bdfile)-1 do begin
  246.         read (bdfile,bd);
  247.         tab (bd.shortname,9);
  248.         tab (bd.boardname,30);
  249.         writeln (accessstr[getuseraccflag (eurec,cnt)]);
  250.         if break then exit
  251.       end
  252.     end;
  253.  
  254.     Procedure changeflag;
  255.     VAR bn,q:integer;
  256.         bname:mstr;
  257.         ac:accesstype;
  258.     begin
  259.       buflen:=8;
  260.       writestr ('Board to change access:');
  261.       bname:=input;
  262.       bn:=searchboard(input);
  263.       if bn=-1 then begin
  264.         writeln ('Not found!');
  265.         exit
  266.       end;
  267.       writeln (^B^M'Current access: '^S,
  268.                accessstr[getuseraccflag (eurec,bn)]);
  269.       getacflag (ac,input);
  270.       if ac=invalid then exit;
  271.       setuseraccflag (eurec,bn,ac);
  272.       case ac of
  273.         letin:q:=2;
  274.         keepout:q:=3;
  275.         bylevel:q:=4
  276.       end;
  277.       writelog (18,q,bname)
  278.     end;
  279.  
  280.     Procedure allflags;
  281.     VAR ac:accesstype;
  282.     begin
  283.       writehdr ('Set all board access flags');
  284.       getacflag (ac,input);
  285.       if ac=invalid then exit;
  286.       writestr ('Confirm [Y/N]:');
  287.       if not yes then exit;
  288.       setalluserflags (eurec,ac);
  289.       writelog (18,5,accessstr[ac])
  290.     end;
  291.  
  292.   begin
  293.     opentempbdfile;
  294.     quit:=false;
  295.     repeat
  296.       repeat
  297.         writestr (^M'L)ist flags, C)hange one flag, A)ll flags, or Q)uit:');
  298.         if hungupon then exit
  299.       until length(input)<>0;
  300.       case upcase(input[1]) of
  301.         'L':listflags;
  302.         'C':changeflag;
  303.         'A':allflags;
  304.         'Q':quit:=true
  305.       end
  306.     until quit;
  307.     closetempbdfile
  308.   end;
  309.  
  310.   Procedure specialsysop;
  311.  
  312.     Procedure getsysop (c:configtype);
  313.     begin
  314.       writeln ('Section ',sectionnames[c],': '^S,
  315.                sysopstr[c in eurec.config]);
  316.       writestr ('Grant sysop access? *');
  317.       if length(input)<>0
  318.         then if yes
  319.           then
  320.             begin
  321.               eurec.config:=eurec.config+[c];
  322.               writelog (18,10,sectionnames[c])
  323.             end
  324.           else
  325.             begin
  326.               eurec.config:=eurec.config-[c];
  327.               writelog (18,11,sectionnames[c])
  328.             end
  329.     end;
  330.  
  331.   begin
  332.     if not truesysop then begin
  333.       truesysops;
  334.       exit
  335.     end;
  336.     writestr
  337. ('Section of M)ain, F)ile, B)ulletin, V)oting, E)mail, D)atabase, P)Doors:');
  338.     if length(input)=0 then exit;
  339.     case upcase(input[1]) of
  340.       'M':getsysop (mainsysop);
  341.       'F':getsysop (udsysop);
  342.       'B':getsysop (bulletinsysop);
  343.       'V':getsysop (votingsysop);
  344.       'E':getsysop (emailsysop);
  345.       'D':getsysop (databasesysop);
  346.       'P':getsysop (doorssysop)
  347.     end
  348.   end;
  349.  
  350.   Procedure getlogint (prompt:mstr; VAR i:integer; ln:integer);
  351.   begin
  352.     getint (prompt,i);
  353.     writelog (18,ln,strr(i))
  354.   end;
  355.  
  356. VAR q:integer;
  357. begin
  358.   seek (ufile,eunum);
  359.   read (ufile,eurec);
  360.   writelog (2,3,eurec.handle);
  361.   repeat
  362.     q:=menu('User edit','UEDIT','SDHPLOEWTBQYNI');
  363.     case q of
  364.       1:eustatus;
  365.       2:eudel;
  366.       3:euname;
  367.       4:eupassword;
  368.       5:eulevel;
  369.       6:getlogint ('u/d points',eurec.udpoints,7);
  370.       7:getlogint ('u/d level',eurec.udlevel,14);
  371.       8:euwanted;
  372.       9:getlogint ('time for today',eurec.timetoday,12);
  373.       10:boardflags;
  374.       12:specialsysop;
  375.       13:euphone;
  376.       14:showinfoforms(strr(eunum))
  377.     end
  378.   until hungupon or (q=11);
  379.   writeurec;
  380.   seek (ufile,eunum);
  381.   write (ufile,eurec);
  382.   readurec
  383. end;
  384.  
  385. Procedure printnews;
  386. VAR nfile:file of integer;
  387.     line:integer;
  388. begin
  389.   assign (nfile,'News');
  390.   reset (nfile);
  391.   if ioresult<>0 then exit;
  392.   if filesize (nfile)=0 then begin
  393.     close (nfile);
  394.     exit
  395.   end;
  396.   writehdr ('News: Hit <SPACE> to abort');
  397.   while not (eof(nfile) or break or hungupon) do begin
  398.     read (nfile,line);
  399.     if line>=0 then begin
  400.       writeln;
  401.       printtext (line)
  402.     end
  403.   end;
  404.   close (nfile)
  405. end;
  406.  
  407. Procedure sendmodemstr (ss:anystr; endifcarrier:boolean);
  408. VAR cnt,ptr:integer;
  409.     k:char;
  410. label exit;
  411. begin
  412.   ptr:=0;
  413.   while ptr<length(ss) do
  414.     begin
  415.       if keyhit or (carrier=endifcarrier) then goto exit;
  416.       ptr:=ptr+1;
  417.       k:=ss[ptr];
  418.       case k of
  419.         '|':sendchar (^M);
  420.         '~':delay (500);
  421.         '^':begin
  422.               ptr:=ptr+1;
  423.               if ptr>length(ss)
  424.                 then k:='^'
  425.                 else k:=upcase(ss[ptr]);
  426.               if k in ['A'..'Z']
  427.                 then sendchar (chr(ord(k)-64))
  428.                 else sendchar (k)
  429.             end;
  430.         else sendchar (k)
  431.       end;
  432.       delay (50);
  433.       while numchars>0 do writecon (getchar)
  434.     end;
  435.   cnt:=0;
  436.   repeat
  437.     while numchars>0 do begin
  438.       cnt:=0;
  439.       writecon (getchar)
  440.     end;
  441.     cnt:=cnt+1
  442.   until (cnt=1000) or keyhit or (carrier=endifcarrier);
  443.   exit:
  444.   break:=keyhit
  445. end;
  446.  
  447. Function getlastcaller:mstr;
  448. VAR qf:file of lastrec;
  449.     l:lastrec;
  450. begin
  451.   getlastcaller:='';
  452.   assign (qf,'Callers');
  453.   reset (qf);
  454.   if ioresult=0 then
  455.     if filesize(qf)>0
  456.       then
  457.         begin
  458.           seek (qf,0);
  459.           read (qf,l);
  460.           getlastcaller:=l.name
  461.         end;
  462.   close (qf)
  463. end;
  464.  
  465. Procedure showlastcallers;
  466. VAR qf:file of lastrec;
  467.     cnt:integer;
  468.     l:lastrec;
  469. begin
  470.   assign (qf,'Callers');
  471.   reset (qf);
  472.   if ioresult=0 then begin
  473.     writehdr ('Recent caller list');
  474.     break:=false;
  475.     for cnt:=0 to filesize(qf)-1 do
  476.       if not break then begin
  477.         read (qf,l);
  478.         tab (l.name,33);
  479.         writeln (datestr(l.when)+' '+timestr(l.when))
  480.       end
  481.   end;
  482.   close (qf)
  483. end;
  484.  
  485. Procedure infoform;
  486. VAR ff:text;
  487.     fn:lstr;
  488.     k:char;
  489.     me:message;
  490. begin
  491.   writeln;
  492.   fn:=textfiledir+'InfoForm';
  493.   if not exist (fn) then begin
  494.     writestr ('There isn''t an information form right now.');
  495.     if issysop then
  496.       writeln ('Sysop: To make an information form, create a text file',
  497.              ^M'called ',fn,'.  Use * to indicate a pause for user input.');
  498.     exit
  499.   end;
  500.   if urec.infoform<>-1 then begin
  501.     writestr ('You have an existing information form!  Replace it? *');
  502.     if not yes then exit;
  503.     deletetext (urec.infoform);
  504.     urec.infoform:=-1;
  505.     writeurec
  506.   end;
  507.   assign (ff,fn);
  508.   reset (ff);
  509.   me.numlines:=1;
  510.   me.title:='';
  511.   me.anon:=false;
  512.   me.text[1]:='Filled out on: '+datestr(now)+' at '+timestr(now);
  513.   while not eof(ff) do begin
  514.     if hungupon then begin
  515.       textclose (ff);
  516.       exit
  517.     end;
  518.     read (ff,k);
  519.     if k='*' then begin
  520.       nochain:=true;
  521.       getstr;
  522.       me.numlines:=me.numlines+1;
  523.       me.text[me.numlines]:=input
  524.     end else writechar (k)
  525.   end;
  526.   textclose (ff);
  527.   urec.infoform:=maketext (me);
  528.   writeurec
  529. end;
  530.  
  531. Procedure openusfile;
  532. const newusers:userspecsrec=(name:'New users';minlevel:1;maxlevel:1;
  533.          minlaston:-maxint;maxlaston:maxint;minpcr:-maxint;maxpcr:maxint);
  534. begin
  535.   assign (usfile,'userspec');
  536.   reset (usfile);
  537.   if ioresult<>0 then begin
  538.     rewrite (usfile);
  539.     if level2nd<>0 then newusers.maxlevel:=level2nd;
  540.     write (usfile,newusers)
  541.   end
  542. end;
  543.  
  544. Procedure editspecs (VAR us:userspecsrec);
  545.  
  546.   Procedure get (tex:string; VAR value:integer; min:boolean);
  547.   VAR vstr:sstr;
  548.   begin
  549.     buflen:=6;
  550.     if abs(value)=maxint then vstr:='None' else vstr:=strr(value);
  551.     writestr (tex+' ['+vstr+']:');
  552.     if input[0]<>#0
  553.       then if upcase(input[1])='N'
  554.         then if min
  555.           then value:=-maxint
  556.           else value:=maxint
  557.         else value:=valu(input)
  558.   end;
  559.  
  560.   Procedure getreal (tex:string; VAR value:real; min:boolean);
  561.   VAR vstr:sstr;
  562.       s:integer;
  563.   begin
  564.     buflen:=10;
  565.     if abs(value)=maxint then vstr:='None' else vstr:=streal(value);
  566.     writestr (tex+' ['+vstr+']:');
  567.     if length(input)<>0
  568.       then if upcase(input[1])='N'
  569.         then if min
  570.           then value:=-maxint
  571.           else value:=maxint
  572.         else begin
  573.           val (input,value,s);
  574.           if s<>0 then value:=0
  575.         end
  576.   end;
  577.  
  578. begin
  579.   writeln (^B^M'Enter specifications; N for none.'^M);
  580.   buflen:=30;
  581.   writestr ('Specification set name ['+us.name+']:');
  582.   if length(input)<>0
  583.     then if match(input,'N')
  584.       then us.name:='Unnamed'
  585.       else us.name:=input;
  586.   get ('Lowest level',us.minlevel,true);
  587.   get ('Highest level',us.maxlevel,true);
  588.   get ('Lowest #days since last call',us.minlaston,true);
  589.   get ('Highest #days since last call',us.maxlaston,true);
  590.   getreal ('Lowest post to call ratio',us.minpcr,true);
  591.   getreal ('Highest post to call ratio',us.maxpcr,true)
  592. end;
  593.  
  594. Procedure getspecs (VAR us:userspecsrec);
  595. begin
  596.   with us do begin
  597.     name:='Unnamed';                     { Assumes USFILE is open !! }
  598.     minlevel:=-maxint;
  599.     maxlevel:=maxint;
  600.     minlaston:=-maxint;
  601.     maxlaston:=maxint;
  602.     minpcr:=-maxint;
  603.     maxpcr:=maxint
  604.   end;
  605.   editspecs (us);
  606.   writestr (^M'Save these specs to disk? *');
  607.   if yes then begin
  608.     seek (usfile,filesize(usfile));
  609.     write (usfile,us)
  610.   end
  611. end;
  612.  
  613. Function searchspecs (VAR us:userspecsrec; name:mstr; editem:boolean):boolean;
  614. VAR pos:integer;
  615. begin
  616.   seek (usfile,0);
  617.   pos:=0;
  618.   while not eof(usfile) do begin
  619.     read (usfile,us);
  620.     if match(us.name,name) or (valu(name)=pos+1) then begin
  621.       searchspecs:=true;
  622.       if editem then begin
  623.         editspecs (us);
  624.         seek (usfile,pos);
  625.         write (usfile,us)
  626.       end;
  627.       exit
  628.     end;
  629.     pos:=pos+1
  630.   end;
  631.   writeln (^M'Not found!');
  632.   searchspecs:=false
  633. end;
  634.  
  635. Procedure listspecs;
  636. VAR us:userspecsrec;
  637.     pos:integer;
  638.  
  639.   Procedure writeval (n:integer);
  640.   begin
  641.     if abs(n)=maxint then write ('   None') else write(n:7)
  642.   end;
  643.  
  644.   Procedure writevalreal (n:real);
  645.   begin
  646.     if abs(n)=maxint then write ('   None') else write(n:7:2)
  647.   end;
  648.  
  649. begin
  650.   writehdr ('User Specification Sets');
  651.   seek (usfile,0);
  652.   pos:=0;
  653.   while not (break or eof(usfile)) do begin
  654.     pos:=pos+1;
  655.     read (usfile,us);
  656.     write (pos:3,'. ');
  657.     tab (us.name,30);
  658.     writeval (us.minlevel);
  659.     writeval (us.maxlevel);
  660.     writeval (us.minlaston);
  661.     writeval (us.maxlaston);
  662.     writevalreal (us.minpcr);
  663.     writevalreal (us.maxpcr);
  664.     writeln
  665.   end
  666. end;
  667.  
  668. Function selectaspec (VAR us:userspecsrec; editem:boolean):boolean;
  669. VAR done:boolean;
  670. begin
  671.   selectaspec:=false;
  672.   openusfile;
  673.   if filesize(usfile)=0
  674.     then getspecs(us)
  675.     else
  676.       repeat
  677.         done:=true;
  678.         writestr (^M'Specification set name (?=list, A=add):');
  679.         if length(input)=0
  680.           then selectaspec:=true
  681.           else if match(input,'A')
  682.             then getspecs(us)
  683.             else if match(input,'?')
  684.               then
  685.                 begin
  686.                   listspecs;
  687.                   done:=false
  688.                 end
  689.               else done:=(not editem) and searchspecs (us,input,editem)
  690.       until done;
  691.   close (usfile)
  692. end;
  693.  
  694. Function selectspecs (VAR us:userspecsrec):boolean;
  695. begin
  696.   selectspecs:=selectaspec (us,false)
  697. end;
  698.  
  699. Procedure editoldspecs;
  700. VAR dummy:boolean;
  701.     us:userspecsrec;
  702. begin
  703.   dummy:=selectaspec (us,true)
  704. end;
  705.  
  706.  
  707.  
  708. Begin
  709. End.
  710.