1 (* Mailvisa ispatcher binary *)
5 let usage = "USAGE mailvisa <command> [options]"
6 let help = "Valid commands are:
8 add Add messages to database
9 calculate Recalculate scores
10 check Check whether a message is spam
11 remove Remove messages from database
15 Use mailvisa <command> -h to list options for that command"
17 (** Execs the program designated by path. The program is
18 passed the concatenation of path and args as its arguments.
19 I.e. the program name is passed as the zeroth argument, as
20 is conventional in Unix.
22 let exec_program path args
=
23 execvp path
(Array.append
[| path
|] args
)
25 (** Execs a mailvisa program with the given arguments. If
26 callerpath is an explicit path, its dirname is prefixed
27 to program. Otherwise, program is sought it the
30 let exec_mailvisa_program callername program args
=
32 if (Filename.dirname callername
) = "." && (Filename.is_implicit callername
) then
33 exec_program program args
35 exec_program (Filename.concat
(Filename.dirname callername
) program
) args
38 | Unix_error
(errno
, _
, _
) ->
39 prerr_endline
("Error running program " ^ program ^
": " ^
(error_message errno
))
41 prerr_endline
("Error running program " ^ program
));
45 (* Abort and print usage message if no command was given *)
46 if (Array.length
Sys.argv
) < 2 then begin
50 (* Extract command and arguments *)
51 let progname = Sys.argv
.(0) in
52 let command = Sys.argv
.(1) in
53 let args = (let length = Array.length Sys.argv
in
55 then Array.sub
Sys.argv
2 (length - 2)
59 | "add" -> exec_mailvisa_program progname "mailvisa-add-messages" args
60 | "calculate" -> exec_mailvisa_program progname "mailvisa-calculate-scores" args
61 | "check" -> exec_mailvisa_program progname "mailvisa-check" args
62 | "help" -> print_endline
help
63 | "remove" -> exec_mailvisa_program progname "mailvisa-remove-messages" args
64 | "start" -> exec_mailvisa_program progname "mailvisad" args
65 | "view" -> exec_mailvisa_program progname "mailvisa-view-scores" args