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

v2.10.3.1

This commit is contained in:
gnosygnu
2015-10-18 22:17:57 -04:00
parent 8e18af05b6
commit 4f43f51b18
1935 changed files with 12500 additions and 12889 deletions

View File

@@ -6,7 +6,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/100_core"/>
<classpathentry combineaccessrules="false" kind="src" path="/140_dbs"/>
<classpathentry combineaccessrules="false" kind="src" path="/150_gfui"/>
<classpathentry kind="lib" path="lib/luaj_xowa.jar"/>
<classpathentry kind="lib" path="lib/jtidy_xowa.jar"/>
<classpathentry kind="lib" path="lib/luaj_xowa.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -22,5 +22,5 @@ public class Bry_comparer implements ComparerAble {
byte[] lhs = (byte[])lhsObj, rhs = (byte[])rhsObj;
return Bry_.Compare(lhs, 0, lhs.length, rhs, 0, rhs.length);
}
public static final Bry_comparer _ = new Bry_comparer(); Bry_comparer() {}
public static final Bry_comparer Instance = new Bry_comparer(); Bry_comparer() {}
}

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.caches; import gplx.*; import gplx.core.*;
import gplx.core.consoles.*;
public class Gfo_cache_mgr {
private Ordered_hash hash = Ordered_hash_.new_bry_();
private Ordered_hash recent = Ordered_hash_.new_bry_();
private Ordered_hash hash = Ordered_hash_.New_bry();
private Ordered_hash recent = Ordered_hash_.New_bry();
public int Max_size() {return max_size;} public Gfo_cache_mgr Max_size_(int v) {max_size = v; return this;} private int max_size;
public int Reduce_by() {return reduce_by;} public Gfo_cache_mgr Reduce_by_(int v) {reduce_by = v; return this;} private int reduce_by;
public int Cur_size() {return cur_size;} private int cur_size;
@@ -65,7 +65,7 @@ public class Gfo_cache_mgr {
hash.Add(key, itm);
}
public void Reduce_recent() {
// Console_adp__sys.I.WriteLine("reducing");
// Console_adp__sys.Instance.WriteLine("reducing");
int len = recent.Count();
for (int i = 0; i < len; i++) {
Gfo_cache_data itm = (Gfo_cache_data)recent.Get_at(i);
@@ -74,7 +74,7 @@ public class Gfo_cache_mgr {
recent.Clear();
}
public void Reduce_cache() {
Console_adp__sys.I.Write_str_w_nl("compacting:");
Console_adp__sys.Instance.Write_str_w_nl("compacting:");
// hash.Sort();
// int len = hash.Count();
// List_adp deleted = List_adp_.new_();

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.caches; import gplx.*; import gplx.core.*;
public class Gfo_cache_mgr_base {
private Ordered_hash hash = Ordered_hash_.new_bry_();
private Ordered_hash hash = Ordered_hash_.New_bry();
public int Compress_max() {return compress_max;} public void Compress_max_(int v) {compress_max = v;} private int compress_max = 16;
public int Compress_to() {return compress_to;} public void Compress_to_(int v) {compress_to = v;} private int compress_to = 8;
protected Object Base_get_or_null(byte[] key) {

View File

@@ -46,7 +46,7 @@ class Io_url_exists_mgr {
byte[] url_key = url.RawBry();
Object rv_obj = cache_mgr.Get_or_null(url_key);
if (rv_obj != null) return ((Bool_obj_ref)rv_obj).Val(); // cached val exists; use it
boolean exists = Io_mgr.I.ExistsFil(url);
boolean exists = Io_mgr.Instance.ExistsFil(url);
cache_mgr.Add(url_key, Bool_obj_ref.new_(exists));
return exists;
}

View File

@@ -1,113 +0,0 @@
/*
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.consoles; import gplx.*; import gplx.core.*;
public class App_cmd_arg {
App_cmd_arg(byte tid, byte val_tid, String key, boolean reqd) {this.tid = tid; this.val_tid = val_tid; this.key = key; this.reqd = reqd;}
public byte Tid() {return tid;} private byte tid;
public byte Val_tid() {return val_tid;} public App_cmd_arg Val_tid_(byte v) {val_tid = v; return this;} private byte val_tid;
public String Val_tid_str() {
switch (val_tid) {
case Val_tid_string: return "string";
case Val_tid_yn: return "yes_no";
case Val_tid_url: return "path";
default: return "unknown";
}
}
public String Key() {return key;} private String key;
public boolean Reqd() {return reqd;} private boolean reqd;
public String Reqd_str() {return reqd ? "required" : "optional";}
public boolean Dirty() {return dirty;} public App_cmd_arg Dirty_(boolean v) {this.dirty = v; return this;} private boolean dirty;
public String Note() {return note;} public App_cmd_arg Note_(String v) {note = v; return this;} private String note;
public String Example() {return example;}
public App_cmd_arg Example_(String v) {example = v; return this;} private String example;
public App_cmd_arg Example_url_(String v) {
Example_(v);
val_tid = Val_tid_url;
return this;
}
public App_cmd_arg Example_list_str_(String v) {
example = String_.Concat_with_obj(" ", v);
val_tid = Val_tid_list_string;
return this;
}
public Object Val() {return val;} public App_cmd_arg Val_(Object v) {this.val = v; return this;} Object val;
public Object Dflt() {return dflt;} public App_cmd_arg Dflt_(Object v) {dflt = v; return this;} Object dflt;
public boolean Val_as_bool() {return Bool_.cast(val);}
public String Val_as_str_or(String or) {return val == null ? or : (String)val;}
public String Val_as_str() {return (String)val;}
public int Val_as_int_or(int or) {return val == null ? or : Int_.parse_or((String)val, or);}
public Io_url Val_as_url_rel_dir_or(Io_url owner_dir, Io_url or) {return Val_as_url_rel_url_or(owner_dir, or, true);}
public Io_url Val_as_url_rel_fil_or(Io_url owner_dir, Io_url or) {return Val_as_url_rel_url_or(owner_dir, or, false);}
public Io_url Val_as_url_rel_url_or(Io_url owner_dir, Io_url or, boolean dir) {return Val_as_url_rel_url_or(Val_as_str(), owner_dir, or, dir);}
public boolean Parse(App_cmd_mgr mgr, String[] s_ary) {
dirty = true;
String s = s_ary.length == 0 ? "" : s_ary[0];
switch (val_tid) {
case Val_tid_string:
val = s;
break;
case Val_tid_url: // NOTE: do not parse urls as it can either be absolute (C:\dir\fil.txt) or relative (fil.txt). relative cannot be parsed without knowing owner dir
val = s;
break;
case Val_tid_yn:
int v_int = Yn.parse_as_int(s);
if (v_int == Bool_.__int) {return mgr.Errs_add(Err_parse_yn, "value must be either y or n: ~{0}", s);}
val = v_int == Bool_.Y_int;
break;
}
return true;
} public static final String Err_parse_yn = "parse_yn";
public App_cmd_arg Clone() {
App_cmd_arg rv = new App_cmd_arg(tid, val_tid, key, reqd);
rv.val = val;
rv.dflt = dflt;
rv.note = note;
rv.example = example;
return rv;
}
public static App_cmd_arg req_(String key) {return new App_cmd_arg(Tid_general, Val_tid_string, key, true);}
public static App_cmd_arg opt_(String key) {return new App_cmd_arg(Tid_general, Val_tid_string, key, false);}
public static App_cmd_arg new_(String key, boolean reqd) {return new App_cmd_arg(Tid_general, Val_tid_string, key, reqd);}
public static App_cmd_arg sys_help_() {return sys_help_("help");}
public static App_cmd_arg sys_help_(String key) {return new App_cmd_arg(Tid_help, Val_tid_string, key, false);}
public static App_cmd_arg sys_header_(String key) {return new App_cmd_arg(Tid_header, Val_tid_yn, key, false);}
public static App_cmd_arg sys_args_(String key) {return new App_cmd_arg(Tid_args, Val_tid_yn, key, false);}
public static final byte Tid_general = 0, Tid_help = 1, Tid_header = 2, Tid_args = 3;
public static final byte Val_tid_string = 0, Val_tid_yn = 1, Val_tid_url = 2, Val_tid_list_string = 3;
public static Io_url Val_as_url_rel_url_or(String val_str, Io_url owner_dir, Io_url or, boolean dir) {
if (val_str == null) return or;
byte val_has_dir = Op_sys.Tid_nil; // if val_str is dir, use it literally (only checking for closing dir_spr); if it's just a name, assume a simple relative path
if (String_.Has(val_str, Op_sys.Lnx.Fsys_dir_spr_str()))
val_has_dir = Op_sys.Tid_lnx;
else if (String_.Has(val_str, Op_sys.Wnt.Fsys_dir_spr_str()))
val_has_dir = Op_sys.Tid_wnt;
if (val_has_dir != Op_sys.Tid_nil) {
if (dir) { // NOTE: need to do extra logic to guarantee trailing "/"; JAVA:7 apparently strips "/dir/" to "/dir" when passed in as argument; DATE:2013-03-20
String val_dir_spr = val_has_dir == Op_sys.Tid_lnx ? Op_sys.Lnx.Fsys_dir_spr_str() : Op_sys.Wnt.Fsys_dir_spr_str();
if (!String_.Has_at_end(val_str, val_dir_spr))
val_str += val_dir_spr;
return Io_url_.new_dir_(val_str);
}
else
return Io_url_.new_fil_(val_str);
}
else
return dir ? owner_dir.GenSubDir(val_str) : owner_dir.GenSubFil(val_str);
}
}

View File

@@ -1,162 +0,0 @@
/*
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.consoles; import gplx.*; import gplx.core.*;
import gplx.core.strings.*;
public class App_cmd_mgr {
private Ordered_hash expd_args = Ordered_hash_.new_(), actl_args = Ordered_hash_.new_();
private List_adp tmp_vals = List_adp_.new_(); private String[] orig_ary;
public App_cmd_mgr Msg_root_(Gfo_msg_root v) {msg_root = v; return this;} private Gfo_msg_root msg_root = Gfo_msg_root._;
public String Arg_prefix() {return arg_prefix;} public App_cmd_mgr Arg_prefix_(String v) {arg_prefix = v; prefix_len = String_.Len(v); return this;} private String arg_prefix = "--"; int prefix_len = 2;
public void Clear() {expd_args.Clear(); actl_args.Clear(); errs.Clear(); key_help = key_header = null;}
public int Actl_len() {return actl_args.Count();}
public App_cmd_arg[] Actl_ary() {return (App_cmd_arg[])actl_args.To_ary(App_cmd_arg.class);}
public App_cmd_mgr Expd_add_many(App_cmd_arg... ary) {for (App_cmd_arg o : ary) Expd_add(o); return this;}
public App_cmd_mgr Expd_add(App_cmd_arg prm) {
expd_args.Add(prm.Key(), prm);
switch (prm.Tid()) {
case App_cmd_arg.Tid_help: key_help = prm.Key(); break;
case App_cmd_arg.Tid_header: key_header = prm.Key(); break;
case App_cmd_arg.Tid_args: key_args = prm.Key(); break;
}
return this;
} String key_help, key_header, key_args;
public boolean Args_process(String[] ary) {Args_parse(ary); return errs.Count() == 0;}
private void Args_parse(String[] ary) {
this.orig_ary = ary;
App_cmd_arg arg = null;
int ary_len = ary.length;
actl_args = Expd_copy();
errs.Clear(); tmp_vals.Clear();
for (int i = 0; i < ary_len; i++) {
String itm = ary[i];
if (String_.Has_at_bgn(itm, arg_prefix)) { // key
if (arg != null) {
String[] tmp_ary = tmp_vals.To_str_ary();
if (!arg.Parse(this, tmp_ary)) {continue;}
tmp_vals.Clear();
}
String key = String_.Mid(itm, prefix_len);
Object o = actl_args.Get_by(key);
if (o == null) {Errs_add(Err_argument_is_unknown, "unknown argument: '~{0}'", key); continue;}
arg = (App_cmd_arg)o;
if (arg.Dirty()) {Errs_add(Err_argument_is_duplicate, "duplicate argument: '~{0}'", key); continue;}
arg.Dirty_(true);
}
else {
if (arg == null) {Errs_add(Err_argument_is_invalid_key, "argument key must be prefixed with '~{0}'; EX: '~{0}~{1}'", arg_prefix, itm); continue;} // should only happen if 1st itm is not "--%"
// if (arg.Val() != null) return Errs_add("argument_is_already_valued", "argument can only take one value: '{0}'", itm);
tmp_vals.Add(itm);
}
}
if (arg != null) {
String[] tmp_ary = tmp_vals.To_str_ary();
arg.Parse(this, tmp_ary);
tmp_vals.Clear();
}
int len = actl_args.Count();
for (int i = 0; i < len; i++) {
arg = (App_cmd_arg)actl_args.Get_at(i);
if (arg.Reqd() && !arg.Dirty()) {Errs_add(Err_argument_is_required, "argument is required: '~{0}'", arg.Key()); continue;}
if (!arg.Dirty() && arg.Dflt() != null) arg.Val_(arg.Dflt());
}
} public static final String Err_argument_is_duplicate = "argument_is_duplicate", Err_argument_is_required = "argument_is_required", Err_argument_is_unknown = "argument_is_unknown", Err_argument_is_invalid_key = "argument_is_invalid_key";
public String Fmt_hdr() {return fmt_hdr;} public App_cmd_mgr Fmt_hdr_(String v) {fmt_hdr = v; return this;} private String fmt_hdr = "";
public App_cmd_arg Args_get(String key) {return (App_cmd_arg)actl_args.Get_by(key);}
public boolean Args_has_help() {
App_cmd_arg arg = (App_cmd_arg)actl_args.Get_by(key_help);
return arg != null && arg.Dirty();
}
public App_cmd_mgr Print_header(Gfo_usr_dlg usr_dlg) {
App_cmd_arg arg_hdr = (App_cmd_arg)actl_args.Get_by(key_header);
if (arg_hdr == null) return this; // no key_header specified; assume header shouldn't be printed
if (!arg_hdr.Val_as_bool()) return this; // key_header specified as false; return;
usr_dlg.Note_gui_none(GRP_KEY, "print.header", fmt_hdr);
return this;
}
public void Print_args(Gfo_usr_dlg usr_dlg) {
sb.Add_char_crlf();
sb.Add_str_w_crlf("arguments:");
int len = orig_ary.length;
if (len == 0) {
sb.Add_fmt_line(" **** NONE ****");
sb.Add_fmt_line(" use --help to show help");
}
else {
for (int i = 0; i < len; i++)
sb.Add_fmt_line(" [{0}] = '{1}'", i, orig_ary[i]);
}
usr_dlg.Note_none(GRP_KEY, "print.args", sb.Xto_str_and_clear());
} String_bldr sb = String_bldr_.new_();
public void Print_fail(Gfo_usr_dlg usr_dlg) {
sb.Add("** error: ").Add_char_crlf();
int len = errs.Count();
for (int i = 0; i < len; i++) {
Gfo_msg_data data = (Gfo_msg_data)errs.Get_at(i);
sb.Add_fmt_line(" " + data.Gen_str_ary());
}
sb.Add_char_crlf();
sb.Add_str_w_crlf(String_.Repeat("-", 80));
usr_dlg.Note_none(GRP_KEY, "print.fail", sb.Xto_str_and_clear());
}
public void Print_help(Gfo_usr_dlg usr_dlg, String app_name) {
sb.Add_str_w_crlf("example:");
sb.Add_fmt(" java -jar {0}.jar", app_name);
int key_max = 0, tid_max = 0;
int len = expd_args.Count();
for (int i = 0; i < len; i++) {
App_cmd_arg arg = (App_cmd_arg)expd_args.Get_at(i);
if (arg.Tid() != App_cmd_arg.Tid_general) continue; // skip header, help
sb.Add(" ").Add(arg_prefix).Add(arg.Key()).Add(" ").Add(arg.Example());
int key_len = String_.Len(arg.Key()); if (key_len > key_max) key_max = key_len;
int tid_len = String_.Len(String_.Format("[{0}:{1}]", arg.Reqd_str(), arg.Val_tid_str())); if (tid_len > tid_max) tid_max = tid_len;
} sb.Add_char_crlf();
sb.Add_char_crlf();
sb.Add_str_w_crlf("detail:");
for (int i = 0; i < len; i++) {
App_cmd_arg arg = (App_cmd_arg)expd_args.Get_at(i);
// if (arg.Tid() != App_cmd_arg.Tid_general) continue; // skip header, help
sb.Add(" ").Add(arg_prefix).Add(String_.PadEnd(arg.Key(), key_max + 1, " ")).Add(String_.PadEnd(String_.Format("[{0}:{1}]", arg.Reqd_str(), arg.Val_tid_str()), tid_max, " "));
if (arg.Dflt() != null)
sb.Add_fmt(" default={0}", arg.Dflt());
sb.Add_char_crlf();
if (arg.Note() != null)
sb.Add(" ").Add(arg.Note()).Add_char_crlf();
// for (int j = 0; j < arg.Itms().Count(); j++) {
// App_arg_info expdInf = (App_arg_info)arg.Itms().Get_at(j);
// sb.Add(" ").Add(String_.PadEnd(expdInf.Key(), key_max + 1, " ")).Add_str_w_crlf(expdInf.Descrip());
// }
}
usr_dlg.Note_gui_none(GRP_KEY, "print.info", sb.Xto_str_and_clear());
}
private Ordered_hash Expd_copy() {
Ordered_hash rv = Ordered_hash_.new_();
int expd_len = expd_args.Count();
for (int i = 0 ; i < expd_len; i++) {
App_cmd_arg arg = (App_cmd_arg)expd_args.Get_at(i);
rv.Add(arg.Key(), arg.Clone());
}
return rv;
}
public boolean Errs_add(String key, String fmt, Object... vals) {
errs.Add(msg_root.Data_new_many(Gfo_msg_itm_.Cmd_warn, GRP_KEY, key, fmt, vals));
return false;
}
public int Errs_len() {return errs.Count();} private List_adp errs = List_adp_.new_();
public Gfo_msg_data Errs_get(int i) {return (Gfo_msg_data)errs.Get_at(i);}
private static final String GRP_KEY = "gplx.app.app_cmd_mgr";
}

View File

@@ -1,142 +0,0 @@
/*
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.consoles; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.tests.*;
public class App_cmd_mgr_tst {
App_cmd_mgr_fxt fxt = new App_cmd_mgr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {
fxt .Expd_(fxt.arg_("a"), fxt.arg_("b"))
.Args_process("--a", "0", "--b", "1")
.Tst_errs_none()
.Tst_actl(fxt.chkr_("a", "0"), fxt.chkr_("b", "1"));
;
}
@Test public void Dflt() {
fxt .Expd_(fxt.arg_("a").Val_tid_(App_cmd_arg.Val_tid_yn).Dflt_(true));
fxt .Args_process("--a", "n").Tst_actl(fxt.chkr_("a", false)); // if val, use it
fxt .Args_process().Tst_actl(fxt.chkr_("a", true)); // if no val, use default
}
@Test public void Header_y() {
fxt.Expd_(App_cmd_arg.sys_header_("print_license")).Args_process("--print_license", "y");
fxt.Mgr().Fmt_hdr_("test_hdr").Print_header(fxt.Usr_dlg());
fxt.tst_write("test_hdr");
fxt.Clear();
}
@Test public void Header_n() {
fxt.Expd_(App_cmd_arg.sys_header_("print_license")).Args_process("--print_license", "n");
fxt.Mgr().Fmt_hdr_("test_hdr").Print_header(fxt.Usr_dlg());
fxt.tst_write();
}
// @Test public void Help_y() {
// fxt.Expd_(App_cmd_arg.sys_header_("help")).Args_process("--help");
//// fxt.Mgr().Fmt_help_grp("bgn ~{args} end").Fmt_help_itm_("~{0} ~{1}").Print_header(fxt.Status_mgr());
//// fxt.Tst_write("test_hdr");
// fxt.Clear();
// }
@Test public void Err_parse_yn() {
fxt .Expd_(fxt.arg_("a").Val_tid_(App_cmd_arg.Val_tid_yn))
.Args_process("--a", "x")
.Tst_errs(App_cmd_arg.Err_parse_yn);
;
}
@Test public void Err_reqd() {
fxt .Expd_(fxt.arg_("a", true), fxt.arg_("b", false))
.Args_process("--b", "1")
.Tst_errs(App_cmd_mgr.Err_argument_is_required);
;
}
@Test public void Err_dupe() {
fxt .Expd_(fxt.arg_("a"))
.Args_process("--a", "0", "--a", "0")
.Tst_errs(App_cmd_mgr.Err_argument_is_duplicate);
;
}
@Test public void Err_unknown() {
fxt .Expd_(fxt.arg_("a"))
.Args_process("--b")
.Tst_errs(App_cmd_mgr.Err_argument_is_unknown);
;
}
@Test public void Err_key_invalid() {
fxt .Expd_(fxt.arg_("a"))
.Args_process("a")
.Tst_errs(App_cmd_mgr.Err_argument_is_invalid_key);
;
}
@Test public void Val_as_url_rel_dir_or() { // PURPOSE: "/xowa" -> "/xowa/"
String root_dir = Op_sys.Cur().Tid_is_wnt() ? "C:\\" : "/", dir_spr = Op_sys.Cur().Fsys_dir_spr_str();
Tst_val_as_url_rel_dir_or(root_dir, dir_spr, root_dir + "sub" , root_dir + "sub" + dir_spr); // /sub -> /sub/
Tst_val_as_url_rel_dir_or(root_dir, dir_spr, root_dir + "sub" + dir_spr , root_dir + "sub" + dir_spr); // /sub/ -> /sub/
Tst_val_as_url_rel_dir_or(root_dir, dir_spr, "sub" , root_dir + "dir" + dir_spr + "sub" + dir_spr); // sub -> /dir/sub/
}
private void Tst_val_as_url_rel_dir_or(String root_dir, String dir_spr, String val, String expd) {
Io_url actl = fxt.arg_("key").Val_(val).Val_as_url_rel_dir_or(Io_url_.new_dir_(root_dir).GenSubDir("dir"), null);
Tfds.Eq(expd, actl.Raw());
}
}
class App_cmd_mgr_fxt {
public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} Gfo_usr_dlg usr_dlg;
public App_cmd_mgr Mgr() {return mgr;} App_cmd_mgr mgr = new App_cmd_mgr(); Tst_mgr tst_mgr = new Tst_mgr();
public App_cmd_mgr_fxt Clear() {
if (usr_dlg == null) {
usr_dlg = Gfo_usr_dlg_.Test();
}
mgr.Clear();
usr_dlg.Gui_wkr().Clear();
return this;
}
public App_cmd_arg arg_(String key) {return arg_(key, false);}
public App_cmd_arg arg_(String key, boolean reqd) {return App_cmd_arg.new_(key, reqd);}
public App_cmd_arg_chkr chkr_(String key, Object val) {return new App_cmd_arg_chkr(key, val);}
public App_cmd_mgr_fxt Expd_(App_cmd_arg... v) {mgr.Expd_add_many(v); return this;}
public App_cmd_mgr_fxt Args_process(String... v) {mgr.Args_process(v); return this;}
public App_cmd_mgr_fxt Tst_actl_len(int v) {Tfds.Eq(v, mgr.Actl_len()); return this;}
public App_cmd_mgr_fxt Tst_actl(App_cmd_arg_chkr... expd) {
App_cmd_arg[] actl = mgr.Actl_ary();
tst_mgr.Tst_ary("", expd, actl);
return this;
}
public App_cmd_mgr_fxt Tst_errs_none() {return Tst_errs(String_.Ary_empty);}
public App_cmd_mgr_fxt Tst_errs(String... expd) {
int len = mgr.Errs_len();
String[] actl = new String[len];
for (int i = 0; i < len; i++) {
Gfo_msg_data data = mgr.Errs_get(i);
actl[i] = data.Item().Key_str();
}
Tfds.Eq_ary_str(expd, actl);
return this;
}
public App_cmd_mgr_fxt tst_write(String... expd) {
String[] actl = ((Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr()).Xto_str_ary();
Tfds.Eq_ary_str(expd, actl);
return this;
}
}
class App_cmd_arg_chkr implements Tst_chkr {
public App_cmd_arg_chkr(String key, Object val) {this.key = key; this.val = val;} private String key; Object val;
public Class<?> TypeOf() {return App_cmd_arg.class;}
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
App_cmd_arg actl = (App_cmd_arg)actl_obj;
int err = 0;
err += mgr.Tst_val(false, path, "key", key, actl.Key());
err += mgr.Tst_val(false, path, "val", val, actl.Val());
return err;
}
}

View File

@@ -0,0 +1,55 @@
/*
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.consoles; import gplx.*; import gplx.core.*;
public class Gfo_cmd_arg_itm {
public Gfo_cmd_arg_itm(int tid, boolean reqd, String key, int val_tid) {this.tid = tid; this.reqd = reqd; this.key = key; this.val_tid = val_tid;}
public int Tid() {return tid;} private final int tid;
public boolean Reqd() {return reqd;} private final boolean reqd;
public String Key() {return key;} private final String key;
public int Val_tid() {return val_tid;} private int val_tid;
public Object Val() {return val;} public Gfo_cmd_arg_itm Val_(Object v) {this.val = v; dirty = true; return this;} private Object val;
public String Note() {return note;} public Gfo_cmd_arg_itm Note_(String v) {note = v; return this;} private String note = "";
public String Example() {return example;} public Gfo_cmd_arg_itm Example_(String v) {example = v; return this;} private String example = "";
public Object Dflt() {return dflt;} public Gfo_cmd_arg_itm Dflt_(Object v) {dflt = v; return this;} private Object dflt;
public boolean Dirty() {return dirty;} private boolean dirty;
public void Clear() {
dirty = false;
val = null;
}
public Gfo_cmd_arg_itm Example_url_(String v) {
Example_(v);
this.val_tid = Gfo_cmd_arg_itm_.Val_tid_url;
return this;
}
public String Reqd_str() {return reqd ? "required" : "optional";}
public String Val_tid_str() {
switch (val_tid) {
case Gfo_cmd_arg_itm_.Val_tid_string: return "string";
case Gfo_cmd_arg_itm_.Val_tid_yn: return "y/n";
case Gfo_cmd_arg_itm_.Val_tid_url: return "path";
default: return "unknown";
}
}
public boolean Val_as_bool() {return Bool_.cast(val);}
public String Val_as_str_or(String or) {return val == null ? or : (String)val;}
public String Val_as_str() {return (String)val;}
public int Val_as_int_or(int or) {return val == null ? or : Int_.parse_or((String)val, or);}
public Io_url Val_as_url__rel_dir_or(Io_url owner_dir, Io_url or) {return Val_as_url__rel_url_or(Bool_.Y, owner_dir, or);}
public Io_url Val_as_url__rel_fil_or(Io_url owner_dir, Io_url or) {return Val_as_url__rel_url_or(Bool_.N, owner_dir, or);}
public Io_url Val_as_url__rel_url_or(boolean to_dir, Io_url owner_dir, Io_url or) {return Gfo_cmd_arg_itm_.Val_as_url__rel_url_or(Val_as_str(), to_dir, owner_dir, or);}
}

View File

@@ -0,0 +1,47 @@
/*
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.consoles; import gplx.*; import gplx.core.*;
public class Gfo_cmd_arg_itm_ {
public static final int Tid_general = 0, Tid_system = 1;
public static final int Val_tid_string = 0, Val_tid_yn = 1, Val_tid_url = 2, Val_tid_list_string = 3;
public static Gfo_cmd_arg_itm req_(String key) {return new Gfo_cmd_arg_itm(Tid_general, Bool_.Y, key, Val_tid_string);}
public static Gfo_cmd_arg_itm opt_(String key) {return new Gfo_cmd_arg_itm(Tid_general, Bool_.N, key, Val_tid_string);}
public static Gfo_cmd_arg_itm new_(String key, boolean reqd, int val_tid) {return new Gfo_cmd_arg_itm(Tid_general, reqd , key, val_tid);}
public static Gfo_cmd_arg_itm sys_(String key) {return new Gfo_cmd_arg_itm(Tid_system , Bool_.N, key, Val_tid_yn);}
public static Gfo_cmd_arg_itm new_(int tid, String key, boolean reqd, int val_tid) {return new Gfo_cmd_arg_itm(tid , reqd , key, val_tid);}
public static Io_url Val_as_url__rel_url_or(String raw, boolean to_dir, Io_url owner_dir, Io_url or) {
if (raw == null) return or;
byte val_has_dir = Op_sys.Tid_nil; // if raw is to_dir, use it literally (only checking for closing dir_spr); if it's just a name, assume a simple relative path
if (String_.Has(raw, Op_sys.Lnx.Fsys_dir_spr_str()))
val_has_dir = Op_sys.Tid_lnx;
else if (String_.Has(raw, Op_sys.Wnt.Fsys_dir_spr_str()))
val_has_dir = Op_sys.Tid_wnt;
if (val_has_dir != Op_sys.Tid_nil) {
if (to_dir) { // NOTE: need to do extra logic to guarantee trailing "/"; JAVA:7 apparently strips "/to_dir/" to "/to_dir" when passed in as argument; DATE:2013-03-20
String val_dir_spr = val_has_dir == Op_sys.Tid_lnx ? Op_sys.Lnx.Fsys_dir_spr_str() : Op_sys.Wnt.Fsys_dir_spr_str();
if (!String_.Has_at_end(raw, val_dir_spr))
raw += val_dir_spr;
return Io_url_.new_dir_(raw);
}
else
return Io_url_.new_fil_(raw);
}
else
return to_dir ? owner_dir.GenSubDir(raw) : owner_dir.GenSubFil(raw);
}
}

View File

@@ -0,0 +1,91 @@
/*
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.consoles; import gplx.*; import gplx.core.*;
public class Gfo_cmd_arg_mgr {
private final Ordered_hash hash = Ordered_hash_.New();
private final List_adp err_list = List_adp_.new_(), tmp_vals = List_adp_.new_();
public String[] Orig_ary() {return orig_ary;} private String[] orig_ary;
public void Reset() {
hash.Clear();
this.Clear();
}
public void Clear() {
int len = hash.Count();
for (int i = 0; i < len; ++i) {
Gfo_cmd_arg_itm itm = (Gfo_cmd_arg_itm)hash.Get_at(i);
itm.Clear();
}
err_list.Clear();
}
public Gfo_cmd_arg_mgr Reg_many(Gfo_cmd_arg_itm... ary) {for (Gfo_cmd_arg_itm itm : ary) Reg(itm); return this;}
public int Len() {return hash.Count();}
public boolean Has(String k) {
Gfo_cmd_arg_itm arg = (Gfo_cmd_arg_itm)hash.Get_by(k);
return arg != null && arg.Dirty();
}
public boolean Get_by_as_bool(String k) {
Gfo_cmd_arg_itm arg = (Gfo_cmd_arg_itm)hash.Get_by(k);
return arg != null && arg.Val() != null && arg.Val_as_bool();
}
public Gfo_cmd_arg_itm Get_at(int i) {return (Gfo_cmd_arg_itm)hash.Get_at(i);}
public Gfo_cmd_arg_itm Get_by(String key) {return (Gfo_cmd_arg_itm)hash.Get_by(key);}
public void Parse(String[] orig_ary) {
this.Clear();
this.orig_ary = orig_ary; int orig_len = orig_ary.length;
Gfo_cmd_arg_itm cur_itm = null;
int orig_idx = 0;
while (true) {
boolean done = orig_idx == orig_len;
String itm = done ? "" : orig_ary[orig_idx++];
boolean itm_is_key = String_.Has_at_bgn(itm, Key_prefix); // has "--" -> is key
if ( cur_itm != null // pending itm
&& (itm_is_key || done)) { // cur arg is key ("--key2"), or all done
cur_itm.Val_(Gfo_cmd_arg_mgr_.Parse_ary_to_str(this, cur_itm.Val_tid(), tmp_vals.To_str_ary_and_clear()));
cur_itm = null;
}
if (done) break;
if (itm_is_key) {
String key = String_.Mid(itm, prefix_len);
Object o = hash.Get_by(key); if (o == null) {Errs__add(Gfo_cmd_arg_mgr_.Err__key__unknown , key); continue;}
cur_itm = (Gfo_cmd_arg_itm)o; if (cur_itm.Dirty()) {Errs__add(Gfo_cmd_arg_mgr_.Err__key__duplicate , key); continue;}
}
else {
if (cur_itm == null) {Errs__add(Gfo_cmd_arg_mgr_.Err__key__missing, itm); continue;} // should only happen if 1st itm is not "--%"
tmp_vals.Add(itm);
}
}
// calc .Reqd and .Dflt
int len = hash.Count();
for (int i = 0; i < len; ++i) {
cur_itm = (Gfo_cmd_arg_itm)hash.Get_at(i);
if (!cur_itm.Dirty()) { // arg not passed
if (cur_itm.Reqd()) // arg required but no value passed; add error
Errs__add(Gfo_cmd_arg_mgr_.Err__val__required, cur_itm.Key());
else if (cur_itm.Dflt() != null) // arg has default
cur_itm.Val_(cur_itm.Dflt());
}
}
}
public boolean Errs__exist() {return err_list.Count() > 0;}
public void Errs__add(String key, String val) {err_list.Add(key + ": " + val);}
public String[] Errs__to_str_ary() {return err_list.To_str_ary();}
public Gfo_cmd_arg_itm[] To_ary() {return (Gfo_cmd_arg_itm[])hash.To_ary(Gfo_cmd_arg_itm.class);}
private void Reg(Gfo_cmd_arg_itm defn) {hash.Add(defn.Key(), defn);}
public static final String Key_prefix = "--"; private static final int prefix_len = 2;
}

View File

@@ -0,0 +1,42 @@
/*
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.consoles; import gplx.*; import gplx.core.*;
class Gfo_cmd_arg_mgr_ {
public static final String
Err__key__unknown = "unknown key"
, Err__key__duplicate = "duplicate key"
, Err__key__missing = "first argument must be prefixed with --"
, Err__val__required = "value is required"
, Err__val__invalid__yn = "value must be either y or n"
;
public static Object Parse_ary_to_str(Gfo_cmd_arg_mgr mgr, int val_tid, String[] ary) {
String itm = ary.length == 0 ? "" : ary[0];
switch (val_tid) {
case Gfo_cmd_arg_itm_.Val_tid_string: return itm;
case Gfo_cmd_arg_itm_.Val_tid_url: return itm; // NOTE: do not parse urls as it can either be absolute (C:\dir\fil.txt) or relative (fil.txt). relative cannot be parsed without knowing owner dir
case Gfo_cmd_arg_itm_.Val_tid_yn:
int itm_as_int = Yn.parse_as_int(itm);
if (itm_as_int == Bool_.__int) {
mgr.Errs__add(Gfo_cmd_arg_mgr_.Err__val__invalid__yn, itm);
return null;
}
return itm_as_int == Bool_.Y_int;
default: throw Err_.new_unhandled(val_tid);
}
}
}

View File

@@ -0,0 +1,95 @@
/*
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.consoles; import gplx.*; import gplx.core.*;
public class Gfo_cmd_arg_mgr_printer {
private final Gfo_cmd_arg_mgr arg_mgr;
private final Bry_bfr tmp_bfr = Bry_bfr.new_();
public Gfo_cmd_arg_mgr_printer(Gfo_cmd_arg_mgr arg_mgr) {this.arg_mgr = arg_mgr;}
public boolean Print(Gfo_usr_dlg usr_dlg, String header, String app_name, String key__print_help, String key__print_header, String key__print_args) {
if (arg_mgr.Get_by_as_bool(key__print_header))
usr_dlg.Note_gui_none("", "", header);
if (arg_mgr.Errs__exist()) {
usr_dlg.Note_none("", "", Get_args());
usr_dlg.Note_none("", "", Get_fail());
usr_dlg.Note_none("", "", Get_help(app_name));
return false;
}
if (arg_mgr.Has(key__print_help)) {
usr_dlg.Note_none("", "", Get_help(app_name));
return false;
}
if (arg_mgr.Get_by_as_bool(key__print_args))
usr_dlg.Note_none("", "", Get_args());
return true;
}
public String Get_args() {
tmp_bfr.Add_byte_nl();
tmp_bfr.Add_str_a7_w_nl("arguments:");
String[] orig_ary = arg_mgr.Orig_ary();
int len = orig_ary.length;
if (len == 0) {
tmp_bfr.Add_str_a7_w_nl(" **** NONE ****");
tmp_bfr.Add_str_a7_w_nl(" use --help to show help");
}
else {
for (int i = 0; i < len; i++) {
String line = String_.Format(" [{0}] = '{1}'", i, orig_ary[i]);
tmp_bfr.Add_str_u8_w_nl(line);
}
}
return tmp_bfr.To_str_and_clear();
}
public String Get_fail() {
tmp_bfr.Add_str_a7_w_nl("** error: ");
String[] err_ary = arg_mgr.Errs__to_str_ary();
int len = err_ary.length;
for (int i = 0; i < len; ++i)
tmp_bfr.Add_str_u8_w_nl(" " + err_ary[i]);
tmp_bfr.Add_byte_nl();
tmp_bfr.Add_str_a7_w_nl(String_.Repeat("-", 80));
return tmp_bfr.To_str_and_clear();
}
public String Get_help(String app_name) {
tmp_bfr.Add_str_a7_w_nl("example:");
tmp_bfr.Add_str_a7(String_.Format(" java -jar {0}.jar", app_name));
int key_max = 0, tid_max = 0;
int len = arg_mgr.Len();
for (int i = 0; i < len; i++) {
Gfo_cmd_arg_itm arg = arg_mgr.Get_at(i); if (arg.Tid() != Gfo_cmd_arg_itm_.Tid_general) continue; // skip header, help
tmp_bfr.Add_str_a7(" ").Add_str_a7(Gfo_cmd_arg_mgr.Key_prefix).Add_str_u8(arg.Key()).Add_str_a7(" ").Add_str_u8(arg.Example());
int key_len = String_.Len(arg.Key()); if (key_len > key_max) key_max = key_len;
int tid_len = String_.Len(String_.Format("[{0}:{1}]", arg.Reqd_str(), arg.Val_tid_str())); if (tid_len > tid_max) tid_max = tid_len;
}
tmp_bfr.Add_byte_nl().Add_byte_nl();
tmp_bfr.Add_str_a7_w_nl("detail:");
for (int i = 0; i < len; i++) {
Gfo_cmd_arg_itm arg = (Gfo_cmd_arg_itm)arg_mgr.Get_at(i);
tmp_bfr.Add_str_a7(" ").Add_str_a7(Gfo_cmd_arg_mgr.Key_prefix)
.Add_str_u8(String_.PadEnd(arg.Key(), key_max + 1, " "))
.Add_str_u8(String_.PadEnd(String_.Format("[{0}:{1}]", arg.Reqd_str(), arg.Val_tid_str()), tid_max, " "));
if (arg.Dflt() != null) {
String dflt_val = Object_.Xto_str_strict_or_null_mark(arg.Dflt());
tmp_bfr.Add_str_u8(String_.Format(" default={0}", dflt_val));
}
tmp_bfr.Add_byte_nl();
if (arg.Note() != null)
tmp_bfr.Add_str_a7(" ").Add_str_u8(arg.Note()).Add_byte_nl();
}
return tmp_bfr.To_str_and_clear();
}
}

View File

@@ -0,0 +1,123 @@
/*
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.consoles; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.tests.*;
public class Gfo_cmd_arg_mgr_tst {
@Before public void init() {fxt.Clear();} private final Gfo_cmd_arg_mgr_fxt fxt = new Gfo_cmd_arg_mgr_fxt();
@Test public void Val__many() {
fxt.Init_args(fxt.Make_arg("a"), fxt.Make_arg("b"));
fxt.Exec_process("--a", "0", "--b", "1");
fxt.Test_errs_none();
fxt.Test_actl(fxt.Make_chkr("a", "0"), fxt.Make_chkr("b", "1"));
}
@Test public void Val__yn() {
fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn), fxt.Make_arg("b", Gfo_cmd_arg_itm_.Val_tid_yn));
fxt.Exec_process("--a", "y", "--b", "n");
fxt.Test_errs_none();
fxt.Test_actl(fxt.Make_chkr("a", Bool_.Y), fxt.Make_chkr("b", Bool_.N));
}
@Test public void Dflt() {
fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn).Dflt_(Bool_.Y));
fxt.Exec_process("--a", "n").Test_actl(fxt.Make_chkr("a", Bool_.N)); // if val, use it
fxt.Exec_process() .Test_actl(fxt.Make_chkr("a", Bool_.Y)); // if no val, use default
}
@Test public void Err__key__unknown() {
fxt.Init_args(fxt.Make_arg("a"));
fxt.Exec_process("--b");
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__key__unknown);
}
@Test public void Err__key__missing() {
fxt.Init_args(fxt.Make_arg("a"));
fxt.Exec_process("a");
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__key__missing);
}
@Test public void Err__key__dupe() {
fxt.Init_args(fxt.Make_arg("a"));
fxt.Exec_process("--a", "0", "--a", "0");
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__key__duplicate);
}
@Test public void Err__val__reqd() {
fxt.Init_args(fxt.Make_arg("a", Bool_.Y), fxt.Make_arg("b", Bool_.N));
fxt.Exec_process("--b", "1");
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__val__required);
}
@Test public void Err__val__parse__yn() {
fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn));
fxt.Exec_process("--a", "x");
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__val__invalid__yn);
}
@Test public void Val_as_url_rel_dir_or() { // PURPOSE: "/xowa" -> "/xowa/"
String root_dir = Op_sys.Cur().Tid_is_wnt() ? "C:\\" : "/", dir_spr = Op_sys.Cur().Fsys_dir_spr_str();
fxt.Test_val_as_url_rel_dir_or(root_dir, dir_spr, root_dir + "sub" , root_dir + "sub" + dir_spr); // /sub -> /sub/
fxt.Test_val_as_url_rel_dir_or(root_dir, dir_spr, root_dir + "sub" + dir_spr , root_dir + "sub" + dir_spr); // /sub/ -> /sub/
fxt.Test_val_as_url_rel_dir_or(root_dir, dir_spr, "sub" , root_dir + "dir" + dir_spr + "sub" + dir_spr); // sub -> /dir/sub/
}
}
class Gfo_cmd_arg_mgr_fxt {
private final Tst_mgr tst_mgr = new Tst_mgr();
public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} Gfo_usr_dlg usr_dlg;
public Gfo_cmd_arg_mgr Mgr() {return mgr;} private final Gfo_cmd_arg_mgr mgr = new Gfo_cmd_arg_mgr();
public Gfo_cmd_arg_mgr_fxt Clear() {
if (usr_dlg == null)
usr_dlg = Gfo_usr_dlg_.Test();
mgr.Reset();
usr_dlg.Gui_wkr().Clear();
return this;
}
public Gfo_cmd_arg_itm Make_arg(String key) {return Make_arg(key, false);}
public Gfo_cmd_arg_itm Make_arg(String key, int tid) {return Make_arg(key, false, tid);}
public Gfo_cmd_arg_itm Make_arg(String key, boolean reqd) {return Gfo_cmd_arg_itm_.new_(key, reqd, Gfo_cmd_arg_itm_.Val_tid_string);}
public Gfo_cmd_arg_itm Make_arg(String key, boolean reqd, int tid) {return Gfo_cmd_arg_itm_.new_(key, reqd, tid);}
public Gfo_cmd_itm_chkr Make_chkr(String key, Object val) {return new Gfo_cmd_itm_chkr(key, val);}
public Gfo_cmd_arg_mgr_fxt Init_args(Gfo_cmd_arg_itm... v) {mgr.Reg_many(v); return this;}
public Gfo_cmd_arg_mgr_fxt Exec_process(String... v) {mgr.Parse(v); return this;}
public Gfo_cmd_arg_mgr_fxt Test_actl(Gfo_cmd_itm_chkr... expd) {
Gfo_cmd_arg_itm[] actl = mgr.To_ary();
tst_mgr.Tst_ary("", expd, actl);
return this;
}
public Gfo_cmd_arg_mgr_fxt Test_errs_none() {return Test_errs(String_.Ary_empty);}
public Gfo_cmd_arg_mgr_fxt Test_errs(String... expd) {
String[] actl = mgr.Errs__to_str_ary();
int len = actl.length;
for (int i = 0; i < len; ++i) { // extract key part; EX: "unknown key: abc" -> unknown key
actl[i] = String_.GetStrBefore(actl[i], ":");
}
Tfds.Eq_ary_str(expd, actl);
return this;
}
public Gfo_cmd_arg_mgr_fxt Test_write(String... expd) {
Tfds.Eq_ary_str(expd, ((Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr()).Xto_str_ary_and_clear());
return this;
}
public void Test_val_as_url_rel_dir_or(String root_dir, String dir_spr, String val, String expd) {
Io_url actl = Make_arg("key").Val_(val).Val_as_url__rel_dir_or(Io_url_.new_dir_(root_dir).GenSubDir("dir"), null);
Tfds.Eq(expd, actl.Raw());
}
}
class Gfo_cmd_itm_chkr implements Tst_chkr {
public Gfo_cmd_itm_chkr(String key, Object val) {this.key = key; this.val = val;} private String key; Object val;
public Class<?> TypeOf() {return Gfo_cmd_arg_itm.class;}
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Gfo_cmd_arg_itm actl = (Gfo_cmd_arg_itm)actl_obj;
int err = 0;
err += mgr.Tst_val(false, path, "key", key, actl.Key());
err += mgr.Tst_val(false, path, "val", val, actl.Val());
return err;
}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.enums; import gplx.*; import gplx.core.*;
class Gfo_enum_grp {
// private Ordered_hash itms = Ordered_hash_.new_();
// private Ordered_hash itms = Ordered_hash_.New();
public Gfo_enum_grp(Guid_adp uid, String key, int id, String name, int sort, String xtn) {
this.uid = uid; this.key = key; this.id = id; this.name = name; this.sort = sort; this.xtn = xtn;
}

View File

@@ -80,8 +80,8 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
}
throw Err_.new_wo_type("fld_dlm failed", "fld_dlm", (char)fld_dlm, "bgn", fld_bgn);
}
public String Read_str_escape() {Move_next_escaped(bfr); return String_.new_u8(bfr.Xto_bry_and_clear());}
public byte[] Read_bry_escape() {Move_next_escaped(bfr); return bfr.Xto_bry_and_clear();}
public String Read_str_escape() {Move_next_escaped(bfr); return String_.new_u8(bfr.To_bry_and_clear());}
public byte[] Read_bry_escape() {Move_next_escaped(bfr); return bfr.To_bry_and_clear();}
public void Move_1() {++pos;}
public void Move_next_escaped() {Move_next_escaped(bfr); bfr.Clear();}
public int Move_next_simple_fld() {

View File

@@ -50,7 +50,7 @@ class Gfo_fld_rdr_fxt {
byte[] bry = Bry_.new_u8(val);
wtr.Bfr_(bfr);
wtr.Write_bry_escape_fld(bry);
Tfds.Eq(expd, bfr.Xto_str());
Tfds.Eq(expd, bfr.To_str());
return this;
} private Bry_bfr bfr = Bry_bfr.new_();
}

View File

@@ -51,7 +51,7 @@ public class Gfo_fld_wtr extends Gfo_fld_base {
public boolean Flush_needed(int v) {return bfr.Len() + v > bfr_max;}
public void Flush() {
if (Fil_gen().Cur_url() == null) fil_gen.Nxt_url();
Io_mgr.I.AppendFilBfr(fil_gen.Cur_url(), bfr);
Io_mgr.Instance.AppendFilBfr(fil_gen.Cur_url(), bfr);
}
public void Flush_nxt() {Flush(); fil_gen.Nxt_url();}
public Gfo_fld_wtr Ctor_xdat() {return (Gfo_fld_wtr)super.Ctor_xdat_base();}

View File

@@ -33,7 +33,7 @@ class Gfo_i18n_itm {
synchronized (tmp_fmtr) {
tmp_fmtr.Fmt_(val);
tmp_fmtr.Bld_bfr_many(tmp_bfr, args);
rv = tmp_bfr.Xto_bry_and_clear();
rv = tmp_bfr.To_bry_and_clear();
}
return val_cmd == null ? rv : val_cmd.Process(src, key, rv);
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.lists; import gplx.*; import gplx.core.*;
import org.junit.*;
public class StatRng_tst {
// Mwl_parser_fxt fx = new Mwl_parser_fxt(); Pf_func_lang_rsc rsc = Pf_func_lang_rsc._;
// Mwl_parser_fxt fx = new Mwl_parser_fxt(); Pf_func_lang_rsc rsc = Pf_func_lang_rsc.Instance;
StatRng_fxt fx = new StatRng_fxt();
@Test public void Empty() {
fx.ini_(1, 1, 5);
@@ -34,6 +34,6 @@ public class StatRng_tst {
}
/*
public class Pf_func_switch_tst {
// Mwl_parser_fxt fx = new Mwl_parser_fxt(); Pf_func_lang_rsc rsc = Pf_func_lang_rsc._;
// Mwl_parser_fxt fx = new Mwl_parser_fxt(); Pf_func_lang_rsc rsc = Pf_func_lang_rsc.Instance;
*/

View File

@@ -46,10 +46,10 @@ public class Gfo_log_fil {
if (session != null) session.Add_by_bfr(msg_bfr);
}
public void Flush() {
Io_mgr.I.AppendFilBfr(fil_cur, fil_bfr);
Io_mgr.Instance.AppendFilBfr(fil_cur, fil_bfr);
}
private Io_url Fil_new() {
String part = size_max == -1 ? "" : "-" + Int_.Xto_str(++file_idx);
String part = size_max == -1 ? "" : "-" + Int_.To_str(++file_idx);
return dir.OwnerDir().GenSubFil_ary(key, part, ".log");
}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.logs; import gplx.*; import gplx.core.*;
public class Gfo_log_mgr {
private final Ordered_hash fil_list = Ordered_hash_.new_();
private final Ordered_hash fil_list = Ordered_hash_.New();
private final Gfo_log_fil session_fil;
private final Io_url dir;
private final long size_dflt = Io_mgr.Len_mb * 2;

View File

@@ -17,7 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
public interface Gfo_inet_conn {
void Clear();
void Upload_by_bytes(String url, byte[] data);
byte[] Download_as_bytes_or_null(String url); // return null instead of throwing exception
int Tid();
void Clear();
void Upload_by_bytes(String url, byte[] data);
byte[] Download_as_bytes_or_null(String url); // return null instead of throwing exception
}

View File

@@ -17,19 +17,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
public class Gfo_inet_conn_ {
public static final int Tid__http = 1, Tid__mem__hash = 2, Tid__mem__pile = 3;
public static Gfo_inet_conn new_http() {return new Gfo_inet_conn__http();}
public static Gfo_inet_conn new_mem_hash() {return new Gfo_inet_conn__mem__hash();}
public static Gfo_inet_conn new_mem_pile() {return new Gfo_inet_conn__mem__pile();}
public static Gfo_inet_conn new_() {
switch (new_prototype) {
default:
case Tid__http: return new_http();
case Tid__mem__hash: return new_mem_hash();
case Tid__mem__pile: return new_mem_pile();
}
}
public static void new_prototype_(int v) {new_prototype = v;} private static int new_prototype = Tid__http;
}
class Gfo_inet_conn__mem__hash implements Gfo_inet_conn {
private final Hash_adp_bry hash = Hash_adp_bry.cs();
public void Clear() {hash.Clear();}
public void Upload_by_bytes(String url, byte[] data) {hash.Add(url, data);}
public byte[] Download_as_bytes_or_null(String url) {return (byte[])hash.Get_by(url);}
private final Hash_adp hash = Hash_adp_.new_();
public int Tid() {return Gfo_inet_conn_.Tid__mem__hash;}
public void Clear() {hash.Clear();}
public void Upload_by_bytes(String url, byte[] data) {hash.Add(url, data);}
public byte[] Download_as_bytes_or_null(String url) {return (byte[])hash.Get_by(url);}
}
class Gfo_inet_conn__mem__pile implements Gfo_inet_conn {
private final List_adp pile = List_adp_.new_();
public void Clear() {pile.Clear();}
public void Upload_by_bytes(String url, byte[] data) {pile.Add(data);}
public byte[] Download_as_bytes_or_null(String url) {return (byte[])List_adp_.Pop_last(pile);}
public int Tid() {return Gfo_inet_conn_.Tid__mem__hash;}
public void Clear() {pile.Clear();}
public void Upload_by_bytes(String url, byte[] data) {pile.Add(data);}
public byte[] Download_as_bytes_or_null(String url) {return (byte[])List_adp_.Pop_last(pile);}
}

View File

@@ -19,9 +19,10 @@ package gplx.core.net; import gplx.*; import gplx.core.*;
import gplx.ios.*;
class Gfo_inet_conn__http implements Gfo_inet_conn {
private final IoEngine_xrg_downloadFil downloader = IoEngine_xrg_downloadFil.new_("", Io_url_.Empty);
public void Clear() {throw Err_.new_unsupported();}
public void Upload_by_bytes(String url, byte[] data) {throw Err_.new_unsupported();}
public byte[] Download_as_bytes_or_null(String url) {
public int Tid() {return Gfo_inet_conn_.Tid__http;}
public void Clear() {throw Err_.new_unsupported();}
public void Upload_by_bytes(String url, byte[] data) {throw Err_.new_unsupported();}
public byte[] Download_as_bytes_or_null(String url) {
try {return downloader.Exec_as_bry(url);}
catch (Exception e) {Err_.Noop(e); return null;}
}

View File

@@ -76,7 +76,7 @@ public class Gfo_protocol_itm {
, Tid_relative_1 = 29 // [//a.org]
, Tid_relative_2 = 30 // [[//a.org]]
;
public static final Ordered_hash Regy = Ordered_hash_.new_bry_();
public static final Ordered_hash Regy = Ordered_hash_.New_bry();
public static final Gfo_protocol_itm
Itm_http = new_(Tid_http , "http://")
, Itm_https = new_(Tid_https , "https://")

View File

@@ -46,6 +46,6 @@ public class Gfo_qarg_itm {
bfr.Add(itm.Val_bry());
bfr.Add_byte_nl();
}
return bfr.Xto_str_and_clear();
return bfr.To_str_and_clear();
}
}

View File

@@ -39,7 +39,7 @@ public class Gfo_qarg_mgr {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by(key);
return arg == null ? or : String_.new_u8(arg.Val_bry());
}
public void Set_val_by_int(byte[] key, int val) {Set_val_by_bry(key, Bry_.new_a7(Int_.Xto_str(val)));}
public void Set_val_by_int(byte[] key, int val) {Set_val_by_bry(key, Bry_.new_a7(Int_.To_str(val)));}
public void Set_val_by_bry(byte[] key, byte[] val) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by(key);
if (arg == null) {
@@ -68,13 +68,13 @@ public class Gfo_qarg_mgr {
Gfo_qarg_itm itm = Get_arg(key); if (itm == null) continue;
bfr.Add_byte(Byte_ascii.Amp).Add(itm.Key_bry()).Add_byte(Byte_ascii.Eq).Add(itm.Val_bry());
}
return bfr.Xto_bry_and_clear();
return bfr.To_bry_and_clear();
}
public byte[] To_bry() {
int len = list.Count(); if (len == 0) return Bry_.Empty;
Bry_bfr bfr = Bry_bfr.new_();
To_bry(bfr, gplx.xowa.Xoa_app_.Utl__encoder_mgr().Href(), false);
return bfr.Xto_bry_and_clear();
return bfr.To_bry_and_clear();
}
public void To_bry(Bry_bfr bfr, Url_encoder href_encoder, boolean encode) {
int len = list.Count(); if (len == 0) return;

View File

@@ -255,7 +255,7 @@ public class Gfo_url_parser {
tmp_bfr.Add_byte_eq().Add(qarg_val);
}
qargs.Clear();
segs_ary.Set_at_last(tmp_bfr.Xto_bry_and_clear());
segs_ary.Set_at_last(tmp_bfr.To_bry_and_clear());
}
public static final byte[] Bry_double_slash = new byte[] {Byte_ascii.Slash, Byte_ascii.Slash};
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
public class Http_post_data_hash {
private final Ordered_hash hash = Ordered_hash_.new_bry_();
private final Ordered_hash hash = Ordered_hash_.New_bry();
public int Len() {return hash.Count();}
public Http_post_data_itm Get_at(int i) {return (Http_post_data_itm)hash.Get_at(i);}
public Http_post_data_itm Get_by(byte[] k) {return (Http_post_data_itm)hash.Get_by(k);}

View File

@@ -76,7 +76,7 @@ public class Http_request_itm {
bfr.Add_kv_dlm(line, String_.new_u8(itm.Key()), itm.Val());
}
}
return bfr.Xto_str_and_clear();
return bfr.To_str_and_clear();
}
public static final int Type_get = 1, Type_post = 2;
}

View File

@@ -121,7 +121,7 @@ public class Http_request_parser {
if (Bry_.Has_at_bgn(line, content_type_boundary)) break;
tmp_bfr.Add(line);
}
byte[] val = tmp_bfr.Xto_bry_and_clear();
byte[] val = tmp_bfr.To_bry_and_clear();
post_data_hash.Add(key, val);
return line;
}

View File

@@ -18,5 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.net; import gplx.*; import gplx.core.*;
import gplx.core.consoles.*;
class Http_server_wtr__console implements Http_server_wtr {
public void Write_str_w_nl(String s) {Console_adp__sys.I.Write_str_w_nl(s);}
public void Write_str_w_nl(String s) {Console_adp__sys.Instance.Write_str_w_nl(s);}
}

View File

@@ -30,5 +30,5 @@ public class Bry_cache {
return ((Bry_obj_ref)rv).Val();
}
Hash_adp hash = Hash_adp_.new_(); Bry_obj_ref hash_ref = Bry_obj_ref.null_();
public static final Bry_cache _ = new Bry_cache(); Bry_cache() {}
public static final Bry_cache Instance = new Bry_cache(); Bry_cache() {}
}

View File

@@ -29,5 +29,5 @@ public class Int_2_val {
int v1 = Int_.parse_or(itms[1], Int_.Min_value); if (v1 == Int_.Min_value) return Null_ptr;
return new Int_2_val(v0, v1);
}
public static String Xto_str(Bry_bfr bfr, int x, int y) {return bfr.Add_int_variable(x).Add_byte_comma().Add_int_variable(y).Xto_str_and_clear();}
public static String Xto_str(Bry_bfr bfr, int x, int y) {return bfr.Add_int_variable(x).Add_byte_comma().Add_int_variable(y).To_str_and_clear();}
}

View File

@@ -35,5 +35,5 @@ public class Int_ary_parser extends Obj_ary_parser_base {
parser.Parse(bry, bgn, end); if (parser.Has_err() || parser.Has_frac()) throw Err_.new_wo_type("failed to parse number", "val", String_.new_u8(bry, bgn, end));
ary[ary_idx++] = parser.Rv_as_int();
}
public static final Int_ary_parser _ = new Int_ary_parser();
public static final Int_ary_parser Instance = new Int_ary_parser();
}

View File

@@ -22,7 +22,7 @@ public class Int_ary_parser_tst {
@Test public void One() {tst_ints("1" , 0, 1, Int_.Ary(1));}
@Test public void None() {tst_ints("" , 0, 0, Int_.Ary());}
private void tst_ints(String raw, int bgn, int end, int[] expd) {
int[] actl = Int_ary_parser._.Parse_ary(Bry_.new_a7(raw), bgn, end, Byte_ascii.Comma);
int[] actl = Int_ary_parser.Instance.Parse_ary(Bry_.new_a7(raw), bgn, end, Byte_ascii.Comma);
Tfds.Eq_ary(expd, actl);
}
}

View File

@@ -51,7 +51,7 @@ public class Tst_mgr {
int max_len = expd_ary_len > actl_ary_len ? expd_ary_len : actl_ary_len;
int err = 0;
for (int i = 0; i < max_len; i++) {
String path = ownerPath + Int_.Xto_str(i);
String path = ownerPath + Int_.To_str(i);
Tst_chkr expd_obj = i < expd_ary_len ? expd_ary[i] : Tst_mgr.Null_chkr;
Object actl_obj = i < actl_ary_len ? actl_ary[i] : "<NULL OBJ>";
String actl_type = i < actl_ary_len ? Type_adp_.NameOf_obj(actl_obj) : "<NULL TYPE>";
@@ -86,7 +86,7 @@ public class Tst_mgr {
Object itm = Array_.Get_at(ary, i);
ary_sb.Add(Object_.Xto_str_strict_or_null_mark(itm)).Add(",");
}
return ary_sb.Xto_str_and_clear();
return ary_sb.To_str_and_clear();
} String_bldr ary_sb = String_bldr_.new_();
String Build() {
String_bldr sb = String_bldr_.new_();
@@ -104,7 +104,7 @@ public class Tst_mgr {
if (!itm.Pass())
sb.Add_fmt("\n{0} {1} {2} '{3}'", String_.PadEnd("", comp_max, " "), " " + String_.PadEnd("", path_max, " "), " " + String_.PadEnd("", name_max, " ") + " ", itm.Actl());
}
return sb.Xto_str_and_clear();
return sb.To_str_and_clear();
}
int Max(int max, String s) {int len = String_.Len(s); return len > max ? len : max;}
public static final Tst_chkr Null_chkr = new Tst_chkr_null();

View File

@@ -32,10 +32,10 @@ public class Gfo_thread_cmd_download implements Gfo_thread_cmd {
public int Async_sleep_interval() {return Gfo_thread_cmd_.Async_sleep_interval_1_second;}
public boolean Async_prog_enabled() {return false;}
@gplx.Virtual public byte Async_init() {
if (Io_mgr.I.ExistsFil(trg)) {
if (Io_mgr.Instance.ExistsFil(trg)) {
int rslt = kit.Ask_yes_no_cancel(GRP_KEY, "target_exists", "Target file already exists: '~{0}'.\nDo you want to delete it?", trg.Raw());
switch (rslt) {
case Gfui_dlg_msg_.Btn_yes: Io_mgr.I.DeleteFil(trg); break;
case Gfui_dlg_msg_.Btn_yes: Io_mgr.Instance.DeleteFil(trg); break;
case Gfui_dlg_msg_.Btn_no: return Gfo_thread_cmd_.Init_cancel_step;
case Gfui_dlg_msg_.Btn_cancel: return Gfo_thread_cmd_.Init_cancel_all;
default: throw Err_.new_unhandled(rslt);
@@ -59,7 +59,7 @@ public class Gfo_thread_cmd_download implements Gfo_thread_cmd {
kit.Ask_ok(GRP_KEY, "download.fail", "download failed. Please select 'read from file' if you've already downloaded a dump: url=~{0} error=~{1}", src, xrg.Rslt_err_str());
}
} boolean download_pass = true;
protected gplx.ios.IoEngine_xrg_downloadFil xrg = Io_mgr.I.DownloadFil_args("", Io_url_.Empty);
protected gplx.ios.IoEngine_xrg_downloadFil xrg = Io_mgr.Instance.DownloadFil_args("", Io_url_.Empty);
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_async_bgn)) Download();
else if (ctx.Match(k, Invk_owner)) return owner;

View File

@@ -30,7 +30,7 @@ public class Gfo_thread_cmd_replace implements Gfo_thread_cmd {
public int Async_sleep_interval() {return Gfo_thread_cmd_.Async_sleep_interval_1_second;}
public boolean Async_prog_enabled() {return false;}
@gplx.Virtual public byte Async_init() {
if (!Io_mgr.I.ExistsFil(fil)) {kit.Ask_ok(GRP_KEY, "file_missing", "File does not exist: '~{0}'", fil.Raw()); return Gfo_thread_cmd_.Init_cancel_step;}
if (!Io_mgr.Instance.ExistsFil(fil)) {kit.Ask_ok(GRP_KEY, "file_missing", "File does not exist: '~{0}'", fil.Raw()); return Gfo_thread_cmd_.Init_cancel_step;}
return Gfo_thread_cmd_.Init_ok;
}
public boolean Async_term() {return true;}
@@ -38,13 +38,13 @@ public class Gfo_thread_cmd_replace implements Gfo_thread_cmd {
public boolean Async_running() {return false;}
@gplx.Virtual public void Async_run() {Exec_find_replace();} // NOTE: do not run async; if multiple commands for same file then they will not always work
public void Exec_find_replace() {
String raw = Io_mgr.I.LoadFilStr(fil);
String raw = Io_mgr.Instance.LoadFilStr(fil);
int pairs_len = pairs.Count();
for (int i = 0; i < pairs_len; i++) {
KeyVal kv = (KeyVal)pairs.Get_at(i);
raw = String_.Replace(raw, kv.Key(), kv.Val_to_str_or_null());
}
Io_mgr.I.SaveFilStr(fil, raw);
Io_mgr.Instance.SaveFilStr(fil, raw);
usr_dlg.Prog_many(GRP_KEY, "done", "replace completed: ~{0} ~{1}", fil.Raw(), pairs_len);
}
public List_adp pairs = List_adp_.new_();

View File

@@ -32,22 +32,22 @@ public class Gfo_thread_cmd_unzip implements Gfo_thread_cmd {
public boolean Async_prog_enabled() {return true;}
public void Async_prog_run(int async_sleep_sum) {
String size_str = " please wait...";
if (trg.Type_fil()) size_str = gplx.ios.Io_size_.To_str(Io_mgr.I.QueryFil(trg).Size());
if (trg.Type_fil()) size_str = gplx.ios.Io_size_.To_str(Io_mgr.Instance.QueryFil(trg).Size());
usr_dlg.Prog_many(GRP_KEY, "unzip", "unzipping: ~{0}", size_str);
}
@gplx.Virtual public byte Async_init() {
if (!Io_mgr.I.ExistsFil(src)) {
if (!Io_mgr.Instance.ExistsFil(src)) {
kit.Ask_ok(GRP_KEY, "source_missing", "Source file does not exist: '~{0}'", src.Raw());
return Gfo_thread_cmd_.Init_cancel_step;
}
trg_is_dir = trg.Type_dir();
if (delete_trg_if_exists
&& (( trg_is_dir && Io_mgr.I.ExistsDir(trg))
|| (!trg_is_dir && Io_mgr.I.ExistsFil(trg)))
&& (( trg_is_dir && Io_mgr.Instance.ExistsDir(trg))
|| (!trg_is_dir && Io_mgr.Instance.ExistsFil(trg)))
) {
int rslt = kit.Ask_yes_no_cancel(GRP_KEY, "target_exists", "Target file already exists: '~{0}'.\nDo you want to delete it?", trg.Raw());
switch (rslt) {
case Gfui_dlg_msg_.Btn_yes: if (trg_is_dir) Io_mgr.I.DeleteDirDeep(trg); else Io_mgr.I.DeleteFil(trg); break;
case Gfui_dlg_msg_.Btn_yes: if (trg_is_dir) Io_mgr.Instance.DeleteDirDeep(trg); else Io_mgr.Instance.DeleteFil(trg); break;
case Gfui_dlg_msg_.Btn_no: return Gfo_thread_cmd_.Init_cancel_step;
case Gfui_dlg_msg_.Btn_cancel: return Gfo_thread_cmd_.Init_cancel_all;
}
@@ -61,7 +61,7 @@ public class Gfo_thread_cmd_unzip implements Gfo_thread_cmd {
}
public boolean Async_term() {
if (rename_dir) {
Io_url[] dirs = Io_mgr.I.QueryDir_args(trg.OwnerDir()).DirOnly_().Recur_(false).ExecAsUrlAry();
Io_url[] dirs = Io_mgr.Instance.QueryDir_args(trg.OwnerDir()).DirOnly_().Recur_(false).ExecAsUrlAry();
int dirs_len = dirs.length;
Io_url zip_dir = Io_url_.Empty;
for (int i = 0; i < dirs_len; i++) {
@@ -76,14 +76,14 @@ public class Gfo_thread_cmd_unzip implements Gfo_thread_cmd {
return false;
}
if (!String_.Eq(String_.Lower(zip_dir.Raw()), String_.Lower(trg.Raw()))) // HACK: inkscape is itself
Io_mgr.I.MoveDirDeep(zip_dir, trg);
Io_mgr.Instance.MoveDirDeep(zip_dir, trg);
}
switch (term_cmd_for_src) {
case Term_cmd_for_src_noop: break;
case Term_cmd_for_src_delete: Io_mgr.I.DeleteFil(src); break;
case Term_cmd_for_src_delete: Io_mgr.Instance.DeleteFil(src); break;
case Term_cmd_for_src_move:
if (term_cmd_for_src_url == Io_url_.Empty) throw Err_.new_wo_type("move specified, but no url");
Io_mgr.I.MoveFil_args(src, term_cmd_for_src_url, true).Exec();
Io_mgr.Instance.MoveFil_args(src, term_cmd_for_src_url, true).Exec();
break;
default: throw Err_.new_unhandled(term_cmd_for_src);
}

View File

@@ -15,8 +15,9 @@ 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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
interface Gfo_html_wkr {
Gfo_html_tkn Get_or_null(byte[] src, int bgn, int end);
void Process(Gfo_html_node node);
package gplx.core.threads.poolables; import gplx.*; import gplx.core.*; import gplx.core.threads.*;
public interface Gfo_poolable_itm {
int Pool__idx();
void Pool__clear (Object[] args);
Gfo_poolable_itm Pool__make (int idx, Object[] args);
}

View File

@@ -0,0 +1,127 @@
/*
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.poolables; import gplx.*; import gplx.core.*; import gplx.core.threads.*;
public class Gfo_poolable_mgr {
private final Object thread_lock = new Object();
private final Gfo_poolable_itm prototype; private final Object[] make_args, clear_args;
private Gfo_poolable_itm[] pool; private int pool_next, pool_len; private final int pool_max;
public Gfo_poolable_mgr(Gfo_poolable_itm prototype, Object[] make_args, Object[] clear_args, int init_pool_len, int pool_max) {// NOTE: random IndexOutOfBounds errors in Get around free[--free_len] with free_len being -1; put member variable initialization within thread_lock to try to avoid; DATE:2014-09-21
this.prototype = prototype; this.make_args = make_args; this.clear_args = clear_args;
this.pool_len = init_pool_len; this.pool_max = pool_max;
this.Clear_fast();
}
public void Clear_safe() {synchronized (thread_lock) {Clear_fast();}}
public void Clear_fast() {
this.pool = new Gfo_poolable_itm[pool_len];
for (int i = 0; i < pool_len; ++i)
pool[i] = prototype.Pool__make(i, make_args);
this.free = new int[pool_len];
pool_next = free_len = 0;
}
public Gfo_poolable_itm Get_safe() {synchronized (thread_lock) {return Get_fast();}}
public Gfo_poolable_itm Get_fast() {
Gfo_poolable_itm rv = null;
int pool_idx = -1;
if (free_len > 0) { // free_itms in pool; use it
pool_idx = free[--free_len];
rv = pool[pool_idx];
}
else { // nothing in pool; take next
if (pool_next == pool_len)
Expand_pool();
pool_idx = pool_next++;
rv = pool[pool_idx];
if (rv == null) {
rv = prototype.Pool__make(pool_idx, make_args);
pool[pool_idx] = rv;
}
}
rv.Pool__clear(clear_args); // NOTE: ALWAYS call Clear when doing Get. caller may forget to call Clear, and reused bfr may have leftover bytes. unit tests will not catch, and difficult to spot in app
return rv;
}
public void Rls_safe(int idx) {synchronized (thread_lock) {Rls_safe(idx);}}
public void Rls_fast(int idx) {
if (idx == -1) throw Err_.new_wo_type("rls called on poolable that was not created by pool_mgr");
int pool_idx = pool_next - 1;
if (idx == pool_idx) // in-sequence; decrement count
this.pool_next = pool_idx;
else { // out-of-sequence
if (free_len == pool_max) { // all used; assume entire pool released, but out of order
// Array_.Sort((Object[])free);
// for (int i = 0; i < pool_max; ++i) {
// if (i != free[i]) throw Err_.new_("pool", "available_list out of order", "contents", "");
// }
for (int i = 0; i < free_len; ++i)
free[i] = 0;
free_len = 0;
}
else { // add to free pool
free[free_len] = idx;
++free_len;
}
}
}
private void Expand_pool() {
// expand pool
int new_pool_len = pool_len == 0 ? 2 : pool_len * 2;
Gfo_poolable_itm[] new_pool = new Gfo_poolable_itm[new_pool_len];
Array_.Copy_to(pool, 0, new_pool, 0, pool_len);
this.pool = new_pool;
this.pool_len = new_pool_len;
// expand free to same len
int[] new_free = new int[pool_len];
Array_.Copy_to(free, 0, new_free, 0, free_len);
this.free = new_free;
}
@gplx.Internal protected int[] Free() {return free;} private int[] free; private int free_len;
@gplx.Internal protected int Pool_len() {return pool_len;}
// public int Mgr_id() {return mgr_id;} private int mgr_id;
// public void Reset_if_gt(int v) {
// this.Clear(); // TODO: for now, just call clear
// }
// public void Clear_fail_check() {
// synchronized (thread_lock) {
// for (int i = 0; i < ary_max; i++) {
// Object itm = ary[i];
// if (itm != null) {
// if (!itm.Mkr_idx_is_null()) throw Err_.new_wo_type("failed to clear bfr", "idx", Int_.To_str(i));
// itm.Clear();
// }
// ary[i] = null;
// }
// ary = Ary_empty;
// free = Int_.Ary_empty;
// free_len = 0;
// nxt_idx = ary_max = 0;
// }
// }
// public void Clear() {
// synchronized (thread_lock) {
// for (int i = 0; i < ary_max; i++) {
// Object itm = ary[i];
// if (itm != null) itm.Clear();
// ary[i] = null;
// }
// ary = Ary_empty;
// free = Int_.Ary_empty;
// free_len = 0;
// nxt_idx = ary_max = 0;
// }
// }
}

View File

@@ -0,0 +1,50 @@
/*
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.poolables; import gplx.*; import gplx.core.*; import gplx.core.threads.*;
import org.junit.*;
public class Gfo_poolable_mgr_tst {
private final Gfo_poolable_mgr_tstr tstr = new Gfo_poolable_mgr_tstr();
@Before public void init() {tstr.Clear();}
@Test public void Get__one() {
tstr.Test__get(0);
tstr.Test__mgr__free(0, 0);
tstr.Test__pool__len(2);
}
}
class Gfo_poolable_mgr_tstr {
private final Gfo_poolable_mgr mgr = new Gfo_poolable_mgr(new Sample_poolable_itm(-1, Object_.Ary_empty), Object_.Ary("make"), Object_.Ary("clear"), 2, 8);
public void Clear() {mgr.Clear_fast();}
public void Test__get(int expd_idx) {
Sample_poolable_itm actl_itm = (Sample_poolable_itm)mgr.Get_fast();
Tfds.Eq(expd_idx, actl_itm.Pool__idx(), "pool_idx");
}
public void Test__mgr__free(int... expd) {
Tfds.Eq_ary(expd, mgr.Free(), "mgr.Free()");
}
public void Test__pool__len(int expd) {
Tfds.Eq(expd, mgr.Pool_len(), "mgr.Pool_len()");
}
}
class Sample_poolable_itm implements Gfo_poolable_itm {
public Sample_poolable_itm(int pool_idx, Object[] make_args) {this.pool_idx = pool_idx; this.pool__make_args = make_args;}
public int Pool__idx() {return pool_idx;} private final int pool_idx;
public Object[] Pool__make_args() {return pool__make_args;} private final Object[] pool__make_args;
public Object[] Pool__clear_args() {return pool__clear_args;} private Object[] pool__clear_args;
public void Pool__clear (Object[] args) {this.pool__clear_args = args;}
public Gfo_poolable_itm Pool__make (int idx, Object[] args) {return new Sample_poolable_itm(idx, args);}
}

View File

@@ -33,7 +33,7 @@ public class Db_attach_cmd {
return this;
}
public void Exec() {
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.I;
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
if (diff_db) conn.Env_db_attach(attach_name, attach_url);
conn.Txn_bgn(attach_name); // NOTE: BEGIN TRAN must occur after ATTACH else sqlite will throw error
int len = sql_list.Count();

View File

@@ -28,7 +28,7 @@ public class Db_attach_rdr {
public void Attach() {
try {
if (diff_db) conn.Env_db_attach(attach_name, attach_url);
} catch (Exception e) {Err_.Noop(e); Gfo_usr_dlg_.I.Warn_many("", "", "db:failed to attach db; name=~{0} url=~{1}", attach_name, attach_url.Raw());}
} catch (Exception e) {Err_.Noop(e); Gfo_usr_dlg_.Instance.Warn_many("", "", "db:failed to attach db; name=~{0} url=~{1}", attach_name, attach_url.Raw());}
}
public Db_rdr Exec_as_rdr(String sql) {
sql = String_.Replace(sql, "<attach_db>", diff_db ? attach_name + "." : ""); // replace <attach> with either "attach_db." or "";

View File

@@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.cfgs; import gplx.*; import gplx.dbs.*;
public class Db_cfg_hash {
private final String grp; private final Ordered_hash hash = Ordered_hash_.new_();
private final String grp; private final Ordered_hash hash = Ordered_hash_.New();
public Db_cfg_hash(String grp) {this.grp = grp;}
public int Len() {return hash.Count();}
public Db_cfg_itm Get_at(int i) {return (Db_cfg_itm)hash.Get_at(i);}
public Db_cfg_itm Get(String key) {
public Db_cfg_itm Get_by(String key) {
Db_cfg_itm rv = (Db_cfg_itm)hash.Get_by(key);
return rv == null ? Db_cfg_itm.Empty : rv;
}

View File

@@ -42,14 +42,14 @@ public class Db_cfg_itm {
public static Db_cfg_itm new_str (String grp, String key, String val) {return new Db_cfg_itm(grp , key, val);}
public static Db_cfg_itm new_bry (String key, byte[] val) {return new Db_cfg_itm(Grp_none , key, String_.new_u8(val));}
public static Db_cfg_itm new_bry (String grp, String key, byte[] val) {return new Db_cfg_itm(grp , key, String_.new_u8(val));}
public static Db_cfg_itm new_int (String key, int val) {return new Db_cfg_itm(Grp_none , key, Int_.Xto_str(val));}
public static Db_cfg_itm new_int (String grp, String key, int val) {return new Db_cfg_itm(grp , key, Int_.Xto_str(val));}
public static Db_cfg_itm new_long (String key, long val) {return new Db_cfg_itm(Grp_none , key, Long_.Xto_str(val));}
public static Db_cfg_itm new_long (String grp, String key, long val) {return new Db_cfg_itm(grp , key, Long_.Xto_str(val));}
public static Db_cfg_itm new_int (String key, int val) {return new Db_cfg_itm(Grp_none , key, Int_.To_str(val));}
public static Db_cfg_itm new_int (String grp, String key, int val) {return new Db_cfg_itm(grp , key, Int_.To_str(val));}
public static Db_cfg_itm new_long (String key, long val) {return new Db_cfg_itm(Grp_none , key, Long_.To_str(val));}
public static Db_cfg_itm new_long (String grp, String key, long val) {return new Db_cfg_itm(grp , key, Long_.To_str(val));}
public static Db_cfg_itm new_byte (String key, byte val) {return new Db_cfg_itm(Grp_none , key, Byte_.To_str(val));}
public static Db_cfg_itm new_byte (String grp, String key, byte val) {return new Db_cfg_itm(grp , key, Byte_.To_str(val));}
public static Db_cfg_itm new_yn (String key, boolean val) {return new Db_cfg_itm(Grp_none , key, Yn.Xto_str(val));}
public static Db_cfg_itm new_yn (String grp, String key, boolean val) {return new Db_cfg_itm(grp , key, Yn.Xto_str(val));}
public static Db_cfg_itm new_yn (String key, boolean val) {return new Db_cfg_itm(Grp_none , key, Yn.To_str(val));}
public static Db_cfg_itm new_yn (String grp, String key, boolean val) {return new Db_cfg_itm(grp , key, Yn.To_str(val));}
public static Db_cfg_itm new_DateAdp (String key, DateAdp val) {return new Db_cfg_itm(Grp_none , key, val.XtoStr_fmt_yyyyMMdd_HHmmss());}
public static Db_cfg_itm new_DateAdp (String grp, String key, DateAdp val) {return new Db_cfg_itm(grp , key, val.XtoStr_fmt_yyyyMMdd_HHmmss());}
public static Db_cfg_itm new_guid (String key, Guid_adp val) {return new Db_cfg_itm(Grp_none , key, val.To_str());}

View File

@@ -40,8 +40,8 @@ public class Db_cfg_tbl implements RlsAble {
public void Delete_all() {conn.Stmt_delete(tbl_name, Db_meta_fld.Ary_empty).Exec_delete();}
public void Insert_yn (String grp, String key, boolean val) {Insert_str(grp, key, val ? "y" : "n");}
public void Insert_byte (String grp, String key, byte val) {Insert_str(grp, key, Byte_.To_str(val));}
public void Insert_int (String grp, String key, int val) {Insert_str(grp, key, Int_.Xto_str(val));}
public void Insert_long (String grp, String key, long val) {Insert_str(grp, key, Long_.Xto_str(val));}
public void Insert_int (String grp, String key, int val) {Insert_str(grp, key, Int_.To_str(val));}
public void Insert_long (String grp, String key, long val) {Insert_str(grp, key, Long_.To_str(val));}
public void Insert_date (String grp, String key, DateAdp val) {Insert_str(grp, key, val.XtoStr_fmt_yyyyMMdd_HHmmss());}
public void Insert_guid (String grp, String key, Guid_adp val) {Insert_str(grp, key, val.To_str());}
public void Insert_bry (String grp, String key, byte[] val) {Insert_str(grp, key, String_.new_u8(val));}
@@ -53,8 +53,8 @@ public class Db_cfg_tbl implements RlsAble {
}
public void Update_yn (String grp, String key, boolean val) {Update_str(grp, key, val ? "y" : "n");}
public void Update_byte (String grp, String key, byte val) {Update_str(grp, key, Byte_.To_str(val));}
public void Update_int (String grp, String key, int val) {Update_str(grp, key, Int_.Xto_str(val));}
public void Update_long (String grp, String key, long val) {Update_str(grp, key, Long_.Xto_str(val));}
public void Update_int (String grp, String key, int val) {Update_str(grp, key, Int_.To_str(val));}
public void Update_long (String grp, String key, long val) {Update_str(grp, key, Long_.To_str(val));}
public void Update_date (String grp, String key, DateAdp val) {Update_str(grp, key, val.XtoStr_fmt_yyyyMMdd_HHmmss());}
public void Update_guid (String grp, String key, Guid_adp val) {Update_str(grp, key, val.To_str());}
public void Update_bry (String grp, String key, byte[] val) {Update_str(grp, key, String_.new_u8(val));}
@@ -63,7 +63,7 @@ public class Db_cfg_tbl implements RlsAble {
stmt_update.Clear().Val_str(fld_val, val).Crt_str(fld_grp, grp).Crt_str(fld_key, key).Exec_update();
}
public void Upsert_yn (String grp, String key, boolean val) {Upsert_str(grp, key, val ? "y" : "n");}
public void Upsert_int (String grp, String key, int val) {Upsert_str(grp, key, Int_.Xto_str(val));}
public void Upsert_int (String grp, String key, int val) {Upsert_str(grp, key, Int_.To_str(val));}
public void Upsert_str (String grp, String key, String val) {
String cur_val = this.Select_str_or(grp, key, null);
if (cur_val == null) this.Insert_str(grp, key, val);
@@ -103,6 +103,16 @@ public class Db_cfg_tbl implements RlsAble {
finally {rdr.Rls();}
return rv;
}
public void Select_as_hash_bry(Hash_adp_bry rv, String grp) {
rv.Clear();
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_grp).Crt_str(fld_grp, grp).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
rv.Add(rdr.Read_bry_by_str(fld_key), rdr.Read_bry_by_str(fld_val));
}
}
finally {rdr.Rls();}
}
// NOTE: Assert guarantees that a value exists in database and returns it (Select + Insert); (1) String val = Assert('grp', 'key', 'val'); (2) Update('grp', 'key', 'val2');
public boolean Assert_yn (String grp, String key, boolean or) {String val = Select_str_or(grp, key, null) ; if (val == null) {Insert_yn (grp, key, or); return or;} return Parse_yn (grp, key, val);}
public byte Assert_byte (String grp, String key, byte or) {String val = Select_str_or(grp, key, null) ; if (val == null) {Insert_byte (grp, key, or); return or;} return Parse_byte (grp, key, val);}

View File

@@ -26,7 +26,7 @@ class Schema_loader_mgr__null implements Schema_loader_mgr {
}
class Schema_loader_mgr__sqlite implements Schema_loader_mgr {
public void Load(Schema_db_mgr db_mgr, Db_conn conn) {
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.load.bgn: conn=~{0}", conn.Conn_info().Xto_api());
Gfo_usr_dlg_.Instance.Log_many("", "", "db.schema.load.bgn: conn=~{0}", conn.Conn_info().Xto_api());
Meta_tbl_mgr tbl_mgr = db_mgr.Tbl_mgr();
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", String_.Ary_empty, String_.Ary("type", "name", "sql"), Db_qry__select_in_tbl.Order_by_null);
Db_rdr rdr = conn.Stmt_new(qry).Exec_select__rls_auto();
@@ -46,6 +46,6 @@ class Schema_loader_mgr__sqlite implements Schema_loader_mgr {
}
}
} finally {rdr.Rls();}
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.load.end");
Gfo_usr_dlg_.Instance.Log_many("", "", "db.schema.load.end");
}
}

View File

@@ -29,7 +29,7 @@ class Schema_update_cmd__tbl_create implements Schema_update_cmd {
public boolean Exec_is_done() {return exec_is_done;} private boolean exec_is_done;
public void Exec(Schema_db_mgr db_mgr, Db_conn conn) {
if (db_mgr.Tbl_mgr().Has(tbl_name)) return;
Gfo_usr_dlg_.I.Log_many("", "", "schema.tbl.create: tbl=~{0}", tbl_name);
Gfo_usr_dlg_.Instance.Log_many("", "", "schema.tbl.create: tbl=~{0}", tbl_name);
Sqlite_engine_.Tbl_create(conn, tbl_name, tbl_sql);
Sqlite_engine_.Idx_create(conn, tbl_idxs);
exec_is_done = true;

View File

@@ -25,7 +25,7 @@ public class Schema_update_mgr {
Schema_update_cmd cmd = (Schema_update_cmd)cmds.Get_at(i);
try {cmd.Exec(schema_mgr, conn);}
catch (Exception e) {
Gfo_usr_dlg_.I.Warn_many("", "", "failed to run update cmd; name=~{0} err=~{1}", cmd.Name(), Err_.Message_gplx_full(e));
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to run update cmd; name=~{0} err=~{1}", cmd.Name(), Err_.Message_gplx_full(e));
}
}
}

View File

@@ -21,13 +21,13 @@ public class Fsdb_db_mgr_ {
public static Fsdb_db_mgr new_detect(Xow_wiki wiki, Io_url wiki_dir, Io_url file_dir) {
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
Io_url url = file_dir.GenSubFil(Fsdb_db_mgr__v1.Mnt_name); // EX: /xowa/file/en.wikipedia.org/wiki.mnt.sqlite3
if (Db_conn_bldr.I.Exists(url)) { // NOTE: check v1 before v2; note that as of v2.5.4, v2 files are automatically created on new import; DATE:2015-06-09
if (Db_conn_bldr.Instance.Exists(url)) { // NOTE: check v1 before v2; note that as of v2.5.4, v2 files are automatically created on new import; DATE:2015-06-09
usr_dlg.Log_many("", "", "fsdb.db_core.v1: url=~{0}", url.Raw());
usr_dlg.Log_many("", "", "fsdb.db_core.v1 exists: orig=~{0} abc=~{1} atr_a=~{2}, atr_b=~{3}"
, Db_conn_bldr.I.Exists(file_dir.GenSubFil(Fsdb_db_mgr__v1.Orig_name))
, Db_conn_bldr.I.Exists(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Fsdb_db_mgr__v1.Abc_name))
, Db_conn_bldr.I.Exists(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Fsdb_db_mgr__v1.Atr_name_v1a))
, Db_conn_bldr.I.Exists(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Fsdb_db_mgr__v1.Atr_name_v1b))
, Db_conn_bldr.Instance.Exists(file_dir.GenSubFil(Fsdb_db_mgr__v1.Orig_name))
, Db_conn_bldr.Instance.Exists(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Fsdb_db_mgr__v1.Abc_name))
, Db_conn_bldr.Instance.Exists(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Fsdb_db_mgr__v1.Atr_name_v1a))
, Db_conn_bldr.Instance.Exists(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Fsdb_db_mgr__v1.Atr_name_v1b))
);
return new Fsdb_db_mgr__v1(file_dir);
}
@@ -41,15 +41,15 @@ public class Fsdb_db_mgr_ {
}
private static Fsdb_db_mgr load_or_null(Xowd_db_layout layout, Gfo_usr_dlg usr_dlg, Io_url wiki_dir, Xow_wiki wiki, String domain_str) {
Io_url main_core_url = wiki_dir.GenSubFil(Fsdb_db_mgr__v2_bldr.Main_core_name(layout, domain_str));
if (!Db_conn_bldr.I.Exists(main_core_url)) return null;
if (!Db_conn_bldr.Instance.Exists(main_core_url)) return null;
usr_dlg.Log_many("", "", "fsdb.db_core.v2: type=~{0} url=~{1}", layout.Name(), main_core_url.Raw());
Db_conn main_core_conn = Db_conn_bldr.I.Get(main_core_url);
Db_conn main_core_conn = Db_conn_bldr.Instance.Get(main_core_url);
if (wiki.Data__core_mgr().Props().Layout_file().Tid_is_all())
return new Fsdb_db_mgr__v2(Fsdb_db_mgr__v2.Cfg__layout_file__get(main_core_conn), wiki_dir, new Fsdb_db_file(main_core_url, main_core_conn), new Fsdb_db_file(main_core_url, main_core_conn));
Io_url user_core_url = wiki_dir.GenSubFil(Fsdb_db_mgr__v2_bldr.Make_user_name(domain_str));
if (!Db_conn_bldr.I.Exists(user_core_url)) // if user file does not exist, create it; needed b/c offline packages don't include file; DATE:2015-04-19
Fsdb_db_mgr__v2_bldr.I.Make_core_file_user(wiki, user_core_url, user_core_url.NameAndExt(), main_core_url.NameAndExt());
Db_conn user_core_conn = Db_conn_bldr.I.Get(user_core_url);
if (!Db_conn_bldr.Instance.Exists(user_core_url)) // if user file does not exist, create it; needed b/c offline packages don't include file; DATE:2015-04-19
Fsdb_db_mgr__v2_bldr.Instance.Make_core_file_user(wiki, user_core_url, user_core_url.NameAndExt(), main_core_url.NameAndExt());
Db_conn user_core_conn = Db_conn_bldr.Instance.Get(user_core_url);
return new Fsdb_db_mgr__v2(Fsdb_db_mgr__v2.Cfg__layout_file__get(main_core_conn), wiki_dir, new Fsdb_db_file(main_core_url, main_core_conn), new Fsdb_db_file(user_core_url, user_core_conn));
}
}

View File

@@ -28,8 +28,8 @@ public class Fsdb_db_mgr__v1 implements Fsdb_db_mgr {
this.mnt_file = get_db(file_dir.GenSubFil(Mnt_name)); // EX: /xowa/enwiki/wiki.mnt.sqlite3
this.abc_file__main = get_db(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Abc_name)); // EX: /xowa/enwiki/fsdb.main/fsdb.abc.sqlite3
this.atr_file__main = get_db(Get_atr_db_url(Bool_.Y, file_dir, Fsm_mnt_tbl.Mnt_name_main)); // EX: /xowa/enwiki/fsdb.main/fsdb.atr.00.sqlite3
if (Db_conn_bldr.I.Get(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_user, Abc_name)) == null) // user doesn't exist; create; DATE:2015-04-20
Fsdb_db_mgr__v1_bldr.I.Make_core_dir(file_dir, Fsm_mnt_mgr.Mnt_idx_user, Fsm_mnt_tbl.Mnt_name_user);
if (Db_conn_bldr.Instance.Get(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_user, Abc_name)) == null) // user doesn't exist; create; DATE:2015-04-20
Fsdb_db_mgr__v1_bldr.Instance.Make_core_dir(file_dir, Fsm_mnt_mgr.Mnt_idx_user, Fsm_mnt_tbl.Mnt_name_user);
this.abc_file__user = get_db(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_user, Abc_name)); // EX: /xowa/enwiki/fsdb.user/fsdb.abc.sqlite3
this.atr_file__user = get_db(Get_atr_db_url(Bool_.N, file_dir, Fsm_mnt_tbl.Mnt_name_user)); // EX: /xowa/enwiki/fsdb.user/fsdb.atr.00.sqlite3
this.orig_tbl_ary = new Xof_orig_tbl[] {new Xof_orig_tbl(orig_file.Conn(), this.File__schema_is_1())};
@@ -43,13 +43,13 @@ public class Fsdb_db_mgr__v1 implements Fsdb_db_mgr {
public Fsdb_db_file File__atr_file__at(int mnt_id) {return mnt_id == Fsm_mnt_mgr.Mnt_idx_main ? atr_file__main : atr_file__user;}
public Fsdb_db_file File__bin_file__at(int mnt_id, int bin_id, String file_name) {
boolean mnt_is_main = mnt_id == Fsm_mnt_mgr.Mnt_idx_main;
String bin_name = (mnt_is_main ? bin_prefix__main : bin_prefix__user) + Int_.Xto_str_pad_bgn_zero(bin_id, 4) + ".sqlite3";
String bin_name = (mnt_is_main ? bin_prefix__main : bin_prefix__user) + Int_.To_str_pad_bgn_zero(bin_id, 4) + ".sqlite3";
String mnt_name = mnt_is_main ? Fsm_mnt_tbl.Mnt_name_main : Fsm_mnt_tbl.Mnt_name_user;
Io_url url = file_dir.GenSubFil_nest(mnt_name, bin_name); // EX: /xowa/enwiki/fsdb.main/fsdb.bin.0000.sqlite3
Db_conn conn = Db_conn_bldr.I.Get(url);
Db_conn conn = Db_conn_bldr.Instance.Get(url);
if (conn == null) { // NOTE: handle wikis with missing bin files; EX:sv.w missing bin.0010; DATE:2015-07-04
gplx.xowa.Xoa_app_.Usr_dlg().Warn_many("", "", "fsdb.v1: missing db; db=~{0}", url.Raw());
return Fsdb_db_mgr__v1_bldr.I.new_db__bin(url);
return Fsdb_db_mgr__v1_bldr.Instance.new_db__bin(url);
}
else
return new Fsdb_db_file(url, conn);
@@ -57,27 +57,27 @@ public class Fsdb_db_mgr__v1 implements Fsdb_db_mgr {
public Fsdb_db_file File__bin_file__new(int mnt_id, String file_name) {
String mnt_name = mnt_id == Fsm_mnt_mgr.Mnt_idx_main ? Fsm_mnt_tbl.Mnt_name_main : Fsm_mnt_tbl.Mnt_name_user;
Io_url url = file_dir.GenSubFil_nest(mnt_name, file_name); // EX: /xowa/enwiki/fsdb.main/fsdb.bin.0000.sqlite3
Db_conn conn = Db_conn_bldr.I.New(url);
Db_conn conn = Db_conn_bldr.Instance.New(url);
Fsd_bin_tbl bin_tbl = new Fsd_bin_tbl(conn, Bool_.Y); bin_tbl.Create_tbl();
return new Fsdb_db_file(url, conn);
}
private Io_url Get_atr_db_url(boolean main, Io_url file_dir, String mnt_name) {
Io_url rv = null;
rv = file_dir.GenSubFil_nest(mnt_name, Atr_name_v1a);
if (Io_mgr.I.ExistsFil(rv)) {
if (Io_mgr.Instance.ExistsFil(rv)) {
if (main)
bin_prefix__main = "fsdb.bin#";
else
bin_prefix__user = "fsdb.bin#";
return rv;
}
rv = file_dir.GenSubFil_nest(mnt_name, Atr_name_v1b); if (Io_mgr.I.ExistsFil(rv)) return rv;
rv = file_dir.GenSubFil_nest(mnt_name, Atr_name_v1b); if (Io_mgr.Instance.ExistsFil(rv)) return rv;
throw Err_.new_wo_type("could not find atr file", "dir", file_dir.Raw(), "mnt", mnt_name);
}
public static final String Orig_name = "wiki.orig#00.sqlite3", Mnt_name = "wiki.mnt.sqlite3", Abc_name = "fsdb.abc.sqlite3"
, Atr_name_v1a = "fsdb.atr#00.sqlite3", Atr_name_v1b = "fsdb.atr.00.sqlite3";
private static Fsdb_db_file get_db(Io_url file) {
Db_conn conn = Db_conn_bldr.I.Get(file);
Db_conn conn = Db_conn_bldr.Instance.Get(file);
if (conn == null) conn = Db_conn_.Noop;
return new Fsdb_db_file(file, conn);
}
@@ -102,12 +102,12 @@ class Fsdb_db_mgr__v1_bldr {
// make bin_fil
new_db__bin(mnt_dir.GenSubFil("fsdb.bin.0000.sqlite3"));
}
private Fsdb_db_file new_db(Io_url url) {return new Fsdb_db_file(url, Db_conn_bldr.I.New(url));}
private Fsdb_db_file new_db(Io_url url) {return new Fsdb_db_file(url, Db_conn_bldr.Instance.New(url));}
public Fsdb_db_file new_db__bin(Io_url url) {
Fsdb_db_file rv = new_db(url);
Fsd_bin_tbl bin_tbl = new Fsd_bin_tbl(rv.Conn(), true); // NOTE: schema_is_1 is always true b/c it is in Fsdb_db_mgr__v1_bldr
bin_tbl.Create_tbl();
return rv;
}
public static final Fsdb_db_mgr__v1_bldr I = new Fsdb_db_mgr__v1_bldr(); Fsdb_db_mgr__v1_bldr() {}
public static final Fsdb_db_mgr__v1_bldr Instance = new Fsdb_db_mgr__v1_bldr(); Fsdb_db_mgr__v1_bldr() {}
}

View File

@@ -40,9 +40,9 @@ public class Fsdb_db_mgr__v2 implements Fsdb_db_mgr {
if (mnt_id == Fsm_mnt_mgr.Mnt_idx_user) return file_user_core;
if (layout.Tid_is_all_or_few()) return file_main_core;
Io_url url = wiki_dir.GenSubFil(file_name);
Db_conn conn = Db_conn_bldr.I.Get(url);
Db_conn conn = Db_conn_bldr.Instance.Get(url);
if (conn == null) { // bin file deleted or not downloaded; use Noop Db_conn and continue; do not fail; DATE:2015-04-16
Gfo_usr_dlg_.I.Warn_many("", "", "fsdb.bin:file does not exist; url=~{0}", url);
Gfo_usr_dlg_.Instance.Warn_many("", "", "fsdb.bin:file does not exist; url=~{0}", url);
conn = Db_conn_.Noop;
}
return new Fsdb_db_file(url, conn);
@@ -51,7 +51,7 @@ public class Fsdb_db_mgr__v2 implements Fsdb_db_mgr {
if (mnt_id == Fsm_mnt_mgr.Mnt_idx_user) return Fsdb_db_mgr__v2_bldr.Make_bin_tbl(file_user_core);
if (layout.Tid_is_all_or_few()) return Fsdb_db_mgr__v2_bldr.Make_bin_tbl(file_main_core);
Io_url url = wiki_dir.GenSubFil(file_name);
Db_conn conn = Db_conn_bldr.I.New(url);
Db_conn conn = Db_conn_bldr.Instance.New(url);
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, Cfg_tbl_name); cfg_tbl.Create_tbl();
return Fsdb_db_mgr__v2_bldr.Make_bin_tbl(new Fsdb_db_file(url, conn));
}

View File

@@ -28,18 +28,18 @@ public class Fsdb_db_mgr__v2_bldr {
Io_url main_core_url = wiki_dir.GenSubFil(main_core_name);
Io_url user_core_url = wiki_dir.GenSubFil(user_core_name);
if (delete_if_exists) {
Db_conn_bldr.I.Get_or_noop(main_core_url).Rls_conn();
Db_conn_bldr.I.Get_or_noop(user_core_url).Rls_conn();
Io_mgr.I.DeleteFil(main_core_url);
Io_mgr.I.DeleteFil(user_core_url);
Db_conn_bldr.Instance.Get_or_noop(main_core_url).Rls_conn();
Db_conn_bldr.Instance.Get_or_noop(user_core_url).Rls_conn();
Io_mgr.Instance.DeleteFil(main_core_url);
Io_mgr.Instance.DeleteFil(user_core_url);
}
Fsdb_db_file main_core_file = Io_mgr.I.ExistsFil(main_core_url) ? Load_core_file(main_core_url) : Make_core_file_main(wiki, main_core_url, main_core_name, layout);
Fsdb_db_file user_core_file = Io_mgr.I.ExistsFil(user_core_url) ? Load_core_file(user_core_url) : Make_core_file_user(wiki, user_core_url, user_core_name, main_core_name);
Fsdb_db_file main_core_file = Io_mgr.Instance.ExistsFil(main_core_url) ? Load_core_file(main_core_url) : Make_core_file_main(wiki, main_core_url, main_core_name, layout);
Fsdb_db_file user_core_file = Io_mgr.Instance.ExistsFil(user_core_url) ? Load_core_file(user_core_url) : Make_core_file_user(wiki, user_core_url, user_core_name, main_core_name);
return new Fsdb_db_mgr__v2(layout, wiki_dir, main_core_file, user_core_file);
}
private Fsdb_db_file Load_core_file(Io_url url) {return new Fsdb_db_file(url, Db_conn_bldr.I.Get(url));}
private Fsdb_db_file Load_core_file(Io_url url) {return new Fsdb_db_file(url, Db_conn_bldr.Instance.Get(url));}
private Fsdb_db_file Make_core_file_main(Xow_wiki wiki, Io_url main_core_url, String main_core_name, Xowd_db_layout layout) {
Db_conn conn = layout.Tid_is_all() ? Db_conn_bldr.I.Get(main_core_url) : Db_conn_bldr.I.New(main_core_url); // if all, use existing (assumes same file name); else, create new
Db_conn conn = layout.Tid_is_all() ? Db_conn_bldr.Instance.Get(main_core_url) : Db_conn_bldr.Instance.New(main_core_url); // if all, use existing (assumes same file name); else, create new
conn.Txn_bgn("fsdb__core_file");
Fsdb_db_file rv = Make_core_file(main_core_url, conn, schema_is_1, Fsm_mnt_mgr.Mnt_idx_main);
if (!layout.Tid_is_all()) // do not make cfg data if all
@@ -49,7 +49,7 @@ public class Fsdb_db_mgr__v2_bldr {
return rv;
}
public Fsdb_db_file Make_core_file_user(Xow_wiki wiki, Io_url user_core_url, String user_file_name, String main_core_name) { // always create file; do not create mnt_tbl;
Db_conn conn = Db_conn_bldr.I.New(user_core_url);
Db_conn conn = Db_conn_bldr.Instance.New(user_core_url);
conn.Txn_bgn("fsdb__core_user");
Fsdb_db_file rv = Make_core_file(user_core_url, conn, schema_is_1, Fsm_mnt_mgr.Mnt_idx_user);
Fsm_bin_tbl dbb_tbl = new Fsm_bin_tbl(conn, schema_is_1, Fsm_mnt_mgr.Mnt_idx_user); dbb_tbl.Insert(0, user_file_name);
@@ -109,5 +109,5 @@ public class Fsdb_db_mgr__v2_bldr {
private static String Main_core_name_lot(String wiki_domain) {return wiki_domain + "-file-core.xowa";} // EX: en.wikipedia.org-file-core.xowa
public static String Make_user_name(String wiki_domain) {return wiki_domain + "-file-user.xowa";} // EX: en.wikipedia.org-file-user.xowa
private static final boolean schema_is_1 = false;
public static final Fsdb_db_mgr__v2_bldr I = new Fsdb_db_mgr__v2_bldr(); Fsdb_db_mgr__v2_bldr() {}
public static final Fsdb_db_mgr__v2_bldr Instance = new Fsdb_db_mgr__v2_bldr(); Fsdb_db_mgr__v2_bldr() {}
}

View File

@@ -67,7 +67,7 @@ public class Fsd_bin_tbl implements RlsAble {
byte[] rv = Select(owner_id, url);
if (rv == null) return false;
if (saved_in_parts.Val_y()) return true;
Io_mgr.I.SaveFilBry(url, rv);
Io_mgr.Instance.SaveFilBry(url, rv);
return true;
}
private byte[] Select(int owner_id, Io_url url) {

View File

@@ -29,6 +29,6 @@ public class Fsd_fil_itm {
public int Ext_id() {return ext_id;} private int ext_id;
public static final Fsd_fil_itm Null = null;
public static byte[] Gen_cache_key(Bry_bfr bfr, int dir_id, byte[] name) {
return bfr.Add_int_variable(dir_id).Add_byte_pipe().Add(name).Xto_bry_and_clear();
return bfr.Add_int_variable(dir_id).Add_byte_pipe().Add(name).To_bry_and_clear();
}
}

View File

@@ -57,5 +57,5 @@ class Fsdb_thm_itm_sorter implements gplx.lists.ComparerAble {
comp = Double_.Compare (lhs.Time() , rhs.Time()); if (comp != CompareAble_.Same) return comp; // sort by increasing time
return Int_.Compare (lhs.Page() , rhs.Page()); // sort by increasing page
}
public static final Fsdb_thm_itm_sorter I = new Fsdb_thm_itm_sorter(); Fsdb_thm_itm_sorter() {}
public static final Fsdb_thm_itm_sorter Instance = new Fsdb_thm_itm_sorter(); Fsdb_thm_itm_sorter() {}
}

View File

@@ -130,7 +130,7 @@ public class Fsd_thm_tbl implements RlsAble {
public static final String Hash_null = "", Modified_null_str = "";
public static boolean Match_nearest(List_adp list, Fsd_thm_itm thm, boolean schema_thm_page) {
int len = list.Count(); if (len == 0) return Bool_.N;
list.Sort_by(Fsdb_thm_itm_sorter.I);
list.Sort_by(Fsdb_thm_itm_sorter.Instance);
int thm_w = thm.W(), thm_page = thm.Page(); double thm_time = thm.Time();
Fsd_thm_itm max = null;
for (int i = 0; i < len; ++i) {

View File

@@ -24,10 +24,10 @@ public class Fsm_cfg_mgr {
}
public void Ctor_by_load() {
Db_cfg_hash hash = Grps_get_or_load(Grp_core);
this.next_id = hash.Get(Key_next_id).To_int_or(-1); if (next_id == -1) throw Err_.new_wo_type("next_id not found in cfg", "url", tbl.Conn().Conn_info().Xto_api());
this.schema_thm_page = hash.Get(Key_schema_thm_page).To_yn_or_n();
this.patch__next_id = hash.Get(Key_patch__next_id).To_yn_or_n();
this.patch__page_gt_1 = hash.Get(Key_patch__page_gt_1).To_yn_or_n();
this.next_id = hash.Get_by(Key_next_id).To_int_or(-1); if (next_id == -1) throw Err_.new_wo_type("next_id not found in cfg", "url", tbl.Conn().Conn_info().Xto_api());
this.schema_thm_page = hash.Get_by(Key_schema_thm_page).To_yn_or_n();
this.patch__next_id = hash.Get_by(Key_patch__next_id).To_yn_or_n();
this.patch__page_gt_1 = hash.Get_by(Key_patch__page_gt_1).To_yn_or_n();
}
public Db_cfg_tbl Tbl() {return tbl;}
public int Next_id() {return next_id++;} private int next_id = 1;

View File

@@ -31,8 +31,8 @@ public class Fsm_mnt_mgr implements GfoInvkAble {
}
this.insert_idx = cfg_tbl.Select_int(Cfg_grp_core, Cfg_key_mnt_insert_idx);
Db_cfg_hash cfg_hash = this.Mnts__get_main().Cfg_mgr().Grps_get_or_load(Xof_fsdb_mgr_cfg.Grp_xowa);
boolean use_thumb_w = cfg_hash.Get(Xof_fsdb_mgr_cfg.Key_upright_use_thumb_w).To_yn_or_n();
boolean fix_default = cfg_hash.Get(Xof_fsdb_mgr_cfg.Key_upright_fix_default).To_yn_or_n();
boolean use_thumb_w = cfg_hash.Get_by(Xof_fsdb_mgr_cfg.Key_upright_use_thumb_w).To_yn_or_n();
boolean fix_default = cfg_hash.Get_by(Xof_fsdb_mgr_cfg.Key_upright_fix_default).To_yn_or_n();
this.patch_upright_tid = Xof_patch_upright_tid_.Merge(use_thumb_w, fix_default);
}
public int Mnts__len() {return mnt_ary_len;}

View File

@@ -94,7 +94,7 @@ public class Gfui_bnd_parser {
Gfui_bnd_tkn tkn = (Gfui_bnd_tkn)tkns.Get_at(i);
tkn.Write(tmp_bfr, !src_is_gfui);
}
return tmp_bfr.Xto_str_and_clear();
return tmp_bfr.To_str_and_clear();
}
private void Process_sym(boolean src_is_gfui, boolean is_numeric, Gfui_bnd_tkn sym_tkn, int itm_bgn, int itm_end) {
Hash_adp_bry regy = src_is_gfui ? gfui_regy : norm_regy;

View File

@@ -26,12 +26,12 @@ public class BinaryHeap_Io_line_rdr_tst {
}
}
class BinaryHeap_Io_line_rdr_fxt {
BinaryHeap_Io_line_rdr heap = new BinaryHeap_Io_line_rdr(Io_sort_split_itm_sorter._); int file_total;
BinaryHeap_Io_line_rdr heap = new BinaryHeap_Io_line_rdr(Io_sort_split_itm_sorter.Instance); int file_total;
public BinaryHeap_Io_line_rdr_fxt Add(String... ary) {
file_total = ary.length;
for (int i = 0; i < file_total; i++) {
Io_url url = Io_url_.mem_fil_("mem/fil_" + ary[i] + ".txt");
Io_mgr.I.SaveFilStr(url, ary[i]);
Io_mgr.Instance.SaveFilStr(url, ary[i]);
Io_line_rdr stream = new Io_line_rdr(Gfo_usr_dlg_.Test(), url);
stream.Read_next();
heap.Add(stream);

View File

@@ -23,7 +23,7 @@ public class Io_buffer_rdr implements RlsAble {
this.rdr = rdr; this.url = url;
if (bfr_len <= 0) throw Err_.new_wo_type("bfr_len must be > 0", "bfr_len", bfr_len);
bfr = new byte[bfr_len]; this.bfr_len = bfr_len;
IoItmFil fil = Io_mgr.I.QueryFil(url); if (!fil.Exists()) throw Err_.new_wo_type("fil does not exist", "url", url);
IoItmFil fil = Io_mgr.Instance.QueryFil(url); if (!fil.Exists()) throw Err_.new_wo_type("fil does not exist", "url", url);
fil_len = fil.Size();
fil_pos = 0;
fil_eof = false;
@@ -61,7 +61,7 @@ public class Io_buffer_rdr implements RlsAble {
}
@gplx.Internal protected void Dump_to_file(int bgn, int len, String url_str, String msg) { // DBG:
String text = String_.new_u8__by_len(bfr, bgn, len);
Io_mgr.I.AppendFilStr(Io_url_.new_any_(url_str), msg + text + "\n");
Io_mgr.Instance.AppendFilStr(Io_url_.new_any_(url_str), msg + text + "\n");
}
public static Io_buffer_rdr new_(Io_stream_rdr rdr, int bfr_len) {
Io_buffer_rdr rv = new Io_buffer_rdr(rdr, rdr.Url(), bfr_len);

View File

@@ -19,7 +19,7 @@ package gplx.ios; import gplx.*;
import org.junit.*; import gplx.ios.*;
public class Io_buffer_rdr_tst {
@Before public void init() {
Io_mgr.I.InitEngine_mem();
Io_mgr.Instance.InitEngine_mem();
fil = Io_url_.mem_fil_("mem/byteStreamRdr.txt");
ini_Write("0123456789");
rdr = Io_buffer_rdr.new_(Io_stream_rdr_.file_(fil), 4);
@@ -52,7 +52,7 @@ public class Io_buffer_rdr_tst {
rdr.Bfr_load_all(); // NOTE: change to zip_rdrs make eof detection difficult; force another load to ensure that file_pos goes past file_len
tst_Bfr("8", "9").tst_ReadDone(true);
}
private void ini_Write(String s) {Io_mgr.I.SaveFilStr(fil, s);}
private void ini_Write(String s) {Io_mgr.Instance.SaveFilStr(fil, s);}
Io_buffer_rdr_tst tst_Bfr(String... expdAry) {
String[] actlAry = new String[rdr.Bfr_len()];
for (int i = 0; i < actlAry.length; i++)

View File

@@ -137,7 +137,7 @@ public class Io_line_rdr {
Io_url url = urls[url_idx];
usr_dlg.Prog_many(GRP_KEY, "load", "loading dump file: ~{0}", url.NameAndExt());
if (file_skip_line0) {
byte[] stream_bry = Io_mgr.I.LoadFilBry(url);
byte[] stream_bry = Io_mgr.Instance.LoadFilBry(url);
int stream_bry_len = stream_bry.length;
int nl_pos = Bry_find_.Find_fwd(stream_bry, Byte_ascii.Nl, 0, stream_bry_len);
if (nl_pos == Bry_.NotFound)
@@ -147,7 +147,7 @@ public class Io_line_rdr {
stream = gplx.ios.IoStream_.ary_(stream_bry);
}
else {
stream = Io_mgr.I.OpenStreamRead(url);
stream = Io_mgr.Instance.OpenStreamRead(url);
}
file_pos = 0; file_len = stream.Len();
file_done = false;

View File

@@ -55,7 +55,7 @@ class Io_line_rdr_fxt {
public Io_line_rdr_fxt File_lines_(int count) {
for (int i = 0; i < count; i++)
tmp.Add_int_fixed(i, 2).Add_byte_nl();
Io_mgr.I.SaveFilBry(rdr.Urls()[0], tmp.Xto_bry_and_clear());
Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.To_bry_and_clear());
return this;
}
// public Io_url[] Src_fils() {return src_fils;} public Io_line_rdr_fxt Src_fils_(Io_url[] v) {src_fils = v; return this;} Io_url[] src_fils;
@@ -69,14 +69,14 @@ class Io_line_rdr_fxt {
public Io_line_rdr_fxt File_lines_pipe_(int count) {
for (int i = 0; i < count; i++)
tmp.Add_int_fixed(i, 2).Add_byte(Byte_ascii.Pipe).Add_byte_nl();
Io_mgr.I.SaveFilBry(rdr.Urls()[0], tmp.Xto_bry_and_clear());
Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.To_bry_and_clear());
return this;
}
public Io_line_rdr_fxt File_lines_(int fil_idx, int bgn, int end) {
for (int i = bgn; i < end; i++)
tmp.Add_int_fixed(i, 2).Add_byte_nl();
Io_mgr.I.SaveFilBry(rdr.Urls()[fil_idx], tmp.Xto_bry_and_clear());
Io_mgr.Instance.SaveFilBry(rdr.Urls()[fil_idx], tmp.To_bry_and_clear());
return this;
}
public Io_line_rdr_fxt Clear() {rdr.Clear(); return this;}

View File

@@ -19,7 +19,7 @@ package gplx.ios; import gplx.*;
import gplx.lists.*;
public class Io_sort {
public Io_sort Memory_max_(int v) {memory_max = v; return this;} private int memory_max = Io_mgr.Len_kb;
public Io_url[] Split(Gfo_usr_dlg usr_dlg, Io_url_gen src_fil_gen, Io_url_gen trg_fil_gen, Io_line_rdr_key_gen key_gen) {return Split(usr_dlg, src_fil_gen, trg_fil_gen, Io_sort_split_itm_sorter._, key_gen);}
public Io_url[] Split(Gfo_usr_dlg usr_dlg, Io_url_gen src_fil_gen, Io_url_gen trg_fil_gen, Io_line_rdr_key_gen key_gen) {return Split(usr_dlg, src_fil_gen, trg_fil_gen, Io_sort_split_itm_sorter.Instance, key_gen);}
public Io_url[] Split(Gfo_usr_dlg usr_dlg, Io_url_gen src_fil_gen, Io_url_gen trg_fil_gen, ComparerAble row_comparer, Io_line_rdr_key_gen key_gen) {
Io_line_rdr rdr = new Io_line_rdr(usr_dlg, src_fil_gen.Prv_urls()).Load_len_(4 * Io_mgr.Len_kb).Key_gen_(key_gen); // NOTE: do not set load_len to memory_max; only want to load in increments
List_adp rv = List_adp_.new_();
@@ -70,11 +70,11 @@ public class Io_sort {
for (int i = 0; i < len; i++) {
Io_sort_split_itm itm = (Io_sort_split_itm)list.Get_at(i);
int add_len = itm.Row_end() - itm.Row_bgn();
if ((tmp.Len() + add_len) > Const_bfr_max) Io_mgr.I.AppendFilBfr(url, tmp);
if ((tmp.Len() + add_len) > Const_bfr_max) Io_mgr.Instance.AppendFilBfr(url, tmp);
tmp.Add_mid(itm.Bfr(), itm.Row_bgn(), itm.Row_end());
itm.Rls();
}
Io_mgr.I.AppendFilBfr(url, tmp);
Io_mgr.Instance.AppendFilBfr(url, tmp);
list.Clear();
url_list.Add(url);
}
@@ -84,7 +84,7 @@ public class Io_sort {
int default_load_len = memory_max / urls_len + 1;
for (int i = 0; i < urls_len; i++) {
Io_url url = urls[i];
int file_len = (int)Io_mgr.I.QueryFil(url).Size();
int file_len = (int)Io_mgr.Instance.QueryFil(url).Size();
int load_len = file_len < default_load_len ? file_len : default_load_len; // PERF.NOTE: 32 MB is default, but if file is 1 MB (or else) only create a bfr for 1 MB; using 32 MB will throw OutOfMemory on -Xmx 64m; DATE:20130112
Io_line_rdr stream_bfr = new Io_line_rdr(usr_dlg, url).Key_gen_(key_gen).Load_len_(load_len);
boolean read = stream_bfr.Read_next();

View File

@@ -25,5 +25,5 @@ class Io_sort_filCmd_null implements Io_sort_filCmd {
public void Bfr_add(Io_line_rdr stream) {}
public void Fil_bgn(Io_line_rdr stream) {}
public void Fil_end() {}
public static final Io_sort_filCmd_null _ = new Io_sort_filCmd_null(); Io_sort_filCmd_null() {}
public static final Io_sort_filCmd_null Instance = new Io_sort_filCmd_null(); Io_sort_filCmd_null() {}
}

View File

@@ -31,7 +31,7 @@ public class Io_sort_fil_basic implements Io_sort_cmd { // 123|bgn|end|1
private void Flush() {
Io_url url = url_gen.Nxt_url();
usr_dlg.Prog_one(GRP_KEY, "make", "making: ~{0}", url.NameAndExt());
Io_mgr.I.SaveFilBry(url, bfr.Bfr(), bfr.Len());
Io_mgr.Instance.SaveFilBry(url, bfr.Bfr(), bfr.Len());
bfr.Clear();
}
static final String GRP_KEY = "xowa.bldr.io_sort";

View File

@@ -47,7 +47,7 @@ public class Io_sort_misc_tst {
}
Io_line_rdr new_Io_line_rdr(String url_str, String text) {
Io_url url = Io_url_.mem_fil_(url_str);
Io_mgr.I.SaveFilStr(url, text);
Io_mgr.Instance.SaveFilStr(url, text);
Io_line_rdr rv = new Io_line_rdr(Gfo_usr_dlg_.Test(), url);
rv.Read_next();
return rv;

View File

@@ -22,5 +22,5 @@ public class Io_sort_split_itm_sorter implements gplx.lists.ComparerAble {
// Tfds.Write(String_.new_u8(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end()), String_.new_u8(rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end()));
return Bry_.Compare(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end(), rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end());
}
public static final Io_sort_split_itm_sorter _ = new Io_sort_split_itm_sorter(); Io_sort_split_itm_sorter() {}
public static final Io_sort_split_itm_sorter Instance = new Io_sort_split_itm_sorter(); Io_sort_split_itm_sorter() {}
}

View File

@@ -27,40 +27,40 @@ public class Io_sort_tst {
class Io_sort_fxt {
Io_sort externalSort = new Io_sort().Memory_max_(Io_mgr.Len_kb);
String_bldr sb = String_bldr_.new_();
public Io_sort_fxt Clear() {Io_mgr.I.InitEngine_mem(); return this;}
public Io_sort_fxt Clear() {Io_mgr.Instance.InitEngine_mem(); return this;}
public Io_sort_fxt Memory_max_(int v) {externalSort.Memory_max_(v); return this;}
public Io_sort_fxt Src_(String v) {src = v; return this;} private String src;
public Io_sort_fxt Sorted_(String v) {sorted = v; return this;} private String sorted;
public void tst() {
Io_url src_url = Io_url_.mem_fil_("mem/src.txt");
Io_url trg_url = Io_url_.mem_fil_("mem/trg.txt");
Io_mgr.I.DeleteFil(src_url); Io_mgr.I.DeleteFil(trg_url);
Io_mgr.Instance.DeleteFil(src_url); Io_mgr.Instance.DeleteFil(trg_url);
Io_mgr.I.SaveFilStr(src_url, src);
Io_mgr.Instance.SaveFilStr(src_url, src);
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Test();
Io_url_gen src_fil_gen = Io_url_gen_.fil_(src_url);
Io_url[] tmp_url_ary = externalSort.Split(usr_dlg, src_fil_gen, Io_url_gen_.dir_(src_url.OwnerDir()), Io_line_rdr_key_gen_.first_pipe);
Io_sort_fil_basic cmd = new Io_sort_fil_basic(usr_dlg, Io_url_gen_.fil_(trg_url), Io_mgr.Len_kb);
externalSort.Merge(usr_dlg, tmp_url_ary, Io_sort_split_itm_sorter._, Io_line_rdr_key_gen_.first_pipe, cmd);
externalSort.Merge(usr_dlg, tmp_url_ary, Io_sort_split_itm_sorter.Instance, Io_line_rdr_key_gen_.first_pipe, cmd);
String actl = Io_mgr.I.LoadFilStr(trg_url);
String actl = Io_mgr.Instance.LoadFilStr(trg_url);
Tfds.Eq_ary_str(String_.SplitLines_nl(sorted), String_.SplitLines_nl(actl));
}
public String GenRandom(int rows, int pad) {
List_adp list = List_adp_.new_();
for (int i = 0; i < rows; i++)
list.Add(Int_.Xto_str_pad_bgn_zero(i, pad) + "|");
list.Add(Int_.To_str_pad_bgn_zero(i, pad) + "|");
list.Shuffle();
for (int i = 0; i < rows; i++) {
String itm = (String)list.Get_at(i);
sb.Add(itm).Add_char_nl();
}
return sb.Xto_str_and_clear();
return sb.To_str_and_clear();
}
public String GenOrdered(int rows, int pad) {
for (int i = 0; i < rows; i++)
sb.Add(Int_.Xto_str_pad_bgn_zero(i, pad) + "|" + "\n");
return sb.Xto_str_and_clear();
sb.Add(Int_.To_str_pad_bgn_zero(i, pad) + "|" + "\n");
return sb.To_str_and_clear();
}
}

View File

@@ -25,21 +25,21 @@ class Io_url_gen_dir implements Io_url_gen {
public String Fmt() {return fmt;} public Io_url_gen_dir Fmt_(String v) {fmt = v; return this;} private String fmt = "{0}.csv";
public int Fmt_digits() {return fmt_digits;} public Io_url_gen_dir Fmt_digits_(int v) {fmt_digits = v; return this;} private int fmt_digits = 10;
public Io_url Cur_url() {return cur_url;} Io_url cur_url;
public Io_url Nxt_url() {cur_url = dir.GenSubFil(String_.Format(fmt, Int_.Xto_str_pad_bgn_zero(idx++, fmt_digits))); return cur_url;} private int idx = 0;
public Io_url Nxt_url() {cur_url = dir.GenSubFil(String_.Format(fmt, Int_.To_str_pad_bgn_zero(idx++, fmt_digits))); return cur_url;} private int idx = 0;
public Io_url[] Prv_urls() {
Io_url[] rv = new Io_url[idx];
for (int i = 0; i < idx; i++) {
rv[i] = dir.GenSubFil(String_.Format(fmt, Int_.Xto_str_pad_bgn_zero(i, fmt_digits)));
rv[i] = dir.GenSubFil(String_.Format(fmt, Int_.To_str_pad_bgn_zero(i, fmt_digits)));
}
return rv;
}
public void Del_all() {if (Io_mgr.I.ExistsDir(dir)) Io_mgr.I.DeleteDirDeep(dir);}
public void Del_all() {if (Io_mgr.Instance.ExistsDir(dir)) Io_mgr.Instance.DeleteDirDeep(dir);}
public Io_url_gen_dir(Io_url dir) {this.dir = dir;} Io_url dir;
}
class Io_url_gen_fil implements Io_url_gen {
public Io_url Cur_url() {return cur_url;} Io_url cur_url;
public Io_url Nxt_url() {return cur_url;}
public Io_url[] Prv_urls() {return new Io_url[]{cur_url};}
public void Del_all() {Io_mgr.I.DeleteFil_args(cur_url).MissingFails_off().Exec();}
public void Del_all() {Io_mgr.Instance.DeleteFil_args(cur_url).MissingFails_off().Exec();}
public Io_url_gen_fil(Io_url fil) {this.cur_url = fil;}
}

View File

@@ -20,9 +20,9 @@ import java.io.*;
import java.util.zip.*;
public class Io_zip_mgr_base implements Io_zip_mgr {
public void Zip_fil(Io_url src_fil, Io_url trg_fil) {
byte[] src_bry = Io_mgr.I.LoadFilBry(src_fil);
byte[] src_bry = Io_mgr.Instance.LoadFilBry(src_fil);
byte[] trg_bry = Zip_bry(src_bry, 0, src_bry.length);
Io_mgr.I.SaveFilBry(trg_fil, trg_bry);
Io_mgr.Instance.SaveFilBry(trg_fil, trg_bry);
}
public void Zip_dir(Io_url src_dir, Io_url trg_fil) {
try {
@@ -56,7 +56,7 @@ public class Io_zip_mgr_base implements Io_zip_mgr {
} catch(IOException e) {throw Err_.new_exc(e, "io", "error duing zip", "src", zip_path);}
}
private Io_url[] Zip_dir__get_subs(Io_url url) {
return Io_mgr.I.QueryDir_args(url).DirInclude_().ExecAsUrlAry();
return Io_mgr.Instance.QueryDir_args(url).DirInclude_().ExecAsUrlAry();
}
public byte[] Zip_bry(byte[] src, int bgn, int len) {
ByteArrayInputStream src_stream = new ByteArrayInputStream(src, bgn, len);
@@ -90,7 +90,7 @@ public class Io_zip_mgr_base implements Io_zip_mgr {
public void Unzip_to_dir(Io_url src_fil, Io_url trg_dir) {
byte[] buffer = new byte[4096];
try{
Io_mgr.I.CreateDirIfAbsent(trg_dir);
Io_mgr.Instance.CreateDirIfAbsent(trg_dir);
ZipInputStream zip_strm = new ZipInputStream(new FileInputStream(src_fil.Raw()));
ZipEntry zip_eny = zip_strm.getNextEntry();
@@ -98,9 +98,9 @@ public class Io_zip_mgr_base implements Io_zip_mgr {
String itm_name = zip_eny.getName();
if (Op_sys.Cur().Tid_is_wnt()) itm_name = String_.Replace(itm_name, "/", "\\");
Io_url itm_url = Io_url_.new_any_(trg_dir.GenSubFil(itm_name).Raw());
Io_mgr.I.CreateDirIfAbsent(itm_url.OwnerDir()); // make sure owner dir exists
Io_mgr.Instance.CreateDirIfAbsent(itm_url.OwnerDir()); // make sure owner dir exists
if (itm_url.Type_fil()) {
Io_mgr.I.SaveFilStr_args(itm_url, "").Exec();
Io_mgr.Instance.SaveFilStr_args(itm_url, "").Exec();
File itm_file = new File(itm_url.Raw());
FileOutputStream itm_strm = new FileOutputStream(itm_file);
int len;
@@ -115,5 +115,5 @@ public class Io_zip_mgr_base implements Io_zip_mgr {
} catch(IOException e) {throw Err_.new_exc(e, "io", "error duing unzip", "src", src_fil.Raw(), "trg", trg_dir.Raw());}
}
byte[] tmp = new byte[4096]; int tmpLen = 4096;
public static final Io_zip_mgr _ = new Io_zip_mgr_base();
public static final Io_zip_mgr Instance = new Io_zip_mgr_base();
}

View File

@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.ios; import gplx.*;
public class Io_zip_mgr_mok implements Io_zip_mgr {
public void Zip_fil(Io_url src_fil, Io_url trg_fil) {
byte[] src_bry = Io_mgr.I.LoadFilBry(src_fil);
byte[] src_bry = Io_mgr.Instance.LoadFilBry(src_fil);
byte[] zip_bry = Zip_bry(src_bry, 0, src_bry.length);
Io_mgr.I.SaveFilBry(trg_fil, zip_bry);
Io_mgr.Instance.SaveFilBry(trg_fil, zip_bry);
}
public void Zip_dir(Io_url src_dir, Io_url trg_fil) {}
public byte[] Zip_bry(byte[] src, int bgn, int len) {return Bry_.Add(Bry_zipped, Bry_.Mid(src, bgn, len));}
@@ -32,5 +32,5 @@ public class Io_zip_mgr_mok implements Io_zip_mgr {
}
public void Unzip_to_dir(Io_url src_fil, Io_url trg_dir) {}
private static final byte[] Bry_zipped = Bry_.new_a7("zipped:");
public static final Io_zip_mgr_mok _ = new Io_zip_mgr_mok(); Io_zip_mgr_mok() {}
public static final Io_zip_mgr_mok Instance = new Io_zip_mgr_mok(); Io_zip_mgr_mok() {}
}

View File

@@ -22,7 +22,7 @@ public class Io_zip_mgr_tst {
Zip_unzip_tst("abcdefghijklmnopqrstuvwxyz");
}
private void Zip_unzip_tst(String s) {
Io_zip_mgr zip_mgr = Io_zip_mgr_base._;
Io_zip_mgr zip_mgr = Io_zip_mgr_base.Instance;
byte[] src = Bry_.new_a7(s);
byte[] zip = zip_mgr.Zip_bry(src, 0, src.length);
byte[] unz = zip_mgr.Unzip_bry(zip, 0, zip.length);

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
public class Dsv_fld_parser_ {
public static final Dsv_fld_parser Bry_parser = Dsv_fld_parser_bry._;
public static final Dsv_fld_parser Int_parser = Dsv_fld_parser_int._;
public static final Dsv_fld_parser Bry_parser = Dsv_fld_parser_bry.Instance;
public static final Dsv_fld_parser Int_parser = Dsv_fld_parser_int.Instance;
public static final Dsv_fld_parser Line_parser__comment_is_pipe = new Dsv_fld_parser_line(Byte_ascii.Pipe);
public static Err err_fld_unhandled(Dsv_fld_parser parser, Dsv_wkr_base wkr, int fld_idx, byte[] src, int bgn, int end) {
throw Err_.new_wo_type("fld unhandled", "parser", Type_adp_.NameOf_obj(parser), "wkr", Type_adp_.NameOf_obj(wkr), "fld_idx", fld_idx, "val", String_.new_u8(src, bgn, end)).Trace_ignore_add_1_();
@@ -80,7 +80,7 @@ class Dsv_fld_parser_bry implements Dsv_fld_parser {
++pos;
}
}
public static final Dsv_fld_parser_bry _ = new Dsv_fld_parser_bry(); Dsv_fld_parser_bry() {}
public static final Dsv_fld_parser_bry Instance = new Dsv_fld_parser_bry(); Dsv_fld_parser_bry() {}
}
class Dsv_fld_parser_int implements Dsv_fld_parser {
private byte fld_dlm = Byte_ascii.Pipe, row_dlm = Byte_ascii.Nl;
@@ -110,5 +110,5 @@ class Dsv_fld_parser_int implements Dsv_fld_parser {
++pos;
}
}
public static final Dsv_fld_parser_int _ = new Dsv_fld_parser_int(); Dsv_fld_parser_int() {}
public static final Dsv_fld_parser_int Instance = new Dsv_fld_parser_int(); Dsv_fld_parser_int() {}
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
public class Dsv_tbl_parser implements GfoInvkAble, RlsAble {
private Dsv_wkr_base mgr;
private Dsv_fld_parser[] fld_parsers = new Dsv_fld_parser[2];
private Dsv_fld_parser[] fld_parsers = new Dsv_fld_parser[2]; private int fld_parsers_len = 2;
public byte[] Src() {return src;} private byte[] src;
public int Fld_bgn() {return fld_bgn;} private int fld_bgn = 0;
public int Fld_idx() {return fld_idx;} private int fld_idx = 0;
@@ -30,7 +30,7 @@ public class Dsv_tbl_parser implements GfoInvkAble, RlsAble {
public void Init(Dsv_wkr_base mgr, Dsv_fld_parser... fld_parsers) {
this.mgr = mgr;
this.fld_parsers = fld_parsers;
int fld_parsers_len = fld_parsers.length;
this.fld_parsers_len = fld_parsers.length;
for (int i = 0; i < fld_parsers_len; i++)
fld_parsers[i].Init(fld_dlm, row_dlm);
}
@@ -50,10 +50,10 @@ public class Dsv_tbl_parser implements GfoInvkAble, RlsAble {
fld_idx = 0;
}
public void Parse(byte[] src) {
int src_len = src.length; if (src_len == 0) return; // NOTE: do not process if empty; note that loop below will process once for empty row
this.src = src;
int src_len = src.length;
int pos = 0;
while (pos < src_len) {
while (true) {
if (fld_idx == 0 && skip_blank_lines) { // row committed; skip blank lines
while (pos < src_len) {
if (src[pos] == row_dlm) {
@@ -64,12 +64,16 @@ public class Dsv_tbl_parser implements GfoInvkAble, RlsAble {
break;
}
}
if (fld_idx == fld_parsers_len) break;
Dsv_fld_parser fld_parser = fld_parsers[fld_idx];
pos = fld_parser.Parse(this, mgr, src, pos, src_len, fld_idx, fld_bgn);
if ( pos > src_len // pos is now fully past src_len; exit
|| pos == src_len && fld_idx == 0 // last pos but fld_idx > 0; do one more iteration which will "commit row; EX: 2 fields and src of "a|"; EOS should close out row
) break;
}
}
public void Rls() {
src = null; fld_parsers = null; mgr = null;
src = null; fld_parsers = null; mgr = null; fld_parsers_len = 0;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_load_by_str)) Parse(m.ReadBry("v"));

View File

@@ -34,7 +34,7 @@ class Mok_int_itm implements To_str_able {
private String fld_0;
private int fld_1, fld_2;
public Mok_int_itm(String fld_0, int fld_1, int fld_2) {this.fld_0 = fld_0; this.fld_1 = fld_1; this.fld_2 = fld_2;}
public String To_str() {return String_.Concat_with_str("|", fld_0, Int_.Xto_str(fld_1), Int_.Xto_str(fld_2));}
public String To_str() {return String_.Concat_with_str("|", fld_0, Int_.To_str(fld_1), Int_.To_str(fld_2));}
}
class Mok_int_mgr extends Mok_mgr_base {
public void Clear() {itms.Clear();}
@@ -42,7 +42,7 @@ class Mok_int_mgr extends Mok_mgr_base {
private String fld_0;
private int fld_1, fld_2;
@Override public Dsv_fld_parser[] Fld_parsers() {
return new Dsv_fld_parser[] {Dsv_fld_parser_bry._, Dsv_fld_parser_int._, Dsv_fld_parser_int._};
return new Dsv_fld_parser[] {Dsv_fld_parser_bry.Instance, Dsv_fld_parser_int.Instance, Dsv_fld_parser_int.Instance};
}
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
switch (fld_idx) {

View File

@@ -53,6 +53,13 @@ public class Dsv_tbl_parser_str_tst {
, fxt.itm_str_("b")
);
}
@Test public void Incomplete_row_2() { // PURPOSE: handle multiple incomplete cells
fxt .Test_load(String_.Concat_lines_nl_skip_last
( "a|")
, fxt.mgr_str_(3)
, fxt.itm_str_("a", "")
);
}
}
abstract class Mok_mgr_base extends Dsv_wkr_base {
public abstract To_str_able[] Itms();

View File

@@ -15,7 +15,7 @@ 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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
interface Gfs_lxr {
int Lxr_tid();
int Process(Gfs_parser_ctx ctx, int bgn, int end);
@@ -45,7 +45,7 @@ class Gfs_lxr_whitespace implements Gfs_lxr {
}
return rv;
}
public static final Gfs_lxr_whitespace _ = new Gfs_lxr_whitespace(); Gfs_lxr_whitespace() {}
public static final Gfs_lxr_whitespace Instance = new Gfs_lxr_whitespace(); Gfs_lxr_whitespace() {}
}
class Gfs_lxr_comment_flat implements Gfs_lxr {
public Gfs_lxr_comment_flat(byte[] bgn_bry, byte[] end_bry) {
@@ -89,7 +89,7 @@ class Gfs_lxr_identifier implements Gfs_lxr {
if (rv == Gfs_lxr_.Rv_eos) ctx.Process_eos(); // eos
return rv;
}
public static final Gfs_lxr_identifier _ = new Gfs_lxr_identifier(); Gfs_lxr_identifier() {}
public static final Gfs_lxr_identifier Instance = new Gfs_lxr_identifier(); Gfs_lxr_identifier() {}
}
class Gfs_lxr_semic implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_semic;}
@@ -103,7 +103,7 @@ class Gfs_lxr_semic implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_semic _ = new Gfs_lxr_semic(); Gfs_lxr_semic() {}
public static final Gfs_lxr_semic Instance = new Gfs_lxr_semic(); Gfs_lxr_semic() {}
}
class Gfs_lxr_dot implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_dot;}
@@ -115,7 +115,7 @@ class Gfs_lxr_dot implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_dot _ = new Gfs_lxr_dot(); Gfs_lxr_dot() {}
public static final Gfs_lxr_dot Instance = new Gfs_lxr_dot(); Gfs_lxr_dot() {}
}
class Gfs_lxr_paren_bgn implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_paren_bgn;}
@@ -126,7 +126,7 @@ class Gfs_lxr_paren_bgn implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_paren_bgn _ = new Gfs_lxr_paren_bgn(); Gfs_lxr_paren_bgn() {}
public static final Gfs_lxr_paren_bgn Instance = new Gfs_lxr_paren_bgn(); Gfs_lxr_paren_bgn() {}
}
class Gfs_lxr_paren_end implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_paren_end;}
@@ -139,7 +139,7 @@ class Gfs_lxr_paren_end implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_paren_end _ = new Gfs_lxr_paren_end(); Gfs_lxr_paren_end() {}
public static final Gfs_lxr_paren_end Instance = new Gfs_lxr_paren_end(); Gfs_lxr_paren_end() {}
}
class Gfs_lxr_quote implements Gfs_lxr {
public Gfs_lxr_quote(byte[] bgn_bry, byte[] end_bry) {
@@ -167,7 +167,7 @@ class Gfs_lxr_quote implements Gfs_lxr {
break;
}
}
ctx.Make_atr_by_bry(lxr_bgn + bgn_bry_len, end_pos, bfr.Xto_bry_and_clear());
ctx.Make_atr_by_bry(lxr_bgn + bgn_bry_len, end_pos, bfr.To_bry_and_clear());
}
else
ctx.Make_atr(lxr_bgn + bgn_bry_len, end_pos);
@@ -184,7 +184,7 @@ class Gfs_lxr_curly_bgn implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_curly_bgn _ = new Gfs_lxr_curly_bgn(); Gfs_lxr_curly_bgn() {}
public static final Gfs_lxr_curly_bgn Instance = new Gfs_lxr_curly_bgn(); Gfs_lxr_curly_bgn() {}
}
class Gfs_lxr_curly_end implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_curly_end;}
@@ -192,7 +192,7 @@ class Gfs_lxr_curly_end implements Gfs_lxr {
ctx.Stack_pop(bgn);
return end;
}
public static final Gfs_lxr_curly_end _ = new Gfs_lxr_curly_end(); Gfs_lxr_curly_end() {}
public static final Gfs_lxr_curly_end Instance = new Gfs_lxr_curly_end(); Gfs_lxr_curly_end() {}
}
class Gfs_lxr_equal implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_eq;}
@@ -200,7 +200,7 @@ class Gfs_lxr_equal implements Gfs_lxr {
ctx.Make_nde(bgn, end).Op_tid_(Gfs_nde.Op_tid_assign);
return end;
}
public static final Gfs_lxr_equal _ = new Gfs_lxr_equal(); Gfs_lxr_equal() {}
public static final Gfs_lxr_equal Instance = new Gfs_lxr_equal(); Gfs_lxr_equal() {}
}
class Gfs_lxr_comma implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_comma;}
@@ -210,5 +210,5 @@ class Gfs_lxr_comma implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_comma _ = new Gfs_lxr_comma(); Gfs_lxr_comma() {}
public static final Gfs_lxr_comma Instance = new Gfs_lxr_comma(); Gfs_lxr_comma() {}
}

View File

@@ -15,7 +15,7 @@ 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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
class Gfs_lxr_ {
public static final int Rv_init = -1, Rv_null = -2, Rv_eos = -3, Rv_lxr = -4;
public static final int Tid_identifier = 1, Tid_dot = 2, Tid_semic = 3, Tid_paren_bgn = 4, Tid_paren_end = 5, Tid_curly_bgn = 6, Tid_curly_end = 7, Tid_quote = 8, Tid_comma = 9, Tid_whitespace = 10, Tid_comment = 11, Tid_eq = 12;

View File

@@ -15,16 +15,16 @@ 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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
public class Gfs_msg_bldr implements GfoMsgParser {
Gfs_parser parser = new Gfs_parser();
private final Gfs_parser parser = new Gfs_parser();
public GfoMsg ParseToMsg(String s) {return Bld(s);}
public GfoMsg Bld(String src) {return Bld(Bry_.new_u8(src));}
public GfoMsg Bld(byte[] src) {
Gfs_nde nde = parser.Parse(src);
return Bld_msg(src, nde);
}
GfoMsg Bld_msg(byte[] src, Gfs_nde nde) {
private GfoMsg Bld_msg(byte[] src, Gfs_nde nde) {
boolean op_is_assign = (nde.Op_tid() == Gfs_nde.Op_tid_assign);
String name = String_.new_u8(nde.Name_bry(src));
if (op_is_assign) name += Tkn_mutator;
@@ -44,6 +44,6 @@ public class Gfs_msg_bldr implements GfoMsgParser {
}
return rv;
}
public static final Gfs_msg_bldr _ = new Gfs_msg_bldr(); Gfs_msg_bldr() {}
public static final Gfs_msg_bldr Instance = new Gfs_msg_bldr(); Gfs_msg_bldr() {}
public static final String Tkn_mutator = "_";
}

View File

@@ -15,7 +15,7 @@ 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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.strings.*;
public class Gfs_msg_bldr_tst {
@Before public void init() {fxt.Clear();} Gfs_msg_bldr_fxt fxt = new Gfs_msg_bldr_fxt();
@@ -43,7 +43,7 @@ public class Gfs_msg_bldr_tst {
}
}
class Gfs_msg_bldr_fxt {
public void Clear() {} String_bldr sb = String_bldr_.new_(); Gfs_msg_bldr msg_bldr = Gfs_msg_bldr._;
public void Clear() {} String_bldr sb = String_bldr_.new_(); Gfs_msg_bldr msg_bldr = Gfs_msg_bldr.Instance;
public KeyVal kv_(String key, String val) {return KeyVal_.new_(key, val);}
public GfoMsg msg_(String key, KeyVal... args) {
GfoMsg rv = GfoMsg_.new_parse_(key);
@@ -71,6 +71,6 @@ class Gfs_msg_bldr_fxt {
if (i != 0) sb.Add_char_crlf();
sb.Add(ary[i].To_str());
}
return sb.Xto_str_and_clear();
return sb.To_str_and_clear();
}
}

View File

@@ -15,7 +15,7 @@ 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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
public class Gfs_nde {
public byte[] Name_bry(byte[] src) {return name == null ? Bry_.Mid(src, name_bgn, name_end) : name;}
public byte[] Name() {return name;} public Gfs_nde Name_(byte[] v) {name = v; return this;} private byte[] name;

View File

@@ -15,7 +15,7 @@ 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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import gplx.core.btries.*;
public class Gfs_parser {
Btrie_fast_mgr trie = Gfs_parser_.trie_();
@@ -67,26 +67,26 @@ public class Gfs_parser {
class Gfs_parser_ {
public static Btrie_fast_mgr trie_() {
Btrie_fast_mgr rv = Btrie_fast_mgr.ci_a7(); // NOTE:ci.ascii:gfs;letters/symbols only;
Gfs_lxr_identifier word_lxr = Gfs_lxr_identifier._;
Gfs_lxr_identifier word_lxr = Gfs_lxr_identifier.Instance;
trie_add_rng(rv, word_lxr, Byte_ascii.Ltr_a, Byte_ascii.Ltr_z);
trie_add_rng(rv, word_lxr, Byte_ascii.Ltr_A, Byte_ascii.Ltr_Z);
trie_add_rng(rv, word_lxr, Byte_ascii.Num_0, Byte_ascii.Num_9);
rv.Add(Byte_ascii.Underline, word_lxr);
trie_add_many(rv, Gfs_lxr_whitespace._, Byte_ascii.Space, Byte_ascii.Nl, Byte_ascii.Cr, Byte_ascii.Tab);
trie_add_many(rv, Gfs_lxr_whitespace.Instance, Byte_ascii.Space, Byte_ascii.Nl, Byte_ascii.Cr, Byte_ascii.Tab);
trie_add_quote(rv, new byte[] {Byte_ascii.Apos});
trie_add_quote(rv, new byte[] {Byte_ascii.Quote});
trie_add_quote(rv, Bry_.new_a7("<:[\"\n"), Bry_.new_a7("\n\"]:>"));
trie_add_quote(rv, Bry_.new_a7("<:['\n"), Bry_.new_a7("\n']:>"));
trie_add_comment(rv, new byte[] {Byte_ascii.Slash, Byte_ascii.Slash}, new byte[] {Byte_ascii.Nl});
trie_add_comment(rv, new byte[] {Byte_ascii.Slash, Byte_ascii.Star}, new byte[] {Byte_ascii.Star, Byte_ascii.Slash});
rv.Add(Byte_ascii.Semic, Gfs_lxr_semic._);
rv.Add(Byte_ascii.Paren_bgn, Gfs_lxr_paren_bgn._);
rv.Add(Byte_ascii.Paren_end, Gfs_lxr_paren_end._);
rv.Add(Byte_ascii.Curly_bgn, Gfs_lxr_curly_bgn._);
rv.Add(Byte_ascii.Curly_end, Gfs_lxr_curly_end._);
rv.Add(Byte_ascii.Dot, Gfs_lxr_dot._);
rv.Add(Byte_ascii.Comma, Gfs_lxr_comma._);
rv.Add(Byte_ascii.Eq, Gfs_lxr_equal._);
rv.Add(Byte_ascii.Semic, Gfs_lxr_semic.Instance);
rv.Add(Byte_ascii.Paren_bgn, Gfs_lxr_paren_bgn.Instance);
rv.Add(Byte_ascii.Paren_end, Gfs_lxr_paren_end.Instance);
rv.Add(Byte_ascii.Curly_bgn, Gfs_lxr_curly_bgn.Instance);
rv.Add(Byte_ascii.Curly_end, Gfs_lxr_curly_end.Instance);
rv.Add(Byte_ascii.Dot, Gfs_lxr_dot.Instance);
rv.Add(Byte_ascii.Comma, Gfs_lxr_comma.Instance);
rv.Add(Byte_ascii.Eq, Gfs_lxr_equal.Instance);
return rv;
}
private static void trie_add_rng(Btrie_fast_mgr trie, Gfs_lxr lxr, byte bgn, byte end) {

View File

@@ -15,7 +15,7 @@ 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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import gplx.core.btries.*;
class Gfs_parser_ctx {
public Btrie_fast_mgr Trie() {return trie;} Btrie_fast_mgr trie;
@@ -97,7 +97,7 @@ class Gfs_err_mgr {
tmp_fail_bfr.Add_byte(Byte_ascii.Eq).Add_byte(Byte_ascii.Apos);
tmp_fail_bfr.Add_str(kv.Val_to_str_or_empty()).Add_byte(Byte_ascii.Apos);
}
return tmp_fail_bfr.Xto_str_and_clear();
return tmp_fail_bfr.To_str_and_clear();
}
Bry_bfr tmp_fail_bfr = Bry_bfr.reset_(255);
KeyValList tmp_fail_args = new KeyValList();
@@ -105,12 +105,12 @@ class Gfs_err_mgr {
String Fail_excerpt_bgn(byte[] src, int src_len, int pos) {
int bgn = pos - excerpt_len; if (bgn < 0) bgn = 0;
Fail_excerpt_rng(tmp_fail_bfr, src, bgn, pos);
return tmp_fail_bfr.Xto_str_and_clear();
return tmp_fail_bfr.To_str_and_clear();
}
String Fail_excerpt_end(byte[] src, int src_len, int pos) {
int end = pos + excerpt_len; if (end > src_len) end = src_len;
Fail_excerpt_rng(tmp_fail_bfr, src, pos, end);
return tmp_fail_bfr.Xto_str_and_clear();
return tmp_fail_bfr.To_str_and_clear();
}
private static void Fail_excerpt_rng(Bry_bfr bfr, byte[] src, int bgn, int end) {
for (int i = bgn; i < end; i++) {

View File

@@ -15,7 +15,7 @@ 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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Gfs_parser_tst {
@Before public void init() {fxt.Clear();} Gfs_parser_fxt fxt = new Gfs_parser_fxt();
@@ -159,7 +159,7 @@ class Gfs_parser_fxt {
path_bfr.Clear().Add_int_variable(i);
To_str(tmp_bfr, path_bfr, src, expd[i]);
}
return tmp_bfr.Xto_str_and_clear();
return tmp_bfr.To_str_and_clear();
}
public void To_str(Bry_bfr bfr, Bry_bfr path, byte[] src, Gfs_nde nde) {
To_str_atr(bfr, path, src, Atr_name, nde.Name(), nde.Name_bgn(), nde.Name_end());

View File

@@ -15,7 +15,7 @@ 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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
public class Gfs_wtr {
public byte Quote_char() {return quote_char;} public Gfs_wtr Quote_char_(byte v) {quote_char = v; return this;} private byte quote_char = Byte_ascii.Apos;
public Bry_bfr Bfr() {return bfr;} private Bry_bfr bfr = Bry_bfr.reset_(255);

View File

@@ -77,7 +77,7 @@ public class Html_nde {
break;
}
}
return dirty ? tmp_bfr.Xto_bry_and_clear() : Bry_.Mid(src, bgn, end);
return dirty ? tmp_bfr.To_bry_and_clear() : Bry_.Mid(src, bgn, end);
}
public byte[] Data(byte[] src) {
return Bry_.Mid(src, tag_lhs_end, tag_rhs_bgn);

View File

@@ -32,7 +32,7 @@ public class Html_utl {
public static byte[] Escape_for_atr_val_as_bry(Bry_bfr bfr, byte quote_byte, byte[] bry) {
if (bry == null) return null;
boolean dirty = Escape_for_atr_val_as_bry(bfr, quote_byte, bry, 0, bry.length);
return dirty ? bfr.Xto_bry_and_clear() : bry;
return dirty ? bfr.To_bry_and_clear() : bry;
}
public static boolean Escape_for_atr_val_as_bry(Bry_bfr bfr, byte quote_byte, byte[] src, int bgn, int end) {
boolean dirty = false;
@@ -100,7 +100,7 @@ public class Html_utl {
if (write_to_bfr)
return null;
else
return dirty ? bfr.Xto_bry_and_clear() : bry;
return dirty ? bfr.To_bry_and_clear() : bry;
}
private static final Btrie_slim_mgr unescape_trie = Btrie_slim_mgr.ci_a7()
@@ -114,7 +114,7 @@ public class Html_utl {
Bry_bfr bfr = Bry_bfr.reset_(255);
byte[] bry = Bry_.new_u8(src);
Unescape(Bool_.Y, bfr, bry, 0, bry.length, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y);
return bfr.Xto_str_and_clear();
return bfr.To_str_and_clear();
}
public static byte[] Unescape(boolean write_to_bfr, Bry_bfr bfr, byte[] bry, int bgn, int end, boolean escape_lt, boolean escape_gt, boolean escape_amp, boolean escape_quote, boolean escape_apos) {
if (bry == null) return null;
@@ -156,7 +156,7 @@ public class Html_utl {
if (write_to_bfr)
return null;
else
return dirty ? bfr.Xto_bry_and_clear() : bry;
return dirty ? bfr.To_bry_and_clear() : bry;
}
public static byte[] Del_comments(Bry_bfr bfr, byte[] src) {return Del_comments(bfr, src, 0, src.length);}
public static byte[] Del_comments(Bry_bfr bfr, byte[] src, int pos, int end) {
@@ -175,6 +175,6 @@ public class Html_utl {
bfr.Add_mid(src, pos, comm_bgn); // add everything between pos and comm_bgn
pos = comm_end + Html_tag_.Comm_end_len; // reposition pos after comm_end
}
return bfr.Xto_bry_and_clear();
return bfr.To_bry_and_clear();
}
}

View File

@@ -82,9 +82,9 @@ public class Html_wtr {
bfr.Add_byte(Byte_ascii.Gt);
return this;
}
public byte[] Xto_bry_and_clear() {return bfr.Xto_bry_and_clear();}
public byte[] Xto_bry() {return bfr.Xto_bry();}
public String Xto_str() {return bfr.Xto_str();}
public byte[] To_bry_and_clear() {return bfr.To_bry_and_clear();}
public byte[] Xto_bry() {return bfr.To_bry();}
public String Xto_str() {return bfr.To_str();}
public static void Write_atr_bry(Bry_bfr bfr, byte[] key, byte[] val) {Write_atr_bry(bfr, Bool_.Y, Byte_ascii.Quote, key, val);}
public static void Write_atr_bry(Bry_bfr bfr, boolean write_space, byte atr_quote, byte[] key, byte[] val) {
if (Bry_.Len_eq_0(val)) return; // don't write empty

View File

@@ -27,7 +27,7 @@ public class Url_encoder implements Url_encoder_interface {
Url_encoder_itm_hex hex = new Url_encoder_itm_hex(primary_encode_marker);
for (int i = 0; i < 256; i++) {
encode_ary[i] = hex; // default encode to hex
decode_ary[i] = Url_encoder_itm_same._; // default decode to same; needed for files; EX: A!%21.png -> A!!.png;
decode_ary[i] = Url_encoder_itm_same.Instance; // default decode to same; needed for files; EX: A!%21.png -> A!!.png;
}
decode_ary[primary_encode_marker] = hex;
}
@@ -49,15 +49,15 @@ public class Url_encoder implements Url_encoder_interface {
}
public void Itms_raw_same_rng(int bgn, int end) {
for (int i = bgn; i <= end; i++) {
encode_ary[i] = Url_encoder_itm_same._;
decode_ary[i] = Url_encoder_itm_same._;
encode_ary[i] = Url_encoder_itm_same.Instance;
decode_ary[i] = Url_encoder_itm_same.Instance;
}
}
public Url_encoder Itms_raw_same_many(int... ary) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
encode_ary[ary[i]] = Url_encoder_itm_same._;
decode_ary[ary[i]] = Url_encoder_itm_same._;
encode_ary[ary[i]] = Url_encoder_itm_same.Instance;
decode_ary[ary[i]] = Url_encoder_itm_same.Instance;
}
return this;
}
@@ -75,20 +75,20 @@ public class Url_encoder implements Url_encoder_interface {
synchronized (thread_lock) {
tmp_bfr.Add(Io_url.Http_file_bry);
Encode(tmp_bfr, url.RawBry());
return tmp_bfr.Xto_bry_and_clear();
return tmp_bfr.To_bry_and_clear();
}
}
public String Encode_str(String str) {
synchronized (thread_lock) {
byte[] bry = Bry_.new_u8(str); Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.Xto_str_and_clear();
byte[] bry = Bry_.new_u8(str); Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.To_str_and_clear();
}
}
public byte[] Encode_bry(String str) {
synchronized (thread_lock) {
byte[] bry = Bry_.new_u8(str); Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.Xto_bry_and_clear();
byte[] bry = Bry_.new_u8(str); Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.To_bry_and_clear();
}
}
public byte[] Encode(byte[] bry) {Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.Xto_bry_and_clear();}
public byte[] Encode(byte[] bry) {Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.To_bry_and_clear();}
public Bry_bfr Encode(Bry_bfr bfr, byte[] bry) {Encode(bfr, bry, 0, bry.length); return bfr;}
public void Encode(Bry_bfr bfr, byte[] bry, int bgn, int end) {
synchronized (thread_lock) {
@@ -106,15 +106,15 @@ public class Url_encoder implements Url_encoder_interface {
}
public String Decode_str(String str) {
synchronized (thread_lock) {
byte[] bry = Bry_.new_u8(str); Decode(bry, 0, bry.length, tmp_bfr, true); return tmp_bfr.Xto_str_and_clear();
byte[] bry = Bry_.new_u8(str); Decode(bry, 0, bry.length, tmp_bfr, true); return tmp_bfr.To_str_and_clear();
}
}
public byte[] Decode(byte[] bry) {return Decode(tmp_bfr, bry, 0, bry.length);}
public byte[] Decode(byte[] bry, int bgn, int end) {return Decode(tmp_bfr, bry, bgn, end);}
public byte[] Decode(Bry_bfr bfr, byte[] bry, int bgn, int end) {Decode(bry, bgn, end, bfr , false); return bfr.Xto_bry_and_clear();}
public byte[] Decode(Bry_bfr bfr, byte[] bry, int bgn, int end) {Decode(bry, bgn, end, bfr , false); return bfr.To_bry_and_clear();}
public byte[] Decode_lax(byte[] bry) {
synchronized (thread_lock) {
Decode(bry, 0, bry.length, tmp_bfr, false); return tmp_bfr.Xto_bry_and_clear();
Decode(bry, 0, bry.length, tmp_bfr, false); return tmp_bfr.To_bry_and_clear();
}
}
public void Decode(byte[] bry, int bgn, int end, Bry_bfr bfr, boolean fail_when_invalid) {
@@ -145,7 +145,7 @@ public class Url_encoder implements Url_encoder_interface {
mediawiki_base(rv, true);
rv.Itms_decode_marker(Byte_ascii.Dot);
rv.Itms_raw_diff(Byte_ascii.Space, Byte_ascii.Underline);
rv.Itms_raw_html_ent(Byte_ascii.Amp, Xop_amp_trie._);
rv.Itms_raw_html_ent(Byte_ascii.Amp, Xop_amp_trie.Instance);
return rv;
}
public static Url_encoder new_http_url_() {
@@ -230,7 +230,7 @@ interface Url_encoder_itm {
class Url_encoder_itm_same implements Url_encoder_itm {
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {bfr.Add_byte(b); return 0;}
public int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid) {bfr.Add_byte(b); return 0;}
public static final Url_encoder_itm _ = new Url_encoder_itm_same();
public static final Url_encoder_itm Instance = new Url_encoder_itm_same();
}
class Url_encoder_itm_diff implements Url_encoder_itm {
public Url_encoder_itm_diff(byte orig, byte repl) {this.orig = orig; this.repl = repl;} private byte orig, repl;
@@ -254,14 +254,14 @@ class Url_encoder_itm_hex implements Url_encoder_itm {
return 0;
}
}
int hex_val = Int_.Xto_int_hex(src[idx + 1]);
int hex_val = Int_.To_int_hex(src[idx + 1]);
if (hex_val == -1) { // invalid hex byte; EX: %GC; DATE:2014-04-10
bfr.Add_byte(b);
return 0;
}
int v_0 = hex_val * 16;
if (v_0 != -1) {
int v_1 = Int_.Xto_int_hex(src[idx + 2]);
int v_1 = Int_.To_int_hex(src[idx + 2]);
if (v_1 != -1) {
bfr.Add_byte((byte)(v_0 + v_1));
return 2;

View File

@@ -29,7 +29,7 @@ public class Url_encoder_tst {
byte[] raw = Bry_.new_a7("0%.jpg");
Bry_bfr tmp_bfr = Bry_bfr.new_();
fxt.Encoder_id().Encoder().Decode(raw, 0, raw.length, tmp_bfr, false);
Tfds.Eq("0%.jpg", tmp_bfr.Xto_str_and_clear());
Tfds.Eq("0%.jpg", tmp_bfr.To_str_and_clear());
}
@Test public void Id_nbsp() {fxt.Encoder_id().Test_encode("a&nbsp;b", "a.C2.A0b");} // NOTE: not just .A0 (160) but utf8-encoded .C2.A0
@Test public void Url_syms() {fxt.Encoder_url().Test_encode_decode("!?^~", "%21%3F%5E%7E");}

View File

@@ -1,24 +0,0 @@
/*
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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
class Gfo_html_node {
public Gfo_html_node(byte[] src, int bgn, int end) {this.src = src; this.bgn = bgn; this.end = end;}
public byte[] Src() {return src;} private final byte[] src;
public int Bgn() {return bgn;} private final int bgn;
public int End() {return end;} private final int end;
}

View File

@@ -1,69 +0,0 @@
/*
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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import gplx.core.btries.*; import gplx.core.primitives.*;
import gplx.xowa.*;
import gplx.xowa.parsers.xndes.*;
class Gfo_html_parser {
private final Gfo_msg_log msg_log = Gfo_msg_log.Test();
private final Xop_xatr_parser xatr_parser = new Xop_xatr_parser();
public void Parse(Gfo_html_wkr handler, byte[] src, int bgn, int end) {
// int src_len = src.length;
// int prv_pos = 0;
// int css_find_bgn_len = Css_find_bgn.length;
// byte[] protocol_prefix_bry = Bry_.new_u8(protocol_prefix);
// while (true) {
// int url_bgn = Bry_find_.Find_fwd(src, Css_find_bgn, prv_pos); if (url_bgn == Bry_.NotFound) break; // nothing left; stop
// url_bgn += css_find_bgn_len;
// int url_end = Bry_find_.Find_fwd(src, Byte_ascii.Quote, url_bgn, src_len); if (url_end == Bry_.NotFound) {usr_dlg.Warn_many("", "main_page.css_parse", "could not find css; pos='~{0}' text='~{1}'", url_bgn, String_.new_u8__by_len(src, url_bgn, url_bgn + 32)); break;}
// byte[] css_url_bry = Bry_.Mid(src, url_bgn, url_end);
// css_url_bry = Bry_.Replace(css_url_bry, Css_amp_find, Css_amp_repl); // &amp; -> &
// css_url_bry = url_encoder.Decode(css_url_bry); // %2C -> %7C -> |
// css_url_bry = Bry_.Add(protocol_prefix_bry, css_url_bry);
// rv.Add(String_.new_u8(css_url_bry));
// prv_pos = url_end;
// }
// return rv.XtoStrAry();
int src_len = src.length; int pos = 0;
while (pos < src_len) {
byte b = src[pos];
switch (b) {
case Byte_ascii.Angle_bgn:
pos = Parse_node(handler, src, end, pos, pos + 1);
break;
default:
++pos;
break;
}
}
}
private int Parse_node(Gfo_html_wkr handler, byte[] src, int end, int tkn_bgn, int tkn_end) {
int name_bgn = tkn_end;
int name_end = Bry_find_.Find_fwd_until_ws(src, name_bgn, end);
if (name_end == Bry_find_.Not_found) return end; // EOS; EX: "<abcEOS"
if (name_bgn == name_end) return tkn_end; // ws; EX: "< "
Object o = handler.Get_or_null(src, name_bgn, name_end);
if (o == null) return name_end; // unknown name: EX: "<unknown >"
int node_end = Bry_find_.Find_fwd(src, Byte_ascii.Angle_end, name_end, end);
if (node_end == Bry_find_.Not_found) return end; // EOS; EX: "<name lots_of_text_but_no_gt EOS"
Xop_xatr_itm[] xatr_ary = xatr_parser.Parse(msg_log, src, name_end, node_end);
Gfo_html_tkn tkn = (Gfo_html_tkn)o;
tkn.Process(src, Xop_xatr_hash.new_ary(src, xatr_ary));
return node_end;
}
}

View File

@@ -1,34 +0,0 @@
/*
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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import gplx.xowa.*;
import gplx.xowa.parsers.xndes.*;
interface Gfo_html_tkn {
int Tid();
byte[] Key();
void Process(byte[] src, Xop_xatr_hash hash);
}
class Gfo_html_tkn_ {
public static final int Tid_link = 1;
public static final byte[] Key_link = Bry_.new_a7("link");
}
class Gfo_html_tkn__link implements Gfo_html_tkn {
public int Tid() {return Gfo_html_tkn_.Tid_link;}
public byte[] Key() {return Gfo_html_tkn_.Key_link;}
@gplx.Virtual public void Process(byte[] src, Xop_xatr_hash hash) {}
}

View File

@@ -50,7 +50,7 @@ public class Json_doc {
Json_itm rv = Find_nde(root_nde, tmp_qry_bry, 0, 0); if (rv == null) return null;
return (Json_grp)rv;
}
public Json_grp Get_grp(byte[][] qry_bry) {
public Json_grp Get_grp_many(byte[]... qry_bry) {
Json_itm rv = Find_nde(root_nde, qry_bry, qry_bry.length - 1, 0); if (rv == null) return null;
return (Json_grp)rv;
}

Some files were not shown because too many files have changed in this diff Show More