:macro cinit
;;
;; cinit.mac - this macro is called automatically when any connection ensures
;;
;; Parametres: %1 - callsign of connected station
;;             %2 - callsign of previously connected station
;;                  or empty when first connection
;;

;; Setup remote command acces list
if %(exist STN_RCMD) == 1
  rcmd %STN_RCMD
else
  rcmd %DEF_RCMD@0
endif

;; When a ENC variable is set for this station, change character translation
;; table
if %(exist STN_ENC) == 1
  translate %STN_ENC
else
  translate %DEF_ENC@0
endif

;; When a TERM variable is set, change terminal type
if %(exist STN_TERM) == 1
  term %STN_TERM
else
  term none
endif

;; When it's a primary connection a path to logbook is set, add a logbook 
;; entry
if "%2" == ""
  if %(exist LOG_PATH@0) == 1
    if %(exist QRG@0) == 1
      log start %LOG_PATH@0/%Y %1 "%QRG@0"
    endif
  endif
endif

;; Reply to login password request (if any)
if %(exist STN_LOGINPW) == 1
  if %(exist STN_PWPROMPT) == 1
    :WAITPWD
    set PROMPT "%<"
    set PWLEN %(strlen "%STN_PWPROMPT")
    if %(strleft %PWLEN "%PROMPT") == "%STN_PWPROMPT"
      tnpwd -n "%STN_LOGINPW" "%PROMPT"
    else
      goto WAITPWD
    endif
    unset PROMPT
  endif
endif
