1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 06:16:40 +02:00

Renamed many functions, removed all IRC specific stuff

This commit is contained in:
Sebastien Helleu
2007-10-31 17:09:43 +01:00
parent eb2835fa24
commit a3cb19dbea
22 changed files with 2845 additions and 7072 deletions
+7 -5
View File
@@ -14,10 +14,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
SET(LIB_MAIN_SRC weechat.c weechat.h alias.c alias.h backtrace.c backtrace.h
command.c command.h completion.c completion.h weelist.c weelist.h weeconfig.c
weeconfig.h history.c history.h hotlist.c hotlist.h log.c log.h fifo.c fifo.h
session.c session.h utf8.c utf8.h util.c util.h)
SET(LIB_CORE_SRC weechat.c weechat.h wee-alias.c wee-alias.h wee-backtrace.c
wee-backtrace.h wee-command.c wee-command.h wee-config.c wee-config.h
wee-config-file.c wee-config-file.h wee-config-option.c wee-config-option.h
wee-hook.c wee-hook.h wee-input.c wee-input.h wee-list.c wee-list.h wee-log.c
wee-log.h wee-string.c wee-string.h wee-upgrade.c wee-upgrade.h wee-utf8.c
wee-utf8.h wee-util.c wee-util.h)
# Check for flock support
INCLUDE(CheckSymbolExists)
@@ -25,4 +27,4 @@ CHECK_INCLUDE_FILES("sys/file.h" HAVE_SYS_FILE_H)
CHECK_SYMBOL_EXISTS(flock "sys/file.h" HAVE_FLOCK)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
ADD_LIBRARY(weechat_main STATIC ${LIB_MAIN_SRC})
ADD_LIBRARY(weechat_core STATIC ${LIB_CORE_SRC})
+30 -28
View File
@@ -16,33 +16,35 @@
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GNUTLS_CFLAGS)
noinst_LIBRARIES = lib_weechat_main.a
noinst_LIBRARIES = lib_weechat_core.a
lib_weechat_main_a_SOURCES = weechat.c \
lib_weechat_core_a_SOURCES = weechat.c \
weechat.h \
alias.c \
alias.h \
backtrace.c \
backtrace.h \
command.c \
command.h \
completion.c \
completion.h \
weelist.c \
weelist.h \
weeconfig.c \
weeconfig.h \
history.c \
history.h \
hotlist.c \
hotlist.h \
log.c \
log.h \
fifo.c \
fifo.h \
session.c \
session.h \
utf8.c \
utf8.h \
util.c \
util.h
wee-alias.c \
wee-alias.h \
wee-backtrace.c \
wee-backtrace.h \
wee-command.c \
wee-command.h \
wee-config.c \
wee-config.h \
wee-config-file.c \
wee-config-file.h \
wee-config-option.c \
wee-config-option.h \
wee-hook.c \
wee-hook.h \
wee-input.c \
wee-input.h \
wee-list.c \
wee-list.h \
wee-log.c \
wee-log.h \
wee-upgrade.c \
wee-upgrade.h \
wee-string.c \
wee-string.h \
wee-utf8.c \
wee-utf8.h \
wee-util.c \
wee-util.h
+58 -55
View File
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* alias.c: WeeChat alias */
/* wee-alias.c: WeeChat alias */
#ifdef HAVE_CONFIG_H
@@ -27,27 +27,27 @@
#include <string.h>
#include "weechat.h"
#include "alias.h"
#include "util.h"
#include "../protocols/irc/irc.h"
#include "wee-alias.h"
#include "wee-config.h"
#include "wee-string.h"
t_weechat_alias *weechat_alias = NULL;
t_weechat_alias *weechat_last_alias = NULL;
struct alias *weechat_alias = NULL;
struct alias *weechat_last_alias = NULL;
/*
* alias_search: search an alias
*/
t_weechat_alias *
struct alias *
alias_search (char *alias_name)
{
t_weechat_alias *ptr_alias;
struct alias *ptr_alias;
for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias)
{
if (ascii_strcasecmp (alias_name, ptr_alias->alias_name) == 0)
if (string_strcasecmp (alias_name, ptr_alias->name) == 0)
return ptr_alias;
}
return NULL;
@@ -57,14 +57,14 @@ alias_search (char *alias_name)
* alias_find_pos: find position for an alias (for sorting aliases)
*/
t_weechat_alias *
struct alias *
alias_find_pos (char *alias_name)
{
t_weechat_alias *ptr_alias;
struct alias *ptr_alias;
for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias)
{
if (ascii_strcasecmp (alias_name, ptr_alias->alias_name) < 0)
if (string_strcasecmp (alias_name, ptr_alias->name) < 0)
return ptr_alias;
}
return NULL;
@@ -75,11 +75,11 @@ alias_find_pos (char *alias_name)
*/
void
alias_insert_sorted (t_weechat_alias *alias)
alias_insert_sorted (struct alias *alias)
{
t_weechat_alias *pos_alias;
struct alias *pos_alias;
pos_alias = alias_find_pos (alias->alias_name);
pos_alias = alias_find_pos (alias->name);
if (weechat_alias)
{
@@ -116,35 +116,35 @@ alias_insert_sorted (t_weechat_alias *alias)
* alias_new: create new alias and add it to alias list
*/
t_weechat_alias *
alias_new (char *alias_name, char *alias_command)
struct alias *
alias_new (char *name, char *command)
{
t_weechat_alias *new_alias, *ptr_alias;
struct alias *new_alias, *ptr_alias;
while (alias_name[0] == '/')
while (name[0] == '/')
{
alias_name++;
name++;
}
if (ascii_strcasecmp (alias_name, "builtin") == 0)
if (string_strcasecmp (name, "builtin") == 0)
return NULL;
ptr_alias = alias_search (alias_name);
ptr_alias = alias_search (name);
if (ptr_alias)
{
if (ptr_alias->alias_command)
free (ptr_alias->alias_command);
ptr_alias->alias_command = strdup (alias_command);
if (ptr_alias->command)
free (ptr_alias->command);
ptr_alias->command = strdup (command);
return ptr_alias;
}
if ((new_alias = ((t_weechat_alias *) malloc (sizeof (t_weechat_alias)))))
if ((new_alias = ((struct alias *) malloc (sizeof (struct alias)))))
{
new_alias->alias_name = strdup (alias_name);
new_alias->alias_command = (char *) malloc (strlen (alias_command) + 1);
new_alias->name = strdup (name);
new_alias->command = (char *) malloc (strlen (command) + 1);
new_alias->running = 0;
if (new_alias->alias_command)
strcpy (new_alias->alias_command, alias_command);
if (new_alias->command)
strcpy (new_alias->command, command);
alias_insert_sorted (new_alias);
return new_alias;
}
@@ -157,22 +157,23 @@ alias_new (char *alias_name, char *alias_command)
*/
char *
alias_get_final_command (t_weechat_alias *alias)
alias_get_final_command (struct alias *alias)
{
t_weechat_alias *ptr_alias;
struct alias *ptr_alias;
char *result;
if (alias->running)
{
irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
gui_printf (NULL,
_("%s circular reference when calling alias \"/%s\"\n"),
WEECHAT_ERROR, alias->alias_name);
gui_chat_printf (NULL,
_("%s%s circular reference when calling alias "
"\"/%s\""),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
WEECHAT_ERROR, alias->name);
return NULL;
}
ptr_alias = alias_search ((alias->alias_command[0] == '/') ?
alias->alias_command + 1 : alias->alias_command);
ptr_alias = alias_search ((alias->command[0] == '/') ?
alias->command + 1 : alias->command);
if (ptr_alias)
{
alias->running = 1;
@@ -180,8 +181,8 @@ alias_get_final_command (t_weechat_alias *alias)
alias->running = 0;
return result;
}
return (alias->alias_command[0] == '/') ?
alias->alias_command + 1 : alias->alias_command;
return (alias->command[0] == '/') ?
alias->command + 1 : alias->command;
}
/*
@@ -224,7 +225,7 @@ alias_replace_args (char *alias_args, char *user_args)
char **argv, *start, *pos, *res;
int argc, length_res, args_count;
argv = explode_string (user_args, " ", 0, &argc);
argv = string_explode (user_args, " ", 0, &argc);
res = NULL;
length_res = 0;
@@ -288,19 +289,23 @@ alias_replace_args (char *alias_args, char *user_args)
}
if (argv)
free_exploded_string (argv);
string_free_exploded (argv);
return res;
}
/*
* alias_replace_vars: replace special vars ($nick, $channel, $server) in a string
* Note: result has to be free() after use
*/
char *
alias_replace_vars (t_irc_server *server, t_irc_channel *channel, char *string)
alias_replace_vars (struct t_gui_buffer *buffer, char *string)
{
char *var_nick, *var_channel, *var_server;
/* TODO: call protocol specific function to do this */
(void) buffer;
/* char *var_nick, *var_channel, *var_server;
char empty_string[1] = { '\0' };
char *res, *temp;
@@ -308,28 +313,26 @@ alias_replace_vars (t_irc_server *server, t_irc_channel *channel, char *string)
var_channel = (channel) ? channel->name : empty_string;
var_server = (server) ? server->name : empty_string;
/* replace nick */
temp = weechat_strreplace (string, "$nick", var_nick);
if (!temp)
return NULL;
res = temp;
/* replace channel */
temp = weechat_strreplace (res, "$channel", var_channel);
free (res);
if (!temp)
return NULL;
res = temp;
/* replace server */
temp = weechat_strreplace (res, "$server", var_server);
free (res);
if (!temp)
return NULL;
res = temp;
/* return result */
return res;
return res;*/
return strdup (string);
}
/*
@@ -337,9 +340,9 @@ alias_replace_vars (t_irc_server *server, t_irc_channel *channel, char *string)
*/
void
alias_free (t_weechat_alias *alias)
alias_free (struct alias *alias)
{
t_weechat_alias *new_weechat_alias;
struct alias *new_weechat_alias;
/* remove alias from list */
if (weechat_last_alias == alias)
@@ -356,10 +359,10 @@ alias_free (t_weechat_alias *alias)
(alias->next_alias)->prev_alias = alias->prev_alias;
/* free data */
if (alias->alias_name)
free (alias->alias_name);
if (alias->alias_command)
free (alias->alias_command);
if (alias->name)
free (alias->name);
if (alias->command)
free (alias->command);
free (alias);
weechat_alias = new_weechat_alias;
}
+14 -16
View File
@@ -20,28 +20,26 @@
#ifndef __WEECHAT_ALIAS_H
#define __WEECHAT_ALIAS_H 1
#include "../protocols/irc/irc.h"
#include "../gui/gui-buffer.h"
typedef struct t_weechat_alias t_weechat_alias;
struct t_weechat_alias
struct alias
{
char *alias_name;
char *alias_command;
char *name;
char *command;
int running;
t_weechat_alias *prev_alias;
t_weechat_alias *next_alias;
struct alias *prev_alias;
struct alias *next_alias;
};
extern t_weechat_alias *weechat_alias;
extern t_weechat_alias *weechat_last_alias;
extern struct alias *weechat_alias;
extern struct alias *weechat_last_alias;
extern t_weechat_alias *alias_search (char *);
extern t_weechat_alias *alias_new (char *, char *);
extern char *alias_get_final_command (t_weechat_alias *);
extern struct alias *alias_search (char *);
extern struct alias *alias_new (char *, char *);
extern char *alias_get_final_command (struct alias *);
extern char *alias_replace_args (char *, char *);
extern char *alias_replace_vars (t_irc_server *, t_irc_channel *, char *);
extern void alias_free (t_weechat_alias *);
extern char *alias_replace_vars (struct t_gui_buffer *, char *);
extern void alias_free (struct alias *);
extern void alias_free_all ();
#endif /* alias.h */
#endif /* wee-alias.h */
+5 -5
View File
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* backtrace.c: display backtrace after a segfault */
/* wee-backtrace.c: display backtrace after a segfault */
#ifdef HAVE_CONFIG_H
@@ -39,9 +39,9 @@
#endif
#include "weechat.h"
#include "backtrace.h"
#include "log.h"
#include "util.h"
#include "wee-backtrace.h"
#include "wee-log.h"
#include "wee-string.h"
/*
@@ -58,7 +58,7 @@ weechat_backtrace_printf (char *message, ...)
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
va_end (argptr);
weechat_iconv_fprintf (stderr, "%s", buffer);
string_iconv_fprintf (stderr, "%s", buffer);
weechat_log_printf ("%s", buffer);
}
+1 -1
View File
@@ -24,4 +24,4 @@
extern void weechat_backtrace ();
#endif /* backtrace.h */
#endif /* wee-backtrace.h */
+1173 -3229
View File
File diff suppressed because it is too large Load Diff
+42 -54
View File
@@ -20,67 +20,55 @@
#ifndef __WEECHAT_COMMAND_H
#define __WEECHAT_COMMAND_H 1
#include "weelist.h"
#include "../protocols/irc/irc.h"
#include "../gui/gui.h"
#include "../gui/gui-buffer.h"
#define MAX_ARGS 8192
typedef struct t_weechat_command t_weechat_command;
struct t_weechat_command
struct command
{
char *command_name; /* WeeChat (internal) command name */
char *command_description; /* command description (for /help) */
char *arguments; /* command arguments (for /help) */
char *arguments_description; /* arguments description (for /help) */
char *completion_template; /* template for completion */
/* NULL=no completion, ""=default (nick) */
int min_arg, max_arg; /* min & max number of arguments */
int conversion; /* = 1 if cmd args are converted (charset */
/* and color) before execution */
int (*cmd_function_args)(t_irc_server *, t_irc_channel *, int, char **);
/* function called when user enters cmd */
int (*cmd_function_1arg)(t_irc_server *, t_irc_channel *, char *);
/* function called when user enters cmd */
char *name; /* WeeChat (internal) command name */
char *description; /* command description (for /help) */
char *arguments; /* command arguments (for /help) */
char *arguments_description; /* arguments description (for /help) */
char *completion_template; /* template for completion */
/* NULL=no completion, ""=default (nick) */
int min_arg, max_arg; /* min & max number of arguments */
int conversion; /* = 1 if cmd args are converted (charset*/
/* and color) before execution */
int (*cmd_function)(struct t_gui_buffer *, char *, int, char **);
/* function called when user enters cmd */
};
extern t_weechat_command weechat_commands[];
extern t_weelist *index_commands;
extern t_weelist *last_index_command;
extern struct command weechat_commands[];
struct t_weelist *weechat_index_commands;
struct t_weelist *weechat_last_index_command;
extern int command_command_is_used (char *);
extern void command_index_build ();
extern void command_index_free ();
extern int command_used_by_weechat (char *);
extern char **split_multi_command (char *, char);
extern void free_multi_command (char **);
extern int exec_weechat_command (t_irc_server *, t_irc_channel *, char *, int);
extern void user_command (t_irc_server *, t_irc_channel *, char *, int);
extern int weechat_cmd_alias (t_irc_server *, t_irc_channel *, char *);
extern int weechat_cmd_buffer (t_irc_server *, t_irc_channel *, char *);
extern int weechat_cmd_builtin (t_irc_server *, t_irc_channel *, char *);
extern int weechat_cmd_clear (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_connect (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_dcc (t_irc_server *, t_irc_channel *, char *);
extern int weechat_cmd_debug (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_disconnect (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_help (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_history (t_irc_server *, t_irc_channel *, int, char **);
extern void weechat_cmd_ignore_display (char *, t_irc_ignore *);
extern int weechat_cmd_ignore (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_key (t_irc_server *, t_irc_channel *, char *);
extern int weechat_cmd_panel (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_plugin (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_reconnect (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_save (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_server (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_set (t_irc_server *, t_irc_channel *, char *);
extern int weechat_cmd_setp (t_irc_server *, t_irc_channel *, char *);
extern int weechat_cmd_unalias (t_irc_server *, t_irc_channel *, char *);
extern int weechat_cmd_unignore (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_upgrade (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_uptime (t_irc_server *, t_irc_channel *, int, char **);
extern int weechat_cmd_window (t_irc_server *, t_irc_channel *, int, char **);
extern void command_index_add (char *);
extern void command_index_remove (char *);
extern int command_is_command (char *);
extern void command_print_stdout (struct command *);
#endif /* command.h */
extern int command_alias (struct t_gui_buffer *, char *, int, char **);
extern int command_buffer (struct t_gui_buffer *, char *, int, char **);
extern int command_builtin (struct t_gui_buffer *, char *, int, char **);
extern int command_clear (struct t_gui_buffer *, char *, int, char **);
extern int command_debug (struct t_gui_buffer *, char *, int, char **);
extern int command_help (struct t_gui_buffer *, char *, int, char **);
extern int command_history (struct t_gui_buffer *, char *, int, char **);
extern int command_key (struct t_gui_buffer *, char *, int, char **);
extern int command_panel (struct t_gui_buffer *, char *, int, char **);
extern int command_plugin (struct t_gui_buffer *, char *, int, char **);
extern int command_quit (struct t_gui_buffer *, char *, int, char **);
extern int command_save (struct t_gui_buffer *, char *, int, char **);
extern int command_set (struct t_gui_buffer *, char *, int, char **);
extern int command_setp (struct t_gui_buffer *, char *, int, char **);
extern int command_unalias (struct t_gui_buffer *, char *, int, char **);
extern int command_unignore (struct t_gui_buffer *, char *, int, char **);
extern int command_upgrade (struct t_gui_buffer *, char *, int, char **);
extern int command_uptime (struct t_gui_buffer *, char *, int, char **);
extern int command_window (struct t_gui_buffer *, char *, int, char **);
#endif /* wee-command.h */
+892 -2219
View File
File diff suppressed because it is too large Load Diff
+89 -169
View File
@@ -20,42 +20,21 @@
#ifndef __WEECHAT_CONFIG_H
#define __WEECHAT_CONFIG_H 1
#include "../protocols/irc/irc.h"
#include "wee-config-option.h"
#include "wee-config-file.h"
#include "../gui/gui-chat.h"
#include "../gui/gui-color.h"
#define WEECHAT_CONFIG_NAME "weechat.rc"
#define CONFIG_SECTION_NONE -1
#define CONFIG_SECTION_LOOK 0
#define CONFIG_SECTION_COLORS 1
#define CONFIG_SECTION_HISTORY 2
#define CONFIG_SECTION_LOG 3
#define CONFIG_SECTION_IRC 4
#define CONFIG_SECTION_DCC 5
#define CONFIG_SECTION_PROXY 6
#define CONFIG_SECTION_PLUGINS 7
#define CONFIG_SECTION_KEYS 8
#define CONFIG_SECTION_ALIAS 9
#define CONFIG_SECTION_IGNORE 10
#define CONFIG_SECTION_SERVER 11
#define CONFIG_NUMBER_SECTIONS 12
#define OPTION_TYPE_BOOLEAN 1 /* values: on/off */
#define OPTION_TYPE_INT 2 /* values: from min to max */
#define OPTION_TYPE_INT_WITH_STRING 3 /* values: one from **array_values */
#define OPTION_TYPE_COLOR 4 /* values: a color name */
#define OPTION_TYPE_STRING 5 /* values: any string, may be empty */
#define BOOL_FALSE 0
#define BOOL_TRUE 1
#define CFG_LOOK_NICKLIST_LEFT 0
#define CFG_LOOK_NICKLIST_RIGHT 1
#define CFG_LOOK_NICKLIST_TOP 2
#define CFG_LOOK_NICKLIST_BOTTOM 3
#define CFG_LOOK_ALIGN_NICK_NONE 0
#define CFG_LOOK_ALIGN_NICK_LEFT 1
#define CFG_LOOK_ALIGN_NICK_RIGHT 2
#define CFG_LOOK_PREFIX_ALIGN_NONE 0
#define CFG_LOOK_PREFIX_ALIGN_LEFT 1
#define CFG_LOOK_PREFIX_ALIGN_RIGHT 2
#define CFG_LOOK_HOTLIST_SORT_GROUP_TIME_ASC 0
#define CFG_LOOK_HOTLIST_SORT_GROUP_TIME_DESC 1
@@ -64,35 +43,8 @@
#define CFG_LOOK_HOTLIST_SORT_NUMBER_ASC 4
#define CFG_LOOK_HOTLIST_SORT_NUMBER_DESC 5
#define CFG_IRC_DISPLAY_AWAY_OFF 0
#define CFG_IRC_DISPLAY_AWAY_LOCAL 1
#define CFG_IRC_DISPLAY_AWAY_CHANNEL 2
typedef struct t_config_section t_config_section;
struct t_config_section
{
int section_number;
char *section_name;
};
typedef struct t_config_option t_config_option;
struct t_config_option
{
char *option_name;
char *short_description;
char *long_description;
int option_type;
int min, max;
int default_int;
char *default_string;
char **array_values;
int *ptr_int;
char **ptr_string;
void (*handler_change)();
};
extern struct t_config_option weechat_options_look[];
extern int cfg_look_color_real_white;
extern int cfg_look_save_on_exit;
extern int cfg_look_set_title;
extern int cfg_look_startup_logo;
@@ -101,7 +53,7 @@ extern char *cfg_look_weechat_slogan;
extern int cfg_look_one_server_buffer;
extern int cfg_look_open_near_server;
extern int cfg_look_scroll_amount;
extern char *cfg_look_buffer_timestamp;
extern char *cfg_look_buffer_time_format;
extern int cfg_look_color_nicks_number;
extern int cfg_look_color_actions;
extern int cfg_look_nicklist;
@@ -112,19 +64,17 @@ extern int cfg_look_nicklist_separator;
extern int cfg_look_nickmode;
extern int cfg_look_nickmode_empty;
extern char *cfg_look_no_nickname;
extern char *cfg_look_nick_prefix;
extern char *cfg_look_nick_suffix;
extern int cfg_look_align_nick;
extern int cfg_look_align_other;
extern int cfg_look_align_size;
extern int cfg_look_align_size_max;
extern char *cfg_look_prefix[GUI_CHAT_PREFIX_NUMBER];
extern int cfg_look_prefix_align;
extern int cfg_look_prefix_align_max;
extern char *cfg_look_prefix_suffix;
extern int cfg_look_align_text_offset;
extern char *cfg_look_nick_completor;
extern char *cfg_look_nick_completion_ignore;
extern int cfg_look_nick_completion_smart;
extern int cfg_look_nick_complete_first;
extern int cfg_look_infobar;
extern char *cfg_look_infobar_timestamp;
extern char *cfg_look_infobar_time_format;
extern int cfg_look_infobar_seconds;
extern int cfg_look_infobar_delay_highlight;
extern int cfg_look_hotlist_names_count;
@@ -132,33 +82,37 @@ extern int cfg_look_hotlist_names_level;
extern int cfg_look_hotlist_names_length;
extern int cfg_look_hotlist_sort;
extern int cfg_look_day_change;
extern char *cfg_look_day_change_timestamp;
extern char *cfg_look_day_change_time_format;
extern char *cfg_look_read_marker;
extern char *cfg_look_input_format;
extern int cfg_look_paste_max_lines;
extern int cfg_col_real_white;
extern struct t_config_option weechat_options_colors[];
extern int cfg_col_separator;
extern int cfg_col_title;
extern int cfg_col_title_more;
extern int cfg_col_title_bg;
extern int cfg_col_title_more;
extern int cfg_col_chat;
extern int cfg_col_chat_time;
extern int cfg_col_chat_time_sep;
extern int cfg_col_chat_prefix1;
extern int cfg_col_chat_prefix2;
extern int cfg_col_chat_server;
extern int cfg_col_chat_join;
extern int cfg_col_chat_part;
extern int cfg_col_chat_nick;
extern int cfg_col_chat_host;
extern int cfg_col_chat_channel;
extern int cfg_col_chat_dark;
extern int cfg_col_chat_highlight;
extern int cfg_col_chat_bg;
extern int cfg_col_chat_time;
extern int cfg_col_chat_time_delimiters;
extern int cfg_col_chat_prefix[GUI_CHAT_PREFIX_NUMBER];
extern int cfg_col_chat_prefix_more;
extern int cfg_col_chat_prefix_suffix;
extern int cfg_col_chat_buffer;
extern int cfg_col_chat_server;
extern int cfg_col_chat_channel;
extern int cfg_col_chat_nick;
extern int cfg_col_chat_nick_self;
extern int cfg_col_chat_nick_other;
extern int cfg_col_chat_nick_colors[GUI_COLOR_NICK_NUMBER];
extern int cfg_col_chat_host;
extern int cfg_col_chat_delimiters;
extern int cfg_col_chat_highlight;
extern int cfg_col_chat_read_marker;
extern int cfg_col_chat_read_marker_bg;
extern int cfg_col_status;
extern int cfg_col_status_bg;
extern int cfg_col_status_delimiters;
extern int cfg_col_status_channel;
extern int cfg_col_status_data_msg;
@@ -166,83 +120,49 @@ extern int cfg_col_status_data_private;
extern int cfg_col_status_data_highlight;
extern int cfg_col_status_data_other;
extern int cfg_col_status_more;
extern int cfg_col_status_bg;
extern int cfg_col_infobar;
extern int cfg_col_infobar_bg;
extern int cfg_col_infobar_delimiters;
extern int cfg_col_infobar_highlight;
extern int cfg_col_infobar_bg;
extern int cfg_col_input;
extern int cfg_col_input_bg;
extern int cfg_col_input_server;
extern int cfg_col_input_channel;
extern int cfg_col_input_nick;
extern int cfg_col_input_delimiters;
extern int cfg_col_input_text_not_found;
extern int cfg_col_input_actions;
extern int cfg_col_input_bg;
extern int cfg_col_nick;
extern int cfg_col_nick_away;
extern int cfg_col_nick_chanowner;
extern int cfg_col_nick_chanadmin;
extern int cfg_col_nick_op;
extern int cfg_col_nick_halfop;
extern int cfg_col_nick_voice;
extern int cfg_col_nick_user;
extern int cfg_col_nick_more;
extern int cfg_col_nick_sep;
extern int cfg_col_nick_self;
extern int cfg_col_nick_colors[GUI_COLOR_WIN_NICK_NUMBER];
extern int cfg_col_nick_private;
extern int cfg_col_nick_bg;
extern int cfg_col_dcc_selected;
extern int cfg_col_dcc_waiting;
extern int cfg_col_dcc_connecting;
extern int cfg_col_dcc_active;
extern int cfg_col_dcc_done;
extern int cfg_col_dcc_failed;
extern int cfg_col_dcc_aborted;
extern int cfg_col_nicklist;
extern int cfg_col_nicklist_bg;
extern int cfg_col_nicklist_away;
extern int cfg_col_nicklist_prefix1;
extern int cfg_col_nicklist_prefix2;
extern int cfg_col_nicklist_prefix3;
extern int cfg_col_nicklist_prefix4;
extern int cfg_col_nicklist_prefix5;
extern int cfg_col_nicklist_more;
extern int cfg_col_nicklist_separator;
extern int cfg_col_info;
extern int cfg_col_info_bg;
extern int cfg_col_info_waiting;
extern int cfg_col_info_connecting;
extern int cfg_col_info_active;
extern int cfg_col_info_done;
extern int cfg_col_info_failed;
extern int cfg_col_info_aborted;
extern struct t_config_option weechat_options_history[];
extern int cfg_history_max_lines;
extern int cfg_history_max_commands;
extern int cfg_history_display_default;
extern int cfg_log_auto_server;
extern int cfg_log_auto_channel;
extern int cfg_log_auto_private;
extern struct t_config_option weechat_options_log[];
extern int cfg_log_plugin_msg;
extern char *cfg_log_path;
extern char *cfg_log_timestamp;
extern int cfg_log_hide_nickserv_pwd;
extern int cfg_irc_display_away;
extern int cfg_irc_show_away_once;
extern char *cfg_irc_default_msg_part;
extern char *cfg_irc_default_msg_quit;
extern int cfg_irc_notice_as_pv;
extern int cfg_irc_away_check;
extern int cfg_irc_away_check_max_nicks;
extern int cfg_irc_lag_check;
extern int cfg_irc_lag_min_show;
extern int cfg_irc_lag_disconnect;
extern int cfg_irc_anti_flood;
extern int cfg_irc_fifo_pipe;
extern char *cfg_irc_highlight;
extern int cfg_irc_colors_receive;
extern int cfg_irc_colors_send;
extern int cfg_irc_send_unknown_commands;
extern int cfg_dcc_auto_accept_files;
extern int cfg_dcc_auto_accept_chats;
extern int cfg_dcc_timeout;
extern int cfg_dcc_blocksize;
extern int cfg_dcc_fast_send;
extern char *cfg_dcc_port_range;
extern char *cfg_dcc_own_ip;
extern char *cfg_dcc_download_path;
extern char *cfg_dcc_upload_path;
extern int cfg_dcc_convert_spaces;
extern int cfg_dcc_auto_rename;
extern int cfg_dcc_auto_resume;
extern char *cfg_log_time_format;
extern struct t_config_option weechat_options_proxy[];
extern int cfg_proxy_use;
extern int cfg_proxy_type;
extern char *cfg_proxy_type_values[];
@@ -252,40 +172,40 @@ extern int cfg_proxy_port;
extern char *cfg_proxy_username;
extern char *cfg_proxy_password;
extern struct t_config_option weechat_options_plugins[];
extern char *cfg_plugins_path;
extern char *cfg_plugins_autoload;
extern char *cfg_plugins_extension;
extern t_config_section config_sections [CONFIG_NUMBER_SECTIONS];
extern t_config_option * weechat_options [CONFIG_NUMBER_SECTIONS];
extern char *weechat_config_sections[];
extern struct t_config_option *weechat_config_options[];
extern char *config_get_section ();
extern void config_change_noop ();
extern void config_change_save_on_exit ();
extern void config_change_title ();
extern void config_change_buffers ();
extern void config_change_buffer_content ();
extern void config_change_hotlist ();
extern void config_change_read_marker ();
extern void config_change_charset ();
extern void config_change_one_server_buffer ();
extern void config_change_color ();
extern void config_change_nicks_colors ();
extern void config_change_away_check ();
extern void config_change_fifo_pipe ();
extern void config_change_notify_levels ();
extern void config_change_log ();
extern int config_option_set_value (t_config_option *, char *);
extern void config_option_list_remove (char **, char *);
extern void config_option_list_set (char **, char *, char *);
extern void config_option_list_get_value (char **, char *, char **, int *);
extern t_config_option *config_option_search (char *);
extern void config_option_search_option_value (char *, t_config_option **, void **);
extern int config_set_value (char *, char *);
extern void *config_get_server_option_ptr (t_irc_server *, char *);
extern int config_set_server_value (t_irc_server *, char *, char *);
extern int config_read ();
extern int config_create_default ();
extern int config_write ();
extern void weechat_config_change_noop ();
extern void weechat_config_change_save_on_exit ();
extern void weechat_config_change_title ();
extern void weechat_config_change_buffers ();
extern void weechat_config_change_buffer_content ();
extern void weechat_config_change_buffer_time_format ();
extern void weechat_config_change_hotlist ();
extern void weechat_config_change_read_marker ();
extern void weechat_config_change_prefix ();
extern void weechat_config_change_charset ();
extern void weechat_config_change_color ();
extern void weechat_config_change_nicks_colors ();
extern void weechat_config_change_away_check ();
extern void weechat_config_change_fifo_pipe ();
extern void weechat_config_change_log ();
#endif /* weeconfig.h */
extern int weechat_config_read_alias (struct t_config_option *, char *, char *);
extern int weechat_config_read_key (struct t_config_option *, char *, char *);
extern int weechat_config_write_alias (FILE *, char *, struct t_config_option *);
extern int weechat_config_write_keys (FILE *, char *, struct t_config_option *);
extern int weechat_config_write_alias_default_values (FILE *, char *,
struct t_config_option *);
extern int weechat_config_write_keys_default_values (FILE *, char *,
struct t_config_option *);
extern int weechat_config_read ();
extern int weechat_config_write ();
extern void weechat_config_print_stdout ();
#endif /* wee-config.h */
+35 -31
View File
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* weelist.c: sorted lists management */
/* wee-list.c: sorted lists management */
#ifdef HAVE_CONFIG_H
@@ -27,9 +27,9 @@
#include <string.h>
#include "weechat.h"
#include "weelist.h"
#include "log.h"
#include "util.h"
#include "wee-list.h"
#include "wee-log.h"
#include "wee-string.h"
/*
@@ -37,14 +37,15 @@
*/
int
weelist_get_size (t_weelist *weelist)
weelist_get_size (struct t_weelist *weelist)
{
t_weelist *ptr_weelist;
struct t_weelist *ptr_weelist;
int count;
count = 0;
for (ptr_weelist = weelist; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist)
for (ptr_weelist = weelist; ptr_weelist;
ptr_weelist = ptr_weelist->next_weelist)
{
count++;
}
@@ -53,17 +54,18 @@ weelist_get_size (t_weelist *weelist)
}
/*
* weelist_search: search date in a list
* weelist_search: search data in a list
*/
t_weelist *
weelist_search (t_weelist *weelist, char *data)
struct t_weelist *
weelist_search (struct t_weelist *weelist, char *data)
{
t_weelist *ptr_weelist;
struct t_weelist *ptr_weelist;
for (ptr_weelist = weelist; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist)
for (ptr_weelist = weelist; ptr_weelist;
ptr_weelist = ptr_weelist->next_weelist)
{
if (ascii_strcasecmp (data, ptr_weelist->data) == 0)
if (string_strcasecmp (data, ptr_weelist->data) == 0)
return ptr_weelist;
}
/* word not found in list */
@@ -74,14 +76,15 @@ weelist_search (t_weelist *weelist, char *data)
* weelist_find_pos: find position for data (keeping list sorted)
*/
t_weelist *
weelist_find_pos (t_weelist *weelist, char *data)
struct t_weelist *
weelist_find_pos (struct t_weelist *weelist, char *data)
{
t_weelist *ptr_weelist;
struct t_weelist *ptr_weelist;
for (ptr_weelist = weelist; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist)
for (ptr_weelist = weelist; ptr_weelist;
ptr_weelist = ptr_weelist->next_weelist)
{
if (ascii_strcasecmp (data, ptr_weelist->data) < 0)
if (string_strcasecmp (data, ptr_weelist->data) < 0)
return ptr_weelist;
}
/* position not found, best position is at the end */
@@ -93,10 +96,10 @@ weelist_find_pos (t_weelist *weelist, char *data)
*/
void
weelist_insert (t_weelist **weelist, t_weelist **last_weelist, t_weelist *element,
int position)
weelist_insert (struct t_weelist **weelist, struct t_weelist **last_weelist,
struct t_weelist *element, int position)
{
t_weelist *pos_weelist;
struct t_weelist *pos_weelist;
if (*weelist)
{
@@ -156,16 +159,16 @@ weelist_insert (t_weelist **weelist, t_weelist **last_weelist, t_weelist *elemen
* weelist_add: create new data and add it to list
*/
t_weelist *
weelist_add (t_weelist **weelist, t_weelist **last_weelist, char *data,
int position)
struct t_weelist *
weelist_add (struct t_weelist **weelist, struct t_weelist **last_weelist,
char *data, int position)
{
t_weelist *new_weelist;
struct t_weelist *new_weelist;
if (!data || (!data[0]))
return NULL;
if ((new_weelist = ((t_weelist *) malloc (sizeof (t_weelist)))))
if ((new_weelist = ((struct t_weelist *) malloc (sizeof (struct t_weelist)))))
{
new_weelist->data = strdup (data);
weelist_insert (weelist, last_weelist, new_weelist, position);
@@ -180,9 +183,10 @@ weelist_add (t_weelist **weelist, t_weelist **last_weelist, char *data,
*/
void
weelist_remove (t_weelist **weelist, t_weelist **last_weelist, t_weelist *element)
weelist_remove (struct t_weelist **weelist, struct t_weelist **last_weelist,
struct t_weelist *element)
{
t_weelist *new_weelist;
struct t_weelist *new_weelist;
if (!element || !(*weelist))
return;
@@ -213,7 +217,7 @@ weelist_remove (t_weelist **weelist, t_weelist **last_weelist, t_weelist *elemen
*/
void
weelist_remove_all (t_weelist **weelist, t_weelist **last_weelist)
weelist_remove_all (struct t_weelist **weelist, struct t_weelist **last_weelist)
{
while (*weelist)
{
@@ -226,9 +230,9 @@ weelist_remove_all (t_weelist **weelist, t_weelist **last_weelist)
*/
void
weelist_print_log (t_weelist *weelist, char *name)
weelist_print_log (struct t_weelist *weelist, char *name)
{
t_weelist *ptr_weelist;
struct t_weelist *ptr_weelist;
for (ptr_weelist = weelist; ptr_weelist;
ptr_weelist = ptr_weelist->next_weelist)
+9 -11
View File
@@ -24,20 +24,18 @@
#define WEELIST_POS_BEGINNING 1
#define WEELIST_POS_END 2
typedef struct t_weelist t_weelist;
struct t_weelist
{
char *data;
t_weelist *prev_weelist;
t_weelist *next_weelist;
struct t_weelist *prev_weelist;
struct t_weelist *next_weelist;
};
extern int weelist_get_size (t_weelist *);
extern t_weelist *weelist_search (t_weelist *, char *);
extern t_weelist *weelist_add (t_weelist **, t_weelist **, char *, int);
extern void weelist_remove (t_weelist **, t_weelist **, t_weelist *);
extern void weelist_remove_all (t_weelist **, t_weelist **);
extern void weelist_print_log (t_weelist *, char *);
extern int weelist_get_size (struct t_weelist *);
extern struct t_weelist *weelist_search (struct t_weelist *, char *);
extern struct t_weelist *weelist_add (struct t_weelist **, struct t_weelist **, char *, int);
extern void weelist_remove (struct t_weelist **, struct t_weelist **, struct t_weelist *);
extern void weelist_remove_all (struct t_weelist **, struct t_weelist **);
extern void weelist_print_log (struct t_weelist *, char *);
#endif /* weelist.h */
#endif /* wee-list.h */
+15 -15
View File
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* log.c: WeeChat log file */
/* wee-log.c: WeeChat log file */
#ifdef HAVE_CONFIG_H
@@ -37,8 +37,8 @@
#include <time.h>
#include "weechat.h"
#include "log.h"
#include "util.h"
#include "wee-log.h"
#include "wee-string.h"
char *weechat_log_filename = NULL; /* log name (~/.weechat/weechat.log) */
@@ -103,11 +103,11 @@ weechat_log_init ()
{
if (!weechat_log_open (NULL, "w"))
{
weechat_iconv_fprintf (stderr,
_("%s unable to create/append to log file (weechat.log)\n"
"If another WeeChat process is using this file, try to run WeeChat\n"
"with another home using \"--dir\" command line option.\n"),
WEECHAT_ERROR);
string_iconv_fprintf (stderr,
_("%s unable to create/append to log file (weechat.log)\n"
"If another WeeChat process is using this file, try to run WeeChat\n"
"with another home using \"--dir\" command line option.\n"),
WEECHAT_ERROR);
exit (1);
}
}
@@ -146,12 +146,12 @@ weechat_log_printf (char *message, ...)
seconds = time (NULL);
date_tmp = localtime (&seconds);
if (date_tmp)
weechat_iconv_fprintf (weechat_log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
buffer);
string_iconv_fprintf (weechat_log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
buffer);
else
weechat_iconv_fprintf (weechat_log_file, "%s", buffer);
string_iconv_fprintf (weechat_log_file, "%s", buffer);
fflush (weechat_log_file);
}
@@ -217,8 +217,8 @@ weechat_log_crash_rename ()
getpid());
if (rename (old_name, new_name) == 0)
{
weechat_iconv_fprintf (stderr, "*** Full crash dump was saved to %s file.\n",
new_name);
string_iconv_fprintf (stderr, "*** Full crash dump was saved to %s file.\n",
new_name);
weechat_log_open (new_name, "a");
free (old_name);
free (new_name);
+1 -1
View File
@@ -28,4 +28,4 @@ extern void weechat_log_close ();
extern void weechat_log_printf (char *, ...);
extern int weechat_log_crash_rename ();
#endif /* log.h */
#endif /* wee-log.h */
+102 -104
View File
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* session.c: save/restore session data */
/* wee-session.c: save/restore session data */
#ifdef HAVE_CONFIG_H
@@ -29,24 +29,23 @@
#include <stdarg.h>
#include <string.h>
#ifdef HAVE_GNUTLS
/*#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>
#endif
#endif*/
#include "weechat.h"
#include "session.h"
#include "hotlist.h"
#include "log.h"
#include "utf8.h"
#include "util.h"
#include "../protocols/irc/irc.h"
#include "../gui/gui.h"
#include "wee-session.h"
#include "wee-log.h"
#include "wee-string.h"
#include "wee-utf8.h"
#include "../gui/gui-chat.h"
#include "../gui/gui-main.h"
/* current server/channel (used when loading session) */
t_irc_server *session_current_server = NULL;
/*t_irc_server *session_current_server = NULL;
t_irc_channel *session_current_channel = NULL;
t_gui_buffer *session_current_buffer = NULL;
t_gui_buffer *session_current_buffer = NULL;*/
long session_last_read_pos = 0;
int session_last_read_length = 0;
@@ -140,7 +139,7 @@ session_write_buf (FILE *file, int id, void *buffer, int size)
* session_save_nick: save a nick into session file
*/
int
/*int
session_save_nick (FILE *file, t_irc_nick *nick)
{
int rc;
@@ -153,13 +152,13 @@ session_save_nick (FILE *file, t_irc_nick *nick)
rc = rc && (session_write_str (file, SESSION_NICK_HOST, nick->host));
rc = rc && (session_write_id (file, SESSION_NICK_END));
return rc;
}
}*/
/*
* session_save_channel: save a channel into session file
*/
int
/*int
session_save_channel (FILE *file, t_irc_channel *channel)
{
int rc;
@@ -192,13 +191,13 @@ session_save_channel (FILE *file, t_irc_channel *channel)
}
return 1;
}
}*/
/*
* session_save_servers: save all servers into session file
*/
int
/*int
session_save_servers (FILE *file)
{
int rc;
@@ -281,13 +280,13 @@ session_save_servers (FILE *file)
}
}
return 1;
}
}*/
/*
* session_save_dcc: save all DCC into session file
*/
int
/*int
session_save_dcc (FILE *file)
{
int rc;
@@ -332,14 +331,14 @@ session_save_dcc (FILE *file)
return 0;
}
return 1;
}
}*/
/*
* session_save_history: save history into session file
* (from last to first, to restore it in good order)
*/
int
/*int
session_save_history (FILE *file, t_history *last_history)
{
int rc;
@@ -355,13 +354,13 @@ session_save_history (FILE *file, t_history *last_history)
}
rc = rc && (session_write_id (file, SESSION_HIST_END));
return rc;
}
}*/
/*
* session_save_line: save a buffer line into session file
*/
int
/*int
session_save_line (FILE *file, t_gui_line *line)
{
int rc;
@@ -380,13 +379,13 @@ session_save_line (FILE *file, t_gui_line *line)
rc = rc && (session_write_buf (file, SESSION_LINE_DATE, &(line->date), sizeof (time_t)));
rc = rc && (session_write_id (file, SESSION_LINE_END));
return rc;
}
}*/
/*
* session_save_buffers: save all buffers into session file
*/
int
/*int
session_save_buffers (FILE *file)
{
int rc;
@@ -419,13 +418,13 @@ session_save_buffers (FILE *file)
return 0;
}
return 1;
}
}*/
/*
* session_save_uptime: save uptime into session file
*/
int
/*int
session_save_uptime (FILE *file)
{
int rc;
@@ -436,13 +435,13 @@ session_save_uptime (FILE *file)
rc = rc && (session_write_buf (file, SESSION_UPT_START_TIME, &weechat_start_time, sizeof (time_t)));
rc = rc && (session_write_id (file, SESSION_UPT_END));
return rc;
}
}*/
/*
* session_save_hotlist: save hotlist into session file
*/
int
/*int
session_save_hotlist (FILE *file)
{
int rc;
@@ -464,13 +463,13 @@ session_save_hotlist (FILE *file)
return 0;
}
return rc;
}
}*/
/*
* session_save: save current session
*/
int
/*int
session_save (char *filename)
{
FILE *file;
@@ -491,7 +490,7 @@ session_save (char *filename)
fclose (file);
return rc;
}
}*/
/* ========================================================================== */
@@ -511,21 +510,21 @@ session_crash (FILE *file, char *message, ...)
fclose (file);
gui_main_end ();
weechat_iconv_fprintf (stderr, "%s %s\n",
WEECHAT_ERROR, buffer);
weechat_iconv_fprintf (stderr,
_("Last operation with session file was at position %ld, "
"read of %d bytes\n"),
session_last_read_pos,
session_last_read_length);
weechat_iconv_fprintf (stderr,
_("Please send %s/%s, %s/%s and "
"above messages to WeeChat developers for support.\n"
"Be careful, private info may be in these files.\n"),
weechat_home,
WEECHAT_LOG_NAME,
weechat_home,
WEECHAT_SESSION_NAME);
string_iconv_fprintf (stderr, "%s %s\n",
WEECHAT_ERROR, buffer);
string_iconv_fprintf (stderr,
_("Last operation with session file was at position %ld, "
"read of %d bytes\n"),
session_last_read_pos,
session_last_read_length);
string_iconv_fprintf (stderr,
_("Please send %s/%s, %s/%s and "
"above messages to WeeChat developers for support.\n"
"Be careful, private info may be in these files.\n"),
weechat_home,
WEECHAT_LOG_NAME,
weechat_home,
WEECHAT_SESSION_NAME);
exit (EXIT_FAILURE);
}
@@ -818,7 +817,7 @@ session_read_ignore_object (FILE *file)
* session_load_server: load server from file
*/
int
/*int
session_load_server (FILE *file)
{
int object_id, rc;
@@ -829,7 +828,7 @@ session_load_server (FILE *file)
int session_size_int;
#endif
/* read server name */
// read server name
server_name = NULL;
if (!session_read_object (file, SESSION_SERV_NAME, SESSION_TYPE_STR, &server_name, 0))
{
@@ -837,7 +836,7 @@ session_load_server (FILE *file)
return 0;
}
/* use or allocate server */
// use or allocate server
weechat_log_printf (_("session: loading server \"%s\"\n"),
server_name);
session_current_server = irc_server_search (server_name);
@@ -858,7 +857,7 @@ session_load_server (FILE *file)
}
free (server_name);
/* read server values */
// read server values
rc = 1;
while (rc)
{
@@ -1036,33 +1035,33 @@ session_load_server (FILE *file)
}
}
return 0;
}
}*/
/*
* session_load_channel: load channel from file
*/
int
/*int
session_load_channel (FILE *file)
{
int object_id, rc, channel_type;
char *channel_name;
/* check if server is allocated for this channel */
// check if server is allocated for this channel
if (!session_current_server)
{
session_crash (file, _("channel found without server"));
return 0;
}
/* read channel type */
// read channel type
if (!session_read_object (file, SESSION_CHAN_TYPE, SESSION_TYPE_INT, &channel_type, 0))
{
session_crash (file, _("channel type not found"));
return 0;
}
/* read channel name */
// read channel name
channel_name = NULL;
if (!session_read_object (file, SESSION_CHAN_NAME, SESSION_TYPE_STR, &channel_name, 0))
{
@@ -1070,7 +1069,7 @@ session_load_channel (FILE *file)
return 0;
}
/* allocate channel */
// allocate channel
weechat_log_printf (_("session: loading channel \"%s\"\n"),
channel_name);
session_current_channel = irc_channel_new (session_current_server,
@@ -1083,7 +1082,7 @@ session_load_channel (FILE *file)
return 0;
}
/* read channel values */
// read channel values
rc = 1;
while (rc)
{
@@ -1112,7 +1111,7 @@ session_load_channel (FILE *file)
break;
case SESSION_CHAN_NICKS_COUNT:
rc = rc && (session_read_int (file, &(session_current_channel->nicks_count)));
/* will be incremented when adding nicks */
// will be incremented when adding nicks
session_current_channel->nicks_count = 0;
break;
case SESSION_CHAN_CHECKING_AWAY:
@@ -1139,27 +1138,27 @@ session_load_channel (FILE *file)
}
}
return 0;
}
}*/
/*
* session_load_nick: load nick from file
*/
int
/*int
session_load_nick (FILE *file)
{
int rc, object_id;
char *nick_name;
t_irc_nick *nick;
/* check if channel is allocated for this nick */
// check if channel is allocated for this nick
if (!session_current_channel)
{
session_crash (file, _("nick found without channel"));
return 0;
}
/* read nick name */
// read nick name
nick_name = NULL;
if (!session_read_object (file, SESSION_NICK_NICK, SESSION_TYPE_STR, &nick_name, 0))
{
@@ -1167,7 +1166,7 @@ session_load_nick (FILE *file)
return 0;
}
/* allocate nick */
// allocate nick
nick = irc_nick_new (session_current_server, session_current_channel,
nick_name, 0, 0, 0, 0, 0, 0, 0);
free (nick_name);
@@ -1177,7 +1176,7 @@ session_load_nick (FILE *file)
return 0;
}
/* read nick values */
// read nick values
rc = 1;
while (rc)
{
@@ -1210,13 +1209,13 @@ session_load_nick (FILE *file)
}
}
return 0;
}
}*/
/*
* session_load_dcc: load DCC from file
*/
int
/*int
session_load_dcc (FILE *file)
{
int object_id, rc;
@@ -1225,7 +1224,7 @@ session_load_dcc (FILE *file)
t_irc_server *ptr_server;
t_irc_channel *ptr_channel;
/* allocate DCC */
// allocate DCC
dcc = irc_dcc_alloc ();
if (!dcc)
{
@@ -1235,7 +1234,7 @@ session_load_dcc (FILE *file)
weechat_log_printf (_("session: loading DCC\n"));
/* read DCC values */
// read DCC values
ptr_server = NULL;
ptr_channel = NULL;
rc = 1;
@@ -1374,13 +1373,13 @@ session_load_dcc (FILE *file)
}
}
return 0;
}
}*/
/*
* session_load_history: load history from file (global or for a buffer)
*/
int
/*int
session_load_history (FILE *file)
{
int object_id, rc;
@@ -1391,7 +1390,7 @@ session_load_history (FILE *file)
else
weechat_log_printf (_("session: loading global history\n"));
/* read history values */
// read history values
rc = 1;
while (rc)
{
@@ -1411,9 +1410,9 @@ session_load_history (FILE *file)
if (!session_read_str_utf8 (file, &text))
return 0;
if (session_current_buffer)
history_buffer_add (session_current_buffer, text);
gui_history_buffer_add (session_current_buffer, text);
else
history_global_add (text);
gui_history_global_add (text);
free (text);
break;
default:
@@ -1425,13 +1424,13 @@ session_load_history (FILE *file)
}
}
return 0;
}
}*/
/*
* session_load_buffer: load buffer from file
*/
int
/*int
session_load_buffer (FILE *file)
{
int object_id, rc;
@@ -1440,7 +1439,7 @@ session_load_buffer (FILE *file)
t_irc_server *ptr_server;
t_irc_channel *ptr_channel;
/* read server name */
// read server name
server_name = NULL;
if (!session_read_object (file, SESSION_BUFF_SERVER, SESSION_TYPE_STR, &server_name, 0))
{
@@ -1448,7 +1447,7 @@ session_load_buffer (FILE *file)
return 0;
}
/* read channel name */
// read channel name
channel_name = NULL;
if (!session_read_object (file, SESSION_BUFF_CHANNEL, SESSION_TYPE_STR, &channel_name, 0))
{
@@ -1456,14 +1455,14 @@ session_load_buffer (FILE *file)
return 0;
}
/* read buffer type */
// read buffer type
if (!session_read_object (file, SESSION_BUFF_TYPE, SESSION_TYPE_INT, &buffer_type, 0))
{
session_crash (file, _("buffer type not found"));
return 0;
}
/* allocate buffer */
// allocate buffer
weechat_log_printf (_("session: loading buffer (server: %s, channel: %s, type: %d)\n"),
(server_name) ? server_name : "-",
(channel_name) ? channel_name : "-",
@@ -1490,7 +1489,8 @@ session_load_buffer (FILE *file)
}
}
session_current_buffer = gui_buffer_new (gui_windows, ptr_server,
session_current_buffer = gui_buffer_new (gui_windows, weechat_protocols,
ptr_server,
ptr_channel, buffer_type, 1);
if (!session_current_buffer)
{
@@ -1501,7 +1501,7 @@ session_load_buffer (FILE *file)
free (server_name);
free (channel_name);
/* read buffer values */
// read buffer values
rc = 1;
while (rc)
{
@@ -1528,26 +1528,26 @@ session_load_buffer (FILE *file)
}
}
return 0;
}
}*/
/*
* session_load_line: load buffer line from file
*/
int
/*int
session_load_line (FILE *file)
{
int object_id, rc;
t_gui_line *line;
/* check if buffer is allocated for this line */
// check if buffer is allocated for this line
if (!session_current_buffer)
{
session_crash (file, _("line found without buffer"));
return 0;
}
/* allocate line */
// allocate line
line = gui_buffer_line_new (session_current_buffer, time (NULL));
if (!line)
{
@@ -1555,7 +1555,7 @@ session_load_line (FILE *file)
return 0;
}
/* read line values */
// read line values
rc = 1;
while (rc)
{
@@ -1609,18 +1609,18 @@ session_load_line (FILE *file)
}
}
return 0;
}
}*/
/*
* session_load_uptime: load uptime from file
*/
int
/*int
session_load_uptime (FILE *file)
{
int object_id, rc;
/* read uptime values */
// read uptime values
rc = 1;
while (rc)
{
@@ -1647,13 +1647,13 @@ session_load_uptime (FILE *file)
}
}
return 0;
}
}*/
/*
* session_load_hotlist: load hotlist from file
*/
int
/*int
session_load_hotlist (FILE *file)
{
int object_id, rc;
@@ -1670,7 +1670,7 @@ session_load_hotlist (FILE *file)
ptr_server = NULL;
ptr_buffer = NULL;
/* read hotlist values */
// read hotlist values
rc = 1;
while (rc)
{
@@ -1712,13 +1712,13 @@ session_load_hotlist (FILE *file)
}
}
return 0;
}
}*/
/*
* session_load: load session from file
*/
int
/*int
session_load (char *filename)
{
FILE *file;
@@ -1838,7 +1838,7 @@ session_load (char *filename)
}
}
/* assign a buffer to all connected servers */
// assign a buffer to all connected servers
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
@@ -1853,15 +1853,13 @@ session_load (char *filename)
if (unlink (filename) < 0)
{
irc_display_prefix (NULL, gui_current_window->buffer, GUI_PREFIX_ERROR);
gui_printf_nolog (gui_current_window->buffer,
_("%s can't delete session file (%s)\n"),
WEECHAT_ERROR, filename);
gui_printf_error_nolog (gui_current_window->buffer,
_("%s can't delete session file (%s)\n"),
WEECHAT_WARNING, filename);
}
irc_display_prefix (NULL, gui_current_window->buffer, GUI_PREFIX_INFO);
gui_printf_nolog (gui_current_window->buffer,
_("Upgrade completed successfully\n"));
gui_printf_info_nolog (gui_current_window->buffer,
_("Upgrade completed successfully\n"));
return 1;
}
}*/
+1 -1
View File
@@ -202,4 +202,4 @@ enum t_session_hotlist
int session_save (char *filename);
int session_load (char *filename);
#endif /* session.h */
#endif /* wee-session.h */
+35 -10
View File
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* utf8.c: UTF-8 string functions for WeeChat */
/* wee-utf8.c: UTF-8 string functions for WeeChat */
#ifdef HAVE_CONFIG_H
@@ -27,9 +27,9 @@
#include <string.h>
#include "weechat.h"
#include "utf8.h"
#include "util.h"
#include "weeconfig.h"
#include "wee-utf8.h"
#include "wee-config.h"
#include "wee-string.h"
int local_utf8 = 0;
@@ -41,7 +41,7 @@ int local_utf8 = 0;
void
utf8_init ()
{
local_utf8 = (ascii_strcasecmp (local_charset, "UTF-8") == 0);
local_utf8 = (string_strcasecmp (local_charset, "UTF-8") == 0);
}
/*
@@ -260,7 +260,7 @@ utf8_strlen (char *string)
}
/*
* utf8_strnlen: return length of an UTF-8 string, for N bytes
* utf8_strnlen: return length of an UTF-8 string, for N bytes max in string
*/
int
@@ -283,11 +283,12 @@ utf8_strnlen (char *string, int bytes)
}
/*
* utf8_width_screen: return number of chars needed on screen to display UTF-8 string
* utf8_strlen_screen: return number of chars needed on screen to display
* UTF-8 string
*/
int
utf8_width_screen (char *string)
utf8_strlen_screen (char *string)
{
int length, num_char;
wchar_t *wstring;
@@ -314,6 +315,30 @@ utf8_width_screen (char *string)
return length;
}
/*
* utf8_char_size_screen: return number of chars needed on screen to display
* UTF-8 char
*/
int
utf8_char_size_screen (char *string)
{
int char_size;
char utf_char[16];
if (!string)
return 0;
char_size = utf8_char_size (string);
if (char_size == 0)
return 0;
memcpy (utf_char, string, char_size);
utf_char[char_size] = '\0';
return utf8_strlen_screen (utf_char);
}
/*
* utf8_add_offset: moves forward N chars in an UTF-8 string
*/
@@ -386,11 +411,11 @@ utf8_pos (char *string, int real_pos)
}
/*
* utf8_get_wc: get wide char from string (first char)
* utf8_get_wide_char: get wide char from string (first char)
*/
wint_t
utf8_get_wc (char *string)
utf8_get_wide_char (char *string)
{
int char_size;
wint_t result;
+4 -3
View File
@@ -41,10 +41,11 @@ extern char *utf8_next_char (char *);
extern int utf8_char_size (char *);
extern int utf8_strlen (char *);
extern int utf8_strnlen (char *, int);
extern int utf8_width_screen (char *);
extern int utf8_strlen_screen (char *);
extern int utf8_char_size_screen (char *);
extern char *utf8_add_offset (char *, int);
extern int utf8_real_pos (char *, int);
extern int utf8_pos (char *, int);
extern wint_t utf8_get_wc (char *);
extern wint_t utf8_get_wide_char (char *);
#endif /* utf8.h */
#endif /* wee-utf8.h */
+123 -646
View File
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* util.c: some useful functions for WeeChat */
/* wee-util.c: some useful functions for WeeChat */
#ifdef HAVE_CONFIG_H
@@ -25,501 +25,24 @@
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#ifdef HAVE_ICONV
#include <iconv.h>
#endif
#ifndef ICONV_CONST
#ifdef ICONV_2ARG_IS_CONST
#define ICONV_CONST const
#else
#define ICONV_CONST
#endif
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include "weechat.h"
#include "utf8.h"
#include "weeconfig.h"
#include "wee-util.h"
#include "wee-config.h"
#include "wee-string.h"
/*
* strndup: define strndup function if not existing (FreeBSD and maybe other)
*/
#ifndef HAVE_STRNDUP
char *
strndup (char *string, int length)
{
char *result;
if ((int)strlen (string) < length)
return strdup (string);
result = (char *)malloc (length + 1);
if (!result)
return NULL;
memcpy (result, string, length);
result[length] = '\0';
return result;
}
#endif
/*
* ascii_tolower: locale independant string conversion to lower case
*/
void
ascii_tolower (char *string)
{
while (string && string[0])
{
if ((string[0] >= 'A') && (string[0] <= 'Z'))
string[0] += ('a' - 'A');
string++;
}
}
/*
* ascii_toupper: locale independant string conversion to upper case
*/
void
ascii_toupper (char *string)
{
while (string && string[0])
{
if ((string[0] >= 'a') && (string[0] <= 'z'))
string[0] -= ('a' - 'A');
string++;
}
}
/*
* ascii_strcasecmp: locale and case independent string comparison
*/
int
ascii_strcasecmp (char *string1, char *string2)
{
int c1, c2;
if (!string1 || !string2)
return (string1) ? 1 : ((string2) ? -1 : 0);
while (string1[0] && string2[0])
{
c1 = (int)((unsigned char) string1[0]);
c2 = (int)((unsigned char) string2[0]);
if ((c1 >= 'A') && (c1 <= 'Z'))
c1 += ('a' - 'A');
if ((c2 >= 'A') && (c2 <= 'Z'))
c2 += ('a' - 'A');
if ((c1 - c2) != 0)
return c1 - c2;
string1++;
string2++;
}
return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
}
/*
* ascii_strncasecmp: locale and case independent string comparison
* with max length
*/
int
ascii_strncasecmp (char *string1, char *string2, int max)
{
int c1, c2, count;
if (!string1 || !string2)
return (string1) ? 1 : ((string2) ? -1 : 0);
count = 0;
while ((count < max) && string1[0] && string2[0])
{
c1 = (int)((unsigned char) string1[0]);
c2 = (int)((unsigned char) string2[0]);
if ((c1 >= 'A') && (c1 <= 'Z'))
c1 += ('a' - 'A');
if ((c2 >= 'A') && (c2 <= 'Z'))
c2 += ('a' - 'A');
if ((c1 - c2) != 0)
return c1 - c2;
string1++;
string2++;
count++;
}
if (count >= max)
return 0;
else
return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
}
/*
* ascii_strcasestr: locale and case independent string search
*/
char *
ascii_strcasestr (char *string, char *search)
{
int length_search;
length_search = strlen (search);
if (!string || !search || (length_search == 0))
return NULL;
while (string[0])
{
if (ascii_strncasecmp (string, search, length_search) == 0)
return string;
string++;
}
return NULL;
}
/*
* weechat_iconv: convert string to another charset
*/
char *
weechat_iconv (int from_utf8, char *from_code, char *to_code, char *string)
{
char *outbuf;
#ifdef HAVE_ICONV
iconv_t cd;
char *inbuf, *ptr_inbuf, *ptr_outbuf, *next_char;
char *ptr_inbuf_shift;
int done;
size_t err, inbytesleft, outbytesleft;
if (from_code && from_code[0] && to_code && to_code[0]
&& (ascii_strcasecmp(from_code, to_code) != 0))
{
cd = iconv_open (to_code, from_code);
if (cd == (iconv_t)(-1))
outbuf = strdup (string);
else
{
inbuf = strdup (string);
ptr_inbuf = inbuf;
inbytesleft = strlen (inbuf);
outbytesleft = inbytesleft * 4;
outbuf = (char *) malloc (outbytesleft + 2);
ptr_outbuf = outbuf;
ptr_inbuf_shift = NULL;
done = 0;
while (!done)
{
err = iconv (cd, (ICONV_CONST char **)(&ptr_inbuf), &inbytesleft,
&ptr_outbuf, &outbytesleft);
if (err == (size_t)(-1))
{
switch (errno)
{
case EINVAL:
done = 1;
break;
case E2BIG:
done = 1;
break;
case EILSEQ:
if (from_utf8)
{
next_char = utf8_next_char (ptr_inbuf);
if (next_char)
{
inbytesleft -= next_char - ptr_inbuf;
ptr_inbuf = next_char;
}
else
{
inbytesleft--;
ptr_inbuf++;
}
}
else
{
ptr_inbuf++;
inbytesleft--;
}
ptr_outbuf[0] = '?';
ptr_outbuf++;
outbytesleft--;
break;
}
}
else
{
if (!ptr_inbuf_shift)
{
ptr_inbuf_shift = ptr_inbuf;
ptr_inbuf = NULL;
inbytesleft = 0;
}
else
done = 1;
}
}
if (ptr_inbuf_shift)
ptr_inbuf = ptr_inbuf_shift;
ptr_outbuf[0] = '\0';
free (inbuf);
iconv_close (cd);
}
}
else
outbuf = strdup (string);
#else
/* make C compiler happy */
(void) from_utf8;
(void) from_code;
(void) to_code;
outbuf = strdup (string);
#endif /* HAVE_ICONV */
return outbuf;
}
/*
* weechat_iconv_to_internal: convert user string (input, script, ..) to
* WeeChat internal storage charset
*/
char *
weechat_iconv_to_internal (char *charset, char *string)
{
char *input, *output;
input = strdup (string);
/* optimize for UTF-8: if charset is NULL => we use term charset =>
if ths charset is already UTF-8, then no iconv needed */
if (local_utf8 && (!charset || !charset[0]))
return input;
if (input)
{
if (utf8_has_8bits (input) && utf8_is_valid (input, NULL))
return input;
output = weechat_iconv (0,
(charset && charset[0]) ?
charset : local_charset,
WEECHAT_INTERNAL_CHARSET,
input);
utf8_normalize (output, '?');
free (input);
return output;
}
return NULL;
}
/*
* weechat_iconv_from_internal: convert internal string to terminal charset,
* for display
*/
char *
weechat_iconv_from_internal (char *charset, char *string)
{
char *input, *output;
input = strdup (string);
/* optimize for UTF-8: if charset is NULL => we use term charset =>
if ths charset is already UTF-8, then no iconv needed */
if (local_utf8 && (!charset || !charset[0]))
return input;
if (input)
{
utf8_normalize (input, '?');
output = weechat_iconv (1,
WEECHAT_INTERNAL_CHARSET,
(charset && charset[0]) ?
charset : local_charset,
input);
free (input);
return output;
}
return NULL;
}
/*
* weechat_iconv_fprintf: encode to terminal charset, then call fprintf on a file
*/
void
weechat_iconv_fprintf (FILE *file, char *data, ...)
{
va_list argptr;
static char buf[4096];
char *buf2;
va_start (argptr, data);
vsnprintf (buf, sizeof (buf) - 1, data, argptr);
va_end (argptr);
buf2 = weechat_iconv_from_internal (NULL, buf);
fprintf (file, "%s", (buf2) ? buf2 : buf);
if (buf2)
free (buf2);
}
/*
* weechat_strreplace: replace a string by new one in a string
* note: returned value has to be free() after use
*/
char *
weechat_strreplace (char *string, char *search, char *replace)
{
char *pos, *new_string;
int length1, length2, length_new, count;
if (!string || !search || !replace)
return NULL;
length1 = strlen (search);
length2 = strlen (replace);
/* count number of strings to replace */
count = 0;
pos = string;
while (pos && pos[0] && (pos = strstr (pos, search)))
{
count++;
pos += length1;
}
/* easy: no string to replace! */
if (count == 0)
return strdup (string);
/* compute needed memory for new string */
length_new = strlen (string) - (count * length1) + (count * length2) + 1;
/* allocate new string */
new_string = (char *)malloc (length_new * sizeof (char));
if (!new_string)
return strdup (string);
/* replace all occurences */
new_string[0] = '\0';
while (string && string[0])
{
pos = strstr (string, search);
if (pos)
{
strncat (new_string, string, pos - string);
strcat (new_string, replace);
pos += length1;
}
else
strcat (new_string, string);
string = pos;
}
return new_string;
}
/*
* weechat_convert_hex_chars: convert hex chars (\x??) to value
*/
char *
weechat_convert_hex_chars (char *string)
{
char *output, hex_str[8], *error;
int pos_output;
long number;
output = (char *)malloc (strlen (string) + 1);
if (output)
{
pos_output = 0;
while (string && string[0])
{
if (string[0] == '\\')
{
string++;
switch (string[0])
{
case '\\':
output[pos_output++] = '\\';
string++;
break;
case 'x':
case 'X':
if (isxdigit (string[1])
&& isxdigit (string[2]))
{
snprintf (hex_str, sizeof (hex_str),
"0x%c%c", string[1], string[2]);
number = strtol (hex_str, &error, 16);
if ((error) && (error[0] == '\0'))
{
output[pos_output++] = number;
string += 3;
}
else
{
output[pos_output++] = '\\';
output[pos_output++] = string[0];
string++;
}
}
else
{
output[pos_output++] = string[0];
string++;
}
break;
default:
output[pos_output++] = '\\';
output[pos_output++] = string[0];
string++;
break;
}
}
else
{
output[pos_output++] = string[0];
string++;
}
}
output[pos_output] = '\0';
}
return output;
}
/*
* get_timeval_diff: calculates difference between two times (return in milliseconds)
* util_get_timeval_diff: calculates difference between two times (return in
* milliseconds)
*/
long
get_timeval_diff (struct timeval *tv1, struct timeval *tv2)
util_get_timeval_diff (struct timeval *tv1, struct timeval *tv2)
{
long diff_sec, diff_usec;
@@ -535,196 +58,150 @@ get_timeval_diff (struct timeval *tv1, struct timeval *tv2)
}
/*
* explode_string: explode a string according to separators
* util_get_time_length: calculates time length with a time format
*/
char **
explode_string (char *string, char *separators, int num_items_max,
int *num_items)
int
util_get_time_length (char *time_format)
{
int i, n_items;
char **array;
char *ptr, *ptr1, *ptr2;
time_t date;
struct tm *local_time;
char text_time[1024];
if (!time_format || !time_format[0])
return 0;
date = time (NULL);
local_time = localtime (&date);
strftime (text_time, sizeof (text_time),
time_format, local_time);
return strlen (text_time);
}
if (num_items != NULL)
*num_items = 0;
if (!string || !string[0])
return NULL;
/* calculate number of items */
ptr = string;
i = 1;
while ((ptr = strpbrk (ptr, separators)))
{
while (strchr (separators, ptr[0]) != NULL)
ptr++;
i++;
}
n_items = i;
if ((num_items_max != 0) && (n_items > num_items_max))
n_items = num_items_max;
array =
(char **) malloc ((n_items + 1) * sizeof (char *));
ptr1 = string;
ptr2 = string;
for (i = 0; i < n_items; i++)
/*
* util_create_dir: create a directory
* return: 1 if ok (or directory already exists)
* 0 if error
*/
int
util_create_dir (char *directory, int permissions)
{
if (mkdir (directory, 0755) < 0)
{
while (strchr (separators, ptr1[0]) != NULL)
ptr1++;
if (i == (n_items - 1) || (ptr2 = strpbrk (ptr1, separators)) == NULL)
if ((ptr2 = strchr (ptr1, '\r')) == NULL)
if ((ptr2 = strchr (ptr1, '\n')) == NULL)
ptr2 = strchr (ptr1, '\0');
if ((ptr1 == NULL) || (ptr2 == NULL))
/* exit if error (except if directory already exists) */
if (errno != EEXIST)
{
array[i] = NULL;
}
else
{
if (ptr2 - ptr1 > 0)
{
array[i] =
(char *) malloc ((ptr2 - ptr1 + 1) * sizeof (char));
array[i] = strncpy (array[i], ptr1, ptr2 - ptr1);
array[i][ptr2 - ptr1] = '\0';
ptr1 = ++ptr2;
}
else
{
array[i] = NULL;
}
string_iconv_fprintf (stderr,
_("%s cannot create directory \"%s\"\n"),
WEECHAT_ERROR, directory);
return 0;
}
return 1;
}
array[i] = NULL;
if (num_items != NULL)
*num_items = i;
return array;
if ((permissions != 0) && (strcmp (directory, getenv ("HOME")) != 0))
chmod (directory, permissions);
return 1;
}
/*
* free_exploded_string: free an exploded string
* util_exec_on_files: find files in a directory and execute a
* function on each file
*/
void
free_exploded_string (char **exploded_string)
util_exec_on_files (char *directory, int (*callback)(char *))
{
int i;
char complete_filename[1024];
DIR *dir;
struct dirent *entry;
struct stat statbuf;
if (exploded_string)
dir = opendir (directory);
if (dir)
{
for (i = 0; exploded_string[i]; i++)
free (exploded_string[i]);
free (exploded_string);
while ((entry = readdir (dir)))
{
snprintf (complete_filename, sizeof (complete_filename) - 1,
"%s/%s", directory, entry->d_name);
lstat (complete_filename, &statbuf);
if (!S_ISDIR(statbuf.st_mode))
{
(int) (*callback) (complete_filename);
}
}
closedir (dir);
}
}
/*
* split_multi_command: split a list of commands separated by 'sep'
* and ecscaped with '\'
* - empty commands are removed
* - spaces on the left of each commands are stripped
* Result must be freed with free_multi_command
* util_search_full_lib_name: search the full name of a WeeChat library
* file with a part of name
* - look in WeeChat user's dir, then WeeChat
* global lib dir
* - sys_directory is the system directory under
* WeeChat lib prefix, for example "plugins"
* - result has to be free() after use
*/
char **
split_multi_command (char *command, char sep)
char *
util_search_full_lib_name (char *filename, char *sys_directory)
{
int nb_substr, arr_idx, str_idx, type;
char **array;
char *buffer, *ptr, *p;
if (command == NULL)
return NULL;
char *name_with_ext, *final_name;
int length;
struct stat st;
nb_substr = 1;
ptr = command;
while ( (p = strchr(ptr, sep)) != NULL)
/* filename is already a full path */
if (strchr (filename, '/') || strchr (filename, '\\'))
return strdup (filename);
length = strlen (filename) + 16;
if (cfg_plugins_extension && cfg_plugins_extension[0])
length += strlen (cfg_plugins_extension);
name_with_ext = (char *)malloc (length);
if (!name_with_ext)
return strdup (filename);
strcpy (name_with_ext, filename);
if (!strchr (filename, '.')
&& cfg_plugins_extension && cfg_plugins_extension[0])
strcat (name_with_ext, cfg_plugins_extension);
/* try WeeChat user's dir */
length = strlen (weechat_home) + strlen (name_with_ext) +
strlen (sys_directory) + 16;
final_name = (char *)malloc (length);
if (!final_name)
{
nb_substr++;
ptr = ++p;
free (name_with_ext);
return strdup (filename);
}
array = (char **) malloc ((nb_substr + 1) * sizeof(char *));
if (!array)
return NULL;
buffer = (char *) malloc ( (strlen(command) + 1) * sizeof (char));
if (!buffer)
snprintf (final_name, length,
"%s/%s/%s", weechat_home, sys_directory, name_with_ext);
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{
free (array);
return NULL;
free (name_with_ext);
return final_name;
}
free (final_name);
ptr = command;
str_idx = 0;
arr_idx = 0;
while(*ptr != '\0')
{
type = 0;
if (*ptr == ';')
{
if (ptr == command)
type = 1;
else if ( *(ptr-1) != '\\')
type = 1;
else if ( *(ptr-1) == '\\')
type = 2;
}
if (type == 1)
{
buffer[str_idx] = '\0';
str_idx = -1;
p = buffer;
/* strip white spaces a the begining of the line */
while (*p == ' ') p++;
if (p && p[0])
array[arr_idx++] = strdup (p);
}
else if (type == 2)
buffer[--str_idx] = *ptr;
else
buffer[str_idx] = *ptr;
str_idx++;
ptr++;
/* try WeeChat global lib dir */
length = strlen (WEECHAT_LIBDIR) + strlen (name_with_ext) +
strlen (sys_directory) + 16;
final_name = (char *)malloc (length);
if (!final_name)
{
free (name_with_ext);
return strdup (filename);
}
buffer[str_idx] = '\0';
p = buffer;
while (*p == ' ') p++;
if (p && p[0])
array[arr_idx++] = strdup (p);
array[arr_idx] = NULL;
snprintf (final_name, length,
"%s/%s/%s", WEECHAT_LIBDIR, sys_directory, name_with_ext);
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{
free (name_with_ext);
return final_name;
}
free (final_name);
free (buffer);
array = (char **) realloc (array, (arr_idx + 1) * sizeof(char *));
return array;
}
/*
* free_multi_command : free a list of commands splitted
* with split_multi_command
*/
void
free_multi_command (char **commands)
{
int i;
if (commands)
{
for (i = 0; commands[i]; i++)
free (commands[i]);
free (commands);
}
return name_with_ext;
}
+6 -18
View File
@@ -20,22 +20,10 @@
#ifndef __WEECHAT_UTIL_H
#define __WEECHAT_UTIL_H 1
#ifndef HAVE_STRNDUP
extern char *strndup (char *, int);
#endif
extern void ascii_tolower (char *);
extern void ascii_toupper (char *);
extern int ascii_strcasecmp (char *, char *);
extern int ascii_strncasecmp (char *, char *, int);
extern char *ascii_strcasestr (char *, char *);
extern char *weechat_iconv (char *, char *, char *);
extern char *weechat_iconv_to_internal (char *, char *);
extern char *weechat_iconv_from_internal (char *, char *);
extern void weechat_iconv_fprintf (FILE *, char *, ...);
extern char *weechat_strreplace (char *, char *, char *);
extern char *weechat_convert_hex_chars (char *);
extern long get_timeval_diff (struct timeval *, struct timeval *);
extern char **explode_string (char *, char *, int, int *);
extern void free_exploded_string (char **);
extern long util_get_timeval_diff (struct timeval *, struct timeval *);
extern int util_get_time_length (char *);
extern int util_create_dir (char *, int);
extern void util_exec_on_files (char *, int (*)(char *));
extern char *util_search_full_lib_name (char *, char *);
#endif /* util.h */
#endif /* wee-util.h */
+202 -446
View File
@@ -46,31 +46,28 @@
#include <time.h>
#include <signal.h>
#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>
#endif
#ifdef HAVE_LANGINFO_CODESET
#include <langinfo.h>
#endif
#include "weechat.h"
#include "alias.h"
#include "backtrace.h"
#include "command.h"
#include "fifo.h"
#include "hotlist.h"
#include "log.h"
#include "session.h"
#include "utf8.h"
#include "util.h"
#include "weeconfig.h"
#include "../protocols/irc/irc.h"
#include "../gui/gui.h"
#ifdef PLUGINS
#include "../plugins/plugins.h"
#endif
#include "wee-alias.h"
#include "wee-backtrace.h"
#include "wee-command.h"
#include "wee-config.h"
#include "wee-hook.h"
#include "wee-log.h"
#include "wee-session.h"
#include "wee-string.h"
#include "wee-utf8.h"
#include "wee-util.h"
#include "../gui/gui-buffer.h"
#include "../gui/gui-chat.h"
#include "../gui/gui-hotlist.h"
#include "../gui/gui-main.h"
#include "../gui/gui-keyboard.h"
#include "../gui/gui-window.h"
#include "../plugins/plugin.h"
char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0]) */
@@ -86,10 +83,6 @@ int server_cmd_line; /* at least 1 server on WeeChat command line */
int auto_connect; /* enabled by default (cmd option to disable) */
int auto_load_plugins; /* enabled by default (cmd option to disable) */
#ifdef HAVE_GNUTLS
gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */
#endif
/*
* weechat_display_usage: display WeeChat usage
@@ -98,30 +91,31 @@ gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */
void
weechat_display_usage (char *exec_name)
{
weechat_iconv_fprintf (stdout, "\n");
weechat_iconv_fprintf (stdout,
_("%s (c) Copyright 2003-2007, compiled on %s %s\n"
"Developed by FlashCode <flashcode@flashtux.org> - %s"),
PACKAGE_STRING, __DATE__, __TIME__, WEECHAT_WEBSITE);
weechat_iconv_fprintf (stdout, "\n\n");
weechat_iconv_fprintf (stdout,
_("Usage: %s [options ...]\n" \
" or: %s [irc[6][s]://[nickname[:password]@]irc.example.org[:port][/channel][,channel[...]]"),
exec_name, exec_name);
weechat_iconv_fprintf (stdout, "\n\n");
weechat_iconv_fprintf (stdout,
_(" -a, --no-connect disable auto-connect to servers at startup\n"
" -c, --config display config file options\n"
" -d, --dir <path> set WeeChat home directory (default: ~/.weechat)\n"
" -f, --key-functions display WeeChat internal functions for keys\n"
" -h, --help this help\n"
" -i, --irc-commands display IRC commands\n"
" -k, --keys display WeeChat default keys\n"
" -l, --license display WeeChat license\n"
" -p, --no-plugin don't load any plugin at startup\n"
" -v, --version display WeeChat version\n"
" -w, --weechat-commands display WeeChat commands\n"));
weechat_iconv_fprintf(stdout, "\n");
string_iconv_fprintf (stdout, "\n");
string_iconv_fprintf (stdout,
_("%s (c) Copyright 2003-2007, compiled on %s %s\n"
"Developed by FlashCode <flashcode@flashtux.org> "
"- %s"),
PACKAGE_STRING, __DATE__, __TIME__, WEECHAT_WEBSITE);
string_iconv_fprintf (stdout, "\n\n");
string_iconv_fprintf (stdout,
_("Usage: %s [options ...]\n" \
" or: %s [irc[6][s]://[nickname[:password]@]"
"irc.example.org[:port][/channel][,channel[...]]"),
exec_name, exec_name);
string_iconv_fprintf (stdout, "\n\n");
string_iconv_fprintf (stdout,
_(" -a, --no-connect disable auto-connect to servers at startup\n"
" -c, --config display config file options\n"
" -d, --dir <path> set WeeChat home directory (default: ~/.weechat)\n"
" -f, --key-functions display WeeChat internal functions for keys\n"
" -h, --help this help\n"
" -m, --commands display WeeChat commands\n"
" -k, --keys display WeeChat default keys\n"
" -l, --license display WeeChat license\n"
" -p, --no-plugin don't load any plugin at startup\n"
" -v, --version display WeeChat version\n\n"));
string_iconv_fprintf(stdout, "\n");
}
/*
@@ -131,145 +125,23 @@ weechat_display_usage (char *exec_name)
void
weechat_display_config_options ()
{
int i, j, k;
weechat_iconv_fprintf (stdout,
_("WeeChat configuration options (<weechat_home>/weechat.rc):\n\n"));
for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
{
if (weechat_options[i])
{
j = 0;
while (weechat_options[i][j].option_name)
{
weechat_iconv_fprintf (stdout,
"* %s:\n",
weechat_options[i][j].option_name);
switch (weechat_options[i][j].option_type)
{
case OPTION_TYPE_BOOLEAN:
weechat_iconv_fprintf (stdout, _(" . type: boolean\n"));
weechat_iconv_fprintf (stdout, _(" . values: 'on' or 'off'\n"));
weechat_iconv_fprintf (stdout, _(" . default value: '%s'\n"),
(weechat_options[i][j].default_int == BOOL_TRUE) ?
"on" : "off");
break;
case OPTION_TYPE_INT:
weechat_iconv_fprintf (stdout, _(" . type: integer\n"));
weechat_iconv_fprintf (stdout, _(" . values: between %d and %d\n"),
weechat_options[i][j].min,
weechat_options[i][j].max);
weechat_iconv_fprintf (stdout, _(" . default value: %d\n"),
weechat_options[i][j].default_int);
break;
case OPTION_TYPE_INT_WITH_STRING:
weechat_iconv_fprintf (stdout, _(" . type: string\n"));
weechat_iconv_fprintf (stdout, _(" . values: "));
k = 0;
while (weechat_options[i][j].array_values[k])
{
weechat_iconv_fprintf (stdout, "'%s'",
weechat_options[i][j].array_values[k]);
if (weechat_options[i][j].array_values[k + 1])
weechat_iconv_fprintf (stdout, ", ");
k++;
}
weechat_iconv_fprintf (stdout, "\n");
weechat_iconv_fprintf (stdout, _(" . default value: '%s'\n"),
(weechat_options[i][j].default_string) ?
weechat_options[i][j].default_string : _("empty"));
break;
case OPTION_TYPE_COLOR:
weechat_iconv_fprintf (stdout, _(" . type: color\n"));
weechat_iconv_fprintf (stdout, _(" . values: Curses or Gtk color\n"));
weechat_iconv_fprintf (stdout, _(" . default value: '%s'\n"),
(weechat_options[i][j].default_string) ?
weechat_options[i][j].default_string : _("empty"));
break;
case OPTION_TYPE_STRING:
switch (weechat_options[i][j].max)
{
case 0:
weechat_iconv_fprintf (stdout, _(" . type: string\n"));
weechat_iconv_fprintf (stdout, _(" . values: any string\n"));
break;
case 1:
weechat_iconv_fprintf (stdout, _(" . type: char\n"));
weechat_iconv_fprintf (stdout, _(" . values: any char\n"));
break;
default:
weechat_iconv_fprintf (stdout, _(" . type: string\n"));
weechat_iconv_fprintf (stdout, _(" . values: any string (limit: %d chars)\n"),
weechat_options[i][j].max);
break;
}
weechat_iconv_fprintf (stdout, _(" . default value: '%s'\n"),
(weechat_options[i][j].default_string) ?
weechat_options[i][j].default_string : _("empty"));
break;
}
weechat_iconv_fprintf (stdout, _(" . description: %s\n"),
_(weechat_options[i][j].long_description));
weechat_iconv_fprintf (stdout, "\n");
j++;
}
}
}
string_iconv_fprintf (stdout,
_("%s configuration options:\n"),
PACKAGE_NAME);
weechat_config_print_stdout ();
}
/*
* weechat_display_commands: display WeeChat and/or IRC commands
* weechat_display_commands: display commands for one or more protocols
*/
void
weechat_display_commands (int weechat_cmd, int irc_cmd)
weechat_display_commands ()
{
int i;
if (weechat_cmd)
{
weechat_iconv_fprintf (stdout,
_("%s internal commands:\n"), PACKAGE_NAME);
weechat_iconv_fprintf (stdout, "\n");
for (i = 0; weechat_commands[i].command_name; i++)
{
weechat_iconv_fprintf (stdout, "* %s", weechat_commands[i].command_name);
if (weechat_commands[i].arguments &&
weechat_commands[i].arguments[0])
weechat_iconv_fprintf (stdout, " %s\n\n", _(weechat_commands[i].arguments));
else
weechat_iconv_fprintf (stdout, "\n\n");
weechat_iconv_fprintf (stdout, "%s\n\n", _(weechat_commands[i].command_description));
if (weechat_commands[i].arguments_description &&
weechat_commands[i].arguments_description[0])
weechat_iconv_fprintf (stdout, "%s\n\n",
_(weechat_commands[i].arguments_description));
}
}
if (irc_cmd)
{
weechat_iconv_fprintf (stdout, _("IRC commands:\n"));
weechat_iconv_fprintf (stdout, "\n");
for (i = 0; irc_commands[i].command_name; i++)
{
if (irc_commands[i].cmd_function_args ||
irc_commands[i].cmd_function_1arg)
{
weechat_iconv_fprintf (stdout, "* %s", irc_commands[i].command_name);
if (irc_commands[i].arguments &&
irc_commands[i].arguments[0])
weechat_iconv_fprintf (stdout, " %s\n\n", _(irc_commands[i].arguments));
else
weechat_iconv_fprintf (stdout, "\n\n");
weechat_iconv_fprintf (stdout, "%s\n\n", _(irc_commands[i].command_description));
if (irc_commands[i].arguments_description &&
irc_commands[i].arguments_description[0])
weechat_iconv_fprintf (stdout, "%s\n\n",
_(irc_commands[i].arguments_description));
}
}
}
string_iconv_fprintf (stdout,
_("%s internal commands:\n"), PACKAGE_NAME);
string_iconv_fprintf (stdout, "\n");
command_print_stdout (weechat_commands);
}
/*
@@ -281,15 +153,15 @@ weechat_display_key_functions ()
{
int i;
weechat_iconv_fprintf (stdout, _("Internal key functions:\n"));
weechat_iconv_fprintf (stdout, "\n");
string_iconv_fprintf (stdout, _("Internal key functions:\n"));
string_iconv_fprintf (stdout, "\n");
i = 0;
while (gui_key_functions[i].function_name)
{
weechat_iconv_fprintf (stdout,
"* %s: %s\n",
gui_key_functions[i].function_name,
_(gui_key_functions[i].description));
string_iconv_fprintf (stdout,
"* %s: %s\n",
gui_key_functions[i].function_name,
_(gui_key_functions[i].description));
i++;
}
}
@@ -304,16 +176,17 @@ weechat_display_keys ()
t_gui_key *ptr_key;
char *expanded_name;
weechat_iconv_fprintf (stdout,
_("%s default keys:\n"), PACKAGE_NAME);
weechat_iconv_fprintf (stdout, "\n");
string_iconv_fprintf (stdout,
_("%s default keys:\n"), PACKAGE_NAME);
string_iconv_fprintf (stdout, "\n");
for (ptr_key = gui_keys; ptr_key; ptr_key = ptr_key->next_key)
{
expanded_name = gui_keyboard_get_expanded_name (ptr_key->key);
weechat_iconv_fprintf (stdout,
"* %s => %s\n",
(expanded_name) ? expanded_name : ptr_key->key,
(ptr_key->function) ? gui_keyboard_function_search_by_ptr (ptr_key->function) : ptr_key->command);
string_iconv_fprintf (stdout,
"* %s => %s\n",
(expanded_name) ? expanded_name : ptr_key->key,
(ptr_key->function) ?
gui_keyboard_function_search_by_ptr (ptr_key->function) : ptr_key->command);
if (expanded_name)
free (expanded_name);
}
@@ -327,8 +200,7 @@ void
weechat_parse_args (int argc, char *argv[])
{
int i;
t_irc_server server_tmp;
weechat_argv0 = strdup (argv[0]);
weechat_session = NULL;
weechat_home = NULL;
@@ -344,8 +216,20 @@ weechat_parse_args (int argc, char *argv[])
else if ((strcmp (argv[i], "-c") == 0)
|| (strcmp (argv[i], "--config") == 0))
{
weechat_display_config_options ();
weechat_shutdown (EXIT_SUCCESS, 0);
if (i + 1 < argc)
{
weechat_display_config_options (argv[i + 1]);
weechat_shutdown (EXIT_SUCCESS, 0);
}
else
{
string_iconv_fprintf (stderr,
_("%s missing argument for \"%s\" "
"option\n"),
WEECHAT_ERROR,
"--config");
weechat_shutdown (EXIT_FAILURE, 0);
}
}
else if ((strcmp (argv[i], "-d") == 0)
|| (strcmp (argv[i], "--dir") == 0))
@@ -354,9 +238,11 @@ weechat_parse_args (int argc, char *argv[])
weechat_home = strdup (argv[++i]);
else
{
weechat_iconv_fprintf (stderr,
_("%s missing argument for --dir option\n"),
WEECHAT_ERROR);
string_iconv_fprintf (stderr,
_("%s missing argument for \"%s\" "
"option\n"),
WEECHAT_ERROR,
"--dir");
weechat_shutdown (EXIT_FAILURE, 0);
}
}
@@ -372,12 +258,6 @@ weechat_parse_args (int argc, char *argv[])
weechat_display_usage (argv[0]);
weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-i") == 0)
|| (strcmp (argv[i], "--irc-commands") == 0))
{
weechat_display_commands (0, 1);
weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-k") == 0)
|| (strcmp (argv[i], "--keys") == 0))
{
@@ -387,43 +267,60 @@ weechat_parse_args (int argc, char *argv[])
else if ((strcmp (argv[i], "-l") == 0)
|| (strcmp (argv[i], "--license") == 0))
{
weechat_iconv_fprintf (stdout, "\n%s%s", WEE_LICENSE);
string_iconv_fprintf (stdout, "\n%s%s", WEECHAT_LICENSE);
weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-m") == 0)
|| (strcmp (argv[i], "--commands") == 0))
{
if (i + 1 < argc)
{
weechat_display_commands (argv[i+1]);
weechat_shutdown (EXIT_SUCCESS, 0);
}
else
{
string_iconv_fprintf (stderr,
_("%s missing argument for \"%s\" "
"option\n"),
WEECHAT_ERROR,
"--commands");
weechat_shutdown (EXIT_FAILURE, 0);
}
}
else if ((strcmp (argv[i], "-p") == 0)
|| (strcmp (argv[i], "--no-plugin") == 0))
{
auto_load_plugins = 0;
}
else if (strcmp (argv[i], "--session") == 0)
{
if (i + 1 < argc)
weechat_session = strdup (argv[++i]);
else
{
weechat_iconv_fprintf (stderr,
_("%s missing argument for --session option\n"),
WEECHAT_ERROR);
string_iconv_fprintf (stderr,
_("%s missing argument for \"%s\" "
"option\n"),
WEECHAT_ERROR,
"--session");
weechat_shutdown (EXIT_FAILURE, 0);
}
}
else if ((strcmp (argv[i], "-v") == 0)
|| (strcmp (argv[i], "--version") == 0))
{
weechat_iconv_fprintf (stdout, PACKAGE_VERSION "\n");
string_iconv_fprintf (stdout, PACKAGE_VERSION "\n");
weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-w") == 0)
|| (strcmp (argv[i], "--weechat-commands") == 0))
{
weechat_display_commands (1, 0);
weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((ascii_strncasecmp (argv[i], "irc", 3) == 0))
/*else if ((weechat_strncasecmp (argv[i], "irc", 3) == 0))
{
if (irc_server_init_with_url (argv[i], &server_tmp) < 0)
{
weechat_iconv_fprintf (stderr,
_("%s invalid syntax for IRC server ('%s'), ignored\n"),
WEECHAT_WARNING, argv[i]);
string_iconv_fprintf (stderr,
_("%s invalid syntax for IRC server "
"('%s'), ignored\n"),
WEECHAT_WARNING, argv[i]);
}
else
{
@@ -436,47 +333,23 @@ weechat_parse_args (int argc, char *argv[])
server_tmp.nick2, server_tmp.nick3,
NULL, NULL, NULL, NULL, 0,
server_tmp.autojoin, 1, NULL))
weechat_iconv_fprintf (stderr,
_("%s unable to create server ('%s'), ignored\n"),
WEECHAT_WARNING, argv[i]);
string_iconv_fprintf (stderr,
_("%s unable to create server "
"('%s'), ignored\n"),
WEECHAT_WARNING, argv[i]);
irc_server_destroy (&server_tmp);
server_cmd_line = 1;
}
}
}*/
else
{
weechat_iconv_fprintf (stderr,
_("%s unknown parameter '%s', ignored\n"),
WEECHAT_WARNING, argv[i]);
string_iconv_fprintf (stderr,
_("%s unknown parameter '%s', ignored\n"),
WEECHAT_WARNING, argv[i]);
}
}
}
/*
* weechat_create_dir: create a directory
* return: 1 if ok (or directory already exists)
* 0 if error
*/
int
weechat_create_dir (char *directory, int permissions)
{
if (mkdir (directory, 0755) < 0)
{
/* exit if error (except if directory already exists) */
if (errno != EEXIST)
{
weechat_iconv_fprintf (stderr, _("%s cannot create directory \"%s\"\n"),
WEECHAT_ERROR, directory);
return 0;
}
return 1;
}
if ((permissions != 0) && (strcmp (directory, getenv ("HOME")) != 0))
chmod (directory, permissions);
return 1;
}
/*
* weechat_create_home_dirs: create WeeChat directories
*/
@@ -493,8 +366,9 @@ weechat_create_home_dirs ()
ptr_home = getenv ("HOME");
if (!ptr_home)
{
weechat_iconv_fprintf (stderr, _("%s unable to get HOME directory\n"),
WEECHAT_ERROR);
string_iconv_fprintf (stderr,
_("%s unable to get HOME directory\n"),
WEECHAT_ERROR);
weechat_shutdown (EXIT_FAILURE, 0);
}
dir_length = strlen (ptr_home) + 10;
@@ -502,8 +376,10 @@ weechat_create_home_dirs ()
(char *) malloc (dir_length * sizeof (char));
if (!weechat_home)
{
weechat_iconv_fprintf (stderr, _("%s not enough memory for home directory\n"),
WEECHAT_ERROR);
string_iconv_fprintf (stderr,
_("%s not enough memory for home "
"directory\n"),
WEECHAT_ERROR);
weechat_shutdown (EXIT_FAILURE, 0);
}
snprintf (weechat_home, dir_length, "%s%s.weechat", ptr_home,
@@ -515,17 +391,19 @@ weechat_create_home_dirs ()
{
if (!S_ISDIR (statinfo.st_mode))
{
weechat_iconv_fprintf (stderr, _("%s home (%s) is not a directory\n"),
WEECHAT_ERROR, weechat_home);
string_iconv_fprintf (stderr,
_("%s home (%s) is not a directory\n"),
WEECHAT_ERROR, weechat_home);
weechat_shutdown (EXIT_FAILURE, 0);
}
}
/* create home directory; error is fatal */
if (!weechat_create_dir (weechat_home, 0))
if (!util_create_dir (weechat_home, 0))
{
weechat_iconv_fprintf (stderr, _("%s unable to create \"%s\" directory\n"),
WEECHAT_ERROR, weechat_home);
string_iconv_fprintf (stderr,
_("%s unable to create \"%s\" directory\n"),
WEECHAT_ERROR, weechat_home);
weechat_shutdown (EXIT_FAILURE, 0);
}
}
@@ -540,22 +418,17 @@ weechat_create_config_dirs ()
char *dir1, *dir2;
/* create logs directory" */
dir1 = weechat_strreplace (cfg_log_path, "~", getenv ("HOME"));
dir2 = weechat_strreplace (dir1, "%h", weechat_home);
(void) weechat_create_dir (dir2, 0700);
dir1 = string_replace (cfg_log_path, "~", getenv ("HOME"));
if (dir1)
{
dir2 = string_replace (dir1, "%h", weechat_home);
if (dir2)
{
(void) util_create_dir (dir2, 0700);
free (dir2);
}
free (dir1);
if (dir2)
free (dir2);
/* create DCC download directory */
dir1 = weechat_strreplace (cfg_dcc_download_path, "~", getenv ("HOME"));
dir2 = weechat_strreplace (dir1, "%h", weechat_home);
(void) weechat_create_dir (dir2, 0700);
if (dir1)
free (dir1);
if (dir2)
free (dir2);
}
}
/*
@@ -567,36 +440,6 @@ weechat_init_vars ()
{
/* start time, used by /uptime command */
weechat_start_time = time (NULL);
/* init gnutls */
#ifdef HAVE_GNUTLS
gnutls_global_init ();
gnutls_certificate_allocate_credentials (&gnutls_xcred);
gnutls_certificate_set_x509_trust_file (gnutls_xcred, "ca.pem", GNUTLS_X509_FMT_PEM);
#endif
}
/*
* weechat_config_read: read WeeChat config file
*/
void
weechat_config_read ()
{
switch (config_read ())
{
case 0: /* read ok */
break;
case -1: /* config file not found */
if (config_create_default () < 0)
exit (EXIT_FAILURE);
if (config_read () != 0)
exit (EXIT_FAILURE);
break;
default: /* other error (fatal) */
irc_server_free_all ();
exit (EXIT_FAILURE);
}
}
/*
@@ -608,42 +451,42 @@ weechat_welcome_message ()
{
if (cfg_look_startup_logo)
{
gui_printf (NULL,
"%s ___ __ ______________ _____ \n"
"%s __ | / /___________ ____/__ /_______ __ /_\n"
"%s __ | /| / /_ _ \\ _ \\ / __ __ \\ __ `/ __/\n"
"%s __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ \n"
"%s ____/|__/ \\___/\\___/\\____/ /_/ /_/\\__,_/ \\__/ \n",
GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK),
GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK));
gui_chat_printf (NULL,
"%s ___ __ ______________ _____ \n"
"%s __ | / /___________ ____/__ /_______ __ /_\n"
"%s __ | /| / /_ _ \\ _ \\ / __ __ \\ __ `/ __/\n"
"%s __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ \n"
"%s ____/|__/ \\___/\\___/\\____/ /_/ /_/\\__,_/ \\__/ ",
GUI_COLOR(GUI_COLOR_CHAT_NICK),
GUI_COLOR(GUI_COLOR_CHAT_NICK),
GUI_COLOR(GUI_COLOR_CHAT_NICK),
GUI_COLOR(GUI_COLOR_CHAT_NICK),
GUI_COLOR(GUI_COLOR_CHAT_NICK));
}
if (cfg_look_weechat_slogan && cfg_look_weechat_slogan[0])
{
gui_printf (NULL, _("%sWelcome to %s%s%s, %s\n"),
(cfg_look_startup_logo) ? " " : "",
GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
PACKAGE_NAME,
GUI_NO_COLOR,
cfg_look_weechat_slogan);
gui_chat_printf (NULL, _("%sWelcome to %s%s%s, %s"),
(cfg_look_startup_logo) ? " " : "",
GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
PACKAGE_NAME,
GUI_NO_COLOR,
cfg_look_weechat_slogan);
}
if (cfg_look_startup_version)
{
gui_printf (NULL, "%s%s%s%s, %s %s %s\n",
(cfg_look_startup_logo) ? " " : "",
GUI_COLOR(GUI_COLOR_WIN_CHAT_CHANNEL),
PACKAGE_STRING,
GUI_NO_COLOR,
_("compiled on"), __DATE__, __TIME__);
gui_chat_printf (NULL, "%s%s%s%s, %s %s %s",
(cfg_look_startup_logo) ? " " : "",
GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
PACKAGE_STRING,
GUI_NO_COLOR,
_("compiled on"), __DATE__, __TIME__);
}
if (cfg_look_startup_logo ||
(cfg_look_weechat_slogan && cfg_look_weechat_slogan[0]) ||
cfg_look_startup_version)
gui_printf (NULL,
"%s-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n",
GUI_COLOR(GUI_COLOR_WIN_CHAT_NICK));
gui_chat_printf (NULL,
"%s-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-",
GUI_COLOR(GUI_COLOR_CHAT_NICK));
weechat_log_printf ("%s (%s %s %s)\n",
PACKAGE_STRING, _("compiled on"), __DATE__, __TIME__);
@@ -658,7 +501,6 @@ weechat_shutdown (int return_code, int crash)
{
if (weechat_argv0)
free (weechat_argv0);
fifo_remove ();
if (weechat_home)
free (weechat_home);
weechat_log_close ();
@@ -666,11 +508,6 @@ weechat_shutdown (int return_code, int crash)
free (local_charset);
alias_free_all ();
#ifdef HAVE_GNUTLS
gnutls_certificate_free_credentials (gnutls_xcred);
gnutls_global_deinit();
#endif
if (crash)
abort();
else
@@ -684,15 +521,6 @@ weechat_shutdown (int return_code, int crash)
void
weechat_dump (int crash)
{
t_irc_server *ptr_server;
t_irc_channel *ptr_channel;
t_irc_nick *ptr_nick;
t_gui_window *ptr_window;
t_gui_buffer *ptr_buffer;
#ifdef PLUGINS
t_weechat_plugin *ptr_plugin;
#endif
/* prevent reentrance */
if (sigsegv)
exit (EXIT_FAILURE);
@@ -714,73 +542,14 @@ weechat_dump (int crash)
{
weechat_log_printf ("****** WeeChat dump request ******\n");
}
gui_window_print_log ();
gui_buffer_print_log ();
gui_hotlist_print_log ();
for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
{
weechat_log_printf ("\n");
irc_server_print_log (ptr_server);
for (ptr_channel = ptr_server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
weechat_log_printf ("\n");
irc_channel_print_log (ptr_channel);
for (ptr_nick = ptr_channel->nicks; ptr_nick;
ptr_nick = ptr_nick->next_nick)
{
weechat_log_printf ("\n");
irc_nick_print_log (ptr_nick);
}
}
}
hook_print_log ();
irc_dcc_print_log ();
gui_panel_print_log ();
weechat_log_printf ("\n");
weechat_log_printf ("[windows/buffers]\n");
weechat_log_printf (" => windows:\n");
for (ptr_window = gui_windows; ptr_window; ptr_window = ptr_window->next_window)
{
weechat_log_printf (" 0x%X\n", ptr_window);
}
weechat_log_printf (" => buffers:\n");
for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
{
weechat_log_printf (" 0x%X\n", ptr_buffer);
}
weechat_log_printf (" => current window = 0x%X\n", gui_current_window);
for (ptr_window = gui_windows; ptr_window; ptr_window = ptr_window->next_window)
{
weechat_log_printf ("\n");
gui_window_print_log (ptr_window);
}
for (ptr_buffer = gui_buffers; ptr_buffer;
ptr_buffer = ptr_buffer->next_buffer)
{
weechat_log_printf ("\n");
gui_buffer_print_log (ptr_buffer);
}
weechat_log_printf ("\n");
irc_ignore_print_log ();
weechat_log_printf ("\n");
hotlist_print_log ();
#ifdef PLUGINS
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
weechat_log_printf ("\n");
plugin_print_log (ptr_plugin);
}
#endif
plugin_print_log ();
weechat_log_printf ("\n");
weechat_log_printf ("****** End of dump ******\n");
@@ -788,31 +557,30 @@ weechat_dump (int crash)
}
/*
* weechat_sigsegv: SIGSEGV handler: save crash log to <weechat_home>/weechat.log and exit
* weechat_sigsegv: SIGSEGV handler: save crash log to
* <weechat_home>/weechat.log and exit
*/
void
weechat_sigsegv ()
{
weechat_dump (1);
irc_dcc_end ();
irc_server_free_all ();
gui_main_end ();
weechat_iconv_fprintf (stderr, "\n");
weechat_iconv_fprintf (stderr, "*** Very bad! WeeChat is crashing (SIGSEGV received)\n");
string_iconv_fprintf (stderr, "\n");
string_iconv_fprintf (stderr, "*** Very bad! WeeChat is crashing (SIGSEGV received)\n");
if (!weechat_log_crash_rename ())
weechat_iconv_fprintf (stderr,
"*** Full crash dump was saved to %s/weechat.log file.\n",
weechat_home);
weechat_iconv_fprintf (stderr, "***\n");
weechat_iconv_fprintf (stderr, "*** Please help WeeChat developers to fix this bug:\n");
weechat_iconv_fprintf (stderr, "*** 1. If you have a core file, please run: gdb weechat-curses core\n");
weechat_iconv_fprintf (stderr, "*** then issue \"bt\" command and send result to developers\n");
weechat_iconv_fprintf (stderr, "*** To enable core files with bash shell: ulimit -c 10000\n");
weechat_iconv_fprintf (stderr, "*** 2. Otherwise send backtrace (below) and weechat.log\n");
weechat_iconv_fprintf (stderr, "*** (be careful, private info may be in this file since\n");
weechat_iconv_fprintf (stderr, "*** part of chats are displayed, so remove lines if needed)\n\n");
string_iconv_fprintf (stderr,
"*** Full crash dump was saved to %s/weechat.log file.\n",
weechat_home);
string_iconv_fprintf (stderr, "***\n");
string_iconv_fprintf (stderr, "*** Please help WeeChat developers to fix this bug:\n");
string_iconv_fprintf (stderr, "*** 1. If you have a core file, please run: gdb weechat-curses core\n");
string_iconv_fprintf (stderr, "*** then issue \"bt\" command and send result to developers\n");
string_iconv_fprintf (stderr, "*** To enable core files with bash shell: ulimit -c 10000\n");
string_iconv_fprintf (stderr, "*** 2. Otherwise send backtrace (below) and weechat.log\n");
string_iconv_fprintf (stderr, "*** (be careful, private info may be in this file since\n");
string_iconv_fprintf (stderr, "*** part of chats are displayed, so remove lines if needed)\n\n");
weechat_backtrace ();
@@ -851,32 +619,20 @@ main (int argc, char *argv[])
weechat_parse_args (argc, argv); /* parse command line args */
weechat_create_home_dirs (); /* create WeeChat directories */
weechat_log_init (); /* init log file */
command_index_build (); /* build cmd index for completion */
weechat_config_read (); /* read configuration */
if (weechat_config_read () < 0) /* read WeeChat configuration */
exit (EXIT_FAILURE);
weechat_create_config_dirs (); /* create config directories */
command_index_build (); /* build cmd index for completion */
gui_main_init (); /* init WeeChat interface */
fifo_create (); /* FIFO pipe for remote control */
if (weechat_session)
session_load (weechat_session); /* load previous session if asked */
//if (weechat_session)
//session_load (weechat_session); /* load previous session if asked */
weechat_welcome_message (); /* display WeeChat welcome message */
#ifdef PLUGINS
plugin_init (auto_load_plugins); /* init plugin interface(s) */
#endif
irc_server_auto_connect (auto_connect, /* auto-connect to servers */
server_cmd_line);
gui_main_loop (); /* WeeChat main loop */
#ifdef PLUGINS
plugin_end (); /* end plugin interface(s) */
#endif
irc_server_disconnect_all (); /* disconnect from all servers */
if (cfg_look_save_on_exit)
(void) config_write (NULL); /* save config file */
(void) weechat_config_write (NULL); /* save WeeChat config file */
command_index_free (); /* free commands index */
irc_dcc_end (); /* remove all DCC */
irc_server_free_all (); /* free all servers */
gui_main_end (); /* shut down WeeChat GUI */
weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */
+1 -5
View File
@@ -66,7 +66,7 @@
/* license */
#define WEE_LICENSE \
#define WEECHAT_LICENSE \
PACKAGE_STRING " (c) Copyright 2003-2007, compiled on " __DATE__ " " __TIME__ \
"\nDeveloped by FlashCode <flashcode@flashtux.org> - " WEECHAT_WEBSITE "\n\n" \
"This program is free software; you can redistribute it and/or modify\n" \
@@ -111,10 +111,6 @@ extern int quit_weechat;
extern char *weechat_home;
extern char *local_charset;
#ifdef HAVE_GNUTLS
extern gnutls_certificate_credentials gnutls_xcred;
#endif
extern void weechat_dump (int);
extern void weechat_shutdown (int, int);