1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-05-03 22:30:22 -04:00
parent f4b95f5ce6
commit 0b5aa9aefe
207 changed files with 2339 additions and 1460 deletions

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.threads; import gplx.*; import gplx.core.*;
import java.util.concurrent.locks.*;
public class Gfo_lock {
private final ReentrantLock lock = new ReentrantLock(true);
public void Lock() {
lock.lock();
}
public void Unlock() {
lock.unlock();
}
}

View File

@@ -15,15 +15,15 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.threads; import gplx.*;
package gplx.core.threads; import gplx.*; import gplx.core.*;
import java.lang.*;
public class ThreadAdp implements Runnable {
public class Thread_adp implements Runnable {
private String name; private GfoInvkAble invk; private String cmd; private GfoMsg msg;
@gplx.Internal protected ThreadAdp(String name, GfoInvkAble invk, String cmd, GfoMsg msg) {
@gplx.Internal protected Thread_adp(String name, GfoInvkAble invk, String cmd, GfoMsg msg) {
this.name = name; this.invk = invk; this.cmd = cmd; this.msg = msg;
this.ctor_ThreadAdp();
}
public ThreadAdp Start() {thread.start(); return this;}
public Thread_adp Start() {thread.start(); return this;}
public void Interrupt() {thread.interrupt();}
public void Join() {
try {
@@ -45,5 +45,5 @@ public class ThreadAdp implements Runnable {
invk.Invk(GfsCtx._, 0, cmd, msg);
}
public Thread Under_thread() {return thread;} private Thread thread;
public static final ThreadAdp Null = new ThreadAdp(ThreadAdp_.Name_null, GfoInvkAble_.Null, "", GfoMsg_.Null);
public static final Thread_adp Null = new Thread_adp(Thread_adp_.Name_null, GfoInvkAble_.Null, "", GfoMsg_.Null);
}

View File

@@ -15,8 +15,8 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.threads; import gplx.*;
public class ThreadAdp_ {
package gplx.core.threads; import gplx.*; import gplx.core.*;
public class Thread_adp_ {
public static void Sleep(int milliseconds) {
try {Thread.sleep(milliseconds);} catch (InterruptedException e) {throw Err_.err_key_(e, "gplx.Thread", "thread interrupted").Add("milliseconds", milliseconds);}
}
@@ -25,12 +25,12 @@ public class ThreadAdp_ {
try {o.wait();}
catch (InterruptedException e) {throw Err_.err_key_(e, "gplx.Thread", "thread wait");}
}
public static ThreadAdp invk_(GfoInvkAble invk, String cmd) {return invk_(Name_null, invk, cmd);}
public static ThreadAdp invk_(String name, GfoInvkAble invk, String cmd) {return new ThreadAdp(name, invk, cmd, GfoMsg_.Null);}
public static ThreadAdp invk_msg_(GfoInvkAble invk, GfoMsg msg) {return invk_msg_(Name_null, invk, msg);}
public static ThreadAdp invk_msg_(String name, GfoInvkAble invk, GfoMsg msg) {return new ThreadAdp(name, invk, msg.Key(), msg);}
public static Thread_adp invk_(GfoInvkAble invk, String cmd) {return invk_(Name_null, invk, cmd);}
public static Thread_adp invk_(String name, GfoInvkAble invk, String cmd) {return new Thread_adp(name, invk, cmd, GfoMsg_.Null);}
public static Thread_adp invk_msg_(GfoInvkAble invk, GfoMsg msg) {return invk_msg_(Name_null, invk, msg);}
public static Thread_adp invk_msg_(String name, GfoInvkAble invk, GfoMsg msg) {return new Thread_adp(name, invk, msg.Key(), msg);}
public static void Run_invk_msg(String name, GfoInvkAble invk, GfoMsg m) {
ThreadAdp_.invk_msg_(name, invk, m).Start();
Thread_adp_.invk_msg_(name, invk, m).Start();
}
public static final String Name_null = null;
}

View File

@@ -624,6 +624,7 @@ public class Bry_ {
}
public static int Xto_int_or(byte[] ary, int or) {return Xto_int_or(ary, null, 0, ary.length, or);}
public static int Xto_int_or(byte[] ary, int bgn, int end, int or) {return Xto_int_or(ary, null, bgn, end, or);}
public static int Xto_int_or(byte[] ary, byte[] ignore_ary, int or) {return Xto_int_or(ary, ignore_ary, 0, ary.length, or);}
public static int Xto_int_or(byte[] ary, byte[] ignore_ary, int bgn, int end, int or) {
if ( ary == null
|| end == bgn // null-len

View File

@@ -121,98 +121,100 @@ public class Bry_fmtr {
public int Missing_adj() {return missing_adj;} public Bry_fmtr Missing_adj_(int v) {missing_adj = v; return this;} int missing_adj;
public boolean Fail_when_invalid_escapes() {return fail_when_invalid_escapes;} public Bry_fmtr Fail_when_invalid_escapes_(boolean v) {fail_when_invalid_escapes = v; return this;} private boolean fail_when_invalid_escapes = true;
public Bry_fmtr Compile() {
Bry_bfr lkp_bfr = Bry_bfr.new_(16);
int fmt_len = fmt.length; int fmt_end = fmt_len - 1; int fmt_pos = 0;
byte[] trg_bry = new byte[fmt_len]; int trg_pos = 0;
boolean lkp_is_active = false, lkp_is_numeric = true;
byte nxt_byte, tmp_byte;
ListAdp list = ListAdp_.new_();
fmt_args_exist = false;
while (true) {
if (fmt_pos > fmt_end) break;
byte cur_byte = fmt[fmt_pos];
if (lkp_is_active) {
if (cur_byte == char_arg_end) {
if (lkp_is_numeric)
list.Add(Bry_fmtr_itm.arg_(lkp_bfr.XtoInt(0) - baseInt));
synchronized (this) { // THREAD: DATE:2015-04-29
Bry_bfr lkp_bfr = Bry_bfr.new_(16);
int fmt_len = fmt.length; int fmt_end = fmt_len - 1; int fmt_pos = 0;
byte[] trg_bry = new byte[fmt_len]; int trg_pos = 0;
boolean lkp_is_active = false, lkp_is_numeric = true;
byte nxt_byte, tmp_byte;
ListAdp list = ListAdp_.new_();
fmt_args_exist = false;
while (true) {
if (fmt_pos > fmt_end) break;
byte cur_byte = fmt[fmt_pos];
if (lkp_is_active) {
if (cur_byte == char_arg_end) {
if (lkp_is_numeric)
list.Add(Bry_fmtr_itm.arg_(lkp_bfr.XtoInt(0) - baseInt));
else {
byte[] key_fmt = lkp_bfr.Xto_bry();
Object idx_ref = keys.Fetch(Bry_obj_ref.new_(key_fmt));
if (idx_ref == null) {
int lkp_bfr_len = lkp_bfr.Len();
byte[] lkp_bry = lkp_bfr.Bfr();
trg_bry[trg_pos++] = char_escape;
trg_bry[trg_pos++] = char_arg_bgn;
for (int i = 0; i < lkp_bfr_len; i++)
trg_bry[trg_pos++] = lkp_bry[i];
trg_bry[trg_pos++] = char_arg_end;
}
else {
list.Add(Bry_fmtr_itm.arg_(((Int_obj_val)idx_ref).Val() - baseInt));
}
}
lkp_is_active = false;
lkp_bfr.Clear();
fmt_args_exist = true;
}
else {
byte[] key_fmt = lkp_bfr.Xto_bry();
Object idx_ref = keys.Fetch(Bry_obj_ref.new_(key_fmt));
if (idx_ref == null) {
int lkp_bfr_len = lkp_bfr.Len();
byte[] lkp_bry = lkp_bfr.Bfr();
trg_bry[trg_pos++] = char_escape;
trg_bry[trg_pos++] = char_arg_bgn;
for (int i = 0; i < lkp_bfr_len; i++)
trg_bry[trg_pos++] = lkp_bry[i];
trg_bry[trg_pos++] = char_arg_end;
lkp_bfr.Add_byte(cur_byte);
switch (cur_byte) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
break;
default:
lkp_is_numeric = false;
break;
}
}
fmt_pos += 1;
}
else if (cur_byte == char_escape) {
if (fmt_pos == fmt_end) {
if (fail_when_invalid_escapes)
throw Err_.new_("escape char encountered but no more chars left");
else {
trg_bry[trg_pos] = cur_byte;
break;
}
}
nxt_byte = fmt[fmt_pos + 1];
if (nxt_byte == char_arg_bgn) {
if (trg_pos > 0) {list.Add(Bry_fmtr_itm.dat_(trg_bry, trg_pos)); trg_pos = 0;} // something pending; add it to list
int eval_lhs_bgn = fmt_pos + 2;
if (eval_lhs_bgn < fmt_len && fmt[eval_lhs_bgn] == char_eval_bgn) { // eval found
fmt_pos = Compile_eval_cmd(fmt, fmt_len, eval_lhs_bgn, list);
continue;
}
else {
list.Add(Bry_fmtr_itm.arg_(((Int_obj_val)idx_ref).Val() - baseInt));
lkp_is_active = true;
lkp_is_numeric = true;
}
}
lkp_is_active = false;
lkp_bfr.Clear();
fmt_args_exist = true;
else { // ~{0}; ~~ -> ~; ~n -> newLine; ~t -> tab
if (nxt_byte == char_escape) tmp_byte = char_escape;
else if (nxt_byte == char_escape_nl) tmp_byte = Byte_ascii.NewLine;
else if (nxt_byte == char_escape_tab) tmp_byte = Byte_ascii.Tab;
else {
if (fail_when_invalid_escapes) throw Err_.new_("unknown escape code").Add("code", Char_.XbyInt(nxt_byte)).Add("fmt_pos", fmt_pos + 1);
else
tmp_byte = cur_byte;
}
trg_bry[trg_pos++] = tmp_byte;
}
fmt_pos += 2;
}
else {
lkp_bfr.Add_byte(cur_byte);
switch (cur_byte) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
break;
default:
lkp_is_numeric = false;
break;
}
trg_bry[trg_pos++] = cur_byte;
fmt_pos += 1;
}
fmt_pos += 1;
}
else if (cur_byte == char_escape) {
if (fmt_pos == fmt_end) {
if (fail_when_invalid_escapes)
throw Err_.new_("escape char encountered but no more chars left");
else {
trg_bry[trg_pos] = cur_byte;
break;
}
}
nxt_byte = fmt[fmt_pos + 1];
if (nxt_byte == char_arg_bgn) {
if (trg_pos > 0) {list.Add(Bry_fmtr_itm.dat_(trg_bry, trg_pos)); trg_pos = 0;} // something pending; add it to list
int eval_lhs_bgn = fmt_pos + 2;
if (eval_lhs_bgn < fmt_len && fmt[eval_lhs_bgn] == char_eval_bgn) { // eval found
fmt_pos = Compile_eval_cmd(fmt, fmt_len, eval_lhs_bgn, list);
continue;
}
else {
lkp_is_active = true;
lkp_is_numeric = true;
}
}
else { // ~{0}; ~~ -> ~; ~n -> newLine; ~t -> tab
if (nxt_byte == char_escape) tmp_byte = char_escape;
else if (nxt_byte == char_escape_nl) tmp_byte = Byte_ascii.NewLine;
else if (nxt_byte == char_escape_tab) tmp_byte = Byte_ascii.Tab;
else {
if (fail_when_invalid_escapes) throw Err_.new_("unknown escape code").Add("code", Char_.XbyInt(nxt_byte)).Add("fmt_pos", fmt_pos + 1);
else
tmp_byte = cur_byte;
}
trg_bry[trg_pos++] = tmp_byte;
}
fmt_pos += 2;
}
else {
trg_bry[trg_pos++] = cur_byte;
fmt_pos += 1;
}
if (lkp_is_active) throw Err_.new_("idx mode not closed");
if (trg_pos > 0) {list.Add(Bry_fmtr_itm.dat_(trg_bry, trg_pos)); trg_pos = 0;}
itms = (Bry_fmtr_itm[])list.Xto_ary(Bry_fmtr_itm.class);
itms_len = itms.length;
return this;
}
if (lkp_is_active) throw Err_.new_("idx mode not closed");
if (trg_pos > 0) {list.Add(Bry_fmtr_itm.dat_(trg_bry, trg_pos)); trg_pos = 0;}
itms = (Bry_fmtr_itm[])list.Xto_ary(Bry_fmtr_itm.class);
itms_len = itms.length;
return this;
}
int Compile_eval_cmd(byte[] fmt, int fmt_len, int eval_lhs_bgn, ListAdp list) {
int eval_lhs_end = Bry_finder.Find_fwd(fmt, char_eval_end, eval_lhs_bgn + Int_.Const_dlm_len, fmt_len); if (eval_lhs_end == Bry_.NotFound) throw Err_mgr._.fmt_(GRP_KEY, "eval_lhs_end_invalid", "could not find eval_lhs_end: ~{0}", String_.new_utf8_(fmt, eval_lhs_bgn, fmt_len));

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.threads.*;
import gplx.core.threads.*;
public class Env_ {
public static void Init(String[] args, String appNameAndExt, Class<?> type) {
mode_testing = false;
@@ -30,10 +30,8 @@ public class Env_ {
appArgs = args;
appUrl = JarAdp_.Url_type(type);
}
public static void Init_drd(String[] args, Io_url url) {
public static void Init_drd() {
mode_testing = mode_debug = false;
appArgs = args;
appUrl = url;
}
public static void Init_testing() {mode_testing = true;}
public static boolean Mode_testing() {return mode_testing;} static boolean mode_testing = true;
@@ -93,7 +91,7 @@ public class Env_ {
return System.getProperty(key);
} static final String Env_prop_key__user_language = "user.language";
public static void Term_add(GfoInvkAble invk, String cmd) {
ThreadAdp thread = ThreadAdp_.invk_(invk, cmd);
Thread_adp thread = Thread_adp_.invk_(invk, cmd);
Runtime.getRuntime().addShutdownHook(thread.Under_thread());
}
}

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.threads.*;
import gplx.core.threads.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@@ -147,7 +147,7 @@ public class ProcessAdp implements GfoInvkAble, RlsAble {
while (thread.isAlive()) {
thread_run = true;
long prv = Env_.TickCount();
ThreadAdp_.Sleep(thread_interval);
Thread_adp_.Sleep(thread_interval);
// try {thread.join(thread_interval);}
// catch (InterruptedException e) {throw Err_.err_key_(e, "gplx.ProcessAdp", "thread interrupted at join");}
long cur = Env_.TickCount();