; HOSTTCP.KSC
;
; Kermit 95 Host-Mode Listener for Incoming TCP/IP Connections.
; January 1996
;
;   Windows 95 can accept multiple simultaneous connections.
;   Windows NT 3.51 can accept only one at a time.
;

; The following code was added to accomodate the new Windows multi-user
; friendly directory layouts introduced with version 1.1.21.  We have
; check several locations for the directories that hostmode uses and
; create them in \v(appdata) if the do not exist at all.

if directory \v(exedir)USERS {
    asg _hostroot \v(exedir)
    forward FOUNDDIRS
}
if directory \v(startup)INCOMING {
    asg _hostroot \v(startup)
    forward FOUNDDIRS
}

if directory \v(appdata)USERS {
    asg _hostroot \v(appdata)
}

:FOUNDDIRS

asg _configfile \freplace(\m(_hostroot)/host.cfg,/,\\)

def MAKEVAR2 if def \%2 _assign \%1 \%2, else _assign \%1

def MAKEVAR -
  if = \findex(=,\%1,1) 0 end, -
  asg \%9 _\freplace(\%1,=,\32), -
  makevar2 \%9

open read \m(_configfile)
if fail forward noconfig
while true { read \%a, if fail break, makevar \%a }

if not def _hostport stop 1 Fatal - HOSTPORT not defined.
set network directory	       ; No directory lookups
set take echo on
set macro echo on

:LOOP
set host * \m(_hostport) /tel  ; Wait for a connection on this port
xif fail { -
  echo K95 Host Mode - Failure to listen on socket \m(_hostport), -
  echo Press a key to exit...,-
  getc \%9,-
  exit 1 -
}
take host.ksc                  ; Execute the host script
msleep 250                     ; Wait for socket to reset
goto loop                      ; Go back and wait for another connection

End ; HOSTTCP.KSC
