home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / SYSPC22.ZIP / ABOUT.PAS next >
Encoding:
Pascal/Delphi Source File  |  1986-08-15  |  6.1 KB  |  268 lines

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