Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Feb 2018 23:27:38 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329000 - head/stand/common
Message-ID:  <201802072327.w17NRc5T096792@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <string.h>
 #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)) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802072327.w17NRc5T096792>