[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#686141: patch to add stdin support to galax-run



The following patch adds support for reading from standard input
when - is given as an argument.

diff -ur a/galax-1.1/toplevel/galax-run.ml b/galax-1.1/toplevel/galax-run.ml
--- a/galax-1.1/toplevel/galax-run.ml	2007-10-26 08:49:33.000000000 -0700
+++ b/galax-1.1/toplevel/galax-run.ml	2020-01-06 10:48:27.635953915 -0800
@@ -77,13 +77,17 @@
     print_processing_file mod_file;
     let (ext_ctxt_item,ext_ctxt) = set_up_external_context proc_ctxt in
     (* Load main module *)
+    let input = match mod_file with
+      "-" -> Galax_io.Channel_Input stdin
+      | filename -> Galax_io.File_Input filename
+    in
     let (mod_ctxt'', stmts) =
       match !context_file with
       | None ->
-	  compile_main_module_helper ext_ctxt_item mod_ctxt (Galax_io.File_Input mod_file)
+	  compile_main_module_helper ext_ctxt_item mod_ctxt input
       | Some f ->
 	  let compiled_program = Galax.import_prolog_only mod_ctxt ext_ctxt_item (Galax_io.File_Input f) in
-	  compile_main_module_helper false compiled_program (Galax_io.File_Input mod_file)
+	  compile_main_module_helper false compiled_program input
     in
 
     (* Evaluate all global variables *)
diff -ur a/galax-1.1/toplevel/top_options.ml b/galax-1.1/toplevel/top_options.ml
--- a/galax-1.1/toplevel/top_options.ml	2007-10-26 08:49:33.000000000 -0700
+++ b/galax-1.1/toplevel/top_options.ml	2020-01-06 11:13:01.339877090 -0800
@@ -963,6 +963,13 @@
   let (parse_list,real_usage) = 
     make_parse_list bos usage option_list true
   in
+  let parse_list =
+    (
+      "-",
+      Arg.Unit (function () -> args := "-" :: !args),
+      "read module from standard input"
+    ) :: parse_list
+  in
   begin
     Arg.parse parse_list (fun arg -> args := arg :: !args) real_usage;
     !args


Reply to: