chiark / gitweb /
Finalise 4.4.0
[chiark-utils.git] / scripts / hexterm
index 5189848ac560611f2008b2485fd2b58f8e192558..9a1b0475bdb4ce05fe84c0a3a8681a8e074ff000 100755 (executable)
@@ -3,10 +3,11 @@ set comment {
 #
 Use of the screen:
 0         1         2         3         4         5         6         7
-xxx| hh hh hh hh  hh hh hh hh  hh hh hh hh  hh hh hh hh_| abcd e_.. .... ...._|
+xxxE hh hh hh hh  hh hh hh hh  hh hh hh hh  hh hh hh hh_| abcd e_.. .... ...._|
 }
 # Display:
 #      | is a vertical delimiter
+#       E is either | to mean echo is on or ' to mean it is off
 #      hh are hex digits of output:
 #              00-ff   actual hex data (bold for stuff we entered)
 #              0-f     under cursor: one digit entered, need the next
@@ -25,18 +26,38 @@ xxx| hh hh hh hh  hh hh hh hh  hh hh hh hh  hh hh hh hh_| abcd e_.. .... ...._|
 #                set count to 0
 #      DEL     clear any entered hex digit
 #      SPC     send 00
+#      '       toggle echo
 # nyi:
 #      G-Z     record last bytes we transmitted and store in memory
 #               if we were halfway through a hex byte, first digit
 #               is length of string to record
 #      g-z     play back memory
 
+
+# Copyright 2005 Ian Jackson <ian@chiark.greenend.org.uk>
+#
+# This script and its documentation (if any) are free software; you
+# can redistribute it and/or modify them under the terms of the GNU
+# General Public License as published by the Free Software Foundation;
+# either version 3, or (at your option) any later version.
+# 
+# chiark-named-conf and its manpage are distributed in the hope that
+# it will be useful, but WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE.  See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, consult the Free Software Foundation's
+# website at www.fsf.org, or the GNU Project website at www.gnu.org.
+
+
 if {[llength $argv] != 1} { error "need serial port arg" }
 
 set port [lindex $argv 0]
 
 set count 0
 set lit 0 ;# 1 means literal (ASCII) entry mode
+set echo 1
 
 proc p {s} {
     puts -nonewline $s
@@ -72,11 +93,16 @@ proc csrs_show {} {
     csr_this_show
 }
 
+proc echop {} {
+    global echo
+    return [expr {$echo ? "|" : "'"}]
+}
+
 proc newline {} {
-    global x count
+    global x echo count
     if {[info exists x]} { csrs_erase; p "\r\n" }
     set x 0
-    p [format "%3x|%*s|%*s|" $count 52 "" 21 ""]
+    p [format "%3x%s%*s|%*s|" $count [echop] 52 "" 21 ""]
     csrs_show
 }
 
@@ -128,9 +154,17 @@ proc onreadp {} {
 }
 
 proc transmit {d} {
-    global p
+    global p echo
     puts -nonewline $p [format %c $d]
-    ch $d bold
+    if {$echo} { ch $d bold }
+}
+
+proc k_echo {} {
+    global echo
+    set echo [expr {!$echo}]
+    tput hpa 3
+    p [echop]
+    csr_this
 }
 
 proc k_newline {} {
@@ -172,11 +206,12 @@ proc k_noparthex {} {
 }
 
 proc k_hexdigit {c} {
-    global h1
+    global h1 echo
     if {![info exists h1]} { set h1 $c; p $c; p "\b"; return }
     set d [expr 0x${h1}${c}]
     unset h1
     transmit $d
+    if {!$echo} { p " \b" }
 }
 
 proc onreadk {} {
@@ -196,8 +231,9 @@ proc onreadk {} {
        if {$lit} { transmit $d; continue }
        switch -exact $d {
            13 { k_newline; continue }
-           127 { k_noparthex; continue }
            32 { transmit 0; continue }
+           39 { k_echo; continue }
+           127 { k_noparthex; continue }
        }
        if {$d >= 48 && $d <= 57} { k_hexdigit $c; continue }
        set kl [expr {$d | 32}]