From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:41459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDelf-0008L6-Lz for qemu-devel@nongnu.org; Fri, 30 Mar 2012 12:33:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SDela-0003P7-Cq for qemu-devel@nongnu.org; Fri, 30 Mar 2012 12:33:38 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:41116) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDela-0003Oc-4g for qemu-devel@nongnu.org; Fri, 30 Mar 2012 12:33:34 -0400 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 30 Mar 2012 10:33:26 -0600 Received: from d03relay01.boulder.ibm.com (d03relay01.boulder.ibm.com [9.17.195.226]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id EC75A1FF004C for ; Fri, 30 Mar 2012 10:32:28 -0600 (MDT) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay01.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q2UGWGdY203904 for ; Fri, 30 Mar 2012 10:32:17 -0600 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q2UGVrts004283 for ; Fri, 30 Mar 2012 10:31:54 -0600 Message-ID: <4F75DFF8.4030403@us.ibm.com> Date: Fri, 30 Mar 2012 11:31:52 -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> <4F75DAB9.9020802@codemonkey.ws> In-Reply-To: <4F75DAB9.9020802@codemonkey.ws> 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: Anthony Liguori Cc: Gavin Shan , Stefan Hajnoczi , qemu-devel , =?ISO-8859-1?Q?Andreas_F=E4rber?= , =?ISO-8859-1?Q?Llu=EDs_Vilanova?= , Wanpeng Li On 03/30/2012 11:09 AM, Anthony Liguori wrote: > 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. glib's option parsing support has some really nice features like translation support, grouping, and inline help for option definition. The grouping is a really nice touch. It will let us have a target specific group, device groups, etc. Regards, Anthony Liguori > > Regards, > > Anthony Liguori >