From ef122b21cfe7ae124206098d0086eb6337beaef7 Mon Sep 17 00:00:00 2001 From: lum Date: Thu, 25 Mar 2021 17:31:21 +0000 Subject: [PATCH] Add an (exit) method. --- usr.bin/mg/interpreter.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/usr.bin/mg/interpreter.c b/usr.bin/mg/interpreter.c index 713d0a4a434..62bfe66c65a 100644 --- a/usr.bin/mg/interpreter.c +++ b/usr.bin/mg/interpreter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interpreter.c,v 1.15 2021/03/25 16:58:46 lum Exp $ */ +/* $OpenBSD: interpreter.c,v 1.16 2021/03/25 17:31:21 lum Exp $ */ /* * This file is in the public domain. * @@ -71,6 +71,7 @@ static int foundvar(char *); static int doregex(char *, char *); static int parseexp(char *); static void clearexp(void); +static int exitinterpreter(void); TAILQ_HEAD(exphead, expentry) ehead; struct expentry { @@ -296,6 +297,11 @@ parseexp(char *funstr) if (doregex(regs, funstr)) return(dobeep_msg("Invalid use of define")); + /* Exit? */ + regs = "^exit$"; + if (doregex(regs, funstr)) + return(exitinterpreter()); + return(multiarg(funstr)); } @@ -593,3 +599,16 @@ doregex(char *r, char *e) regfree(®ex_buff); return(FALSE); } + +/* + * Display a message so it is apparent that this is the method which stopped + * execution. + */ +static int +exitinterpreter() +{ + cleanup(); + if (batch == 0) + return(dobeep_msg("Interpreter exited via exit command.")); + return(FALSE); +} -- 2.20.1