From 7f9db2e32838cac315965d986518fc61cf44567e Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Thu, 24 May 2018 21:35:49 +0200 Subject: Let's have it just load everything, to start with. --- src/hastabel2idp/Main.java | 87 +++++++++++++++++ src/hastabel2idp/Parameters.java | 196 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 283 insertions(+) create mode 100644 src/hastabel2idp/Main.java create mode 100644 src/hastabel2idp/Parameters.java (limited to 'src') diff --git a/src/hastabel2idp/Main.java b/src/hastabel2idp/Main.java new file mode 100644 index 0000000..5013c0c --- /dev/null +++ b/src/hastabel2idp/Main.java @@ -0,0 +1,87 @@ +package hastabel2idp; + +import hastabel.World; + +import java.io.IOException; + +public class Main +{ + public static void main (String... args) + { + final Parameters params; + final World world; + + params = new Parameters(args); + + if (!params.are_valid()) + { + return; + } + + world = new World(); + + for (final String level_file: params.get_level_files()) + { + load_file(world, level_file); + + if (!world.is_valid()) + { + return; + } + } + + for (final String model_file: params.get_model_files()) + { + load_file(world, model_file); + + if (!world.is_valid()) + { + return; + } + } + + world.ensure_first_order(); + + if (!world.is_valid()) + { + return; + } + + try + { + world.load_property(params.get_property_file()); + } + catch (final IOException ioe) + { + System.err.println + ( + "[E] IOException when loading \"" + + params.get_property_file() + + "\":\n" + + ioe.getMessage() + ); + + world.invalidate(); + } + } + + private static void load_file (final World world, final String filename) + { + try + { + world.load(filename); + } + catch (final IOException ioe) + { + System.err.println + ( + "[E] IOException when loading \"" + + filename + + "\":\n" + + ioe.getMessage() + ); + + world.invalidate(); + } + } +} diff --git a/src/hastabel2idp/Parameters.java b/src/hastabel2idp/Parameters.java new file mode 100644 index 0000000..a46e820 --- /dev/null +++ b/src/hastabel2idp/Parameters.java @@ -0,0 +1,196 @@ +package hastabel2idp; + +import java.util.List; +import java.util.ArrayList; + +public class Parameters +{ + private final List level_files; + private final List model_files; + private final String property_file; + private final String output_file; + private final boolean be_verbose; + + private final boolean are_valid; + + public static void print_usage () + { + System.out.println + ( + "HaStABeL to IDP\n" + + "USAGE:\n" + + "\thastabel2idp.sh +\n" + + "PARAMETERS:\n" + + "\t- \tFile to write the solutions in.\n" + + "\t- \tList of files to be loaded.\n" + + "OPTIONS:\n" + + "\t- -v|--verbose\tPrint informative messages to STDOUT.\n" + + "NOTES:\n" + + "\t- Exactly one property file must be in .\n" + + "\t- Property files have a \".pro\" extension.\n" + + "\t- Model files have a \".mod\" extension.\n" + + "\t- Level files have a \".lvl\" extension.\n" + + "\t- The files may be given in any order." + ); + } + + public Parameters (final String... args) + { + boolean has_pro_file, has_error, should_be_verbose; + String prop_file; + + level_files = new ArrayList(); + model_files = new ArrayList(); + + should_be_verbose = false; + + if (args.length < 2) + { + print_usage(); + + property_file = new String(); + output_file = new String(); + + are_valid = false; + be_verbose = false; + + return; + } + + has_pro_file = false; + has_error = false; + + output_file = args[0]; + + if + ( + (output_file.equals("-v") || output_file.equals("--verbose")) + /* || ... */ + ) + { + print_usage(); + + System.err.println + ( + "[F] An option was found in lieu of the output file." + ); + + System.exit(-1); + } + + if + ( + output_file.endsWith(".lvl") + || output_file.endsWith(".mod") + || output_file.endsWith(".pro") + ) + { + print_usage(); + + System.err.println + ( + "[F] The output file has an extension that could be used in an" + + " input file. It is most likely that you did not indicate an" + + " output file, meaning that one of the input files was about to" + + " be written over. So likely, in fact, that we'll abort here. The" + + " output file you indicated was \"" + + output_file + + "\"." + ); + + System.exit(-1); + } + + prop_file = new String(); + + for (int i = 1; i < args.length; ++i) + { + if (args[i].endsWith(".lvl")) + { + level_files.add(args[i]); + } + else if (args[i].endsWith(".mod")) + { + model_files.add(args[i]); + } + else if (args[i].endsWith(".pro")) + { + if (has_pro_file) + { + System.err.println + ( + "[E] Both files \"" + + prop_file + + "\" and \"." + + args[i] + + "\" contain a property. Only one can be used at a time." + ); + + has_error = true; + } + else + { + has_pro_file = true; + prop_file = args[i]; + } + } + else if (args[i].equals("-v") || args[i].equals("--verbose")) + { + should_be_verbose = true; + } + else + { + System.err.println + ( + "[E] Unknown file type \"" + + args[i] + + "\"." + ); + + has_error = true; + } + } + + property_file = prop_file; + + if (!has_pro_file) + { + System.err.println("[E] There was no property file."); + + has_error = true; + } + + be_verbose = should_be_verbose; + are_valid = !has_error; + } + + public List get_level_files () + { + return level_files; + } + + public List get_model_files () + { + return model_files; + } + + public String get_property_file () + { + return property_file; + } + + public String get_output_file () + { + return output_file; + } + + public boolean be_verbose () + { + return be_verbose; + } + + public boolean are_valid () + { + return are_valid; + } +} -- cgit v1.2.3-70-g09d2