mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-02-18 05:30:29 +00:00
align text records
This commit is contained in:
parent
030121f12c
commit
d97ba0393b
@ -248,7 +248,7 @@ public class IntegerBasicProgram extends AbstractFile
|
|||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* To find integer basic in memory:
|
* To find integer basic in memory:
|
||||||
* $CA $CB contain the starting address
|
* $CA $CB contain the starting address ($9464)
|
||||||
* http://www.easy68k.com/paulrsm/6502/INTLST.TXT
|
* http://www.easy68k.com/paulrsm/6502/INTLST.TXT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -5,39 +5,44 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
|
|||||||
// only used by Prodos text files - note the fixed block size of 512 - bad!
|
// only used by Prodos text files - note the fixed block size of 512 - bad!
|
||||||
public class TextBuffer
|
public class TextBuffer
|
||||||
{
|
{
|
||||||
public final byte[] buffer;
|
public final byte[] buffer;
|
||||||
public final int reclen;
|
public final int reclen;
|
||||||
public final int firstRecNo;
|
public final int firstRecNo;
|
||||||
|
|
||||||
public TextBuffer (byte[] tempBuffer, int reclen, int firstBlock)
|
public TextBuffer (byte[] tempBuffer, int reclen, int firstBlock)
|
||||||
{
|
{
|
||||||
this.reclen = reclen;
|
this.reclen = reclen;
|
||||||
|
|
||||||
// calculate recNo of first full record
|
// calculate recNo of first full record
|
||||||
int firstByte = firstBlock * 512; // logical byte #
|
int firstByte = firstBlock * 512; // logical byte #
|
||||||
int rem = firstByte % reclen;
|
int rem = firstByte % reclen;
|
||||||
firstRecNo = firstByte / reclen + (rem > 0 ? 1 : 0);
|
firstRecNo = firstByte / reclen + (rem > 0 ? 1 : 0);
|
||||||
int offset = (rem > 0) ? reclen - rem : 0;
|
int offset = (rem > 0) ? reclen - rem : 0;
|
||||||
|
|
||||||
int availableBytes = tempBuffer.length - offset;
|
int availableBytes = tempBuffer.length - offset;
|
||||||
int totalRecords = (availableBytes - 1) / reclen + 1;
|
int totalRecords = (availableBytes - 1) / reclen + 1;
|
||||||
|
|
||||||
// should check whether the two buffers are identical, and maybe skip this
|
// should check whether the two buffers are identical, and maybe skip this
|
||||||
// step
|
// step
|
||||||
buffer = new byte[totalRecords * reclen];
|
buffer = new byte[totalRecords * reclen];
|
||||||
int copyBytes = Math.min (availableBytes, buffer.length);
|
int copyBytes = Math.min (availableBytes, buffer.length);
|
||||||
System.arraycopy (tempBuffer, offset, buffer, 0, copyBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (copyBytes < 0)
|
||||||
public String toString ()
|
System.out.printf ("offset %d len %d copy %d%n", offset, buffer.length,
|
||||||
{
|
copyBytes);
|
||||||
StringBuilder text = new StringBuilder ();
|
else
|
||||||
|
System.arraycopy (tempBuffer, offset, buffer, 0, copyBytes);
|
||||||
|
}
|
||||||
|
|
||||||
text.append ("Record length : " + reclen + "\n");
|
@Override
|
||||||
text.append ("First record : " + firstRecNo + "\n\n");
|
public String toString ()
|
||||||
text.append (HexFormatter.format (buffer, 0, buffer.length) + "\n");
|
{
|
||||||
|
StringBuilder text = new StringBuilder ();
|
||||||
|
|
||||||
return text.toString ();
|
text.append ("Record length : " + reclen + "\n");
|
||||||
}
|
text.append ("First record : " + firstRecNo + "\n\n");
|
||||||
|
text.append (HexFormatter.format (buffer, 0, buffer.length) + "\n");
|
||||||
|
|
||||||
|
return text.toString ();
|
||||||
|
}
|
||||||
}
|
}
|
@ -88,7 +88,7 @@ public class TextFile extends AbstractFile
|
|||||||
for (TextBuffer tb : buffers)
|
for (TextBuffer tb : buffers)
|
||||||
{
|
{
|
||||||
buffer = tb.buffer;
|
buffer = tb.buffer;
|
||||||
knownLength (text, tb.firstRecNo);
|
text = knownLength (text, tb.firstRecNo);
|
||||||
}
|
}
|
||||||
return text.toString ();
|
return text.toString ();
|
||||||
}
|
}
|
||||||
@ -102,6 +102,7 @@ public class TextFile extends AbstractFile
|
|||||||
recNo++;
|
recNo++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = buffer.length - ptr;
|
int len = buffer.length - ptr;
|
||||||
int bytes = len < recordLength ? len : recordLength;
|
int bytes = len < recordLength ? len : recordLength;
|
||||||
|
|
||||||
@ -111,9 +112,12 @@ public class TextFile extends AbstractFile
|
|||||||
if ((buffer[ptr + bytes - 1] & 0x7F) == 0x0D) // ignore CR
|
if ((buffer[ptr + bytes - 1] & 0x7F) == 0x0D) // ignore CR
|
||||||
bytes--;
|
bytes--;
|
||||||
|
|
||||||
text.append (String.format ("%,10d %,8d %s%n", recNo * recordLength, recNo++,
|
String line = HexFormatter.getString (buffer, ptr, bytes);
|
||||||
HexFormatter.getString (buffer, ptr, bytes)));
|
line = line.replaceAll ("\\n", "\n ");
|
||||||
|
text.append (
|
||||||
|
String.format ("%,10d %,8d %s%n", recNo * recordLength, recNo++, line));
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user