From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448061; cv=none; d=zohomail.com; s=zohoarc; b=lmxWTYYW3+3jiOxdyg/zFFCr+j60oIetZ8cYDdPbRTeyOP4sdxEqpE4SJNpIwWjS4vTDK+qk+fbib6NFUIKOS0QvY0orb7AYe7X4WgQNmBdLWcARJPiDQLxVJaGib4AMIn19/y07XodDURC1aqF0s8f8PS686zvlx/A+IdkuXz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448061; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NvFFY94GWKHlZU83kg4dnepogD24tgBCtnMR+Y/hTrA=; b=Ld3RQ8xEghHZfXyaa8pUoHwkXB68gM5RQxosVOOmpNlhah1IBkNJ7nNlPMt/gcKY6YsvKUBunrKn1R7bcxyRatnNAnh6bs7T0wVAwyvvLYZyqSA4IxV6QZiIE9f15KL+1Yg7Swhv1HiWlSd4nLLnvKgx0VweA5g8A7QIeVYl2Mk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612448061663473.35982221912525; Thu, 4 Feb 2021 06:14:21 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-313-KZ3upAA7N_Sz4sbgA3mRxw-1; Thu, 04 Feb 2021 09:14:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0F571C7405; Thu, 4 Feb 2021 14:14:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF75E60C72; Thu, 4 Feb 2021 14:14:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 91F485807D; Thu, 4 Feb 2021 14:14:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDkLh031547 for ; Thu, 4 Feb 2021 09:13:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 313B15D9F4; Thu, 4 Feb 2021 14:13:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6CB25D9EF for ; Thu, 4 Feb 2021 14:13:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448060; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NvFFY94GWKHlZU83kg4dnepogD24tgBCtnMR+Y/hTrA=; b=BSfzNux2BDB81UJ/3+YI6hWK11Bm1Mh6sv2H1/8hfBZkpzkrZKIm61khVnWqp1AVA8oX+9 uo+N6aU85njjj+me3pGqUXL/Jz7xWd8km3GgoCQwBMs97sP7RQZRo9h3tfm8dUnvE9vxtn m0HAtGdfl1zeiXy6hwc7kNqfnTNZXto= X-MC-Unique: KZ3upAA7N_Sz4sbgA3mRxw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 01/12] lib: Substitute some STREQLEN with STRPREFIX Date: Thu, 4 Feb 2021 15:13:26 +0100 Message-Id: <8094c50eb17f6cf0375a0a4d756eb1093484223f.1612447905.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are few cases where STREQLEN() is called like this: STREQLEN(var, string, strlen(string)) which is the same as STRPREFIX(var, string). Use STRPREFIX() because it is more obvious what the check is doing. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- src/libxl/xen_xl.c | 2 +- src/util/vircgroupv2.c | 10 +++++----- tools/vsh.c | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 941832ce4e..69b139354e 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -950,7 +950,7 @@ xenParseXLUSBController(virConfPtr conf, virDomainDefPt= r def) else usbctrl_type =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2; } else { - if (STREQLEN(type, "qusb", 4)) { + if (STRPREFIX(type, "qusb")) { if (usbctrl_version =3D=3D 1) usbctrl_type =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_Q= USB1; else diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 4a239f067a..49acd27714 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -938,7 +938,7 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group, } tmp +=3D strlen(name); =20 - if (STREQLEN(tmp, "max", 3)) { + if (STRPREFIX(tmp, "max")) { *riops =3D 0; } else if (virStrToLong_ui(tmp, &tmp, 10, riops) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1007,7 +1007,7 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group, } tmp +=3D strlen(name); =20 - if (STREQLEN(tmp, "max", 3)) { + if (STRPREFIX(tmp, "max")) { *wiops =3D 0; } else if (virStrToLong_ui(tmp, &tmp, 10, wiops) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1076,7 +1076,7 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group, } tmp +=3D strlen(name); =20 - if (STREQLEN(tmp, "max", 3)) { + if (STRPREFIX(tmp, "max")) { *rbps =3D 0; } else if (virStrToLong_ull(tmp, &tmp, 10, rbps) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1145,7 +1145,7 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group, } tmp +=3D strlen(name); =20 - if (STREQLEN(tmp, "max", 3)) { + if (STRPREFIX(tmp, "max")) { *wbps =3D 0; } else if (virStrToLong_ull(tmp, &tmp, 10, wbps) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1578,7 +1578,7 @@ virCgroupV2GetCpuCfsQuota(virCgroupPtr group, return -1; } =20 - if (STREQLEN(str, "max", 3)) { + if (STRPREFIX(str, "max")) { *cfs_quota =3D VIR_CGROUP_CPU_QUOTA_MAX; return 0; } diff --git a/tools/vsh.c b/tools/vsh.c index 0e2d4955b4..a242619b8a 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2568,7 +2568,6 @@ static char ** vshReadlineCommandGenerator(const char *text) { size_t grp_list_index =3D 0, cmd_list_index =3D 0; - size_t len =3D strlen(text); const char *name; const vshCmdGrp *grp; const vshCmdDef *cmds; @@ -2588,7 +2587,7 @@ vshReadlineCommandGenerator(const char *text) if (cmds[cmd_list_index++].flags & VSH_CMD_FLAG_ALIAS) continue; =20 - if (STREQLEN(name, text, len)) { + if (STRPREFIX(name, text)) { if (VIR_REALLOC_N(ret, ret_size + 2) < 0) { g_strfreev(ret); return NULL; --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448104; cv=none; d=zohomail.com; s=zohoarc; b=YYyI7j6LPSp3QM9yKvCxr+/4SN0KrbSAEplfpmmWCwNDoszU8Mek1qy8zyftyYcCC56qs4A1nsU5TiVXoGhYKPsOiF/LyqkjdnGtLe7HcnTnNZvROE5RDdKQFIzIKhAdLDMxfMBAZ5luABvZhMnVFmYd7rchD6LSA4p30bv0G44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448104; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=t7iGwdFZR9VPgGQLfCu4hXDcTyPU5aFFRz/VZAl7J98=; b=UW+S1lLqpUQ3mmHHt7t+5zi6Bu8vBiDgeIupgTsC4Lg6QM9wRPcRZi7N68Jkx3j3P4AZ83vlPLGQVpb8bavjKG41QOVhI2MY0gGS/gr9qr5NaaBoIx2vIhRz/Mb/qSAVBOocSjQL0ijVO/hr6lkTpR77Os1LVTmgQLgfGWmWZZo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612448104874776.293916249798; Thu, 4 Feb 2021 06:15:04 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-8Yes8C6yMBuT9fylP-dP0Q-1; Thu, 04 Feb 2021 09:14:21 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6034801969; Thu, 4 Feb 2021 14:14:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A22C1722EF; Thu, 4 Feb 2021 14:14:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 607955807B; Thu, 4 Feb 2021 14:14:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDl2w031553 for ; Thu, 4 Feb 2021 09:13:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0DAF05D9F6; Thu, 4 Feb 2021 14:13:47 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 838655D9EF for ; Thu, 4 Feb 2021 14:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448103; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=t7iGwdFZR9VPgGQLfCu4hXDcTyPU5aFFRz/VZAl7J98=; b=djpxVAIiQMYSDNDdAv+NeetrhEcCYdQpEtT2W2vrEzcWciStChYHaDRc6Yk7ybMCydsUse 87dVZuuIS5SRENc5XwaM/g5TICQW97pJv9zB8Ky5ruoCMtOXaIIHbjRF60t0BueDj1wqZB 76ps4PEGvdQWT89WezqFIeI7nFMIuHE= X-MC-Unique: 8Yes8C6yMBuT9fylP-dP0Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 02/12] vsh: Don't put VSH_OT_ALIAS onto list of completions Date: Thu, 4 Feb 2021 15:13:27 +0100 Message-Id: <7e8f2d3d0e21c5e440e28c8a6c5cc133747feabb.1612447905.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We've invented VSH_OT_ALIAS type for --option so that we can rewrite some --options (e.g. fix spelling). For instance blkdeviotune command uses this feature heavily: --options-with-dash are preferred over old --options_with_underscore. Both versions are supported but only the new ones (not aliased) are documented and reported in --help. Except for options completer, which happily put also aliased versions in front of user's eyes. Note, there is a second (gross) way we use aliases: to rewrite options from --oldoption to --newoption=3Dvalue (for instance --shareable option of attach-disk is an alias of --mode=3Dshareable). And just like with the previous group - don't generate them into the list of possible options. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index a242619b8a..cc777bee12 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2614,7 +2614,6 @@ vshReadlineOptionsGenerator(const char *text, { size_t list_index =3D 0; size_t len =3D strlen(text); - const char *name; size_t ret_size =3D 0; char **ret =3D NULL; =20 @@ -2624,12 +2623,15 @@ vshReadlineOptionsGenerator(const char *text, if (!cmd->opts) return NULL; =20 - while ((name =3D cmd->opts[list_index].name)) { + for (list_index =3D 0; cmd->opts[list_index].name; list_index++) { + const char *name =3D cmd->opts[list_index].name; bool exists =3D false; vshCmdOpt *opt =3D last->opts; size_t name_len; =20 - list_index++; + /* Skip aliases, we do not report them in help output either. */ + if (cmd->opts[list_index].type =3D=3D VSH_OT_ALIAS) + continue; =20 if (len > 2) { /* provide auto-complete only when the text starts with -- */ --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448053; cv=none; d=zohomail.com; s=zohoarc; b=ZxcRF3CcZPSDTlV52z2tAD0PTPmbjoRgehFiR/TCKDBz3RKH+xdhud7psEzYLcUvYiPgQ/sLUT6yCVUDd+zNj9nAnBTisHh494/Xe/pidUzUcYE9Fg2702N0ETSVxuMJuJiebh7uZgR/gRB+Gf7SXYg3wAYS9cNgs6V+W+gSVJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448053; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yrNSz8Vh2ADLSKZLV9UsooStVUxtWOIQhVU+osjhb6k=; b=CnnMSeEb1luCH0KWJxFIjeGxLeSdRZXH8zoj/GRvh7dOC/HOio51N9EaWyguuRJTm8nL3GoSSqFhQyuJE4vGynNFkHqqg3VZjDiXo9Q3QR8EyQXKojMRgw36L6VwLqrARsrsXQCxGobLxXjla3EgX1v/IuWpC+EhsHtOIBVo6DU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612448053063988.4148662500165; Thu, 4 Feb 2021 06:14:13 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-jSk4KBs6P4G8X9u4U-32MA-1; Thu, 04 Feb 2021 09:14:02 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C490835E2F; Thu, 4 Feb 2021 14:13:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 745615D9EF; Thu, 4 Feb 2021 14:13:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D5CFA18095CB; Thu, 4 Feb 2021 14:13:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDpxO031588 for ; Thu, 4 Feb 2021 09:13:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 162CA5D9EF; Thu, 4 Feb 2021 14:13:51 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C32F5D9C9 for ; Thu, 4 Feb 2021 14:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448046; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=yrNSz8Vh2ADLSKZLV9UsooStVUxtWOIQhVU+osjhb6k=; b=UUwN59v2VQj0w5m8XN5aQ4tH8rQgWK3YK+x7KCMVhPNytI5p1u5BfJEDFir1A3/WUJrkAL BtrIFi1ryo5pfY0Nuh824tkxkaXdbdUBI+CHbKV/pMOXngHjksyDNoRiI+JDXSPV1FWey8 boY+26lpoZuP2MDmguJDo+0MTDGVeVo= X-MC-Unique: jSk4KBs6P4G8X9u4U-32MA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 03/12] vsh: Use g_auto(GStrv) to free string list returned by completer callback Date: Thu, 4 Feb 2021 15:13:28 +0100 Message-Id: <1aeefc3b76c57c447569e6bfc304782e0b8d05e3.1612447905.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This saves us explicit call of g_strfreev() in error path. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index cc777bee12..3cb657f582 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2778,9 +2778,9 @@ vshReadlineParse(const char *text, int state) list =3D vshReadlineOptionsGenerator(text, cmd, partial); =20 if (opt && opt->completer) { - char **completer_list =3D opt->completer(autoCompleteOpaqu= e, - partial, - opt->completer_flag= s); + g_auto(GStrv) completer_list =3D opt->completer(autoComple= teOpaque, + partial, + opt->complet= er_flags); =20 /* Escape completions, if needed (i.e. argument * we are completing wasn't started with a quote @@ -2805,7 +2805,6 @@ vshReadlineParse(const char *text, int state) if (completer_list && (vshCompleterFilter(&completer_list, text) < 0 || virStringListMerge(&list, &completer_list) < 0)) { - g_strfreev(completer_list); goto cleanup; } } --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448061; cv=none; d=zohomail.com; s=zohoarc; b=JknEroHplHm8Nb0d9oTMPAldVJxhSpVTPc2vikPSFv1rkuwLLWmZbYj6NQcC2356x/5wQjyOCeZE7AE4yvfbUzOo5F+/OELyR3tml1kuuzMI6+EKGuBFPLU8K5DPldwhZrqL07qVu7qA9DSwS9GL420ciuqGrqVE+hju4fwL4/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448061; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UcEZyUaB0mqRgwKjsa/BisM+lA6z9EwyX/cjNIdiRwM=; b=XfodGFpYJ+W61hHb48y7CzSH/A/o1tnFezOKU84k91E+dFYWSuOtTwrUih+WZCsaSj9+wpMflaajZFo1CrOu3xFbK3kb3SH97AfOXyO8r1npRkLEDYwd12R6wjP5VHVbKoisJDQ7DHkTxdu3B6SlgdI1dz6o6+5pCLCONknDrvA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 16124480618371007.0127303458943; Thu, 4 Feb 2021 06:14:21 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-220-_D4EGT_kM-eSXokAsYtKbw-1; Thu, 04 Feb 2021 09:14:16 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E3856107ACC7; Thu, 4 Feb 2021 14:14:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BFB932BFE2; Thu, 4 Feb 2021 14:14:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 87FA318089CC; Thu, 4 Feb 2021 14:14:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDphT031604 for ; Thu, 4 Feb 2021 09:13:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id E63375D9EF; Thu, 4 Feb 2021 14:13:51 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 681525D9C9 for ; Thu, 4 Feb 2021 14:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448058; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UcEZyUaB0mqRgwKjsa/BisM+lA6z9EwyX/cjNIdiRwM=; b=XyLzXvmca5fm+87kV4sRQrf/oIIKVfshusPFmyaLvO9/pmT9v4S1Iedcd86Q5RtHU6FCps HJm+6tY7f+o1hqbZzWFjWTvkZkneORh4WgwJSWvXPqXhuXk0svy9LzPpRz8S/mHQZ0Q3Rm UQJlAOnVdxomGnhvNsnydqnhgCVTsD8= X-MC-Unique: _D4EGT_kM-eSXokAsYtKbw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 04/12] vsh: Accept NULL @list in vshCompleterFilter() Date: Thu, 4 Feb 2021 15:13:29 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The aim of vshCompleterFilter() is to take a string list and a prefix and remove all strings from the list that don't have the desired prefix. The function is used to filter out those strings returned by a completer callback that don't correspond with user's (partial) input. For instance, domain name completer virshDomainNameCompleter() returns all domain names and then vshCompleterFilter() refines the list so that only domains with correct prefix of their name are offered to user. This was a design choice - it allows us to have shorter completers as they do not have to copy the list filtering over and over. Having said all of that, it may happen that a completer does not return anything (e.g. there is no domain in requested state, virsh is not connected and thus completer exited early, etc.). In that case, the string list is NULL and vshCompleterFilter() can simply return early. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 3cb657f582..13bf525acc 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2703,7 +2703,7 @@ vshCompleterFilter(char ***list, size_t i; =20 if (!list || !*list) - return -1; + return 0; =20 list_len =3D virStringListLength((const char **) *list); newList =3D g_new0(char *, list_len + 1); @@ -2802,9 +2802,8 @@ vshReadlineParse(const char *text, int state) /* For string list returned by completer we have to do * filtering based on @text because completer returns all * possible strings. */ - if (completer_list && - (vshCompleterFilter(&completer_list, text) < 0 || - virStringListMerge(&list, &completer_list) < 0)) { + if (vshCompleterFilter(&completer_list, text) < 0 || + virStringListMerge(&list, &completer_list) < 0) { goto cleanup; } } --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448069; cv=none; d=zohomail.com; s=zohoarc; b=WislEQ2GTC2d8GZDk+W6xvy7dWPwF0dRwJJ86KplEDy0oMbYZpRigea3kszj8rrZu6NZywTYjATodPyYDqKn3+a0RwRc6rbmmeKVk5BMZ0+O/wLesKpieeMFXg8xIAx8n9uUIBqnOYKyBeq7zHu/T9ZdT7j8yy2vlhcz8Ul5EN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448069; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2YSbMLFJuCjUb5TpR4eVX7JYM3Bz6WTc7GJfPGhblrk=; b=NS+O55QWVk/Hm8EC2Gg/nXq1jhi6Y913tci7S1ii/Ry7EP7fvWfzAbNktqy9A7XfgzNgwivbPutRQaULNoZcTgG/gDf0atio/8LPgKGpBkbpBhbSBafv3zIz+wY6f3Qs5rC04lzmp5ZybVu/9DObdMjlNRyB6/+UxyDB/IYQvs0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612448069523892.6844655630788; Thu, 4 Feb 2021 06:14:29 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-331-6o7Z-VNSNYeqNvjGsSkXyg-1; Thu, 04 Feb 2021 09:14:25 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5ADEC7400; Thu, 4 Feb 2021 14:14:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0C3A6F992; Thu, 4 Feb 2021 14:14:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 691FE5807B; Thu, 4 Feb 2021 14:14:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDqYh031613 for ; Thu, 4 Feb 2021 09:13:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id C315E5D9EF; Thu, 4 Feb 2021 14:13:52 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44BC35D9C9 for ; Thu, 4 Feb 2021 14:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448067; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=2YSbMLFJuCjUb5TpR4eVX7JYM3Bz6WTc7GJfPGhblrk=; b=CuqfjTSBpdfS4b166wsZuq3iGB5M+nvT61GluVyhdSEsJ9mIJODEblYojlLaIsZY8liR3j aLZUltACGuWGS+YXhDbAdMrOEuRHpBDryw4RbKlneFEndmVTIC5BoVJQ3meJPG5rvp5RnU +gF/c7osvHRPJDy76oN2GVEm/Az3qEY= X-MC-Unique: 6o7Z-VNSNYeqNvjGsSkXyg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 05/12] vsh: Prefer g_strdup_printf() over g_snprintf() in vshReadlineOptionsGenerator() Date: Thu, 4 Feb 2021 15:13:30 +0100 Message-Id: <1c840bb82dd187cb02b4e830a31de03f5a8303d5.1612447905.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The vshReadlineOptionsGenerator() function returns a string list of all --options for given command. But the way that individual items on the list are allocated can be written better. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 13bf525acc..d7ab7c61db 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2627,7 +2627,6 @@ vshReadlineOptionsGenerator(const char *text, const char *name =3D cmd->opts[list_index].name; bool exists =3D false; vshCmdOpt *opt =3D last->opts; - size_t name_len; =20 /* Skip aliases, we do not report them in help output either. */ if (cmd->opts[list_index].type =3D=3D VSH_OT_ALIAS) @@ -2660,9 +2659,7 @@ vshReadlineOptionsGenerator(const char *text, return NULL; } =20 - name_len =3D strlen(name); - ret[ret_size] =3D g_new0(char, name_len + 3); - g_snprintf(ret[ret_size], name_len + 3, "--%s", name); + ret[ret_size] =3D g_strdup_printf("--%s", name); ret_size++; /* Terminate the string list properly. */ ret[ret_size] =3D NULL; --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448083; cv=none; d=zohomail.com; s=zohoarc; b=MaMga1c08NnV9Kg3BhsqKeaqxVjvqpSdG1p1F57GNwWlV+5Uk/oY1h9b9V/n91r0Nw4f436ZxxTvnQTR5mGWKt4Dvw/qwFoOEInXmkMCTU50zKDblTT1UJrYfrdNYC1MRqg+7FIDpSfdQuNvLhrwhlyggTo+H67ImEsbVHQ4FeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448083; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eOTwHmJVbXtjjbicSIzPaIjXhadTzO9lv3039kZNjYM=; b=GbW3S+hvwDF7dXTPNCpcOaVyy9uQLw3S85NUpPuyUVTNHcAfKAzDPUcN/AL2DMSwAQ85nPelGCL82pzjjqU3QG6AjyFT5tciyibvHg3KjNiE3H/r5ESO0vfwttXWi9KC+wiNf4ZNkUn3UiIKEYB3cMtLIlxdT90abp2n8Xk/nKU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612448083183266.1030395546186; Thu, 4 Feb 2021 06:14:43 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-43-VQ0zNF7uM8eMAX68PdSFkw-1; Thu, 04 Feb 2021 09:14:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4DB80107ACFC; Thu, 4 Feb 2021 14:13:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0EE51971C; Thu, 4 Feb 2021 14:13:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7DBF01809C8F; Thu, 4 Feb 2021 14:13:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDrGe031618 for ; Thu, 4 Feb 2021 09:13:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9EDF35D9EF; Thu, 4 Feb 2021 14:13:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20F8D5D9C9 for ; Thu, 4 Feb 2021 14:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448045; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=eOTwHmJVbXtjjbicSIzPaIjXhadTzO9lv3039kZNjYM=; b=eGs9pg5pY03/ws2029h7gA9XH5pQi2rWFaFnaBhdHJ/1QlcO968S9+VANMAjJPaYmpwfk8 Gl7WBBX7Wpp2IcrEcGZnT7jg9WdpzafxnIZ6YWc8dVIHqnXCeEJWr8tTdW2aIAZyAWhLjO q+M2tyENtoitzFuu9JoPp+YrU2uPjQw= X-MC-Unique: VQ0zNF7uM8eMAX68PdSFkw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 06/12] vsh: Use g_auto() for string lists returned in readline command/options generators Date: Thu, 4 Feb 2021 15:13:31 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are two functions that are used to generate completion lists: vshReadlineCommandGenerator() for command names and vshReadlineOptionsGenerator() for --options for given command. Both return a string list, but may also fail while constructing it. For that case, they call g_strfreev() explicitly, which is needless since we have g_auto(GStrv). Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index d7ab7c61db..70b7e3e285 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2572,7 +2572,7 @@ vshReadlineCommandGenerator(const char *text) const vshCmdGrp *grp; const vshCmdDef *cmds; size_t ret_size =3D 0; - char **ret =3D NULL; + g_auto(GStrv) ret =3D NULL; =20 grp =3D cmdGroups; =20 @@ -2588,10 +2588,9 @@ vshReadlineCommandGenerator(const char *text) continue; =20 if (STRPREFIX(name, text)) { - if (VIR_REALLOC_N(ret, ret_size + 2) < 0) { - g_strfreev(ret); + if (VIR_REALLOC_N(ret, ret_size + 2) < 0) return NULL; - } + ret[ret_size] =3D g_strdup(name); ret_size++; /* Terminate the string list properly. */ @@ -2604,7 +2603,7 @@ vshReadlineCommandGenerator(const char *text) } } =20 - return ret; + return g_steal_pointer(&ret); } =20 static char ** @@ -2615,7 +2614,7 @@ vshReadlineOptionsGenerator(const char *text, size_t list_index =3D 0; size_t len =3D strlen(text); size_t ret_size =3D 0; - char **ret =3D NULL; + g_auto(GStrv) ret =3D NULL; =20 if (!cmd) return NULL; @@ -2654,10 +2653,8 @@ vshReadlineOptionsGenerator(const char *text, if (exists) continue; =20 - if (VIR_REALLOC_N(ret, ret_size + 2) < 0) { - g_strfreev(ret); + if (VIR_REALLOC_N(ret, ret_size + 2) < 0) return NULL; - } =20 ret[ret_size] =3D g_strdup_printf("--%s", name); ret_size++; @@ -2665,7 +2662,7 @@ vshReadlineOptionsGenerator(const char *text, ret[ret_size] =3D NULL; } =20 - return ret; + return g_steal_pointer(&ret); } =20 =20 --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448066; cv=none; d=zohomail.com; s=zohoarc; b=lW5MeIZuu2of3nkFiQzNkiD7CjPFh6G1vZb0KPDN79vJVgdlx1bMoVZrMYDgDpkjzYbzDxZDBg4E57+tYVneGI1GiytbJgvOrmj0Q7sjkIw0OxVxCunFsvEfVoE7D+itZaVDboBzprsLp3g+NRdBot15DPWap6KLf4PV0yILliI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448066; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nNOAD0tYG0MSKb/hKTgPEhqoV+z3lmnJe9KcjkRSoJs=; b=FZc5P2SAKyaA6Ndnc4F1cPbjRmjvM22JpJii+Rra1d6YCv7LC0GpGHF7SWaLzrhOZPa+cGvc3qMu64lNcRD0Aw0Z5KQzQXtk8r7EYMXL9dEu7rwC8uKQ3DSf202zQAA6kKZaAjst7Sao8RS413Y7HYPc7rBMWJSCbKwvGAWEzvI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 161244806631820.081360364427383; Thu, 4 Feb 2021 06:14:26 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-_PXQRZj7MPqQQq4JDVqXJQ-1; Thu, 04 Feb 2021 09:14:21 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C3337835E27; Thu, 4 Feb 2021 14:14:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A1D8760C76; Thu, 4 Feb 2021 14:14:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 66FC31809C92; Thu, 4 Feb 2021 14:14:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDsL4031624 for ; Thu, 4 Feb 2021 09:13:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7A94D5D9F4; Thu, 4 Feb 2021 14:13:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id F09D45D9C9 for ; Thu, 4 Feb 2021 14:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448064; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=nNOAD0tYG0MSKb/hKTgPEhqoV+z3lmnJe9KcjkRSoJs=; b=Ci3bX2eRUSpGfLl7276QZUsesbciazQS8Mlz09/OXr+yevCQNh320qIIP85Ad1IygsqiS9 zKK6haA7EN1nCbxYOgRxq9LwKe6o9n3p0Gq5lOBuqP5ZQcAPKNb+8aQT4RForUh6NheCMx KXnYeul4OMTGuXmajlfecdPk2COazlo= X-MC-Unique: _PXQRZj7MPqQQq4JDVqXJQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 07/12] vsh: Rewrite opt->type check in vshReadlineParse() Date: Thu, 4 Feb 2021 15:13:32 +0100 Message-Id: <381d2fd560903abda8255359120e8116eb366cc2.1612447905.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The vshReadlineParse() function is called whenever user hits . If there is no command (or a partially written one), then a list of possible commands is printed to the user. But, if there is a command then its --options are generated. But obviously, we can not generate --options if there already is an --option that's expecting a value. For instance, consider: virsh # start --domain In this case we want to call completer for --domain option, but that's a different story. Anyway, the way that we currently check whether --options list should be generated is checking the type of the last --option. If it isn't DATA, STRING, INT, or ARGV (all these expect a value), then we can generate --option list. Well, writing the condition this way is needlessly verbose and also prone to errors (see d9a320bf97 for example). We know that boolean type does not require a value. This leaves us with the only type that was not mentioned yet - VSH_OT_ALIAS. This is a special type for backwards compatibility and it refers to another --option which can be just any type. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 70b7e3e285..f83b2a95a9 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2765,10 +2765,7 @@ vshReadlineParse(const char *text, int state) if (!cmd) { list =3D vshReadlineCommandGenerator(text); } else { - if (!opt || (opt->type !=3D VSH_OT_DATA && - opt->type !=3D VSH_OT_STRING && - opt->type !=3D VSH_OT_INT && - opt->type !=3D VSH_OT_ARGV)) + if (!opt || opt->type =3D=3D VSH_OT_BOOL) list =3D vshReadlineOptionsGenerator(text, cmd, partial); =20 if (opt && opt->completer) { --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448059; cv=none; d=zohomail.com; s=zohoarc; b=JUisul4sofkkucKYyl3Qmxx/Q+oluqOjCpo2sIoZTcP848YPoPxtl06ybAXMANIQB+V1L8OVY/JHI4soo4uusDdWuRcfuO3tOkdK9OpCHdrNSgjtD53rlXDiN0c8XXgWvLQoKNtcMuY4nLyneqXxFCYrOuAJRo9R4Mrmf0yMfpg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448059; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NGIeulsjD50W9eZEXxbj0KeaQU3cVyazaUM0PcE3/sk=; b=Mjex7D6hSGgpCfy1BHx8hWGaQip2S5yRr2MNgCTw1PkgEG7yg9MXUd7hVm+gWoxOzWmt9W+dCTPgOI5Pv7cbozvkpXdsIq0OlraENn6NyYfIiWaDV2/7VtcLzYad+zzwte2UeJ3VKkePDzcJUQn1QIZKQ5IzkjMHw46HJH5mdMk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612448059836337.8118417999067; Thu, 4 Feb 2021 06:14:19 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-5-K6YC92hoNWiua89bTBmGnw-1; Thu, 04 Feb 2021 09:14:16 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8184E801968; Thu, 4 Feb 2021 14:14:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B287E150; Thu, 4 Feb 2021 14:14:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E427E58076; Thu, 4 Feb 2021 14:14:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDtlI031629 for ; Thu, 4 Feb 2021 09:13:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 565745D9F4; Thu, 4 Feb 2021 14:13:55 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBF895D9C9 for ; Thu, 4 Feb 2021 14:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448058; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NGIeulsjD50W9eZEXxbj0KeaQU3cVyazaUM0PcE3/sk=; b=IbMQYxnS2qtb/EVIY4T/85qxzkMlY9TWlDIxe0Rw+JaCZJHMth1dtD4sW6TseP4DFH15+c cusw+Y8eTSh84vq6CgVk17PY3vuDr/FTlKrKzgUalJeNFZ2lvB1C6Kd3lEst9LoOpTx7pf 9X+GyVtNTJrPhFIlaHHuNR0hmbJPg3U= X-MC-Unique: K6YC92hoNWiua89bTBmGnw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 08/12] vsh: Deduplicate filtering in vshReadlineOptionsGenerator() Date: Thu, 4 Feb 2021 15:13:33 +0100 Message-Id: <6cc6ade4d91517c6a6aeb7e5fa7324ef6d2b4aeb.1612447905.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This is what we do for completer callbacks: we let them generate all possible outputs ignoring any partial input (e.g. prefix of a domain name) and then use vshCompleterFilter() to filter out those strings which don't fit the partial input (prefix). The same algorithm is implemented in vshReadlineOptionsGenerator() even though a bit differently. There is no need to have the same code twice. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index f83b2a95a9..5f082f1a35 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2607,12 +2607,11 @@ vshReadlineCommandGenerator(const char *text) } =20 static char ** -vshReadlineOptionsGenerator(const char *text, +vshReadlineOptionsGenerator(const char *text G_GNUC_UNUSED, const vshCmdDef *cmd, vshCmd *last) { size_t list_index =3D 0; - size_t len =3D strlen(text); size_t ret_size =3D 0; g_auto(GStrv) ret =3D NULL; =20 @@ -2631,16 +2630,6 @@ vshReadlineOptionsGenerator(const char *text, if (cmd->opts[list_index].type =3D=3D VSH_OT_ALIAS) continue; =20 - if (len > 2) { - /* provide auto-complete only when the text starts with -- */ - if (STRNEQLEN(text, "--", 2)) - return NULL; - if (STRNEQLEN(name, text + 2, len - 2)) - continue; - } else if (STRNEQLEN(text, "--", len)) { - return NULL; - } - while (opt) { if (STREQ(opt->def->name, name) && opt->def->type !=3D VSH_OT_= ARGV) { exists =3D true; @@ -2790,14 +2779,15 @@ vshReadlineParse(const char *text, int state) } } =20 - /* For string list returned by completer we have to do - * filtering based on @text because completer returns all - * possible strings. */ - if (vshCompleterFilter(&completer_list, text) < 0 || - virStringListMerge(&list, &completer_list) < 0) { + if (virStringListMerge(&list, &completer_list) < 0) goto cleanup; - } } + + /* For string list returned by completers we have to do + * filtering based on @text because completers returns all + * possible strings. */ + if (vshCompleterFilter(&list, text) < 0) + goto cleanup; } } =20 --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448107; cv=none; d=zohomail.com; s=zohoarc; b=XFBBs1XkJSfFc/C83JvWcsHY4nps7Lv/+436UCIb/4CbwB8gfDNAgmMrjUOpTxirDG12J/UuJFJjrdfQo5akDM6p4O7mfZeOwUfsPCSq7uBk5nv4G/cL+BGvo6tYwzlmi2Jwzm3yMRki41d5N07eVKHr0f8/otF4HU4hwbqtzQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448107; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xyRN55/7CFxzAhhDg8AFxO5+2H9hKq2jeJQNtb7FKWY=; b=lHvtskS8eF7Zuk039+E7jbRYDJ94c6wImzBJxfCoSaBHp4raA7luZu22ioYUdg2WPOipiCEq2315Apk+QGrU1CS9GBSevTSBlrfaCBXRFaDM89UDKBrzBrlxhGb55NHyF65+JG3cm2k8AQGBHWNIbWlq9kooqNOB3bl7siHJsZQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612448107884367.7377972930075; Thu, 4 Feb 2021 06:15:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-425-ZbbyttewNyeFMas7rqpULw-1; Thu, 04 Feb 2021 09:14:27 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4C3F107ACE8; Thu, 4 Feb 2021 14:14:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A091671CA4; Thu, 4 Feb 2021 14:14:21 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 684F018095CB; Thu, 4 Feb 2021 14:14:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDur7031643 for ; Thu, 4 Feb 2021 09:13:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 31F945D9F4; Thu, 4 Feb 2021 14:13:56 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id A81D75D9C9 for ; Thu, 4 Feb 2021 14:13:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448106; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xyRN55/7CFxzAhhDg8AFxO5+2H9hKq2jeJQNtb7FKWY=; b=d3Eq48RPpG0RMeXa9D+TZn3ho2cpEuIHXDVLkgec5C4UoFil7kpTufZKt08DX2h9b0bGdk YxkoG3tyFfQQBmj7ar4ev2XeJ/49v3pYVnTQiNIxhikmDy4CBeJ8fXUqLWrJXdq7jJjH5R z+X0Msx5/DrwSE4MSE6fkeDPmZHNS+M= X-MC-Unique: ZbbyttewNyeFMas7rqpULw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 09/12] vsh: Deduplicate filtering in vshReadlineCommandGenerator() Date: Thu, 4 Feb 2021 15:13:34 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This is what we do for completer callbacks: we let them generate all possible outputs ignoring any partial input (e.g. prefix of a domain name) and then use vshCompleterFilter() to filter out those strings which don't fit the partial input (prefix). The same algorithm is implemented in vshReadlineCommandGenerator(). There is no need to have the same code twice. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 5f082f1a35..e0dbda04c8 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2561,11 +2561,10 @@ vshTreePrint(vshControl *ctl, vshTreeLookup lookup,= void *opaque, * * Generator function for command completion. * - * Returns a string list of commands with @text prefix, - * NULL if there's no such command. + * Returns a string list of all commands, or NULL on failure. */ static char ** -vshReadlineCommandGenerator(const char *text) +vshReadlineCommandGenerator(const char *text G_GNUC_UNUSED) { size_t grp_list_index =3D 0, cmd_list_index =3D 0; const char *name; @@ -2587,15 +2586,13 @@ vshReadlineCommandGenerator(const char *text) if (cmds[cmd_list_index++].flags & VSH_CMD_FLAG_ALIAS) continue; =20 - if (STRPREFIX(name, text)) { - if (VIR_REALLOC_N(ret, ret_size + 2) < 0) - return NULL; + if (VIR_REALLOC_N(ret, ret_size + 2) < 0) + return NULL; =20 - ret[ret_size] =3D g_strdup(name); - ret_size++; - /* Terminate the string list properly. */ - ret[ret_size] =3D NULL; - } + ret[ret_size] =3D g_strdup(name); + ret_size++; + /* Terminate the string list properly. */ + ret[ret_size] =3D NULL; } } else { cmd_list_index =3D 0; @@ -2782,13 +2779,13 @@ vshReadlineParse(const char *text, int state) if (virStringListMerge(&list, &completer_list) < 0) goto cleanup; } - - /* For string list returned by completers we have to do - * filtering based on @text because completers returns all - * possible strings. */ - if (vshCompleterFilter(&list, text) < 0) - goto cleanup; } + + /* For string list returned by completers we have to do + * filtering based on @text because completers returns all + * possible strings. */ + if (vshCompleterFilter(&list, text) < 0) + goto cleanup; } =20 if (list) { --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448062; cv=none; d=zohomail.com; s=zohoarc; b=gJ3Rwv/bJ7hyTxlZT4cVhK0g5NamYMgxlAsWKMCzjIT1ZBCLMgqxwtPSMR8wFVwT5dI67vPfBGV7J6WUe/HgUk1PVh8nz1XsMuSS/GSZin+QgKVMgL9FDVTKyrJR408PbvhtixuNUGP15e+WEuZS+r8OE460hHnK2oNohP5jOpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448062; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kg3g3PHPEdZekhhaaZOH1MGQ2meaB2o8CpZ+QKj8wjE=; b=Gp8lmUmaiukExZ2/e06pqMIolIIfrhHu6AFJJTej+32TW860Y08K1H1WPPOCXCkvXDh/1/phy/CsAaUSfhc+AjG+xX7Rdo9RQ2Mmt5/AAqm535ld0F+8oaK7YjqfSBcybOVw+yZxW3CPPC6F3FH+TRnOMdAFNpQmgHBpgF/eM2Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612448062615488.38895668859004; Thu, 4 Feb 2021 06:14:22 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-216-zyPfTVFbNJOAaU2L-0juAg-1; Thu, 04 Feb 2021 09:14:18 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 654ACC7408; Thu, 4 Feb 2021 14:14:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 418FC722E1; Thu, 4 Feb 2021 14:14:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0727B58080; Thu, 4 Feb 2021 14:14:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDv7I031656 for ; Thu, 4 Feb 2021 09:13:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0DF1C5D9EF; Thu, 4 Feb 2021 14:13:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 838BF5D9C9 for ; Thu, 4 Feb 2021 14:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448061; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kg3g3PHPEdZekhhaaZOH1MGQ2meaB2o8CpZ+QKj8wjE=; b=dtdeRAJcR1gtS+bmw4UI/3kJxTM9z+gtQM9X8x3VUV4YkKG6d2u4u0LLZ7SPLkBYCi5drY W+oByjsfvqcJ8PST23WjcbRwGRvehzdS6tbK79EDzjMTUds35XTKHkYr4OmHYJUTucaMXc rmXnZdaTSqxiD60K3dtKKMAXHDQw4g0= X-MC-Unique: zyPfTVFbNJOAaU2L-0juAg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 10/12] vsh: Simplify condition for calling completer callback Date: Thu, 4 Feb 2021 15:13:35 +0100 Message-Id: <7882e140ad65e86cea43a3cfd5d510e56d31e9c6.1612447905.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The way we currently call completer callbacks is that if we've found --option that user wants to complete value for and it has callback set then the callback is called. And just before that, if no --option to have the value completed is found or is found and is of boolean type then a list of --option is generated (for given command). But these two conditions can never be true at the same time because boolean type of --options do not accept values. Therefore the calling of completer callback can be promoted onto the same level as the --option list generation. This means that merging of two lists can be dropped to and completer callback can store its retval directly into @list (but as shown earlier one of the string lists to merge is always empty). Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index e0dbda04c8..0d3c4fd7c7 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2750,34 +2750,28 @@ vshReadlineParse(const char *text, int state) =20 if (!cmd) { list =3D vshReadlineCommandGenerator(text); - } else { - if (!opt || opt->type =3D=3D VSH_OT_BOOL) - list =3D vshReadlineOptionsGenerator(text, cmd, partial); + } else if (!opt || opt->type =3D=3D VSH_OT_BOOL) { + list =3D vshReadlineOptionsGenerator(text, cmd, partial); + } else if (opt && opt->completer) { + list =3D opt->completer(autoCompleteOpaque, + partial, + opt->completer_flags); + } =20 - if (opt && opt->completer) { - g_auto(GStrv) completer_list =3D opt->completer(autoComple= teOpaque, - partial, - opt->complet= er_flags); + /* Escape completions, if needed (i.e. argument + * we are completing wasn't started with a quote + * character). This also enables filtering done + * below to work properly. */ + if (list && + !rl_completion_quote_character) { + size_t i; =20 - /* Escape completions, if needed (i.e. argument - * we are completing wasn't started with a quote - * character). This also enables filtering done - * below to work properly. */ - if (completer_list && - !rl_completion_quote_character) { - size_t i; + for (i =3D 0; list[i]; i++) { + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; =20 - for (i =3D 0; completer_list[i]; i++) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferEscape(&buf, '\\', " ", "%s", completer_l= ist[i]); - VIR_FREE(completer_list[i]); - completer_list[i] =3D virBufferContentAndReset(&bu= f); - } - } - - if (virStringListMerge(&list, &completer_list) < 0) - goto cleanup; + virBufferEscape(&buf, '\\', " ", "%s", list[i]); + VIR_FREE(list[i]); + list[i] =3D virBufferContentAndReset(&buf); } } =20 --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448107; cv=none; d=zohomail.com; s=zohoarc; b=TM42GbT0voCafFhKYFRBnJj1skIG0+qRoIzs/MyaWu3Bq5m/cQZ52mNax1u+1OTqCqRxvQhsu3gvE4k490Zl4OUzFX4p7xQYAMDk6nN3GTwokQkoNnPuLPvgo5pGHYg/Ok9rbK6pBGKFHap9/XmiXd7BwtwOiDrVCEkjpoSJDNU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448107; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bMO8WE2HlAau/twG8tCT/bcRAdcir1ooIF0f9ikZI6M=; b=V0/QOyeEHOmGQjf7DB67L4yWXZyAHpQPVxdKm+R8cz8SYAeHrUQLZnDTbQz0J/Fhl0YYbDRxUVnFXDdhxQc11RH4w5GH2ugemltZDC/o/TGgQpuXZPTOHWMBIOOw4sHbyBWOohxqTu2KwtfShYiYoC1I55TLE1uafdD+kV/fBtM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612448107395308.75301347909965; Thu, 4 Feb 2021 06:15:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-EC22MoTGPRS_ZrLSYyzTCQ-1; Thu, 04 Feb 2021 09:14:31 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 867EF801968; Thu, 4 Feb 2021 14:14:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 62C9F7770F; Thu, 4 Feb 2021 14:14:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 28F9918089CB; Thu, 4 Feb 2021 14:14:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDvub031661 for ; Thu, 4 Feb 2021 09:13:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id DDEEF5D9EF; Thu, 4 Feb 2021 14:13:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FE0A5D9C9 for ; Thu, 4 Feb 2021 14:13:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448105; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bMO8WE2HlAau/twG8tCT/bcRAdcir1ooIF0f9ikZI6M=; b=Pvomft4TYUPOWYLMYFbTegtBa0ufpcIc8P3raLbvOfF/fhMLg3+YN3e8RnPSziCiGVeDXE Rj08NCx2YauXEQmYQgT5cFmbaun5b5ZpfPUwE795H3aZSLnl4Y78z/5fAxvZ8s+dguJej+ G2IasqdDCLCj7DM7WGiOi6aaEsJTICU= X-MC-Unique: EC22MoTGPRS_ZrLSYyzTCQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 11/12] vsh: Rework vshReadlineCommandGenerator() Date: Thu, 4 Feb 2021 15:13:36 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Firstly, move variable declarations into the inner most block they are used. Secondly, use for() loop instead of while so that we don't have to advance loop counter explicitly on 'continue'. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 0d3c4fd7c7..3650b7130a 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2566,37 +2566,30 @@ vshTreePrint(vshControl *ctl, vshTreeLookup lookup,= void *opaque, static char ** vshReadlineCommandGenerator(const char *text G_GNUC_UNUSED) { - size_t grp_list_index =3D 0, cmd_list_index =3D 0; - const char *name; + size_t grp_list_index =3D 0; const vshCmdGrp *grp; - const vshCmdDef *cmds; size_t ret_size =3D 0; g_auto(GStrv) ret =3D NULL; =20 grp =3D cmdGroups; =20 - /* Return the next name which partially matches from the - * command list. - */ - while (grp[grp_list_index].name) { - cmds =3D grp[grp_list_index].commands; + for (grp_list_index =3D 0; grp[grp_list_index].name; grp_list_index++)= { + const vshCmdDef *cmds =3D grp[grp_list_index].commands; + size_t cmd_list_index; =20 - if (cmds[cmd_list_index].name) { - while ((name =3D cmds[cmd_list_index].name)) { - if (cmds[cmd_list_index++].flags & VSH_CMD_FLAG_ALIAS) - continue; + for (cmd_list_index =3D 0; cmds[cmd_list_index].name; cmd_list_ind= ex++) { + const char *name =3D cmds[cmd_list_index].name; =20 - if (VIR_REALLOC_N(ret, ret_size + 2) < 0) - return NULL; + if (cmds[cmd_list_index].flags & VSH_CMD_FLAG_ALIAS) + continue; =20 - ret[ret_size] =3D g_strdup(name); - ret_size++; - /* Terminate the string list properly. */ - ret[ret_size] =3D NULL; - } - } else { - cmd_list_index =3D 0; - grp_list_index++; + if (VIR_REALLOC_N(ret, ret_size + 2) < 0) + return NULL; + + ret[ret_size] =3D g_strdup(name); + ret_size++; + /* Terminate the string list properly. */ + ret[ret_size] =3D NULL; } } =20 --=20 2.26.2 From nobody Sun Apr 28 21:52:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612448078; cv=none; d=zohomail.com; s=zohoarc; b=mU44NWNoiiszfuFj+Iw3dq2WXBqpXTjYRLYcWfqc7kYt76WREqpYU7La9oUMWZfFF833moHaIQr4k/4itS5zpTFbG01qkTiFm9duXpWp7/A3yzUkdxVeVF15wB+9DENeDfAdty9kN6yGoLEb+zmlieVhtR9PZWt7/gFKYPsuCdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448078; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3iUuAfBcQHxJijJ11fmvEg0aN6DBbUwmJFI1yXzlP34=; b=iyK/RA/MdJqxuQULzeduaGyCpHp3Hb24cwnjXlY2Pr0Ydj8Y2oN4ajmA/CeT5oUjooOEofVs+Er65iedXiIerSQSc6TNJLE8NLD26k/2BY8I9IxZvgC4SytApOVHAPoU0LfrvE6MV/d0NST7zYLRQR+O6LOwk9T0wWriUbwQX8I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612448078383267.0973742654435; Thu, 4 Feb 2021 06:14:38 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-155-SMIyT2bdOaWP7JtMXMhUXQ-1; Thu, 04 Feb 2021 09:14:34 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6BEBE100C66F; Thu, 4 Feb 2021 14:14:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4AB0E722EE; Thu, 4 Feb 2021 14:14:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1899D5807D; Thu, 4 Feb 2021 14:14:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EE5VT031699 for ; Thu, 4 Feb 2021 09:14:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 852055DA2E; Thu, 4 Feb 2021 14:14:05 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 059645D9F4 for ; Thu, 4 Feb 2021 14:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448076; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3iUuAfBcQHxJijJ11fmvEg0aN6DBbUwmJFI1yXzlP34=; b=GyYd5TjpfuWPYbUz39pabBelqN/HXBjDgxhCwZI9Q0KZcNa2weoHU+EL1NM4mLTIUMUlxO 7Pz5Dt9xTF8YRaOowUmQl+01Q86R+VGV5aoZAdxmT8kNmW/XUVebNwybbD4dckzbOVdn8J NQG0zaNV+4xDRjGtR5tBzdB9caHqqJw= X-MC-Unique: SMIyT2bdOaWP7JtMXMhUXQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 12/12] vsh: Drop unused @text arg from readline generators Date: Thu, 4 Feb 2021 15:13:37 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" After previous patches neither vshReadlineCommandGenerator() nor vshReadlineOptionsGenerator() use prefix that user wants to complete. The argument is marked as unused in both functions. Drop it then. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- tools/vsh.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 3650b7130a..708e8b6f86 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2557,14 +2557,13 @@ vshTreePrint(vshControl *ctl, vshTreeLookup lookup,= void *opaque, =20 /** * vshReadlineCommandGenerator: - * @text: optional command prefix * * Generator function for command completion. * * Returns a string list of all commands, or NULL on failure. */ static char ** -vshReadlineCommandGenerator(const char *text G_GNUC_UNUSED) +vshReadlineCommandGenerator(void) { size_t grp_list_index =3D 0; const vshCmdGrp *grp; @@ -2597,8 +2596,7 @@ vshReadlineCommandGenerator(const char *text G_GNUC_U= NUSED) } =20 static char ** -vshReadlineOptionsGenerator(const char *text G_GNUC_UNUSED, - const vshCmdDef *cmd, +vshReadlineOptionsGenerator(const vshCmdDef *cmd, vshCmd *last) { size_t list_index =3D 0; @@ -2742,9 +2740,9 @@ vshReadlineParse(const char *text, int state) opt =3D vshReadlineCommandFindOpt(partial); =20 if (!cmd) { - list =3D vshReadlineCommandGenerator(text); + list =3D vshReadlineCommandGenerator(); } else if (!opt || opt->type =3D=3D VSH_OT_BOOL) { - list =3D vshReadlineOptionsGenerator(text, cmd, partial); + list =3D vshReadlineOptionsGenerator(cmd, partial); } else if (opt && opt->completer) { list =3D opt->completer(autoCompleteOpaque, partial, --=20 2.26.2