home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / bbs / tpbbs10.ark / TPMS10.INC < prev    next >
Encoding:
Text File  |  1986-09-14  |  14.4 KB  |  719 lines

  1. {**************************************************}
  2. {  TPMESG.INC   This module includes all of the    }
  3. {  message base procedures for TPBBS.              }
  4. {**************************************************}
  5.  
  6. procedure msgprompt(tag:password);
  7.  
  8. begin
  9. line1:='Msg #';
  10. if not xpr then
  11.  begin
  12.   str(mfirst,temp);
  13.   line1:=line1+' ('+temp;
  14.   str(mlast,temp);
  15.   line1:=line1+' - '+temp+') to '+tag;
  16.  end;
  17. line1:=line1+'? ';
  18. n:=1;
  19. printstring;
  20. end;
  21.  
  22.  
  23. procedure entrmsg;
  24. var aa : allstrings;
  25.  
  26. label getname,found,enttxt,mantxt,abort,done;
  27. begin
  28.    str(mlast+1,temp);
  29.    line:='Msg # will be '+temp;
  30.    printstring;
  31.   getname: line1:='To (C/R for all)? ';n:=1;
  32.   printstring;
  33.   c:=1;getstring;c:=0;
  34.   if bstring='' then bstring:='ALL';
  35.   whoto:=bstring;
  36.   aa:=whoto;
  37.   if whoto='SYSOP' then goto found;
  38.   if whoto<>'ALL' then
  39.    begin
  40.     assign(user_file,drive2+'USER'+ext);
  41.     reset(user_file);
  42.     while not eof(user_file) do
  43.     begin
  44.      read(user_file,user_rec);
  45.      with user_rec do
  46.      begin
  47.       if aa=name then goto found;
  48.      end;
  49.     end;
  50.     line1:='Not a known user. OK(Y/N)? ';n:=1;
  51.     printstring;
  52.     getstring;
  53.     bstring:=copy(bstring,1,1);
  54.     bstring:=stupcase(bstring);
  55.     if bstring<>'Y' then
  56.      begin
  57.      close(user_file);
  58.      goto getname;
  59.      end;
  60.    end;
  61.   found: line1:='Subject? ';n:=1;
  62.   printstring;
  63.   getstring;
  64.   if bstring='' then goto abort;
  65.   subto:=bstring;
  66.   line1:='Private message (Y/N)? ';n:=1;
  67.   printstring;
  68.   getstring;
  69.   if bstring='' then bstring:='N';
  70.   dd:=copy(bstring,1,1);
  71.   dd:=stupcase(dd);
  72.   if dd='Y' then passto:='*' else passto:='';
  73.   if not xpr then
  74.    begin
  75.     line:='Enter up to 15 lines of text (NO semicolons).';
  76.     printstring;
  77.     line:='Type C/R on blank line to end.';
  78.     printstring;
  79.    end;
  80.   line:='   I------------------------------------------------------------I';
  81.   printstring;
  82.   lc:=1;
  83.  
  84. enttxt: while (lc<16) and (bstring<>'') do
  85.   begin
  86.    str(lc,temp);
  87.    if lc<10 then line1:=' '+temp+'>' else line1:=temp+'>';
  88.    n:=1;printstring;
  89.    getstring;
  90.    if bstring<>'' then messbuff[lc]:=bstring;
  91.    if lc>12 then
  92.     begin
  93.      str(15-lc,temp);
  94.      line:='('+temp+' lines left)';
  95.      printstring;
  96.     end;
  97.    lc:=lc+1;
  98.   end;
  99.  if lc=16 then lc:=15 else lc:=lc-2;
  100.  
  101. mantxt:
  102.  if lc=0 then goto abort;
  103.  writeln;
  104.  if xpr then line1:='L,E,A,C,S: ' else line1:='L)ist E)dit A)bort C)ontinue S)ave: ';
  105.  n:=1;
  106.  printstring;
  107.  getstring;
  108.  if bstring='' then goto mantxt;
  109.  aa:=stupcase(bstring);
  110.  a:=pos(aa,'LEACS');
  111.   case a of
  112.    1: begin          {List}
  113.       line:='To:  '+whoto;
  114.       printstring;
  115.       line:='Re:  '+subto;
  116.       printstring;
  117.       line:='PW:  '+passto;
  118.       printstring;
  119.       writeln;
  120.       for i:=1 to lc do
  121.        begin
  122.         str(i,temp);
  123.         if i<10 then line:=' '+temp+'>' else line:=temp+'>';
  124.         line:=line+messbuff[i];printstring;
  125.        end;
  126.       end;
  127.  
  128.  2: begin            {Edit}
  129.       if not xpr then
  130.        begin
  131.         line:='Enter line number to change (C/R to end).';
  132.         printstring;
  133.         line:='Then enter replacement or C/R for no change.';
  134.         printstring;
  135.        end;
  136.       line1:='Line #? ';n:=1;
  137.       printstring;
  138.       getstring;
  139.       makenum;
  140.        if (x>0) and (x<=lc) then
  141.         begin
  142.          if not xpr then line:='Was:';printstring;
  143.          str(x,temp);
  144.          if x<10 then line:=' '+temp+'>' else line:=temp+'>';
  145.          line:=line+messbuff[x];printstring;
  146.          if x<10 then line1:=' '+temp+'>' else line1:=temp+'>';
  147.          n:=1;printstring;
  148.          getstring;
  149.          if bstring<>'' then messbuff[x]:=bstring;
  150.         end;
  151.     end;
  152.  
  153.  3: goto abort;      {Abort}
  154.  
  155.  4: begin            {Continue}
  156.      lc:=lc+1;if lc<16 then goto enttxt;
  157.     end;
  158.  
  159.  5: begin            {Save}
  160.      line1:='Updating system files...';
  161.      n:=1;printstring;
  162.  
  163.  {Counters}
  164.      assign(stat_file,drive2+'COUNTERS'+ext);
  165.      reset(stat_file);
  166.      read(stat_file,stat_rec);
  167.      with stat_rec do
  168.       begin
  169.        seek(stat_file,filepos(stat_file)-1);
  170.        message_pointer:=message_pointer+1;
  171.        msgs:=message_pointer;
  172.        calls:=calls;
  173.        mlast:=mlast+1;
  174.        if mfirst=0 then mfirst:=1;mstart:=1;
  175.        mnum:=mlast;
  176.        seek(summary_file,1);
  177.        write(stat_file,stat_rec);
  178.        close(stat_file);
  179.       end;
  180.  
  181.  {Summary}
  182.      assign(summary_file,drive3+'SUMMARY'+ext);
  183.      {$I-}
  184.      reset(summary_file);
  185.      {$I+}
  186.      if ioresult<>0 then
  187.      begin
  188.       rewrite(summary_file);
  189.      end;
  190.      if ioresult=0 then
  191.      begin
  192.       seek(summary_file,filesize(summary_file));
  193.      end;
  194.      with summary_rec do
  195.       begin
  196.        msgnum:=mlast;
  197.        person_from:=firstname+' '+lastname;
  198.        person_to:=whoto;
  199.        subject:=subto;
  200.        mdate:=pdate;
  201.        mpassword:=passto;
  202.        no_of_lines:=lc;
  203.        write(summary_file,summary_rec);
  204.       end;
  205.       close(summary_file);
  206.  
  207. {Messages}
  208.       assign(message_file,drive3+'MESSAGES'+ext);
  209.       {$I-}
  210.       reset(message_file);
  211.       {$I+}
  212.       if ioresult<>0 then rewrite(message_file)
  213.       else seek(message_file,filesize(message_file));
  214.       with message_rec do
  215.        begin
  216.         str(mlast,temp);
  217.         msgtext:=temp;
  218.         write(message_file,message_rec);
  219.         msgtext:=firstname+' '+lastname;
  220.         write(message_file,message_rec);
  221.         msgtext:=whoto;
  222.         write(message_file,message_rec);
  223.         msgtext:=subto;
  224.         write(message_file,message_rec);
  225.         if clock then
  226.          begin
  227.           getdate;
  228.           gettime;
  229.          end;
  230.         msgtext:=pdate+'  '+ptime;
  231.         write(message_file,message_rec);
  232.         msgtext:=passto;
  233.         write(message_file,message_rec);
  234.         for i:= 1 to lc do
  235.          begin
  236.           msgtext:=messbuff[i];
  237.           write(message_file,message_rec);
  238.          end;
  239.         msgtext:='9999';
  240.         write(message_file,message_rec);
  241.        end;
  242.       close(message_file);
  243.     writeln;
  244.     goto done;
  245.  end;
  246. end;
  247. goto mantxt;
  248.  
  249. line:='Entry finished.';
  250. printstring;
  251. close(user_file);
  252. abort: line:='++ Aborted ++';
  253. printstring;
  254. done:;
  255. end;
  256.  
  257. {get a record from the message file, put it in temp}
  258. procedure readrec;
  259.  
  260. begin
  261. read(message_file,message_rec);
  262. with message_rec do
  263.  begin
  264.   temp:=msgtext;
  265.  end;
  266. end;
  267.  
  268. procedure readmsg;
  269.  
  270. label query,search,read1,read2,read3,read4,loop,loop1,skip,done;
  271.  
  272. begin
  273. fflag:=false;
  274. query: writeln;
  275.  option:=' ';
  276.  msgprompt('Read');
  277.  getstring;
  278.  if bstring='' then goto done;
  279.  makenum;
  280.  rnum:=x;
  281.  if dd='+' then option:='+';
  282.  writeln;
  283.  if (rnum<mfirst) or (rnum>mlast) then
  284.   begin
  285.    line:='++ No such msg ++';
  286.    printstring;
  287.    goto query;
  288.   end;
  289.  writeln;
  290.  fflag:=true;
  291.  assign(message_file,drive3+'MESSAGES'+ext);
  292.  {$I-}
  293.  reset(message_file);
  294.  {$I+}
  295.  if ioresult<>0 then goto query;
  296.  search:
  297.  while not eof(message_file) do
  298.   begin
  299.    readrec;
  300.    bstring:=temp;
  301.    makenum;
  302.    if (x=0) or (x=30000) then goto skip;
  303.    if rnum=x then goto read1;
  304.    if rnum<x then goto loop;
  305. skip: while temp<>'9999' do
  306.        begin
  307.         readrec;
  308.        end;
  309.   end;
  310. goto done;
  311.  
  312. loop:
  313. if option<>'+' then
  314.  begin
  315.   line:='++ Message not found ++';
  316.   printstring;
  317.   goto query;
  318.  end;
  319.  
  320. read1:
  321.  str(x,msghead[1]);
  322.  for i:=2 to 5 do
  323.   begin
  324.    readrec;
  325.    msghead[i]:=temp;
  326.   end;
  327.  readrec;
  328.  if firstname='SYSOP' then goto read2;
  329.  if temp='*' then
  330.   begin
  331.    line:=stupcase(firstname)+' '+stupcase(lastname);
  332.    temp2:=stupcase(msghead[2]);
  333.    if line<>temp2 then
  334.     begin
  335.      temp2:=stupcase(msghead[3]);
  336.      if line<>temp2 then goto loop1;
  337.     end;
  338.    writeln;
  339.    goto read2;
  340.   end;
  341.  writeln;
  342.  goto read2;
  343.  
  344. loop1:
  345. while temp<>'9999' do
  346.  begin
  347.   readrec;
  348.  end;
  349.  writeln('Private message.');
  350.  writeln;
  351.  if option='+' then goto search;
  352.  goto read4;
  353.  
  354. read2:
  355.  line:='Msg #  :'+msghead[1];
  356.  printstring;
  357.  line:='From   :'+msghead[2];
  358.  printstring;
  359.  line:='To     :'+msghead[3];
  360.  printstring;
  361.  line:='Subject:'+msghead[4];
  362.  printstring;
  363.  line:='Date   :'+msghead[5];
  364.  printstring;
  365.  writeln;
  366.  
  367. read3:
  368.   readrec;
  369.   if temp<>'9999' then
  370.    begin
  371.     line:=temp;
  372.     printstring;
  373.     goto read3;
  374.    end;
  375.  
  376. read4:
  377. writeln;
  378. if option<>'+' then goto query;
  379. if page then pprompt;
  380. if dd='N' then goto done;
  381. goto search;
  382.  
  383. done:
  384. if fflag=true then
  385.  close(message_file);
  386. fflag:=false;
  387. end;
  388.  
  389. procedure summinit;
  390. label foundstart,done;
  391.  
  392. begin
  393. fflag:=false;
  394. writeln;
  395. msgprompt('Start');
  396. getstring;
  397. makenum;
  398. rnum:=x;
  399. writeln;
  400. line:='';
  401. if rnum>mlast then
  402.  begin
  403.   line:='++ No such msg ++';
  404.   printstring;
  405.   goto done;
  406.  end;
  407.  
  408. fflag:=true;
  409. assign(summary_file,drive3+'SUMMARY'+ext);
  410. reset(summary_file);
  411. while not eof(summary_file) do
  412.  begin
  413.   read(summary_file,summary_rec);
  414.   with summary_rec do
  415.    begin
  416.     if msgnum>=rnum then goto foundstart;
  417.    end;
  418.  end;
  419.  
  420. foundstart:
  421. seek(summary_file,filepos(summary_file)-1);
  422.  
  423. done:
  424. end;
  425.  
  426.  
  427. procedure summarize;
  428. label skip,done;
  429.  
  430. begin
  431. summinit;
  432. if fflag=false then goto done;
  433. if line<>'' then goto done;
  434. while not eof(summary_file) do
  435.  begin
  436.   read(summary_file,summary_rec);
  437.   with summary_rec do
  438.    begin
  439.    if mpassword<>'' then
  440.     dd:=copy(mpassword,1,1);
  441.     if msgnum<>0 then
  442.      begin
  443.       str(msgnum,temp);z:=length(temp);
  444.       line:=temp;
  445.       if z<4 then
  446.        begin
  447.        for i:=z+1 to 4 do
  448.         begin
  449.          line:=' '+line;
  450.         end;
  451.        end;
  452.       line:=line+': ';
  453.       str(no_of_lines,temp);
  454.       pad(temp,3);
  455.       line:=line+temp+mdate+' ';
  456.       temp:=person_from;
  457.       z:=pos('SYSOP',temp);
  458.       if z=0 then
  459.        begin
  460.         z:=pos(' ',temp);
  461.         temp:=copy(temp,z+1,length(temp)-z);
  462.        end;
  463.       pad(temp,10);
  464.       line:=line+temp+' => ';
  465.       temp:=person_to;
  466.       z:=pos(' ',temp);
  467.       temp:=copy(temp,z+1,length(temp)-z);
  468.       pad(temp,10);
  469.       line:=line+temp;
  470.       temp:=subject;
  471.       if dd='*' then temp:='(Private)';
  472.       line:=line+temp;
  473.       printstring;
  474.       dd:=' ';
  475.      end;
  476.    end;
  477.   skip:
  478.  end;
  479. done:
  480. writeln;
  481. if fflag=true then close(summary_file);
  482. fflag:=false;
  483. writeln;
  484. end;
  485.  
  486.  
  487. procedure qwik_summary;
  488. label skip,done;
  489.  
  490. begin
  491. summinit;
  492. if fflag=false then goto done;
  493. if line<>'' then goto done;
  494. temp2:=stupcase(firstname)+' '+stupcase(lastname);
  495.  
  496. while not eof(summary_file) do
  497.  begin
  498.   read(summary_file,summary_rec);
  499.   with summary_rec do
  500.    begin
  501.     if mpassword<>'' then
  502.      dd:=copy(mpassword,1,1);
  503.     if msgnum<>0 then
  504.      begin
  505.       str(msgnum,temp);
  506.       line:=temp+'  ';
  507.       temp:=subject;
  508.       if dd='*' then temp:='(Private)';
  509.       line:=line+temp;
  510.       printstring;
  511.       dd:=' ';
  512.       skip:
  513.      end;
  514.    end;
  515.  end;
  516. done:
  517. writeln;
  518. if fflag=true then close(summary_file);
  519. fflag:=false;
  520. writeln;
  521. end;
  522.  
  523.  
  524. procedure killmsg;
  525. label query,kill1,kill2,kill3,done;
  526.  
  527. begin
  528. query: writeln;
  529.  msgprompt('Kill');
  530.  getstring;
  531.  makenum;
  532.  knum:=x;
  533.  writeln;
  534.  if bstring='' then goto done;
  535.  if (knum<mfirst) or (knum>mlast) then
  536.   begin
  537.    line:='++ No such msg ++';
  538.    printstring;
  539.    goto query;
  540.   end;
  541.  line1:='Scanning message base...';n:=1;
  542.  printstring;
  543.  assign(summary_file,drive3+'SUMMARY'+ext);
  544.  reset(summary_file);
  545.  while not eof(summary_file) do
  546.   begin
  547.    read(summary_file,summary_rec);
  548.    with summary_rec do
  549.     begin
  550.      if knum=msgnum then
  551.       begin
  552.        if firstname='SYSOP' then goto kill1;
  553.        temp:=stupcase(firstname+' '+lastname);
  554.        line:=stupcase(person_from);
  555.        if line=temp then goto kill1;
  556.        line:=stupcase(person_to);
  557.        if line=temp then goto kill1;
  558.        writeln;
  559.        line:='++ That message doesn''t belong to you ++';
  560.        printstring;
  561.        goto done;
  562.       end;
  563.     end;
  564.   end;
  565.  line:='++ Message not found ++';
  566.  printstring;
  567.  goto query;
  568.  
  569. kill1:
  570. writeln;
  571. line1:='Updating system files...';n:=1;
  572. printstring;
  573. with summary_rec do
  574.   begin
  575.    seek(summary_file,filepos(summary_file)-1);
  576.    msgnum:=0;
  577.    write(summary_file,summary_rec);
  578.   end;
  579. close(summary_file);
  580.  
  581. kill2:
  582. assign(message_file,drive3+'MESSAGES'+ext);
  583. reset(message_file);
  584. while not eof(message_file) do
  585.  begin
  586.   read(message_file,message_rec);
  587.   with message_rec do
  588.    begin
  589.     bstring:=msgtext;
  590.     makenum;
  591.     if knum=x then
  592.      begin
  593.       seek(message_file,filepos(message_file)-1);
  594.       msgtext:='0:'+msgtext+' '+firstname+' '+lastname;
  595.       write(message_file,message_rec);
  596.       goto kill3;
  597.      end;
  598.    end;
  599.  end;
  600.  
  601. kill3:
  602. close(message_file);
  603. assign(stat_file,drive2+'COUNTERS'+ext);
  604. reset(stat_file);
  605. read(stat_file,stat_rec);
  606. seek(stat_file,filepos(stat_file)-1);
  607. with stat_rec do
  608.  begin
  609.   message_pointer:=message_pointer-1;
  610.   msgs:=message_pointer;
  611.   calls:=calls;
  612.   mstart:=mstart;
  613.   mnum:=mnum;
  614.   write(stat_file,stat_rec);
  615.  end;
  616. close(stat_file);
  617. writeln;
  618. line:='Message killed.';
  619. printstring;
  620. goto query;
  621.  
  622. done:
  623. end;
  624.  
  625. procedure get_mcommand;
  626. label start;
  627.  
  628. begin
  629.  start:
  630.   ff:=0;
  631.   line1:='[M]Function:';
  632.   if not xpr then
  633.     line1:=line1+'E,R,S,Q,K,C,G,A (? for HELP)';
  634.   line1:=line1+'?';
  635.   n:=1;
  636.   printstring;
  637.   n:=0;
  638.   c:=1;
  639.   getstring;
  640.   c:=0;
  641.   if bstring<>'' then
  642.    begin
  643.     ff:=pos(bstring,'ERSQK?ACG');
  644.     if ff=0 then
  645.       begin
  646.         line:='I don'+''''+'t understand '+''''+bstring+''''+', '+firstname+'.';
  647.         printstring;
  648.         writeln;
  649.         save:='';
  650.         goto start;
  651.       end;
  652.    end;
  653. end;
  654.  
  655. procedure do_mcommand;
  656. begin
  657.  
  658. case ff of
  659.  
  660.  1: begin
  661.      entrmsg;
  662.     end;
  663.  
  664.  2: begin
  665.      readmsg;
  666.     end;
  667.  
  668.  3: begin
  669.      if mlast<>0 then summarize;
  670.     end;
  671.  
  672.  4: begin
  673.      if mlast<>0 then qwik_summary;
  674.     end;
  675.  
  676.  5: begin
  677.      killmsg;
  678.     end;
  679.  
  680.  6: begin
  681.      writeln;
  682.      line:='            [Message system menu]';
  683.      printstring;
  684.      line:='E: Enter message         R: Retrieve message';
  685.      printstring;
  686.      line:='S: Scan messsages        Q: Qwik-scan messages';
  687.      printstring;
  688.      line:='K: Kill message          C: Exit to CP/M';
  689.      printstring;
  690.      line:='G: Goodbye (logoff)      A: Abort to main system';
  691.      printstring;
  692.      writeln;
  693.     end;
  694.  
  695.  7: begin
  696.      eflag:=0;
  697.     end;
  698.  
  699.  8: begin
  700.      exit_to_cpm;
  701.     end;
  702.  
  703.  9: begin
  704.      goodbye;
  705.     end;
  706.  
  707. end;
  708. end;
  709. begin
  710.      eflag:=0;
  711.     end;
  712.  
  713.  8: begin
  714.      exit_to_cpm;
  715.     end;
  716.  
  717.  9: begin
  718.      goodbye;
  719.