From e6d7baf883ef3e75a9e5bd616a59df9405f63872 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 11 Nov 2012 07:49:06 +0100 Subject: added O...$ GOTO command --- goto.cpp | 33 ++++++++++++++++++++++++++++++++- goto.h | 8 +++++++- parser.cpp | 1 + 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/goto.cpp b/goto.cpp index ddbc69f..01786f1 100644 --- a/goto.cpp +++ b/goto.cpp @@ -4,13 +4,15 @@ #include #include "sciteco.h" +#include "expressions.h" #include "parser.h" #include "undo.h" #include "rbtree.h" #include "goto.h" namespace States { - StateLabel label; + StateLabel label; + StateGotoCmd gotocmd; } static gchar *skip_label = NULL; @@ -199,3 +201,32 @@ StateLabel::custom(gchar chr) return this; } + +State * +StateGotoCmd::done(const gchar *str) +{ + gint64 value; + gchar **labels; + + BEGIN_EXEC(&States::start); + + value = expressions.pop_num_calc(); + labels = g_strsplit(str, ",", -1); + + if (value > 0 && value <= g_strv_length(labels) && *labels[value-1]) { + gint pc = table.find(labels[value-1]); + + if (pc >= 0) { + macro_pc = pc; + } else { + /* skip till label is defined */ + undo.push_str(skip_label); + skip_label = g_strdup(labels[value-1]); + undo.push_var(mode); + mode = MODE_PARSE_ONLY; + } + } + + g_strfreev(labels); + return &States::start; +} diff --git a/goto.h b/goto.h index b2faecd..84157b1 100644 --- a/goto.h +++ b/goto.h @@ -18,8 +18,14 @@ private: State *custom(gchar chr); }; +class StateGotoCmd : public StateExpectString { +private: + State *done(const gchar *str); +}; + namespace States { - extern StateLabel label; + extern StateLabel label; + extern StateGotoCmd gotocmd; } void goto_table_clear(void); diff --git a/parser.cpp b/parser.cpp index 5591db5..8ae51f3 100644 --- a/parser.cpp +++ b/parser.cpp @@ -200,6 +200,7 @@ StateStart::StateStart() : State() init(" \f\r\n\v"); transitions['!'] = &States::label; + transitions['O'] = &States::gotocmd; transitions['^'] = &States::control; transitions['F'] = &States::flowcommand; transitions['"'] = &States::condcommand; -- cgit v1.2.3