; K95.INI - Standard Kermit 95 initialization file.
;
; This file sets up the standard and expected environment for Kermit 95.
; Please don't edit this file.  Make any desired customizations in the
; K95SITE.INI and/or K95CUSTOM.INI file, which is executed by this file.
;
; . Sets up EDITOR if necessary
; . Defines NETEDIT macro
; . Executes customization file
;
; V2.4, Feb 2002
; K95 1.1.21 or later required:
; . Eliminates old dialing directories.
; . Updates customization file search.
;
; V3.0, July 2022
; Updated to support C-Kermit for Windows

echo EXECUTING STANDARD K95 INITIALIZATION FILE:
echo
echo " \flongpathname(\fpathname(\v(cmdfile)))"
echo
if = \v(xversion) 0 {
    ; Running on C-Kermit for Windows.
    if < \v(version) 800206 forward custom ; C-Kermit too old
} else {
    if < \v(xversion) 1121 forward custom  ; K95 too old
}

; Dialing and Network directories
; (THESE ARE OBSOLETE)
; set dial directory ckermit.kdd cis.kdd sprint.kdd tymnet.kdd genie.kdd
; set network directory ckermit.knd

; Editor - K95 Version 1.1.9 or later required

if def \v(editor) forward netedit     ; Picked up from registry?

; Set up the default editor for the EDIT command.  If you would rather use
; a different editor, then either define an EDITOR environment variable, or
; add a SET EDITOR command to your K95CUSTOM.INI file to override this one.
;
xif not def \$(EDITOR) {
    xif def \$(SystemRoot) {                    ; Windows NT
        set editor \$(SystemRoot)\\NOTEPAD.EXE
    } else {
        xif def \$(windir) {                    ; Windows 95
            set editor \$(windir)\\NOTEPAD.EXE
        } else {
            echo ERROR setting default editor name --
            echo Unable to locate proper Windows Environment variables  
        }
    }
}

:NETEDIT

; NETEDIT macro -- See UPDATES.TXT for an explanation.
;  
def _NETEDIT {
    switch \v(protocol) {
      :kermit,   output kermit -s \%1\13, break
      :zmodem,   output sz -a \%1\13, break
      :ymodem,   output sb -a \%1\13, break
      :ymodem-g, output sb -a \%1\13, break
      :xmodem,   output sx -a \%1\13, break
      :default, end 1 "\v(protocol)" - protocol unexpected
    }
    receive \%1
    if fail end 1 "\%1" - Download failed
    edit \%1
    if def WAIT_FOR_EDITOR getok
    if not exist \%1 end 1 -
      File "\%1" missing after edit - Did you change its name\?
    set file type text
    send \%1
    asg status \v(status)
    delete \%1
    if not = \m(status) 0 end 1 Upload failed
    end 0
}

def NETEDIT {
    local mode current
    asg mode \v(ftype)			; Save things
    set term autodownload off
    asg current \v(directory)
    if def \v(download) cd \v(download)
    do _netedit \%1			; Execute the macro
    asg status \v(status)
    set term autodownload on		; Restore things
    cd \m(current)
    set file type \m(mode)
    end \m(status)			; Return
}

:CUSTOM ; Locate and execute the Site or User-specific customization file.

if exist \v(inidir)K95SITE.INI take \v(inidir)K95SITE.INI
else if exist \$(K95CUSTOM) take \$(K95CUSTOM)
else if exist \v(appdata)K95CUSTOM.INI take \v(appdata)K95CUSTOM.INI
else if exist \v(inidir)K95CUSTOM.INI take \v(inidir)K95CUSTOM.INI
else if exist \v(exedir)K95CUSTOM.INI take \v(exedir)K95CUSTOM.INI
else if exist \v(exedir)K95CUSTOM.SAMPLE {
    ; Couldn't find k95custom.ini anywhere on the system. Rename
    ; the supplied k95custom.sample template and run that.
    echo Could not find k95custom.ini - renaming k95custom.sample and using that...
    rename \v(exedir)K95CUSTOM.SAMPLE \v(exedir)k95custom.ini
    take \v(exedir)K95CUSTOM.INI
}

end ; of K95.INI
