(************************************************************ get_date.ml Created : Mon Jan 30 00:15:08 2006 Last modified: Mon Jan 30 00:42:11 2006 Compile: ocamlc -dtypes str.cma get_date.ml -o get_date # FTP Directory: sources/ocaml # ************************************************************) (** @author Takashi Masuyama *) let linelimit = 10 type date = Date of (int * int * int * int * int * int) let date_regexp = Str.regexp ".*Last modified: [^ ]+ \\([A-Za-z]+\\) \\([0-9]+\\) \\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) \\([0-9]+\\)" let month_list = ["Jan"; "Feb"; "Mar"; "Apr"; "May"; "Jun"; "Jul"; "Aug"; "Sep"; "Oct"; "Nov"; "Dec"] let str_month_to_num_month target = let rec get_index n lst = match lst with [] -> raise Not_found | hd::tl -> if hd = target then n else get_index (n+1) tl in get_index 1 month_list let get_last_modified instream = let rec iter count = if count = 0 then raise Not_found else let line = input_line instream in if Str.string_match date_regexp line 0 then let month = str_month_to_num_month (Str.matched_group 1 line) in let day = int_of_string (Str.matched_group 2 line) in let hour = int_of_string (Str.matched_group 3 line) in let min = int_of_string (Str.matched_group 4 line) in let sec = int_of_string (Str.matched_group 5 line) in let year = int_of_string (Str.matched_group 6 line) in Date(year, month, day, hour, min, sec) else iter (count-1) in iter linelimit let print_date date = match date with Date(year, month, day, hour, min, sec) -> Printf.printf "%04d/%02d/%02d %02d/%02d/%02d\n" year month day hour min sec let _ = let instream = open_in "get_date.ml" in print_date (get_last_modified instream); close_in instream (* * Local Variables: * namazu-default-dir:"/home/tak/.indexes/ocaml" * End: *)