blob: 0b218ab2397bbf18cd18d90270706764781926d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#include <glib.h>
#include <glib/gprintf.h>
#include "sciteco.h"
#include "parser.h"
gint macro_pc = 0;
static struct {
StateStart start;
} states;
static State *current_state = &states.start;
gboolean
macro_execute(const gchar *macro)
{
while (macro[macro_pc]) {
if (!State::input(macro[macro_pc])) {
message_display(GTK_MESSAGE_ERROR,
"Syntax error \"%c\"",
macro[macro_pc]);
return FALSE;
}
macro_pc++;
}
return TRUE;
}
State::State()
{
for (int i = 0; i < MAX_TRANSITIONS; i++)
transitions[i] = NULL;
}
gboolean
State::input(gchar chr)
{
State *state = current_state;
for (;;) {
State *next = state->get_next_state(chr);
if (!next)
/* Syntax error */
return FALSE;
if (next == state)
break;
state = next;
chr = '\0';
}
if (state != current_state) {
undo.push_var<State *>(current_state);
current_state = state;
}
return TRUE;
}
StateStart::StateStart() : State()
{
transitions['\0'] = this;
transitions[' '] = this;
transitions['\r'] = this;
transitions['\n'] = this;
transitions['\v'] = this;
}
State *
StateStart::custom(gchar chr)
{
#if 0
if (IS_CTL(chr))
return states.ctl.get_next_state(CTL_ECHO(chr));
#endif
switch (g_ascii_toupper(chr)) {
/*
* commands
*/
case 'C':
editor_msg(SCI_CHARRIGHT);
undo.push_msg(SCI_CHARLEFT);
break;
default:
return NULL;
}
return this;
}
|