let main () =
  Arg.parse options
    (fun s -> remaining := s :: !remaining)
    (Printf.sprintf "Usage: %s [options] <files>\nThe '-' file is the standard input.\nOptions are:" Sys.argv.(0));

  match List.rev !remaining with
    [] ->
      prerr_endline (Printf.sprintf "Usage: %s [options] <files>" Sys.argv.(0));
      exit 1
  | files ->
      try
        let tdl = List.fold_left
          (fun acc f -> Tdl.merge_top_groups (tdl_of_file f) acc)
          (Tdl.group ())
          files
        in
        match !output_type with
          Rss ->
            let channel =  rss_channel_of_tdl "Things done" tdl in
            Rss.print_channel (formatter_of_out_channel stdout) channel
        | Tdl ->
            Tdl.print_group Format.std_formatter tdl;
            Format.print_flush ()
        | Tdl_by_day prefix ->
            split_by_day prefix tdl
      with
        Sys_error s
      | Failure s ->
          prerr_endline s ; exit 1