fluffy/hd.go

79 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"bytes"
"fmt"
"os"
"io"
)
const charset = "" +
"·☺☻♥♦♣♠•◘○◙♂♀♪♫☼" +
"►◄↕‼¶§▬↨↑↓→←∟↔▲▼" +
" !\"#$%&'()*+,-./" +
"0123456789:;<=>?" +
"@ABCDEFGHIJKLMNO" +
"PQRSTUVWXYZ[\\]^_" +
"`abcdefghijklmno" +
"pqrstuvwxyz{|}~⌂" +
"ÇüéâäàåçêëèïîìÄÅ" +
"ÉæÆôöòûùÿÖÜ¢£¥€ƒ" +
"áíóúñѪº½⅓¼⅕⅙⅛«»" +
"░▒▓│┤╡╢╖╕╣║╗╝╜╛┐" +
"└┴┬├─┼╞╟╚╔╩╦╠═╬╧" +
"╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀" +
"αßΓπΣσµτΦΘΩδ∞φε∩" +
"⁰¹²³⁴⁵⁶⁷⁸⁹ⁱⁿ⁽⁼⁾¤"
func main() {
offset := 0
b := make([]byte, 16)
lb := make([]byte, 16)
chars := []rune(charset)
skipping := false
for ;; {
n, err := os.Stdin.Read(b)
if err != nil {
if err != io.EOF {
fmt.Println("read failed:", err)
}
break
}
if (offset > 0) && (bytes.Equal(lb, b)) {
if ! skipping {
fmt.Println("*")
}
offset += n
skipping = true
continue
}
copy(lb, b)
skipping = false
fmt.Printf("%08x ", offset)
offset += n
for i := 0; i < 16; i += 1 {
if i % 8 == 0 {
fmt.Printf(" ")
}
if i < n {
fmt.Printf("%02x ", b[i])
} else {
fmt.Printf(" ")
}
}
fmt.Printf("ǀ")
for i := 0; i < n; i += 1 {
fmt.Printf("%c", chars[b[i]])
}
fmt.Printf("ǀ\n")
}
fmt.Printf("%08x\n", offset)
}