Adjusting the filename checks; 'ac' now uses the checks. #59
This commit is contained in:
parent
bc931fdaa0
commit
9d8b4be006
|
@ -172,7 +172,7 @@ public class DosFormatDisk extends FormattedDisk {
|
|||
/**
|
||||
* Create a FileEntry.
|
||||
*/
|
||||
public FileEntry createFile() throws DiskFullException {
|
||||
public DosFileEntry createFile() throws DiskFullException {
|
||||
byte[] vtoc = readVtoc();
|
||||
int track = AppleUtil.getUnsignedByte(vtoc[1]);
|
||||
int sector = AppleUtil.getUnsignedByte(vtoc[2]);
|
||||
|
@ -706,6 +706,9 @@ public class DosFormatDisk extends FormattedDisk {
|
|||
* and trimmed (trailing whitespace may cause confusion).
|
||||
*/
|
||||
public String getSuggestedFilename(String filename) {
|
||||
if (filename.charAt(0) < '@') {
|
||||
filename = "A" + filename;
|
||||
}
|
||||
int len = Math.min(filename.length(), 30);
|
||||
return filename.toUpperCase().substring(0, len).trim();
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ public class PascalFormatDisk extends FormattedDisk {
|
|||
/**
|
||||
* Create a new FileEntry.
|
||||
*/
|
||||
public FileEntry createFile() throws DiskFullException {
|
||||
public PascalFileEntry createFile() throws DiskFullException {
|
||||
// find index of largest free space
|
||||
int count = 0; int index = 0; int max = 0;
|
||||
int last = 0; int first = 0; int free = 0;
|
||||
|
@ -574,24 +574,28 @@ public class PascalFormatDisk extends FormattedDisk {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a valid filename for the given filename. This is somewhat
|
||||
* of a guess, but the Pascal filenames appear to have similar
|
||||
* restrictions as ProDOS.
|
||||
* Returns a valid filename for the given filename.
|
||||
* <p/>
|
||||
* Summary taken from the filename description in "Apple Pascal:
|
||||
* Operating System Reference Manual."
|
||||
* <p/>
|
||||
* A legal diskette filename can consist of up to 15 characters.
|
||||
* Lower- case letters typed into a filename are translated to upper-case,
|
||||
* and spaces and non-printing characters are removed from the filename.
|
||||
* All characters are legal in filenames. However, from the keyboard you should
|
||||
* not type filenames that include the following characters:
|
||||
* dollar sign ($), left square bracket ([), equals sign (=) question mark, (?),
|
||||
* RETURN, and the CTRL characters C, F, M, S, U, and @.
|
||||
* <p/>
|
||||
* WARNING: The Filer will not be able to access filenames containing the
|
||||
* characters dollar sign ($), equals sign (=), question mark (?),
|
||||
* or comma (,)
|
||||
*/
|
||||
public String getSuggestedFilename(String filename) {
|
||||
StringBuffer newName = new StringBuffer();
|
||||
if (!Character.isLetter(filename.charAt(0))) {
|
||||
newName.append('A');
|
||||
}
|
||||
int i=0;
|
||||
while (newName.length() < 15 && i<filename.length()) {
|
||||
char ch = filename.charAt(i);
|
||||
if (Character.isLetterOrDigit(ch) || ch == '.') {
|
||||
newName.append(ch);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return newName.toString().toUpperCase().trim();
|
||||
String name = filename.toUpperCase()
|
||||
.replaceAll("[ \t\r\n]", "")
|
||||
.replaceAll("[^A-Z0-9.]", ".");
|
||||
return name.substring(0, Math.min(name.length(),15));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -197,7 +197,7 @@ public class ProdosFormatDisk extends FormattedDisk {
|
|||
/**
|
||||
* Create a FileEntry in the Volume Directory.
|
||||
*/
|
||||
public FileEntry createFile() throws DiskFullException {
|
||||
public ProdosFileEntry createFile() throws DiskFullException {
|
||||
return createFile(volumeHeader);
|
||||
}
|
||||
|
||||
|
@ -1229,8 +1229,10 @@ public class ProdosFormatDisk extends FormattedDisk {
|
|||
int i=0;
|
||||
while (newName.length() < 15 && i<filename.length()) {
|
||||
char ch = filename.charAt(i);
|
||||
if (Character.isLetterOrDigit(ch) || ch == '.') {
|
||||
if (Character.isLetterOrDigit(ch)) {
|
||||
newName.append(ch);
|
||||
} else {
|
||||
newName.append('.');
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -227,7 +227,7 @@ public class ac {
|
|||
FileEntry entry = name.createEntry(formattedDisk);
|
||||
if (entry != null) {
|
||||
entry.setFiletype(fileType);
|
||||
entry.setFilename(name.name);
|
||||
entry.setFilename(formattedDisk.getSuggestedFilename(name.name));
|
||||
entry.setFileData(data);
|
||||
if (entry.needsAddress()) {
|
||||
entry.setAddress(config.startAddress);
|
||||
|
@ -260,7 +260,7 @@ public class ac {
|
|||
FileEntry entry = name.createEntry(formattedDisk);
|
||||
if (entry != null) {
|
||||
entry.setFiletype(fileType);
|
||||
entry.setFilename(name.name);
|
||||
entry.setFilename(formattedDisk.getSuggestedFilename(name.name));
|
||||
entry.setFileData(buf.toByteArray());
|
||||
if (entry.needsAddress()) {
|
||||
entry.setAddress(stringToInt(address));
|
||||
|
@ -316,7 +316,7 @@ public class ac {
|
|||
FileEntry entry = name.createEntry(formattedDisk);
|
||||
if (entry != null) {
|
||||
entry.setFiletype(fileType);
|
||||
entry.setFilename(name.name);
|
||||
entry.setFilename(formattedDisk.getSuggestedFilename(name.name));
|
||||
entry.setFileData(buf.toByteArray());
|
||||
if (entry.needsAddress()) {
|
||||
entry.setAddress(stringToInt(address));
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.webcodepro.applecommander.storage.os.dos33;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.webcodepro.applecommander.storage.Disk;
|
||||
import com.webcodepro.applecommander.storage.DiskFullException;
|
||||
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
|
||||
import com.webcodepro.applecommander.storage.physical.DosOrder;
|
||||
import com.webcodepro.applecommander.storage.physical.ImageOrder;
|
||||
|
||||
public class DosFormatDiskTest {
|
||||
@Test
|
||||
public void testSanitizeFilename() throws DiskFullException {
|
||||
ByteArrayImageLayout layout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
|
||||
ImageOrder order = new DosOrder(layout);
|
||||
DosFormatDisk[] disks = DosFormatDisk.create("deleteme.do", order);
|
||||
DosFormatDisk disk = disks[0];
|
||||
|
||||
assertEquals("FILENAME", disk.getSuggestedFilename("FileName"));
|
||||
assertEquals("A2021", disk.getSuggestedFilename("2021"));
|
||||
assertEquals("A..", disk.getSuggestedFilename(".."));
|
||||
assertEquals("THE FILE NAME", disk.getSuggestedFilename("The File Name"));
|
||||
assertEquals("A\t HIDDEN TAB", disk.getSuggestedFilename("\t hidden tab"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.webcodepro.applecommander.storage.os.pascal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.webcodepro.applecommander.storage.Disk;
|
||||
import com.webcodepro.applecommander.storage.DiskFullException;
|
||||
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
|
||||
import com.webcodepro.applecommander.storage.physical.ImageOrder;
|
||||
import com.webcodepro.applecommander.storage.physical.ProdosOrder;
|
||||
|
||||
public class PascalFormatDiskTest {
|
||||
@Test
|
||||
public void testSanitizeFilename() throws DiskFullException {
|
||||
ByteArrayImageLayout layout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
|
||||
ImageOrder order = new ProdosOrder(layout);
|
||||
PascalFormatDisk[] disks = PascalFormatDisk.create("deleteme.po", "TEST", order);
|
||||
PascalFormatDisk disk = disks[0];
|
||||
|
||||
assertEquals("FILENAME", disk.getSuggestedFilename("FileName"));
|
||||
assertEquals("2021", disk.getSuggestedFilename("2021"));
|
||||
assertEquals("..", disk.getSuggestedFilename(".."));
|
||||
assertEquals("THEFILENAME", disk.getSuggestedFilename("The File Name"));
|
||||
assertEquals("HIDDENTAB", disk.getSuggestedFilename("\t hidden tab"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.webcodepro.applecommander.storage.os.prodos;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.webcodepro.applecommander.storage.Disk;
|
||||
import com.webcodepro.applecommander.storage.DiskFullException;
|
||||
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
|
||||
import com.webcodepro.applecommander.storage.physical.ImageOrder;
|
||||
import com.webcodepro.applecommander.storage.physical.ProdosOrder;
|
||||
|
||||
public class ProdosFormatDiskTest {
|
||||
@Test
|
||||
public void testSanitizeFilename() throws DiskFullException {
|
||||
ByteArrayImageLayout layout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
|
||||
ImageOrder order = new ProdosOrder(layout);
|
||||
ProdosFormatDisk[] disks = ProdosFormatDisk.create("deleteme.po", "nothere", order);
|
||||
ProdosFormatDisk disk = disks[0];
|
||||
|
||||
assertEquals("FILENAME", disk.getSuggestedFilename("FileName"));
|
||||
assertEquals("A2021", disk.getSuggestedFilename("2021"));
|
||||
assertEquals("A..", disk.getSuggestedFilename(".."));
|
||||
assertEquals("THE.FILE.NAME", disk.getSuggestedFilename("The File Name"));
|
||||
assertEquals("A..HIDDEN.TAB", disk.getSuggestedFilename("\t hidden tab"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue