My working unpac repository
at opam/upstream/seq 54 lines 2.0 kB view raw
1(**************************************************************************) 2(* *) 3(* OCaml *) 4(* *) 5(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) 6(* OCaml port by John Malecki and Xavier Leroy *) 7(* *) 8(* Copyright 1996 Institut National de Recherche en Informatique et *) 9(* en Automatique. *) 10(* *) 11(* All rights reserved. This file is distributed under the terms of *) 12(* the GNU Lesser General Public License version 2.1, with the *) 13(* special exception on linking described in the file LICENSE. *) 14(* *) 15(**************************************************************************) 16 17(* Handling of keyboard interrupts *) 18 19let interrupted = ref false 20 21let is_protected = ref false 22 23let break _signum = 24 if !is_protected 25 then interrupted := true 26 else raise Sys.Break 27 28let _ = 29 match Sys.os_type with 30 "Win32" -> () 31 | _ -> 32 Sys.set_signal Sys.sigint (Sys.Signal_handle break); 33 Sys.set_signal Sys.sigpipe (Sys.Signal_handle(fun _ -> raise End_of_file)) 34 35let protect f = 36 if !is_protected then 37 f () 38 else begin 39 is_protected := true; 40 if not !interrupted then 41 f (); 42 is_protected := false; 43 if !interrupted then begin interrupted := false; raise Sys.Break end 44 end 45 46let unprotect f = 47 if not !is_protected then 48 f () 49 else begin 50 is_protected := false; 51 if !interrupted then begin interrupted := false; raise Sys.Break end; 52 f (); 53 is_protected := true 54 end