From a97dac93e1610df42ec9d1688bd49e92b47518e9 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 1 Sep 2019 08:27:21 +1000 Subject: [PATCH] Change ractool drange syntax from i:j to i..j This is more consistent with the RAC spec, and on the Windows command line the colon might be confused with the ":" in "C:\" names. --- cmd/ractool/data.go | 12 ++++++------ cmd/ractool/main.go | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cmd/ractool/data.go b/cmd/ractool/data.go index 45372681..2b4fd4e2 100644 --- a/cmd/ractool/data.go +++ b/cmd/ractool/data.go @@ -63,15 +63,15 @@ or temporary disk space. Examples: ractool -decode foo.rac | sha256sum - ractool -decode -drange=400:500 foo.rac + ractool -decode -drange=400..500 foo.rac ractool -encode foo.dat > foo.rac ractool -encode -codec=zlib -dchunksize=256k foo.dat > foo.rac -The "400:500" flag value means the 100 bytes ranging from a DSpace offset +The "400..500" flag value means the 100 bytes ranging from a DSpace offset (offset in terms of decompressed bytes, not compressed bytes) of 400 (inclusive) to 500 (exclusive). Either or both bounds may be omitted, similar -to Go slice syntax. A "400:" flag value would mean ranging from 400 (inclusive) -to the end of the decompressed file. +to Rust slice syntax. A "400.." flag value would mean ranging from 400 +(inclusive) to the end of the decompressed file. The "256k" flag value means 256 kibibytes (262144 bytes), as does "256K". Similarly, "1m" and "1M" both mean 1 mebibyte (1048576 bytes). @@ -86,7 +86,7 @@ General Flags: Decode-Related Flags: -drange - the "i:j" range to decompress, ":8" means the first 8 bytes + the "i..j" range to decompress, "..8" means the first 8 bytes -singlethreaded whether to decode on a single execution thread @@ -154,7 +154,7 @@ Extended Example: real 0m0.392s user 0m0.407s sys 0m0.118s - $ time ractool -decode -drange=50000000:50000008 shared.rac + $ time ractool -decode -drange=50000000..50000008 shared.rac Business real 0m0.003s user 0m0.004s diff --git a/cmd/ractool/main.go b/cmd/ractool/main.go index 9c47647e..41d94bec 100644 --- a/cmd/ractool/main.go +++ b/cmd/ractool/main.go @@ -64,15 +64,15 @@ or temporary disk space. Examples: ractool -decode foo.rac | sha256sum - ractool -decode -drange=400:500 foo.rac + ractool -decode -drange=400..500 foo.rac ractool -encode foo.dat > foo.rac ractool -encode -codec=zlib -dchunksize=256k foo.dat > foo.rac -The "400:500" flag value means the 100 bytes ranging from a DSpace offset +The "400..500" flag value means the 100 bytes ranging from a DSpace offset (offset in terms of decompressed bytes, not compressed bytes) of 400 (inclusive) to 500 (exclusive). Either or both bounds may be omitted, similar -to Go slice syntax. A "400:" flag value would mean ranging from 400 (inclusive) -to the end of the decompressed file. +to Rust slice syntax. A "400.." flag value would mean ranging from 400 +(inclusive) to the end of the decompressed file. The "256k" flag value means 256 kibibytes (262144 bytes), as does "256K". Similarly, "1m" and "1M" both mean 1 mebibyte (1048576 bytes). @@ -87,7 +87,7 @@ General Flags: Decode-Related Flags: -drange - the "i:j" range to decompress, ":8" means the first 8 bytes + the "i..j" range to decompress, "..8" means the first 8 bytes -singlethreaded whether to decode on a single execution thread @@ -155,7 +155,7 @@ Extended Example: real 0m0.392s user 0m0.407s sys 0m0.118s - $ time ractool -decode -drange=50000000:50000008 shared.rac + $ time ractool -decode -drange=50000000..50000008 shared.rac Business real 0m0.003s user 0m0.004s @@ -199,8 +199,8 @@ var ( encodeFlag = flag.Bool("encode", false, "whether to encode the input") // Decode-related flags. - drangeFlag = flag.String("drange", ":", - "the \"i:j\" range to decompress, \":8\" means the first 8 bytes") + drangeFlag = flag.String("drange", "..", + "the \"i..j\" range to decompress, \"..8\" means the first 8 bytes") singlethreadedFlag = flag.Bool("singlethreaded", false, "whether to decode on a single execution thread") @@ -287,11 +287,11 @@ func parseNumber(s string) int64 { return i << shift } -// parseRange parses a string like "1:23", returning i=1 and j=23. Either or +// parseRange parses a string like "1..23", returning i=1 and j=23. Either or // both numbers can be missing, in which case i and/or j will be negative, and // it is up to the caller to interpret that placeholder value meaningfully. func parseRange(s string) (i int64, j int64, ok bool) { - n := strings.IndexByte(s, ':') + n := strings.Index(s, "..") if n < 0 { return 0, 0, false } @@ -302,9 +302,9 @@ func parseRange(s string) (i int64, j int64, ok bool) { return 0, 0, false } - if n+1 >= len(s) { + if n+2 >= len(s) { j = -1 - } else if j = parseNumber(s[n+1:]); j < 0 { + } else if j = parseNumber(s[n+2:]); j < 0 { return 0, 0, false }