From owner-svn-src-all@freebsd.org Wed Feb 7 23:27:39 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7C9C7EE3BDC; Wed, 7 Feb 2018 23:27:39 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 20B4484B89; Wed, 7 Feb 2018 23:27:39 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1B94E5CB1; Wed, 7 Feb 2018 23:27:39 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w17NRcPd096795; Wed, 7 Feb 2018 23:27:38 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w17NRc5T096792; Wed, 7 Feb 2018 23:27:38 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201802072327.w17NRc5T096792@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Wed, 7 Feb 2018 23:27:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329000 - head/stand/common X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/stand/common X-SVN-Commit-Revision: 329000 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Feb 2018 23:27:39 -0000 Author: imp Date: Wed Feb 7 23:27:38 2018 New Revision: 329000 URL: https://svnweb.freebsd.org/changeset/base/329000 Log: Move simple interpreter 'perform' into interp.c and call it interp_builtin_cmd(). Modified: head/stand/common/bootstrap.h head/stand/common/interp.c head/stand/common/interp_simple.c Modified: head/stand/common/bootstrap.h ============================================================================== --- head/stand/common/bootstrap.h Wed Feb 7 23:27:25 2018 (r328999) +++ head/stand/common/bootstrap.h Wed Feb 7 23:27:38 2018 (r329000) @@ -47,6 +47,8 @@ extern char command_errbuf[COMMAND_ERRBUFSZ]; /* interp.c */ void interact(void); void interp_emit_prompt(void); +int interp_builtin_cmd(int argc, char *argv[]); + /* Called by interp.c for interp_*.c embedded interpreters */ int interp_include(const char *filename); /* Execute commands from filename */ void interp_init(void); /* Initialize interpreater */ Modified: head/stand/common/interp.c ============================================================================== --- head/stand/common/interp.c Wed Feb 7 23:27:25 2018 (r328999) +++ head/stand/common/interp.c Wed Feb 7 23:27:38 2018 (r329000) @@ -139,3 +139,35 @@ interp_emit_prompt(void) putchar(' '); free(pr); } + +/* + * Perform a builtin command + */ +int +interp_builtin_cmd(int argc, char *argv[]) +{ + int result; + struct bootblk_command **cmdp; + bootblk_cmd_t *cmd; + + if (argc < 1) + 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); + } else { + command_errmsg = "unknown command"; + } + return(result); +} Modified: head/stand/common/interp_simple.c ============================================================================== --- head/stand/common/interp_simple.c Wed Feb 7 23:27:25 2018 (r328999) +++ head/stand/common/interp_simple.c Wed Feb 7 23:27:38 2018 (r329000) @@ -35,38 +35,6 @@ __FBSDID("$FreeBSD$"); #include #include "bootstrap.h" -/* - * Perform the command - */ -static int -perform(int argc, char *argv[]) -{ - int result; - struct bootblk_command **cmdp; - bootblk_cmd_t *cmd; - - if (argc < 1) - 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); - } else { - command_errmsg = "unknown command"; - } - return(result); -} - void interp_init(void) { @@ -86,7 +54,7 @@ interp_run(const char *input) return CMD_ERROR; } - if (perform(argc, argv)) { + if (interp_builtin_cmd(argc, argv)) { printf("%s: %s\n", argv[0], command_errmsg); free(argv); return CMD_ERROR; @@ -195,7 +163,7 @@ interp_include(const char *filename) /* Parse the command */ if (!parse(&argc, &argv, sp->text)) { - if ((argc > 0) && (perform(argc, argv) != 0)) { + if ((argc > 0) && (interp_builtin_cmd(argc, argv) != 0)) { /* normal command */ printf("%s: %s\n", argv[0], command_errmsg); if (!(sp->flags & SL_IGNOREERR)) {