aboutsummaryrefslogtreecommitdiffhomepage
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
parent90f203bff189706c2dec34482475b89d0a232597 (diff)
downloadsciteco-6bf314fa5193872e26e3eaabe222ee1e2a823c08.tar.gz
goto table cleanup
-rw-r--r--cmdline.cpp2
-rw-r--r--goto.cpp35
-rw-r--r--goto.h5
-rw-r--r--main.cpp2
-rw-r--r--parser.cpp4
-rw-r--r--qbuffers.cpp8
6 files changed, 28 insertions, 28 deletions
diff --git a/cmdline.cpp b/cmdline.cpp
index 9f500a3..d8e71ac 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -136,7 +136,7 @@ process_edit_cmd(gchar key)
interface.ssm(SCI_EMPTYUNDOBUFFER);
undo.clear();
- goto_table->clear();
+ Goto::table->clear();
*cmdline = '\0';
macro_pc = 0;
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;
}
}
diff --git a/goto.h b/goto.h
index b44ffa2..146bade 100644
--- a/goto.h
+++ b/goto.h
@@ -71,7 +71,10 @@ public:
#endif
};
-extern GotoTable *goto_table;
+namespace Goto {
+ extern GotoTable *table;
+ extern gchar *skip_label;
+}
/*
* Command states
diff --git a/main.cpp b/main.cpp
index a1da02d..552b1e0 100644
--- a/main.cpp
+++ b/main.cpp
@@ -136,7 +136,7 @@ main(int argc, char **argv)
}
g_free(mung_file);
- goto_table = &cmdline_goto_table;
+ Goto::table = &cmdline_goto_table;
interface.ssm(SCI_EMPTYUNDOBUFFER);
undo.enabled = true;
diff --git a/parser.cpp b/parser.cpp
index 25c940b..5d41b5e 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -71,7 +71,7 @@ file_execute(const gchar *filename)
macro_pc = 0;
States::current = &States::start;
- goto_table = &file_goto_table;
+ Goto::table = &file_goto_table;
if (!g_file_get_contents(filename, &macro, NULL, NULL))
return false;
@@ -89,7 +89,7 @@ file_execute(const gchar *filename)
macro_pc = 0;
States::current = &States::start;
- goto_table = NULL;
+ Goto::table = NULL;
return true;
}
diff --git a/qbuffers.cpp b/qbuffers.cpp
index 26e4599..3c11ab0 100644
--- a/qbuffers.cpp
+++ b/qbuffers.cpp
@@ -143,7 +143,7 @@ QRegister::undo_edit(void)
void
QRegister::execute(void) throw (State::Error)
{
- GotoTable *parent_goto_table = goto_table;
+ GotoTable *parent_goto_table = Goto::table;
GotoTable macro_goto_table;
State *parent_state = States::current;
@@ -160,7 +160,7 @@ QRegister::execute(void) throw (State::Error)
macro_pc = 0;
str = get_string();
- goto_table = &macro_goto_table;
+ Goto::table = &macro_goto_table;
try {
macro_execute(str);
@@ -168,14 +168,14 @@ QRegister::execute(void) throw (State::Error)
g_free(str);
macro_pc = parent_pc;
States::current = parent_state;
- goto_table = parent_goto_table;
+ Goto::table = parent_goto_table;
throw; /* forward */
}
g_free(str);
macro_pc = parent_pc;
States::current = parent_state;
- goto_table = parent_goto_table;
+ Goto::table = parent_goto_table;
}
bool