control-c support

This commit is contained in:
Kelvin Sherlock
2016-02-05 13:19:20 -05:00
parent f58f6d4115
commit 0dfecbd520
3 changed files with 51 additions and 3 deletions

View File

@@ -4,6 +4,7 @@
#include "fdset.h"
#include "builtins.h"
#include "mpw-shell.h"
#include "error.h"
#include <stdexcept>
#include <unordered_map>
@@ -16,6 +17,8 @@
#include <sys/wait.h>
#include <sysexits.h>
extern volatile int control_c;
namespace {
std::string &lowercase(std::string &s) {
@@ -121,6 +124,9 @@ command::~command()
*/
int simple_command::execute(Environment &env, const fdmask &fds, bool throwup) {
if (control_c) throw execution_of_input_terminated();
std::string s = expand_vars(text, env);
env.echo("%s", s.c_str());
@@ -160,6 +166,8 @@ int simple_command::execute(Environment &env, const fdmask &fds, bool throwup) {
int evaluate_command::execute(Environment &env, const fdmask &fds, bool throwup) {
if (control_c) throw execution_of_input_terminated();
std::string s = expand_vars(text, env);
env.echo("%s", s.c_str());
@@ -215,6 +223,9 @@ int vector_command::execute(Environment &e, const fdmask &fds, bool throwup) {
}
int error_command::execute(Environment &e, const fdmask &fds, bool throwup) {
if (control_c) throw execution_of_input_terminated();
std::string s = expand_vars(text, e);
e.echo("%s", s.c_str());