open Sys;;
exception Error_Annule of int;;
let faire0 cmd =
match (Sys.command cmd) with
| 0 -> ();
| n when (n <> 0) -> raise (Error_Annule(n));;
let wait_lourd s =
let tmps_init = Sys.time() in
while (( (Sys.time ()) -. tmps_init) < s) do
();
done;;
let wait s =
faire0 ("sleep "^(string_of_float s));;
type temps = {
heure : int;
minute : int;
seconde : int;
milisec : int;
};;
let convertir_temps s =
let si = ref (1000. *. s) in
let heu = floor (!si /. 3600000.) in
si := !si -. (3600000. *. heu);
let min = floor (!si /. 60000.) in
si := !si -. (60000. *. min);
let sec = floor (!si /. 1000.) in
si := !si -. (1000. *. sec);
let msec = floor (!si) in
{ heure = int_of_float heu; minute = int_of_float min; seconde = int_of_float sec; milisec = int_of_float msec};;
let string_of_temps tmp =
match (tmp.heure, tmp.minute, tmp.seconde) with
| 0,0,0 -> ((string_of_int tmp.milisec)^"ms")
| 0,0,_ -> ((string_of_int tmp.seconde)^"s:"^(string_of_int tmp.milisec)^"ms")
| 0,_,_ -> ((string_of_int tmp.minute)^"m:"^(string_of_int tmp.seconde)^"s:"^(string_of_int tmp.milisec)^"ms")
| _,_,_ -> ((string_of_int tmp.heure)^"H:"^(string_of_int tmp.minute)^"m:"^(string_of_int tmp.seconde)^"s:"^(string_of_int tmp.milisec)^"ms")
let string_time () =
string_of_temps (convertir_temps (time ()));;
type temps_full = {
tmp : temps;
se : float};;
let temps_debut_chrono = ref { tmp={heure = 0; minute = 0; seconde = 0; milisec = 0}; se=0.};;
let chronometre_est_actif = ref false;;
let lancer_chrono () =
chronometre_est_actif := true;
temps_debut_chrono := { tmp=convertir_temps (time ()); se=(time ())};;
exception Chronometre_non_actif;;
let temps_chrono () =
(if not(!chronometre_est_actif) then raise Chronometre_non_actif);
string_of_temps (convertir_temps ((time ()) -. !temps_debut_chrono.se ) );;
let stopper_chrono () =
chronometre_est_actif := false;
temps_debut_chrono := { tmp={heure = 0; minute = 0; seconde = 0; milisec = 0}; se=0.};;