6 package com.google.appinventor.components.runtime.util;
8 import android.util.Log;
10 import gnu.expr.Language;
11 import gnu.mapping.Environment;
12 import gnu.mapping.OutPort;
13 import gnu.mapping.Procedure0;
14 import gnu.mapping.TtyInPort;
15 import gnu.mapping.Values;
16 import gnu.text.FilePath;
27 java.net.Socket socket;
30 private static final int REPL_STACK_SIZE = 256*1024;
32 public TelnetRepl(Language language, java.net.Socket socket) {
33 this.language = language;
38 Thread thread = Thread.currentThread();
39 ClassLoader contextClassLoader = thread.getContextClassLoader();
40 if (contextClassLoader ==
null) {
43 thread.setContextClassLoader(Telnet.class.getClassLoader());
47 Shell.run(language, Environment.getCurrent());
49 }
catch (RuntimeException e) {
50 Log.d(
"TelnetRepl",
"Repl is exiting with error " + e.getMessage());
56 }
catch (java.io.IOException ex) {
68 public static Thread
serve (Language language, java.net.Socket client)
69 throws java.io.IOException {
70 Telnet conn =
new Telnet(client,
true);
71 java.io.OutputStream sout = conn.getOutputStream();
72 java.io.InputStream sin = conn.getInputStream();
73 OutPort out =
new OutPort(sout, FilePath.valueOf(
"/dev/stdout"));
74 TtyInPort in =
new TtyInPort(sin, FilePath.valueOf(
"/dev/stdin"), out);
85 in, out, out,
"Telnet Repl Thread", REPL_STACK_SIZE);