summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Sitkevich <1553398+sitkevij@users.noreply.github.com>2020-11-01 10:50:53 -0800
committerGitHub <noreply@github.com>2020-11-01 10:50:53 -0800
commitf031a489a609a225acba421413e785a0a8cc8aac (patch)
tree8b782614bb8775f2d4c9576f1e02fbb5fb985c54
parent3e508eab230297a5b938ccbce7d2cdc5f3b43892 (diff)
parent7346e3eb85424922ccba2df9da12e3ede28ae823 (diff)
Merge pull request #39 from jmg-duarte/master
Add more byte array output formats (Python, Kotlin, Java)
-rw-r--r--README.md31
-rw-r--r--src/lib.rs7
-rw-r--r--src/main.rs4
3 files changed, 37 insertions, 5 deletions
diff --git a/README.md b/README.md
index 927cdc2..08ed55e 100644
--- a/README.md
+++ b/README.md
@@ -95,7 +95,7 @@ If `<USERDIR>/.cargo/bin` is part of the `PATH` environment variable, `hx` shoul
### output arrays in `rust`, `c` or `golang`
-`hx` has a feature which can output the input file bytes as source code arrays.
+`hx` has a feature which can output the input file bytes as source code arrays.
For example:
@@ -126,6 +126,33 @@ a := [3]byte{
}
```
+#### python array: -ap
+
+```sh
+$ hx -ap -c8 tests/files/tiny.txt
+a = [
+ 0x69, 0x6c, 0x0a
+]
+```
+
+#### kotlin array: -ak
+
+```sh
+$ hx -ak -c8 tests/files/tiny.txt
+val a = byteArrayOf(
+ 0x69, 0x6c, 0x0a
+)
+```
+
+#### java array: -aj
+
+```sh
+$ hx -aj -c8 tests/files/tiny.txt
+byte[] a = new byte[]{
+ 0x69, 0x6c, 0x0a
+};
+```
+
## manual
```txt
@@ -141,7 +168,7 @@ FLAGS:
-V, --version Prints version information
OPTIONS:
- -a, --array <array_format> Set source code format output: rust (r), C (c), golang (g) [possible values: r, c, g]
+ -a, --array <array_format> Set source code format output: rust (r), C (c), golang (g), python (p), kotlin (k), java (j) [possible values: r, c, g, p, k, j]
-t, --color <color> Set color tint terminal output. 0 to disable, 1 to enable [possible values: 0, 1]
-c, --cols <columns> Set column length
-f, --format <format> Set format of octet: Octal (o), LowerHex (x), UpperHex (X), Binary (b) [possible
diff --git a/src/lib.rs b/src/lib.rs
index 4002b1e..3504f91 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -381,6 +381,9 @@ pub fn output_array(
"r" => writeln!(locked, "let ARRAY: [u8; {}] = [", page.bytes)?,
"c" => writeln!(locked, "unsigned char ARRAY[{}] = {{", page.bytes)?,
"g" => writeln!(locked, "a := [{}]byte{{", page.bytes)?,
+ "p" => writeln!(locked, "a = [")?,
+ "k" => writeln!(locked, "val a = byteArrayOf(")?,
+ "j" => writeln!(locked, "byte[] a = new byte[]{{")?,
_ => writeln!(locked, "unknown array format")?,
}
let mut i: u64 = 0x0;
@@ -402,8 +405,10 @@ pub fn output_array(
"{}",
match array_format {
"r" => "];",
- "c" => "};",
+ "c" | "j" => "};",
"g" => "}",
+ "p" => "]",
+ "k" => ")",
_ => "unknown array format",
}
)
diff --git a/src/main.rs b/src/main.rs
index 2c19a30..81c003c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -58,8 +58,8 @@ fn main() {
.short("a")
.long(ARG_ARR)
.value_name("array_format")
- .help("Set source code format output: rust (r), C (c), golang (g)")
- .possible_values(&["r", "c", "g"])
+ .help("Set source code format output: rust (r), C (c), golang (g), python (p), kotlin (k), java (j)")
+ .possible_values(&["r", "c", "g", "p", "k", "j"])
.takes_value(true),
)
.arg(