From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Pu7dF-00043O-Vt for garchives@archives.gentoo.org; Mon, 28 Feb 2011 18:15:45 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2B8D71C02A; Mon, 28 Feb 2011 18:15:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id F313C1C02A for ; Mon, 28 Feb 2011 18:15:34 +0000 (UTC) Received: from flycatcher.gentoo.org (flycatcher.gentoo.org [81.93.255.6]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 68C871B4007 for ; Mon, 28 Feb 2011 18:15:34 +0000 (UTC) Received: by flycatcher.gentoo.org (Postfix, from userid 559) id 0E58D20054; Mon, 28 Feb 2011 18:15:33 +0000 (UTC) From: "Mike Frysinger (vapier)" To: gentoo-commits@lists.gentoo.org Reply-To: gentoo-dev@lists.gentoo.org, vapier@gentoo.org Subject: [gentoo-commits] gentoo-projects commit in portage-utils: q.c X-VCS-Repository: gentoo-projects X-VCS-Files: q.c X-VCS-Directories: portage-utils X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger Content-Type: text/plain; charset=utf8 Message-Id: <20110228181533.0E58D20054@flycatcher.gentoo.org> Date: Mon, 28 Feb 2011 18:15:33 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 710028f94dfa50fb839118da173378a8 vapier 11/02/28 18:15:33 Modified: q.c Log: add a helper for easily running applets from other applets Revision Changes Path 1.50 portage-utils/q.c file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils= /q.c?rev=3D1.50&view=3Dmarkup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils= /q.c?rev=3D1.50&content-type=3Dtext/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils= /q.c?r1=3D1.49&r2=3D1.50 Index: q.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /var/cvsroot/gentoo-projects/portage-utils/q.c,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- q.c 21 Feb 2011 01:33:47 -0000 1.49 +++ q.c 28 Feb 2011 18:15:32 -0000 1.50 @@ -1,7 +1,7 @@ /* * Copyright 2005-2010 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/q.c,v 1.49 2011/0= 2/21 01:33:47 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/portage-utils/q.c,v 1.50 2011/0= 2/28 18:15:32 vapier Exp $ * * Copyright 2005-2010 Ned Ludd - * Copyright 2005-2010 Mike Frysinger - @@ -22,7 +22,7 @@ "Module path", COMMON_OPTS_HELP }; -static const char q_rcsid[] =3D "$Id: q.c,v 1.49 2011/02/21 01:33:47 vap= ier Exp $"; +static const char q_rcsid[] =3D "$Id: q.c,v 1.50 2011/02/28 18:15:32 vap= ier Exp $"; #define q_usage(ret) usage(ret, Q_FLAGS, q_long_opts, q_opts_help, looku= p_applet_idx("q")) =20 static APPLET lookup_applet(const char *applet) @@ -134,3 +134,43 @@ =20 return (func)(argc - 1, ++argv); } + +static int run_applet_l(const char *arg, ...) +{ + int (*applet)(int, char **); + va_list ap; + int ret, optind_saved, argc; + char **argv; + const char *argv0_saved; + + optind_saved =3D optind; + argv0_saved =3D argv0; + + applet =3D lookup_applet(arg); + if (!applet) + return -1; + + /* This doesn't NULL terminate argv, but you should be using argc */ + va_start(ap, arg); + argc =3D 0; + argv =3D NULL; + while (arg) { + argv =3D xrealloc(argv, sizeof(*argv) * ++argc); + argv[argc - 1] =3D xstrdup(arg); + arg =3D va_arg(ap, const char *); + } + va_end(ap); + + optind =3D 0; + argv0 =3D argv[0]; + ret =3D applet(argc, argv); + + while (argc--) + free(argv[argc]); + free(argv); + + optind =3D optind_saved; + argv0 =3D argv0_saved; + + return ret; +}