qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] help parsing qemu options
@ 2015-03-09 17:50 Gabriel L. Somlo
  2015-03-10  8:40 ` Markus Armbruster
  0 siblings, 1 reply; 8+ messages in thread
From: Gabriel L. Somlo @ 2015-03-09 17:50 UTC (permalink / raw)
  To: qemu-devel

Hi,

Assuming I'm trying to add a new command line option to qemu in vl.c:

...

static QemuOptsList qemu_foo_opts = {
    .name = "foo",
    .implied_opt_name = "name",
    .head = QTAILQ_HEAD_INITIALIZER(qemu_foo_opts.head),
    .desc = {
        {
            .name = "name",
            .type = QEMU_OPT_STRING,
        }, {
            .name = "file",
            .type = QEMU_OPT_STRING,
        },
        { /* end of list */ }
    },
};

...

main() {

    ...
    qemu_add_opts(&qemu_foo_opts);

    ...

    /* second pass of option parsing */
    ...
    for(;;) {
        ...
        switch(popt->index) {
            ...

        case QEMU_OPTION_foo:
            opts = qemu_opts_parse(qemu_find_opts("foo"), optarg, 0);
            if (!foo_option_add(qemu_opt_get(opts, "name"),
                                qemu_opt_get(opts, "file"))) {
                fprintf(stderr, "invalid foo entry config %s\n", optarg);
                exit(1);
            }
            break;

    ...
}


Somewhere else in the source I have

bool foo_option_add(const char *name, const char *file) {

    if (/* everything OK */) {
        return true;
    }

    return false;
}    


Assuming the above is correct (and that the appropriate glue is added
to qemu-options.hx to tie "-foo name=abc,file=xyz" to QEMU_OPTION_foo),
I'm wondering about preventing "name" and "file" from being turned
into Booleans should their arguments be omitted on the command line.

To clarify:

-foo abcxyz   results in a parse error generated by qemu_opts_parse()
              which is as it should be

-foo file=abc,name=xyz   results in a call to foo_option_add("xyz", "abc")
                         which is the desired behavior

-foo file=,name=   results in a call to foo_option_add("", "")
                   which is also OK, as I can sanity-check my
                   arguments from within foo_option_add()

However,

-foo file,name    results in a call to foo_option_add("on", "on")
                  i.e., in the absence of string values, both
                  "file" and "name" are converted into Booleans
                  and given the string value "on" by qemu_opts_parse()
                  which is NOT what I want, and I'm wondering if
                  that behavior can somehow be turned off for
                  any given QemuOptsList ?

I guess I could be looking for a file named "on" in the current
directory, and attempt to use the value "on" to insert the object
from the given file (and fail if no file named "on" could be found,
but this is not as clean as I would like it to be, and I'm wondering
if there's a better way).

Thanks much,
--Gabriel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-03-11 13:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-09 17:50 [Qemu-devel] help parsing qemu options Gabriel L. Somlo
2015-03-10  8:40 ` Markus Armbruster
2015-03-10 17:35   ` Gabriel L. Somlo
2015-03-11  7:52     ` Markus Armbruster
2015-03-11 11:59       ` Kevin Wolf
2015-03-11 12:40         ` Gabriel L. Somlo
2015-03-11 12:53           ` Gabriel L. Somlo
2015-03-11 13:17             ` Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).