diff options
author | Julian Sitkevich <1553398+sitkevij@users.noreply.github.com> | 2020-11-01 10:50:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-01 10:50:53 -0800 |
commit | f031a489a609a225acba421413e785a0a8cc8aac (patch) | |
tree | 8b782614bb8775f2d4c9576f1e02fbb5fb985c54 | |
parent | 3e508eab230297a5b938ccbce7d2cdc5f3b43892 (diff) | |
parent | 7346e3eb85424922ccba2df9da12e3ede28ae823 (diff) |
Merge pull request #39 from jmg-duarte/master
Add more byte array output formats (Python, Kotlin, Java)
-rw-r--r-- | README.md | 31 | ||||
-rw-r--r-- | src/lib.rs | 7 | ||||
-rw-r--r-- | src/main.rs | 4 |
3 files changed, 37 insertions, 5 deletions
@@ -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 @@ -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( |