home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ktfc / ktfc0d5.zip / PROLOG0.5 < prev    next >
Text File  |  2000-05-24  |  15KB  |  465 lines

  1. ; File prolog0.5, copyright (C) Peter Lyall Easthope, 2000.
  2. ; All rights reserved.
  3.  
  4. cls                               ; Clear screen.
  5. echo {KTFC: Kermit To FirstClass(tm).   Copyright (C) Peter Lyall Easthope, 2000.}
  6. echo {All rights reserved.  Version 0.5 released 2000 05 24.  Documentation is in}
  7. echo {file ktfc0d5.txt.}
  8.  
  9. ; ============ Begin user configuration section ============
  10. set modem HAYES        ; Change this to your modem type, see modems\read.me.
  11.                        ; Speed is set in the modem script *.scr. 
  12. set port com2          ; Change if desired.  If COM3 or 4, read KERMIT.BWR.
  13.  
  14. def _dialnum {}   ; Phone number of your FC server.
  15. ;def _dialnum {T5392157}   ; GulfNet.  T means tone rather than pulse dialing.
  16. ;def _dialnum {T12505392157}   ; Long distance.
  17.  
  18. ; User is Asked for Userid if AU is 1.  If AU is 0 the user is not asked and
  19. ; Userid retains the value defined below.
  20. def AU 1 
  21.  
  22. ; User is Asked for Password if AP is 1.  If AP is 0 the user is not asked 
  23. ; and Password retains the value defined below.
  24. def AP 1
  25.  
  26. def Userid   {guest}   ; Your Userid is needed here only if AU is 0
  27. ; CAUTION: if your password is here anyone with access to your computer
  28. ; can read it.
  29. def Password {please}   ; Your Password is needed here only if AP is 0
  30.  
  31. ; The names of the files for incoming and outgoing messages are user
  32. ; definable.  Factory defaults are mailin and mailout.
  33. asg InFile mailin                
  34. ;asg InFile \v(ndate).in       ; Name according to date
  35. asg OutFile mailout
  36. ;asg OutFile \v(ndate).out     ; Name according to date
  37. def MSep {**EndOfMsg**}               ; Message separator
  38.  
  39. ; Each message in OutFile is confirmed before sending if CS is 1. 
  40. ; Otherwise each message in OutFile is sent without confirmation.
  41. def CS 1 
  42.  
  43. ; User is prompted for Confirmation before Deleting a Message from 
  44. ; the server if CDM is 1.  If CDM is 0 the message is deleted without 
  45. ; confirmation.
  46. def CDM 1 
  47.  
  48. ; Each message can be Deleted from server After it is Received if DAR  
  49. ; is 1.  If DAR is 0, messages are not deleted immediately after receipt.
  50. def DAR 0 
  51.  
  52. ; The file containing outgoing messages is deleted after the messages 
  53. ; have been sent if DOFAS is 1.  If DOFAS is 0 the file is left in place.
  54. def DOFAS 0 
  55.  
  56. ; Specify the signature lines.
  57. ; These lines are applied to the end of each message by 
  58. ; the procedure Sig invoked in the procedure ProceedMsg.
  59. def SigLen 3                      ; Number of lines in signature
  60. declare \&s[\m(SigLen)]           ; Declare the signature array
  61. def \&s[1] { }
  62. def \&s[2] {Sent with Kermit and KTFC}
  63. def \&s[3] {Recommended reading:  http://www.cc.columbia.edu/kermit/}
  64.  
  65. def WaitTime 60                   ; seconds to wait for input.
  66. ; With modem speeds below 14,400 b/s the delays during login can be long!
  67.  
  68. set input case observe
  69. set input timeout quit
  70. set translation input off
  71. ;if exist \v(ndate).log del \v(ndate).log  ; Delete old session log
  72. ;log session \v(ndate).log       ; start session log
  73. ; ============ End user configuration section ============
  74.  
  75. ; Global variable InLine stores a line received by input.
  76. ; Global variable OutLine stores a line pending output.
  77.  
  78. xif equal \v(system) {MS-DOS} {
  79.   xif < \v(version) 316 {
  80.     echo {MS-DOS Kermit 3.1.6 or later is required.  Get it from}
  81.     echo {http://www.columbia.edu/kermit/mskermit.html}
  82.     exit
  83.   }
  84. }
  85.  
  86. xif equal \m(_dialnum) {} {
  87.   echo {There is no server phone number.}
  88.   echo {Read ktfcmdn.txt and set your server phone number in}
  89.   echo {the User Configuration section of the prolog file.}
  90.   exit
  91. }
  92.  
  93. asg SepLength \flength(\m(MSep)) ; Record length for convenience
  94.  
  95. ; errext macro, for use in scripts that want to hang up a dialed
  96. ; or network connection if there is any error.
  97. ; \3 is the character from <ctrl>C; it signals "cancel" to the FC Server.
  98. ; Thus "errext {Blah} \3" writes "Blah" to the screen, aborts any 
  99. ; command on the FC server and terminates execution of Kermit.
  100. def errext {
  101.   echo {Error: \%1}
  102.   if > \v(argc) 1 output {\%2}
  103.   hangup
  104.   pause 2
  105.   exit
  106. }
  107.  
  108. ; chkmdm and dial are from MSKERMIT.INI.
  109. ;
  110. ; Check that we have a dialing script available for given modem type.
  111. ; This allows _MODEM definition to be changed in MSCUSTOM.INI and even
  112. ; on the fly after initialization.
  113. def chkmdm {
  114.   asg _mdmscr
  115.   if not eq "\$(MDMSCR)" "" asg _mdmscr \$(MDMSCR)
  116.   if exist \m(_mdmscr) end 0
  117.   xif exist \v(inidir)MODEMS\\\m(_modem).SCR {
  118.     asg _mdmscr \v(inidir)MODEMS\\\m(_modem).SCR
  119.   }
  120.   xif not def _mdmscr {
  121.     xif inpath \m(_modem).SCR {
  122.       asg _mdmscr \v(inpath)\m(_modem).SCR
  123.     }
  124.   }
  125.   if not def _mdmscr end 1
  126.   if not exist \m(_mdmscr) end 1
  127.   end 0
  128. }
  129.  
  130. def dial {
  131.   local car par stat
  132.   do chkmdm
  133.   if fail errext {Dialing script not found.}
  134.   asg \%1 \m(_dialnum)
  135.   asg car \v(carrier)
  136.   asg par \v(parity)
  137.   set carrier off
  138.   set parity none
  139.   take \m(_mdmscr)
  140.   asg stat \v(status)
  141.   set parity \m(par)
  142.   set carrier \m(car)
  143.   if not = 0 \m(stat) end 1
  144.   if < \v(cmdlevel) 3 echo -
  145. {Call complete.  Use the CONNECT command to go online.}
  146.   end 0
  147. }
  148.  
  149. def IInput {
  150.   clear input
  151.   input \m(WaitTime) \%1 
  152.   if failure errext \%2 \%3 
  153. }
  154.  
  155. def GetPrompt { IInput {> } {"> " not received in GetPrompt} \3 }
  156.  
  157. def IInputLine { IInput {\10} {"\\10" not received in IInputLine} \3 }
  158.  
  159. def minputLine { 
  160.   clear input
  161.   minput \m(WaitTime) {\10} {[More]} {Failure of minput in minputLine}
  162.   switch \v(minput) {
  163.     :0, errext {Unrecognized chars from host in minputLine}
  164.     :1, break
  165.     :2, output {\13}, GetPrompt, IInputLine, break
  166.     :default, errext {Undefined switch in minputLine}
  167.   }
  168. }
  169.  
  170. ; Beginning of procedures used to log in.
  171.  
  172. xif = \m(AU) 0 {
  173.   def GetUserid { echo {} }
  174. } else {
  175.   def GetUserid { ask Userid {what is your userid?\32} }
  176. }
  177.  
  178. xif = \m(AP) 0 {
  179.   def GetPassword { echo {} }
  180. } else {
  181.   def GetPassword { askq Password {what is your password?\32} }
  182. }
  183.  
  184. def MBprompt {Type an item's name or number to open it}    
  185. asg MBPLength \flength(\m(MBprompt))
  186. def MBEmpty {Home:MailBox: No items.}
  187. asg MBELength \flength(\m(MBEmpty))
  188. def CmdSummary {Commands: Help,Logout,Exit,Read,New,Home,Delete,}
  189. asg CmdSummary {\m(CmdSummary)Scan,Send,Reply,Forward.}
  190. asg CSLength \flength(\m(CmdSummary))
  191.  
  192. def GoodPW {
  193.   output {\13}
  194. ;  echo {Password accepted and 1st [More] prompt acknowledged}
  195.   return 0
  196. }
  197.  
  198. def BadPW {
  199.   xif = \m(AU) 1 { 
  200.     echo {Check Userid you are giving.}
  201.     GetUserID 
  202.   } else {
  203.     echo {Check Userid coded in configuration section of prolog.} 
  204.   }
  205.   xif = \m(AP) 1 { 
  206.     echo {Check Password you are giving.} 
  207.     GetPassword
  208.   } else {
  209.     echo {Check Password coded in configuration section of prolog.} 
  210.   }
  211.   if = \m(AU) 0 errext {}
  212.   if = \m(AP) 0 errext {}
  213.   return 1
  214. }
  215.   
  216. ; Delays up to 12 s for the arrival of "Press RETURN twice to connect"
  217. ; have been observed.  Allow plenty of time.
  218. def Login {
  219.   GetUserid
  220.   GetPassword
  221.   dial \m(Server)
  222.   set input echo off
  223.   IInput {Press RETURN twice to connect} {No prompt for <RETURN> from host}
  224.   if fail errext {No EOL request from the host}
  225.   output {\13\13}
  226.   IInput {UserID: } {No UserID prompt from the host}
  227.   while = 1 1 { 
  228.     output {\m(Userid)\13}
  229.     IInput {Password: } {No Password prompt from the host}
  230.     output {\m(Password)\13}
  231.     clear input
  232.     minput \m(WaitTime) {[More]} {UserID: }
  233.     switch \v(minput) {
  234.       :0, errext {No prompt from host after password}
  235.       :1, GoodPW, break
  236.       :2, BadPW, break
  237.       :default, errext {Undefined switch value after password}
  238.     }
  239.     xif = \v(return) 0 {break} else { 
  240.       echo {Trying user verification again.} 
  241.     }
  242.   }
  243.   IInput {[More]} {2nd [More] prompt not received from host}
  244. ;  echo {2nd [More] prompt received.} 
  245.   output {\13}
  246.   IInput {Scan.} {command prompt not received from host}
  247.   GetPrompt
  248. ;  pause                           ; Something needs time here.
  249.   echo {Login completed.}
  250.   echo {}
  251. }
  252.  
  253. ; End of procedures used to log in.
  254.  
  255. ; SaveLine copies \v(input) to a macro variable.  The DOS version 
  256. ; also eliminates the spurious "," added to the end of an incoming 
  257. ; line and inserts a period to prevent deletion of empty lines.  See 
  258. ; "System Specific Notes > MS-DOS" in ktfcmdn.txt.
  259. xif equal \v(system) {MS-DOS} {
  260.   def SaveLine {
  261.     local InLen Location
  262.     asg InLine {\v(input)}  
  263.     asg InLen \feval(\flength(\m(InLine)) )
  264.     xif > \m(InLen) 2 {
  265.       asg Location \feval(\m(InLen) - 2 )
  266.       asg InLine {\fsubstr(\m(InLine), 1, \m(Location) )}
  267.     } else { 
  268.       asg InLine {.}
  269.     }
  270.   }
  271. } else {
  272.   def SaveLine {
  273.     asg InLine {\v(input)}
  274.   }
  275. }
  276.  
  277. ; InputMB1 handles any incoming line which ends with \10.
  278. ; There are two cases: the mailbox prompt line and a content line.
  279. ; There is one argument.  If it is 1 the line is written to the open file.
  280. ; If the argument is 0 the line is discarded.
  281. def InputMB1 {
  282.   xif equal {\fsubstr(\m(InLine),1,40)} {\fsubstr(\m(MBprompt),1,40)} {
  283.     def ExitMB 1
  284.     InputMB11 } else {
  285.     ; This line in the directory describes a message
  286.     if equal {\%1} {1} writeln file {\m(InLine)}
  287.   }
  288. }
  289.  
  290. ; InputMB11 is invoked after receiving the directory instructional prompt.
  291. def InputMB11 {
  292.   clear input
  293.   minput \m(WaitTime) {\10} {[More]} 
  294.   switch \v(minput) {
  295.     :0, errext {Unrecognized characters from host in InputMB11}
  296.     :1, InputMB111, break
  297.     :2, output {\13}, InputMB111, break
  298.     :default, errext {Undefined switch in InputMB11}
  299.   }
  300. }
  301.  
  302. ; InputMB111 is invoked after receiving the FC command prompt.
  303. def InputMB111 {
  304. ;  echo {Beginning InputMB111}
  305. ;  echo {}
  306.   clear input
  307.   minput \m(WaitTime) {> } {[More]} 
  308.   switch \v(minput) {
  309.     :0, errext {Unrecognized characters from host in InputMB111}
  310.     :1, break
  311.     :2, output {\13}, GetPrompt, break
  312.     :default, errext {Undefined switch in InputMB111}
  313.   }
  314. }
  315.  
  316. ; InputMB2 handles the [More] prompt.
  317. def InputMB2 { output \13, IInput {J} {J not received in InputMB2} }
  318.  
  319. ; If possible, get a message number from the Mailbox line.
  320. def GetMsgNum {
  321.   local begin end
  322. ;  echo {Beginning GetMsgNum.}
  323.   asg begin \feval(1)
  324.   asg end \feval(4)
  325.   while = 0 0 {
  326.     if > \m(begin) \m(end) break
  327.     if numeric {\fsubstr(\m(Title),\m(begin),1)} break
  328. ;    echo {Incrementing begin.}
  329.     asg begin \feval(\m(begin)+1) 
  330.   }
  331.   while = 0 0 {
  332.     if > \m(begin) \m(end) break
  333.     if numeric {\fsubstr(\m(Title),\m(end),1)} break
  334. ;    echo {Decrementing end.}
  335.     asg end \feval(\m(end)-1)
  336.   }
  337.   xif > \m(begin) \m(end) {
  338.     asg MsgNum {0} 
  339.     echo {No valid message number in this Mailbox line.}
  340.   } else {
  341.     asg length \feval(1+\m(end)-\m(begin))
  342.     asg MsgNum {\fsubstr(\m(Title),\m(begin),\m(length))} 
  343.     ; echo {Message number is \m(MsgNum).}
  344.   }
  345.   xif equal {\fsubstr(\m(Title),\m(begin),1)} {0} {asg MsgNum {0} }
  346. ; If a valid message number was not found, MsgNum is 0.
  347. ; Otherwise MsgNum contains the message number.
  348. }
  349.  
  350. ; InputMsg1 handles any incoming line which ends with \10.
  351. ; There are two cases: the command summary line and a line of message.
  352. def InputMsg1 {
  353.   xif equal {\fsubstr(\m(InLine),1,\m(CSLength))} {\m(CmdSummary)} {
  354.     def ExitMsg 1, InputMsg11 } else { 
  355. ;    SkipLines
  356.     writeln file {\m(InLine)} 
  357.   }
  358. }
  359.  
  360. ; InputMsg11 follows the FC command summary.
  361. def InputMsg11 {
  362.   clear input
  363.   minput \m(WaitTime) {> } {[More]} 
  364.   switch \v(minput) {
  365.     :0, errext {Unrecognized characters from host in InputMsg11}
  366.     :1, return, break
  367.     :2, output \13, GetPrompt, return, break
  368.     :default, errext {Undefined switch in InputMsg11}
  369.   }
  370. }
  371.  
  372. ; ClearMore handles the [More] prompt.
  373. def ClearMore { 
  374.   output \13
  375.   IInput {J} {J not received in ClearMore}
  376. }
  377.  
  378. def ContinueRecvMsg {
  379.   local ExitMsg
  380.   def ExitMsg 0
  381.   while equal \m(ExitMsg) 0 { 
  382.     clear input
  383.     ; The following cases correspond to line received, screen is full
  384.     ; and prompt for attachment.
  385.     minput \m(WaitTime) {\10} {[More]} {\27[2D} 
  386.     switch \v(minput) {
  387.       :0, errext {Unrecognized characters from host when receiving message}
  388.       :1, SaveLine, InputMsg1, break
  389.       :2, ClearMore, break
  390.       :3, output \13, GetPrompt, def ExitMsg 1, break
  391.       :default, errext {Undefined switch in Message reading loop}
  392.     }
  393.   }
  394. }
  395.  
  396. def ProceedRecvMsg {
  397.   SaveLine 
  398.   xif equal {\fsubstr(\m(InLine), 1, 1 )} {M} {
  399.     echo {Valid message number.  \m(InFile) file opened.}
  400.     writeln file {\m(InLine)} 
  401.     ContinueRecvMsg
  402.   } else {
  403.     echo {Invalid message number; server is asking again for message number.}
  404.     echo {Cancel this message number and continue to next line in directory.}
  405.     output \3
  406.     GetPrompt
  407.   }
  408. }
  409.  
  410. ; Receive a message
  411. def RecvMsg {
  412.   open append \m(InFile)
  413.   if failure errext {can't open file for incoming mail}
  414.   output {\m(MsgNum)\13}
  415.   IInput {\10} {echo of message request not received} 
  416.   ; Now accept the first line from the server in response to the 
  417.   ; message number just submitted.
  418.   clear input
  419.   ; The following cases correspond to line received, screen is full.
  420.   minput \m(WaitTime) {\10} {[More]} 
  421.   switch \v(minput) {
  422.     :0, errext {Unrecognized characters from host when receiving message}
  423.     :1, ProceedRecvMsg, break
  424.     :2, ClearMore, IInputLine, ProceedRecvMsg, break
  425.     :default, errext {Undefined switch in Message reading loop}
  426.   }
  427. ;  echo {Finished processing this message number.}
  428.   writeln file {\m(MSep) ***************}
  429.   close write-file
  430.   echo {Message received.  \m(InFile) file closed.}
  431.   xif = \m(DAR) 1 {
  432.     DelMsg {The following message has been copied to this machine.}
  433.   }
  434. }
  435.  
  436. xif = \m(CDM) 0 {
  437.   ; Define DelMsg without confirmation.
  438.   def DelMsg { 
  439.     output {d \m(MsgNum) y\13} 
  440.     GetPrompt 
  441.   }
  442. } else {
  443.   ; Define delMessg with confirmation
  444.   def DelMsg {
  445.     ; The argument of delMessg is a string used to prompt the user.
  446.     while = 1 1 { 
  447.       echo {\%1}
  448.       echo {\m(Title)} 
  449.       getc \%u {Delete this message from the server? (y/n): }
  450.       xif equal \%u {y} {
  451.         echo {y}
  452.         output {d \m(MsgNum) y\13} 
  453.         GetPrompt 
  454.         break
  455.       }
  456.       xif equal \%u {n} {
  457.         echo {n}
  458.         break
  459.       } else {
  460.         echo {Please respond by keying <y> or <n>.}
  461.       }
  462.     }
  463.   }
  464. }
  465.