Version 0 of Morse code

Updated 2002-05-17 12:57:13

Morse en/decoder: works both ways ASCII <-> Morse

  proc morse {s} {
    set _morse {
        A ._ � ._._ B _... C _._. D _.. E . F .._.
        G __. H .... I .. J .___ K _._ L ._.. M __
        N _. O ___ � ___. P .__. Q __._ R ._. S ...
        T _ U .._ � ..__ V ..._ W .__ X _.._ Y _.__ Z __..
        0 _____ 1 .____ 2 ..___ 3 ...__ 4 ...._ 5 .....
        6 _.... 7 __... 8 ___.. 9 ____.
        . ._._._ , __..__ ? ..__.. / _.._. ( _.__. ) _.__._
        + ._._. : ___... ; ...___ - _...._ = _..._
        ~ ._... # ..._._ $ _..._._ 
    }
    set res ""
    if [regexp {^[._ ]+$} $s] {
        regsub -all {  +} $s " B " s
        foreach i [split $s] {
            if {$i==""}  continue
            if {$i=="B"} {append res " "; continue}
            set ix [lsearch $_morse $i]
            if {$ix>=0} {
                append res [lindex $_morse [expr {$ix-1}]]
            } else {append res ?}
        }
    } else {
        foreach i [split [string toupper $s] ""] {
            if {$i==" "} {append res "  "; continue}
            set ix [lsearch -exact $_morse $i]
            if {$ix>=0 && $ix%2==0} {
                append res "[lindex $_morse [expr {$ix+1}]] "
            }
        }
    }
    set res
  } ;#RS - slightly uncrufted 2001-12-04

KBK (2002-04-09)

 QST QST QST DE KE9TV/2 KE9TV/2 KE9TV/2 BT

added punctuation, plus added procedural signs

 ~ - Stand by (AS)
 # - End of work (SK or VA)
 $ - Break (BK)

Procedural signs AR, BT and KN are encoded by +, = and ( respectively, since those are the meaning of those signs within a message body.

Ampersand should be sent as the two characters ES.

Still to do: AAA is a period, but a decimal point is sent as a character R.

 VY 73 DE KE9TV/2 SK AR

Arts and crafts of Tcl-Tk programming