From 95d3930c53ed49a9c48b9a4455c26b03a332fb03 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Tue, 15 Mar 2016 07:09:04 +1100 Subject: [PATCH] balance brackets --- .../bytezone/diskbrowser/visicalc/Cell.java | 6 ++++-- .../diskbrowser/visicalc/Expression.java | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/com/bytezone/diskbrowser/visicalc/Cell.java b/src/com/bytezone/diskbrowser/visicalc/Cell.java index 435de5f..dd0cbc1 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Cell.java +++ b/src/com/bytezone/diskbrowser/visicalc/Cell.java @@ -100,8 +100,6 @@ class Cell implements Comparable, Value expressionText = "24"; else if (address.sortValue == 259) expressionText = "11.9"; - else if (address.sortValue == 579) - expressionText = "D9*G5/(1-((1+G5)^-D4))"; } String getText (int colWidth, char defaultFormat) @@ -181,8 +179,12 @@ class Cell implements Comparable, Value @Override public double getValue () { + if (type != CellType.VALUE) + return 0; + if (value == null) createValue (); + return value.getValue (); } diff --git a/src/com/bytezone/diskbrowser/visicalc/Expression.java b/src/com/bytezone/diskbrowser/visicalc/Expression.java index a5a27cd..2b7f5e8 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Expression.java +++ b/src/com/bytezone/diskbrowser/visicalc/Expression.java @@ -176,10 +176,20 @@ class Expression implements Value if (leftBracket != rightBracket) { - System.out.printf ("**** Unbalanced brackets: left:%d, right:%d ****%n", - leftBracket, rightBracket); - System.out.println (input); - return "@ERROR()"; + if (rightBracket > leftBracket) + { + System.out.printf ("**** Unbalanced brackets: left:%d, right:%d ****%n", + leftBracket, rightBracket); + System.out.println (input); + return "@ERROR()"; + } + // System.out.printf ("Old expression:[%s]%n", line); + while (rightBracket < leftBracket) + { + line = line + ")"; + rightBracket++; + } + // System.out.printf ("New expression:[%s]%n", line); } return line; }