From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:43947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDeOR-0000XA-66 for qemu-devel@nongnu.org; Fri, 30 Mar 2012 12:09:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SDeOM-0005kv-7V for qemu-devel@nongnu.org; Fri, 30 Mar 2012 12:09:38 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:61911) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDeOM-0005kk-2r for qemu-devel@nongnu.org; Fri, 30 Mar 2012 12:09:34 -0400 Received: by obbwd20 with SMTP id wd20so1277460obb.4 for ; Fri, 30 Mar 2012 09:09:32 -0700 (PDT) Message-ID: <4F75DAB9.9020802@codemonkey.ws> Date: Fri, 30 Mar 2012 11:09:29 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1333111003-28556-1-git-send-email-liwp@linux.vnet.ibm.com> <87bonet6zk.fsf@ginnungagap.bsc.es> In-Reply-To: <87bonet6zk.fsf@ginnungagap.bsc.es> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH] RFC: options parse in vl.c should be moduled List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?ISO-8859-1?Q?Llu=EDs_Vilanova?= Cc: Anthony Liguori , Wanpeng Li , Stefan Hajnoczi , qemu-devel , =?ISO-8859-1?Q?Andreas_F=E4rber?= , Gavin Shan On 03/30/2012 10:59 AM, Lluís Vilanova wrote: > Wanpeng Li writes: > >> Consider of the options parse process in main function of vl.c is too >> long.It should be module into single function to clear ideas, strengthen >> the source code management, and increase code readability.So I module the >> process of options parse as function options_parse, and expose some variables >> in order to not influence command-line invocations. > > Another approach would be to use something similar to QOM type registration. > > In order to keep code to a minimum, you can define an array of pointers to > QParameter structures, instead of an array of function pointers (what > __attribute__((constructors)) does). > > So, for example: > > static void opt_icount_handler(const char *args) > { > if (kvm_enabled() || xen_enabled()) { > fprintf(stderr, "-icount is not allowed with kvm or xen\n"); > exit(1); > } > /* ... contents of configure_icount ... */ > } > > static QEMUOption opt_icount = { > .name = "icount", > .signature = "[N|auto]", > .help = "enable virtual instruction counter with 2^N clock ticks per instruction", > .mode = QEMU_MODE_SYSTEM, > .priority = QEMU_OPT_PRIO_BEFORE_DEVICES, > .section = QEMU_OPT_SECTION_DEBUG, > .handler = opt_icount_handler > }; > > param_register(opt_icount); > > > Here, param_register would define an array of pointers to QEMUOption structures, > although I'm not sure how this can be handled on formats other than ELF. My plan is to have a -query-capabilities so we can change the help text, then use GOptionContext. It would take a small function that goes through and promotes any option in the format '-foo' to '--foo'. But that's not too hard. Then we can completely rip out the option parsing, qemu-options.hx, and all of that other junk. Regards, Anthony Liguori