mirror of
https://github.com/depp/syncfiles.git
synced 2025-02-19 20:30:39 +00:00
Extract packbits into separate repository
This commit is contained in:
parent
f39ab85222
commit
d77ccf009e
@ -2,4 +2,7 @@ module moria.us/macroman
|
||||
|
||||
go 1.16
|
||||
|
||||
require golang.org/x/text v0.3.5
|
||||
require (
|
||||
github.com/depp/packbits v1.0.0
|
||||
golang.org/x/text v0.3.5
|
||||
)
|
||||
|
@ -1,3 +1,5 @@
|
||||
github.com/depp/packbits v1.0.0 h1:KqnhCkzI5WbWuwKsAgPI/JLF11mBXBEvYADiwKZMXi0=
|
||||
github.com/depp/packbits v1.0.0/go.mod h1:wDV3NXiMB4a+KztSJ93UMH9cBKj5cEGooAbgRXTpQ78=
|
||||
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/depp/packbits"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
)
|
||||
|
||||
@ -150,45 +151,6 @@ func tableToBytes(t []uint16) []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
func getRun(bytes []byte) (repeat bool, run []byte) {
|
||||
if len(bytes) == 0 {
|
||||
return
|
||||
}
|
||||
ref := bytes[0]
|
||||
n := 1
|
||||
for n < len(bytes) && bytes[n] == ref {
|
||||
n++
|
||||
}
|
||||
if n >= 2 {
|
||||
return true, bytes[:n]
|
||||
}
|
||||
for i, b := range bytes[1:] {
|
||||
if b == ref {
|
||||
return false, bytes[:i]
|
||||
}
|
||||
ref = b
|
||||
}
|
||||
return false, bytes
|
||||
}
|
||||
|
||||
func packBits(bytes []byte) []byte {
|
||||
var result []byte
|
||||
for len(bytes) > 0 {
|
||||
repeat, run := getRun(bytes)
|
||||
if len(run) > 128 {
|
||||
run = run[:128]
|
||||
}
|
||||
if repeat {
|
||||
result = append(result, byte(1-len(run)), run[0])
|
||||
} else {
|
||||
result = append(result, byte(len(run)-1))
|
||||
result = append(result, run...)
|
||||
}
|
||||
bytes = bytes[len(run):]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func printTable(table []uint16) error {
|
||||
if _, err := fmt.Print("static const unsigned short kFromUnixTable[] = {"); err != nil {
|
||||
return err
|
||||
@ -249,8 +211,7 @@ func main() {
|
||||
dumpTransitions(table)
|
||||
}
|
||||
bytes := tableToBytes(table)
|
||||
// printTable(table)
|
||||
bits := packBits(bytes)
|
||||
bits := packbits.Pack(bytes)
|
||||
if err := printData(os.Stdout, len(bytes), bits); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error:", err)
|
||||
os.Exit(1)
|
||||
|
@ -31,22 +31,22 @@ static const unsigned char kFromUnixData[1256] = {
|
||||
153,0,4,157,0,156,0,158,246,0,0,159,129,0,129,0,129,0,129,0,129,0,251,0,0,34,
|
||||
129,0,129,0,137,0,0,216,129,0,129,0,129,0,129,0,210,0,6,202,0,193,0,162,0,163,
|
||||
254,0,0,180,254,0,10,164,0,172,0,169,0,187,0,199,0,194,254,0,6,168,0,248,0,161,
|
||||
0,177,252,0,8,171,0,181,0,166,0,225,0,252,254,0,2,188,0,200,250,0,0,192,129,0,
|
||||
129,0,129,0,31,0,203,0,231,0,229,0,204,0,128,0,129,0,174,0,130,0,233,0,131,0,
|
||||
230,0,232,0,237,0,234,0,235,0,236,254,0,10,132,0,241,0,238,0,239,0,205,0,133,
|
||||
254,0,8,175,0,244,0,242,0,243,0,134,252,0,32,167,0,136,0,135,0,137,0,139,0,138,
|
||||
0,140,0,190,0,141,0,143,0,142,0,144,0,145,0,147,0,146,0,148,0,149,254,0,22,150,
|
||||
0,152,0,151,0,153,0,155,0,154,0,214,0,191,0,157,0,156,0,158,0,159,252,0,0,216,
|
||||
129,0,129,0,129,0,158,0,0,245,129,0,129,0,129,0,192,0,2,206,0,207,184,0,0,217,
|
||||
129,0,129,0,129,0,206,0,0,196,129,0,129,0,129,0,154,0,2,246,0,255,224,0,10,249,
|
||||
0,250,0,251,0,254,0,247,0,253,129,0,129,0,129,0,129,0,234,0,0,189,129,0,129,0,
|
||||
129,0,212,0,0,185,129,0,129,0,129,0,131,0,4,44,0,45,0,46,254,0,0,47,250,0,2,48,
|
||||
0,49,230,0,0,50,129,0,129,0,129,0,137,0,2,208,0,209,250,0,4,212,0,213,0,226,254,
|
||||
0,4,210,0,211,0,227,254,0,4,160,0,224,0,165,250,0,0,201,238,0,0,228,240,0,2,220,
|
||||
0,221,129,0,129,0,129,0,238,0,0,218,129,0,129,0,129,0,129,0,178,0,0,219,129,0,
|
||||
129,0,129,0,150,0,0,170,129,0,129,0,129,0,194,0,0,182,250,0,0,198,240,0,0,184,
|
||||
254,0,0,183,240,0,0,195,250,0,0,176,232,0,0,186,129,0,129,0,129,0,200,0,0,197,
|
||||
210,0,0,173,250,0,2,178,0,179,129,0,129,0,129,0,184,0,0,215,129,0,129,0,129,0,
|
||||
129,0,209,0,0,52,240,0,0,53,129,0,129,0,129,0,129,0,219,0,0,240,129,0,129,0,129,
|
||||
0,254,0,2,222,0,223,129,0,135,0,
|
||||
0,177,252,0,8,171,0,181,0,166,0,225,0,252,254,0,2,188,0,200,250,0,1,192,0,129,0,
|
||||
129,0,129,0,30,203,0,231,0,229,0,204,0,128,0,129,0,174,0,130,0,233,0,131,0,230,
|
||||
0,232,0,237,0,234,0,235,0,236,254,0,10,132,0,241,0,238,0,239,0,205,0,133,254,0,
|
||||
8,175,0,244,0,242,0,243,0,134,252,0,32,167,0,136,0,135,0,137,0,139,0,138,0,140,
|
||||
0,190,0,141,0,143,0,142,0,144,0,145,0,147,0,146,0,148,0,149,254,0,22,150,0,152,
|
||||
0,151,0,153,0,155,0,154,0,214,0,191,0,157,0,156,0,158,0,159,252,0,0,216,129,0,
|
||||
129,0,129,0,158,0,0,245,129,0,129,0,129,0,192,0,2,206,0,207,184,0,0,217,129,0,
|
||||
129,0,129,0,206,0,0,196,129,0,129,0,129,0,154,0,2,246,0,255,224,0,10,249,0,250,
|
||||
0,251,0,254,0,247,0,253,129,0,129,0,129,0,129,0,234,0,0,189,129,0,129,0,129,0,
|
||||
212,0,0,185,129,0,129,0,129,0,131,0,4,44,0,45,0,46,254,0,0,47,250,0,2,48,0,49,
|
||||
230,0,0,50,129,0,129,0,129,0,137,0,2,208,0,209,250,0,4,212,0,213,0,226,254,0,4,
|
||||
210,0,211,0,227,254,0,4,160,0,224,0,165,250,0,0,201,238,0,0,228,240,0,2,220,0,
|
||||
221,129,0,129,0,129,0,238,0,0,218,129,0,129,0,129,0,129,0,178,0,0,219,129,0,129,
|
||||
0,129,0,150,0,0,170,129,0,129,0,129,0,194,0,0,182,250,0,0,198,240,0,0,184,254,0,
|
||||
0,183,240,0,0,195,250,0,0,176,232,0,0,186,129,0,129,0,129,0,200,0,0,197,210,0,0,
|
||||
173,250,0,2,178,0,179,129,0,129,0,129,0,184,0,0,215,129,0,129,0,129,0,129,0,209,
|
||||
0,0,52,240,0,0,53,129,0,129,0,129,0,129,0,219,0,0,240,129,0,129,0,129,0,254,0,2,
|
||||
222,0,223,129,0,135,0,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user