import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import java.text.NumberFormat;
import javax.net.ssl.*;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import java.nio.file.Files;
import java.nio.file.Path;
class main {
static Object dm_remote_rcall(String method, String computerID, Object... args) {
return dm_evaluateOnOtherMachine(computerID, assertIdentifier(method) + "(" + joinWithComma(map("toJava",args)) + ")");
}
static String toJava(Object o) {
if (o == null) return "null";
if (o instanceof String) return quote(o);
throw fail("toJava: " + className(o));
}
static Object dm_evaluateOnOtherMachine(final String computerID, String code, Object... __) {
return dm_evalOnOtherMachineWithReturnValue(computerID, code, __);
}
static String assertIdentifier(String s) {
return assertIsIdentifier(s);
}
static String assertIdentifier(String msg, String s) {
return assertIsIdentifier(msg, s);
}
static String joinWithComma(Collection c) {
return join(", ", c);
}
static String joinWithComma(String... c) {
return join(", ", c);
}
static String joinWithComma(Pair p) {
return p == null ? "" : joinWithComma(str(p.a), str(p.b));
}
static List map(Iterable l, Object f) { return map(f, l); }
static List map(Object f, Iterable l) {
List x = emptyList(l);
if (l != null) for (Object o : l)
x.add(callF(f, o));
return x;
}
static List map(Iterable l, F1 f) { return map(f, l); }
static List map(F1 f, Iterable l) {
List x = emptyList(l);
if (l != null) for (A o : l)
x.add(callF(f, o));
return x;
}
static List map(IF1 f, Iterable l) { return map(l, f); }
static List map(Iterable l, IF1 f) {
List x = emptyList(l);
if (l != null) for (A o : l)
x.add(f.get(o));
return x;
}
static List map(IF1 f, A[] l) { return map(l, f); }
static List map(A[] l, IF1 f) {
List x = emptyList(l);
if (l != null) for (A o : l)
x.add(f.get(o));
return x;
}
static List map(Object f, Object[] l) { return map(f, asList(l)); }
static List map(Object[] l, Object f) { return map(f, l); }
static List map(Object f, Map map) {
return map(map, f);
}
// map: func(key, value) -> list element
static List map(Map map, Object f) {
List x = new ArrayList();
if (map != null) for (Object _e : map.entrySet()) {
Map.Entry e = (Map.Entry) _e;
x.add(callF(f, e.getKey(), e.getValue()));
}
return x;
}
static List map(Map map, IF2 f) {
return map(map, (Object) f);
}
static String quote(Object o) {
if (o == null) return "null";
return quote(str(o));
}
static String quote(String s) {
if (s == null) return "null";
StringBuilder out = new StringBuilder((int) (l(s)*1.5+2));
quote_impl(s, out);
return out.toString();
}
static void quote_impl(String s, StringBuilder out) {
out.append('"');
int l = s.length();
for (int i = 0; i < l; i++) {
char c = s.charAt(i);
if (c == '\\' || c == '"')
out.append('\\').append(c);
else if (c == '\r')
out.append("\\r");
else if (c == '\n')
out.append("\\n");
else if (c == '\0')
out.append("\\0");
else
out.append(c);
}
out.append('"');
}
static RuntimeException fail() { throw new RuntimeException("fail"); }
static RuntimeException fail(Throwable e) { throw asRuntimeException(e); }
static RuntimeException fail(Object msg) { throw new RuntimeException(String.valueOf(msg)); }
static RuntimeException fail(String msg) { throw new RuntimeException(msg == null ? "" : msg); }
static RuntimeException fail(String msg, Throwable innerException) { throw new RuntimeException(msg, innerException); }
static String className(Object o) {
return getClassName(o);
}
static long dm_evalOnOtherMachineWithReturnValue_timeout = 60000;
static Object dm_evalOnOtherMachineWithReturnValue(final String computerID, String code, Object... __) {
final String id = aGlobalID();
final Var < Either < Object , String > > var = new Var();
AutoCloseable __12 = vmBus_onMessage("gotFromPrivateChat", new VF2() { public void get(String sender, String msg) { try {
if (var.has() || neq(sender, computerID)) return;
Matches m = new Matches();
if (!startsWith(msg, "done " + id + " ", m)) return;
if (neq(getAuthorOfSignedText(msg), computerID)) {
File f = javaxCachesDir("failed-eval-msg-" + computerID);
saveTextFile(f, msg);
var.set((Either) eitherB("eval result from " + computerID + " did not verify, saved as " + f));
}
String s = firstLine(m.rest());
if (startsWith(s, "direct: ", m))
var.set((Either) eitherA(m.rest()));
else if (startsWith(s, "quoted: ", m))
var.set((Either) eitherA(unquote(m.rest())));
else if (startsWith(s, "base64: ", m))
var.set((Either) eitherA(base64decode(m.rest())));
else if (startsWith(s, "error: ", m))
var.set((Either) eitherB(m.rest()));
else
var.set((Either) eitherB("unknown mode"));
} catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "if (var.has() || neq(sender, computerID)) ret;\r\n new Matches m;\r\n if (!..."; }}); try {
dm_privateChat_sendSigned(computerID, computerID + " eval "
+ (boolOptPar(__, "realEval") ? "real " : "")
+ (boolOptPar(__, "fresh") ? "fresh " : "")
+ id + ": " + code);
Either