From bc0993e9d3d247888cefb41466e73171fe656aab Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Thu, 15 Dec 2022 20:35:26 +1000 Subject: [PATCH] better pascal TEXT handling --- .../diskbrowser/applefile/PascalText.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/PascalText.java b/src/com/bytezone/diskbrowser/applefile/PascalText.java index 89c8d6d..699b2b6 100755 --- a/src/com/bytezone/diskbrowser/applefile/PascalText.java +++ b/src/com/bytezone/diskbrowser/applefile/PascalText.java @@ -4,6 +4,8 @@ package com.bytezone.diskbrowser.applefile; public class PascalText extends TextFile // -----------------------------------------------------------------------------------// { + private final static int PAGE_SIZE = 1024; + // ---------------------------------------------------------------------------------// public PascalText (String name, byte[] buffer) // ---------------------------------------------------------------------------------// @@ -16,28 +18,34 @@ public class PascalText extends TextFile public String getText () // ---------------------------------------------------------------------------------// { + // Text files are broken up into 1024-byte pages. + // [DLE] [indent] [text] [CR] ... [nulls] + StringBuilder text = new StringBuilder (getHeader ()); - int ptr = 0x400; + int ptr = PAGE_SIZE; // skip text editor header + while (ptr < buffer.length) { - if (buffer[ptr] == 0x00) + if (buffer[ptr] == 0x00) // padding to page boundary { - ++ptr; + ptr = (ptr / PAGE_SIZE + 1) * PAGE_SIZE; // skip to next page continue; } - if (buffer[ptr] == 0x10) + if (buffer[ptr] == 0x10) // Data Link Escape code { - int tab = buffer[ptr + 1] - 0x20; + int tab = (buffer[ptr + 1] & 0xFF) - 32; // indent amaount while (tab-- > 0) text.append (" "); ptr += 2; } - String line = getLine (ptr); - text.append (line + "\n"); - ptr += line.length () + 1; + while (buffer[ptr] != 0x0D) + text.append ((char) buffer[ptr++]); + + text.append ("\n"); + ptr++; } if (text.length () > 0) @@ -45,16 +53,4 @@ public class PascalText extends TextFile return text.toString (); } - - // ---------------------------------------------------------------------------------// - private String getLine (int ptr) - // ---------------------------------------------------------------------------------// - { - StringBuilder line = new StringBuilder (); - - while (buffer[ptr] != 0x0D) - line.append ((char) buffer[ptr++]); - - return line.toString (); - } } \ No newline at end of file