1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.8.5.1'

This commit is contained in:
gnosygnu
2016-08-29 23:31:58 -04:00
parent e4a2af026b
commit 232838c732
292 changed files with 4502 additions and 1838 deletions

View File

@@ -1054,4 +1054,7 @@ public class Bry_ {
for (int i = 0; i < len; ++i)
bry[i] = Byte_.Zero;
}
public static byte[] Replace_nl_w_tab(byte[] src, int bgn, int end) {
return Bry_.Replace(Bry_.Mid(src, bgn, end), Byte_ascii.Nl, Byte_ascii.Tab);
}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Bry_find_ {
public static final int Not_found = -1;
public static final int Not_found = -1;
public static int Find_fwd(byte[] src, byte lkp) {return Find_fwd(src, lkp, 0, src.length);}
public static int Find_fwd(byte[] src, byte lkp, int cur) {return Find_fwd(src, lkp, cur, src.length);}
public static int Find_fwd(byte[] src, byte lkp, int cur, int end) {

View File

@@ -42,6 +42,11 @@ public class Byte_ {
if (v == itm) return true;
return false;
}
public static boolean Eq_many(byte v, byte... ary) {
for (byte itm : ary)
if (v != itm) return false;
return true;
}
public static int Compare(byte lhs, byte rhs) {
if (lhs == rhs) return CompareAble_.Same;
else if (lhs < rhs) return CompareAble_.Less;

View File

@@ -48,6 +48,9 @@ public class Datetime_now {
if (autoincrement) manual = rv.Add_minute(1); // simulate passage of manual by increasing manual by 1 minute with each call
return rv;
}
public static DateAdp Get_force() { // ignore manual and force get of real time
return new DateAdp(new GregorianCalendar());
}
// private static final DateAdp manual_time_dflt = DateAdp_.parse_gplx("2001-01-01 00:00:00.000");
// private static DateAdp manual_time;
// static boolean Now_enabled() {return now_enabled;} private static boolean now_enabled;

View File

@@ -19,7 +19,7 @@ package gplx;
public class Gfo_usr_dlg_ {
private static Gfo_usr_dlg_base test__list, test__show;
public static Gfo_usr_dlg Instance = Gfo_usr_dlg_noop.Instance; // NOTE: global instance which can be reassigned
public static final Gfo_usr_dlg Noop = Gfo_usr_dlg_noop.Instance;
public static final Gfo_usr_dlg Noop = Gfo_usr_dlg_noop.Instance;
public static Gfo_usr_dlg__gui Test__list__init() {
if (test__list == null)
test__list = new Gfo_usr_dlg_base(Gfo_usr_dlg__log_.Noop, Gfo_usr_dlg__gui_.Test);
@@ -70,5 +70,5 @@ class Gfo_usr_dlg_noop implements Gfo_usr_dlg {
public String Log_direct(String msg) {return "";}
public String Plog_many(String grp_key, String msg_key, String fmt, Object... args) {return "";}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
public static final Gfo_usr_dlg_noop Instance = new Gfo_usr_dlg_noop(); Gfo_usr_dlg_noop() {}
public static final Gfo_usr_dlg_noop Instance = new Gfo_usr_dlg_noop(); Gfo_usr_dlg_noop() {}
}

View File

@@ -83,7 +83,7 @@ public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log {
}
catch (Exception e) {Err_.Noop(e);} // java.lang.StringBuilder can throw exceptions in some situations when called on a different thread; ignore errors
} private String_bldr sb = String_bldr_.new_thread(); // NOTE: use java.lang.StringBuffer to try to avoid random exceptions when called on a different thread
private String Bld_msg(String s) {return sb.Add(Datetime_now.Get().XtoUtc().XtoStr_fmt_yyyyMMdd_HHmmss_fff()).Add(" ").Add(s).Add_char_nl().To_str_and_clear();}
private String Bld_msg(String s) {return sb.Add(Datetime_now.Get_force().XtoUtc().XtoStr_fmt_yyyyMMdd_HHmmss_fff()).Add(" ").Add(s).Add_char_nl().To_str_and_clear();}
private void Log_msg(Io_url url, String txt) {
if (queue_enabled) {
String url_raw = url == null ? "mem" : url.Raw();

View File

@@ -27,9 +27,9 @@ public class Io_url_ {
if (usr_dir == null) {
switch (Op_sys.Cur().Tid()) {
case Op_sys.Tid_wnt: usr_dir = Io_url_.new_inf_("C:\\", IoUrlInfo_.Wnt); break;
case Op_sys.Tid_lnx: usr_dir = Io_url_.new_inf_(String_.Format("/home/{0}/", Env_.UserName()), IoUrlInfo_.Lnx); break;
case Op_sys.Tid_osx: usr_dir = Io_url_.new_inf_(String_.Format("/Users/{0}/", Env_.UserName()), IoUrlInfo_.Lnx); break;
case Op_sys.Tid_drd: usr_dir = Io_url_.new_inf_(String_.Format("/mnt/{0}/", Env_.UserName()), IoUrlInfo_.Lnx); break;
case Op_sys.Tid_lnx: usr_dir = Io_url_.new_inf_(String_.Format("/home/{0}/", System_.Prop__user_name()), IoUrlInfo_.Lnx); break;
case Op_sys.Tid_osx: usr_dir = Io_url_.new_inf_(String_.Format("/Users/{0}/", System_.Prop__user_name()), IoUrlInfo_.Lnx); break;
case Op_sys.Tid_drd: usr_dir = Io_url_.new_inf_(String_.Format("/mnt/{0}/", System_.Prop__user_name()), IoUrlInfo_.Lnx); break;
default: throw Err_.new_unhandled(Op_sys.Cur().Tid());
}
}
@@ -49,22 +49,31 @@ public class Io_url_ {
public static Io_url new_dir_(String raw) {return new_any_(raw);} // NOTE: for now, same as new_fil; stack overflow when doing new_dir
public static Io_url new_any_(String raw) {return new_inf_(raw, IoUrlInfoRegy.Instance.Match(raw));}
public static Io_url new_inf_(String raw, IoUrlInfo info) {return String_.Eq(raw, "") ? Io_url_.Empty : new Io_url(raw, info);}
public static Io_url http_any_(String src, boolean wnt) {
return new_any_(parse_http_file(src, wnt));
public static Io_url New__http_or_fail(String raw) {return New__http_or_fail(Bry_.new_u8(raw));}
public static Io_url New__http_or_fail(byte[] raw) {
Io_url rv = New__http_or_null(raw);
if (rv == null) throw Err_.new_wo_type("url:invalid http_file raw", "raw", raw);
return rv;
}
private static String parse_http_file(String v, boolean wnt) {
byte[] v_bry = Bry_.new_u8(v);
int v_len = v_bry.length;
if (Bry_.Has_at_bgn(v_bry, Io_url.Http_file_bry, 0, v_len)) {
byte[] rv = new byte[v_len - Io_url.Http_file_len];
for (int i = 0; i < rv.length; i++) {
byte b = v_bry[i + Io_url.Http_file_len];
if (wnt && b == Byte_ascii.Slash) b = Byte_ascii.Backslash;
public static Io_url New__http_or_null(String raw) {return New__http_or_null(Bry_.new_u8(raw));}
public static Io_url New__http_or_null(byte[] raw) {
int len = raw.length;
if (!Bry_.Has_at_bgn(raw, Io_url.Http_file_bry, 0, len)) return null; // doesn't start with "file:///"; return null;
// bld rv; note that wnt has to convert / to \
byte[] rv = null;
if (Op_sys.Cur().Tid_is_wnt()) {
int rv_len = len - Io_url.Http_file_len;
rv = new byte[rv_len];
for (int i = 0; i < rv_len; ++i) {
byte b = raw[i + Io_url.Http_file_len];
if (b == Op_sys.Dir_spr__lnx) b = Op_sys.Dir_spr__wnt;
rv[i] = b;
}
return String_.new_u8(rv);
}
return v;
else
rv = Bry_.Mid(raw, Io_url.Http_file_len);
return rv == null ? null : new_any_(String_.new_u8(rv));
}
public static Io_url store_orFail_(SrlMgr mgr, String key, Io_url v) {

View File

@@ -0,0 +1,32 @@
/*
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;
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
public class Io_url__tst {
@Before public void init() {fxt.Clear();} private final Io_url__fxt fxt = new Io_url__fxt();
@Test public void Basic__lnx() {fxt.Test__New__http_or_null(Bool_.N, "file:///C:/a.txt", "C:/a.txt");}
@Test public void Basic__wnt() {fxt.Test__New__http_or_null(Bool_.Y, "file:///C:/a.txt", "C:\\a.txt");}
@Test public void Null() {fxt.Test__New__http_or_null(Bool_.N, "C:/a.txt", null);}
}
class Io_url__fxt {
public void Clear() {Io_mgr.Instance.InitEngine_mem();}
public void Test__New__http_or_null(boolean os_is_wnt, String raw, String expd) {
Op_sys.Cur_(os_is_wnt ? Op_sys.Tid_wnt : Op_sys.Tid_lnx);
Gftest.Eq__obj_or_null(expd, Io_url_.New__http_or_null(raw));
}
}

View File

@@ -24,6 +24,7 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
public static void Eq_byte (byte expd , byte actl, String fmt, Object... args) {Eq_exec_y(expd, actl, fmt, args);}
public static void Eq_int (int expd , int actl) {Eq_exec_y(expd, actl, "", Object_.Ary_empty);}
public static void Eq_int (int expd , int actl, String fmt, Object... args) {Eq_exec_y(expd, actl, fmt, args);}
public static void Eq_double(double expd, double actl) {Eq_exec_y(expd, actl, "", Object_.Ary_empty);}
public static void Eq_str (byte[] expd, byte[] actl, String fmt, Object... args) {Eq_exec_y(String_.new_u8(expd), String_.new_u8(actl), fmt, args);}
public static void Eq_str (byte[] expd, String actl, String fmt, Object... args) {Eq_exec_y(String_.new_u8(expd), actl, fmt, args);}
public static void Eq_str (String expd, byte[] actl, String fmt, Object... args) {Eq_exec_y(expd, String_.new_u8(actl), fmt, args);}

View File

@@ -33,7 +33,7 @@ public class Time_span_ {
long fracs = Merge_long(units, Time_span_.Divisors);
return Time_span_.fracs_(fracs);
}
public static Time_span from_(long bgn) {return Time_span_.fracs_(Env_.TickCount() - bgn);}
public static Time_span from_(long bgn) {return Time_span_.fracs_(System_.Ticks() - bgn);}
public static final long parse_null = Long_.Min_value;
public static Time_span parse(String raw) {
byte[] bry = Bry_.new_u8(raw);

View File

@@ -39,19 +39,37 @@ public class Bry_rdr {
public int Move_to(int v) {this.pos = v; return pos;}
public int Move_by_one() {return Move_by(1);}
public int Move_by(int v) {this.pos += v; return pos;}
public int Find_fwd_lr() {return Find_fwd(dflt_dlm , Bool_.Y, Bool_.N);}
public int Find_fwd_lr(byte find) {return Find_fwd(find , Bool_.Y, Bool_.N);}
public int Find_fwd_lr(byte[] find) {return Find_fwd(find , Bool_.Y, Bool_.N);}
public int Find_fwd_rr() {return Find_fwd(dflt_dlm , Bool_.N, Bool_.N);}
public int Find_fwd_rr(byte find) {return Find_fwd(find , Bool_.N, Bool_.N);}
public int Find_fwd_rr(byte[] find) {return Find_fwd(find , Bool_.N, Bool_.N);}
private int Find_fwd(byte find, boolean ret_lhs, boolean pos_lhs) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end); if (find_pos == Bry_find_.Not_found) {err_wkr.Fail("find failed", "find", Byte_ascii.To_str(find)); return Bry_find_.Not_found;}
public int Find_fwd_lr() {return Find_fwd(dflt_dlm , Bool_.Y, Bool_.N, Fail_if_missing);}
public int Find_fwd_lr(byte find) {return Find_fwd(find , Bool_.Y, Bool_.N, Fail_if_missing);}
public int Find_fwd_lr_or(byte find, int or)
{return Find_fwd(find , Bool_.Y, Bool_.N, or);}
public int Find_fwd_lr(byte[] find) {return Find_fwd(find , Bool_.Y, Bool_.N, Fail_if_missing);}
public int Find_fwd_rr() {return Find_fwd(dflt_dlm , Bool_.N, Bool_.N, Fail_if_missing);}
public int Find_fwd_rr(byte find) {return Find_fwd(find , Bool_.N, Bool_.N, Fail_if_missing);}
public int Find_fwd_rr(byte[] find) {return Find_fwd(find , Bool_.N, Bool_.N, Fail_if_missing);}
private int Find_fwd(byte find, boolean ret_lhs, boolean pos_lhs, int or) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end);
if (find_pos == Bry_find_.Not_found) {
if (or == Fail_if_missing) {
err_wkr.Fail("find failed", "find", Byte_ascii.To_str(find));
return Bry_find_.Not_found;
}
else
return or;
}
pos = find_pos + (pos_lhs ? 0 : 1);
return ret_lhs ? find_pos : pos;
}
private int Find_fwd(byte[] find, boolean ret_lhs, boolean pos_lhs) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end); if (find_pos == Bry_find_.Not_found) {err_wkr.Fail("find failed", "find", String_.new_u8(find)); return Bry_find_.Not_found;}
private int Find_fwd(byte[] find, boolean ret_lhs, boolean pos_lhs, int or) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end);
if (find_pos == Bry_find_.Not_found) {
if (or == Fail_if_missing) {
err_wkr.Fail("find failed", "find", String_.new_u8(find));
return Bry_find_.Not_found;
}
else
return or;
}
pos = find_pos + (pos_lhs ? 0 : find.length);
return ret_lhs ? find_pos : pos;
}
@@ -203,4 +221,5 @@ public class Bry_rdr {
}
return this;
}
private static final int Fail_if_missing = Int_.Min_value;
}

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.encoders; import gplx.*; import gplx.core.*;
public class Hex_utl_ {
static public int Parse_or(byte[] src, int or) {return Parse_or(src, 0, src.length, or);}
static public int Parse_or(byte[] src, int bgn, int end, int or) {
public static int Parse_or(byte[] src, int or) {return Parse_or(src, 0, src.length, or);}
public static int Parse_or(byte[] src, int bgn, int end, int or) {
int rv = 0; int factor = 1;
byte b = Byte_.Max_value_127;
for (int i = end - 1; i >= bgn; i--) {
@@ -35,11 +35,11 @@ public class Hex_utl_ {
}
return rv;
}
static public int Parse(String src) {
public static int Parse(String src) {
int rv = Parse_or(src, -1); if (rv == -1) throw Err_.new_parse("HexDec", "src");
return rv;
}
static public int Parse_or(String src, int or) {
public static int Parse_or(String src, int or) {
int rv = 0; int digit = 0, factor = 1, len = String_.Len(src);
for (int i = len - 1; i > -1; --i) {
digit = To_int(String_.CharAt(src, i));
@@ -49,7 +49,7 @@ public class Hex_utl_ {
}
return rv;
}
static public void Encode_bry(byte[] src, byte[] trg) {
public static void Encode_bry(byte[] src, byte[] trg) {
int src_len = src.length, trg_len = trg.length;
if (trg_len != src_len * 2) throw Err_.new_("hex", "trg.len must be src.len * 2", "src_len", src_len, "trg_len", trg_len);
int trg_idx = -1;
@@ -59,7 +59,7 @@ public class Hex_utl_ {
trg[++trg_idx] = To_byte_lcase(0xf & src_byte);
}
}
static public String To_str(int val, int pad) {
public static String To_str(int val, int pad) {
char[] ary = new char[8]; int idx = 8; // 8 is max len of hexString; (2^4 * 8); EX: int.MaxValue = 7FFFFFFF
do {
int byt = val % 16;
@@ -70,7 +70,7 @@ public class Hex_utl_ {
ary[--idx] = '0';
return String_.new_charAry_(ary, idx, 8-idx);
}
static public void Write(byte[] bry, int bgn, int end, int val) {
public static void Write(byte[] bry, int bgn, int end, int val) {
for (int i = end - 1; i > bgn - 1; i--) {
int b = val % 16;
bry[i] = To_byte(b);
@@ -78,7 +78,21 @@ public class Hex_utl_ {
if (val == 0) break;
}
}
static private int To_int(char c) {
public static boolean Is_hex_many(byte... ary) {
for (byte itm : ary) {
switch (itm) {
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:
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E: case Byte_ascii.Ltr_F:
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e: case Byte_ascii.Ltr_f:
break;
default:
return false;
}
}
return true;
}
private static int To_int(char c) {
switch (c) {
case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4;
case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9;
@@ -87,7 +101,7 @@ public class Hex_utl_ {
default: return -1;
}
}
static private char To_char(int val) {
private static char To_char(int val) {
switch (val) {
case 0: return '0'; case 1: return '1'; case 2: return '2'; case 3: return '3'; case 4: return '4';
case 5: return '5'; case 6: return '6'; case 7: return '7'; case 8: return '8'; case 9: return '9';
@@ -95,7 +109,7 @@ public class Hex_utl_ {
default: throw Err_.new_parse("hexstring", Int_.To_str(val));
}
}
static private byte To_byte(int v) {
private static byte To_byte(int v) {
switch (v) {
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3; case 4: return Byte_ascii.Num_4;
case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7; case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9;
@@ -103,7 +117,7 @@ public class Hex_utl_ {
default: throw Err_.new_parse("hexstring", Int_.To_str(v));
}
}
static private byte To_byte_lcase(int v) {
private static byte To_byte_lcase(int v) {
switch (v) {
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3;
case 4: return Byte_ascii.Num_4; case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7;

View File

@@ -16,8 +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.core.envs; import gplx.*; import gplx.core.*;
import gplx.core.threads.*;
public class Env_ {
public class Env_ {
public static void Init(String[] args, String appNameAndExt, Class<?> type) {
mode_testing = false;
mode_debug = String_.In("GPLX_DEBUG_MODE_ENABLED", args);
@@ -33,67 +32,17 @@ public class Env_ {
public static void Init_drd() {
mode_testing = mode_debug = false;
}
public static void Init_testing() {mode_testing = true;}
public static void Init_testing_n_() {mode_testing = false;}
public static boolean Mode_testing() {return mode_testing;} static boolean mode_testing = true;
public static boolean Mode_debug() {return mode_debug;} static boolean mode_debug = false;
public static void Init_testing() {mode_testing = true;}
public static void Init_testing_n_() {mode_testing = false;}
public static boolean Mode_testing() {return mode_testing;} private static boolean mode_testing = true;
public static boolean Mode_debug() {return mode_debug;} private static boolean mode_debug = false;
public static String[] AppArgs() {return appArgs;} static String[] appArgs;
public static Io_url AppUrl() {
if (mode_testing) return Io_url_.mem_fil_("mem/testing.jar");
if (appUrl == Io_url_.Empty) throw Err_.new_wo_type("Env_.Init was not called");
return appUrl;
} static Io_url appUrl = Io_url_.Empty;
public static void Exit() {Exit_code(0);}
public static void Exit_code(int code) {System.exit(code);}
public static String UserName() {return System.getProperty("user.name");}
public static void GarbageCollect() {if (mode_testing) return; System.gc();}
public static long TickCount() {return TickCount_Test >= 0 ? TickCount_Test : System.currentTimeMillis();}
public static int TickCount_elapsed_in_sec(long time_bgn) {return (int)(Env_.TickCount() - time_bgn) / 1000;}
public static int TickCount_elapsed_in_frac(long time_bgn) {return (int)(Env_.TickCount() - time_bgn);}
public static long TickCount_Test = -1; // in milliseconds
public static void TickCount_normal() {TickCount_Test = -1;}
public static int System_cpu_count() {return Runtime.getRuntime().availableProcessors();}
public static long System_memory_max() {return Runtime.getRuntime().maxMemory();}
public static long System_memory_total() {return Runtime.getRuntime().totalMemory();}
public static long System_memory_free() {return Runtime.getRuntime().freeMemory();}
public static final String LocalHost = "127.0.0.1";
public static String NewLine_lang() {return mode_testing ? "\n" : "\n";}
public static String GenHdr(boolean forSourceCode, String programName, String hdr_bgn, String hdr_end) {
String newLine = Op_sys.Lnx.Nl_str();
String lineEnd = Op_sys.Lnx.Nl_str();
String codeBgn = forSourceCode ? "/*" + newLine : "";
String codeEnd = forSourceCode ? "*/" + newLine : "";
String codeHdr = forSourceCode ? "This file is part of {0}." + newLine + newLine : "";
String fmt = String_.Concat
( codeBgn
, codeHdr
, hdr_bgn
, "Copyright (c) 2012-2016 gnosygnu@gmail.com", newLine
, newLine
, "This program is free software: you can redistribute it and/or modify", lineEnd
, "it under the terms of the GNU Affero General Public License as", lineEnd
, "published by the Free Software Foundation, either version 3 of the", lineEnd
, "License, or (at your option) any later version.", newLine
, newLine
, "This program is distributed in the hope that it will be useful,", lineEnd
, "but WITHOUT ANY WARRANTY; without even the implied warranty of", lineEnd
, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", lineEnd
, "GNU Affero General Public License for more details.", newLine
, newLine
, "You should have received a copy of the GNU Affero General Public License", lineEnd
, "along with this program. If not, see <http://www.gnu.org/licenses/>.", newLine
, codeEnd
, hdr_end
);
return String_.Format(fmt, programName);
}
public static String Env_prop__user_language() {return Env_prop(Env_prop_key__user_language);}
public static String Env_prop__java_version() {return Env_prop(Env_prop_key__java_version);}
public static String Env_prop(String key) {
return System.getProperty(key);
}
private static final String
Env_prop_key__user_language = "user.language"
, Env_prop_key__java_version = "java.version"
;
}

View File

@@ -20,16 +20,16 @@ public class Op_sys {
Op_sys(byte tid, byte sub_tid, String os_name, byte bitness, String nl_str, byte fsys_dir_spr_byte, boolean fsys_case_match) {
this.tid = tid; this.sub_tid = sub_tid; this.os_name = os_name; this.bitness = bitness; this.nl_str = nl_str; this.fsys_dir_spr_byte = fsys_dir_spr_byte; this.fsys_dir_spr_str = Char_.To_str((char)fsys_dir_spr_byte); this.fsys_case_match = fsys_case_match;
}
public byte Tid() {return tid;} private final byte tid;
public byte Sub_tid() {return sub_tid;} private final byte sub_tid;
public byte Tid() {return tid;} private final byte tid;
public byte Sub_tid() {return sub_tid;} private final byte sub_tid;
public String Os_name() {return os_name;} private String os_name;
public byte Bitness() {return bitness;} private final byte bitness;
public byte Bitness() {return bitness;} private final byte bitness;
public String Bitness_str() {return (bitness == Bitness_32 ? "32" : "64");}
public String Nl_str() {return nl_str;} private final String nl_str;
public String Fsys_dir_spr_str() {return fsys_dir_spr_str;} private final String fsys_dir_spr_str;
public byte Fsys_dir_spr_byte() {return fsys_dir_spr_byte;} private final byte fsys_dir_spr_byte;
public String Nl_str() {return nl_str;} private final String nl_str;
public String Fsys_dir_spr_str() {return fsys_dir_spr_str;} private final String fsys_dir_spr_str;
public byte Fsys_dir_spr_byte() {return fsys_dir_spr_byte;} private final byte fsys_dir_spr_byte;
public String Fsys_http_frag_to_url_str(String raw) {return fsys_dir_spr_byte == Byte_ascii.Slash ? raw : String_.Replace(raw, Lnx.Fsys_dir_spr_str(), fsys_dir_spr_str);}
public boolean Fsys_case_match() {return fsys_case_match;} private final boolean fsys_case_match;
public boolean Fsys_case_match() {return fsys_case_match;} private final boolean fsys_case_match;
public String Fsys_case_match_str(String s) {return String_.CaseNormalize(fsys_case_match, s);}
public boolean Tid_is_wnt() {return tid == Tid_wnt;}
public boolean Tid_is_lnx() {return tid == Tid_lnx;}
@@ -40,11 +40,12 @@ public class Op_sys {
public static final byte Tid_nil = 0, Tid_wnt = 1, Tid_lnx = 2, Tid_osx = 3, Tid_drd = 4;
public static final byte Sub_tid_unknown = 0, Sub_tid_win_xp = 1, Sub_tid_win_7 = 2, Sub_tid_win_8 = 3;
public static final byte Bitness_32 = 1, Bitness_64 = 2;
public static final char Dir_spr_char_lnx = '\n';
public static final Op_sys Lnx = new_unx_flavor_(Tid_lnx, "linux", Bitness_32);
public static final Op_sys Osx = new_unx_flavor_(Tid_osx, "macosx", Bitness_32);
public static final Op_sys Drd = new_unx_flavor_(Tid_drd, "android", Bitness_32);
public static final Op_sys Wnt = new_wnt_(Sub_tid_unknown, Bitness_32);
public static final char Nl_char_lnx = '\n';
public static final byte Dir_spr__lnx = Byte_ascii.Slash, Dir_spr__wnt = Byte_ascii.Backslash;
public static final Op_sys Lnx = new_unx_flavor_(Tid_lnx, "linux", Bitness_32);
public static final Op_sys Osx = new_unx_flavor_(Tid_osx, "macosx", Bitness_32);
public static final Op_sys Drd = new_unx_flavor_(Tid_drd, "android", Bitness_32);
public static final Op_sys Wnt = new_wnt_(Sub_tid_unknown, Bitness_32);
public static Op_sys Cur() {return cur_op_sys;} static Op_sys cur_op_sys = new_auto_identify_();
public static String Fsys_path_to_lnx(String v) {
return cur_op_sys.Tid_is_wnt() ? String_.Replace(v, Wnt.fsys_dir_spr_str, Lnx.fsys_dir_spr_str) : v;
@@ -52,8 +53,8 @@ public class Op_sys {
public static String Fsys_path_to_wnt(String v) {
return cur_op_sys.Tid_is_wnt() ? String_.Replace(v, Lnx.fsys_dir_spr_str, Wnt.fsys_dir_spr_str) : v;
}
private static Op_sys new_wnt_(byte bitness, byte sub_tid) {return new Op_sys(Tid_wnt , sub_tid , "windows", bitness, "\r\n", Byte_ascii.Backslash , Bool_.N);}
private static Op_sys new_unx_flavor_(byte tid, String os_name, byte bitness) {return new Op_sys(tid , Sub_tid_unknown , os_name , bitness, "\n" , Byte_ascii.Slash , Bool_.Y);}
private static Op_sys new_wnt_(byte bitness, byte sub_tid) {return new Op_sys(Tid_wnt , sub_tid , "windows", bitness, "\r\n", Dir_spr__wnt , Bool_.N);}
private static Op_sys new_unx_flavor_(byte tid, String os_name, byte bitness) {return new Op_sys(tid , Sub_tid_unknown , os_name , bitness, "\n" , Dir_spr__lnx , Bool_.Y);}
public static void Cur_(int tid) {
switch (tid) {
case Tid_wnt: cur_op_sys = Wnt; break;

View File

@@ -167,11 +167,11 @@ public class Process_adp implements Gfo_invk, Rls_able {
notify_fmtr.Fmt_(prog_fmt);
while (thread.isAlive()) {
thread_run = true;
long prv = Env_.TickCount();
long prv = System_.Ticks();
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();
long cur = System_.Ticks();
int dif = (int)(cur - prv);
elapsed += dif;
if (prog_dlg != null) {

View File

@@ -0,0 +1,25 @@
/*
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.envs; import gplx.*; import gplx.core.*;
public class Runtime_ {
// *** Hardware-related
public static int Cpu_count() {return Runtime.getRuntime().availableProcessors();}
public static long Memory_max() {return Runtime.getRuntime().maxMemory();}
public static long Memory_total() {return Runtime.getRuntime().totalMemory();}
public static long Memory_free() {return Runtime.getRuntime().freeMemory();}
}

View File

@@ -0,0 +1,63 @@
/*
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.envs; import gplx.*; import gplx.core.*;
public class System_ {
// *** ticks
public static long Ticks() {return Ticks__test_val >= 0 ? Ticks__test_val : System.currentTimeMillis();}
public static int Ticks__elapsed_in_sec (long time_bgn) {return (int)(Ticks() - time_bgn) / 1000;}
public static int Ticks__elapsed_in_frac (long time_bgn) {return (int)(Ticks() - time_bgn);}
public static void Ticks__test_set(long v) {Ticks__test_val = v;}
public static void Ticks__test_add(long v) {Ticks__test_val += v;}
public static void Ticks__test_off() {Ticks__test_val = -1;}
private static long Ticks__test_val = -1; // in milliseconds
// *** misc methods: Exit / GC
public static void Exit() {Exit_by_code(0);}
public static void Exit_by_code(int code) {System.exit(code);}
public static void Garbage_collect() {if (Env_.Mode_testing()) return; System.gc();}
// *** java properties: getProperty; "-D" properties
public static String Prop__user_language() {return Prop__get(Prop_key__user_language);}
public static String Prop__user_name() {return Prop__get(Prop_key__user_name);}
public static String Prop__java_version() {return Prop__get(Prop_key__java_version);}
public static String Prop__java_home() {return Prop__get(Prop_key__java_home);}
private static String Prop__get(String key) {
return System.getProperty(key);
}
private static final String
Prop_key__user_language = "user.language"
, Prop_key__user_name = "user.name"
, Prop_key__java_version = "java.version"
, Prop_key__java_home = "java.version"
;
// *** environment variables: getenv
public static String Env__machine_name() {
String rv = "UNKNOWN_MACHINE_NAME";
rv = Env__get(Env_key__computername); if (String_.Len_gt_0(rv)) return rv;
rv = Env__get(Env_key__hostname); if (String_.Len_gt_0(rv)) return rv;
return rv;
}
private static String Env__get(String key) {
return System.getenv(key);
}
private static final String
Env_key__computername = "COMPUTERNAME"
, Env_key__hostname = "HOSTNAME"
;
}

View File

@@ -33,7 +33,7 @@ public class IoEngine_xrg_loadFilStr {
public String[] ExecAsStrAryLnx() {
String raw = Exec();
if (String_.Len(raw) == 0) return String_.Ary_empty;
return String_.Split(raw, Op_sys.Dir_spr_char_lnx, false);
return String_.Split(raw, Op_sys.Nl_char_lnx, false);
}
int Bom_Utf8 = 65279; // U+FEFF; see http://en.wikipedia.org/wiki/Byte_order_mark
public static IoEngine_xrg_loadFilStr new_(Io_url url) {

View File

@@ -59,11 +59,11 @@ public class Io_download_fmt {
prog_pct = 0;
prog_rate = 0;
prog_left = 0;
time_bgn = time_prv = Env_.TickCount();
time_bgn = time_prv = System_.Ticks();
time_checkpoint = 0;
}
public void Prog(int prog_read) {
time_now = Env_.TickCount();
time_now = System_.Ticks();
time_dif = time_now - time_bgn; if (time_dif == 0) time_dif = 1; // avoid div by zero error below
prog_done += prog_read;
time_checkpoint += time_now - time_prv;
@@ -84,7 +84,7 @@ public class Io_download_fmt {
usr_dlg.Prog_none("", "prog", prog_msg);
}
public void Term() {
time_end = Env_.TickCount();
time_end = System_.Ticks();
// prog_rate = (prog_done * 1000) / (time_dif);
// prog_pct = (prog_done * 10000) / src_len; // 100 00 to get 2 decimal places; EX: .1234 -> 1234 -> 12.34%
// prog_left = (1000 * (src_len - prog_done)) / prog_rate;

View File

@@ -43,12 +43,12 @@ class Io_download_fmt_fxt {
if (fmt == null) {
fmt = new Io_download_fmt();
}
Env_.TickCount_Test = 0;
System_.Ticks__test_set(0);
prog_done = prog_rate = prog_pct = prog_left = -1;
prog_msg = null;
return this;
} Io_download_fmt fmt;
public Io_download_fmt_fxt Now_add_f(int v) {Env_.TickCount_Test += v; return this;}
public Io_download_fmt_fxt Now_add_f(int v) {System_.Ticks__test_add(v); return this;}
public Io_download_fmt_fxt Prog_done_(int v) {prog_done = v; return this;} long prog_done = -1;
public Io_download_fmt_fxt Prog_pct_ (int v) {prog_pct = v; return this;} long prog_pct = -1;
public Io_download_fmt_fxt Prog_rate_(int v) {prog_rate = v; return this;} long prog_rate = -1;

View File

@@ -19,22 +19,22 @@ package gplx.core.logs; import gplx.*; import gplx.core.*;
public abstract class Gfo_log__base implements Gfo_log {
private long time_prv = 0;
public void Warn(String msg, Object... args) {
long time = gplx.core.envs.Env_.TickCount();
long time = gplx.core.envs.System_.Ticks();
long elapsed = time_prv == 0 ? 0 : time - time_prv;
Exec(Gfo_log_itm.Type__warn, time, elapsed, msg, args);
}
public void Note(String msg, Object... args) {
long time = gplx.core.envs.Env_.TickCount();
long time = gplx.core.envs.System_.Ticks();
long elapsed = time_prv == 0 ? 0 : time - time_prv;
Exec(Gfo_log_itm.Type__note, time, elapsed, msg, args);
}
public void Info(String msg, Object... args) {
long time = gplx.core.envs.Env_.TickCount();
long time = gplx.core.envs.System_.Ticks();
long elapsed = time_prv == 0 ? 0 : time - time_prv;
Exec(Gfo_log_itm.Type__info, time, elapsed, msg, args);
}
public void Prog(String msg, Object... args) {
long time = gplx.core.envs.Env_.TickCount();
long time = gplx.core.envs.System_.Ticks();
long elapsed = time_prv == 0 ? 0 : time - time_prv;
Exec(Gfo_log_itm.Type__prog, time, elapsed, msg, args);
}

View File

@@ -21,6 +21,7 @@ public class Int_obj_ref {
public int Val() {return val;} public Int_obj_ref Val_(int v) {val = v; return this;} int val;
public int Val_add() {val++; return val;}
public int Val_add_post() {return val++;}
public int Val_add_pre() {return ++val;}
public int Val_add(int v) {val += v; return val;}
public Int_obj_ref Val_zero_() {val = 0; return this;}
public Int_obj_ref Val_neg1_() {val = -1; return this;}

View File

@@ -21,6 +21,7 @@ public class Gftest {
private static final Bry_bfr bfr = Bry_bfr_.New();
public static void Eq__ary(int[] expd, int[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__int, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(long[] expd, long[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__long, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary__lines(String expd, byte[] actl, String msg_fmt, Object... msg_args) {Eq__ary__lines(expd, String_.new_u8(actl), msg_fmt, msg_args);}
public static void Eq__ary__lines(String expd, String actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bry, Bry_split_.Split_lines(Bry_.new_u8(expd)), Bry_split_.Split_lines(Bry_.new_u8(actl)), msg_fmt, msg_args);}
public static void Eq__ary(String[] expd, String[] actl) {Eq__array(Type_adp_.Tid__bry, Bry_.Ary(expd), Bry_.Ary(actl), "no_msg");}
public static void Eq__ary(String[] expd, String[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bry, Bry_.Ary(expd), Bry_.Ary(actl), msg_fmt, msg_args);}
@@ -51,6 +52,11 @@ public class Gftest {
bfr.Add(Bry__line_end);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
public static void Eq__obj_or_null(Object expd, Object actl) {
if (expd == null) expd = Str__null;
if (actl == null) actl = Str__null;
Eq__str(Object_.Xto_str_or(expd, Str__null), Object_.Xto_str_or(actl, null), Str__null);
}
public static void Eq__str(String expd, byte[] actl, String msg_fmt, Object... msg_args) {Eq__str(expd, String_.new_u8(actl), msg_fmt, msg_args);}
public static void Eq__str(String expd, byte[] actl) {Eq__str(expd, String_.new_u8(actl), null);}
public static void Eq__str(String expd, String actl) {Eq__str(expd, actl, null);}
@@ -181,8 +187,9 @@ public class Gftest {
}
return rv;
}
private static final String Str__null = "<<NULL>>";
private static final byte[] Bry__item__eq_n = Bry_.new_a7("!= ") // Bry__item__eq_y = Bry_.new_a7("== "),
, Bry__null = Bry_.new_a7("<<NULL>>")
, Bry__null = Bry_.new_a7(Str__null)
, Bry__line_bgn = Bry_.new_a7("\n************************************************************************************************\n")
, Bry__line_mid = Bry_.new_a7("\n------------------------------------------------------------------------------------------------\n")
, Bry__line_end = Bry_.new_a7( "________________________________________________________________________________________________")

View File

@@ -60,7 +60,7 @@ public class PerfLogMgr_fxt {
}
class PerfLogTmr {
public void Bgn() {bgn = Env_.TickCount();} long bgn;
public long ElapsedMilliseconds() {return Env_.TickCount() - bgn; }
public void Bgn() {bgn = System_.Ticks();} long bgn;
public long ElapsedMilliseconds() {return System_.Ticks() - bgn; }
public static PerfLogTmr new_() {return new PerfLogTmr();} PerfLogTmr() {}
}

View File

@@ -24,7 +24,7 @@ class Thread_halt_wkr implements Gfo_invk {
public Thread_halt_wkr(Thread_adp_mgr mgr, Thread_halt_itm itm, Thread_halt_cbk cbk, int sleep_time, int quit_time) {
this.mgr = mgr; this.thread = itm.Thread; this.thread_key = itm.Key; this.cbk = cbk;
this.sleep_time = sleep_time; this.quit_time = quit_time;
this.bgn_time = gplx.core.envs.Env_.TickCount();
this.bgn_time = gplx.core.envs.System_.Ticks();
}
private void Halt() {
// first, cancel the thread
@@ -32,7 +32,7 @@ class Thread_halt_wkr implements Gfo_invk {
// now check if canceled; interrupt if not;
while (true) {
long time_now = gplx.core.envs.Env_.TickCount();
long time_now = gplx.core.envs.System_.Ticks();
boolean halted = false, interrupted = false;
if (thread.Thread__is_alive()) { // thread is still alive
if ( !thread.Thread__cancelable() // itm is not cancelable