From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Thu, 27 Oct 2022 09:30:50 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1onxLm-003pGo-AQ for lore@lore.pengutronix.de; Thu, 27 Oct 2022 09:30:50 +0200 Received: from bombadil.infradead.org ([2607:7c80:54:3::133]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1onxLl-0000D8-4Z for lore@pengutronix.de; Thu, 27 Oct 2022 09:30:49 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:From:In-Reply-To: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MtviN7RigylmZHH410lVntYKtErzs0AfPRVlgB5QrAE=; b=J76eExj4NHUSEOLoo76KjVCnpg spuKYKxUfUwBBxfnVTeEqfl5qq566qmaMbcGC6L2RXFYHQggTn8D7NdiloJ+u5uipwu//HP7QwwaV ofWNIwGRp6eeD2lArDSwIoIY8R2fruJTwlSIPIPOi7OUMvqp5q5lX4BA+kDWeEHGqxWCx/16Z2P6B ZlshZ3BXmM47pT+NxdVPwddvFT5PV4Uf1Ls7RgPzzRRH2yvK4tHY01y15MxoRRAwb8S7islYhhGZM BVLj9mJjFgqXrsKFcXetGxJLyVEVYq/jtRkgw8lyYsFIPxgbYnVkBtpmsnI154jHQB2evBqr82K0d YlwZdoAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1onxKU-00CAcj-Re; Thu, 27 Oct 2022 07:29:30 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1onxKH-00CAa3-LR for barebox@lists.infradead.org; Thu, 27 Oct 2022 07:29:19 +0000 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1onxKG-0008Qs-CW; Thu, 27 Oct 2022 09:29:16 +0200 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1onxKG-0003eI-52; Thu, 27 Oct 2022 09:29:16 +0200 Date: Thu, 27 Oct 2022 09:29:16 +0200 To: Ahmad Fatoum Cc: barebox@lists.infradead.org Message-ID: <20221027072916.GB9130@pengutronix.de> References: <20221026064205.2360041-1-a.fatoum@pengutronix.de> <20221026064205.2360041-5-a.fatoum@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221026064205.2360041-5-a.fatoum@pengutronix.de> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain User-Agent: Mutt/1.10.1 (2018-07-13) From: Sascha Hauer X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_002917_739635_1E2ECC1D X-CRM114-Status: GOOD ( 26.56 ) X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "barebox" X-SA-Exim-Connect-IP: 2607:7c80:54:3::133 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.ext.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-4.9 required=4.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Subject: Re: [PATCH 5/6] commands: drvinfo: support filtering by driver X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.ext.pengutronix.de) On Wed, Oct 26, 2022 at 08:42:04AM +0200, Ahmad Fatoum wrote: > drvinfo can be very long especially for the in-tree defconfigs, > add optional filtering support: > > barebox@board:/ drvinfo imx7d > Driver Device(s) > -------------------- > imx7d-src > 30390000.reset-controller@30390000.of > imx7d_adc > 30610000.adc@30610000.of > 30620000.adc@30620000.of > > Use 'devinfo DEVICE' for more information > > Signed-off-by: Ahmad Fatoum > --- > commands/drvinfo.c | 13 +++++++++++++ > common/complete.c | 21 +++++++++++++++++++++ > include/complete.h | 1 + > 3 files changed, 35 insertions(+) > > diff --git a/commands/drvinfo.c b/commands/drvinfo.c > index 9f8f971ee9dd..27ff55f01d90 100644 > --- a/commands/drvinfo.c > +++ b/commands/drvinfo.c > @@ -5,15 +5,23 @@ > #include > #include > #include > +#include > > static int do_drvinfo(int argc, char *argv[]) > { > + char *filter = NULL; > struct driver_d *drv; > struct device_d *dev; > > + if (IS_ENABLED(CONFIG_AUTO_COMPLETE) && argc > 1) > + filter = strjoin(" ", &argv[1], argc - 1); Why does this depend on CONFIG_AUTO_COMPLETE? > + > printf("Driver\tDevice(s)\n"); > printf("--------------------\n"); > for_each_driver(drv) { > + if (filter && !str_has_prefix(drv->name, filter)) > + continue; I don't see how this is expected to work. When you pass multiple drivers as argument 'filter' will be a concatenation of multiple driver names which then matches nothing. How about using fnmatch? We could then pass things like "*usb*" Sascha > + > printf("%s\n",drv->name); > for_each_device(dev) { > if (dev->driver == drv) > @@ -24,6 +32,7 @@ static int do_drvinfo(int argc, char *argv[]) > if (IS_ENABLED(CONFIG_CMD_DEVINFO)) > printf("\nUse 'devinfo DEVICE' for more information\n"); > > + free(filter); > return 0; > } > > @@ -31,5 +40,9 @@ static int do_drvinfo(int argc, char *argv[]) > BAREBOX_CMD_START(drvinfo) > .cmd = do_drvinfo, > BAREBOX_CMD_DESC("list compiled-in device drivers") > +#ifdef CONFIG_AUTO_COMPLETE > + BAREBOX_CMD_OPTS("[DRIVER]") > +#endif > BAREBOX_CMD_GROUP(CMD_GRP_INFO) > + BAREBOX_CMD_COMPLETE(driver_complete) > BAREBOX_CMD_END > diff --git a/common/complete.c b/common/complete.c > index ab3c98549314..916d13d776ce 100644 > --- a/common/complete.c > +++ b/common/complete.c > @@ -174,6 +174,27 @@ static int device_param_complete(struct device_d *dev, struct string_list *sl, > return 0; > } > > +int driver_complete(struct string_list *sl, char *instr) > +{ > + struct driver_d *drv; > + int len; > + > + if (!instr) > + instr = ""; > + > + len = strlen(instr); > + > + for_each_driver(drv) { > + if (strncmp(instr, drv->name, len)) > + continue; > + > + string_list_add_asprintf(sl, "%s ", drv->name); > + } > + > + return COMPLETE_CONTINUE; > +} > +EXPORT_SYMBOL(driver_complete); > + > int empty_complete(struct string_list *sl, char *instr) > { > return COMPLETE_END; > diff --git a/include/complete.h b/include/complete.h > index b0e675b5599f..2068760ac235 100644 > --- a/include/complete.h > +++ b/include/complete.h > @@ -14,6 +14,7 @@ void complete_reset(void); > > int command_complete(struct string_list *sl, char *instr); > int device_complete(struct string_list *sl, char *instr); > +int driver_complete(struct string_list *sl, char *instr); > int empty_complete(struct string_list *sl, char *instr); > int eth_complete(struct string_list *sl, char *instr); > int command_var_complete(struct string_list *sl, char *instr); > -- > 2.30.2 > > > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |