(************************************************************ mylib.ml Created : Fri Aug 30 13:08:51 2002 Last modified: Thu Oct 24 01:34:08 2002 Compile: make bcl # Compile: ocamlopt.opt mylib.ml -o mylib # ************************************************************) (** 個人的に作成したライブラリ。ファイル処理が中心 @author 増山隆 @version $Id: drawMakefile.ml,v 1.5 2002/10/16 03:48:05 tak Exp $ @see Pervasivesモジュールの説明 @see 作者のウェブページ バグ 2002/10/23 input_line_with_escapeで空行がある場合にも正しく処理できるようにした *) (** \直後の改行で複数行に跨って良いような入力を処理する。 \でつながった複数行を一行として 扱って読み込む。 @param in_channel 入力チャネル @raise End_of_file ファイルをすべて読んだら投げる *) let input_line_with_escape in_channel = let result = ref "" in let is_continue = ref true in let count = ref 0 in try while !is_continue do let line = input_line in_channel in (** for debug **) (* let _ = begin Printf.printf "LINE# %s #\n" line; flush stdout end in*) let length = String.length line in begin is_continue := (length > 0) && (String.get line (length-1) = '\\'); incr count; if !is_continue then if length > 2 then result := !result ^ (String.sub line 0 (length-2)) else () else result := !result ^ line end done; !result with End_of_file -> if !count = 0 then raise End_of_file else !result let dependency_regexp = Str.regexp "^\\([/.a-zA-Z0-9_-]+\\):+ *\\(.+\\)$" let spaces_regexp = Str.regexp "[ \t]+" (** 一つのdependencyの行を読み込む *) let rec read_dependency_file in_channel = let line = input_line_with_escape in_channel in if Str.string_match dependency_regexp line 0 then let head = Str.matched_group 1 line in let tail_list = Str.split spaces_regexp (Str.matched_group 2 line) in (head,tail_list) else read_dependency_file in_channel let make_interval_list s e = let rec iter c result = if c < s then result else iter (c-1) (c::result) in iter e []