summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2020-08-25 17:04:23 +0200
committernsensfel <SpamShield0@noot-noot.org>2020-08-25 17:04:23 +0200
commite620e366e5ffb90aa0ae321872e970c7de30b236 (patch)
tree22e984093f76850ad70db9ec94fceb8fca43218a /src
parent3a910e2df9bb71e0a1601e3be9367278bf6f897f (diff)
Adds invokation parameters.
Diffstat (limited to 'src')
-rw-r--r--src/core/src/tonkadur/Main.java12
-rw-r--r--src/core/src/tonkadur/RuntimeParameters.java140
-rw-r--r--src/core/src/tonkadur/TonkadurPlugin.java4
-rw-r--r--src/core/src/tonkadur/error/ErrorCategory.java20
-rw-r--r--src/core/src/tonkadur/fate/v1/Base.java11
-rw-r--r--src/core/src/tonkadur/fate/v1/error/ErrorCategory.java7
-rw-r--r--src/core/src/tonkadur/wyrd/v1/Base.java9
-rw-r--r--src/json-export/Makefile2
-rw-r--r--src/json-export/src/tonkadur/plugin/JSONExport.java44
9 files changed, 245 insertions, 4 deletions
diff --git a/src/core/src/tonkadur/Main.java b/src/core/src/tonkadur/Main.java
index 62879d2..4362d31 100644
--- a/src/core/src/tonkadur/Main.java
+++ b/src/core/src/tonkadur/Main.java
@@ -21,15 +21,25 @@ public class Main
final tonkadur.wyrd.v1.lang.World wyrd_world;
final Context context;
+ tonkadur.fate.v1.Base.initialize();
+ tonkadur.wyrd.v1.Base.initialize();
+
plugins = TonkadurPlugin.get_plugins();
+ if (!RuntimeParameters.parse_options(args))
+ {
+ RuntimeParameters.print_usage(plugins);
+
+ return;
+ }
+
for (final TonkadurPlugin tp: plugins)
{
tp.initialize(args);
}
fate_world = new tonkadur.fate.v1.lang.World();
- context = Context.build(args[0]);
+ context = Context.build(RuntimeParameters.get_input_file());
for (final TonkadurPlugin tp: plugins)
{
diff --git a/src/core/src/tonkadur/RuntimeParameters.java b/src/core/src/tonkadur/RuntimeParameters.java
index 2c434d2..bf72b04 100644
--- a/src/core/src/tonkadur/RuntimeParameters.java
+++ b/src/core/src/tonkadur/RuntimeParameters.java
@@ -1,8 +1,10 @@
package tonkadur;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import tonkadur.error.ErrorCategory;
@@ -13,6 +15,7 @@ public class RuntimeParameters
protected static final Collection<ErrorCategory> disabled_errors;
protected static final Collection<ErrorCategory> tolerated_errors;
protected static boolean consider_warnings_as_errors;
+ protected static String target_file;
static
{
@@ -42,8 +45,145 @@ public class RuntimeParameters
return include_directories;
}
+ public static String get_input_file ()
+ {
+ return target_file;
+ }
+
public static void add_include_directory (final String name)
{
include_directories.add(name);
}
+
+ public static void print_usage
+ (
+ final Collection<TonkadurPlugin> plugins
+ )
+ {
+ System.out.println("Usage: tonkadur [<options>] <file>");
+ System.out.println("Options:");
+ System.out.println
+ (
+ " -i|--include <directory>\tAdds <directory> to the search path."
+ );
+ System.out.println
+ (
+ " -s|--strict\t\t\tWarnings are errors."
+ );
+ System.out.println
+ (
+ " -te|--tolerate-error <name>\tRelates <name> to a simple warning."
+ );
+ System.out.println
+ (
+ " -se|--silence-error <name>\tErrors of type <name> are ignored."
+ );
+
+ for (final TonkadurPlugin plugin: plugins)
+ {
+ plugin.print_options();
+ }
+
+ System.out.println("");
+ System.out.println("Home page: https://tonkadur.of.tacticians.online");
+ }
+
+ public static boolean parse_options (final String[] options)
+ {
+ final Iterator<String> options_it;
+
+ if (options.length == 0)
+ {
+ return false;
+ }
+
+ target_file = options[options.length - 1];
+
+ options_it = Arrays.stream(options).iterator();
+
+ while (options_it.hasNext())
+ {
+ final String option = options_it.next();
+
+ if (option.equals("-i") || option.equals("--include"))
+ {
+ if (!options_it.hasNext())
+ {
+ return false;
+ }
+
+ include_directories.add(options_it.next());
+ }
+ else if (option.equals("-s") || option.equals("--strict"))
+ {
+ consider_warnings_as_errors = true;
+ }
+ else if (option.equals("-te") || option.equals("--tolerate-error"))
+ {
+ final ErrorCategory er;
+ final String er_name;
+
+ if (!options_it.hasNext())
+ {
+ return false;
+ }
+
+ er_name = options_it.next();
+
+ er = ErrorCategory.get_error_category(er_name);
+
+ if (er == null)
+ {
+ System.err.println("Unknown error type \"" + er_name + "\".");
+ System.err.println("Available error types:");
+
+
+ for (final String er_type: ErrorCategory.get_error_categories())
+ {
+ System.err.println("- " + er_type);
+ }
+
+ System.err.println("");
+
+ return false;
+ }
+
+ tolerated_errors.add(er);
+ }
+ else if (option.equals("-se") || option.equals("--silence-error"))
+ {
+ final ErrorCategory er;
+ final String er_name;
+
+ if (!options_it.hasNext())
+ {
+ return false;
+ }
+
+ er_name = options_it.next();
+
+ er = ErrorCategory.get_error_category(er_name);
+
+ if (er == null)
+ {
+ System.err.println("Unknown error type \"" + er_name + "\".");
+ System.err.println("Available error types:");
+
+
+ for (final String er_type: ErrorCategory.get_error_categories())
+ {
+ System.err.println("- " + er_type);
+ }
+
+ System.err.println("");
+
+ return false;
+ }
+
+ disabled_errors.add(er);
+ }
+ }
+
+ return true;
+ }
}
diff --git a/src/core/src/tonkadur/TonkadurPlugin.java b/src/core/src/tonkadur/TonkadurPlugin.java
index 2df21d0..42b3b90 100644
--- a/src/core/src/tonkadur/TonkadurPlugin.java
+++ b/src/core/src/tonkadur/TonkadurPlugin.java
@@ -126,4 +126,8 @@ public abstract class TonkadurPlugin
{
}
+
+ public void print_options ()
+ {
+ }
}
diff --git a/src/core/src/tonkadur/error/ErrorCategory.java b/src/core/src/tonkadur/error/ErrorCategory.java
index 122cff3..9c9f552 100644
--- a/src/core/src/tonkadur/error/ErrorCategory.java
+++ b/src/core/src/tonkadur/error/ErrorCategory.java
@@ -1,23 +1,43 @@
package tonkadur.error;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
public class ErrorCategory
{
+ protected static final Map<String, ErrorCategory> by_name;
+
public static final ErrorCategory INVALID_INPUT;
public static final ErrorCategory PROGRAMMING_ERROR;
public static final ErrorCategory FILE_ACCESS;
static
{
+ by_name = new HashMap<String, ErrorCategory>();
+
INVALID_INPUT = new ErrorCategory("Invalid Input");
PROGRAMMING_ERROR = new ErrorCategory("Programming Error");
FILE_ACCESS = new ErrorCategory("File Access");
}
+ public static ErrorCategory get_error_category (final String name)
+ {
+ return by_name.get(name);
+ }
+
+ public static Collection<String> get_error_categories ()
+ {
+ return by_name.keySet();
+ }
+
protected final String name;
protected ErrorCategory (final String name)
{
this.name = name;
+
+ by_name.put(name, this);
}
@Override
diff --git a/src/core/src/tonkadur/fate/v1/Base.java b/src/core/src/tonkadur/fate/v1/Base.java
new file mode 100644
index 0000000..4dfa199
--- /dev/null
+++ b/src/core/src/tonkadur/fate/v1/Base.java
@@ -0,0 +1,11 @@
+package tonkadur.fate.v1;
+
+import tonkadur.fate.v1.error.ErrorCategory;
+
+public class Base
+{
+ public static void initialize ()
+ {
+ ErrorCategory.initialize();
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java b/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java
index 35f4b94..20fac02 100644
--- a/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java
+++ b/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java
@@ -1,6 +1,6 @@
package tonkadur.fate.v1.error;
-class ErrorCategory extends tonkadur.error.ErrorCategory
+public class ErrorCategory extends tonkadur.error.ErrorCategory
{
public static final ErrorCategory CONFLICTING;
public static final ErrorCategory DUPLICATE_DECLARATION;
@@ -21,6 +21,11 @@ class ErrorCategory extends tonkadur.error.ErrorCategory
UNKNOWN = new ErrorCategory("unknown");
}
+ public static void initialize ()
+ {
+ /* Ensures class is loaded. */
+ }
+
private ErrorCategory (final String name)
{
super(name);
diff --git a/src/core/src/tonkadur/wyrd/v1/Base.java b/src/core/src/tonkadur/wyrd/v1/Base.java
new file mode 100644
index 0000000..2d3538b
--- /dev/null
+++ b/src/core/src/tonkadur/wyrd/v1/Base.java
@@ -0,0 +1,9 @@
+package tonkadur.wyrd.v1;
+
+public class Base
+{
+ public static void initialize ()
+ {
+ /* Nothing to do. */
+ }
+}
diff --git a/src/json-export/Makefile b/src/json-export/Makefile
index afe05e5..8654cc8 100644
--- a/src/json-export/Makefile
+++ b/src/json-export/Makefile
@@ -75,7 +75,7 @@ clean:
rm -rf $(LIB_DIR)/$(STANDALONE)
# Pattern rules can be used to generate multiple target in a single action.
-$(CLASSES): $(BIN_DIR)/%.class: $(SRC_DIR)/%.java $(BIN_DIR)
+$(CLASSES): $(BIN_DIR)/%.class: $(SRC_DIR)/%.java $(BIN_DIR) $(JSON_SIMPLE_JAR) $(TONKADUR_CORE_JAR)
$(JAVAC) -cp $(CLASSPATH) -d $(BIN_DIR) $<
%.jar:
diff --git a/src/json-export/src/tonkadur/plugin/JSONExport.java b/src/json-export/src/tonkadur/plugin/JSONExport.java
index 6d746f9..1e5a070 100644
--- a/src/json-export/src/tonkadur/plugin/JSONExport.java
+++ b/src/json-export/src/tonkadur/plugin/JSONExport.java
@@ -1,6 +1,10 @@
package tonkadur.plugin;
+import java.util.Arrays;
+import java.util.Iterator;
+
import tonkadur.TonkadurPlugin;
+import tonkadur.RuntimeParameters;
import tonkadur.wyrd.v1.lang.World;
@@ -15,7 +19,39 @@ public class JSONExport extends TonkadurPlugin
public void initialize (final String[] args)
throws Throwable
{
- output_file = (args[0] + ".json");
+ final Iterator<String> args_it;
+
+ args_it = Arrays.stream(args).iterator();
+
+ output_file = null;
+
+ while (args_it.hasNext())
+ {
+ final String option = args_it.next();
+
+ if (option.equals("-o") || option.equals("--output"))
+ {
+ if (!args_it.hasNext())
+ {
+ throw
+ new Exception
+ (
+ "Invalide usage. No arguments to "
+ + option
+ + " parameter"
+ );
+ }
+
+ output_file = args_it.next();
+
+ break;
+ }
+ }
+
+ if (output_file == null)
+ {
+ output_file = (RuntimeParameters.get_input_file() + ".json");
+ }
}
@Override
@@ -31,4 +67,10 @@ public class JSONExport extends TonkadurPlugin
{
Translator.toJSON(wyrd_world, output_file);
}
+
+ @Override
+ public void print_options ()
+ {
+ System.out.println(" -o|--output <file>\t\tOutput to <file>.");
+ }
}