(************************************************************ inverseDepend.ml Created : Fri Aug 30 13:04:02 2002 Last modified: Fri Aug 30 15:09:50 2002 Compile: ocamlopt.opt -I /home/tak/lib/ocaml mylib.cmx str.cmxa inverseDepend.ml -o inverseDepend # Example: cat ~/project/ml_graph/ocaml-3.06/.depend | ./inverseDepend ************************************************************) (** 依存性の逆エッジ。どのモジュールに使われるのかな? .depend を読み込んで参照元を出力する。 標準入力から読み込み。またしてもインターフェイス手抜き @author 増山隆 @see http://www002.upp.so-net.ne.jp/mamewo/ml.html *) open Mylib let head_tail_delim_regexp = Str.regexp ":+" let tail_delim_regexp = Str.regexp "[\t ]+" (*type t = Depend of string * (string list)*) type t = Depend of (string * string) exception Error of string (** End_of_file 例外はスルーする *) (*let rec input_dependency_line in_channel =*) (* let str = input_line_with_escape in_channel in*) (* match Str.split head_tail_delim_regexp str with*) (* [] ->*) (* input_dependency_line in_channel*) (* | head::tail::[] ->*) (* Depend(head,(Str.split tail_delim_regexp tail))*) (* | _ -> raise (Error ("bad dependency line "^str))*) let rec input_dependency_line in_channel = let str = input_line_with_escape in_channel in match Str.split head_tail_delim_regexp str with [] -> input_dependency_line in_channel | head::tail::[] -> Depend(head,tail) | _ -> raise (Error ("bad dependency line "^str)) let is_depend_on target_regexp (Depend(head,tail)) = Str.string_match target_regexp tail 0 let _ = (* 標準入力からの読み込み *) let input = stdin in (* ここらへんが変わったようなきがする * string_match は 指定された位置から厳密にマッチを始めるんだったっけ? * とりあえず .* で回避 *) let target = Str.regexp ".*parse" in try while true do let Depend(head,lst) as dep = input_dependency_line input in if is_depend_on target dep then print_string (head ^ "\n") else () done with End_of_file -> ();