Wapp

Artifact [ce973538f2]
Login

Artifact ce973538f271715981a49dca8bb4e3a56b035e9754d6a47ffae449da4a3ce872:


#!/usr/bin/tclsh
#
# Convert a binary file (such as an image) into hex.
#
# Usage:
#
#     tclsh file-to-hex.tcl FILENAME
#
if {[llength $argv]!=2} {
  puts stderr "Usage: $argv0 (hex|base64) FILENAME"
  exit 1
}
set mode [lindex $argv 0]
if {$mode!="hex" && $mode!="base64"} {
  puts stderr "Usage: $argv0 (hex|base64) FILENAME"
  exit
}
set filename [lindex $argv 1]
set fd [open $filename rb]
set x [binary encode $mode [read $fd]]
puts "  w3-unsafe \[binary decode $mode \173"
set n [string length $x]
for {set i 0} {$i<$n} {incr i 64} {
  puts "    [string range $x $i [expr {$i+63}]]"
}
puts "  \175\]"