From: wang Date: Wed, 9 Oct 2013 00:27:04 +0000 (+0200) Subject: Bug fixed for stdin and stdout in a different platform. X-Git-Url: https://scm.cri.mines-paristech.fr/git/Faustine.git/commitdiff_plain/50baab1849bddf73ee88b54f52b28060de1ce289 Bug fixed for stdin and stdout in a different platform. Tested by "make test". --- diff --git a/Makefile b/Makefile index 5f8cbba..582ead6 100644 --- a/Makefile +++ b/Makefile @@ -37,12 +37,11 @@ mrproper: clean test: @$(MAKE) -C $(SINWAVE_DIR) - @ls -l $(SINWAVE_DIR)/output1.wav @echo " You might want to check the output file with either:" - @echo "audacity $(SINWAVE_DIR)/output1.wav" - @echo "open $(SINWAVE_DIR)/output1.wav" - @echo "octave -q --eval 'plot(wavread(\"$(SINWAVE_DIR)/output1.wav\")); pause'" + @echo "audacity $(SINWAVE_DIR)/sin.wav" + @echo "open $(SINWAVE_DIR)/sin.wav" + @echo "octave -q --eval 'plot(wavread(\"$(SINWAVE_DIR)/sin.wav\")); pause'" examples:: @($(MAKE) -C $(EXAMPLES_DIR)) diff --git a/interpreter/main.ml b/interpreter/main.ml index 7275d01..94b0ae1 100644 --- a/interpreter/main.ml +++ b/interpreter/main.ml @@ -59,16 +59,36 @@ let file_of_path : string -> string = let n = List.length fragments in List.nth fragments (n - 1);; +let valid_input_file : string -> bool = + fun (file : string) -> + let fragments = Str.split (Str.regexp "\.") file in + let n = List.length fragments in + let extension = List.nth fragments (n - 1) in + if extension = "csv" || extension = "wav" then true + else false;; + +let chk_input_path : string -> bool = + fun (path : string) -> + let file_in = file_of_path path in + valid_input_file file_in;; + let stdinput = fun (x : unit) -> let path = Unix.readlink "/proc/self/fd/0" in - if path <> "/dev/pts/4" then + if chk_input_path path then ( incr size_input; inputs := !inputs @ [path] ) else ();; +let chk_output_path : string -> bool = + fun (path : string) -> + let fragments = Str.split (Str.regexp "/") path in + let location = List.nth fragments 0 in + if location = "dev" then false + else true;; + let stdoutput = fun (x : unit) -> let path = Unix.readlink "/proc/self/fd/1" in - if path <> "/dev/pts/4" then output := path + if chk_output_path path then output := path else ();; let stdio = fun (x : unit) ->