Skip to content

Commit

Permalink
support unicode output
Browse files Browse the repository at this point in the history
Task #125 - jyacas doesn't correctly write unicode
  • Loading branch information
grzegorzmazur committed Sep 19, 2015
1 parent 8244977 commit e00335d
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 93 deletions.
8 changes: 4 additions & 4 deletions JavaYacas/net/sf/yacas/BigNumber.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.sf.yacas;

import java.io.OutputStream;
import java.io.Writer;
import java.math.*;

class BigNumber
Expand Down Expand Up @@ -334,15 +334,15 @@ public void Mod( BigNumber aY, BigNumber aZ) throws Exception
}

/// For debugging purposes, dump internal state of this object into a string
public void DumpDebugInfo(OutputStream aOutput) throws Exception
public void DumpDebugInfo(Writer aOutput) throws Exception
{
if (integer != null)
{
aOutput.write(("integer: "+integer.toString()+"\n").getBytes());
aOutput.write(("integer: "+integer.toString()+"\n"));
}
else
{
aOutput.write(("decimal: "+decimal.unscaledValue()+" scale "+decimal.scale()+" x 10^("+iTensExp+")\n").getBytes());
aOutput.write(("decimal: "+decimal.unscaledValue()+" scale "+decimal.scale()+" x 10^("+iTensExp+")\n"));
}
}

Expand Down
8 changes: 4 additions & 4 deletions JavaYacas/net/sf/yacas/CYacas.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package net.sf.yacas;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.io.Writer;


public class CYacas
{
public CYacas(OutputStream stdoutput)
public CYacas(Writer stdoutput)
{
try
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public String Evaluate(String input)
env.SetVariable(percent,result,true);
env.Protect(percent);

ByteArrayOutputStream output = new ByteArrayOutputStream();
StringWriter output = new StringWriter();

if (env.iPrettyPrinter != null)
{
Expand Down
9 changes: 5 additions & 4 deletions JavaYacas/net/sf/yacas/ConsoleApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,16 @@ public void lostOwnership(Clipboard clipboard, Transferable contents)

boolean calculating = false;

ByteArrayOutputStream stdoutput = null;
StringWriter stdoutput = null;
CYacas yacas = null;

@Override
public void start()
{
clearOutputLines();

stdoutput = new ByteArrayOutputStream();

stdoutput = new StringWriter();
yacas = new CYacas(stdoutput);
yacas.env.iCurrentInput = new CachedStdFileInput(yacas.env.iInputStatus);

Expand Down Expand Up @@ -803,7 +804,7 @@ void PerformRequest(String outputPrompt, String inputLine, boolean doRepaint)
{
paint(getGraphics());
}
stdoutput.reset();
stdoutput.getBuffer().setLength(0);
String response = yacas.Evaluate(inputLine);
calculating = false;

Expand Down Expand Up @@ -1674,7 +1675,7 @@ public void InvokeCalculationSilent(String expression)
}
else
{
stdoutput.reset();
stdoutput.getBuffer().setLength(0);
String response = yacas.Evaluate(expression);
calculating = false;
AddOutputLine(stdoutput.toString());
Expand Down
14 changes: 7 additions & 7 deletions JavaYacas/net/sf/yacas/InfixPrinter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.sf.yacas;

import java.io.OutputStream;
import java.io.Writer;


class InfixPrinter extends LispPrinter
Expand All @@ -19,7 +19,7 @@ public InfixPrinter(LispOperators aPrefixOperators,
iPrevLastChar = 0;
}
@Override
public void Print(LispPtr aExpression, OutputStream aOutput, LispEnvironment aEnvironment) throws Exception
public void Print(LispPtr aExpression, Writer aOutput, LispEnvironment aEnvironment) throws Exception
{
iCurrentEnvironment = aEnvironment;
Print(aExpression, aOutput, KMaxPrecedence);
Expand All @@ -29,7 +29,7 @@ public void RememberLastChar(char aChar)
{
iPrevLastChar = aChar;
}
void Print(LispPtr aExpression, OutputStream aOutput, int iPrecedence) throws Exception
void Print(LispPtr aExpression, Writer aOutput, int iPrecedence) throws Exception
{
LispError.LISPASSERT(aExpression.Get() != null);

Expand Down Expand Up @@ -203,17 +203,17 @@ else if (string == iCurrentEnvironment.iNth.String())
}
}
}
void WriteToken(OutputStream aOutput,String aString) throws Exception
void WriteToken(Writer aOutput,String aString) throws Exception
{
if (LispTokenizer.IsAlNum(iPrevLastChar) && (LispTokenizer.IsAlNum(aString.charAt(0)) || aString.charAt(0)=='_'))
{
aOutput.write(" ".getBytes());
aOutput.write(" ");
}
else if (LispTokenizer.IsSymbolic(iPrevLastChar) && LispTokenizer.IsSymbolic(aString.charAt(0)))
{
aOutput.write(" ".getBytes());
aOutput.write(" ");
}
aOutput.write(aString.getBytes());
aOutput.write(aString);
RememberLastChar(aString.charAt(aString.length()-1));
}
LispOperators iPrefixOperators;
Expand Down
8 changes: 4 additions & 4 deletions JavaYacas/net/sf/yacas/LispEnvironment.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.sf.yacas;

import java.io.OutputStream;
import java.io.Writer;
import java.util.Set;
import java.util.HashSet;
import java.util.HashMap;
Expand All @@ -11,7 +11,7 @@ class LispEnvironment
{
//TODO FIXME

LispEnvironment(OutputStream aCurrentOutput) throws Exception
LispEnvironment(Writer aCurrentOutput) throws Exception
{
iCurrentTokenizer = iDefaultTokenizer;
iInitialOutput = aCurrentOutput;
Expand Down Expand Up @@ -321,8 +321,8 @@ public int GetUniqueId()
return iLastUniqueId++;
}

OutputStream iCurrentOutput = null;
OutputStream iInitialOutput = null;
Writer iCurrentOutput = null;
Writer iInitialOutput = null;

LispPrinter iCurrentPrinter = null;
LispInput iCurrentInput = null;
Expand Down
22 changes: 11 additions & 11 deletions JavaYacas/net/sf/yacas/LispPrinter.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package net.sf.yacas;

import java.io.OutputStream;
import java.io.Writer;


class LispPrinter
{
public void Print(LispPtr aExpression, OutputStream aOutput, LispEnvironment aEnvironment) throws Exception
public void Print(LispPtr aExpression, Writer aOutput, LispEnvironment aEnvironment) throws Exception
{
PrintExpression(aExpression, aOutput, aEnvironment,0);
}
public void RememberLastChar(char aChar)
{
}

void PrintExpression(LispPtr aExpression, OutputStream aOutput,
void PrintExpression(LispPtr aExpression, Writer aOutput,
LispEnvironment aEnvironment,int aDepth /* =0 */) throws Exception
{
LispPtr iter = new LispPtr();
Expand All @@ -26,8 +26,8 @@ void PrintExpression(LispPtr aExpression, OutputStream aOutput,

if (string != null)
{
aOutput.write(string.getBytes());
aOutput.write(" ".getBytes());
aOutput.write(string);
aOutput.write(" ");
}
// else print "(", print sublist, and print ")"
else if (iter.Get().SubList() != null)
Expand All @@ -36,25 +36,25 @@ else if (iter.Get().SubList() != null)
{
Indent(aOutput,aDepth+1);
}
aOutput.write("(".getBytes());
aOutput.write("(");
PrintExpression((iter.Get().SubList()),aOutput, aEnvironment,aDepth+1);
aOutput.write(")".getBytes());
aOutput.write(")");
item=0;
}
else
{
aOutput.write("[GenericObject]".getBytes());
aOutput.write("[GenericObject]");
}
iter = (iter.Get().Next());
item++;
} // print next element
}

void Indent(OutputStream aOutput, int aDepth) throws Exception {
aOutput.write("\n".getBytes());
void Indent(Writer aOutput, int aDepth) throws Exception {
aOutput.write("\n");
int i;
for (i = aDepth; i > 0; i--) {
aOutput.write(" ".getBytes());
aOutput.write(" ");
}
}
};
Expand Down
16 changes: 8 additions & 8 deletions JavaYacas/net/sf/yacas/LispStandard.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.sf.yacas;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Paths;

Expand Down Expand Up @@ -481,21 +481,21 @@ public static void InternalUse(LispEnvironment aEnvironment,String aFileName) th
}

public static void DoPatchString(String unpatchedString,
OutputStream aOutput,
Writer aOutput,
LispEnvironment aEnvironment) throws Exception
{
String[] tags = unpatchedString.split("\\?\\>");
if (tags.length > 1) {
for (int x = 0; x < tags.length; x++) {
String[] tag = tags[x].split("\\<\\?");
if (tag.length > 1) {
aOutput.write(tag[0].getBytes());
aOutput.write(tag[0]);
String scriptCode = tag[1].trim();
StringBuffer scriptCodeBuffer =
new StringBuffer(scriptCode);
StringInput scriptStream =
new StringInput(scriptCodeBuffer, aEnvironment.iInputStatus);
OutputStream previous = aEnvironment.iCurrentOutput;
Writer previous = aEnvironment.iCurrentOutput;
try {
aEnvironment.iCurrentOutput = aOutput;
LispStandard.DoInternalLoad(aEnvironment, scriptStream);
Expand All @@ -506,9 +506,9 @@ public static void DoPatchString(String unpatchedString,
}
}
}
aOutput.write(tags[tags.length - 1].getBytes());
aOutput.write(tags[tags.length - 1]);
} else {
aOutput.write(unpatchedString.getBytes());
aOutput.write(unpatchedString);
}
}

Expand Down Expand Up @@ -540,7 +540,7 @@ static String PrintExpression(LispPtr aExpression,
LispEnvironment aEnvironment,
int aMaxChars) throws Exception
{
ByteArrayOutputStream newOutput = new ByteArrayOutputStream();
StringWriter newOutput = new StringWriter();
InfixPrinter infixprinter = new InfixPrinter(aEnvironment.iPrefixOperators,
aEnvironment.iInfixOperators,
aEnvironment.iPostfixOperators,
Expand Down

0 comments on commit e00335d

Please sign in to comment.