File moved to src/common directory

This commit is contained in:
Sebastien Helleu 2003-10-25 14:38:17 +00:00
parent 13716a5228
commit ee3bb0d14f
20 changed files with 0 additions and 7202 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,80 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_COMMAND_H
#define __WEECHAT_COMMAND_H 1
#include "irc/irc.h"
#define MAX_ARGS 8192
typedef struct t_weechat_command t_weechat_command;
struct t_weechat_command
{
char *command_name;
char *command_description;
char *arguments;
char *arguments_description;
int min_arg, max_arg;
int (*cmd_function_args)(int, char **);
int (*cmd_function_1arg)(char *);
};
typedef struct t_weechat_alias t_weechat_alias;
struct t_weechat_alias
{
char *alias_name;
char *alias_command;
t_weechat_alias *prev_alias;
t_weechat_alias *next_alias;
};
typedef struct t_index_command t_index_command;
struct t_index_command
{
char *command_name;
t_index_command *prev_index;
t_index_command *next_index;
};
extern t_weechat_alias *weechat_alias;
extern t_index_command *index_commands;
extern t_index_command *index_command_new (char *);
extern void index_command_build ();
extern t_weechat_alias *alias_new (char *, char *);
extern int exec_weechat_command (t_irc_server *, char *);
extern void user_command (t_irc_server *, char *);
extern int weechat_cmd_alias (char *);
extern int weechat_cmd_clear (int, char **);
extern int weechat_cmd_connect (int, char **);
extern int weechat_cmd_disconnect (int, char **);
extern int weechat_cmd_help (int, char **);
extern int weechat_cmd_server (int, char **);
extern int weechat_cmd_save (int, char **);
extern int weechat_cmd_set (int, char **);
extern int weechat_cmd_unalias (char *);
#endif /* command.h */

View File

@ -1,210 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* completion.c: completes words according to context (cmd/nick) */
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "completion.h"
#include "irc/irc.h"
#include "command.h"
/*
* completion_init: init completion
*/
void
completion_init (t_completion *completion)
{
completion->position = -1;
completion->base_word = NULL;
}
/*
* completion_free: free completion
*/
void
completion_free (t_completion *completion)
{
if (completion->base_word)
free (completion->base_word);
}
/*
* completion_command: complete a command
*/
void
completion_command (t_completion *completion)
{
int length, word_found_seen;
t_index_command *ptr_index;
length = strlen (completion->base_word) - 1;
word_found_seen = 0;
for (ptr_index = index_commands; ptr_index; ptr_index = ptr_index->next_index)
{
if (strncasecmp (ptr_index->command_name, completion->base_word + 1, length) == 0)
{
if ((!completion->word_found) || word_found_seen)
{
completion->word_found = ptr_index->command_name;
return;
}
}
if (completion->word_found &&
(strcasecmp (ptr_index->command_name, completion->word_found) == 0))
word_found_seen = 1;
}
if (completion->word_found)
{
completion->word_found = NULL;
completion_command (completion);
}
}
/*
* completion_nick: complete a nick
*/
void
completion_nick (t_completion *completion, t_irc_channel *channel)
{
int length, word_found_seen;
t_irc_nick *ptr_nick;
length = strlen (completion->base_word);
word_found_seen = 0;
for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
{
if (strncasecmp (ptr_nick->nick, completion->base_word, length) == 0)
{
if ((!completion->word_found) || word_found_seen)
{
completion->word_found = ptr_nick->nick;
return;
}
}
if (completion->word_found &&
(strcasecmp (ptr_nick->nick, completion->word_found) == 0))
word_found_seen = 1;
}
if (completion->word_found)
{
completion->word_found = NULL;
completion_nick (completion, channel);
}
}
/*
* completion_search: complete word according to context
*/
void
completion_search (t_completion *completion, void *channel,
char *buffer, int size, int pos)
{
int i, pos_start, pos_end;
char *old_word_found;
/* TODO: complete when no word is there with command according to context */
if (size == 0)
{
completion->word_found = NULL;
return;
}
/* if new complation => look for base word */
if (pos != completion->position)
{
completion->word_found = NULL;
if ((pos == size) || (buffer[pos-1] != ' '))
pos--;
if ((pos > 0) && (buffer[pos] == ' '))
return;
i = pos;
while ((i >= 0) && (buffer[i] != ' '))
i--;
pos_start = i + 1;
i = pos;
while ((i < size) && (buffer[i] != ' '))
i++;
pos_end = i - 1;
if (pos_start > pos_end)
return;
completion->base_word_pos = pos_start;
if (completion->base_word)
free (completion->base_word);
completion->base_word = (char *) malloc (pos_end - pos_start + 2);
for (i = pos_start; i <= pos_end; i++)
completion->base_word[i - pos_start] = buffer[i];
completion->base_word[pos_end - pos_start + 1] = '\0';
if (completion->base_word[0] == '/')
completion->position_replace = pos_start + 1;
else
completion->position_replace = pos_start;
}
/* completion */
old_word_found = completion->word_found;
if (completion->base_word[0] == '/')
{
completion_command (completion);
if (completion->word_found)
{
if (old_word_found)
completion->diff_size = strlen (completion->word_found) -
strlen (old_word_found);
else
completion->diff_size = strlen (completion->word_found) -
strlen (completion->base_word) + 1;
}
}
else
{
if (channel)
{
completion_nick (completion, (t_irc_channel *)channel);
if (completion->word_found)
{
if (old_word_found)
completion->diff_size = strlen (completion->word_found) -
strlen (old_word_found);
else
completion->diff_size = strlen (completion->word_found) -
strlen (completion->base_word);
}
}
}
}

View File

@ -1,42 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_COMPLETION_H
#define __WEECHAT_COMPLETION_H 1
typedef struct t_completion t_completion;
struct t_completion
{
char *base_word; /* word to complete (when Tab was pressed) */
int base_word_pos; /* beggining of base word */
int position; /* position where we shoud complete */
char *word_found; /* word found (to replace base word) */
int position_replace; /* position where word should be replaced */
int diff_size; /* size difference (< 0 = char(s) deleted) */
};
extern void completion_init (t_completion *);
extern void completion_free (t_completion *);
extern void completion_search (t_completion *, void *, char *, int, int);
#endif /* completion.h */

File diff suppressed because it is too large Load Diff

View File

@ -1,157 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_CONFIG_H
#define __WEECHAT_CONFIG_H 1
#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_DCC 4
#define CONFIG_SECTION_PROXY 5
#define CONFIG_SECTION_ALIAS 6
#define CONFIG_SECTION_SERVER 7
#define CONFIG_NUMBER_SECTIONS 8
#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
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;
int (*handler_change)(int *, char **);
};
extern int cfg_look_set_title;
extern int cfg_look_startup_logo;
extern int cfg_look_startup_version;
extern char *cfg_look_weechat_slogan;
extern int cfg_look_color_nicks;
extern int cfg_look_color_actions;
extern int cfg_look_remove_colors_from_msgs;
extern int cfg_look_nicklist;
extern int cfg_look_nicklist_position;
extern int cfg_look_nicklist_min_size;
extern int cfg_look_nicklist_max_size;
extern int cfg_look_nickmode;
extern int cfg_look_nickmode_empty;
extern char *cfg_look_no_nickname;
extern char *cfg_look_completor;
extern int cfg_col_title;
extern int cfg_col_title_bg;
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_nick;
extern int cfg_col_chat_host;
extern int cfg_col_chat_channel;
extern int cfg_col_chat_dark;
extern int cfg_col_chat_bg;
extern int cfg_col_status;
extern int cfg_col_status_active;
extern int cfg_col_status_data_msg;
extern int cfg_col_status_data_other;
extern int cfg_col_status_more;
extern int cfg_col_status_bg;
extern int cfg_col_input;
extern int cfg_col_input_channel;
extern int cfg_col_input_nick;
extern int cfg_col_input_bg;
extern int cfg_col_nick;
extern int cfg_col_nick_op;
extern int cfg_col_nick_halfop;
extern int cfg_col_nick_voice;
extern int cfg_col_nick_sep;
extern int cfg_col_nick_self;
extern int cfg_col_nick_private;
extern int cfg_col_nick_bg;
extern int cfg_history_max_lines;
extern int cfg_history_max_commands;
extern int cfg_log_auto_channels;
extern int cfg_log_auto_private;
extern char *cfg_log_path;
extern char *cfg_log_name;
extern char *cfg_log_timestamp;
extern char *cfg_log_start_string;
extern char *cfg_log_end_string;
extern int cfg_dcc_auto_accept_files;
extern int cfg_dcc_auto_accept_max_size;
extern int cfg_dcc_auto_accept_chats;
extern int cfg_dcc_timeout;
extern char *cfg_dcc_download_path;
extern char *cfg_dcc_upload_path;
extern int cfg_dcc_auto_rename;
extern int cfg_dcc_auto_resume;
extern int cfg_proxy_use;
extern char *cfg_proxy_address;
extern int cfg_proxy_port;
extern char *cfg_proxy_password;
extern t_config_section config_sections [CONFIG_NUMBER_SECTIONS];
extern t_config_option * weechat_options [CONFIG_NUMBER_SECTIONS];
extern int config_read ();
extern int config_create_default ();
extern int config_write ();
#endif /* config.h */

View File

@ -1,66 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* history.c: memorize and call again commands or text */
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "history.h"
#include "gui/gui.h"
t_history *history_general = NULL;
t_history *history_general_ptr = NULL;
/*
* history_add: add a text/command to history
*/
void
history_add (void *window, char *string)
{
t_history *new_history;
new_history = (t_history *)malloc (sizeof (t_history));
if (new_history)
{
new_history->text = strdup (string);
/* add history to general history */
if (history_general)
history_general->prev_history = new_history;
new_history->next_history = history_general;
new_history->prev_history = NULL;
history_general = new_history;
/* add history to local history */
if (((t_gui_window *)(window))->history)
((t_gui_window *)(window))->history->prev_history = new_history;
new_history->next_history = ((t_gui_window *)(window))->history;
new_history->prev_history = NULL;
((t_gui_window *)window)->history = new_history;
}
}

View File

@ -1,37 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_HISTORY_H
#define __WEECHAT_HISTORY_H 1
typedef struct t_history t_history;
struct t_history
{
char *text; /* text or command (as entered by user) */
t_history *next_history; /* link to next text/command */
t_history *prev_history; /* link to previous text/command */
};
extern void history_add (void *, char *);
#endif /* history.h */

View File

@ -1,326 +0,0 @@
/* ############################################################################
* ### ___ __ ______________ _____ ###
* ### __ | / /___________ ____/__ /_______ __ /_ ###
* ### __ | /| / /_ _ \ _ \ / __ __ \ __ `/ __/ ###
* ### __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ ###
* ### ____/|__/ \___/\___/\____/ /_/ /_/\__,_/ \__/ ###
* ### ###
* ### WeeChat - Wee Enhanced Environment for Chat ###
* ### Fast & light environment for Chat ###
* ### ###
* ### By: FlashCode <flashcode@flashtux.org> ###
* ### Bounga <bounga@altern.org> ###
* ### Xahlexx <xahlexx@tuxisland.org> ###
* ### ###
* ### http://weechat.flashtux.org ###
* ### ###
* ############################################################################
*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* weechat.c: core functions for WeeChat */
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include "weechat.h"
#include "config.h"
#include "command.h"
#include "irc/irc.h"
#include "gui/gui.h"
/* char *display_name; */
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
FILE *log_file; /* WeeChat log file (~/.weechat/weechat.log */
/*
* log_printf: displays a message in WeeChat log (~/.weechat/weechat.log)
*/
void
log_printf (char *message, ...)
{
static char buffer[4096];
va_list argptr;
static time_t seconds;
struct tm *date_tmp;
if (!log_file)
return;
va_start (argptr, message);
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
va_end (argptr);
seconds = time (NULL);
date_tmp = localtime (&seconds);
fprintf (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);
fflush (log_file);
}
/*
* wee_parse_args: parse command line args
*/
void
wee_parse_args (int argc, char *argv[])
{
int i;
for (i = 1; i < argc; i++)
{
if ((strcmp (argv[i], "-h") == 0)
|| (strcmp (argv[i], "--help") == 0))
{
printf ("\n%s%s", WEE_USAGE);
exit (0);
}
else if ((strcmp (argv[i], "-l") == 0)
|| (strcmp (argv[i], "--license") == 0))
{
printf ("\n%s%s", WEE_LICENSE);
exit (0);
}
/*else if ((strcmp (argv[i], "-d") == 0)
|| (strcmp (argv[i], "--display") == 0))
{
if (i == (argc - 1))
fprintf (stderr,
_("%s no display specified (parameter '%s'), ignored\n"),
WEECHAT_WARNING, argv[i]);
else
{
display_name = argv[i + 1];
i++;
}
}*/
else if ((strcmp (argv[i], "-v") == 0)
|| (strcmp (argv[i], "--version") == 0))
{
printf (WEECHAT_VERSION "\n");
exit (0);
}
else
{
fprintf (stderr,
_("%s unknown parameter '%s', ignored\n"),
WEECHAT_WARNING, argv[i]);
}
}
}
/*
* wee_create_home_dir: create weechat home directory (if not found)
*/
void
wee_create_home_dir ()
{
char *weechat_home_dir;
int return_code;
weechat_home_dir =
(char *) malloc ((strlen (getenv ("HOME")) + 64) * sizeof (char));
sprintf (weechat_home_dir, "%s/.weechat", getenv ("HOME"));
return_code = mkdir (weechat_home_dir, 0755);
if (return_code < 0)
{
if (errno != EEXIST)
{
fprintf (stderr, _("%s cannot create directory \"%s\"\n"),
WEECHAT_ERROR, weechat_home_dir);
free (weechat_home_dir);
exit (1);
}
}
free (weechat_home_dir);
}
/*
* wee_init_vars: initialize some variables
*/
void
wee_init_vars ()
{
/* GUI not yet initialized */
gui_ready = 0;
/* init received messages queue */
recv_msgq = NULL;
msgq_last_msg = NULL;
}
/*
* wee_init_log: initialize log file
*/
void
wee_init_log ()
{
char *filename;
filename =
(char *) malloc ((strlen (getenv ("HOME")) + 64) * sizeof (char));
sprintf (filename, "%s/.weechat/" WEECHAT_LOG_NAME, getenv ("HOME"));
if ((log_file = fopen (filename, "wt")) == NULL)
{
free (filename);
fprintf (stderr,
_("%s unable to create/append to log file (~/.weechat/"
WEECHAT_LOG_NAME), WEECHAT_ERROR);
}
free (filename);
}
/*
* wee_shutdown: shutdown WeeChat
*/
void
wee_shutdown ()
{
server_free_all ();
gui_end ();
if (log_file)
fclose (log_file);
exit (0);
}
/*
* main: WeeChat startup
*/
int
main (int argc, char *argv[])
{
t_irc_server *ptr_server;
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, "/usr/share/locale");
textdomain (PACKAGE);
/* Gtk init */
#ifdef WEE_GTK
gtk_init (&argc, &argv);
#endif
/* initialize variables */
wee_init_vars ();
/* parse command line args */
wee_parse_args (argc, argv);
/* create weechat home directory */
wee_create_home_dir ();
/* init log file */
wee_init_log ();
/* build commands index (sorted), for completion */
index_command_build ();
/* read configuration */
switch (config_read ())
{
case 0: /* success */
break;
case -1: /* config file not found */
config_create_default ();
config_read ();
break;
default: /* other error (fatal) */
server_free_all ();
return 1;
}
/* init gui */
gui_init ();
/* Welcome message - yeah! */
if (cfg_look_startup_logo)
{
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX1,
" ___ __ ______________ _____ \n"
" __ | / /___________ ____/__ /_______ __ /_\n"
" __ | /| / /_ _ \\ _ \\ / __ __ \\ __ `/ __/\n"
" __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ \n"
" ____/|__/ \\___/\\___/\\____/ /_/ /_/\\__,_/ \\__/ \n");
}
if (cfg_look_weechat_slogan && cfg_look_weechat_slogan[0])
{
gui_printf_color (NULL, COLOR_WIN_CHAT, _("%sWelcome to "),
(cfg_look_startup_logo) ? " " : "");
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX2, WEECHAT_NAME);
gui_printf_color (NULL, COLOR_WIN_CHAT,
", %s\n", cfg_look_weechat_slogan);
}
if (cfg_look_startup_version)
{
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX2,
"%s" WEECHAT_NAME_AND_VERSION,
(cfg_look_startup_logo) ? " " : "");
gui_printf_color (NULL, COLOR_WIN_CHAT,
", %s %s %s\n",
_("compiled on"), __DATE__, __TIME__);
}
if (cfg_look_startup_logo ||
(cfg_look_weechat_slogan && cfg_look_weechat_slogan[0]) ||
cfg_look_startup_version)
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX1,
"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
/* connect to all servers (with autoconnect flag) */
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (ptr_server->autoconnect)
{
gui_window_new (ptr_server, NULL);
if (server_connect (ptr_server))
irc_login (ptr_server);
}
}
gui_main_loop ();
server_disconnect_all ();
/* save config file */
config_write (NULL);
/* program ending */
wee_shutdown ();
/* make gcc happy (statement never executed) */
return 0;
}

View File

@ -1,98 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_H
#define __WEECHAT_H 1
#include <stdio.h>
#include <locale.h>
#include <libintl.h>
#define PACKAGE "weechat"
#define _(string) gettext(string)
#define N_(string) (string)
#define WEECHAT_NAME "WeeChat"
#define WEECHAT_VERSION "0.0.3-pre2"
#define WEECHAT_NAME_AND_VERSION WEECHAT_NAME " " WEECHAT_VERSION
#define WEECHAT_COPYRIGHT WEECHAT_NAME " (c) 2003 by Wee Team"
#define WEECHAT_WEBSITE "http://weechat.flashtux.org"
#define WEECHAT_ERROR _(WEECHAT_NAME " Error:")
#define WEECHAT_WARNING _(WEECHAT_NAME " Warning:")
/* debug mode, 0=normal use, 1=some debug msg, 2=full debug (developers only) */
#define DEBUG 0
/* log file */
#define WEECHAT_LOG_NAME "weechat.log"
/* license */
#define WEE_LICENSE \
WEECHAT_NAME_AND_VERSION " (c) Copyright 2003, compiled on " __DATE__ __TIME__ \
"Developed by FlashCode <flashcode@flashtux.org>\n" \
" Bounga <bounga@altern.org>\n" \
" Xahlexx <xahlexx@tuxisland.org>\n\n" \
"This program is free software; you can redistribute it and/or modify\n" \
"it under the terms of the GNU General Public License as published by\n" \
"the Free Software Foundation; either version 2 of the License, or\n" \
"(at your option) any later version.\n" \
"\n", \
\
"This program is distributed in the hope that it will be useful,\n" \
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \
"GNU General Public License for more details.\n" \
"\n" \
"You should have received a copy of the GNU General Public License\n" \
"along with this program; if not, write to the Free Software\n" \
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n"
#define WEE_USAGE \
WEECHAT_NAME_AND_VERSION " (c) Copyright 2003, compiled on " __DATE__ __TIME__ \
"Developed by FlashCode <flashcode@flashtux.org>\n" \
" Bounga <bounga@altern.org>\n" \
" Xahlexx <xahlexx@tuxisland.org>\n\n" \
" Bounga <bounga@altern.org>\n" \
" Xahlexx <xahlexx@tuxisland.org>\n\n" \
" -h, --help this help screen\n", \
" -l, --license display WeeChat license\n" \
" -v, --version display WeeChat version\n\n"
/* " -d, --display choose X display\n" \*/
/*#define DEFAULT_DISPLAY ":0" */
/*extern char *display_name; */
int quit_weechat;
extern int quit_weechat;
extern void log_printf (char *, ...);
extern void wee_shutdown ();
#endif /* weechat.h */

File diff suppressed because it is too large Load Diff

View File

@ -1,80 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_COMMAND_H
#define __WEECHAT_COMMAND_H 1
#include "irc/irc.h"
#define MAX_ARGS 8192
typedef struct t_weechat_command t_weechat_command;
struct t_weechat_command
{
char *command_name;
char *command_description;
char *arguments;
char *arguments_description;
int min_arg, max_arg;
int (*cmd_function_args)(int, char **);
int (*cmd_function_1arg)(char *);
};
typedef struct t_weechat_alias t_weechat_alias;
struct t_weechat_alias
{
char *alias_name;
char *alias_command;
t_weechat_alias *prev_alias;
t_weechat_alias *next_alias;
};
typedef struct t_index_command t_index_command;
struct t_index_command
{
char *command_name;
t_index_command *prev_index;
t_index_command *next_index;
};
extern t_weechat_alias *weechat_alias;
extern t_index_command *index_commands;
extern t_index_command *index_command_new (char *);
extern void index_command_build ();
extern t_weechat_alias *alias_new (char *, char *);
extern int exec_weechat_command (t_irc_server *, char *);
extern void user_command (t_irc_server *, char *);
extern int weechat_cmd_alias (char *);
extern int weechat_cmd_clear (int, char **);
extern int weechat_cmd_connect (int, char **);
extern int weechat_cmd_disconnect (int, char **);
extern int weechat_cmd_help (int, char **);
extern int weechat_cmd_server (int, char **);
extern int weechat_cmd_save (int, char **);
extern int weechat_cmd_set (int, char **);
extern int weechat_cmd_unalias (char *);
#endif /* command.h */

View File

@ -1,210 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* completion.c: completes words according to context (cmd/nick) */
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "completion.h"
#include "irc/irc.h"
#include "command.h"
/*
* completion_init: init completion
*/
void
completion_init (t_completion *completion)
{
completion->position = -1;
completion->base_word = NULL;
}
/*
* completion_free: free completion
*/
void
completion_free (t_completion *completion)
{
if (completion->base_word)
free (completion->base_word);
}
/*
* completion_command: complete a command
*/
void
completion_command (t_completion *completion)
{
int length, word_found_seen;
t_index_command *ptr_index;
length = strlen (completion->base_word) - 1;
word_found_seen = 0;
for (ptr_index = index_commands; ptr_index; ptr_index = ptr_index->next_index)
{
if (strncasecmp (ptr_index->command_name, completion->base_word + 1, length) == 0)
{
if ((!completion->word_found) || word_found_seen)
{
completion->word_found = ptr_index->command_name;
return;
}
}
if (completion->word_found &&
(strcasecmp (ptr_index->command_name, completion->word_found) == 0))
word_found_seen = 1;
}
if (completion->word_found)
{
completion->word_found = NULL;
completion_command (completion);
}
}
/*
* completion_nick: complete a nick
*/
void
completion_nick (t_completion *completion, t_irc_channel *channel)
{
int length, word_found_seen;
t_irc_nick *ptr_nick;
length = strlen (completion->base_word);
word_found_seen = 0;
for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
{
if (strncasecmp (ptr_nick->nick, completion->base_word, length) == 0)
{
if ((!completion->word_found) || word_found_seen)
{
completion->word_found = ptr_nick->nick;
return;
}
}
if (completion->word_found &&
(strcasecmp (ptr_nick->nick, completion->word_found) == 0))
word_found_seen = 1;
}
if (completion->word_found)
{
completion->word_found = NULL;
completion_nick (completion, channel);
}
}
/*
* completion_search: complete word according to context
*/
void
completion_search (t_completion *completion, void *channel,
char *buffer, int size, int pos)
{
int i, pos_start, pos_end;
char *old_word_found;
/* TODO: complete when no word is there with command according to context */
if (size == 0)
{
completion->word_found = NULL;
return;
}
/* if new complation => look for base word */
if (pos != completion->position)
{
completion->word_found = NULL;
if ((pos == size) || (buffer[pos-1] != ' '))
pos--;
if ((pos > 0) && (buffer[pos] == ' '))
return;
i = pos;
while ((i >= 0) && (buffer[i] != ' '))
i--;
pos_start = i + 1;
i = pos;
while ((i < size) && (buffer[i] != ' '))
i++;
pos_end = i - 1;
if (pos_start > pos_end)
return;
completion->base_word_pos = pos_start;
if (completion->base_word)
free (completion->base_word);
completion->base_word = (char *) malloc (pos_end - pos_start + 2);
for (i = pos_start; i <= pos_end; i++)
completion->base_word[i - pos_start] = buffer[i];
completion->base_word[pos_end - pos_start + 1] = '\0';
if (completion->base_word[0] == '/')
completion->position_replace = pos_start + 1;
else
completion->position_replace = pos_start;
}
/* completion */
old_word_found = completion->word_found;
if (completion->base_word[0] == '/')
{
completion_command (completion);
if (completion->word_found)
{
if (old_word_found)
completion->diff_size = strlen (completion->word_found) -
strlen (old_word_found);
else
completion->diff_size = strlen (completion->word_found) -
strlen (completion->base_word) + 1;
}
}
else
{
if (channel)
{
completion_nick (completion, (t_irc_channel *)channel);
if (completion->word_found)
{
if (old_word_found)
completion->diff_size = strlen (completion->word_found) -
strlen (old_word_found);
else
completion->diff_size = strlen (completion->word_found) -
strlen (completion->base_word);
}
}
}
}

View File

@ -1,42 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_COMPLETION_H
#define __WEECHAT_COMPLETION_H 1
typedef struct t_completion t_completion;
struct t_completion
{
char *base_word; /* word to complete (when Tab was pressed) */
int base_word_pos; /* beggining of base word */
int position; /* position where we shoud complete */
char *word_found; /* word found (to replace base word) */
int position_replace; /* position where word should be replaced */
int diff_size; /* size difference (< 0 = char(s) deleted) */
};
extern void completion_init (t_completion *);
extern void completion_free (t_completion *);
extern void completion_search (t_completion *, void *, char *, int, int);
#endif /* completion.h */

File diff suppressed because it is too large Load Diff

View File

@ -1,157 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_CONFIG_H
#define __WEECHAT_CONFIG_H 1
#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_DCC 4
#define CONFIG_SECTION_PROXY 5
#define CONFIG_SECTION_ALIAS 6
#define CONFIG_SECTION_SERVER 7
#define CONFIG_NUMBER_SECTIONS 8
#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
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;
int (*handler_change)(int *, char **);
};
extern int cfg_look_set_title;
extern int cfg_look_startup_logo;
extern int cfg_look_startup_version;
extern char *cfg_look_weechat_slogan;
extern int cfg_look_color_nicks;
extern int cfg_look_color_actions;
extern int cfg_look_remove_colors_from_msgs;
extern int cfg_look_nicklist;
extern int cfg_look_nicklist_position;
extern int cfg_look_nicklist_min_size;
extern int cfg_look_nicklist_max_size;
extern int cfg_look_nickmode;
extern int cfg_look_nickmode_empty;
extern char *cfg_look_no_nickname;
extern char *cfg_look_completor;
extern int cfg_col_title;
extern int cfg_col_title_bg;
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_nick;
extern int cfg_col_chat_host;
extern int cfg_col_chat_channel;
extern int cfg_col_chat_dark;
extern int cfg_col_chat_bg;
extern int cfg_col_status;
extern int cfg_col_status_active;
extern int cfg_col_status_data_msg;
extern int cfg_col_status_data_other;
extern int cfg_col_status_more;
extern int cfg_col_status_bg;
extern int cfg_col_input;
extern int cfg_col_input_channel;
extern int cfg_col_input_nick;
extern int cfg_col_input_bg;
extern int cfg_col_nick;
extern int cfg_col_nick_op;
extern int cfg_col_nick_halfop;
extern int cfg_col_nick_voice;
extern int cfg_col_nick_sep;
extern int cfg_col_nick_self;
extern int cfg_col_nick_private;
extern int cfg_col_nick_bg;
extern int cfg_history_max_lines;
extern int cfg_history_max_commands;
extern int cfg_log_auto_channels;
extern int cfg_log_auto_private;
extern char *cfg_log_path;
extern char *cfg_log_name;
extern char *cfg_log_timestamp;
extern char *cfg_log_start_string;
extern char *cfg_log_end_string;
extern int cfg_dcc_auto_accept_files;
extern int cfg_dcc_auto_accept_max_size;
extern int cfg_dcc_auto_accept_chats;
extern int cfg_dcc_timeout;
extern char *cfg_dcc_download_path;
extern char *cfg_dcc_upload_path;
extern int cfg_dcc_auto_rename;
extern int cfg_dcc_auto_resume;
extern int cfg_proxy_use;
extern char *cfg_proxy_address;
extern int cfg_proxy_port;
extern char *cfg_proxy_password;
extern t_config_section config_sections [CONFIG_NUMBER_SECTIONS];
extern t_config_option * weechat_options [CONFIG_NUMBER_SECTIONS];
extern int config_read ();
extern int config_create_default ();
extern int config_write ();
#endif /* config.h */

View File

@ -1,66 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* history.c: memorize and call again commands or text */
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "history.h"
#include "gui/gui.h"
t_history *history_general = NULL;
t_history *history_general_ptr = NULL;
/*
* history_add: add a text/command to history
*/
void
history_add (void *window, char *string)
{
t_history *new_history;
new_history = (t_history *)malloc (sizeof (t_history));
if (new_history)
{
new_history->text = strdup (string);
/* add history to general history */
if (history_general)
history_general->prev_history = new_history;
new_history->next_history = history_general;
new_history->prev_history = NULL;
history_general = new_history;
/* add history to local history */
if (((t_gui_window *)(window))->history)
((t_gui_window *)(window))->history->prev_history = new_history;
new_history->next_history = ((t_gui_window *)(window))->history;
new_history->prev_history = NULL;
((t_gui_window *)window)->history = new_history;
}
}

View File

@ -1,37 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_HISTORY_H
#define __WEECHAT_HISTORY_H 1
typedef struct t_history t_history;
struct t_history
{
char *text; /* text or command (as entered by user) */
t_history *next_history; /* link to next text/command */
t_history *prev_history; /* link to previous text/command */
};
extern void history_add (void *, char *);
#endif /* history.h */

View File

@ -1,326 +0,0 @@
/* ############################################################################
* ### ___ __ ______________ _____ ###
* ### __ | / /___________ ____/__ /_______ __ /_ ###
* ### __ | /| / /_ _ \ _ \ / __ __ \ __ `/ __/ ###
* ### __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ ###
* ### ____/|__/ \___/\___/\____/ /_/ /_/\__,_/ \__/ ###
* ### ###
* ### WeeChat - Wee Enhanced Environment for Chat ###
* ### Fast & light environment for Chat ###
* ### ###
* ### By: FlashCode <flashcode@flashtux.org> ###
* ### Bounga <bounga@altern.org> ###
* ### Xahlexx <xahlexx@tuxisland.org> ###
* ### ###
* ### http://weechat.flashtux.org ###
* ### ###
* ############################################################################
*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* weechat.c: core functions for WeeChat */
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include "weechat.h"
#include "config.h"
#include "command.h"
#include "irc/irc.h"
#include "gui/gui.h"
/* char *display_name; */
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
FILE *log_file; /* WeeChat log file (~/.weechat/weechat.log */
/*
* log_printf: displays a message in WeeChat log (~/.weechat/weechat.log)
*/
void
log_printf (char *message, ...)
{
static char buffer[4096];
va_list argptr;
static time_t seconds;
struct tm *date_tmp;
if (!log_file)
return;
va_start (argptr, message);
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
va_end (argptr);
seconds = time (NULL);
date_tmp = localtime (&seconds);
fprintf (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);
fflush (log_file);
}
/*
* wee_parse_args: parse command line args
*/
void
wee_parse_args (int argc, char *argv[])
{
int i;
for (i = 1; i < argc; i++)
{
if ((strcmp (argv[i], "-h") == 0)
|| (strcmp (argv[i], "--help") == 0))
{
printf ("\n%s%s", WEE_USAGE);
exit (0);
}
else if ((strcmp (argv[i], "-l") == 0)
|| (strcmp (argv[i], "--license") == 0))
{
printf ("\n%s%s", WEE_LICENSE);
exit (0);
}
/*else if ((strcmp (argv[i], "-d") == 0)
|| (strcmp (argv[i], "--display") == 0))
{
if (i == (argc - 1))
fprintf (stderr,
_("%s no display specified (parameter '%s'), ignored\n"),
WEECHAT_WARNING, argv[i]);
else
{
display_name = argv[i + 1];
i++;
}
}*/
else if ((strcmp (argv[i], "-v") == 0)
|| (strcmp (argv[i], "--version") == 0))
{
printf (WEECHAT_VERSION "\n");
exit (0);
}
else
{
fprintf (stderr,
_("%s unknown parameter '%s', ignored\n"),
WEECHAT_WARNING, argv[i]);
}
}
}
/*
* wee_create_home_dir: create weechat home directory (if not found)
*/
void
wee_create_home_dir ()
{
char *weechat_home_dir;
int return_code;
weechat_home_dir =
(char *) malloc ((strlen (getenv ("HOME")) + 64) * sizeof (char));
sprintf (weechat_home_dir, "%s/.weechat", getenv ("HOME"));
return_code = mkdir (weechat_home_dir, 0755);
if (return_code < 0)
{
if (errno != EEXIST)
{
fprintf (stderr, _("%s cannot create directory \"%s\"\n"),
WEECHAT_ERROR, weechat_home_dir);
free (weechat_home_dir);
exit (1);
}
}
free (weechat_home_dir);
}
/*
* wee_init_vars: initialize some variables
*/
void
wee_init_vars ()
{
/* GUI not yet initialized */
gui_ready = 0;
/* init received messages queue */
recv_msgq = NULL;
msgq_last_msg = NULL;
}
/*
* wee_init_log: initialize log file
*/
void
wee_init_log ()
{
char *filename;
filename =
(char *) malloc ((strlen (getenv ("HOME")) + 64) * sizeof (char));
sprintf (filename, "%s/.weechat/" WEECHAT_LOG_NAME, getenv ("HOME"));
if ((log_file = fopen (filename, "wt")) == NULL)
{
free (filename);
fprintf (stderr,
_("%s unable to create/append to log file (~/.weechat/"
WEECHAT_LOG_NAME), WEECHAT_ERROR);
}
free (filename);
}
/*
* wee_shutdown: shutdown WeeChat
*/
void
wee_shutdown ()
{
server_free_all ();
gui_end ();
if (log_file)
fclose (log_file);
exit (0);
}
/*
* main: WeeChat startup
*/
int
main (int argc, char *argv[])
{
t_irc_server *ptr_server;
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, "/usr/share/locale");
textdomain (PACKAGE);
/* Gtk init */
#ifdef WEE_GTK
gtk_init (&argc, &argv);
#endif
/* initialize variables */
wee_init_vars ();
/* parse command line args */
wee_parse_args (argc, argv);
/* create weechat home directory */
wee_create_home_dir ();
/* init log file */
wee_init_log ();
/* build commands index (sorted), for completion */
index_command_build ();
/* read configuration */
switch (config_read ())
{
case 0: /* success */
break;
case -1: /* config file not found */
config_create_default ();
config_read ();
break;
default: /* other error (fatal) */
server_free_all ();
return 1;
}
/* init gui */
gui_init ();
/* Welcome message - yeah! */
if (cfg_look_startup_logo)
{
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX1,
" ___ __ ______________ _____ \n"
" __ | / /___________ ____/__ /_______ __ /_\n"
" __ | /| / /_ _ \\ _ \\ / __ __ \\ __ `/ __/\n"
" __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ \n"
" ____/|__/ \\___/\\___/\\____/ /_/ /_/\\__,_/ \\__/ \n");
}
if (cfg_look_weechat_slogan && cfg_look_weechat_slogan[0])
{
gui_printf_color (NULL, COLOR_WIN_CHAT, _("%sWelcome to "),
(cfg_look_startup_logo) ? " " : "");
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX2, WEECHAT_NAME);
gui_printf_color (NULL, COLOR_WIN_CHAT,
", %s\n", cfg_look_weechat_slogan);
}
if (cfg_look_startup_version)
{
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX2,
"%s" WEECHAT_NAME_AND_VERSION,
(cfg_look_startup_logo) ? " " : "");
gui_printf_color (NULL, COLOR_WIN_CHAT,
", %s %s %s\n",
_("compiled on"), __DATE__, __TIME__);
}
if (cfg_look_startup_logo ||
(cfg_look_weechat_slogan && cfg_look_weechat_slogan[0]) ||
cfg_look_startup_version)
gui_printf_color (NULL, COLOR_WIN_CHAT_PREFIX1,
"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
/* connect to all servers (with autoconnect flag) */
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (ptr_server->autoconnect)
{
gui_window_new (ptr_server, NULL);
if (server_connect (ptr_server))
irc_login (ptr_server);
}
}
gui_main_loop ();
server_disconnect_all ();
/* save config file */
config_write (NULL);
/* program ending */
wee_shutdown ();
/* make gcc happy (statement never executed) */
return 0;
}

View File

@ -1,98 +0,0 @@
/*
* Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
* Bounga <bounga@altern.org>
* Xahlexx <xahlexx@tuxisland.org>
* See README for License detail.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_H
#define __WEECHAT_H 1
#include <stdio.h>
#include <locale.h>
#include <libintl.h>
#define PACKAGE "weechat"
#define _(string) gettext(string)
#define N_(string) (string)
#define WEECHAT_NAME "WeeChat"
#define WEECHAT_VERSION "0.0.3-pre2"
#define WEECHAT_NAME_AND_VERSION WEECHAT_NAME " " WEECHAT_VERSION
#define WEECHAT_COPYRIGHT WEECHAT_NAME " (c) 2003 by Wee Team"
#define WEECHAT_WEBSITE "http://weechat.flashtux.org"
#define WEECHAT_ERROR _(WEECHAT_NAME " Error:")
#define WEECHAT_WARNING _(WEECHAT_NAME " Warning:")
/* debug mode, 0=normal use, 1=some debug msg, 2=full debug (developers only) */
#define DEBUG 0
/* log file */
#define WEECHAT_LOG_NAME "weechat.log"
/* license */
#define WEE_LICENSE \
WEECHAT_NAME_AND_VERSION " (c) Copyright 2003, compiled on " __DATE__ __TIME__ \
"Developed by FlashCode <flashcode@flashtux.org>\n" \
" Bounga <bounga@altern.org>\n" \
" Xahlexx <xahlexx@tuxisland.org>\n\n" \
"This program is free software; you can redistribute it and/or modify\n" \
"it under the terms of the GNU General Public License as published by\n" \
"the Free Software Foundation; either version 2 of the License, or\n" \
"(at your option) any later version.\n" \
"\n", \
\
"This program is distributed in the hope that it will be useful,\n" \
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \
"GNU General Public License for more details.\n" \
"\n" \
"You should have received a copy of the GNU General Public License\n" \
"along with this program; if not, write to the Free Software\n" \
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n"
#define WEE_USAGE \
WEECHAT_NAME_AND_VERSION " (c) Copyright 2003, compiled on " __DATE__ __TIME__ \
"Developed by FlashCode <flashcode@flashtux.org>\n" \
" Bounga <bounga@altern.org>\n" \
" Xahlexx <xahlexx@tuxisland.org>\n\n" \
" Bounga <bounga@altern.org>\n" \
" Xahlexx <xahlexx@tuxisland.org>\n\n" \
" -h, --help this help screen\n", \
" -l, --license display WeeChat license\n" \
" -v, --version display WeeChat version\n\n"
/* " -d, --display choose X display\n" \*/
/*#define DEFAULT_DISPLAY ":0" */
/*extern char *display_name; */
int quit_weechat;
extern int quit_weechat;
extern void log_printf (char *, ...);
extern void wee_shutdown ();
#endif /* weechat.h */