

array set ucode_greek {
   alpha   "\u03B1"   Alpha   "\u0391"
   beta    "\u03B2"   Beta    "\u0392"
   gamma   "\u03B3"   Gamma   "\u0393"
   delta   "\u03B4"   Delta   "\u0394"
   epsilon "\u03B5"   Epsilon "\u0395"
   zeta    "\u03B6"   Zeta    "\u0396"
   eta     "\u03B7"   Eta     "\u0397"
   theta   "\u03B8"   Theta   "\u0398"
   iota    "\u03B9"   Iota    "\u0399"
   kappa   "\u03BA"   Kappa   "\u039A"
   lambda  "\u03BB"   Lambda  "\u039B"
   mu      "\u03BC"   Mu      "\u039C"
   nu      "\u03BD"   Nu      "\u039D"
   xi      "\u03BE"   Xi      "\u039E"
   omicron "\u03BF"   Omicron "\u039F"
   pi      "\u03C0"   Pi      "\u03A0"
   pho     "\u03C1"   Pho     "\u03A1"
   sigma1  "\u03C2"   Sigma1  "\u03A2"
   sigma   "\u03C3"   Sigma   "\u03A3"
   tau     "\u03C4"   Tau     "\u03A4"
   upsilon "\u03C5"   Upsilon "\u03A5"
   phi     "\u03C6"   Phi     "\u03A6"
   chi     "\u03C7"   Chi     "\u03A7"
   psi     "\u03C8"   Psi     "\u03A8"
   omega   "\u03C9"   Omega   "\u03A9"
   theta1  "\u03D1"
   phi1    "\u03D5"
   omega1  "\u03D6"
}


array set enc_symbol {
   alpha   "\u03B1"   Alpha   "\u0391"
   beta    "\u03B2"   Beta    "\u0392"
   gamma   "\u03B3"   Gamma   "\u0393"
   delta   "\u03B4"   Delta   "\u0394"
   epsilon "\u03B5"   Epsilon "\u0395"
   zeta    "\u03B6"   Zeta    "\u0396"
   eta     "\u03B7"   Eta     "\u0397"
   theta   "\u03B8"   Theta   "\u0398"
   iota    "\u03B9"   Iota    "\u0399"
   kappa   "\u03BA"   Kappa   "\u039A"
   lambda  "\u03BB"   Lambda  "\u039B"
   mu      "\u03BC"   Mu      "\u039C"
   nu      "\u03BD"   Nu      "\u039D"
   xi      "\u03BE"   Xi      "\u039E"
   omicron "\u03BF"   Omicron "\u039F"
   pi      "\u03C0"   Pi      "\u03A0"
   pho     "\u03C1"   Pho     "\u03A1"
   sigma1  "\u03C2"   Sigma1  "\u03A2"
   sigma   "\u03C3"   Sigma   "\u03A3"
   tau     "\u03C4"   Tau     "\u03A4"
   upsilon "\u03C5"   Upsilon "\u03A5"
   phi     "\u03C6"   Phi     "\u03A6"
   chi     "\u03C7"   Chi     "\u03A7"
   psi     "\u03C8"   Psi     "\u03A8"
   omega   "\u03C9"   Omega   "\u03A9"
   theta1  "\u03D1"
   phi1    "\u03D5"
   omega1  "\u03D6"
}


proc ucode_scan_entry {s} {

   set n [string length $s]
   set r ""
   for {set i 0} {$i < $n} {incr i} {
      if {[string range $s $i [expr $i+1]] == "\\u"} {
         eval append r [string range $s $i [expr $i+5]]
         incr i 5 
      } else {
         append r [string index $s $i]
      }
   }

   return $r
}


proc from_oct {n} {
   set k [string length $n]
   set m 0
   for {set i 0} {$i < $k} {incr i} {
      set j [expr 3*($k - $i -1)]
      set m [expr $m + ([string index $n $i] << $j)]
   }
   return [binary format c $m]
}
