1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-08 10:43:13 +02:00

Moved content of src/common/log.c to src/gui/gui-log.c, log.c is now used for WeeChat log file

This commit is contained in:
Sebastien Helleu
2006-05-20 09:45:02 +00:00
parent 1bc71392c4
commit 0eea93bba3
50 changed files with 686 additions and 544 deletions
+1
View File
@@ -23,6 +23,7 @@ lib_weechat_gui_common_a_SOURCES = gui-buffer.c \
gui-common.c \
gui-action.c \
gui-keyboard.c \
gui-log.c \
gui-window.c \
gui-panel.c \
gui.h \
+2 -6
View File
@@ -20,9 +20,7 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\"
bin_PROGRAMS = weechat-curses
if PLUGINS
weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \
../gui-window.o ../gui-panel.o \
../gui-keyboard.o ../gui-action.o \
weechat_curses_LDADD = ../lib_weechat_gui_common.a \
../../common/lib_weechat_main.a \
../../irc/lib_weechat_irc.a \
../../plugins/lib_weechat_plugins.a \
@@ -30,9 +28,7 @@ weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \
$(NCURSES_LIBS) \
$(GNUTLS_LFLAGS)
else
weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \
../gui-window.o ../gui-panel.o \
../gui-keyboard.o ../gui-action.o \
weechat_curses_LDADD = ../lib_weechat_gui_common.a \
../../common/lib_weechat_main.a \
../../irc/lib_weechat_irc.a \
$(PLUGINS_LIBS) \
+1
View File
@@ -32,6 +32,7 @@
#include "../../common/weechat.h"
#include "../gui.h"
#include "../../common/hotlist.h"
#include "../../common/log.h"
#include "../../common/weeconfig.h"
#include "gui-curses.h"
+2 -6
View File
@@ -20,9 +20,7 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GTK_CFLAGS)
bin_PROGRAMS = weechat-gtk
if PLUGINS
weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \
../gui-window.o ../gui-panel.o \
../gui-keyboard.o ../gui-action.o \
weechat_gtk_LDADD = ../lib_weechat_gui_common.a \
../../common/lib_weechat_main.a \
../../irc/lib_weechat_irc.a \
../../plugins/lib_weechat_plugins.a \
@@ -30,9 +28,7 @@ weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \
$(GTK_LIBS) \
$(GNUTLS_LFLAGS)
else
weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \
../gui-window.o ../gui-panel.o \
../gui-keyboard.o ../gui-action.o \
weechat_gtk_LDADD = ../lib_weechat_gui_common.a \
../../common/lib_weechat_main.a \
../../irc/lib_weechat_irc.a \
$(PLUGINS_LIBS) \
+1
View File
@@ -30,6 +30,7 @@
#include "../../common/weechat.h"
#include "../gui.h"
#include "../../common/hotlist.h"
#include "../../common/log.h"
#include "../../common/weeconfig.h"
#include "gui-gtk.h"
+3 -3
View File
@@ -98,7 +98,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type,
if (cfg_look_one_server_buffer && server && !channel)
gui_buffers->all_servers = 1;
if (cfg_log_auto_server)
log_start (gui_buffers);
gui_log_start (gui_buffers);
return gui_buffers;
}
@@ -165,7 +165,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type,
if ((cfg_log_auto_server && BUFFER_IS_SERVER(new_buffer))
|| (cfg_log_auto_channel && BUFFER_IS_CHANNEL(new_buffer))
|| (cfg_log_auto_private && BUFFER_IS_PRIVATE(new_buffer)))
log_start (new_buffer);
gui_log_start (new_buffer);
/* init input buffer */
new_buffer->has_input = (new_buffer->type == BUFFER_TYPE_STANDARD) ? 1 : 0;
@@ -479,7 +479,7 @@ gui_buffer_free (t_gui_buffer *buffer, int switch_to_another)
/* close log if opened */
if (buffer->log_file)
log_end (buffer);
gui_log_end (buffer);
if (buffer->input_buffer)
free (buffer->input_buffer);
+7 -7
View File
@@ -193,18 +193,18 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *nick, char *message)
}
if (buffer->line_complete && buffer->log_file && buffer->last_line->log_write)
{
log_write_date (buffer);
gui_log_write_date (buffer);
if (buffer->last_line->nick)
{
log_write (buffer, "<");
log_write (buffer, buffer->last_line->nick);
log_write (buffer, "> ");
gui_log_write (buffer, "<");
gui_log_write (buffer, buffer->last_line->nick);
gui_log_write (buffer, "> ");
}
if (buffer->last_line->ofs_start_message >= 0)
log_write_line (buffer,
buffer->last_line->data + buffer->last_line->ofs_start_message);
gui_log_write_line (buffer,
buffer->last_line->data + buffer->last_line->ofs_start_message);
else
log_write_line (buffer, buffer->last_line->data);
gui_log_write_line (buffer, buffer->last_line->data);
}
}
+1
View File
@@ -31,6 +31,7 @@
#include "../common/weechat.h"
#include "gui.h"
#include "../common/command.h"
#include "../common/log.h"
#ifdef PLUGINS
#include "../plugins/plugins.h"
+188
View File
@@ -0,0 +1,188 @@
/*
* Copyright (c) 2003-2006 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* gui-log.c: log buffers to files */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "../common/weechat.h"
#include "gui.h"
#include "../common/log.h"
#include "../common/weeconfig.h"
/*
* gui_log_write_date: writes date to log file
*/
void
gui_log_write_date (t_gui_buffer *buffer)
{
static char buf_time[256];
static time_t seconds;
struct tm *date_tmp;
if (buffer->log_file)
{
seconds = time (NULL);
date_tmp = localtime (&seconds);
if (date_tmp)
{
strftime (buf_time, sizeof (buf_time) - 1, cfg_log_timestamp, date_tmp);
fprintf (buffer->log_file, "%s ", buf_time);
fflush (buffer->log_file);
}
}
}
/*
* gui_log_write_line: writes a line to log file
*/
void
gui_log_write_line (t_gui_buffer *buffer, char *message)
{
char *msg_no_color;
if (buffer->log_file)
{
msg_no_color = (char *)gui_color_decode ((unsigned char *)message, 0);
fprintf (buffer->log_file, "%s\n",
(msg_no_color) ? msg_no_color : message);
fflush (buffer->log_file);
if (msg_no_color)
free (msg_no_color);
}
}
/*
* gui_log_write: writes a message to log file
*/
void
gui_log_write (t_gui_buffer *buffer, char *message)
{
char *msg_no_color;
if (buffer->log_file)
{
msg_no_color = (char *)gui_color_decode ((unsigned char *)message, 0);
fprintf (buffer->log_file, "%s",
(msg_no_color) ? msg_no_color : message);
fflush (buffer->log_file);
if (msg_no_color)
free (msg_no_color);
}
}
/*
* gui_log_start: starts a log
*/
void
gui_log_start (t_gui_buffer *buffer)
{
int length;
char *log_path, *log_path2;
log_path = weechat_strreplace (cfg_log_path, "~", getenv ("HOME"));
log_path2 = weechat_strreplace (log_path, "%h", weechat_home);
if (!log_path || !log_path2)
{
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
if (log_path)
free (log_path);
if (log_path2)
free (log_path2);
return;
}
length = strlen (log_path2) + 64;
if (SERVER(buffer))
length += strlen (SERVER(buffer)->name);
if (CHANNEL(buffer))
length += strlen (CHANNEL(buffer)->name);
buffer->log_filename = (char *) malloc (length);
if (!buffer->log_filename)
{
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
if (log_path)
free (log_path);
if (log_path2)
free (log_path2);
return;
}
strcpy (buffer->log_filename, log_path2);
if (log_path)
free (log_path);
if (log_path2)
free (log_path2);
if (buffer->log_filename[strlen (buffer->log_filename) - 1] != DIR_SEPARATOR_CHAR)
strcat (buffer->log_filename, DIR_SEPARATOR);
if (SERVER(buffer))
{
strcat (buffer->log_filename, SERVER(buffer)->name);
strcat (buffer->log_filename, ".");
}
if (CHANNEL(buffer))
{
strcat (buffer->log_filename, CHANNEL(buffer)->name);
strcat (buffer->log_filename, ".");
}
strcat (buffer->log_filename, "weechatlog");
buffer->log_file = fopen (buffer->log_filename, "a");
if (!buffer->log_file)
{
weechat_log_printf (_("Unable to write log file for a buffer\n"));
free (buffer->log_filename);
return;
}
gui_log_write (buffer, _("**** Beginning of log "));
gui_log_write_date (buffer);
gui_log_write (buffer, "****\n");
}
/*
* gui_log_end: ends a log
*/
void
gui_log_end (t_gui_buffer *buffer)
{
if (buffer->log_file)
{
gui_log_write (buffer, _("**** End of log "));
gui_log_write_date (buffer);
gui_log_write (buffer, "****\n");
fclose (buffer->log_file);
buffer->log_file = NULL;
}
if (buffer->log_filename)
free (buffer->log_filename);
}
+9
View File
@@ -27,6 +27,7 @@
#include "gui-window.h"
#include "gui-keyboard.h"
#define gui_printf(buffer, fmt, argz...) \
gui_printf_internal(buffer, 1, MSG_TYPE_INFO, NULL, fmt, ##argz)
@@ -42,6 +43,7 @@
#define gui_printf_nolog_notime(buffer, fmt, argz...) \
gui_printf_internal(buffer, 0, MSG_TYPE_NOLOG, NULL, fmt, ##argz)
typedef struct t_gui_infobar t_gui_infobar;
struct t_gui_infobar
@@ -163,6 +165,13 @@ extern int gui_keyboard_pressed (char *);
extern void gui_keyboard_free (t_gui_key *);
extern void gui_keyboard_free_all ();
/* log */
extern void gui_log_write_date (t_gui_buffer *);
extern void gui_log_write_line (t_gui_buffer *, char *);
extern void gui_log_write (t_gui_buffer *, char *);
extern void gui_log_start (t_gui_buffer *);
extern void gui_log_end (t_gui_buffer *);
/* other */
extern void gui_infobar_printf (int, int, char *, ...);
extern void gui_infobar_printf_from_buffer (t_gui_buffer *, int, int, char *, char *, ...);