1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
(**************************************************************************)
(* *)
(* Headache *)
(* *)
(* Vincent Simonet, Projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 2002 *)
(* Institut National de Recherche en Informatique et en Automatique. *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Library General Public License. *)
(* *)
(* Vincent.Simonet@inria.fr http://cristal.inria.fr/~simonet/ *)
(* *)
(**************************************************************************)
type regexp_filename = Str.regexp
;;
type regexp_skip = Str.regexp
;;
type param_skip = bool * regexp_skip
;;
let skip ~verbose skip_lst ic oc =
let multiple_skip_lst,simple_skip_lst =
List.partition (fun (_,(multiple,_)) -> multiple) skip_lst
in
let rec skip_aux () =
let initial_pos =
LargeFile.pos_in ic
in
try
let line =
input_line ic
in
let match_line skip_lst =
let (_,(multiple,_)) =
List.find
(fun (_, (_,rg_skip)) -> Str.string_match rg_skip line 0)
skip_lst
in multiple
in
try
let multiple =
try
match_line multiple_skip_lst;
with Not_found ->
match_line simple_skip_lst;
in
if verbose then
prerr_endline
("Line : "^line^" skipped");
(match oc with
| None -> ()
| Some oc ->
output_string oc line;
output_string oc "\n");
if multiple then skip_aux ()
with Not_found ->
LargeFile.seek_in ic initial_pos
with End_of_file ->
()
in
skip_aux ()
;;
|