diff --git a/java/CheckArg.java b/java/CheckArg.java index debfe93..a981098 100644 --- a/java/CheckArg.java +++ b/java/CheckArg.java @@ -111,7 +111,7 @@ public String value(final String arg){ } public boolean isset(final String arg){ - return _valid_args.get(arg) != null; + return _valid_args_vals.get(arg) != null; } public static String str_err(final Error errno){ @@ -169,8 +169,9 @@ private String str_repeat(char c, int times){ private int arg(final String arg){ if(! _next_is_val_of.isEmpty() ){ _valid_args_vals.put(_next_is_val_of, arg); + int ret = _call_cb(_next_is_val_of); _next_is_val_of = ""; - return Error.CA_ALLOK.ordinal(); + return ret; } if( arg.charAt(0) == '-' ) { // yay, some arg @@ -215,16 +216,7 @@ private int arg_long(final String arg){ if( ! hasval.booleanValue() || ! val.isEmpty()){ // if arg has no val, or val is found already, call callback now, if there's one - Callable cb = _valid_args_cb.get(real_arg); - if( cb != null ){ - try{ - cb.call(); - }catch(Exception e){ - ca_error(Error.CA_CALLBACK, ": "+e+"!"); - e.printStackTrace(); - return Error.CA_CALLBACK.ordinal(); - } - } + return _call_cb(real_arg); } return Error.CA_ALLOK.ordinal(); @@ -248,6 +240,9 @@ private int arg_short(final String arg){ return Error.CA_ALLOK.ordinal(); } else { _valid_args_vals.put(larg, "x"); + int ret = _call_cb(larg); + if( ret != Error.CA_ALLOK.ordinal() ) + return ret; } } else { ca_error(Error.CA_INVARG, ": -"+arg.charAt(i)+"!"); @@ -257,6 +252,20 @@ private int arg_short(final String arg){ return Error.CA_ALLOK.ordinal(); } + private int _call_cb(final String larg){ + Callable cb = _valid_args_cb.get(larg); + if( cb != null ){ + try{ + cb.call(); + }catch(Exception e){ + ca_error(Error.CA_CALLBACK, ": "+e+"!"); + e.printStackTrace(); + return Error.CA_CALLBACK.ordinal(); + } + } + return Error.CA_ALLOK.ordinal(); + } + private String long2short(final String larg){ for (Map.Entry e : _short2long.entrySet() ) { if( e.getValue().equals(larg) ) @@ -265,17 +274,17 @@ private String long2short(final String larg){ return null; } - String _appname, _descr, _appendix, _usage_line, _posarg_help_descr, _posarg_help_usage; - boolean _autohelp_on; - String _next_is_val_of; - - Map _valid_args; - Map _valid_args_vals; - Map> _valid_args_cb; - Map _autohelp; - Map _short2long; - List _pos_args; - String _args[]; + private String _appname, _descr, _appendix, _usage_line, _posarg_help_descr, _posarg_help_usage; + private boolean _autohelp_on; + private String _next_is_val_of; + + private Map _valid_args; + private Map _valid_args_vals; + private Map> _valid_args_cb; + private Map _autohelp; + private Map _short2long; + private List _pos_args; + private String _args[]; private static final Map _errors; static {