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

  1. #!/usr/local/bin/kermit +
  2. #
  3. # g e t l i n e  --  Get first free dialout line.
  4. #
  5. # Given a string of the form:
  6. #
  7. #  device,modem,speed:device,modem,speed:device,modem,speed...
  8. # ...this script cycles through the devices until it finds a free one
  9. # that it can assign.  Upon failure it exits with a failure code.
  10. # If it succeeds it returns with the associated modem type and speed also
  11. # set: if called as a "kerbang" script, it leaves you at the C-Kermit>
  12. # prompt; if called from another script, returns to the calling script.
  13. #
  14. # The string can be provided as a command-line argument or (if no
  15. # command-line argument is given) the value of the DIALOUTS environment
  16. # variable (DIALOUTS symbol or logical name in VMS).
  17. #
  18. # Illustrates using \fsplit() to break up delimited strings into arrays.
  19. #
  20. # Author: F. da Cruz, Columbia University, April 1999
  21. # Updated Oct 1999 for QNX port locking.
  22. #
  23. local \&a[] \&b[] \%i myname          ; Local variables
  24. local list defmodem defspeed usage    ; More local variables
  25.  
  26. .myname := \fbasename(\%0)            ; Name of this script
  27. .defmodem = usr                       ; Default modem type (*)
  28. .defspeed = 57600                     ; Default speed (*)
  29.  
  30. ; (*) Change as needed
  31.  
  32. define USAGE {
  33.     echo {\m(myname): \%1}
  34.     echo Please supply a device list as (the only) command-line argument or
  35.     echo in the DIALOUTS environment variable.  A device list looks like:
  36.     echo {"device,modem,speed:device,modem,speed:device,modem,speed..."}
  37.     exit 1
  38. }
  39. if > \v(argc) 2 {                     ; Check for bad command line
  40.     usage {Too many arguments.}
  41. }
  42. if def \%1 .list := \%1               ; Get command-line argument 
  43. if not def list .list := \$(DIALOUTS) ; If none get DIALOUTS variable
  44. if not def list {                     ; If none give message and fail
  45.     usage {No device list given.}
  46. }
  47. set quiet on                          ; Suppress error messages
  48. set qnx-port-lock on                  ; Significant in QNX - ignored elsewhere
  49. for \%i 1 \fsplit(\m(list),&a,:) 1 {  ; Loop for each triplet
  50.     dcl \&b[3]                        ; Re-create this array each time
  51.     .\%m := \fsplit(\&a[\%i],&b,{,})  ; Split this triplet
  52.     if not def \&b[1] continue        ; Watch out for empty ones
  53.     echo Trying \&b[1]...
  54.     if not def \&b[2] {               ; If no modem type included
  55.         .\&b[2] = \m(defmodem)        ; supply default
  56.     }
  57.     if not def \&b[3] {               ; Ditto for speed
  58.         .\&b[3] = \m(defspeed)
  59.     }
  60.     set modem type \&b[2]             ; Try to set modem type
  61.     if fail continue                  ; Failed - go to next triplet
  62.     set line \&b[1]                   ; Try to get the line
  63.     if fail continue                  ; Failed - go to next triplet
  64.     set speed \&b[3]                  ; Set the speed but ignore errors
  65.     if !\v(local) continue            ; Make sure we're in local mode
  66.     echo {  Line:  \v(line)}          ; Report what we got...
  67.     echo {  Modem: \v(modem)}
  68.     echo {  Speed: \v(speed)}
  69.     end 0                             ; And return successfully
  70. }
  71. exit 1 No devices free                ; Didn't get one - fail
  72.