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

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