summaryrefslogtreecommitdiff
path: root/src/fe-text/textbuffer.c
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2002-01-20 16:57:06 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2002-01-20 16:57:06 +0000
commitf12d3914e580ea1bd4d55d94190e9e59aea14f86 (patch)
treefb2328ac559529e1e83e4dee3fb15b46b386fdfd /src/fe-text/textbuffer.c
parent93061dd48fca1b85ddcca611502435c068d0a1d8 (diff)
downloadirssi-f12d3914e580ea1bd4d55d94190e9e59aea14f86.zip
Added -before and -after options to /LASTLOG. You can also use
-<number> to specify both before and after values. Added special "#" option name to commands which specifies that -<number> parameter is allowed. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2331 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-text/textbuffer.c')
-rw-r--r--src/fe-text/textbuffer.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c
index 29527622..14524690 100644
--- a/src/fe-text/textbuffer.c
+++ b/src/fe-text/textbuffer.c
@@ -196,7 +196,6 @@ static LINE_REC *textbuffer_line_insert(TEXT_BUFFER_REC *buffer,
buffer->first_line->prev = line;
buffer->first_line = line;
} else {
- line->prev = prev;
line->next = prev->next;
if (line->next != NULL)
line->next->prev = line;
@@ -234,7 +233,8 @@ void textbuffer_line_unref_list(TEXT_BUFFER_REC *buffer, GList *list)
g_return_if_fail(buffer != NULL);
while (list != NULL) {
- textbuffer_line_unref(buffer, list->data);
+ if (list->data != NULL)
+ textbuffer_line_unref(buffer, list->data);
list = list->next;
}
}
@@ -445,14 +445,16 @@ void textbuffer_line2text(LINE_REC *line, int coloring, GString *str)
GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
int level, int nolevel, const char *text,
+ int before, int after,
int regexp, int fullword, int case_sensitive)
{
#ifdef HAVE_REGEX_H
regex_t preg;
#endif
- LINE_REC *line;
+ LINE_REC *line, *pre_line;
GList *matches;
- GString *str;
+ GString *str;
+ int i, match_after, line_matched;
g_return_val_if_fail(buffer != NULL, NULL);
g_return_val_if_fail(text != NULL, NULL);
@@ -468,7 +470,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
#endif
}
- matches = NULL;
+ matches = NULL; match_after = 0;
str = g_string_new(NULL);
line = startline != NULL ? startline : buffer->first_line;
@@ -487,17 +489,38 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
textbuffer_line2text(line, FALSE, str);
- if (
+ line_matched =
#ifdef HAVE_REGEX_H
- regexp ? regexec(&preg, str->str, 0, NULL, 0) == 0 :
+ regexp ? regexec(&preg, str->str, 0, NULL, 0) == 0 :
#endif
- fullword ? strstr_full_case(str->str, text,
- !case_sensitive) != NULL :
- case_sensitive ? strstr(str->str, text) != NULL :
- stristr(str->str, text) != NULL) {
+ fullword ? strstr_full_case(str->str, text, !case_sensitive) != NULL :
+ case_sensitive ? strstr(str->str, text) != NULL :
+ stristr(str->str, text) != NULL;
+ if (line_matched) {
+ /* add the -before lines */
+ pre_line = line;
+ for (i = 0; i < before; i++) {
+ if (pre_line->prev == NULL ||
+ g_list_find(matches, pre_line->prev) != NULL)
+ break;
+ pre_line = pre_line->prev;
+ }
+
+ for (; pre_line != line; pre_line = pre_line->next) {
+ textbuffer_line_ref(pre_line);
+ matches = g_list_append(matches, pre_line);
+ }
+
+ match_after = after;
+ }
+
+ if (line_matched || match_after > 0) {
/* matched */
textbuffer_line_ref(line);
matches = g_list_append(matches, line);
+
+ if (!line_matched && --match_after == 0)
+ matches = g_list_append(matches, NULL);
}
}
#ifdef HAVE_REGEX_H