1
0
mirror of https://github.com/irssi/irssi.git synced 2024-09-22 04:35:58 -04:00

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
This commit is contained in:
Timo Sirainen 2002-01-20 16:57:06 +00:00 committed by cras
parent 93061dd48f
commit f12d3914e5
6 changed files with 98 additions and 28 deletions

View File

@ -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]) ||

View File

@ -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)

View File

@ -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 },

View File

@ -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,

View File

@ -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

View File

@ -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);