From 81656bc9b817440f79da5ec15de04e7947a59a9a Mon Sep 17 00:00:00 2001 From: Rob Greene Date: Sat, 26 May 2018 17:39:25 -0500 Subject: [PATCH] Tweaking to allow some useful filetype mnemonics. --- tools/asu/README.md | 4 +-- .../applesingle/tools/asu/CreateCommand.java | 2 +- .../tools/asu/ProdosFileTypeConverter.java | 28 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tools/asu/src/main/java/io/github/applecommander/applesingle/tools/asu/ProdosFileTypeConverter.java diff --git a/tools/asu/README.md b/tools/asu/README.md index 860899c..de62113 100644 --- a/tools/asu/README.md +++ b/tools/asu/README.md @@ -75,7 +75,7 @@ Resource Fork: Not present The `--fix-text` flag flips the high-bit and translates the newline character: ```shell -$ echo "Hello World!" | asu create --name my-text-file --stdout --filetype 0x04 --stdin-fork=data --fix-text | hexdump -C +$ echo "Hello World!" | asu create --name my-text-file --stdout --filetype txt --stdin-fork=data --fix-text | hexdump -C 00000000 00 05 16 00 00 02 00 00 00 00 00 00 00 00 00 00 |................| 00000010 00 00 00 00 00 00 00 00 00 03 00 00 00 03 00 00 |................| 00000020 00 3e 00 00 00 0c 00 00 00 0b 00 00 00 4a 00 00 |.>...........J..| @@ -89,7 +89,7 @@ $ echo "Hello World!" | asu create --name my-text-file --stdout --filetype 0x04 Without the `--fix-text` flag: ```shell -$ echo "Hello World!" | asu create --name my-text-file --stdout --filetype 0x04 --stdin-fork=data | hexdump -C +$ echo "Hello World!" | asu create --name my-text-file --stdout --filetype txt --stdin-fork=data | hexdump -C 00000000 00 05 16 00 00 02 00 00 00 00 00 00 00 00 00 00 |................| 00000010 00 00 00 00 00 00 00 00 00 03 00 00 00 03 00 00 |................| 00000020 00 3e 00 00 00 0c 00 00 00 0b 00 00 00 4a 00 00 |.>...........J..| diff --git a/tools/asu/src/main/java/io/github/applecommander/applesingle/tools/asu/CreateCommand.java b/tools/asu/src/main/java/io/github/applecommander/applesingle/tools/asu/CreateCommand.java index 556dc32..d9026a3 100644 --- a/tools/asu/src/main/java/io/github/applecommander/applesingle/tools/asu/CreateCommand.java +++ b/tools/asu/src/main/java/io/github/applecommander/applesingle/tools/asu/CreateCommand.java @@ -42,7 +42,7 @@ public class CreateCommand implements Callable { @Option(names = "--access", description = "Set the ProDOS access flags", converter = IntegerTypeConverter.class) private Integer access; - @Option(names = "--filetype", description = "Set the ProDOS file type", converter = IntegerTypeConverter.class) + @Option(names = "--filetype", description = "Set the ProDOS file type (also accepts BIN/BAS/SYS)", converter = ProdosFileTypeConverter.class) private Integer filetype; @Option(names = "--auxtype", description = "Set the ProDOS auxtype", converter = IntegerTypeConverter.class) diff --git a/tools/asu/src/main/java/io/github/applecommander/applesingle/tools/asu/ProdosFileTypeConverter.java b/tools/asu/src/main/java/io/github/applecommander/applesingle/tools/asu/ProdosFileTypeConverter.java new file mode 100644 index 0000000..44ccd84 --- /dev/null +++ b/tools/asu/src/main/java/io/github/applecommander/applesingle/tools/asu/ProdosFileTypeConverter.java @@ -0,0 +1,28 @@ +package io.github.applecommander.applesingle.tools.asu; + +import java.util.HashMap; +import java.util.Map; + +import picocli.CommandLine.ITypeConverter; + +/** Add support for the more common ProDOS file type strings as well as integers. */ +public class ProdosFileTypeConverter extends IntegerTypeConverter implements ITypeConverter { + private final Map fileTypes = new HashMap() { + private static final long serialVersionUID = 1812781095833750521L; + { + put("TXT", "$04"); + put("BIN", "$06"); + put("INT", "$fa"); + put("BAS", "$fc"); + put("REL", "$fe"); + put("SYS", "$ff"); + } + }; + + @Override + public Integer convert(String value) { + // If we find the string in our map, swap it for the correct hex string. + // Else just pass in the original value. + return super.convert(fileTypes.getOrDefault(value.toUpperCase(), value)); + } +}