aboutsummaryrefslogtreecommitdiffhomepage
path: root/goto.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-11-19 22:30:17 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-11-20 06:07:33 +0100
commit6bf314fa5193872e26e3eaabe222ee1e2a823c08 (patch)
tree11791308915b3d2e42ed9db81ff28fd3ed441eee /goto.cpp
parent90f203bff189706c2dec34482475b89d0a232597 (diff)
downloadsciteco-6bf314fa5193872e26e3eaabe222ee1e2a823c08.tar.gz
goto table cleanup
Diffstat (limited to 'goto.cpp')
-rw-r--r--goto.cpp35
1 files changed, 16 insertions, 19 deletions
diff --git a/goto.cpp b/goto.cpp
index 0db7a2b..ab55358 100644
--- a/goto.cpp
+++ b/goto.cpp
@@ -12,9 +12,10 @@ namespace States {
StateGotoCmd gotocmd;
}
-static gchar *skip_label = NULL;
-
-GotoTable *goto_table = NULL;
+namespace Goto {
+ GotoTable *table = NULL;
+ gchar *skip_label = NULL;
+}
gint
GotoTable::remove(gchar *name)
@@ -96,18 +97,16 @@ StateLabel::StateLabel() : State()
State *
StateLabel::custom(gchar chr) throw (Error)
{
- gchar *new_str;
-
if (chr == '!') {
- goto_table->undo_set(strings[0],
- goto_table->set(strings[0], macro_pc));
+ Goto::table->undo_set(strings[0],
+ Goto::table->set(strings[0], macro_pc));
- if (!g_strcmp0(strings[0], skip_label)) {
- undo.push_str(skip_label);
- g_free(skip_label);
- skip_label = NULL;
+ if (!g_strcmp0(strings[0], Goto::skip_label)) {
+ undo.push_str(Goto::skip_label);
+ g_free(Goto::skip_label);
+ Goto::skip_label = NULL;
- undo.push_var<Mode>(mode);
+ undo.push_var(mode);
mode = MODE_NORMAL;
}
@@ -119,9 +118,7 @@ StateLabel::custom(gchar chr) throw (Error)
}
undo.push_str(strings[0]);
- new_str = g_strdup_printf("%s%c", strings[0] ? : "", chr);
- g_free(strings[0]);
- strings[0] = new_str;
+ String::append(strings[0], chr);
return this;
}
@@ -138,15 +135,15 @@ StateGotoCmd::done(const gchar *str) throw (Error)
labels = g_strsplit(str, ",", -1);
if (value > 0 && value <= g_strv_length(labels) && *labels[value-1]) {
- gint pc = goto_table->find(labels[value-1]);
+ gint pc = Goto::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);
+ undo.push_str(Goto::skip_label);
+ Goto::skip_label = g_strdup(labels[value-1]);
+ undo.push_var(mode);
mode = MODE_PARSE_ONLY_GOTO;
}
}