COMMENT - Standard C-Kermit initialization file
;
; For C-Kermit Version: 5A(190)
;
; Filename:
;   .kermrc     (UNIX, OS-9, Aegis)
;
; To override settings or definitions made in this file, to
; add new settings or definitions, or to make any other desired
; customizations, create a separate, personal customization file called: 
;
;   .mykermrc     (UNIX, OS-9, Aegis)

def \%g FORWARD			; Use FORWARD for speed if available.


\%g \v(system)			; First do system-dependent items...

:UNIX				; UNIX, all versions
def _dedit vi			; Default editor is VI
asg _myinit -
  \v(home).mykermrc		; Customization filename
if > \v(version) 501189 if remote \%g COMMON ; Skip local-mode items if "-R"
asg _dialdir -
  \v(home).kdd			; C-Kermit dialing directory
asg _servicedir -
  \v(home).ksd			; C-Kermit services directory
\%g COMMON                      ; End of UNIX section

:COMMON				; System-independent items

; Make the C-Kermit prompt show my current directory.
; Environment variable or logical name CKPROMPT takes precedence.
;
if def \$(CKPROMPT) set prompt \$(CKPROMPT)
  else  set prompt [\v(dir)] C-Kermit>

COMMENT - File transfer macros
;
def _SEND asg \%9 \ffiles(\%1),-
  if = 0 \%9 end 1 {\?File not found},-
  if = 1 \%9 send \%1 \%2,-  ; Single file with as-name
  else send \%1              ; or wildcard with no as-name
def BINARY set file type binary
def TEXT set file type text
def BSEND binary, _send \%1 \%2	; Send binary file(s)
def TSEND text, _send \%1 \%2	; Send text file(s)
def BGET remote set file type binary, -          ; Get binary file(s)
  if success get \%1 \%2 \%3 \%4 \%5 \%6 \%7 \%8 ;  from server
def TGET remote set file type text, -            ; Get text file(s)
  if success get \%1 \%2 \%3 \%4 \%5 \%6 \%7 \%8 ;  from server
def FAST -
  ech FAST file transfer settings - use at your own risk...,-
  set win 5, set rec packet 5000, set contr u all,-
  set con p 0 1 3 13 17 19 129 141 145 147
def ROBUST set win 1, set rec packet 90, set con p all

COMMENT - EDIT macro.
;
; EDITOR environment variable, if defined, takes precedence.
;
check push			; Only works if we have a PUSH command
if fail \%g files		; (so it doesn't work on the Macintosh).

if def \$(EDITOR) assign myeditor \$(EDITOR)
  else assign myeditor \m(_dedit)
if not def myeditor def myeditor edit
def _dedit
def myfile

def edit if = \v(argc) 2 assign myfile \%1,-
  if not def myfile echo Edit what?,-
  else run \m(myeditor) \m(myfile)

:FILES

; Get customization, dialing directory, and services directory filenames.
; Let environment variables take precedence, so users do not have to edit
; this file to change these filenames.
;
if def \$(CKERMOD) assign _myinit \$(CKERMOD)
if not def _myinit assign _myinit \v(home)CKERMOD.INI

if > \v(version) 501189 if remote \%g NOSERVICES

if def \$(CKDDIR) assign _dialdir \$(CKDDIR)
if not def _dialdir assign _dialdir \v(home)CKERMIT.KDD

if def \$(CKSDIR) assign _servicedir \$(CKSDIR)
if not def _servicedir assign _servicedir \v(home)CKERMIT.KSD

CHECK DIAL			; Is the DIAL command enabled?
xif fail { -			; No.
    echo DIAL disabled -
} else { -			; Yes, check for and open the dial directory.
    xif exist \m(_dialdir) { -
        set dial directory \m(_dialdir), -
        echo { Dial directory is \m(_dialdir) } -
    } -
}

COMMENT - Check for existence of services directory
;
if not exist \m(_servicedir) \%g NOSERVICES

COMMENT - Have services directory, so read it and define related macros
;
echo { Services directory is \m(_servicedir)}

def max_svcs 50               ; Adjust this if you have more than 50 entries!
open read \m(_servicedir)     ; Open services directory file
xif fail { -
    echo Can't open \m(_servicedir), -
    goto NOSERVICES -
}
declare \&d[\m(max_svcs)]     ; Declare array for service directory entries
for \%i 1 \m(max_svcs) 1 { -  ; Read entries into array
    read \&d[\%i], -
    if fail \%g DONE -
}
close read                    ; Didn't reach the end
echo -                        ; Close the file and print useful message
  \?Too many entries in services directory:
echo { Maximum is \m(max_svcs).}
echo { Change definition of max_svcs in \v(cmdfile) to allow more. }
echo { Services directory disabled.}
\%g NOSERVICES

:DONE                         ; We have the services directory in memory
asg \&d[0] \feval(\%i - 1)    ; Keep size of array in zeroth element

; LIST macro.  Arguments:
; \%1 = service name (optional)
;
def LIST -
  if > \v(argc) 1 goto SEARCH, -
  echo \&d[0] items in services directory:, -   ; No search item
  for \%i 1 \&d[0] 1 { echo \&d[\%i] }, end, -  ; List whole directory
:SEARCH, -                                      ; Search item given
  lookup \%1, -                                 ; Look it up
  if def \v(return) echo \v(return), -          ; List it if found
  else echo \%1: Not found                      ; or say it wasn't

COMMENT - SERIAL macro.  Arguments:
; \%1 = device name
; \%2 = speed
;
def SERIAL -
  if < \v(argc) 3 -                       ; All arguments given?
    end 1 Usage: SERIAL device speed,-    ; No.
  set line \%1,-                          ; OK, try to SET LINE.
  if failure -                            ; If this failed,
    end 1 Can't open device: \%1,-        ; print message and quit.
  set speed \%2,-                         ; Try to set the speed.
  if fail end 1 Unsupported speed: \%2,-  ; Failed.
  echo Connection successful.             ; Succeeded.

COMMENT - NET macro.  Arguments:
; \%1 = network type
; \%2 = host name or address
;
def NET if < \v(argc) 3 end 1 Usage: NET network host,-
  set network \%1,-
  if fail end 1 unsupported network: \%1,-
  set host \%2,-
  if fail end 1 can't reach host: \%2,-
  echo Connection successful.

COMMENT - CALL macro.  Arguments:
;
; \%1 = modem type
; \%2 = device name
; \%3 = speed
; \%4 = phone number
;
def CALL if < \v(argc) 5 end 1 Usage: CALL modem device speed number,-
  set modem \%1,-
  if fail end 1 unknown modem type: \%1,-
  set line \%2,-
  if fail end 1 can't open device: \%2,-
  set speed \%3,-
  if fail end 1 unsupported speed: \%3,-
  for \%i 1 10 1 { -
    xif > \%i 1 { -
        echo Will redial in 1 minute: please wait...,-
        pause 60,-
        echo Redialing: try number \%i...,-
    },-
    dial \%4,-
    if success goto OK,-
    hangup,-
  } -
  end 1 Can't place call: \%4,-
  :ok,-
  pause 1,-
  echo Connection successful.

COMMENT - UNIXLOGIN macro.  Arguments:
; \%1 = user ID
; \%2 = password
;
def UNIXLOGIN if < \v(argc) 2 end 1 Usage: \%0 userid password,-
    if eq \fcode(\%2) 32 asg \%2 \fsubst(\%2,2), -
    while not def \%2 { - 
        askq \%2 { \%1's password: } -
    },-
    set parity none,-
    set duplex full,-
    set handshake none,-
    set case on,-
    out \13,-
    set input timeout proceed,-
    for \%i 1 15 1 { -
        in 5 login:,-
        if success goto DOLOGIN,-
        output \\B -
    },-
    end 1 No login prompt,-
:DOLOGIN,-
    out \%1\13,-
    inp 5 Password:,-
    if fail end 1 No password prompt,-
    out \%2\13,-
    def \%2,-
    if not def \%3 asg \%3 {\13\10$ },-
    inp 60 \%3,-
    if fail end 1 No system prompt,-
    echo, echo Login successful.


COMMENT - NOLOGIN macro.  Does nothing.  Use when login not required.
;
def nologin comment

COMMENT - LOOKUP macro.  Argument:
; \%1 = Service name to look for in services directory
;
def LOOKUP -
    set case off,-          ; Ignore alphabetic case
    for \%i 1 \&d[0] 1 { -  ; Loop thru services directory
        if eq \%1 \fsubstr(\&d[\%i],1,\flen(\%1)) - ; Got a match?
          break -           ; If so, we're done
    },-
    if not > \%i \&d[0] return \&d[\%i] ; Return the entry

def _a1 return \%1
def _a2 return \%2

def DOACCESS -		; (Used internally by ACCESS macro)
    do \%5 \%6 \%7 \%8 \%9,- ; Do the connection macro
    if fail end 1,-
    _a2 \%3,-                ; Prompt, if any
    asg \%2 \v(return),-
    _a1 \%3,-                ; Login macro name
    asg \%3 \v(return),-
    do \%3 \%4 {\%1} \%2     ; Login macro, userid, password, prompt

; ACCESS macro.  Arguments:
; \%1 = service name
; \%2 = password (optional)
;
def ACCESS -
    if not defined \%1 end 1 access what?,-      ; Check service
    lookup \%1,-                                 ; Look it up
    if success doaccess { \%2} \v(return),-      ; OK, try it
    else end 1 "\%1" not in services directory,- ; Not found
    if fail stop 1                               ; DOACCESS failed?

\%g ENDSERVICES			; Skip around NOSERVICES definitions.

:NOSERVICES
def access echo { Services directory not available.}
asg list \m(access)

:ENDSERVICES

COMMENT - Execute user's personal customization file
;
:CUSTOM
xif exist \m(_myinit)  { -		; If it exists,
    echo Executing \m(_myinit)..., -	; print message,
    take \m(_myinit) -			; and TAKE the file.
}

; End of C-Kermit 5A initialization file.
