home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / dialout < prev    next >
Text File  |  2020-01-01  |  8KB  |  202 lines

  1. #!/usr/local/bin/kermit +
  2. #
  3. # d i a l o u t  --  Menu-driven dialing out with C-Kermit.
  4. #
  5. # Forces user to fill in the necessary blanks before it will dial.
  6. #
  7. # Hint: Set up and run the "getline" script first and all the blanks 
  8. # will be filled in except the phone number.  For example, make a new
  9. # script that contains something like:
  10. #
  11. #   getline /dev/cua,usr,57600:/dev/cub,hayes,2400:/dev/ttyS0,unknown,38400
  12. #   dialout {\%1}
  13. #
  14. # The phone number can be supplied as a command-line argument (in quotes
  15. # if it contains spaces or parens, etc, because of the shell).
  16. #
  17. # Ideas for further development:
  18. #  . Choices for local country and area code.
  19. #  . Choices for dialing directory.
  20. #  . Choices for redial limit and interval.
  21. #  . Choices for terminal type and many other settings.
  22. #
  23. # Requires C-Kermit 7.0 Beta.07 or later.
  24. #
  25. # Author: F. da Cruz, Columbia University, May 1999.
  26.  
  27. local modem device speed phone watch      ; Local variables
  28. local \%p \%m \%c \%x lastmsg
  29.  
  30. set eval new                              ; Use new form of EVALUATE command.
  31. set case off                              ; Case doesn't matter in commands
  32. set quiet on                              ; Suppress most error messages
  33. set take error off                        ; Ditto
  34. set macro error off                       ; Ditto
  35. set exit warning off                      ; Ditto
  36.  
  37. define MSG {                              ; Print message at given location.
  38.     if > \v(argc) 2 screen move \%2 \%3   ; Move to given row/col (if any)
  39.     screen cleol                          ; Clear to end of line
  40.     if def \%1 xecho {\fcontents(\%1)}    ; Print message (if any)
  41. }
  42.  
  43. define ERRMSG {                           ; Print error message on message line
  44.     asg lastmsg {  \fcontents(\%1)}       ; Save the message for repainting
  45.     msg {\m(lastmsg)} \%m
  46. }
  47.  
  48. define PAINT {                            ; Paint the menu
  49.     screen clear                          ;      Row:
  50.     echo                                         ;  1
  51.     echo {  \v(xprogram) Dialout Setup}          ;  2
  52.     echo                                         ;  3
  53.     echo {   1. Modem type         [\m(modem)]}  ;  4
  54.     echo {   2. Device             [\m(device)]} ;  5
  55.     echo {   3. Speed              [\m(speed)]}  ;  6
  56.     echo {   4. Phone number       [\m(phone)]}  ;  7
  57.     echo {   5. Watch modem dialog [\m(watch)]}  ;  8
  58.     echo                                         ;  9
  59.     echo {   6. Go}                              ; 10
  60.     echo {   7. Restart/Clear}                   ; 11
  61.     echo {   8. Help}                            ; 12
  62.     echo {   9. Quit/Exit}                       ; 13
  63.     echo                                         ; 14
  64.     def \%p 15                                   ; Prompt line
  65.     def \%m 16                                   ; Message line
  66.     msg {\m(lastmsg)} \%m
  67. }
  68.  
  69. :BEGIN
  70. if ( not local && equal "\v(modem)" "none" ) { ; If remote or no modem type...
  71.     set modem type unknown                     ; Default modem type is UNKNOWN
  72. }
  73. assign modem \v(modem)                    ; Set local modem variable too.
  74. define watch No                           ; Default watch modem dialog is No.
  75. undef device                              ; Initialize device to none.
  76. undef speed                               ; Ditto for speed.
  77. undef phone                               ; And phone number.
  78. if ( local ) {                            ; But if we have a device assigned
  79.     assign device \v(line)                ; make it the default.
  80.     assign speed \v(speed)                ; And pick up its speed.
  81. }
  82. if def \%1 asg phone \%1                  ; Get phone number from command line.
  83.  
  84. :REFRESH                                  ; Back here to refresh screen.
  85. paint                                     ; Display the menu.
  86. set flag off                              ; FLAG ON means to exit the loop.
  87.  
  88. while ( not flag ) {                      ; Loop to read and execute choices.
  89.     msg {} \%p                            ; Move to prompt row and clear it.
  90.     getc \%c {  Choice: }                 ; Prompt and get one character.
  91.     eval \%x \fcode(\%c)&127              ; Get its 7-bit code.
  92.     if ( < \%x 32 || = \%x 127 ) {        ; Handle control characters.
  93.         xecho ^\fchar(\%x#64)             ; Echo as ^X.
  94.     switch \%x {                      ; What is it really?
  95.       :12, goto refresh               ; ^L = Refresh screen.
  96.       :3,:4                           ; ^C and ^D...
  97.             msg {} \%m, exit 0 {  Bye}    ; are the same as Quit.
  98.       :default, continue              ; Ignore all others.
  99.         }
  100.     }
  101.     xecho \%c                             ; Not a control character - echo it.
  102.     switch \%c {                          ; Execute the choice.
  103.       :m, :1                              ; MODEM...
  104.           msg {} \%m                      ; Move to message line.
  105.           ask modem {  Modem: }           ; Prompt for modem type.
  106.           if def \m(modem) {              ; If they gave one...
  107.                set modem type \m(modem)   ; Try to set it.
  108.                if fail { 
  109.                    errmsg {Invalid modem type: "\m(modem)"}
  110.                } else {
  111.                    undef lastmsg
  112.                }
  113.                asg modem \v(modem)
  114.           }
  115.           paint                           ; Repaint to show new modem type
  116.           break
  117.       :d, :2                              ; DEVICE...
  118.           msg {} \%m                      ; Move to message line
  119.           ask device {  Device: }         ; Prompt for device.
  120.           if def \m(device) {             ; Etc, as above.
  121.                set line \m(device)
  122.                if fail {
  123.                    errmsg {\m(device): \v(setlinemsg)}
  124.                } else {
  125.                       if not def speed asg speed \v(speed)
  126.                    undef lastmsg
  127.                }
  128.                asg device \v(line)
  129.           }
  130.           paint
  131.           break
  132.       :s, :3                              ; SPEED...
  133.           if not local {                  ; No SET SPEED before SET LINE.
  134.               errmsg {You must choose a device before setting the speed}
  135.               continue
  136.           }
  137.           msg {} \%m                      ; Move to message line
  138.           ask speed {  Speed: }           ; Prompt for speed
  139.           if def \m(speed) {
  140.               set speed \m(speed)
  141.               if fail {
  142.                   errmsg {Can't set speed: "\m(speed)"}
  143.                   undef speed
  144.               } else {
  145.                   asg speed \v(speed)
  146.                   undef lastmsg
  147.               }
  148.           }
  149.           paint
  150.           break
  151.       :n, :p, :4                          ; PHONE NUMBER...
  152.           msg {} \%m
  153.           ask phone {  Number: }
  154.           paint
  155.           break
  156.       :w, :5                              ; WATCH...
  157.           msg {} \%m
  158.           getok {  Watch? },
  159.           if success def watch Yes
  160.           else define watch No
  161.           undef lastmsg
  162.           paint
  163.           break
  164.       :g, :6                              ; GO...
  165.           if not def modem  { errmsg {Modem not selected},     continue }
  166.           if not def device { errmsg {Device not selected},    continue }
  167.           if not def phone  { errmsg {Phone number not given}, continue }
  168.           set flag on, break
  169.       :c, :r, :7                          ; CLEAR or RESET...
  170.           close
  171.           set modem type unknown
  172.           undef phone
  173.           undef lastmsg
  174.           undef \%1
  175.           goto begin
  176.       :h, :8                              ; HELP...
  177.           msg {Press the digit or the first letter of the menu choice.} \%m
  178.           break          
  179.       :q, :e, :9                          ; QUIT...
  180.           msg {} \%m, exit 0 {  Bye}
  181.       :default
  182.           errmsg {Not a valid choice: "\%c"}
  183.     }
  184. }
  185. msg {} \%m
  186.  
  187. echo
  188. set dial display off                      ; Watch modem display...
  189. if eq "\m(watch)" "yes" set dial displ on ; Translate yes/no to on/off.
  190.  
  191. set quiet off                             ; Allow Kermit messages again.
  192. set dial connect on                       ; CONNECT automatically.
  193. set exit on-disconnect on                 ; Exit automatically on hangup.
  194. dial \m(phone)                            ; Dial the number.
  195. if fail exit 1 Call failed.               ; Give up if no answer.
  196.  
  197. ; Here we exit automatically if the connection drops.  If the user
  198. ; escapes back, she gets the prompt so files can be transferred, etc.,
  199. ; and has the opportunity to re-CONNECT.
  200. ;
  201. ; End.
  202.