method header lines

This commit is contained in:
Denis Molony 2020-02-08 17:50:03 +10:00
parent 09965c02aa
commit 4788f4bca4
14 changed files with 348 additions and 239 deletions

View File

@ -6,7 +6,9 @@ import java.util.List;
import com.bytezone.diskbrowser.applefile.AbstractFile; import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class AppleworksADBFile extends AbstractFile public class AppleworksADBFile extends AbstractFile
// -----------------------------------------------------------------------------------//
{ {
static final String line = "-------------------------------------------------------" static final String line = "-------------------------------------------------------"
+ "-----------------------------------\n"; + "-----------------------------------\n";
@ -42,7 +44,9 @@ public class AppleworksADBFile extends AbstractFile
final List<Record> records = new ArrayList<> (); final List<Record> records = new ArrayList<> ();
private final Record standardRecord; private final Record standardRecord;
// ---------------------------------------------------------------------------------//
public AppleworksADBFile (String name, byte[] buffer) public AppleworksADBFile (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
super (name, buffer); super (name, buffer);
@ -125,8 +129,10 @@ public class AppleworksADBFile extends AbstractFile
} }
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
@ -179,7 +185,9 @@ public class AppleworksADBFile extends AbstractFile
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
private void removeTrailing (StringBuilder text, char c) private void removeTrailing (StringBuilder text, char c)
// ---------------------------------------------------------------------------------//
{ {
while (text.charAt (text.length () - 1) == c) while (text.charAt (text.length () - 1) == c)
text.deleteCharAt (text.length () - 1); text.deleteCharAt (text.length () - 1);

View File

@ -6,12 +6,16 @@ import java.util.List;
import com.bytezone.diskbrowser.applefile.AbstractFile; import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class AppleworksSSFile extends AbstractFile public class AppleworksSSFile extends AbstractFile
// -----------------------------------------------------------------------------------//
{ {
Header header; Header header;
List<Row> rows = new ArrayList<> (); List<Row> rows = new ArrayList<> ();
// ---------------------------------------------------------------------------------//
public AppleworksSSFile (String name, byte[] buffer) public AppleworksSSFile (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{ {
super (name, buffer); super (name, buffer);
@ -32,8 +36,10 @@ public class AppleworksSSFile extends AbstractFile
} }
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (header.toString ()); StringBuilder text = new StringBuilder (header.toString ());
@ -47,14 +53,18 @@ public class AppleworksSSFile extends AbstractFile
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
static String getCellName (int row, int column) static String getCellName (int row, int column)
// ---------------------------------------------------------------------------------//
{ {
char c1 = (char) ('A' + column / 26 - 1); char c1 = (char) ('A' + column / 26 - 1);
char c2 = (char) ('A' + column % 26); char c2 = (char) ('A' + column % 26);
return "" + (c1 == '@' ? "" : c1) + c2 + row; return "" + (c1 == '@' ? "" : c1) + c2 + row;
} }
// ---------------------------------------------------------------------------------//
private class Header private class Header
// ---------------------------------------------------------------------------------//
{ {
private final int[] columnWidths = new int[127]; private final int[] columnWidths = new int[127];
private final char calcOrder; private final char calcOrder;
@ -245,7 +255,9 @@ public class AppleworksSSFile extends AbstractFile
} }
} }
// ---------------------------------------------------------------------------------//
private class Row private class Row
// ---------------------------------------------------------------------------------//
{ {
private final int rowNumber; private final int rowNumber;
private final List<Cell> cells = new ArrayList<> (); private final List<Cell> cells = new ArrayList<> ();

View File

@ -1,195 +1,202 @@
package com.bytezone.diskbrowser.appleworks; package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.applefile.AbstractFile; import com.bytezone.diskbrowser.applefile.AbstractFile;
public class AppleworksWPFile extends AbstractFile // -----------------------------------------------------------------------------------//
{ public class AppleworksWPFile extends AbstractFile
Header header; // -----------------------------------------------------------------------------------//
{
public AppleworksWPFile (String name, byte[] buffer) Header header;
{
super (name, buffer); // ---------------------------------------------------------------------------------//
public AppleworksWPFile (String name, byte[] buffer)
header = new Header (); // ---------------------------------------------------------------------------------//
} {
super (name, buffer);
@Override
public String getText () header = new Header ();
{ }
int leftMargin = header.leftMargin;
int rightMargin; // ---------------------------------------------------------------------------------//
int topMargin; @Override
int bottomMargin; public String getText ()
int paperLength; // ---------------------------------------------------------------------------------//
int indent; {
int leftMargin = header.leftMargin;
int ptr = 300; // skip the header int rightMargin;
StringBuilder text = new StringBuilder (header.toString ()); int topMargin;
text.append ("\n"); int bottomMargin;
int paperLength;
while (true) int indent;
{
int b1 = buffer[ptr] & 0xFF; int ptr = 300; // skip the header
int b2 = buffer[ptr + 1] & 0xFF; StringBuilder text = new StringBuilder (header.toString ());
// System.out.printf ("%02X%02X %n", (buffer[ptr] & 0xFF), (buffer[ptr + 1] & 0xFF)); text.append ("\n");
if (b1 == 0xFF && b2 == 0xFF) while (true)
break; {
int b1 = buffer[ptr] & 0xFF;
switch (b2) int b2 = buffer[ptr + 1] & 0xFF;
{
case 0: if (b1 == 0xFF && b2 == 0xFF)
int len = b1; break;
int b3 = buffer[ptr + 2] & 0xFF;
int b4 = buffer[ptr + 3] & 0xFF; switch (b2)
{
int lineMargin = b3 & 0x7F; case 0:
boolean containsTabs = (b3 & 0x80) != 0; int len = b1;
int textLen = b4 & 0x7F; int b3 = buffer[ptr + 2] & 0xFF;
boolean cr = (b4 & 0x80) != 0; int b4 = buffer[ptr + 3] & 0xFF;
if (false) int lineMargin = b3 & 0x7F;
System.out.printf ("%02X %02X %d %d %s %s%n", b3, b4, lineMargin, textLen, boolean containsTabs = (b3 & 0x80) != 0;
containsTabs, cr); int textLen = b4 & 0x7F;
if (b3 == 0xFF) boolean cr = (b4 & 0x80) != 0;
text.append ("--------- Ruler ----------\n");
else if (false)
{ System.out.printf ("%02X %02X %d %d %s %s%n", b3, b4, lineMargin, textLen,
// left margin containsTabs, cr);
for (int i = 0; i < leftMargin; i++) if (b3 == 0xFF)
text.append (" "); text.append ("--------- Ruler ----------\n");
for (int i = 0; i < lineMargin; i++) else
text.append (" "); {
// left margin
// check for tabs (I'm guessing about how this works) for (int i = 0; i < leftMargin; i++)
if (false) text.append (" ");
{ for (int i = 0; i < lineMargin; i++)
while (buffer[ptr + 4] == 0x16) // tab character text.append (" ");
{
ptr++; // check for tabs (I'm guessing about how this works)
len--; if (false)
while (buffer[ptr + 4] == 0x17) // tab fill character {
{ while (buffer[ptr + 4] == 0x16) // tab character
text.append (" "); {
ptr++; ptr++;
len--; len--;
} while (buffer[ptr + 4] == 0x17) // tab fill character
} {
text.append (new String (buffer, ptr + 4, len - 2)); text.append (" ");
ptr += len; ptr++;
} len--;
else }
{ }
StringBuilder line = new StringBuilder (); text.append (new String (buffer, ptr + 4, len - 2));
int p = ptr + 4; ptr += len;
ptr += len; }
len -= 2; else
{
while (--len >= 0) StringBuilder line = new StringBuilder ();
{ int p = ptr + 4;
char c = (char) buffer[p++]; ptr += len;
if (c >= 0x20) len -= 2;
line.append (c);
else if (c == 0x17) while (--len >= 0)
line.append (' '); {
} char c = (char) buffer[p++];
if (c >= 0x20)
text.append (line.toString ()); line.append (c);
} else if (c == 0x17)
} line.append (' ');
}
text.append ("\n");
text.append (line.toString ());
if (cr) }
text.append ("\n"); }
break; text.append ("\n");
case 0xD0: if (cr)
text.append ("\n"); text.append ("\n");
break;
break;
case 0xD9:
leftMargin = b1; case 0xD0:
break; text.append ("\n");
break;
case 0xDA:
rightMargin = b1; case 0xD9:
break; leftMargin = b1;
break;
case 0xDE:
indent = b1; case 0xDA:
break; rightMargin = b1;
break;
case 0xE2:
paperLength = b1; case 0xDE:
break; indent = b1;
break;
case 0xE3:
topMargin = b1; case 0xE2:
break; paperLength = b1;
break;
case 0xE4:
bottomMargin = b1; case 0xE3:
break; topMargin = b1;
break;
default:
System.out.printf ("Unknown value in %s: %02X %02X%n", name, b1, b2); case 0xE4:
} bottomMargin = b1;
ptr += 2; break;
}
if (false) default:
System.out.printf ("", leftMargin, rightMargin, topMargin, bottomMargin, System.out.printf ("Unknown value in %s: %02X %02X%n", name, b1, b2);
paperLength, indent); }
return text.toString (); ptr += 2;
} }
if (false)
private class Header System.out.printf ("", leftMargin, rightMargin, topMargin, bottomMargin,
{ paperLength, indent);
private final char[] tabStops = new char[80]; return text.toString ();
private final String tabs; }
private final boolean zoom;
private final boolean paginated; // ---------------------------------------------------------------------------------//
private final int leftMargin; private class Header
private final boolean mailMerge; // ---------------------------------------------------------------------------------//
private final int sfMinVers; {
private final char[] tabStops = new char[80];
private final boolean multipleRulers; private final String tabs;
private final boolean zoom;
public Header () private final boolean paginated;
{ private final int leftMargin;
// see Asimov disks/images 2/pd_collections/apple_linc/ private final boolean mailMerge;
// 1988-02 side A (no boot).dsk private final int sfMinVers;
assert buffer[4] == 0x4F;
private final boolean multipleRulers;
int ptr = 5;
for (int i = 0; i < 80; i++) public Header ()
tabStops[i] = (char) buffer[ptr++]; {
// see Asimov disks/images 2/pd_collections/apple_linc/
tabs = new String (tabStops); // 1988-02 side A (no boot).dsk
zoom = buffer[85] != 0; assert buffer[4] == 0x4F;
paginated = buffer[90] != 0;
leftMargin = buffer[91] & 0xFF; int ptr = 5;
mailMerge = buffer[92] != 0; for (int i = 0; i < 80; i++)
tabStops[i] = (char) buffer[ptr++];
multipleRulers = buffer[176] != 0;
sfMinVers = buffer[183] & 0xFF; tabs = new String (tabStops);
} zoom = buffer[85] != 0;
paginated = buffer[90] != 0;
@Override leftMargin = buffer[91] & 0xFF;
public String toString () mailMerge = buffer[92] != 0;
{
StringBuilder text = new StringBuilder (); multipleRulers = buffer[176] != 0;
sfMinVers = buffer[183] & 0xFF;
text.append (String.format ("Tabs ......... %s %n", tabs)); }
text.append (String.format ("Zoom ......... %s %n", zoom));
text.append (String.format ("Mail merge ... %s %n", mailMerge)); @Override
text.append (String.format ("Left margin .. %d %n", leftMargin)); public String toString ()
text.append (String.format ("Min version .. %d %n", sfMinVers)); {
text.append (String.format ("Mult rulers .. %s %n", multipleRulers)); StringBuilder text = new StringBuilder ();
text.append (String.format ("Paginated .... %s %n", paginated));
text.append (String.format ("Tabs ......... %s %n", tabs));
return text.toString (); text.append (String.format ("Zoom ......... %s %n", zoom));
} text.append (String.format ("Mail merge ... %s %n", mailMerge));
} text.append (String.format ("Left margin .. %d %n", leftMargin));
text.append (String.format ("Min version .. %d %n", sfMinVers));
text.append (String.format ("Mult rulers .. %s %n", multipleRulers));
text.append (String.format ("Paginated .... %s %n", paginated));
return text.toString ();
}
}
} }

View File

@ -1,6 +1,8 @@
package com.bytezone.diskbrowser.appleworks; package com.bytezone.diskbrowser.appleworks;
// -----------------------------------------------------------------------------------//
class Cell class Cell
// -----------------------------------------------------------------------------------//
{ {
final String cellName; final String cellName;
final int row; final int row;
@ -8,14 +10,18 @@ class Cell
String value; String value;
String type; String type;
// ---------------------------------------------------------------------------------//
static String getCellName (int row, int column) static String getCellName (int row, int column)
// ---------------------------------------------------------------------------------//
{ {
char c1 = (char) ('A' + column / 26 - 1); char c1 = (char) ('A' + column / 26 - 1);
char c2 = (char) ('A' + column % 26); char c2 = (char) ('A' + column % 26);
return "" + (c1 == '@' ? "" : c1) + c2 + row; return "" + (c1 == '@' ? "" : c1) + c2 + row;
} }
// ---------------------------------------------------------------------------------//
public Cell (int row, int column, int offset, int length) public Cell (int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
{ {
this.row = row; this.row = row;
this.column = column; this.column = column;
@ -23,8 +29,10 @@ class Cell
cellName = getCellName (row, column); cellName = getCellName (row, column);
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
return String.format ("%5s : %s %s%n", cellName, type, value); return String.format ("%5s : %s %s%n", cellName, type, value);
} }

View File

@ -2,19 +2,25 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class CellAddress // -----------------------------------------------------------------------------------//
class CellAddress
// -----------------------------------------------------------------------------------//
{ {
int colRef; int colRef;
int rowRef; int rowRef;
public CellAddress (byte[] buffer, int offset) // ---------------------------------------------------------------------------------//
CellAddress (byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{ {
colRef = buffer[offset]; colRef = buffer[offset];
rowRef = HexFormatter.intValue (buffer[offset + 1], buffer[offset + 2]); rowRef = HexFormatter.intValue (buffer[offset + 1], buffer[offset + 2]);
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
return String.format ("[Row=%04d, Col=%04d]", rowRef, colRef); return String.format ("[Row=%04d, Col=%04d]", rowRef, colRef);
} }

View File

@ -2,12 +2,16 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class CellConstant extends Cell // -----------------------------------------------------------------------------------//
class CellConstant extends Cell
// -----------------------------------------------------------------------------------//
{ {
double saneDouble; double saneDouble;
CellFormat format; CellFormat format;
public CellConstant (byte[] buffer, int row, int column, int offset, int length) // ---------------------------------------------------------------------------------//
CellConstant (byte[] buffer, int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
{ {
super (row, column, offset, length); super (row, column, offset, length);

View File

@ -1,6 +1,8 @@
package com.bytezone.diskbrowser.appleworks; package com.bytezone.diskbrowser.appleworks;
public class CellFormat // -----------------------------------------------------------------------------------//
class CellFormat
// -----------------------------------------------------------------------------------//
{ {
boolean labelAllowed; boolean labelAllowed;
boolean valueAllowed; boolean valueAllowed;
@ -13,7 +15,9 @@ public class CellFormat
boolean appropriate; boolean appropriate;
int decimals; int decimals;
public CellFormat (byte format) // ---------------------------------------------------------------------------------//
CellFormat (byte format)
// ---------------------------------------------------------------------------------//
{ {
display = (format & 0x40) == 0; display = (format & 0x40) == 0;
labelAllowed = (format & 0x10) == 0; labelAllowed = (format & 0x10) == 0;
@ -29,13 +33,17 @@ public class CellFormat
appropriate = formatting == 6; appropriate = formatting == 6;
} }
public CellFormat (byte format, byte decimals) // ---------------------------------------------------------------------------------//
CellFormat (byte format, byte decimals)
// ---------------------------------------------------------------------------------//
{ {
this (format); this (format);
this.decimals = decimals & 0x07; this.decimals = decimals & 0x07;
} }
public String mask () // ---------------------------------------------------------------------------------//
String mask ()
// ---------------------------------------------------------------------------------//
{ {
String fmt = dollars ? "$%" : "%"; String fmt = dollars ? "$%" : "%";
if (commas) if (commas)

View File

@ -2,18 +2,22 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class CellFormula // -----------------------------------------------------------------------------------//
class CellFormula
// -----------------------------------------------------------------------------------//
{ {
private static String[] tokens = {// private static String[] tokens =
"@Deg", "@Rad", "@Pi", "@True", "@False", "@Not", "@IsBlank", "@IsNA", "@IsError", { "@Deg", "@Rad", "@Pi", "@True", "@False", "@Not", "@IsBlank", "@IsNA", "@IsError",
"@Exp", "@Ln", "@Log", "@Cos", "@Sin", "@Tan", "@ACos", "@ASin", "@ATan2", "@Exp", "@Ln", "@Log", "@Cos", "@Sin", "@Tan", "@ACos", "@ASin", "@ATan2",
"@ATan", "@Mod", "@FV", "@PV", "@PMT", "@Term", "@Rate", "@Round", "@Or", "@And", "@ATan", "@Mod", "@FV", "@PV", "@PMT", "@Term", "@Rate", "@Round", "@Or", "@And",
"@Sum", "@Avg", "@Choose", "@Count", "@Error", "@IRR", "@If", "@Int", "@Lookup", "@Sum", "@Avg", "@Choose", "@Count", "@Error", "@IRR", "@If", "@Int", "@Lookup",
"@Max", "@Min", "@NA", "@NPV", "@Sqrt", "@Abs", "", "<>", ">=", "<=", "=", ">", "@Max", "@Min", "@NA", "@NPV", "@Sqrt", "@Abs", "", "<>", ">=", "<=", "=", ">",
"<", ",", "^", ")", "-", "+", "/", "*", "(", "-", "+", "..." }; "<", ",", "^", ")", "-", "+", "/", "*", "(", "-", "+", "..." };
String value; String value;
public CellFormula (Cell cell, byte[] buffer, int offset, int length) // ---------------------------------------------------------------------------------//
CellFormula (Cell cell, byte[] buffer, int offset, int length)
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
@ -42,7 +46,7 @@ public class CellFormula
{ {
CellAddress address = new CellAddress (buffer, offset + i + 1); CellAddress address = new CellAddress (buffer, offset + i + 1);
String cellName = String cellName =
Cell.getCellName (cell.row + address.rowRef, cell.column + address.colRef); Cell.getCellName (cell.row + address.rowRef, cell.column + address.colRef);
i += 3; i += 3;
text.append (cellName); text.append (cellName);
} }

View File

@ -2,12 +2,16 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class CellLabel extends Cell // -----------------------------------------------------------------------------------//
class CellLabel extends Cell
// -----------------------------------------------------------------------------------//
{ {
boolean propagated; boolean propagated;
String label; String label;
public CellLabel (byte[] buffer, int row, int column, int offset, int length) // ---------------------------------------------------------------------------------//
CellLabel (byte[] buffer, int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
{ {
super (row, column, offset, length); super (row, column, offset, length);

View File

@ -2,7 +2,9 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class CellValue extends Cell // -----------------------------------------------------------------------------------//
class CellValue extends Cell
// -----------------------------------------------------------------------------------//
{ {
CellFormat format; CellFormat format;
CellFormula formula; CellFormula formula;
@ -10,7 +12,9 @@ public class CellValue extends Cell
boolean lastEvalError; boolean lastEvalError;
double saneDouble; double saneDouble;
public CellValue (byte[] buffer, int row, int column, int offset, int length) // ---------------------------------------------------------------------------------//
CellValue (byte[] buffer, int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
{ {
super (row, column, offset, length); super (row, column, offset, length);

View File

@ -1,16 +1,21 @@
package com.bytezone.diskbrowser.appleworks; package com.bytezone.diskbrowser.appleworks;
// -----------------------------------------------------------------------------------//
class LabelReport extends Report class LabelReport extends Report
// -----------------------------------------------------------------------------------//
{ {
// ---------------------------------------------------------------------------------//
public LabelReport (AppleworksADBFile parent, byte[] buffer, int offset) LabelReport (AppleworksADBFile parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{ {
super (parent, buffer, offset); super (parent, buffer, offset);
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
return "Skipping vertical report\n"; return "Skipping vertical report\n";
} }
} }

View File

@ -7,14 +7,18 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
// -----------------------------------------------------------------------------------//
class Record class Record
// -----------------------------------------------------------------------------------//
{ {
AppleworksADBFile parent; AppleworksADBFile parent;
int length; int length;
List<String> items = new ArrayList<> (); List<String> items = new ArrayList<> ();
Map<Integer, Double> calculatedItems = new HashMap<Integer, Double> ();// move to TableReport Map<Integer, Double> calculatedItems = new HashMap<> (); // move to TableReport
public Record (AppleworksADBFile parent, byte[] buffer, int ptr) // ---------------------------------------------------------------------------------//
Record (AppleworksADBFile parent, byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//
{ {
this.parent = parent; this.parent = parent;
int count; int count;
@ -55,16 +59,20 @@ class Record
items.add (""); items.add ("");
} }
public String getItem (int index) // ---------------------------------------------------------------------------------//
String getItem (int index)
// ---------------------------------------------------------------------------------//
{ {
return items.get (index); return items.get (index);
} }
public double calculateItem (int pos, int name, String condition) // ---------------------------------------------------------------------------------//
double calculateItem (int pos, int name, String condition)
// ---------------------------------------------------------------------------------//
{ {
try try
{ {
// System.out.printf ("%nCalculating %d (%s): %s%n", pos, (char) name, condition); // System.out.printf ("%nCalculating %d (%s): %s%n", pos, (char) name, condition);
Pattern p = Pattern.compile ("([A-Za-z]{1,2})(([-+*/]([A-Za-z]{1,2}|[0-9]))*)"); Pattern p = Pattern.compile ("([A-Za-z]{1,2})(([-+*/]([A-Za-z]{1,2}|[0-9]))*)");
Matcher m = p.matcher (condition); Matcher m = p.matcher (condition);
if (m.matches ()) if (m.matches ())
@ -112,7 +120,9 @@ class Record
return 0.0; return 0.0;
} }
// ---------------------------------------------------------------------------------//
private String valueOf (int field) private String valueOf (int field)
// ---------------------------------------------------------------------------------//
{ {
int itemNo = field - 'A'; int itemNo = field - 'A';
@ -138,12 +148,16 @@ class Record
return "0.0"; return "0.0";
} }
public String getReportLine (String format) // ---------------------------------------------------------------------------------//
String getReportLine (String format)
// ---------------------------------------------------------------------------------//
{ {
return String.format (format, (Object[]) items.toArray (new String[items.size ()])); return String.format (format, (Object[]) items.toArray (new String[items.size ()]));
} }
public String getReportLine () // ---------------------------------------------------------------------------------//
String getReportLine ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
String format = String.format ("%%-%ds : %%s%%n", parent.maxCategoryName); String format = String.format ("%%-%ds : %%s%%n", parent.maxCategoryName);
@ -163,8 +177,10 @@ class Record
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
String format = "%-" + parent.maxCategoryName + "s [%s]%n"; String format = "%-" + parent.maxCategoryName + "s [%s]%n";
@ -175,4 +191,4 @@ class Record
return text.toString (); return text.toString ();
} }
} }

View File

@ -2,7 +2,9 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
abstract class Report abstract class Report
// -----------------------------------------------------------------------------------//
{ {
static final String line = "-------------------------------------------------------" static final String line = "-------------------------------------------------------"
+ "-----------------------------------\n"; + "-----------------------------------\n";
@ -37,7 +39,9 @@ abstract class Report
private final boolean printDash; private final boolean printDash;
private String fudgeReason; private String fudgeReason;
public Report (AppleworksADBFile parent, byte[] buffer, int offset) // ---------------------------------------------------------------------------------//
Report (AppleworksADBFile parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{ {
this.parent = parent; this.parent = parent;
@ -126,24 +130,32 @@ abstract class Report
if (buffer[offset + 480 + fudge] == 0) // test high byte if (buffer[offset + 480 + fudge] == 0) // test high byte
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
selectionRules[i] = HexFormatter.unsignedShort (buffer, offset + 479 + i * 2 + fudge); selectionRules[i] =
HexFormatter.unsignedShort (buffer, offset + 479 + i * 2 + fudge);
testTypes[i] = HexFormatter.unsignedShort (buffer, offset + 485 + i * 2 + fudge); testTypes[i] = HexFormatter.unsignedShort (buffer, offset + 485 + i * 2 + fudge);
continuation[i] = HexFormatter.unsignedShort (buffer, offset + 491 + i * 2 + fudge); continuation[i] =
HexFormatter.unsignedShort (buffer, offset + 491 + i * 2 + fudge);
comparison[i] = pascalString (buffer, offset + 497 + i * 32 + fudge); comparison[i] = pascalString (buffer, offset + 497 + i * 32 + fudge);
} }
else else
System.out.println ("*** Invalid value in report rules ***"); System.out.println ("*** Invalid value in report rules ***");
} }
public abstract String getText (); // ---------------------------------------------------------------------------------//
abstract String getText ();
// ---------------------------------------------------------------------------------//
// ---------------------------------------------------------------------------------//
protected String pascalString (byte[] buffer, int ptr) protected String pascalString (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//
{ {
return new String (buffer, ptr + 1, buffer[ptr] & 0xFF); return new String (buffer, ptr + 1, buffer[ptr] & 0xFF);
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();

View File

@ -1,6 +1,8 @@
package com.bytezone.diskbrowser.appleworks; package com.bytezone.diskbrowser.appleworks;
// -----------------------------------------------------------------------------------//
class TableReport extends Report class TableReport extends Report
// -----------------------------------------------------------------------------------//
{ {
private final int[] columnWidths = new int[33]; private final int[] columnWidths = new int[33];
private final int[] spaces = new int[33]; private final int[] spaces = new int[33];
@ -15,7 +17,9 @@ class TableReport extends Report
private final int groupTotalColumn; private final int groupTotalColumn;
private final boolean printGroupTotals; private final boolean printGroupTotals;
public TableReport (AppleworksADBFile parent, byte[] buffer, int offset) // ---------------------------------------------------------------------------------//
TableReport (AppleworksADBFile parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{ {
super (parent, buffer, offset); super (parent, buffer, offset);
@ -39,8 +43,10 @@ class TableReport extends Report
printGroupTotals = buffer[offset + 217] != 0; printGroupTotals = buffer[offset + 217] != 0;
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
@ -69,7 +75,8 @@ class TableReport extends Report
categoryName = categoryName.substring (0, columnWidths[i]); categoryName = categoryName.substring (0, columnWidths[i]);
header.append (categoryName); header.append (categoryName);
header.append (gap.substring (0, columnWidths[i] + spaces[i] - categoryName.length ())); header.append (
gap.substring (0, columnWidths[i] + spaces[i] - categoryName.length ()));
underline.append (line.substring (0, columnWidths[i])); underline.append (line.substring (0, columnWidths[i]));
underline.append (gap.substring (0, spaces[i])); underline.append (gap.substring (0, spaces[i]));
} }
@ -98,8 +105,8 @@ class TableReport extends Report
String cond = calculatedRules[calcField]; String cond = calculatedRules[calcField];
int col = calculatedColumn[calcField] - 1; int col = calculatedColumn[calcField] - 1;
String format = "%12." + justification[col] + "f"; String format = "%12." + justification[col] + "f";
item = item = String.format (format, record.calculateItem (calcField, i + 97, cond))
String.format (format, record.calculateItem (calcField, i + 97, cond)).trim (); .trim ();
// System.out.println (item); // System.out.println (item);
} }
@ -178,19 +185,23 @@ class TableReport extends Report
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
private StringBuilder trimRight (StringBuilder text) private StringBuilder trimRight (StringBuilder text)
// ---------------------------------------------------------------------------------//
{ {
while (text.length () > 0 && text.charAt (text.length () - 1) == ' ') while (text.length () > 0 && text.charAt (text.length () - 1) == ' ')
text.deleteCharAt (text.length () - 1); text.deleteCharAt (text.length () - 1);
return text; return text;
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String toString () public String toString ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (super.toString ()); StringBuilder text = new StringBuilder (super.toString ());
text.append (String.format ("Calculated ......... %d %d %d%n", calculatedColumn[0], text.append (String.format ("Calculated ......... %d %d %d%n", calculatedColumn[0],
calculatedColumn[1], calculatedColumn[2])); calculatedColumn[1], calculatedColumn[2]));
text.append (String.format ("Group total ........ %d%n", groupTotalColumn)); text.append (String.format ("Group total ........ %d%n", groupTotalColumn));
text.append (String.format ("Print gr totals .... %s%n", printGroupTotals)); text.append (String.format ("Print gr totals .... %s%n", printGroupTotals));
text.append (String.format ("Calc category1 ..... %s%n", calculatedCategory[0])); text.append (String.format ("Calc category1 ..... %s%n", calculatedCategory[0]));
@ -202,9 +213,9 @@ class TableReport extends Report
text.append (String.format ("%n Width Space Name Foot Just%n")); text.append (String.format ("%n Width Space Name Foot Just%n"));
for (int i = 0; i < categoriesOnThisReport; i++) for (int i = 0; i < categoriesOnThisReport; i++)
text.append (String.format (" %2d %2d %02X %02X %02X %n", columnWidths[i], text.append (
spaces[i], reportCategoryNames[i], footTotals[i], String.format (" %2d %2d %02X %02X %02X %n", columnWidths[i],
justification[i])); spaces[i], reportCategoryNames[i], footTotals[i], justification[i]));
return text.toString (); return text.toString ();
} }