Warning: this is an htmlized version!
The original is across this link,
and the conversion rules are here.
# eev/libeeg/term - a library for eeg4.
# By edrx, 2001nov26.
# Htmlized version: <http://angg.twu.net/eev/libeeg/term.html>.
# This file adds support for terminal-dependent key sequences to "k".
# (find-angg "eev/libeeg/k")

# «.termkeys_tputs_to_tcl»	(to "termkeys_tputs_to_tcl")
# «.termkeysfname»		(to "termkeysfname")
# «.save_termkeys_file»		(to "save_termkeys_file")


# This function generates the key definitions that depend on the value
# of $TERM, as a big string that can be evaluated as Tcl code.

# «termkeys_tputs_to_tcl»  (to ".termkeys_tputs_to_tcl")
proc termkeys_tputs_to_tcl {} {
  set bigstr "# Generated automatically by eeg4\n"
  foreach {keyname capname} {
    up   kcuu1  down kcud1  right kcuf1  left kcub1
    home khome  ins  kich1  del   kdch1  end  kend
    pgdn knp    pgup kpp    kp-5  kb2    bsp  kbs
    f1 kf1 f2 kf2 f3 kf3 f4 kf4 f5 kf5 f6 kf6 f7 kf7 f8 kf8
    f9 kf9 f10 kf10 f11 kf11 f12 kf12 f13 kf13 f14 kf14
    f15 kf15 f16 kf16 f17 kf17 f18 kf18 f19 kf19 f20 kf20
  } {
    if {[catch {
      set str [exec tput $capname]
      if {$str!=""} {
        append bigstr "defkey $keyname [list $str]\n"
      } else {
        append bigstr "# $keyname ($capname): undefined\n"
      }
    }]} {
      append bigstr "# $keyname ($capname): tput error\n"
    }
  }
  return $bigstr
}

# Now comes some code about optimizing things by saving the Tcl code
# generated by termkeys_tputs_to_tcl to a file and sourcing it.

# «termkeysfname»  (to ".termkeysfname")
proc termkeysfname {} { toeeglibfname term-[getenv TERM].auto.tcl }

# «save_termkeys_file»  (to ".save_termkeys_file")
# (find-eev "Makefile" "eeg4-termkeys")
#
proc save_termkeys_file {} {
  set fname [termkeysfname]
  writefile $fname [termkeys_tputs_to_tcl]
  puts "Wrote $fname"
}


if {[file exists [termkeysfname]]} {
  # Good, the file exists, just source it.
  uplevel #0 source [termkeysfname]
} else {
  # Oh, no! The file doesn't exist... so we generate the string with
  # what should have been its contents and we evaluate it. This is
  # much slower because we have to call tput many times.
  uplevel #0 [termkeys_tputs_to_tcl]
}



#
#  Local Variables:
#  mode:		 tcl
#  coding:               no-conversion
#  ee-anchor-format:     "«%s»"
#  ee-charset-indicator: "Ñ"
#  End: