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 javax.net.ssl.*;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.text.*;
class main {
public static void main(final String[] args) throws Exception {
autoRestart(5);
printStruct(ai_parse_toList1("{I} {like} {you}"));
printStruct(ai_parse_toList1("{This} - {and that}"));
printStruct(ai_parse_toList1("Simple"));
printStruct(ai_parse_toList1("{Full}"));
printStruct(ai_parse_toList1("{{Nested}}"));
printStruct(ai_parse_toList1("{{Nested} and {nested}}"));
}
static double autoRestart_interval = 10;
static boolean autoRestart_on, autoRestart_debug, autoRestart_simulate;
static java.util.Timer autoRestart_timer;
static void autoRestart(double interval) {
autoRestart_interval = interval;
autoRestart();
}
static void autoRestart() {
if (autoRestart_on) return;
autoRestart_on = true;
autoRestart_schedule();
preloadProgramTitle();
}
static void autoRestart_off() {
if (!autoRestart_on) return;
stopTimer(autoRestart_timer);
autoRestart_timer = null;
}
static void autoRestart_schedule() {
autoRestart_timer = doLater_daemon(toMS(autoRestart_interval), "autoRestart_check");
}
static void autoRestart_check() {
try {
String newMD5 = loadPageSilently("http://ai1.lol/1010693/raw?id=" + psI(programID()));
if (!isMD5(newMD5)) { if (autoRestart_debug) print("autoRestart: no server transpilation"); return; }
if (autoRestart_localMD5 == null)
autoRestart_localMD5 = md5(loadCachedTranspilation(programID()));
String localMD5 = autoRestart_localMD5();
if (neq(localMD5, newMD5)) {
if (autoRestart_simulate)
print("Would upgrade now. " + localMD5 + " -> " + newMD5);
else {
infoBox("Upgrading " + programTitle());
restartWithDelay(1000);
sleep();
}
}
} finally {
if (autoRestart_debug) print("autoRestart: Done");
autoRestart_schedule();
}
}
static A printStruct(String prefix, A a) {
printStructure(prefix, a);
return a;
}
static A printStruct(A a) {
printStructure(a);
return a;
}
static List ai_parse_toList1(String parse) {
return ai_parse_toList1(parse, curlySep());
}
static List ai_parse_toList1(String parse, Pair sep) {
assertNempty(sep.a);
assertNempty(sep.b);
int i = 0;
List stack = new ArrayList();
StringBuilder buf = new StringBuilder();
List out = new ArrayList();
while (i < l(parse)) { ping();
if (substringAtIs(parse, i, sep.a)) {
if (nempty(buf)) out.add(getAndClearStringBuilder(buf));
stack.add(i);
i += l(sep.a);
} else if (substringAtIs(parse, i, sep.b)) {
int j = popLast(stack);
i += l(sep.b);
if (empty(stack))
out.add(substring(parse, j, i));
} else if (empty(stack))
buf.append(parse.charAt(i++));
else i++;
}
if (nempty(buf)) out.add(getAndClearStringBuilder(buf));
return out;
}
static Map _registerThread_threads = newWeakHashMap();
static Thread _registerThread(Thread t) {
_registerThread_threads.put(t, true);
return t;
}
static void _registerThread() { _registerThread(Thread.currentThread()); }
static void restartWithDelay(int delay) {
Object j = getJavaX();
call(j, "preKill");
call(j, "nohupJavax", smartJoin((String[]) get(j, "fullArgs")), call(j, "fullVMArguments"));
sleep(delay);
System.exit(0);
sleep();
}
static volatile boolean ping_pauseAll;
static int ping_sleep = 100; // poll pauseAll flag every 100
static volatile boolean ping_anyActions;
static Map ping_actions = newWeakHashMap();
// always returns true
static boolean ping() {
if (ping_pauseAll || ping_anyActions ) ping_impl();
return true;
}
// returns true when it slept
static boolean ping_impl() { try {
if (ping_pauseAll && !isAWTThread()) {
do
Thread.sleep(ping_sleep);
while (ping_pauseAll);
return true;
}
if (ping_anyActions) {
Object action;
synchronized(ping_actions) {
action = ping_actions.get(currentThread());
if (action instanceof Runnable)
ping_actions.remove(currentThread());
if (ping_actions.isEmpty()) ping_anyActions = false;
}
if (action instanceof Runnable)
((Runnable) action).run();
else if (eq(action, "cancelled"))
throw fail("Thread cancelled.");
}
return false;
} catch (Exception __e) { throw rethrow(__e); } }
static JWindow infoBox(String text) {
return infoMessage(text);
}
static JWindow infoBox(String text, double seconds) {
return infoMessage(text, seconds);
}
static JWindow infoBox(Throwable e) {
return infoMessage(e);
}
static Map newWeakHashMap() {
return _registerWeakMap(synchroMap(new WeakHashMap()));
}
static String getAndClearStringBuilder(StringBuilder buf) {
String s = str(buf);
buf.setLength(0);
return s;
}
static ThreadLocal loadPage_charset = new ThreadLocal();
static boolean loadPage_allowGzip = true, loadPage_debug;
static boolean loadPage_anonymous; // don't send computer ID
static int loadPage_verboseness = 100000;
static int loadPage_retries = 1; //60; // seconds
static ThreadLocal loadPage_silent = new ThreadLocal();
static volatile int loadPage_forcedTimeout; // ms
static ThreadLocal loadPage_forcedTimeout_byThread = new ThreadLocal(); // ms
static ThreadLocal