summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/core/commands.c18
-rw-r--r--src/fe-text/lastlog.c60
-rw-r--r--src/fe-text/module-formats.c1
-rw-r--r--src/fe-text/module-formats.h1
-rw-r--r--src/fe-text/textbuffer.c45
-rw-r--r--src/fe-text/textbuffer.h1
6 files changed, 98 insertions, 28 deletions
diff --git a/src/core/commands.c b/src/core/commands.c
index 9d7cfe2d..f1119069 100644
--- a/src/core/commands.c
+++ b/src/core/commands.c
@@ -565,9 +565,9 @@ static int get_cmd_options(char **data, int ignore_unknown,
break;
}
- if (!isspace(**data))
+ if (!isspace(**data)) {
option = cmd_get_param(data);
- else {
+ } else {
option = "-";
(*data)++;
}
@@ -575,6 +575,18 @@ static int get_cmd_options(char **data, int ignore_unknown,
/* check if this option can have argument */
pos = optlist == NULL ? -1 :
option_find(optlist, option);
+
+ if (pos == -1 && optlist != NULL &&
+ is_numeric(option, '\0')) {
+ /* check if we want -<number> option */
+ pos = option_find(optlist, "#");
+ if (pos != -1) {
+ g_hash_table_insert(options, "#",
+ option);
+ pos = -3;
+ }
+ }
+
if (pos == -1 && !ignore_unknown) {
/* unknown option! */
*data = option;
@@ -591,7 +603,7 @@ static int get_cmd_options(char **data, int ignore_unknown,
option = optlist[pos] +
iscmdtype(*optlist[pos]);
}
- if (options != NULL)
+ if (options != NULL && pos != -3)
g_hash_table_insert(options, option, "");
if (pos < 0 || !iscmdtype(*optlist[pos]) ||
diff --git a/src/fe-text/lastlog.c b/src/fe-text/lastlog.c
index e4155611..61fb5fc1 100644
--- a/src/fe-text/lastlog.c
+++ b/src/fe-text/lastlog.c
@@ -31,6 +31,8 @@
#include "gui-windows.h"
#include "gui-printtext.h"
+#define DEFAULT_LASTLOG_BEFORE 3
+#define DEFAULT_LASTLOG_AFTER 3
#define MAX_LINES_WITHOUT_FORCE 1000
static void window_lastlog_clear(WINDOW_REC *window)
@@ -100,7 +102,7 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
GList *list, *tmp;
GString *line;
char *str;
- int level, len;
+ int level, before, after, len;
level = cmd_options_get_level("lastlog", optlist);
if (level == -1) return; /* error in options */
@@ -136,9 +138,23 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
if (startline == NULL)
startline = textbuffer_view_get_lines(WINDOW_GUI(window)->view);
+ str = g_hash_table_lookup(optlist, "#");
+ if (str != NULL) {
+ before = after = atoi(str);
+ } else {
+ str = g_hash_table_lookup(optlist, "before");
+ before = str == NULL ? 0 : *str != '\0' ?
+ atoi(str) : DEFAULT_LASTLOG_BEFORE;
+
+ str = g_hash_table_lookup(optlist, "after");
+ if (str == NULL) str = g_hash_table_lookup(optlist, "a");
+ after = str == NULL ? 0 : *str != '\0' ?
+ atoi(str) : DEFAULT_LASTLOG_AFTER;
+ }
+
list = textbuffer_find_text(WINDOW_GUI(window)->view->buffer, startline,
level, MSGLEVEL_LASTLOG,
- searchtext,
+ searchtext, before, after,
g_hash_table_lookup(optlist, "regexp") != NULL,
g_hash_table_lookup(optlist, "word") != NULL,
g_hash_table_lookup(optlist, "case") != NULL);
@@ -154,12 +170,12 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
len = g_list_length(tmp);
}
- if(g_hash_table_lookup(optlist, "count") != NULL) {
- printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
- TXT_LASTLOG_COUNT, len);
- g_list_free(list);
- return;
- }
+ if (g_hash_table_lookup(optlist, "count") != NULL) {
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
+ TXT_LASTLOG_COUNT, len);
+ g_list_free(list);
+ return;
+ }
if (len > MAX_LINES_WITHOUT_FORCE && fhandle == -1 &&
g_hash_table_lookup(optlist, "force") == NULL) {
@@ -176,6 +192,20 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
while (tmp != NULL && (count < 0 || count > 0)) {
LINE_REC *rec = tmp->data;
+ if (rec == NULL) {
+ if (tmp->next == NULL)
+ break;
+ if (fhandle != -1) {
+ write(fhandle, "--\n", 3);
+ } else {
+ printformat_window(active_win,
+ MSGLEVEL_LASTLOG,
+ TXT_LASTLOG_SEPARATOR);
+ }
+ tmp = tmp->next;
+ continue;
+ }
+
/* get the line text */
textbuffer_line2text(rec, fhandle == -1, line);
if (!settings_get_bool("timestamps")) {
@@ -212,9 +242,10 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
g_list_free(list);
}
-/* SYNTAX: LASTLOG [-] [-file <filename>] [-clear] [-<level> -<level...>]
- [-count] [-new | -away] [-regexp | -word] [-case]
- [-window <ref#|name>] [<pattern>] [<count> [<start>]] */
+/* SYNTAX: LASTLOG [-] [-file <filename>] [-window <ref#|name>] [-new | -away]
+ [-<level> -<level...>] [-clear] [-count] [-case]
+ [-regexp | -word] [-before [<#>]] [-after [<#>]]
+ [-<# before+after>] [<pattern>] [<count> [<start>]] */
static void cmd_lastlog(const char *data)
{
GHashTable *optlist;
@@ -224,8 +255,9 @@ static void cmd_lastlog(const char *data)
g_return_if_fail(data != NULL);
- if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS,
- "lastlog", &optlist, &text, &countstr, &start))
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_UNKNOWN_OPTIONS, "lastlog", &optlist,
+ &text, &countstr, &start))
return;
if (*start == '\0' && is_numeric(text, 0) && *text != '0' &&
@@ -263,7 +295,7 @@ void lastlog_init(void)
{
command_bind("lastlog", NULL, (SIGNAL_FUNC) cmd_lastlog);
- command_set_options("lastlog", "!- force clear -file -window new away word regexp case count");
+ command_set_options("lastlog", "!- # force clear -file -window new away word regexp case count @a @after @before");
}
void lastlog_deinit(void)
diff --git a/src/fe-text/module-formats.c b/src/fe-text/module-formats.c
index afae7e79..4a37db25 100644
--- a/src/fe-text/module-formats.c
+++ b/src/fe-text/module-formats.c
@@ -29,6 +29,7 @@ FORMAT_REC gui_text_formats[] =
{ "lastlog_count", "{hilight Lastlog}: $0 lines", 1, { 1 } },
{ "lastlog_start", "{hilight Lastlog}:", 0 },
{ "lastlog_end", "{hilight End of Lastlog}", 0 },
+ { "lastlog_separator", "--", 0 },
{ "refnum_not_found", "Window number $0 not found", 1, { 0 } },
{ "window_too_small", "Not enough room to resize this window", 0 },
diff --git a/src/fe-text/module-formats.h b/src/fe-text/module-formats.h
index eb8f3dff..2bbf4007 100644
--- a/src/fe-text/module-formats.h
+++ b/src/fe-text/module-formats.h
@@ -7,6 +7,7 @@ enum {
TXT_LASTLOG_COUNT,
TXT_LASTLOG_START,
TXT_LASTLOG_END,
+ TXT_LASTLOG_SEPARATOR,
TXT_REFNUM_NOT_FOUND,
TXT_WINDOW_TOO_SMALL,
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
diff --git a/src/fe-text/textbuffer.h b/src/fe-text/textbuffer.h
index 87e950fa..c411f294 100644
--- a/src/fe-text/textbuffer.h
+++ b/src/fe-text/textbuffer.h
@@ -96,6 +96,7 @@ void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer);
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);
void textbuffer_init(void);