From 779bb1654d20af6139f17bdaf9a38bcb75d20965 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 8 Nov 2012 04:39:28 +0100 Subject: EX command --- cmdline.cpp | 8 +++++++- parser.cpp | 23 +++++++++++++++++++++++ parser.h | 9 +++++++++ sciteco.h | 1 + 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/cmdline.cpp b/cmdline.cpp index b9c58a0..152adc5 100644 --- a/cmdline.cpp +++ b/cmdline.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -13,6 +14,8 @@ static gchar *macro_echo(const gchar *macro, const gchar *prefix = ""); gchar *cmdline = NULL; +bool quit_requested = false; + void cmdline_keypress(gchar key) { @@ -73,7 +76,10 @@ process_edit_cmd(gchar key) case '\x1B': if (cmdline && cmdline[cmdline_len - 1] == '\x1B') { - /* TODO: exit if previously requested */ + if (quit_requested) { + /* FIXME */ + exit(EXIT_SUCCESS); + } undo.clear(); goto_table_clear(); diff --git a/parser.cpp b/parser.cpp index df87b32..61e1398 100644 --- a/parser.cpp +++ b/parser.cpp @@ -169,6 +169,7 @@ StateStart::StateStart() : State() transitions['!'] = &states.label; transitions['^'] = &states.control; + transitions['E'] = &states.ecommand; transitions['I'] = &states.insert; } @@ -552,6 +553,28 @@ StateControl::custom(gchar chr) return &states.start; } +StateECommand::StateECommand() : State() +{ + transitions['\0'] = this; +} + +State * +StateECommand::custom(gchar chr) +{ + switch (g_ascii_toupper(chr)) { + case 'X': + BEGIN_EXEC(&states.start); + undo.push_var(quit_requested); + quit_requested = true; + break; + + default: + return NULL; + } + + return &states.start; +} + /* * NOTE: cannot support VideoTECO's I because * beginning and end of strings must be determined diff --git a/parser.h b/parser.h index 2798469..edcece7 100644 --- a/parser.h +++ b/parser.h @@ -76,6 +76,14 @@ private: State *custom(gchar chr); }; +class StateECommand : public State { +public: + StateECommand(); + +private: + State *custom(gchar chr); +}; + class StateInsert : public StateExpectString { private: void initial(void); @@ -91,6 +99,7 @@ extern struct States { StateStart start; StateLabel label; StateControl control; + StateECommand ecommand; StateInsert insert; } states; diff --git a/sciteco.h b/sciteco.h index 88b41cc..e35ce92 100644 --- a/sciteco.h +++ b/sciteco.h @@ -9,6 +9,7 @@ #include extern gchar *cmdline; +extern bool quit_requested; void message_display(GtkMessageType type, const gchar *fmt, ...) G_GNUC_PRINTF(2, 3); -- cgit v1.2.3