home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 189.img / TCS120S.ZIP / MAINR2.PAS < prev    next >
Pascal/Delphi Source File  |  1989-04-04  |  5KB  |  218 lines

  1. {$R-,S-,I-,D-,F+,V-,B-,N-,L+ }
  2. {$M 65500,0,0 }
  3.  
  4. unit mainr2;
  5.  
  6. interface
  7.  
  8. uses gentypes,modem,subs1,subs2,statret,configrt,overret1,
  9.      textret,userret,mailret,lineedit,ansiedit,mainr1;
  10.  
  11. function reedit (var m:message; g:boolean):boolean;
  12. function editor (var m:message; gettitle:boolean; tttitle:lstr):integer;
  13. procedure seekbdfile (n:integer);
  14. procedure writebdfile (var bd:boardrec);
  15. procedure writecurboard;
  16. procedure addnews;
  17. procedure sendmailto (uname:mstr; anon:boolean);
  18. procedure addfeedback (var m:mailrec);
  19. procedure hangupmodem;
  20. procedure setupmodem;
  21. procedure dialnumber (num:lstr);
  22. procedure disconnect;
  23.  
  24. implementation
  25.  
  26. function reedit (var m:message; g:boolean):boolean;
  27. begin
  28.   if fseditor in urec.config
  29.     then reedit:=ansireedit (m,g)
  30.     else reedit:=linereedit (m,g);
  31.   trimmessage (m)
  32. end;
  33.  
  34. function editor (var m:message; gettitle:boolean; tttitle:lstr):integer;
  35. var thetitle:lstr;
  36.  
  37.   function getthetitle:boolean;
  38.   begin
  39.     m.anon:=false;
  40.     getthetitle:=true;
  41.     m.title:=tttitle;
  42.     thetitle:=tttitle;
  43.     if gettitle then begin
  44.     if (notitle=false) or (emailing=false) then begin
  45.       buflen:=30;
  46.       writestr (^M^M'Subject: &');
  47.       if (length(input)=0) and (notitle=false) then begin
  48.         getthetitle:=false;
  49.         exit
  50.       end;
  51.       if (notitle=false) then begin
  52.        m.title:=input;
  53.        thetitle:=m.title;
  54.       end;
  55.       if (emailing=false) and (nosendprompt=false) then begin
  56.        writestr ('To [CR/All]: &');
  57.        if length(input)=0 then m.leftto:='All' else
  58.        m.leftto:=input;
  59.       end;
  60.       if ulvl>=anonymouslevel then begin
  61.         buflen:=1;
  62.         writestr ('Anonymous [y/N]? *');
  63.         m.anon:=yes
  64.       end
  65.     end;
  66.    end;
  67.    if (not gettitle) or (emailing) or (notitle) then begin
  68.     m.title:=tttitle;
  69.     m.leftto:='All';
  70.     m.anon:=false;
  71.    end;
  72.   end;
  73.  
  74. begin
  75.   editor:=-1;
  76.   m.numlines:=0;
  77.   if getthetitle then
  78.    if reedit(m,gettitle) then
  79.     editor:=maketext(m)
  80. end;
  81.  
  82. procedure seekbdfile (n:integer);
  83. begin
  84.   seek (bdfile,n);
  85.   seek (bifile,n); che
  86. end;
  87.  
  88. procedure writebdfile (var bd:boardrec);
  89. begin
  90.   write (bdfile,bd);
  91.   write (bifile,bd.shortname)
  92. end;
  93.  
  94. procedure writecurboard;
  95. begin
  96.   seekbdfile (curboardnum);
  97.   writebdfile (curboard); che
  98. end;
  99.  
  100. procedure addnews;
  101. var newline,r:integer;
  102.     nfile:file of integer;
  103.     numnews,cnt:integer;
  104.     m:message;
  105. begin
  106.   writehdr ('Adding to the News');
  107.   titlestr:='Adding to the News';
  108.   sendstr:='No one';
  109.   newline:=editor (m,false,'Adding to the News');
  110.   if newline<0 then exit;
  111.   r:=ioresult;
  112.   assign (nfile,'News');
  113.   reset (nfile);
  114.   r:=ioresult;
  115.   if r<>0
  116.     then
  117.       begin
  118.         if r<>1 then writeln ('Error ',r,' opening news file; recreating.');
  119.         rewrite (nfile);
  120.         write (nfile,newline);
  121.         numnews:=0
  122.       end
  123.     else
  124.       begin
  125.         numnews:=filesize(nfile);
  126.         for cnt:=numnews-1 downto 0 do
  127.           begin
  128.             seek (nfile,cnt);
  129.             read (nfile,r);
  130.             seek (nfile,cnt+1);
  131.             write (nfile,r)
  132.           end;
  133.         che;
  134.         seek (nfile,0);
  135.         write (nfile,newline)
  136.       end;
  137.   writeln ('News added.  News items: ',numnews+1);
  138.   writelog (2,1,'');
  139.   close (nfile)
  140. end;
  141.  
  142. procedure sendmailto (uname:mstr; anon:boolean);
  143. var un:integer;
  144.     me:message;
  145.     line:integer;
  146.     u:userrec;
  147. begin
  148.   if length(uname)=0 then exit;
  149.   un:=lookupuser (uname);
  150.   if un=0 then writeln ('User not found.') else begin
  151.     if anon and (ulvl<sysoplevel) then uname:=anonymousstr;
  152.     seek (ufile,un);
  153.     read (ufile,u);
  154.     if u.emailannounce>-1 then begin
  155.       writehdr (u.handle+'''s Announcement');
  156.       printtext (u.emailannounce)
  157.     end;
  158.     writehdr ('Sending E-Mail to '+uname);
  159.     titlestr:='Sending E-Mail to '+uname;
  160.     emailing:=true;
  161.     line:=editor (me,true,'Sending E-Mail to '+uname);
  162.     emailing:=false;
  163.     if line>=0 then addmail (un,line,me)
  164.   end
  165. end;
  166.  
  167. procedure addfeedback (var m:mailrec);
  168. var ffile:file of mailrec;
  169. begin
  170.   assign (ffile,'Feedback');
  171.   reset (ffile);
  172.   if ioresult<>0 then begin
  173.     close (ffile);
  174.     rewrite (ffile)
  175.   end;
  176.   seek (ffile,filesize(ffile));
  177.   write (ffile,m);
  178.   close (ffile);
  179.   newfeedback:=newfeedback+1;
  180. end;
  181.  
  182. procedure hangupmodem;
  183. var tries:integer;
  184. begin
  185.   tries:=0;
  186.   while carrier and (tries<5) do begin
  187.     hangup;
  188.     sendmodemstr (modemhangupstr,false);
  189.     tries:=tries+1
  190.   end;
  191.   setparam (usecom,baudrate,parity)
  192. end;
  193.  
  194. procedure setupmodem;
  195. begin
  196.   if carrier then exit;
  197.   writeln (usr,^M^J'[Setting up the Modem]'^J);
  198.   sendmodemstr (modemsetupstr,true);
  199.   if hashayes then sendmodemstr ('|~~ATS0=0M0Q0V0X1|',true)
  200. end;
  201.  
  202. procedure dialnumber (num:lstr);
  203. begin
  204.   sendmodemstr (modemdialprefix+num+modemdialsuffix,true)
  205. end;
  206.  
  207. procedure disconnect;
  208. begin
  209.   if online then hangupmodem;
  210.   online:=true;
  211.   writelog (0,3,'');
  212.   if (unum>0) and not disconnected then updateuserstats (true);
  213.   disconnected:=true
  214. end;
  215.  
  216. begin
  217. end.
  218.