Pulling in AppleSingle library. Closes #14.

This commit is contained in:
Rob Greene 2018-05-26 22:13:58 -05:00
parent 56b3af7a44
commit d93bc82b7b
3 changed files with 79 additions and 34 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
/.project
pom.xml.versionsBackup
*.bin
*.dsk

47
pom.xml
View File

@ -12,9 +12,9 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
<timestamp>${maven.build.timestamp}</timestamp>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
<timestamp>${maven.build.timestamp}</timestamp>
</properties>
<dependencies>
@ -23,27 +23,32 @@
<artifactId>picocli</artifactId>
<version>[3.0,3.1)</version>
</dependency>
<dependency>
<groupId>net.sf.applecommander</groupId>
<artifactId>applesingle-api</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
<manifestEntries>
<Implementation-Version>${project.version} (${timestamp})</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
<manifestEntries>
<Implementation-Version>${project.version} (${timestamp})</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>

View File

@ -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<Void> {
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<Void> {
@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<Void> {
}
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<Void> {
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);
}
}
}