On Monday, 11 July 2016 18:00:04 CEST Richard W.M. Jones wrote:
On Mon, Jul 11, 2016 at 06:03:39PM +0200, Pino Toscano wrote:
> diff --git a/mllib/getopt-c.c b/mllib/getopt-c.c
> new file mode 100644
> index 0000000..e5e832c
> --- /dev/null
> +++ b/mllib/getopt-c.c
> +static void
> +do_call1 (value funv, value paramv)
> +{
> + CAMLparam2 (funv, paramv);
> + CAMLlocal1 (rv);
> +
> + rv = caml_callback_exn (funv, paramv);
> +
> + if (Is_exception_result (rv))
> + fprintf (stderr,
> + "libguestfs: uncaught OCaml exception in getopt callback:
%s",
Does this need \n?
I think so, fixed.
> + case 0:
> + if (STREQ (longopts[option_index].name, "help")) {
> + show_help (specsv, usage_msgv);
> + }
> + /* specv_index set already -- nothing to do. */
> + break;
> +
> + case 'h':
> + show_help (specsv, usage_msgv);
> + break;
Is this right? Several commands (eg. virt-df) take a -h option which
isn't for help.
virt-df is written in C though.
OTOH, I fixed it so it is added only if not present already.
> +let parse_argv argv specs ?anon_fun usage_msg =
> + (* Sanity check the input *)
> + let validate_key key =
> + if String.length key == 0 || key == "-" || key == "--"
> + || key.[0] != '-' then
> + raise (Invalid_argument (sprintf "invalid option key: '%s'"
key))
Whereever you've written 'raise (Invalid_argument ...)' you can
replace it with 'invalid_arg ...'.
Oh -- fixed, thanks.
New version coming in a minute.
Thanks,
--
Pino Toscano