Markus Mottl avatar Markus Mottl committed e2ec1a2

Fixed C-header parsing bug

Comments (0)

Files changed (4)

   | FLOAT
   | UINT
 
-let parse = 
+let parse =
+  let regexp_partial = Str.regexp "double gsl_cdf_" in
   let regexp_full = Str.regexp "double gsl_cdf_\\([^ ]+\\) (\\([^)]+\\));" in
   let regexp_arg  = Str.regexp "const \\(double\\|unsigned int\\) \\([a-zA-Z0-9_]+\\)" in
-  fun s ->
+  let rec loop s =
     if Str.string_match regexp_full s 0
     then
       let fun_name = Str.matched_group 1 s in
-      let args = 
-	begin 
-	  let acc = ref [] in
-	  let i = ref (Str.group_beginning 2) in
-	  begin try while true do
-	    let _ = Str.search_forward regexp_arg s !i in
-	    let ty =
-	      match Str.matched_group 1 s with
-	      | "double" -> FLOAT
-	      | "unsigned int" -> UINT 
-	      | _ -> assert false in
-	    let n = Str.matched_group 2 s in
-	    acc := (ty, n) :: !acc ;
-	    i := Str.match_end ()
-	  done
-	  with Not_found -> () end ;
-	  List.rev !acc
-	end in
+      let args =
+        let acc = ref [] in
+        let i = ref (Str.group_beginning 2) in
+        begin try while true do
+            let _ = Str.search_forward regexp_arg s !i in
+            let ty =
+              match Str.matched_group 1 s with
+              | "double" -> FLOAT
+              | "unsigned int" -> UINT
+              | _ -> assert false in
+            let n = Str.matched_group 2 s in
+            acc := (ty, n) :: !acc ;
+            i := Str.match_end ()
+          done
+        with Not_found -> () end;
+        List.rev !acc
+      in
       if List.length args > 5
       then (Printf.eprintf "functions `%s' has more than 5 arguments, this is unsupported\n%!" fun_name ; None)
       else Some (fun_name, args)
+    else if Str.string_match regexp_partial s 0 then
+      loop (s ^ read_line ())
     else
       None
+  in
+  loop
 
 let may f = function
   | None -> ()
 let print_all_float fun_name oc args =
   if all_float args
   then Printf.fprintf oc " \"gsl_cdf_%s\" \"float\"" fun_name
-let print_ml_args oc args = 
+let print_ml_args oc args =
   List.iter (fun (ty, a) ->
     let l = String.lowercase a in
     match ty with
     | UINT  -> Printf.fprintf oc "%s:int -> "   l)
     args
 let print_ml (fun_name, args) =
-  Printf.printf 
+  Printf.printf
     "external %s : %afloat = \"ml_gsl_cdf_%s\"%a\n"
     fun_name
     print_ml_args args
     | UINT  -> output_string oc " Unsigned_int_val,")
     args
 let print_c (fun_name, args) =
-  Printf.printf 
+  Printf.printf
     "ML%d(gsl_cdf_%s,%a copy_double)\n\n"
-    (List.length args) 
-    fun_name 
+    (List.length args)
+    fun_name
     print_c_args args
 
-let c_output = 
+let c_output =
   Array.length Sys.argv > 1 && Sys.argv.(1) = "--c"
 
 let _ =
   if c_output
-  then Printf.printf "#include <gsl/gsl_cdf.h>\n#include \"wrappers.h\"\n\n" 
+  then Printf.printf "#include <gsl/gsl_cdf.h>\n#include \"wrappers.h\"\n\n"
   else Printf.printf "(** Cumulative distribution functions *)\n\n" ;
 
   try while true do
-    may 
-      (if c_output then print_c else print_ml) 
+    may
+      (if c_output then print_c else print_ml)
       (parse (read_line ()))
   done with End_of_file -> ()
 external negative_binomial_Q : k:int -> p:float -> n:float -> float = "ml_gsl_cdf_negative_binomial_Q"
 external pascal_P : k:int -> p:float -> n:int -> float = "ml_gsl_cdf_pascal_P"
 external pascal_Q : k:int -> p:float -> n:int -> float = "ml_gsl_cdf_pascal_Q"
+external hypergeometric_P : k:int -> n1:int -> n2:int -> t:int -> float = "ml_gsl_cdf_hypergeometric_P"
+external hypergeometric_Q : k:int -> n1:int -> n2:int -> t:int -> float = "ml_gsl_cdf_hypergeometric_Q"
 external negative_binomial_Q : k:int -> p:float -> n:float -> float = "ml_gsl_cdf_negative_binomial_Q"
 external pascal_P : k:int -> p:float -> n:int -> float = "ml_gsl_cdf_pascal_P"
 external pascal_Q : k:int -> p:float -> n:int -> float = "ml_gsl_cdf_pascal_Q"
+external hypergeometric_P : k:int -> n1:int -> n2:int -> t:int -> float = "ml_gsl_cdf_hypergeometric_P"
+external hypergeometric_Q : k:int -> n1:int -> n2:int -> t:int -> float = "ml_gsl_cdf_hypergeometric_Q"
 
 ML3(gsl_cdf_pascal_Q, Unsigned_int_val, Double_val, Unsigned_int_val, copy_double)
 
+ML4(gsl_cdf_hypergeometric_P, Unsigned_int_val, Unsigned_int_val, Unsigned_int_val, Unsigned_int_val, copy_double)
+
+ML4(gsl_cdf_hypergeometric_Q, Unsigned_int_val, Unsigned_int_val, Unsigned_int_val, Unsigned_int_val, copy_double)
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.