+ // Third param "true" uses Opt.PRIVATE args --setargile=argfile and
+ // --unsetargfile
+ return new ArgParser(argsList, initsubstitutions, true);
+ }
+
+ protected static List<String> readArgFile(File argFile)
+ {
+ List<String> args = new ArrayList<>();
+ if (argFile != null && argFile.exists())
+ {
+ try
+ {
+ for (String line : Files.readAllLines(Paths.get(argFile.getPath())))
+ {
+ if (line != null && line.length() > 0
+ && line.charAt(0) != ARGFILECOMMENT)
+ args.add(line);
+ }
+ } catch (IOException e)
+ {
+ String message = Arg.ARGFILE.argString() + "=\"" + argFile.getPath()
+ + "\": File could not be read.";
+ Console.debug(message, e);
+ Jalview.exit(message, 3);
+ }
+ }
+ return args;
+ }
+
+ public static enum Position
+ {
+ FIRST, BEFORE, AFTER
+ }
+
+ public static String getValueFromSubValOrArg(ArgValuesMap avm, Arg a,
+ SubVals sv)
+ {
+ return getFromSubValArgOrPref(avm, a, sv, null, null, null);
+ }
+
+ public static String getFromSubValArgOrPref(ArgValuesMap avm, Arg a,
+ SubVals sv, String key, String pref, String def)
+ {
+ return getFromSubValArgOrPref(avm, a, Position.FIRST, null, sv, key,
+ pref, def);
+ }
+
+ public static String getFromSubValArgOrPref(ArgValuesMap avm, Arg a,
+ Position pos, ArgValue av, SubVals sv, String key, String pref,
+ String def)
+ {
+ if (key == null)
+ key = a.getName();
+ if (sv != null && sv.has(key) && sv.get(key) != null)
+ return sv.get(key);
+ if (avm != null && avm.containsArg(a))
+ {
+ String val = null;
+ if (pos == Position.FIRST && avm.getValue(a) != null)
+ return avm.getValue(a);
+ else if (pos == Position.BEFORE
+ && avm.getClosestPreviousArgValueOfArg(av, a) != null)
+ return avm.getClosestPreviousArgValueOfArg(av, a).getValue();
+ else if (pos == Position.AFTER
+ && avm.getClosestNextArgValueOfArg(av, a) != null)
+ return avm.getClosestNextArgValueOfArg(av, a).getValue();
+ }
+ return pref != null ? Cache.getDefault(pref, def) : def;
+ }
+
+ public static boolean getBoolFromSubValOrArg(ArgValuesMap avm, Arg a,
+ SubVals sv)
+ {
+ return getFromSubValArgOrPref(avm, a, sv, null, null, false);
+ }
+
+ public static boolean getFromSubValArgOrPref(ArgValuesMap avm, Arg a,
+ SubVals sv, String key, String pref, boolean def)
+ {
+ if (key == null)
+ key = a.getName();
+ if (sv != null && sv.has(key) && sv.get(key) != null)
+ return sv.get(key).toLowerCase(Locale.ROOT).equals("true");
+ if (avm != null && avm.containsArg(a))
+ return avm.getBoolean(a);
+ return pref != null ? Cache.getDefault(pref, def) : def;
+ }
+
+ // the following methods look for the "*" linkedId and add the argvalue to all
+ // linkedId ArgValues if it does
+ private void addValue(String linkedId, ArgValues avs, SubVals sv,
+ String v, int argIndex, boolean doSubs)
+ {
+ Arg a = avs.arg();
+ if (MATCHALLLINKEDIDS.equals(linkedId) && a.hasOption(Opt.ALLOWALL))
+ {
+ for (String id : getLinkedIds())
+ {
+ if (id == null || MATCHALLLINKEDIDS.equals(id))
+ continue;
+ ArgValuesMap avm = linkedArgs.get(id);
+ if (a.hasOption(Opt.REQUIREINPUT)
+ && !avm.hasArgWithOption(Opt.INPUT))
+ continue;
+ ArgValues tavs = avm.getOrCreateArgValues(a);
+ String val = v;
+ if (doSubs)
+ {
+ val = makeSubstitutions(v, id);
+ sv = new SubVals(sv, val);
+ }
+ tavs.addValue(sv, val, argIndex);
+ finaliseStoringArgValue(id, tavs);
+ }
+ }
+ else
+ {
+ String val = v;
+ if (doSubs)
+ {
+ val = makeSubstitutions(v, linkedId);
+ sv = new SubVals(sv, val);
+ }
+ avs.addValue(sv, val, argIndex);
+ finaliseStoringArgValue(linkedId, avs);
+ }
+ }
+
+ private void addValue(String linkedId, ArgValues avs, String v,
+ int argIndex, boolean doSubs)
+ {
+ Arg a = avs.arg();
+ if (MATCHALLLINKEDIDS.equals(linkedId) && a.hasOption(Opt.ALLOWALL))
+ {
+ for (String id : getLinkedIds())
+ {
+ if (id == null || MATCHALLLINKEDIDS.equals(id))
+ continue;
+ ArgValuesMap avm = linkedArgs.get(id);
+ // don't set an output if there isn't an input
+ if (a.hasOption(Opt.REQUIREINPUT)
+ && !avm.hasArgWithOption(Opt.INPUT))
+ continue;
+ ArgValues tavs = avm.getOrCreateArgValues(a);
+ String val = doSubs ? makeSubstitutions(v, id) : v;
+ tavs.addValue(val, argIndex);
+ finaliseStoringArgValue(id, tavs);
+ }
+ }
+ else
+ {
+ String val = doSubs ? makeSubstitutions(v, linkedId) : v;
+ avs.addValue(val, argIndex);
+ finaliseStoringArgValue(linkedId, avs);
+ }
+ }
+
+ private void setBoolean(String linkedId, ArgValues avs, boolean b,
+ int argIndex)
+ {
+ Arg a = avs.arg();
+ if (MATCHALLLINKEDIDS.equals(linkedId) && a.hasOption(Opt.ALLOWALL))
+ {
+ for (String id : getLinkedIds())
+ {
+ if (id == null || MATCHALLLINKEDIDS.equals(id))
+ continue;
+ ArgValuesMap avm = linkedArgs.get(id);
+ if (a.hasOption(Opt.REQUIREINPUT)
+ && !avm.hasArgWithOption(Opt.INPUT))
+ continue;
+ ArgValues tavs = avm.getOrCreateArgValues(a);
+ tavs.setBoolean(b, argIndex);
+ finaliseStoringArgValue(id, tavs);
+ }
+ }
+ else
+ {
+ avs.setBoolean(b, argIndex);
+ finaliseStoringArgValue(linkedId, avs);
+ }
+ }
+
+ private void setNegated(String linkedId, ArgValues avs, boolean b)
+ {
+ Arg a = avs.arg();
+ if (MATCHALLLINKEDIDS.equals(linkedId) && a.hasOption(Opt.ALLOWALL))
+ {
+ for (String id : getLinkedIds())
+ {
+ if (id == null || MATCHALLLINKEDIDS.equals(id))
+ continue;
+ ArgValuesMap avm = linkedArgs.get(id);
+ if (a.hasOption(Opt.REQUIREINPUT)
+ && !avm.hasArgWithOption(Opt.INPUT))
+ continue;
+ ArgValues tavs = avm.getOrCreateArgValues(a);
+ tavs.setNegated(b);
+ }
+ }
+ else
+ {
+ avs.setNegated(b);
+ }
+ }
+
+ private void incrementCount(String linkedId, ArgValues avs)
+ {
+ Arg a = avs.arg();
+ if (MATCHALLLINKEDIDS.equals(linkedId) && a.hasOption(Opt.ALLOWALL))
+ {
+ for (String id : getLinkedIds())
+ {
+ if (id == null || MATCHALLLINKEDIDS.equals(id))
+ continue;
+ ArgValuesMap avm = linkedArgs.get(id);
+ if (a.hasOption(Opt.REQUIREINPUT)
+ && !avm.hasArgWithOption(Opt.INPUT))
+ continue;
+ ArgValues tavs = avm.getOrCreateArgValues(a);
+ tavs.incrementCount();
+ }
+ }
+ else
+ {
+ avs.incrementCount();
+ }