diff options
author | Timo Sirainen <cras@irssi.org> | 2001-03-07 23:55:54 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-03-07 23:55:54 +0000 |
commit | 9f28d164567245722fb7077184acb9f66e5721fb (patch) | |
tree | 1af3491143a625369414ce13d7ce895fd7dd203f /src/fe-text | |
parent | 00abe69923f124555f50e129249acb7d4265fea7 (diff) | |
download | irssi-9f28d164567245722fb7077184acb9f66e5721fb.zip |
/LASTLOG -window unknown crashed irssi
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1360 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-text')
-rw-r--r-- | src/fe-text/lastlog.c | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/src/fe-text/lastlog.c b/src/fe-text/lastlog.c index 53ae511a..11addf29 100644 --- a/src/fe-text/lastlog.c +++ b/src/fe-text/lastlog.c @@ -87,13 +87,13 @@ int cmd_options_get_level(const char *cmd, GHashTable *optlist) } static void show_lastlog(const char *searchtext, GHashTable *optlist, - int start, int count) + int start, int count, int fhandle) { WINDOW_REC *window; GList *startline, *list, *tmp; GString *line; char *str; - int level, fhandle, len; + int level, len; level = cmd_options_get_level("lastlog", optlist); if (level == -1) return; /* error in options */ @@ -105,25 +105,6 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist, return; } - /* target where to print it */ - fhandle = -1; - str = g_hash_table_lookup(optlist, "file"); - if (str != NULL) { - str = convert_home(str); - fhandle = open(str, O_WRONLY | O_APPEND | O_CREAT, - octal2dec(settings_get_int("log_create_mode"))); - g_free(str); - - if (fhandle == -1) { - printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, - "%s", g_strerror(errno)); - return; - } - } - - if (fhandle == -1 && g_hash_table_lookup(optlist, "-") == NULL) - printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_START); - /* which window's lastlog to look at? */ window = active_win; str = g_hash_table_lookup(optlist, "window"); @@ -131,6 +112,11 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist, window = is_numeric(str, '\0') ? window_find_refnum(atoi(str)) : window_find_item(NULL, str); + if (window == NULL) { + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_REFNUM_NOT_FOUND, str); + return; + } } if (g_hash_table_lookup(optlist, "new") != NULL) @@ -169,6 +155,9 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist, return; } + if (fhandle == -1 && g_hash_table_lookup(optlist, "-") == NULL) + printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_START); + line = g_string_new(NULL); while (tmp != NULL && (count < 0 || count > 0)) { LINE_REC *rec = tmp->data; @@ -202,9 +191,6 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist, if (fhandle == -1 && g_hash_table_lookup(optlist, "-") == NULL) printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_END); - if (fhandle != -1) - close(fhandle); - WINDOW_GUI(window)->lastlog_last_check = g_list_last(WINDOW_GUI(window)->bottom_startline); @@ -217,9 +203,9 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist, static void cmd_lastlog(const char *data) { GHashTable *optlist; - char *text, *countstr, *start; + char *text, *countstr, *start, *fname; void *free_arg; - int count; + int count, fhandle; g_return_if_fail(data != NULL); @@ -236,7 +222,25 @@ static void cmd_lastlog(const char *data) count = atoi(countstr); if (count == 0) count = -1; - show_lastlog(text, optlist, atoi(start), count); + /* target where to print it */ + fhandle = -1; + fname = g_hash_table_lookup(optlist, "file"); + if (fname != NULL) { + fname = convert_home(fname); + fhandle = open(fname, O_WRONLY | O_APPEND | O_CREAT, + octal2dec(settings_get_int("log_create_mode"))); + g_free(fname); + } + + if (fname != NULL && fhandle == -1) { + printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, + "%s", g_strerror(errno)); + } else { + show_lastlog(text, optlist, atoi(start), count, fhandle); + if (fhandle != -1) + close(fhandle); + } + cmd_params_free(free_arg); } |