.key target
.bra 
.ket 
.def target sys:

; make required commands resident
resident >NIL: c:assign add pure
resident >NIL: c:copy add pure
resident >NIL: c:list add pure
resident >NIL: c:search add pure
resident >NIL: c:type add pure
resident >NIL: c:wait

; copy setmap to ram to avoid a disk swap
copy sys:system/setmap ram: quiet

; build the keymap choice table
failat 21

set keysource Extras2.0:
set keytarget target
;
echo "*Ec*N                KeyMap Selection"
echo "*NThis will allow you to choose a keymap for use in the"
echo "installation procedure.  Your Extras disk will be required."
echo "*NDo you wish to continue ? (1 = Yes / 0 = No) " noline
unset query
set >NIL: query ?
if NOT "$query" EQ "1"
    if NOT "$query" EQ "y"
        skip keyexit2
    endif
endif

; devs: will later be assigned to Extras.  we save off the current assign
; now to avoid a disk swap later.
assign olddevs$process: devs:
;
if EXISTS ${keysource}devs/keymaps
    list ${keysource}devs/keymaps lformat "%-8n(%c)" >t:key${process}
    type t:key${process} number to t:akey${process}
endif
echo "    0 usa     (American)" >>t:akey${process}

lab keystart
;
echo "*Ec*N                Select KeyMap*N"
;
unset number
type t:akey${process}
echo "*NYour choice (RETURN to exit without choosing) ? " noline
set >NIL: number ?
; did they want to just quit ?
if "$number" EQ "*$number"
    skip keyexit1
endif
;
; usa keymap is in rom
if "$number" EQ "0"
    setenv sys/keyboard usa
    skip keyend
endif
;
; validity check
if "$number" GT "9"
    echo "*NInvalid selection."
    wait 3 sec
    skip back keystart
else
    if "0" GT "$number"
        echo "*NInvalid selection."
        wait 3 sec
        skip back keystart
    endif
endif

;
; translate the number into the keymap name
;
set look string="`echo " $number "`"
; make sure selection number exists in list
search >NIL: t:akey${process} $look
if WARN
    echo "*NInvalid selection."
    wait 3
    skip back keystart
endif

echo "`search t:akey${process} $look`" first 14 len 4 >env:sys/keyboard
;
lab keyend

; set the selected keymap
assign devs: ${keysource}devs
ram:setmap ${sys/keyboard}
assign devs: olddevs$process:

;
lab keyexit1

delete >NIL: t:key${process} t:akey${process} quiet

lab keyexit2

delete >NIL: ram:setmap

resident >NIL: remove assign
resident >NIL: remove copy
resident >NIL: remove list
resident >NIL: remove search
resident >NIL: remove type
resident >NIL: remove wait

unset query
unset look
unset number
unset keysource
unset keytarget
