aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--cmdline.cpp3
-rw-r--r--goto.cpp6
-rw-r--r--goto.h4
-rw-r--r--parser.cpp57
-rw-r--r--parser.h19
-rw-r--r--qbuffers.cpp8
-rw-r--r--qbuffers.h4
7 files changed, 60 insertions, 41 deletions
diff --git a/cmdline.cpp b/cmdline.cpp
index ea8894e..171b2e3 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -7,6 +7,7 @@
#include "sciteco.h"
#include "parser.h"
+#include "qbuffers.h"
#include "goto.h"
#include "undo.h"
@@ -99,7 +100,7 @@ process_edit_cmd(gchar key)
}
case '\t':
- if (current_state == &states.file) {
+ if (States::current == &States::file) {
gchar *new_chars = filename_complete(strings[0], escape_char);
if (new_chars)
g_stpcpy(insert, new_chars);
diff --git a/goto.cpp b/goto.cpp
index a3b3dfa..fd47bcc 100644
--- a/goto.cpp
+++ b/goto.cpp
@@ -8,6 +8,10 @@
#include "undo.h"
#include "goto.h"
+namespace States {
+ StateLabel label;
+}
+
static gchar *skip_label = NULL;
class GotoTable {
@@ -196,7 +200,7 @@ StateLabel::custom(gchar chr)
g_free(strings[0]);
strings[0] = NULL;
- return &states.start;
+ return &States::start;
}
undo.push_str(strings[0]);
diff --git a/goto.h b/goto.h
index cfa5c50..b2faecd 100644
--- a/goto.h
+++ b/goto.h
@@ -18,6 +18,10 @@ private:
State *custom(gchar chr);
};
+namespace States {
+ extern StateLabel label;
+}
+
void goto_table_clear(void);
#endif
diff --git a/parser.cpp b/parser.cpp
index 34d686f..18decd1 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -6,13 +6,20 @@
#include "sciteco.h"
#include "undo.h"
#include "expressions.h"
+#include "goto.h"
+#include "qbuffers.h"
#include "parser.h"
gint macro_pc = 0;
-States states;
+namespace States {
+ StateStart start;
+ StateControl control;
+ StateECommand ecommand;
+ StateInsert insert;
-State *current_state = &states.start;
+ State *current = &start;
+}
namespace Modifiers {
static bool colon = false;
@@ -66,7 +73,7 @@ State::eval_colon(void)
bool
State::input(gchar chr)
{
- State *state = current_state;
+ State *state = States::current;
for (;;) {
State *next = state->get_next_state(chr);
@@ -82,9 +89,9 @@ State::input(gchar chr)
chr = '\0';
}
- if (state != current_state) {
- undo.push_var<State *>(current_state);
- current_state = state;
+ if (state != States::current) {
+ undo.push_var<State *>(States::current);
+ States::current = state;
}
return true;
@@ -166,10 +173,10 @@ StateStart::StateStart() : State()
transitions['\0'] = this;
init(" \f\r\n\v");
- transitions['!'] = &states.label;
- transitions['^'] = &states.control;
- transitions['E'] = &states.ecommand;
- transitions['I'] = &states.insert;
+ transitions['!'] = &States::label;
+ transitions['^'] = &States::control;
+ transitions['E'] = &States::ecommand;
+ transitions['I'] = &States::insert;
}
void
@@ -196,7 +203,7 @@ StateStart::custom(gchar chr)
* <CTRL/x> commands implemented in StateCtrlCmd
*/
if (IS_CTL(chr))
- return states.control.get_next_state(CTL_ECHO(chr));
+ return States::control.get_next_state(CTL_ECHO(chr));
/*
* arithmetics
@@ -492,17 +499,17 @@ StateControl::custom(gchar chr)
{
switch (g_ascii_toupper(chr)) {
case 'O':
- BEGIN_EXEC(&states.start);
+ BEGIN_EXEC(&States::start);
expressions.set_radix(8);
break;
case 'D':
- BEGIN_EXEC(&states.start);
+ BEGIN_EXEC(&States::start);
expressions.set_radix(10);
break;
case 'R':
- BEGIN_EXEC(&states.start);
+ BEGIN_EXEC(&States::start);
expressions.eval();
if (!expressions.args())
expressions.push(expressions.radix);
@@ -514,16 +521,16 @@ StateControl::custom(gchar chr)
* Alternatives: ^i, ^I, <CTRL/I>, <TAB>
*/
case 'I':
- BEGIN_EXEC(&states.insert);
+ BEGIN_EXEC(&States::insert);
expressions.eval();
expressions.push('\t');
- return &states.insert;
+ return &States::insert;
/*
* Alternatives: ^[, <CTRL/[>, <ESC>
*/
case '[':
- BEGIN_EXEC(&states.start);
+ BEGIN_EXEC(&States::start);
expressions.discard_args();
break;
@@ -531,17 +538,17 @@ StateControl::custom(gchar chr)
* Additional numeric operations
*/
case '_':
- BEGIN_EXEC(&states.start);
+ BEGIN_EXEC(&States::start);
expressions.push(~expressions.pop_num_calc());
break;
case '*':
- BEGIN_EXEC(&states.start);
+ BEGIN_EXEC(&States::start);
expressions.push_calc(Expressions::OP_POW);
break;
case '/':
- BEGIN_EXEC(&states.start);
+ BEGIN_EXEC(&States::start);
expressions.push_calc(Expressions::OP_MOD);
break;
@@ -549,13 +556,13 @@ StateControl::custom(gchar chr)
return NULL;
}
- return &states.start;
+ return &States::start;
}
StateECommand::StateECommand() : State()
{
transitions['\0'] = this;
- transitions['B'] = &states.file;
+ transitions['B'] = &States::file;
}
State *
@@ -563,7 +570,7 @@ StateECommand::custom(gchar chr)
{
switch (g_ascii_toupper(chr)) {
case 'X':
- BEGIN_EXEC(&states.start);
+ BEGIN_EXEC(&States::start);
undo.push_var<bool>(quit_requested);
quit_requested = true;
break;
@@ -572,7 +579,7 @@ StateECommand::custom(gchar chr)
return NULL;
}
- return &states.start;
+ return &States::start;
}
/*
@@ -616,5 +623,5 @@ State *
StateInsert::done(const gchar *str __attribute__((unused)))
{
/* nothing to be done when done */
- return &states.start;
+ return &States::start;
}
diff --git a/parser.h b/parser.h
index e655e34..91ee036 100644
--- a/parser.h
+++ b/parser.h
@@ -91,21 +91,16 @@ private:
State *done(const gchar *str);
};
-#include "goto.h"
-#include "qbuffers.h"
-
extern gint macro_pc;
-extern struct States {
- StateStart start;
- StateLabel label;
- StateControl control;
- StateECommand ecommand;
- StateFile file;
- StateInsert insert;
-} states;
+namespace States {
+ extern StateStart start;
+ extern StateControl control;
+ extern StateECommand ecommand;
+ extern StateInsert insert;
-extern State *current_state;
+ extern State *current;
+}
extern enum Mode {
MODE_NORMAL = 0,
diff --git a/qbuffers.cpp b/qbuffers.cpp
index 289683a..d9eba9f 100644
--- a/qbuffers.cpp
+++ b/qbuffers.cpp
@@ -15,6 +15,10 @@
#include "expressions.h"
#include "qbuffers.h"
+namespace States {
+ StateFile file;
+}
+
Ring ring;
bool
@@ -159,7 +163,7 @@ StateFile::initial(void)
State *
StateFile::done(const gchar *str)
{
- BEGIN_EXEC(&states.start);
+ BEGIN_EXEC(&States::start);
if (is_glob_pattern(str)) {
gchar *dirname;
@@ -197,5 +201,5 @@ StateFile::done(const gchar *str)
do_edit(*str ? str : NULL);
}
- return &states.start;
+ return &States::start;
}
diff --git a/qbuffers.h b/qbuffers.h
index b837423..56580c4 100644
--- a/qbuffers.h
+++ b/qbuffers.h
@@ -136,6 +136,10 @@ private:
State *done(const gchar *str);
};
+namespace States {
+ extern StateFile file;
+}
+
/*
* Auxiliary functions
*/