Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

stdio streams may now be set at a single place in ERT#setXxxStream() …

…or ...

...ERT#set_stdio()

Manually applied patch by jetztgradnet

jetztgradnet@9abc3cc
  • Loading branch information...
commit 91f305e758379a9c6c260e34fdd221398607a44e 1 parent 644bf65
@krestenkrab krestenkrab authored
View
6 erjang_cfg.properties
@@ -1,6 +1,6 @@
-#erjang.otp.root = /usr/local/lib/erlang
-#erjang.erts.version = 5.8
-#erjang.otp.version = R14B
+erjang.otp.root = /usr/local/lib/erlang
+erjang.erts.version = 5.8.3
+erjang.otp.version = R14B02
# erjang.debug.port=true
# erjang.debug.inet=true
View
76 src/main/java/erjang/ERT.java
@@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -1050,15 +1051,56 @@ public static void shutdown() {
async_scheduler.shutdown();
}
- static public InputStream orig_in = System.in;
- static public PrintStream orig_out = System.out;
- static public PrintStream orig_err = System.err;
+ static protected volatile InputStream in = System.in;
+ static protected volatile PrintStream out = System.out;
+ static protected volatile PrintStream err = System.err;
public static void set_stdio(InputStream in,
PrintStream out, PrintStream err) {
- System.setIn(in);
- System.setOut(out);
- System.setErr(err);
+ // avoid null
+ ERT.in = (in != null ? in : new NullInputStream());
+ ERT.out = (out != null ? out : new PrintStream(new NullOutputStream()));
+ ERT.err = (err != null ? err : new PrintStream(new NullOutputStream()));
+ }
+
+ public static void set_stdio(InputStream in,
+ OutputStream out, OutputStream err) {
+ // avoid null
+ ERT.in = (in != null ? in : new NullInputStream());
+ ERT.out = (out != null ? new PrintStream(out) : new PrintStream(new NullOutputStream()));
+ ERT.err = (err != null ? new PrintStream(err) : new PrintStream(new NullOutputStream()));
+ }
+
+ public static void setInputStream(InputStream in) {
+ ERT.in = (in != null ? in : new NullInputStream());
+ }
+
+ public static InputStream getInputStream() {
+ return in;
+ }
+
+ public static void setOutputStream(PrintStream out) {
+ ERT.out = (out != null ? out : new PrintStream(new NullOutputStream()));
+ }
+
+ public static void setOutputStream(OutputStream out) {
+ ERT.out = (out != null ? new PrintStream(out) : new PrintStream(new NullOutputStream()));
+ }
+
+ public static PrintStream getOutputStream() {
+ return out;
+ }
+
+ public static void setErrorStream(PrintStream err) {
+ ERT.err = (err != null ? err : new PrintStream(new NullOutputStream()));
+ }
+
+ public static void setErrorStream(OutputStream err) {
+ ERT.err = (err != null ? new PrintStream(err) : new PrintStream(new NullOutputStream()));
+ }
+
+ public static PrintStream getErrorStream() {
+ return err;
}
public static File newFile(String file_name) {
@@ -1077,4 +1119,26 @@ public static void debug(boolean condition, String text) {
debug(text);
}
}
+
+ static class NullInputStream extends InputStream {
+ @Override
+ public int read() throws IOException {
+ return -1;
+ }
+ }
+ static class NullOutputStream extends OutputStream {
+ @Override
+ public void write(int arg0) throws IOException {
+ // ignore
+ }
+ @Override
+ public void write(byte[] b) throws IOException {
+ // ignore
+ }
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ // ignore
+ }
+ }
+
}
View
3  src/main/java/erjang/console/TTYTextAreaDriverControl.java
@@ -47,6 +47,7 @@
import erjang.EHandle;
import erjang.EObject;
import erjang.EPID;
+import erjang.ERT;
import erjang.EString;
import erjang.driver.EDriverInstance;
import erjang.driver.IO;
@@ -157,7 +158,7 @@ public void replace(DocumentFilter.FilterBypass fb,
}
public InputStream getInputStream() {
- return System.in;
+ return ERT.getInputStream();
}
public OutputStream getOutputStream() {
View
6 src/main/java/erjang/driver/FDDriverInstance.java
@@ -60,15 +60,15 @@ public FDDriverInstance(int in, int out) {
this.out = out;
if (in == 0) {
- ins = System.in;
+ ins = ERT.getInputStream();
}
if (out == 1) {
- outs = System.out;
+ outs = ERT.getOutputStream();
}
if (out == 2) {
- outs = System.err;
+ outs = ERT.getErrorStream();
}
// that's it.
}
View
2  src/main/java/erjang/driver/efile/EFile.java
@@ -1965,7 +1965,7 @@ void reply_list_directory(String[] files) throws Pausable {
*
* @see http://www.erlang.org/doc/apps/stdlib/unicode_usage.html#id60205
*/
- static boolean unicodeDriverInterface = ("R14B".compareTo(erjang.Main.otp_version) < 0);
+ static boolean unicodeDriverInterface = ("R14B".compareTo(erjang.Main.otp_version == null ? "" : erjang.Main.otp_version) < 0);
/**
* Determine whether to use the new unicode driver interface
View
2  src/main/java/erjang/m/erlang/ErlProc.java
@@ -120,7 +120,7 @@ public static EObject process_info(EObject pid) {
@BIF
public static EObject display(EProc proc, EObject obj) {
- System.out.println(obj);
+ ERT.getOutputStream().println(obj);
return ERT.TRUE;
}
View
4 src/main/java/erjang/util/Progress.java
@@ -21,6 +21,8 @@
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
+import erjang.ERT;
+
public class Progress {
static ProgressListener listener;
@@ -47,7 +49,7 @@ static public void activity(String string) {
}
if (!Boolean.parseBoolean(suppress)) {
- System.err.write(wheel[next % 4]);
+ ERT.getErrorStream().write(wheel[next % 4]);
}
} catch (IOException e) {
// ignore
Please sign in to comment.
Something went wrong with that request. Please try again.