home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ktfc / ktfc0d5.zip / SR0.5 < prev   
Text File  |  2000-05-24  |  8KB  |  278 lines

  1. ; File sr0.5, copyright (C) Peter Lyall Easthope, 2000.
  2. ; All rights reserved. 
  3.  
  4. take prolog0.5            ; User configuration and procedures for login.
  5.  
  6. ; Beginning of procedures used to send messages.
  7.  
  8. def ConfirmSend {
  9.   local csf
  10.   if = \m(CS) 0 return 0  
  11.   while = 1 1 {
  12.     echo {Message \m(OutLine)}    ; Echo first address
  13.     getc \%u {Proceed to send message? (y/n): }
  14.     switch \%u {
  15.       :y, echo {y}, asg csf 0, break 
  16.       :n, echo {n}, asg csf 1, break
  17.       :default, echo {Please respond by keying <y> or <n>.}, asg csf 2
  18.     }
  19.     if < \m(csf) 2 break
  20.   }
  21.   return \m(csf)
  22. }
  23.  
  24. def SendSubj {
  25.   output {\13}                    ; Clear "Copies:" loop
  26.   IInput {Subject:} {"Subject:" not received in SendSubj} \3
  27.   output {\fsubstr(\m(OutLine),9)\13}
  28. }
  29.  
  30. ; This procedure is invoked by ProceedMsg and SendCopiesAd.  
  31. ; AddrRes is localized in ProceedMsg. 
  32. def abortAddr {
  33.   asg AddrRes 1
  34.   output \3
  35.   echo {Aborting message}
  36.   SkipOut
  37. }
  38.  
  39. ; This procedure is invoked by ProceedMsg.  AddrRes is localized there. 
  40. def SendCopiesAd {
  41.   while = 1 1 {
  42.     ; Send Copies addresses
  43.     xif equal {\fsubstr(\m(OutLine),1,7)} {Copies:} {
  44.       asg OutLine \fsubstr(\m(OutLine),8) }
  45.     output \m(OutLine)
  46.     if < 0 \findex(@,\m(OutLine),1) output {,i}
  47.     output {\13}
  48.     clear input                   ; Empty the INPUT buffer
  49.     ; The following cases correspond to defective, ambiguous and 
  50.     ; recognizable addresses. 
  51.     minput \m(WaitTime) {s found\13\10Copies:\9\9} {\27[3D} {Copies:\9\9} 
  52.     switch \v(minput) {
  53.       :0, errext {Unrecognized char's when expecting "Copies:"}
  54.       :1, abortAddr, break
  55.       :2, abortAddr, break
  56.       :3, break
  57.       :default, errext {Undefined switch after echo from outgoing address}
  58.     }
  59.     if = \m(AddrRes) 1 break 
  60.     read OutLine                  ; Read line from the OutFile
  61.     xif equal {\fsubstr(\m(OutLine),1,8)} {Subject:} return
  62.   }
  63. }
  64.  
  65. def SendMsgBody {
  66.   local EndMsg
  67.   IInput {[More]} {No [More] prompt when editor starts}
  68.   output \13                         ; Start message body editor
  69.   IInput {J} {No "clear screen", J, when editor starts}
  70.   ; echo Finished editor screen setup.
  71.   ; FC editor fills screen with 24 lines
  72.   asg LineCount \feval(24)
  73.   asg EndMsg 0
  74.   while > \m(LineCount) 0 {
  75.     IInput {H} -
  76.     {Cursor row,col control not received before sending a line} {\3}
  77.     read OutLine
  78.     xif failure {
  79.       asg EndMsg 1
  80.       break
  81.     }
  82.     xif equal {\fsubstr(\m(OutLine),1,\m(SepLength))} {\m(MSep)} {
  83.       asg EndMsg 1
  84.       break
  85.     }
  86.     output {\m(OutLine)\13}
  87.     asg LineCount \feval(\m(LineCount)-1)
  88.   }
  89. ;  echo {Exited 24 line loop.}
  90.   if = \m(EndMsg) 1 return
  91. ;  echo {Starting 25th line.}
  92.   while = 1 1 {
  93.    ; Screen is full; accept K control
  94.    IInput {K} {Screen is full but K control not received.} {\3}
  95.    IInput {H} {Cursor row,col control not received before sending a line} {\3}
  96.    read OutLine
  97.    if failure break
  98.    if equal {\fsubstr(\m(OutLine),1,\m(SepLength))} {\m(MSep)} break
  99.    output {\m(OutLine)\13}
  100.   }
  101. }
  102.  
  103. def Sig {
  104.   for \%f 1 \m(SigLen) 1 {
  105.     output {\&s[\%f]\13}
  106.     asg LineCount \feval(\m(LineCount)-1)
  107.     xif = \m(LineCount) 0 { 
  108.       ; Sreen is full; accept K control
  109.       IInput {K} {K control not received after filling screen} \3        
  110.       asg LineCount \feval(24)
  111.     }
  112.     IInput {H} {Cursor row,col control not received after sig line} {\3}
  113.   }
  114. }
  115.  
  116. def CloseMsg {
  117. ;  set input echo on
  118.   ; Send <esc> to leave message body editor.
  119.   output {\27}
  120.   IInput {J} {clear screen, J, not received in CloseMsg}
  121.   IInput {2D} {cursor control, 2D, not received in CloseMsg}
  122.   output {\13}
  123.   IInput {3D} {cursor control, 3D, not received in CloseMsg}
  124.   output {\13}
  125.   minput \m(WaitTime) {Forward.} {Scan.}      ; accept command summary
  126.   GetPrompt
  127.   echo {Message sent.}
  128. ;  set input echo off
  129. }
  130.  
  131. def ProceedMsg {
  132. ;  echo {Beginning ProceedMsg.}
  133.   output {n\13}                   ; Ask FirstClass to create a message
  134.   echo {Sending message, "\m(OutLine)".}
  135.   IInput {To:} {"To:" not received from host in ProceedMsg} \3
  136.   local AddrRes
  137.   asg AddrRes 0                ; Indicates an acceptable address
  138.   while = 1 1 {
  139.     ; Send address
  140.     xif equal {\fsubstr(\m(OutLine),1,3)} {To:} {
  141.       asg OutLine \fsubstr(\m(OutLine),4) }
  142.     output \m(OutLine)
  143.     if < 0 \findex(@,\m(OutLine),1) output {,i}
  144.     output {\13}
  145.     clear input                   ; Empty the INPUT buffer
  146.     ; The following cases correspond to defective, ambiguous and 
  147.     ; recognizable addresses. 
  148.     minput \m(WaitTime) {s found\13\10To:\9\9} {\27[3D} {To:\9\9} 
  149.     switch \v(minput) {
  150.       :0, errext {Unrecognized characters when expecting "To:"}
  151.       :1, abortAddr, break
  152.       :2, abortAddr, break
  153.       :3, break
  154.       :default, errext {Undefined switch after echo from outgoing address}
  155.     }
  156.     if = \m(AddrRes) 1 break 
  157.     read OutLine                  ; Read line from the OutFile
  158.     xif equal {\fsubstr(\m(OutLine),1,8)} {Subject:} {
  159.       output {\13}                ; Clear "To:" loop
  160.       SendSubj
  161.       break 
  162.     } else {
  163.       xif equal {\fsubstr(\m(OutLine),1,7)} {Copies:} {
  164.         output {\13}              ; Clear "To:" loop
  165.         SendCopiesAd
  166.         if = \m(AddrRes) 0 SendSubj
  167.         break
  168.       }
  169.     }
  170.   }
  171.   if = \m(AddrRes) 1 return 
  172.   SendMsgBody
  173.   xif not equal {n} {\fsubstr(\m(OutLine),\feval(\m(SepLength)+1),1)} {Sig}
  174.   CloseMsg
  175. }
  176.  
  177. def SendMsgs {
  178.   open read \m(OutFile)
  179.   if failure errext {Can't open \m(OutFile)}
  180.   while = 1 1 {
  181.     read OutLine                  ; Read the address from the OutFile
  182.     if failure return             ; No more messages in OutFile
  183.     if equal {\fsubstr(\m(OutLine),1,\m(SepLength))} {\m(MSep)} return
  184.     ConfirmSend
  185.     xif = \v(return) 0 {ProceedMsg} else {SkipOut}
  186. ;    echo {Finished processing outgoing message.}
  187.   }
  188.   close read-file
  189. }
  190.  
  191. ; End of procedures used to send messages.
  192.  
  193. ; Beginning of procedures used to receive messages.
  194.  
  195. ; SkipOut is used to read through an outgoing message but not send it.
  196. def SkipOut {
  197.   local LineBuffer
  198.   while = 1 1 { 
  199.     read LineBuffer 
  200.     if failure break 
  201.     if equal {\fsubstr(\m(LineBuffer),1,\m(SepLength))} {\m(MSep)} break
  202.   }
  203. ;  echo {Leaving SkipOut.}
  204. }
  205.  
  206. def GetMailbox {
  207.   open write MAILBOX
  208.   if failure errext {can't open MAILBOX for writing}
  209.   echo {MAILBOX opened for writing.}
  210.   output {1\13}
  211.   IInput {J} {J not received before reading Mailbox}
  212.   IInputLine
  213.   SaveLine
  214.   writeln file {\m(InLine)}
  215.   xif equal {\fsubstr(\m(InLine),1,23)} {Home:MailBox: No items.} {
  216.     ; Mailbox is empty.
  217.     IInputLine
  218.     IInputLine
  219.     GetPrompt 
  220.   } else {
  221.     ; Mailbox is not empty.
  222.     local ExitMB
  223.     def ExitMB 0
  224.     while equal \m(ExitMB) 0 { 
  225.       clear input
  226.       minput \m(WaitTime) {\10} {[More]}
  227.       switch \v(minput) {
  228.         :0, errext {Unrecognized characters when receiving Mailbox}
  229.         :1, SaveLine, InputMB1 {1}, break
  230.         :2, InputMB2, break
  231.         :default, errext {Undefined switch in Mailbox reading loop}
  232.       }
  233.     }
  234.   }
  235.   close write-file
  236. }
  237.  
  238. ; ProcessMsgs gets the mailbox listing into a file and then reads 
  239. ; unread messages.
  240. def ProcessMsgs {
  241.   GetMailbox
  242.   echo {MAILBOX file written and closed.  Checking each entry ... }
  243.   open read MAILBOX
  244.   if failure errext {can't open MAILBOX for reading}
  245.   read Title
  246.   if failure errext {Nothing in mailbox}
  247.   while = 1 1 { 
  248.     read Title
  249.     if failure break
  250. ;    echo {Checking a line in the mailbox file ...}
  251. ;    echo {\m(Title)}
  252.     xif equal {\fsubstr(\m(Title),1,1)} {*} { 
  253.       GetMsgNum
  254.       if > \m(MsgNum) 0 RecvMsg 
  255.     } 
  256.   }
  257.   close read-file                 ; Close the MAILBOX file
  258. }
  259.  
  260. ; End of procedures used to receive messages or to tidy the mailbox.
  261.  
  262. def Communicate {
  263.   Login
  264.   xif exist \m(OutFile) {
  265.     SendMsgs     ; Send outgoing messages ...
  266.     xif = \m(DOFAS) 1 { delete \m(OutFile) }
  267.   }
  268.   ProcessMsgs        ; Read the incoming messages or tidy the mailbox.
  269.   output {logout y\13}
  270.   hangup
  271.   close session                   ; Close session log
  272.   quit
  273. }
  274.  
  275. ; Finished macro definitions.  
  276.  
  277. Communicate                       ; Make it happen.
  278.