summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-05-28 15:50:05 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-05-28 15:50:05 +0200
commit84831716add27b53954142c3bbd72539b9168021 (patch)
tree68df8f61349d7d84847754aaf96f6cf05eee35e7
parent1a64a73c47394dab7b10e6fd87fb8390df3ad89c (diff)
downloadhastabel2idp-84831716add27b53954142c3bbd72539b9168021.zip
hastabel2idp-84831716add27b53954142c3bbd72539b9168021.tar.bz2
Can now run IDP.
-rw-r--r--99_general.txt4
-rw-r--r--99_idp_main.txt4
-rw-r--r--src/hastabel2idp/Main.java96
-rw-r--r--src/hastabel2idp/OutputFile.java29
-rw-r--r--src/hastabel2idp/Parameters.java30
5 files changed, 150 insertions, 13 deletions
diff --git a/99_general.txt b/99_general.txt
deleted file mode 100644
index 4f0e7c7..0000000
--- a/99_general.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-procedure main(){
- printmodels(onemodel(T,S,Vout))
-}
-
diff --git a/99_idp_main.txt b/99_idp_main.txt
new file mode 100644
index 0000000..9dee3df
--- /dev/null
+++ b/99_idp_main.txt
@@ -0,0 +1,4 @@
+procedure main(){
+ printmodels(allmodels(T,S,Vout))
+}
+
diff --git a/src/hastabel2idp/Main.java b/src/hastabel2idp/Main.java
index e64e132..f4201de 100644
--- a/src/hastabel2idp/Main.java
+++ b/src/hastabel2idp/Main.java
@@ -6,6 +6,8 @@ import hastabel.World;
import hastabel.lang.Formula;
import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
public class Main
{
@@ -52,9 +54,26 @@ public class Main
write_idp(world, property, params);
- OutputFile.close_all();
+ System.out.println("# Flushing generated files...");
+ OutputFile.flush_all();
+
+ if (params.get_idp_executable() == null)
+ {
+ System.out.println("# No IDP executable set. Stopping here.");
+ OutputFile.close_all();
- System.out.println("# Done.");
+ return;
+ }
+
+ System.out.println("# Running IDP...");
+
+ System.out.println
+ (
+ "# Result: "
+ + run_idp(world, params)
+ );
+
+ OutputFile.close_all();
}
private static void load_file (final World world, final String filename)
@@ -143,9 +162,80 @@ public class Main
{
final Project project;
-
project = new Project(params);
project.generate("my_property", world, property);
}
+
+ private static String run_idp
+ (
+ final World world,
+ final Parameters params
+ )
+ {
+ final Process idp;
+ final BufferedReader idp_stdout, idp_stderr;
+ final String target;
+ final String[] args;
+
+ String line, result;
+
+ result = null;
+
+ args = new String[6];
+
+ args[0] = params.get_idp_executable();
+ args[1] = params.get_vocabulary_filename();
+ args[2] = params.get_structure_filename();
+ args[3] = params.get_theory_filename();
+ args[4] = params.get_vocabulary_out_filename();
+ args[5] = params.get_idp_main_filename();
+
+ try
+ {
+ idp =
+ (
+ new ProcessBuilder
+ (
+ args[0],
+ args[1],
+ args[2],
+ args[3],
+ args[4],
+ args[5]
+ )
+ ).start();
+
+ target = "my_property = {";
+
+ idp_stdout =
+ new BufferedReader(new InputStreamReader(idp.getInputStream()));
+
+ while ((line = idp_stdout.readLine()) != null)
+ {
+ System.out.println(line);
+
+ if (line.contains(target))
+ {
+ result = line;
+ }
+ }
+
+ idp_stderr =
+ new BufferedReader(new InputStreamReader(idp.getErrorStream()));
+
+ while ((line = idp_stderr.readLine()) != null)
+ {
+ System.err.println("[E] " + line);
+ }
+
+ idp.waitFor();
+ }
+ catch (final Exception e)
+ {
+ System.err.println(e.toString());
+ }
+
+ return result;
+ }
}
diff --git a/src/hastabel2idp/OutputFile.java b/src/hastabel2idp/OutputFile.java
index 79af6e9..cfd4378 100644
--- a/src/hastabel2idp/OutputFile.java
+++ b/src/hastabel2idp/OutputFile.java
@@ -24,6 +24,14 @@ public class OutputFile
}
}
+ public static void flush_all ()
+ {
+ for (final OutputFile f: ALL_OUTPUT_FILES)
+ {
+ f.flush();
+ }
+ }
+
public static OutputFile new_output_file (final String filename)
{
final OutputFile result;
@@ -68,6 +76,27 @@ public class OutputFile
buffered_writer = bf;
}
+ public void flush ()
+ {
+ try
+ {
+ buffered_writer.flush();
+ }
+ catch (final Exception e)
+ {
+ System.err.println
+ (
+ "[F] Could not flush output file \""
+ + filename
+ + "\":"
+ );
+
+ e.printStackTrace();
+
+ System.exit(-1);
+ }
+ }
+
public void write (final String data)
{
try
diff --git a/src/hastabel2idp/Parameters.java b/src/hastabel2idp/Parameters.java
index 1642fbd..18f5c45 100644
--- a/src/hastabel2idp/Parameters.java
+++ b/src/hastabel2idp/Parameters.java
@@ -9,8 +9,8 @@ public class Parameters
private final List<String> model_files;
private final String property_file;
private final String output_dir;
+ private final String idp_exec;
private final boolean be_verbose;
-
private final boolean are_valid;
public static void print_usage ()
@@ -24,7 +24,7 @@ public class Parameters
+ "\t- <OUTPUT_DIR>\tDirectory in which to write the IDP model.\n"
+ "\t- <FILES>\tList of files to be loaded.\n"
+ "OPTIONS:\n"
- + "\t- -v|--verbose\tPrint informative messages to STDOUT.\n"
+ + "\t- -e|--exec <IDP_EXEC>\tIDP executable path.\n"
+ "NOTES:\n"
+ "\t- Exactly one property file must be in <FILES>.\n"
+ "\t- Property files have a \".pro\" extension.\n"
@@ -37,7 +37,7 @@ public class Parameters
public Parameters (final String... args)
{
boolean has_pro_file, has_error, should_be_verbose;
- String prop_file;
+ String prop_file, idp_file;
level_files = new ArrayList<String>();
model_files = new ArrayList<String>();
@@ -53,18 +53,20 @@ public class Parameters
are_valid = false;
be_verbose = false;
+ idp_exec = null;
return;
}
has_pro_file = false;
has_error = false;
+ idp_file = null;
output_dir = args[0];
if
(
- (output_dir.equals("-v") || output_dir.equals("--verbose"))
+ (output_dir.equals("-e") || output_dir.equals("--exec"))
/* || ... */
)
{
@@ -134,9 +136,14 @@ public class Parameters
prop_file = args[i];
}
}
- else if (args[i].equals("-v") || args[i].equals("--verbose"))
+ else if (args[i].equals("-e") || args[i].equals("--exec"))
{
- should_be_verbose = true;
+ i++;
+
+ if (i < args.length)
+ {
+ idp_file = args[i];
+ }
}
else
{
@@ -151,6 +158,7 @@ public class Parameters
}
}
+ idp_exec = idp_file;
property_file = prop_file;
if (!has_pro_file)
@@ -169,6 +177,11 @@ public class Parameters
return level_files;
}
+ public String get_idp_executable ()
+ {
+ return idp_exec;
+ }
+
public List<String> get_model_files ()
{
return model_files;
@@ -204,6 +217,11 @@ public class Parameters
return output_dir + "/01_structure.txt";
}
+ public String get_idp_main_filename ()
+ {
+ return "./99_idp_main.txt";
+ }
+
public boolean be_verbose ()
{
return be_verbose;