Allow generating to AppleSingle format. #16.

This commit is contained in:
Rob Greene 2018-06-19 20:39:39 -05:00
parent be6670d05a
commit b9ce5e434d
2 changed files with 58 additions and 6 deletions

View File

@ -1,10 +1,10 @@
## Overview # Overview
`st` is a command-line tool to investigate and (ultimately) author shape tables for inclusion in Applesoft programs. `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. 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 ```shell
$ st --help $ st --help
@ -54,6 +54,8 @@ Options:
-w, --width=<width> Set width (defaults: text=80, image=1024) -w, --width=<width> Set width (defaults: text=80, image=1024)
``` ```
# Features
## Text extract ## Text extract
```shell ```shell
@ -122,3 +124,21 @@ $ st generate --stdout api/src/test/resources/box-longform.st | st extract --std
|.XXX.| |.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
```

View File

@ -1,13 +1,18 @@
package io.github.applecommander.bastools.tools.st; package io.github.applecommander.bastools.tools.st;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.concurrent.Callable; 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.ShapeGenerator;
import io.github.applecommander.bastools.api.shapes.ShapeTable; import io.github.applecommander.bastools.api.shapes.ShapeTable;
import picocli.CommandLine.Command; import picocli.CommandLine.Command;
import picocli.CommandLine.Help.Visibility;
import picocli.CommandLine.Option; import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters; import picocli.CommandLine.Parameters;
@ -16,6 +21,8 @@ import picocli.CommandLine.Parameters;
descriptionHeading = "%n", descriptionHeading = "%n",
optionListHeading = "%nOptions:%n") optionListHeading = "%nOptions:%n")
public class GenerateCommand implements Callable<Void> { public class GenerateCommand implements Callable<Void> {
public static final int BIN = 0x06;
@Option(names = { "-h", "--help" }, description = "Show help for subcommand", usageHelp = true) @Option(names = { "-h", "--help" }, description = "Show help for subcommand", usageHelp = true)
private boolean helpFlag; private boolean helpFlag;
@ -24,23 +31,48 @@ public class GenerateCommand implements Callable<Void> {
@Option(names = "--stdout", description = "Write to stdout") @Option(names = "--stdout", description = "Write to stdout")
private boolean stdoutFlag; 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") @Option(names = { "-o", "--output" }, description = "Write output to file")
private Path outputFile; private Path outputFile;
@Parameters(arity = "0..1", description = "File to process") @Parameters(arity = "0..1", description = "File to process")
private Path inputFile; private Path inputFile;
@Override @Override
public Void call() throws IOException { public Void call() throws IOException {
validateArguments(); validateArguments();
ShapeTable st = stdinFlag ? ShapeGenerator.generate(System.in) : ShapeGenerator.generate(inputFile); 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) { if (stdoutFlag) {
st.write(System.out); System.out.write(byteStream.toByteArray());
} else { } else {
st.write(outputFile); try (OutputStream outputStream = Files.newOutputStream(outputFile)) {
outputStream.write(byteStream.toByteArray());
}
} }
return null; return null;