summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-05-15 22:13:54 +0200
committerSebastien Helleu <flashcode@flashtux.org>2008-05-15 22:13:54 +0200
commit91084108ae84755b073661c5fcb757db32b53eac (patch)
tree7b21caef71a5d758f1ac3a13348f858fc222f48b /src
parentf67a5164199431ec2330442cd170616d96d222d7 (diff)
downloadweechat-91084108ae84755b073661c5fcb757db32b53eac.zip
Add arguments for plugin init functions and "irc://.." command line option for irc plugin
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-command.c2
-rw-r--r--src/core/weechat.c124
-rw-r--r--src/core/weechat.h1
-rw-r--r--src/plugins/alias/alias.c6
-rw-r--r--src/plugins/charset/charset.c6
-rw-r--r--src/plugins/debug/debug.c6
-rw-r--r--src/plugins/demo/demo.c6
-rw-r--r--src/plugins/fifo/fifo.c6
-rw-r--r--src/plugins/irc/irc-server.c314
-rw-r--r--src/plugins/irc/irc-server.h6
-rw-r--r--src/plugins/irc/irc.c32
-rw-r--r--src/plugins/logger/logger.c6
-rw-r--r--src/plugins/plugin-api.c5
-rw-r--r--src/plugins/plugin.c50
-rw-r--r--src/plugins/plugin.h5
-rw-r--r--src/plugins/scripts/lua/weechat-lua.c5
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c6
-rw-r--r--src/plugins/scripts/python/weechat-python.c6
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby.c6
-rw-r--r--src/plugins/weechat-plugin.h3
-rw-r--r--src/plugins/xfer/xfer.c6
21 files changed, 206 insertions, 401 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 24847f194..296a7935d 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -2231,7 +2231,7 @@ command_upgrade (void *data, struct t_gui_buffer *buffer,
execvp (exec_args[0], exec_args);*/
/* this code should not be reached if execvp is ok */
- plugin_init (1);
+ plugin_init (1, 0, NULL);
/*string_iconv_fprintf (stderr,
_("Error: exec failed (program: \"%s\"), exiting WeeChat"),
diff --git a/src/core/weechat.c b/src/core/weechat.c
index f9c266897..44f622cad 100644
--- a/src/core/weechat.c
+++ b/src/core/weechat.c
@@ -75,7 +75,6 @@ char *weechat_home = NULL; /* home dir. (default: ~/.weechat) */
char *weechat_local_charset = NULL; /* example: ISO-8859-1, UTF-8 */
int weechat_server_cmd_line = 0; /* at least 1 server on cmd line */
int weechat_auto_load_plugins = 1; /* auto load plugins */
-int weechat_auto_connect = 1; /* auto connect in plugins */
/*
@@ -93,54 +92,28 @@ weechat_display_usage (char *exec_name)
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[...]]"),
+ _("Usage: %s [option...] [plugin:option...]\n"),
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"
- " -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"));
+ _(" -a, --no-connect disable auto-connect to servers at startup\n"
+ " -d, --dir <path> set WeeChat home directory (default: ~/.weechat)\n"
+ " -h, --help this help\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"
+ " plugin:option option for plugin\n"
+ " for example, irc plugin can connect\n"
+ " to server with url like:\n"
+ " irc[6][s]://[nickname[:password]@]"
+ "irc.example.org[/port][//#channel1][,#channel2[...]]\n"
+ " (look at plugins documentation for more information\n"
+ " about possible options)\n"));
string_iconv_fprintf(stdout, "\n");
}
/*
- * weechat_display_config_options: display config options
- */
-
-void
-weechat_display_config_options ()
-{
- string_iconv_fprintf (stdout,
- /* TRANSLATORS: %s is "weechat" */
- _("%s configuration options:\n"),
- PACKAGE_NAME);
- config_file_print_stdout (weechat_config_file);
-}
-
-/*
- * weechat_display_commands: display commands for one or more protocols
- */
-
-void
-weechat_display_commands ()
-{
- string_iconv_fprintf (stdout,
- /* TRANSLATORS: %s is "weechat" */
- _("%s internal commands:\n"),
- PACKAGE_NAME);
- string_iconv_fprintf (stdout, "\n");
- command_print_stdout ();
-}
-
-/*
* weechat_display_keys: display WeeChat default keys
*/
@@ -181,31 +154,10 @@ weechat_parse_args (int argc, char *argv[])
weechat_home = NULL;
weechat_server_cmd_line = 0;
weechat_auto_load_plugins = 1;
- weechat_auto_connect = 1;
for (i = 1; i < argc; i++)
{
- if ((strcmp (argv[i], "-a") == 0)
- || (strcmp (argv[i], "--no-connect") == 0))
- weechat_auto_connect = 0;
- else if ((strcmp (argv[i], "-c") == 0)
- || (strcmp (argv[i], "--config") == 0))
- {
- if (i + 1 < argc)
- {
- weechat_display_config_options (argv[i + 1]);
- weechat_shutdown (EXIT_SUCCESS, 0);
- }
- else
- {
- string_iconv_fprintf (stderr,
- _("Error: missing argument for \"%s\" "
- "option\n"),
- "--config");
- weechat_shutdown (EXIT_FAILURE, 0);
- }
- }
- else if ((strcmp (argv[i], "-d") == 0)
+ if ((strcmp (argv[i], "-d") == 0)
|| (strcmp (argv[i], "--dir") == 0))
{
if (i + 1 < argc)
@@ -237,12 +189,6 @@ weechat_parse_args (int argc, char *argv[])
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))
- {
- weechat_display_commands ();
- weechat_shutdown (EXIT_SUCCESS, 0);
- }
else if ((strcmp (argv[i], "-p") == 0)
|| (strcmp (argv[i], "--no-plugin") == 0))
{
@@ -267,40 +213,6 @@ weechat_parse_args (int argc, char *argv[])
string_iconv_fprintf (stdout, PACKAGE_VERSION "\n");
weechat_shutdown (EXIT_SUCCESS, 0);
}
- /*else if ((weechat_strncasecmp (argv[i], "irc", 3) == 0))
- {
- if (irc_server_init_with_url (argv[i], &server_tmp) < 0)
- {
- string_iconv_fprintf (stderr,
- _("Warning: invalid syntax for IRC server "
- "('%s'), ignored\n"),
- argv[i]);
- }
- else
- {
- if (!irc_server_new (server_tmp.name, server_tmp.autoconnect,
- server_tmp.autoreconnect,
- server_tmp.autoreconnect_delay,
- 1, server_tmp.address, server_tmp.port,
- server_tmp.ipv6, server_tmp.ssl,
- server_tmp.password, server_tmp.nick1,
- server_tmp.nick2, server_tmp.nick3,
- NULL, NULL, NULL, NULL, 0,
- server_tmp.autojoin, 1, NULL))
- string_iconv_fprintf (stderr,
- _("Warning: unable to create server "
- "('%s'), ignored\n"),
- argv[i]);
- irc_server_free_data (&server_tmp);
- server_cmd_line = 1;
- }
- }*/
- else
- {
- string_iconv_fprintf (stderr,
- _("Warning: unknown parameter '%s', ignored\n"),
- argv[i]);
- }
}
}
@@ -486,8 +398,8 @@ main (int argc, char *argv[])
//session_load (weechat_session); /* load previous session if asked */
weechat_welcome_message (); /* display WeeChat welcome message */
command_startup (0); /* command executed before plugins */
- plugin_init (weechat_auto_load_plugins); /* init plugin interface(s) */
- weechat_auto_connect = 1; /* auto-connect for future plugins */
+ plugin_init (weechat_auto_load_plugins, /* init plugin interface(s) */
+ argc, argv);
command_startup (1); /* command executed after plugins */
gui_main_loop (); /* WeeChat main loop */
diff --git a/src/core/weechat.h b/src/core/weechat.h
index 4a29f308b..7608d407e 100644
--- a/src/core/weechat.h
+++ b/src/core/weechat.h
@@ -103,7 +103,6 @@ extern time_t weechat_start_time;
extern int weechat_quit;
extern char *weechat_home;
extern char *weechat_local_charset;
-extern int weechat_auto_connect;
extern void weechat_dump (int crash);
extern void weechat_shutdown (int return_code, int crash);
diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c
index c64f28c49..724f3ed33 100644
--- a/src/plugins/alias/alias.c
+++ b/src/plugins/alias/alias.c
@@ -818,8 +818,12 @@ alias_completion_cb (void *data, char *completion, struct t_gui_buffer *buffer,
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
weechat_plugin = plugin;
if (!alias_config_init ())
diff --git a/src/plugins/charset/charset.c b/src/plugins/charset/charset.c
index fc67b889a..1964844e5 100644
--- a/src/plugins/charset/charset.c
+++ b/src/plugins/charset/charset.c
@@ -513,8 +513,12 @@ charset_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
weechat_plugin = plugin;
/* get terminal & internal charsets */
diff --git a/src/plugins/debug/debug.c b/src/plugins/debug/debug.c
index 514b11fc0..fa154405e 100644
--- a/src/plugins/debug/debug.c
+++ b/src/plugins/debug/debug.c
@@ -86,8 +86,12 @@ debug_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
weechat_plugin = plugin;
weechat_hook_command ("debug",
diff --git a/src/plugins/demo/demo.c b/src/plugins/demo/demo.c
index 1f4b2609f..2206a13c5 100644
--- a/src/plugins/demo/demo.c
+++ b/src/plugins/demo/demo.c
@@ -402,8 +402,12 @@ demo_signal_cb (void *data, char *signal, char *type_data, void *signal_data)
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
weechat_plugin = plugin;
weechat_hook_command ("demo_printf",
diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c
index 5e92498ed..1317fc9b5 100644
--- a/src/plugins/fifo/fifo.c
+++ b/src/plugins/fifo/fifo.c
@@ -345,8 +345,12 @@ fifo_config_cb (void *data, char *option, char *value)
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
weechat_plugin = plugin;
if (fifo_create ())
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index ba9852c11..63270e728 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -26,7 +26,6 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
-#include <pwd.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -374,23 +373,25 @@ irc_server_alloc (char *name)
}
/*
- * irc_server_init_with_url: init a server with url of this form:
- * irc://nick:pass@irc.toto.org:6667
- * returns: 0 = ok
- * -1 = invalid syntax
+ * irc_server_alloc_with_url: init a server with url of this form:
+ * irc://nick:pass@irc.toto.org:6667
+ * returns: 1 = ok
+ * 0 = error
*/
-/*
int
-irc_server_init_with_url (struct t_irc_server *server, char *irc_url)
+irc_server_alloc_with_url (char *irc_url)
{
char *url, *pos_server, *pos_channel, *pos, *pos2;
- int ipv6, ssl;
- struct passwd *my_passwd;
+ char *password, *nick1, *nicks, *autojoin;
+ int ipv6, ssl, length;
+ struct t_irc_server *ptr_server;
- irc_server_init (server);
ipv6 = 0;
ssl = 0;
+ password = NULL;
+ nick1 = NULL;
+ autojoin = NULL;
if (weechat_strncasecmp (irc_url, "irc6://", 7) == 0)
{
pos = irc_url + 7;
@@ -413,7 +414,7 @@ irc_server_init_with_url (struct t_irc_server *server, char *irc_url)
pos = irc_url + 6;
}
else
- return -1;
+ return 0;
url = strdup (pos);
pos_server = strchr (url, '@');
@@ -424,286 +425,79 @@ irc_server_init_with_url (struct t_irc_server *server, char *irc_url)
if (!pos[0])
{
free (url);
- return -1;
+ return 0;
}
pos2 = strchr (url, ':');
if (pos2)
{
pos2[0] = '\0';
- server->password = strdup (pos2 + 1);
+ password = strdup (pos2 + 1);
}
- server->nick1 = strdup (url);
+ nick1 = strdup (url);
}
else
- {
- if ((my_passwd = getpwuid (geteuid ())) != NULL)
- server->nick1 = strdup (my_passwd->pw_name);
- else
- {
- weechat_printf (NULL,
- _("%s%s: error retrieving user's name: %s"),
- weechat_prefix ("error"), "irc",
- strerror (errno));
- free (url);
- return -1;
- }
pos_server = url;
- }
+
if (!pos_server[0])
{
free (url);
- return -1;
+ return 0;
}
- pos_channel = strchr (pos_server, '/');
+ pos_channel = strstr (pos_server, "//");
if (pos_channel)
{
pos_channel[0] = '\0';
- pos_channel++;
+ pos_channel += 2;
}
- pos = strchr (pos_server, ':');
- if (pos)
- {
- pos[0] = '\0';
- server->port = atoi (pos + 1);
- }
- server->name = strdup (pos_server);
- server->address = strdup (pos_server);
if (pos_channel && pos_channel[0])
{
if (irc_channel_is_channel (pos_channel))
- server->autojoin = strdup (pos_channel);
+ autojoin = strdup (pos_channel);
else
{
- server->autojoin = malloc (strlen (pos_channel) + 2);
- strcpy (server->autojoin, "#");
- strcat (server->autojoin, pos_channel);
+ autojoin = malloc (strlen (pos_channel) + 2);
+ strcpy (autojoin, "#");
+ strcat (autojoin, pos_channel);
}
}
- free (url);
-
- server->ipv6 = ipv6;
- server->ssl = ssl;
-
- // some default values
- if (server->port < 0)
- server->port = IRC_SERVER_DEFAULT_PORT;
- server->nick2 = malloc (strlen (server->nick1) + 2);
- strcpy (server->nick2, server->nick1);
- server->nick2 = strcat (server->nick2, "1");
- server->nick3 = malloc (strlen (server->nick1) + 2);
- strcpy (server->nick3, server->nick1);
- server->nick3 = strcat (server->nick3, "2");
+ ptr_server = irc_server_alloc (pos_server);
- return 0;
-}
-*/
-
-/*
- * irc_server_init_with_config_options: init a server with config options
- * (called when reading config file)
- */
-/*
-void
-irc_server_init_with_config_options (struct t_irc_server *server,
- struct t_config_section *section,
- int config_reload)
-{
- struct t_config_option *ptr_option;
- struct t_irc_server *ptr_server;
-
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_NAME);
- if (!ptr_option)
- {
- irc_server_free (server);
- return;
- }
-
- if (config_reload)
+ if (ptr_server)
{
- for (ptr_server = irc_servers; ptr_server;
- ptr_server = ptr_server->next_server)
+ irc_server_set_addresses (ptr_server, pos_server);
+ ptr_server->ipv6 = ipv6;
+ ptr_server->ssl = ssl;
+
+ if (nick1)
{
- if ((ptr_server != server)
- && (strcmp (ptr_server->name,
- weechat_config_string (ptr_option)) == 0))
- break;
+ length = ((strlen (nick1) + 2) * 5) + 1;
+ nicks = malloc (length);
+ if (nicks)
+ {
+ snprintf (nicks, length,
+ "%s,%s1,%s2,%s3,%s4",
+ nick1, nick1, nick1, nick1, nick1);
+ irc_server_set_nicks (ptr_server, nicks);
+ free (nicks);
+ }
}
- if (ptr_server)
- irc_server_free (server);
- else
- ptr_server = server;
- }
- else
- ptr_server = server;
-
- // server internal name
- if (ptr_server->name)
- free (ptr_server->name);
- ptr_server->name = strdup (weechat_config_string (ptr_option));
-
- // auto-connect
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_AUTOCONNECT);
- if (ptr_option)
- ptr_server->autoconnect = weechat_config_integer (ptr_option);
-
- // auto-reconnect
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_AUTORECONNECT);
- if (ptr_option)
- ptr_server->autoreconnect = weechat_config_integer (ptr_option);
-
- // auto-reconnect delay
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_AUTORECONNECT_DELAY);
- if (ptr_option)
- ptr_server->autoreconnect_delay = weechat_config_integer (ptr_option);
-
- // addresses
- if (ptr_server->addresses)
- {
- free (ptr_server->addresses);
- ptr_server->addresses = NULL;
- }
- ptr_server->addresses_count = 0;
- if (ptr_server->addresses_array)
- {
- weechat_string_free_exploded (ptr_server->addresses_array);
- ptr_server->addresses_array = NULL;
- }
- if (ptr_server->ports_array)
- {
- free (ptr_server->ports_array);
- ptr_server->ports_array = NULL;
- }
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_ADDRESSES);
- if (ptr_option)
- irc_server_set_addresses (ptr_server, weechat_config_string (ptr_option));
-
- // ipv6
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_IPV6);
- if (ptr_option)
- ptr_server->ipv6 = weechat_config_integer (ptr_option);
-
- // SSL
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_SSL);
- if (ptr_option)
- ptr_server->ssl = weechat_config_integer (ptr_option);
-
- // password
- if (ptr_server->password)
- {
- free (ptr_server->password);
- ptr_server->password = NULL;
- }
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_PASSWORD);
- if (ptr_option)
- ptr_server->password = strdup (weechat_config_string (ptr_option));
-
- // nicks
- if (ptr_server->nicks)
- {
- free (ptr_server->nicks);
- ptr_server->nicks = NULL;
- }
- ptr_server->nicks_count = 0;
- if (ptr_server->nicks_array)
- {
- weechat_string_free_exploded (ptr_server->nicks_array);
- ptr_server->nicks_array = NULL;
- }
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_NICKS);
- if (ptr_option)
- irc_server_set_nicks (ptr_server, weechat_config_string (ptr_option));
-
- // username
- if (ptr_server->username)
- {
- free (ptr_server->username);
- ptr_server->username = NULL;
- }
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_USERNAME);
- if (ptr_option)
- ptr_server->username = strdup (weechat_config_string (ptr_option));
-
- // realname
- if (ptr_server->realname)
- {
- free (ptr_server->realname);
- ptr_server->realname = NULL;
- }
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_REALNAME);
- if (ptr_option)
- ptr_server->realname = strdup (weechat_config_string (ptr_option));
-
- // hostname
- if (ptr_server->hostname)
- {
- free (ptr_server->hostname);
- ptr_server->hostname = NULL;
- }
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_HOSTNAME);
- if (ptr_option)
- ptr_server->hostname = strdup (weechat_config_string (ptr_option));
-
- // command
- if (ptr_server->command)
- {
- free (ptr_server->command);
- ptr_server->command = NULL;
- }
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_COMMAND);
- if (ptr_option)
- ptr_server->command = strdup (weechat_config_string (ptr_option));
-
- // command delay
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_COMMAND_DELAY);
- if (ptr_option)
- ptr_server->command_delay = weechat_config_integer (ptr_option);
-
- // auto-join
- if (ptr_server->autojoin)
- {
- free (ptr_server->autojoin);
- ptr_server->autojoin = NULL;
- }
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_AUTOJOIN);
- if (ptr_option)
- ptr_server->autojoin = strdup (weechat_config_string (ptr_option));
-
- // auto-rejoin
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_AUTOREJOIN);
- if (ptr_option)
- ptr_server->autorejoin = weechat_config_integer (ptr_option);
-
- // notify_levels
- if (ptr_server->notify_levels)
- {
- free (ptr_server->notify_levels);
- ptr_server->notify_levels = NULL;
- }
- ptr_option = weechat_config_search_option (NULL, section,
- IRC_CONFIG_SERVER_NOTIFY_LEVELS);
- if (ptr_option)
- ptr_server->notify_levels = strdup (weechat_config_string (ptr_option));
+ ptr_server->password = (password) ? strdup (password) : NULL;
+ ptr_server->autojoin = (autojoin) ? strdup (autojoin) : NULL;
+ ptr_server->temp_server = 1;
+ ptr_server->autoconnect = 1;
+ }
+
+ if (password)
+ free (password);
+ if (nick1)
+ free (nick1);
+ if (autojoin)
+ free (autojoin);
+ free (url);
- ptr_server->reloaded_from_config = 1;
+ return (ptr_server) ? 1 : 0;
}
-*/
/*
* irc_server_outqueue_add: add a message in out queue
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index c1903d903..b63c18526 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -146,11 +146,7 @@ extern void irc_server_set_with_option (struct t_irc_server *server,
struct t_config_option *option);
extern void irc_server_init (struct t_irc_server *server);
extern struct t_irc_server *irc_server_alloc (char *name);
-
-/*extern void irc_server_init_with_config_options (struct t_irc_server *server,
- struct t_config_section *section,
- int config_reload);
-*/
+extern int irc_server_alloc_with_url (char *irc_url);
extern struct t_irc_server *irc_server_new (char *name, int autoconnect,
int autoreconnect,
int autoreconnect_delay,
diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c
index b850cceb4..c07e5ce1d 100644
--- a/src/plugins/irc/irc.c
+++ b/src/plugins/irc/irc.c
@@ -83,9 +83,9 @@ irc_signal_quit_cb (void *data, char *signal, char *type_data,
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
- char *auto_connect;
+ int i, auto_connect;
weechat_plugin = plugin;
@@ -113,10 +113,30 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
/* hook completions */
irc_completion_init ();
-
- auto_connect = weechat_info_get ("auto_connect");
- irc_server_auto_connect ((auto_connect && (strcmp (auto_connect, "1") == 0)) ? 1 : 0,
- 0);
+
+ /* look at arguments */
+ auto_connect = 1;
+ for (i = 0; i < argc; i++)
+ {
+ if ((weechat_strcasecmp (argv[i], "-a") == 0)
+ || (weechat_strcasecmp (argv[i], "--no-connect") == 0))
+ {
+ auto_connect = 0;
+ }
+ else if ((weechat_strncasecmp (argv[i], "irc", 3) == 0))
+ {
+ if (!irc_server_alloc_with_url (argv[i]))
+ {
+ weechat_printf (NULL,
+ _("%s%s: invalid syntax for IRC server "
+ "('%s'), ignored"),
+ weechat_prefix ("error"), "irc",
+ argv[i]);
+ }
+ }
+ }
+
+ irc_server_auto_connect (auto_connect, 0);
irc_hook_timer = weechat_hook_timer (1 * 1000, 0, 0,
&irc_server_timer_cb, NULL);
diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c
index add0c81a3..b73aad733 100644
--- a/src/plugins/logger/logger.c
+++ b/src/plugins/logger/logger.c
@@ -678,8 +678,12 @@ logger_config_cb (void *data, char *option, char *value)
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
weechat_plugin = plugin;
if (!logger_config_read ())
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index 967e75478..a24f16937 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -459,11 +459,6 @@ plugin_api_info_get (struct t_weechat_plugin *plugin, char *info)
snprintf (value, sizeof (value), "%d", gui_filters_enabled);
return value;
}
- else if (string_strcasecmp (info, "auto_connect") == 0)
- {
- snprintf (value, sizeof (value), "%d", weechat_auto_connect);
- return value;
- }
/* info not found */
return NULL;
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index fd26a3347..250c0481f 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -56,6 +56,9 @@
struct t_weechat_plugin *weechat_plugins = NULL;
struct t_weechat_plugin *last_weechat_plugin = NULL;
+int plugin_argc; /* command line arguments (used only */
+char **plugin_argv; /* first time loading plugin) */
+
/*
* plugin_search: search a plugin by name
@@ -90,7 +93,8 @@ plugin_load (char *filename)
char *name, *author, *description, *version, *weechat_version, *license;
char *charset;
t_weechat_init_func *init_func;
- int rc;
+ int rc, i, argc;
+ char **argv;
struct t_weechat_plugin *new_plugin;
if (!filename)
@@ -427,9 +431,42 @@ plugin_load (char *filename)
else
weechat_plugins = new_plugin;
last_weechat_plugin = new_plugin;
+
+ /* build arguments for plugin */
+ argc = 0;
+ argv = NULL;
+ if (plugin_argc > 0)
+ {
+ argv = malloc ((plugin_argc + 1) * sizeof (*argv));
+ if (argv)
+ {
+ argc = 0;
+ for (i = 0; i < plugin_argc; i++)
+ {
+ if ((string_strcasecmp (plugin_argv[i], "-a") == 0)
+ || (string_strcasecmp (plugin_argv[i], "--no-connect") == 0)
+ || (string_strncasecmp (plugin_argv[i], name, strlen (name)) == 0))
+ {
+ argv[argc] = plugin_argv[i];
+ argc++;
+ }
+ }
+ if (argc == 0)
+ {
+ free (argv);
+ argv = NULL;
+ }
+ else
+ argv[argc] = NULL;
+ }
+ }
/* init plugin */
- rc = ((t_weechat_init_func *)init_func) (new_plugin);
+ rc = ((t_weechat_init_func *)init_func) (new_plugin, argc, argv);
+
+ if (argv)
+ free (argv);
+
if (rc != WEECHAT_RC_OK)
{
gui_chat_printf (NULL,
@@ -735,8 +772,11 @@ plugin_reload_name (char *name)
*/
void
-plugin_init (int auto_load)
+plugin_init (int auto_load, int argc, char *argv[])
{
+ plugin_argc = argc;
+ plugin_argv = argv;
+
/* read plugins options on disk */
plugin_config_init ();
plugin_config_read ();
@@ -744,6 +784,10 @@ plugin_init (int auto_load)
/* auto-load plugins if asked */
if (auto_load)
plugin_auto_load ();
+
+ /* discard command arguments for future plugins */
+ plugin_argc = 0;
+ plugin_argv = NULL;
}
/*
diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h
index ca2d3e3a2..1d05abe98 100644
--- a/src/plugins/plugin.h
+++ b/src/plugins/plugin.h
@@ -22,7 +22,8 @@
#include "weechat-plugin.h"
-typedef int (t_weechat_init_func) (struct t_weechat_plugin *plugin);
+typedef int (t_weechat_init_func) (struct t_weechat_plugin *plugin,
+ int argc, char *argv[]);
typedef int (t_weechat_end_func) (struct t_weechat_plugin *plugin);
extern struct t_weechat_plugin *weechat_plugins;
@@ -38,7 +39,7 @@ extern void plugin_unload (struct t_weechat_plugin *plugin);
extern void plugin_unload_name (char *name);
extern void plugin_unload_all ();
extern void plugin_reload_name (char *name);
-extern void plugin_init (int auto_load);
+extern void plugin_init (int auto_load, int argc, char *argv[]);
extern void plugin_end ();
extern void plugin_print_log ();
diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c
index 2aa388710..f6ca6a6e9 100644
--- a/src/plugins/scripts/lua/weechat-lua.c
+++ b/src/plugins/scripts/lua/weechat-lua.c
@@ -470,8 +470,11 @@ weechat_lua_buffer_closed_cb (void *data, char *signal, char *type_data,
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
weechat_lua_plugin = plugin;
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index 638c8ef69..ec65da636 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -611,12 +611,16 @@ weechat_perl_buffer_closed_cb (void *data, char *signal, char *type_data,
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
#ifndef MULTIPLICITY
char *perl_args[] = { "", "-e", "0" };
#endif
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
weechat_perl_plugin = plugin;
#ifndef MULTIPLICITY
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c
index 32b46f581..c593aa102 100644
--- a/src/plugins/scripts/python/weechat-python.c
+++ b/src/plugins/scripts/python/weechat-python.c
@@ -644,8 +644,12 @@ weechat_python_buffer_closed_cb (void *data, char *signal, char *type_data,
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
weechat_python_plugin = plugin;
/* init stdout/stderr buffer */
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c
index 7e920c612..190aab498 100644
--- a/src/plugins/scripts/ruby/weechat-ruby.c
+++ b/src/plugins/scripts/ruby/weechat-ruby.c
@@ -646,7 +646,7 @@ weechat_ruby_buffer_closed_cb (void *data, char *signal, char *type_data,
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
int ruby_error;
char *weechat_ruby_code =
@@ -692,6 +692,10 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
"end\n"
};
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
weechat_ruby_plugin = plugin;
ruby_error = 0;
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 0bcf417fc..8d49971a7 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -426,7 +426,8 @@ struct t_weechat_plugin
/* WeeChat developers: ALWAYS add new functions at the end */
};
-extern int weechat_plugin_init (struct t_weechat_plugin *plugin);
+extern int weechat_plugin_init (struct t_weechat_plugin *plugin,
+ int argc, char *argv[]);
extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
/* macros for easy call to plugin API */
diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c
index 4d07d0830..a6d558773 100644
--- a/src/plugins/xfer/xfer.c
+++ b/src/plugins/xfer/xfer.c
@@ -1194,8 +1194,12 @@ xfer_debug_dump_cb (void *data, char *signal, char *type_data,
*/
int
-weechat_plugin_init (struct t_weechat_plugin *plugin)
+weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
+ /* make C compiler happy */
+ (void) argc;
+ (void) argv;
+
weechat_plugin = plugin;
if (!xfer_config_init ())