dmolony-DiskBrowser/src/com/bytezone/diskbrowser/applefile/PascalText.java

56 lines
1.7 KiB
Java
Raw Normal View History

2020-02-07 11:52:46 +00:00
package com.bytezone.diskbrowser.applefile;
// -----------------------------------------------------------------------------------//
2020-09-14 09:51:14 +00:00
public class PascalText extends TextFile
2020-02-07 11:52:46 +00:00
// -----------------------------------------------------------------------------------//
{
2022-12-15 10:35:26 +00:00
private final static int PAGE_SIZE = 1024;
2020-02-07 11:52:46 +00:00
// ---------------------------------------------------------------------------------//
public PascalText (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{
super (name, buffer);
}
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
2022-12-15 10:35:26 +00:00
// Text files are broken up into 1024-byte pages.
// [DLE] [indent] [text] [CR] ... [nulls]
2020-02-07 11:52:46 +00:00
StringBuilder text = new StringBuilder (getHeader ());
2022-12-15 10:35:26 +00:00
int ptr = PAGE_SIZE; // skip text editor header
2020-02-07 11:52:46 +00:00
while (ptr < buffer.length)
{
2022-12-15 10:35:26 +00:00
if (buffer[ptr] == 0x00) // padding to page boundary
2020-02-07 11:52:46 +00:00
{
2022-12-15 10:35:26 +00:00
ptr = (ptr / PAGE_SIZE + 1) * PAGE_SIZE; // skip to next page
2020-02-07 11:52:46 +00:00
continue;
}
2021-06-18 00:48:38 +00:00
2022-12-15 10:35:26 +00:00
if (buffer[ptr] == 0x10) // Data Link Escape code
2020-02-07 11:52:46 +00:00
{
2022-12-15 10:35:26 +00:00
int tab = (buffer[ptr + 1] & 0xFF) - 32; // indent amaount
2020-02-07 11:52:46 +00:00
while (tab-- > 0)
text.append (" ");
ptr += 2;
}
2021-06-18 00:48:38 +00:00
2022-12-15 10:35:26 +00:00
while (buffer[ptr] != 0x0D)
text.append ((char) buffer[ptr++]);
text.append ("\n");
ptr++;
2020-02-07 11:52:46 +00:00
}
if (text.length () > 0)
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
2015-06-01 09:35:51 +00:00
}