home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 276.img / FORUM21S.ZIP / ABOUT.PAS next >
Pascal/Delphi Source File  |  1988-02-13  |  6KB  |  275 lines

  1. {$R-,S-,I-,D-,T-,F-,V-,B-,N-,L+ }
  2. {$M 65500,0,0 }
  3.  
  4. unit about;
  5.  
  6. interface
  7.  
  8. uses gentypes,configrt,gensubs,subs1,subs2;
  9.  
  10. procedure aboutthisbbs;
  11.  
  12. implementation
  13.  
  14. procedure aboutthisbbs;
  15. var ab:abrec;
  16.  
  17.   function numabouts:integer;
  18.   begin
  19.     numabouts:=filesize(abfile)
  20.   end;
  21.  
  22.   procedure seekabfile (n:integer);
  23.   begin
  24.     seek (abfile,n-1)
  25.   end;
  26.  
  27.   procedure openabfile;
  28.   var n:integer;
  29.   begin
  30.     n:=ioresult;
  31.     assign (abfile,'Aboutbbs');
  32.     reset (abfile);
  33.     if ioresult<>0 then begin
  34.       close (abfile);
  35.       n:=ioresult;
  36.       rewrite (abfile)
  37.     end
  38.   end;
  39.  
  40.   procedure listabouts;
  41.   var cnt:integer;
  42.       b:boolean;
  43.   begin
  44.     writeln;
  45.     b:=true;
  46.     seekabfile (1);
  47.     for cnt:=1 to numabouts do begin
  48.       read (abfile,ab);
  49.       if (ulvl>=ab.level) or issysop then begin
  50.         if b then begin
  51.           writestr (^M'Num Title'^M);
  52.           b:=false
  53.         end;
  54.         tab (strr(cnt),4);
  55.         writeln (ab.title);
  56.         if break then exit
  57.       end
  58.     end;
  59.     if b then writestr ('Sorry, no information files are available!')
  60.   end;
  61.  
  62.   function getaboutnum:integer;
  63.   var n:integer;
  64.   begin
  65.     getaboutnum:=0;
  66.     repeat
  67.       writestr ('Information file number [?=list]:');
  68.       if length(input)=0 then exit;
  69.       if upcase(input[1])='?'
  70.         then listabouts
  71.         else begin
  72.           n:=valu(input);
  73.           if (n<1) or (n>numabouts) then begin
  74.             writestr (^M'Sorry, file number out of range!');
  75.             exit
  76.           end;
  77.           seekabfile (n);
  78.           read (abfile,ab);
  79.           if (ulvl<ab.level) and (not issysop) then begin
  80.             reqlevel (ab.level);
  81.             exit
  82.           end;
  83.           getaboutnum:=n;
  84.           exit
  85.         end
  86.     until hungupon
  87.   end;
  88.  
  89.   procedure showaboutfile (n:integer);
  90.   begin
  91.     seekabfile (n);
  92.     read (abfile,ab);
  93.     if ulvl<ab.level then begin
  94.       reqlevel (ab.level);
  95.       exit
  96.     end;
  97.     writeln (^M'Title:   '^S,ab.title,
  98.              ^M'Updated: '^S,timestr(ab.when),' at ',datestr(ab.when),^M);
  99.     printfile (ab.fname)
  100.   end;
  101.  
  102.   procedure makeaboutfile;
  103.   var t:text;
  104.       b:boolean;
  105.   begin
  106.     assign (t,ab.fname);
  107.     rewrite (t);
  108.     writestr (^M'Enter text, /S to save:'^M);
  109.     repeat
  110.       lastprompt:='Continue...'^M;
  111.       wordwrap:=true;
  112.       getstr;
  113.       b:=match(input,'/S');
  114.       if not b then writeln (t,input)
  115.     until b;
  116.     textclose (t);
  117.     writestr (^M'File created!');
  118.     ab.when:=now;
  119.     writelog (3,2,ab.fname)
  120.   end;
  121.  
  122.   procedure addabout;
  123.   begin
  124.     writestr ('Title:');
  125.     if length(input)=0 then exit;
  126.     ab.title:=input;
  127.     writestr ('Level:');
  128.     ab.level:=valu(input);
  129.     writestr ('Filename (include path ['+textfiledir+']):');
  130.     if length(input)=0 then exit;
  131.     if pos('\',input)=0 then input:=textfiledir+input;
  132.     ab.fname:=input;
  133.     if not exist(ab.fname) then begin
  134.       writestr ('File not found!  Enter file now? *');
  135.       if yes then makeaboutfile
  136.     end;
  137.     ab.when:=now;
  138.     seekabfile (numabouts+1);
  139.     write (abfile,ab);
  140.     writestr ('File added.');
  141.     writelog (3,1,ab.title)
  142.   end;
  143.  
  144.   procedure changeabout;
  145.   var n:integer;
  146.  
  147.     procedure getstr (prompt:mstr; var ss; len:integer);
  148.     var a:anystr absolute ss;
  149.     begin
  150.       writeln (^B^M'  Current ',prompt,' is: '^S,a);
  151.       buflen:=len;
  152.       writestr ('Enter new '+prompt+':');
  153.       if length(input)>0 then a:=input;
  154.     end;
  155.  
  156.     procedure getint (prompt:mstr; var i:integer);
  157.     var q:sstr;
  158.         n:integer;
  159.     begin
  160.       str (i,q);
  161.       getstr (prompt,q,5);
  162.       n:=valu (q);
  163.       if n<>0 then i:=n
  164.     end;
  165.  
  166.   begin
  167.     n:=getaboutnum;
  168.     if n=0 then exit;
  169.     seekabfile (n);
  170.     read (abfile,ab);
  171.     getstr ('title',ab.title,80);
  172.     getint ('level',ab.level);
  173.     getstr ('filename',ab.fname,80);
  174.     if not exist (ab.fname) then write (^B^M,ab.fname,' not found!');
  175.     writestr (^M'Create new file '+ab.fname+'? *');
  176.     if yes then makeaboutfile;
  177.     seekabfile (n);
  178.     write (abfile,ab);
  179.     writelog (3,3,ab.title);
  180.   end;
  181.  
  182.   procedure deleteabout;
  183.   var cnt,n:integer;
  184.       f:file;
  185.   begin
  186.     n:=getaboutnum;
  187.     if n=0 then exit;
  188.     seekabfile (n);
  189.     read (abfile,ab);
  190.     writestr ('Delete '+ab.title+'? *');
  191.     if not yes then exit;
  192.     writestr ('Erase disk file '+ab.fname+'? *');
  193.     if yes then begin
  194.       assign (f,ab.fname);
  195.       erase (f);
  196.       if ioresult<>0
  197.         then writestr ('Couldn''t erase file.')
  198.     end;
  199.     for cnt:=n+1 to numabouts do begin
  200.       seekabfile (cnt);
  201.       read (abfile,ab);
  202.       seekabfile (cnt-1);
  203.       write (abfile,ab)
  204.     end;
  205.     seekabfile (numabouts);
  206.     truncate (abfile);
  207.     writestr (^M'Deleted.');
  208.     writelog (3,4,ab.title)
  209.   end;
  210.  
  211.   procedure updateabout;
  212.   var n:integer;
  213.   begin
  214.     n:=getaboutnum;
  215.     if n=0 then exit;
  216.     seekabfile (n);
  217.     read (abfile,ab);
  218.     ab.when:=now;
  219.     seekabfile (n);
  220.     write (abfile,ab);
  221.     writeln ('File ',n,' time/date updated.');
  222.     writelog (3,5,ab.title)
  223.   end;
  224.  
  225.   procedure sysopcommands;
  226.   var q:integer;
  227.   begin
  228.     if not issysop then begin
  229.       reqlevel (sysoplevel);
  230.       exit
  231.     end;
  232.     repeat
  233.       q:=menu ('ABOUT sysop','ABOUT','QACDU');
  234.       case q of
  235.         2:addabout;
  236.         3:changeabout;
  237.         4:deleteabout;
  238.         5:updateabout;
  239.       end
  240.     until hungupon or (q=1)
  241.   end;
  242.  
  243. label exit;
  244. var prompt:lstr;
  245.     n:integer;
  246.     k:char;
  247. begin
  248.   openabfile;
  249.   repeat
  250.     prompt:=^M'Information file number [?=list';
  251.     if issysop then prompt:=prompt+', %=sysop';
  252.     prompt:=prompt+']:';
  253.     writestr (prompt);
  254.     if length(input)=0 then goto exit;
  255.     k:=upcase(input[1]);
  256.     case k of
  257.       'Q':goto exit;
  258.       '%':sysopcommands;
  259.       '?':listabouts;
  260.       else begin
  261.         n:=valu(input);
  262.         if n<>0 then
  263.           if (n<0) or (n>numabouts)
  264.             then writestr ('Out of range!')
  265.             else showaboutfile (n)
  266.       end
  267.     end
  268.   until hungupon;
  269.   exit:
  270.   close (abfile)
  271. end;
  272.  
  273. begin
  274. end.
  275.