summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@src.gnome.org>2002-06-18 04:20:38 +0000
committerNalin Dahyabhai <nalin@src.gnome.org>2002-06-18 04:20:38 +0000
commit5aba0af966e7eea386f95f944cad25b76d07e11b (patch)
treef5cc71e9a8f0cd6e6ec7b12535fcd42b48e48163
parent2fa3b394c54ac2cf3d72d54b74553c2fae16bc48 (diff)
Sort out greedy vs. non-greedy pattern matching. Make 1047 an alias for 47vte_0_4_1
* src/trie.c (vte_trie_match, vte_trie_match_x): Sort out greedy vs. non-greedy pattern matching. * src/vte.c (vte_sequence_handler_decset_internal): Make 1047 an alias for 47 (use alternate buffer), and handle cursor save/restore properly.
-rw-r--r--ChangeLog5
-rw-r--r--README1
-rw-r--r--src/trie.c72
-rw-r--r--src/vte.c50
-rw-r--r--vte.spec5
5 files changed, 113 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index ef13669..b29ca91 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-06-17 nalin
+ * src/trie.c (vte_trie_match, vte_trie_match_x): Sort out greedy vs.
+ non-greedy pattern matching.
+ * src/vte.c (vte_sequence_handler_decset_internal): Make 1047 an alias
+ for 47 (use alternate buffer), and handle cursor save/restore properly.
2002-06-14 nalin
* src/vte.c, src/vte.h (vte_terminal_fork_command): Add a parameter for
passing in environment variables to add.
diff --git a/README b/README
index 93964fd..ddd79ce 100644
--- a/README
+++ b/README
@@ -26,7 +26,6 @@
implemented (ff, fs, i1, i3, is, iP, LF, LO, MC, mh, ML, mm, mo, nw, pf,
pk, pl, pf, po, pO, ps, px, r1, r2, r3, RA, RF, rp, rs, RX, SA, SX, wi,
several more from the XTerm set).
-- Sequence matching is greedy, so that C=AB matches C and not A and then B.
- Bold doesn't work right if the default foreground color isn't gray. Need
to move to 20-color palette to fix this right.
- I'm not sure the widget implementation itself is correct. There are many
diff --git a/src/trie.c b/src/trie.c
index 276ff22..51f1363 100644
--- a/src/trie.c
+++ b/src/trie.c
@@ -497,6 +497,7 @@ vte_trie_add(struct vte_trie *trie, const char *pattern, size_t length,
* works, and the result string if we have an exact match. */
static const char *
vte_trie_matchx(struct vte_trie *trie, const wchar_t *pattern, size_t length,
+ gboolean greedy,
const char **res, const wchar_t **consumed,
GQuark *quark, GValueArray *array)
{
@@ -517,7 +518,7 @@ vte_trie_matchx(struct vte_trie *trie, const wchar_t *pattern, size_t length,
/* Trivial cases. We've matched an entire pattern, or we're out of
* pattern to match. */
- if (trie->result) {
+ if (trie->result != NULL) {
*res = trie->result;
*quark = trie->quark;
*consumed = pattern;
@@ -559,6 +560,7 @@ vte_trie_matchx(struct vte_trie *trie, const wchar_t *pattern, size_t length,
return vte_trie_matchx(path->trie,
pattern + partial,
length - partial,
+ FALSE,
res,
consumed,
quark,
@@ -581,6 +583,7 @@ vte_trie_matchx(struct vte_trie *trie, const wchar_t *pattern, size_t length,
const char *tmp;
GQuark tmpquark = 0;
GValueArray *tmparray;
+ gboolean better = FALSE;
/* Move past characters which might match this
* part of the string... */
while (cclass->multiple &&
@@ -600,16 +603,42 @@ vte_trie_matchx(struct vte_trie *trie, const wchar_t *pattern, size_t length,
vte_trie_matchx(subtrie,
prospect,
length - (prospect - pattern),
+ greedy,
&tmp,
consumed,
&tmpquark,
tmparray);
- /* If it's a better match than any we've seen
- * so far, call it the "best so far". */
- if ((best == NULL) ||
- ((best[0] == '\0') &&
- (tmp != NULL) &&
- (tmp[0] != '\0'))) {
+ /* If we haven't seen any matches yet, go ahead
+ * and go by this result. */
+ if (best == NULL) {
+ better = TRUE;
+ }
+ /* If we have a match, and we didn't have one
+ * already, go by this result. */
+ if ((best != NULL) &&
+ (best[0] == '\0') &&
+ (tmp != NULL) &&
+ (tmp[0] != '\0')) {
+ better = TRUE;
+ }
+ /* If we already have a match, and this one's
+ * better (longer if we're greedy, shorter if
+ * we're not), then go by this result. */
+ if ((tmp != NULL) &&
+ (tmp[0] != '\0') &&
+ (bestconsumed != NULL) &&
+ (consumed != NULL) &&
+ (*consumed != NULL)) {
+ if (greedy &&
+ (bestconsumed < *consumed)) {
+ better = TRUE;
+ }
+ if (!greedy &&
+ (bestconsumed > *consumed)) {
+ better = TRUE;
+ }
+ }
+ if (better) {
best = tmp;
if (bestarray != NULL) {
g_value_array_free(bestarray);
@@ -704,6 +733,7 @@ vte_trie_match(struct vte_trie *trie, const wchar_t *pattern, size_t length,
GValue *value;
const wchar_t *dummyconsumed;
gpointer ptr;
+ gboolean greedy = FALSE;
int i;
valuearray = g_value_array_new(0);
@@ -717,8 +747,8 @@ vte_trie_match(struct vte_trie *trie, const wchar_t *pattern, size_t length,
}
*consumed = pattern;
- ret = vte_trie_matchx(trie, pattern, length, res, consumed,
- quark, valuearray);
+ ret = vte_trie_matchx(trie, pattern, length, greedy,
+ res, consumed, quark, valuearray);
if (((ret == NULL) || (ret[0] == '\0')) || (valuearray->n_values == 0)){
if (valuearray != NULL) {
@@ -903,6 +933,8 @@ main(int argc, char **argv)
g_quark_from_string("vtmatch"));
vte_trie_add(trie, "<esc>[%i%mL", 11, "multimatch",
g_quark_from_string("multimatch"));
+ vte_trie_add(trie, "<esc>[%mL<esc>[%mL", 18, "greedy",
+ g_quark_from_string("greedy"));
vte_trie_add(trie, "<esc>]2;%sh", 11, "decset-title",
g_quark_from_string("decset-title"));
if (argc > 1) {
@@ -1045,6 +1077,28 @@ main(int argc, char **argv)
}
quark = 0;
+ convert_mbstowcs("<esc>[25L", 9, buf, &buflen, sizeof(buf));
+ g_print("`%s' = `%s'\n", "<esc>[25L",
+ vte_trie_match(trie, buf, buflen,
+ NULL, &consumed, &quark, &array));
+ g_print("=> `%s' (%d)\n", g_quark_to_string(quark), consumed - buf);
+ if (array != NULL) {
+ dump_array(array);
+ g_value_array_free(array);
+ }
+
+ quark = 0;
+ convert_mbstowcs("<esc>[25L<esc>[24L", 18, buf, &buflen, sizeof(buf));
+ g_print("`%s' = `%s'\n", "<esc>[25L<esc>[24L",
+ vte_trie_match(trie, buf, buflen,
+ NULL, &consumed, &quark, &array));
+ g_print("=> `%s' (%d)\n", g_quark_to_string(quark), consumed - buf);
+ if (array != NULL) {
+ dump_array(array);
+ g_value_array_free(array);
+ }
+
+ quark = 0;
convert_mbstowcs("<esc>[25;26L", 12, buf, &buflen, sizeof(buf));
g_print("`%s' = `%s'\n", "<esc>[25;26L",
vte_trie_match(trie, buf, buflen,
diff --git a/src/vte.c b/src/vte.c
index 8a4e07a..c17515b 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -3221,43 +3221,64 @@ vte_sequence_handler_decset_internal(VteTerminal *terminal,
gpointer *pvalue;
gpointer fvalue;
gpointer tvalue;
+ VteTerminalSequenceHandler reset, set;
} settings[] = {
/* Application/normal keypad. */
{1, NULL, &terminal->pvt->keypad, NULL,
GINT_TO_POINTER(VTE_KEYPAD_NORMAL),
- GINT_TO_POINTER(VTE_KEYPAD_APPLICATION),},
+ GINT_TO_POINTER(VTE_KEYPAD_APPLICATION),
+ NULL, NULL,},
/* Reverse video. */
{5, &terminal->pvt->screen->reverse_mode, NULL, NULL,
GINT_TO_POINTER(FALSE),
- GINT_TO_POINTER(TRUE),},
+ GINT_TO_POINTER(TRUE),
+ NULL, NULL,},
/* Send-coords-on-click. */
{9, &terminal->pvt->mouse_send_xy_on_click, NULL, NULL,
GINT_TO_POINTER(FALSE),
- GINT_TO_POINTER(TRUE),},
+ GINT_TO_POINTER(TRUE),
+ NULL, NULL,},
/* Cursor visible. */
{25, &terminal->pvt->screen->cursor_visible, NULL, NULL,
GINT_TO_POINTER(FALSE),
- GINT_TO_POINTER(TRUE),},
+ GINT_TO_POINTER(TRUE),
+ NULL, NULL,},
/* Alternate screen. */
{47, NULL, NULL, (gpointer*) &terminal->pvt->screen,
&terminal->pvt->normal_screen,
- &terminal->pvt->alternate_screen,},
+ &terminal->pvt->alternate_screen,
+ NULL, NULL,},
/* Send-coords-on-button. */
{1000, &terminal->pvt->mouse_send_xy_on_button, NULL, NULL,
GINT_TO_POINTER(FALSE),
- GINT_TO_POINTER(TRUE),},
+ GINT_TO_POINTER(TRUE),
+ NULL, NULL,},
/* Hilite tracking*/
{1001, &terminal->pvt->mouse_hilite_tracking, NULL, NULL,
GINT_TO_POINTER(FALSE),
- GINT_TO_POINTER(TRUE),},
+ GINT_TO_POINTER(TRUE),
+ NULL, NULL,},
/* Cell motion tracking*/
{1002, &terminal->pvt->mouse_cell_motion_tracking, NULL, NULL,
GINT_TO_POINTER(FALSE),
- GINT_TO_POINTER(TRUE),},
+ GINT_TO_POINTER(TRUE),
+ NULL, NULL,},
/* All motion tracking*/
{1003, &terminal->pvt->mouse_all_motion_tracking, NULL, NULL,
GINT_TO_POINTER(FALSE),
- GINT_TO_POINTER(TRUE),},
+ GINT_TO_POINTER(TRUE),
+ NULL, NULL,},
+ /* Use alternate screen buffer. */
+ {1047, NULL, NULL, (gpointer*) &terminal->pvt->screen,
+ &terminal->pvt->normal_screen,
+ &terminal->pvt->alternate_screen,
+ NULL, NULL,},
+ /* Save/restore cursor position. */
+ {1048, NULL, NULL, NULL,
+ NULL,
+ NULL,
+ vte_sequence_handler_rc,
+ vte_sequence_handler_sc,},
};
g_return_if_fail(VTE_IS_TERMINAL(terminal));
@@ -3320,6 +3341,15 @@ vte_sequence_handler_decset_internal(VteTerminal *terminal,
*(settings[i].pvalue) = set ?
settings[i].tvalue :
settings[i].fvalue;
+ } else
+ if (settings[i].set && settings[i].reset) {
+ if (set) {
+ settings[i].set(terminal, NULL,
+ 0, NULL);
+ } else {
+ settings[i].reset(terminal, NULL,
+ 0, NULL);
+ }
}
}
}
@@ -3331,10 +3361,12 @@ vte_sequence_handler_decset_internal(VteTerminal *terminal,
vte_invalidate_all(terminal);
break;
case 25:
+ case 1048:
/* Repaint the cell the cursor is in. */
vte_invalidate_cursor_once(terminal);
break;
case 47:
+ case 1047:
/* Reset scrollbars and repaint everything. */
vte_terminal_adjust_adjustments(terminal);
vte_invalidate_all(terminal);
diff --git a/vte.spec b/vte.spec
index a6c6a87..06df7b9 100644
--- a/vte.spec
+++ b/vte.spec
@@ -1,5 +1,5 @@
Name: vte
-Version: 0.4.0
+Version: 0.4.1
Release: 1
Summary: An experimental terminal emulator.
License: LGPL
@@ -57,6 +57,9 @@ make install DESTDIR=$RPM_BUILD_ROOT
%{_libdir}/pkgconfig/*
%changelog
+* Tue Jun 18 2002 Nalin Dahyabhai <nalin@redhat.com> 0.4.1-1
+- fix use of alternate buffer in xterm emulation mode
+
* Fri Jun 14 2002 Nalin Dahyabhai <nalin@redhat.com> 0.4.0-1
- add a means for apps to add environment variables