mirror of
https://github.com/AppleCommander/bastools.git
synced 2024-12-28 08:30:42 +00:00
Allow generating to AppleSingle format. #16.
This commit is contained in:
parent
be6670d05a
commit
b9ce5e434d
@ -1,10 +1,10 @@
|
||||
## Overview
|
||||
# Overview
|
||||
|
||||
`st` is a command-line tool to investigate and (ultimately) author shape tables for inclusion in Applesoft programs.
|
||||
|
||||
Samples are extracted from the [original Mouse Maze](https://github.com/a2geek/mouse-maze-2001/tree/master/doc/original), written in 1983.
|
||||
|
||||
## Usage
|
||||
# Usage
|
||||
|
||||
```shell
|
||||
$ st --help
|
||||
@ -54,6 +54,8 @@ Options:
|
||||
-w, --width=<width> Set width (defaults: text=80, image=1024)
|
||||
```
|
||||
|
||||
# Features
|
||||
|
||||
## Text extract
|
||||
|
||||
```shell
|
||||
@ -122,3 +124,21 @@ $ st generate --stdout api/src/test/resources/box-longform.st | st extract --std
|
||||
|.XXX.|
|
||||
+-----+
|
||||
```
|
||||
|
||||
## Generate to AppleSingle
|
||||
|
||||
```shell
|
||||
$ cat api/src/test/resources/box-longform.st | st generate --stdin --stdout --single | asu info --stdin
|
||||
Real Name: SHAPES.BIN
|
||||
ProDOS info:
|
||||
Access: 0xC3
|
||||
File Type: 0x06
|
||||
Auxtype: 0x6000
|
||||
File dates info:
|
||||
Creation: 2018-06-20T01:36:59Z
|
||||
Modification: 2018-06-20T01:36:59Z
|
||||
Access: 2018-06-20T01:36:59Z
|
||||
Backup: 2018-06-20T01:36:59Z
|
||||
Data Fork: Present, 14 bytes
|
||||
Resource Fork: Not present
|
||||
```
|
@ -1,13 +1,18 @@
|
||||
package io.github.applecommander.bastools.tools.st;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import io.github.applecommander.applesingle.AppleSingle;
|
||||
import io.github.applecommander.bastools.api.shapes.ShapeGenerator;
|
||||
import io.github.applecommander.bastools.api.shapes.ShapeTable;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.Help.Visibility;
|
||||
import picocli.CommandLine.Option;
|
||||
import picocli.CommandLine.Parameters;
|
||||
|
||||
@ -16,6 +21,8 @@ import picocli.CommandLine.Parameters;
|
||||
descriptionHeading = "%n",
|
||||
optionListHeading = "%nOptions:%n")
|
||||
public class GenerateCommand implements Callable<Void> {
|
||||
public static final int BIN = 0x06;
|
||||
|
||||
@Option(names = { "-h", "--help" }, description = "Show help for subcommand", usageHelp = true)
|
||||
private boolean helpFlag;
|
||||
|
||||
@ -25,6 +32,15 @@ public class GenerateCommand implements Callable<Void> {
|
||||
@Option(names = "--stdout", description = "Write to stdout")
|
||||
private boolean stdoutFlag;
|
||||
|
||||
@Option(names = "--single", description = "Write to AppleSingle file (requires address, defaults to 0x6000)")
|
||||
private boolean applesingleFlag;
|
||||
|
||||
@Option(names = "--address", description = "Address for AppleSingle file", showDefaultValue = Visibility.ALWAYS)
|
||||
private int address = 0x6000;
|
||||
|
||||
@Option(names = "--name", description = "Filename assign in AppleSingle file", showDefaultValue = Visibility.ALWAYS)
|
||||
private String realName = "SHAPES.BIN";
|
||||
|
||||
@Option(names = { "-o", "--output" }, description = "Write output to file")
|
||||
private Path outputFile;
|
||||
|
||||
@ -37,10 +53,26 @@ public class GenerateCommand implements Callable<Void> {
|
||||
|
||||
ShapeTable st = stdinFlag ? ShapeGenerator.generate(System.in) : ShapeGenerator.generate(inputFile);
|
||||
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
st.write(byteStream);
|
||||
|
||||
if (applesingleFlag) {
|
||||
AppleSingle applesingle = AppleSingle.builder()
|
||||
.realName(realName)
|
||||
.dataFork(byteStream.toByteArray())
|
||||
.auxType(address)
|
||||
.fileType(BIN)
|
||||
.build();
|
||||
byteStream.reset();
|
||||
applesingle.save(byteStream);
|
||||
}
|
||||
|
||||
if (stdoutFlag) {
|
||||
st.write(System.out);
|
||||
System.out.write(byteStream.toByteArray());
|
||||
} else {
|
||||
st.write(outputFile);
|
||||
try (OutputStream outputStream = Files.newOutputStream(outputFile)) {
|
||||
outputStream.write(byteStream.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user