From nobody Thu Sep 01 17:11:19 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MJSHr00bkz4b0Xq; Thu, 1 Sep 2022 17:11:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MJSHq6crrz3VHx; Thu, 1 Sep 2022 17:11:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662052279; h=from:from: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; bh=k3d0T+TPjllETzdMB00/RijyvZLkI3URCrJttBmabio=; b=DGKNgf2DQ/psocJD8Icyhgx7oUqU+kdYG8bVtGVcgWK+DIQNy+Vk5b5PcS19ifXrP/LFPr FXmKPYeJx6azPbMwUkUj/jNr+kxxJImhL/f7mj72ZmthBYyI4Xrod6GrLRqium3+1lcKrq 2n0rpGXINbldgDdqXR4ifrm8P9fVoYhS1S2QcMLFs5QE0T3QzrVCtXLNYb5XnTSbBrE/dZ cAZOB6d2+Ui1042pn74tcRfXFmhBq5yzDI1y/XyUWvbdzwfL8sazQil5Lv8vWEPOkyF3MY zzqQpTS5B7xUUS/KjhUDEFCc0ggUHE4BCKN0p4wHp/IWuvPP1W3PEAOBYxHdiw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MJSHq5hPtzXW3; Thu, 1 Sep 2022 17:11:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 281HBJaY002592; Thu, 1 Sep 2022 17:11:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 281HBJmL002591; Thu, 1 Sep 2022 17:11:19 GMT (envelope-from git) Date: Thu, 1 Sep 2022 17:11:19 GMT Message-Id: <202209011711.281HBJmL002591@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 113dfadd5c8c - main - stand: separate the command lookup from the command execution List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 113dfadd5c8c2b8a566bf4d0e969e1dff62c9e2f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662052279; h=from:from: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; bh=k3d0T+TPjllETzdMB00/RijyvZLkI3URCrJttBmabio=; b=USZUkcsHBPQtDdW1j0xMEMxsqBOts+DYk2dCt//09TEz5FbVdD5Cxyyr9MaN1vYLW2KRKT E+/6fPVEJcqy4Doui+sDQoVvSNnEDtJPAREN4QQWbsR+4AgfrKWLdU5Kxz6MR7RPnDHJcO fKIVuGLFbl3C0MESGRVedxVh4dy+18ML3GwXskJ2CPMWXQ7KUgowCONy34KtqkGnUUu5qD PyJak2+qy5Ousp9hUDaO6tJBuw26zpF+RR8DPpGmxwP4gf520i5jrxWKO/h0Wh1o0R7cF2 U6eKMyK2x/7pwFrZA7dlnXj1jxszerGMSnlJlKUTK0uJDS6PaKgDFBSMyXTOaw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1662052279; a=rsa-sha256; cv=none; b=VNkwGCcRfGZ2IJr0Hk5G6T1txIqcLHrbRauaonmvQwjPP+/vo1is9RY5RZutAhUMsLg7Ll X9MamiHVk9KdlstogCiHUY/y4+UIV/i1CMth8LDDPAhu4O0ClwP66/sl2U7zQV6sxPHWh1 Tz7GKgg/W9P3otxTSnoqJMf+ZgJbEbV/uGI+01SOmQoek128+/rI70qLx9nwWV+3w7n2gh yRJkgcLIDQn1g2+psq0QBb1z9BXk5McnZEcZiocu4e2B3zv0p9eIx9D6YPsCdy4rTYxX0C Z+016Vw5kf6+Xr2MrfyoLUKVraBMvGJcrE24GO3GFVUfjTgl1EruIZF17zqo5w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=113dfadd5c8c2b8a566bf4d0e969e1dff62c9e2f commit 113dfadd5c8c2b8a566bf4d0e969e1dff62c9e2f Author: Warner Losh AuthorDate: 2022-09-01 17:05:42 +0000 Commit: Warner Losh CommitDate: 2022-09-01 17:08:16 +0000 stand: separate the command lookup from the command execution Factor out interp_lookup_cmd to search for a command from interp_builtin_cmd. This simplifies the latter and can be used to expand lua to ask if a command exists. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D36363 --- stand/common/interp.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/stand/common/interp.c b/stand/common/interp.c index de5ea55eab41..227e7ad91e29 100644 --- a/stand/common/interp.c +++ b/stand/common/interp.c @@ -152,6 +152,19 @@ interp_emit_prompt(void) free(pr); } +static struct bootblk_command * +interp_lookup_cmd(const char *cmd) +{ + struct bootblk_command **cmdp; + + /* search the command set for the command */ + SET_FOREACH(cmdp, Xcommand_set) { + if (((*cmdp)->c_name != NULL) && !strcmp(cmd, (*cmdp)->c_name)) + return (*cmdp); + } + return (NULL); +} + /* * Perform a builtin command */ @@ -159,27 +172,21 @@ int interp_builtin_cmd(int argc, char *argv[]) { int result; - struct bootblk_command **cmdp; - bootblk_cmd_t *cmd; + struct bootblk_command *cmd; if (argc < 1) - return(CMD_OK); + return (CMD_OK); /* set return defaults; a successful command will override these */ command_errmsg = command_errbuf; strcpy(command_errbuf, "no error message"); - cmd = NULL; result = CMD_ERROR; - /* search the command set for the command */ - SET_FOREACH(cmdp, Xcommand_set) { - if (((*cmdp)->c_name != NULL) && !strcmp(argv[0], (*cmdp)->c_name)) - cmd = (*cmdp)->c_fn; - } - if (cmd != NULL) { - result = (cmd)(argc, argv); + cmd = interp_lookup_cmd(argv[0]); + if (cmd != NULL && cmd->c_fn) { + result = cmd->c_fn(argc, argv); } else { command_errmsg = "unknown command"; } - return(result); + return (result); }