diff --git a/.gitignore b/.gitignore
index e9a6a76..d444b80 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
/.project
pom.xml.versionsBackup
*.bin
+*.dsk
diff --git a/pom.xml b/pom.xml
index 0552902..10d1133 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,9 +12,9 @@
1.8
1.8
- UTF-8
- yyyy-MM-dd HH:mm
- ${maven.build.timestamp}
+ UTF-8
+ yyyy-MM-dd HH:mm
+ ${maven.build.timestamp}
@@ -23,27 +23,32 @@
picocli
[3.0,3.1)
+
+ net.sf.applecommander
+ applesingle-api
+ 1.0.0
+
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- 3.0.2
-
-
-
- true
- true
- false
-
-
- ${project.version} (${timestamp})
-
-
-
-
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.0.2
+
+
+
+ true
+ true
+ false
+
+
+ ${project.version} (${timestamp})
+
+
+
+
org.springframework.boot
spring-boot-maven-plugin
diff --git a/src/main/java/io/github/applecommander/bastokenizer/Main.java b/src/main/java/io/github/applecommander/bastokenizer/Main.java
index f4ab9c9..f029311 100644
--- a/src/main/java/io/github/applecommander/bastokenizer/Main.java
+++ b/src/main/java/io/github/applecommander/bastokenizer/Main.java
@@ -21,6 +21,7 @@ import com.webcodepro.applecommander.util.applesoft.TokenReader;
import com.webcodepro.applecommander.util.applesoft.Visitors;
import com.webcodepro.applecommander.util.applesoft.Visitors.ByteVisitor;
+import io.github.applecommander.applesingle.AppleSingle;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Help.Visibility;
@@ -30,10 +31,14 @@ import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
/** A command-line interface to the AppleSoft BAS tokenizer libraries. */
-@Command(description = "Transforms an AppleSoft program from text back to it's tokenized state.",
+@Command(description = "Transforms an AppleSoft program from text back to its tokenized state.",
+ descriptionHeading = "%n",
+ commandListHeading = "%nCommands:%n",
+ optionListHeading = "%nOptions:%n",
name = "bt", mixinStandardHelpOptions = true,
versionProvider = Main.VersionProvider.class)
public class Main implements Callable {
+ private static final int BAS = 0xfc;
public static Configuration configuration = new Configuration();
@Option(names = { "-o", "--output" }, description = "Write binary output to file.")
@@ -51,8 +56,11 @@ public class Main implements Callable {
@Option(names = { "--variables" }, description = "Generate a variable report")
boolean showVariableReport;
- @Option(names = { "-p", "--pipe" }, description = "Pipe binary output to stdout.")
- boolean pipeOutput;
+ @Option(names = "--stdout", description = "Send binary output to stdout.")
+ boolean stdoutFlag;
+
+ @Option(names = "--applesingle", description = "Write output in AppleSingle format")
+ boolean applesingleFlag;
@Option(names = "--pretty", description = "Pretty print structure as bastokenizer understands it.")
boolean prettyPrint;
@@ -116,10 +124,10 @@ public class Main implements Callable {
}
boolean hasTextOutput = hexFormat || copyFormat || prettyPrint || listPrint || showTokens || showVariableReport
|| debugFlag || showLineAddresses;
- if (pipeOutput && hasTextOutput) {
+ if (stdoutFlag && hasTextOutput) {
System.err.println("The pipe option blocks any other stdout options.");
return false;
- } else if (!(pipeOutput || hasTextOutput || outputFile != null)) {
+ } else if (!(stdoutFlag || hasTextOutput || outputFile != null)) {
System.err.println("What do you want to do?");
return false;
}
@@ -149,20 +157,51 @@ public class Main implements Callable {
ByteVisitor byteVisitor = Visitors.byteVisitor(address);
byte[] data = byteVisitor.dump(program);
+ if (showLineAddresses) {
+ byteVisitor.getLineAddresses().forEach((l,a) -> System.out.printf("%5d ... $%04x\n", l, a));
+ }
if (hexFormat) {
HexDumper.standard().dump(address, data);
}
if (copyFormat) {
HexDumper.apple2().dump(address, data);
}
- if (outputFile != null) {
- Files.write(outputFile.toPath(), data);
- }
- if (showLineAddresses) {
- byteVisitor.getLineAddresses().forEach((l,a) -> System.out.printf("%5d ... $%04x\n", l, a));
- }
- if (pipeOutput) {
- System.out.write(data);
+
+ saveResults(data);
+ }
+
+ public void saveResults(byte[] data) throws IOException {
+ if (applesingleFlag) {
+ String realName = null;
+ if (sourceFile != null) {
+ realName = sourceFile.getName().toUpperCase();
+ } else if (outputFile != null) {
+ realName = outputFile.getName().toUpperCase();
+ } else {
+ realName = "UNKNOWN";
+ }
+ if (realName.endsWith(".BAS")) {
+ realName = realName.substring(0, realName.length()-4);
+ }
+ AppleSingle as = AppleSingle.builder()
+ .auxType(address)
+ .fileType(BAS)
+ .dataFork(data)
+ .realName(realName)
+ .build();
+ if (outputFile != null) {
+ as.save(outputFile);
+ }
+ if (stdoutFlag) {
+ as.save(System.out);
+ }
+ } else {
+ if (outputFile != null) {
+ Files.write(outputFile.toPath(), data);
+ }
+ if (stdoutFlag) {
+ System.out.write(data);
+ }
}
}