1
(***********************************************************************)
5
(* Pierre Weis, projet Cristal, INRIA Rocquencourt *)
7
(* Copyright 2001 Institut National de Recherche en Informatique et *)
8
(* en Automatique. All rights reserved. This file is distributed *)
9
(* only by permission. *)
11
(***********************************************************************)
16
let ligne_trouv�e = ref false;;
18
let grep_sur_canal auto nom_fich canal =
21
let ligne = input_line canal in
22
if reconna�t auto ligne then begin
23
ligne_trouv�e := true;
24
print_string nom_fich;
29
with End_of_file -> ();;
31
let grep_sur_fichier auto nom_fich =
33
let canal = open_in nom_fich in
34
try grep_sur_canal auto nom_fich canal; close_in canal
35
with exc -> close_in canal; raise exc
36
with Sys_error message ->
37
prerr_string "Erreur sur le fichier ";
38
prerr_string nom_fich;
40
prerr_endline message;;
42
let construire_auto expr =
43
d�terminise(expr_vers_automate(lire(Stream.of_string expr)));;
45
let grep expr fichier =
46
grep_sur_fichier (construire_auto expr) fichier;;
48
if !Sys.interactive then () else
49
if Array.length Sys.argv < 2 then begin
50
prerr_endline "Utilisation: grep <motif> <fichiers>";
54
try construire_auto Sys.argv.(1) with
56
prerr_endline ("Erreur de syntaxe dans l'expression: " ^ s);
59
prerr_endline "Erreur de syntaxe dans l'expression";
61
if Array.length Sys.argv >= 3 then
62
for i = 2 to Array.length Sys.argv - 1 do
63
grep_sur_fichier auto Sys.argv.(i)
66
grep_sur_canal auto "(entr�e standard)" stdin;
67
exit (if !ligne_trouv�e then 0 else 1)