Added alias plugin, added missing config file functions in plugins API
This commit is contained in:
parent
e0826e1ce7
commit
2888d41425
@ -36,6 +36,7 @@ OPTION(ENABLE_GTK "Enable GTK interface")
|
||||
OPTION(DISABLE_NLS "Disable Native Language Support")
|
||||
OPTION(DISABLE_GNUTLS "Disable SSLv3/TLS connection support")
|
||||
OPTION(DISABLE_IRC "Disable IRC plugin")
|
||||
OPTION(DISABLE_ALIAS "Disable Alias plugin")
|
||||
OPTION(DISABLE_ASPELL "Disable Aspell plugin")
|
||||
OPTION(DISABLE_CHARSET "Disable Charset plugin")
|
||||
OPTION(DISABLE_FIFO "Disable FIFO plugin")
|
||||
|
21
configure.in
21
configure.in
@ -92,6 +92,7 @@ AH_VERBATIM([PREFIX], [#undef PREFIX])
|
||||
AH_VERBATIM([WEECHAT_LIBDIR], [#undef WEECHAT_LIBDIR])
|
||||
AH_VERBATIM([WEECHAT_SHAREDIR], [#undef WEECHAT_SHAREDIR])
|
||||
AH_VERBATIM([PLUGIN_IRC], [#undef PLUGIN_IRC])
|
||||
AH_VERBATIM([PLUGIN_ALIAS], [#undef PLUGIN_ALIAS])
|
||||
AH_VERBATIM([PLUGIN_ASPELL], [#undef PLUGIN_ASPELL])
|
||||
AH_VERBATIM([PLUGIN_CHARSET], [#undef PLUGIN_CHARSET])
|
||||
AH_VERBATIM([PLUGIN_FIFO], [#undef PLUGIN_FIFO])
|
||||
@ -114,6 +115,7 @@ AC_ARG_ENABLE(gtk, [ --enable-gtk Turn on Gtk interface (d
|
||||
AC_ARG_ENABLE(qt, [ --enable-qt Turn on Qt interface (default=off)],enable_qt=$enableval,enable_qt=no)
|
||||
AC_ARG_ENABLE(gnutls, [ --disable-gnutls Turn off gnutls support (default=compiled if found)],enable_gnutls=$enableval,enable_gnutls=yes)
|
||||
AC_ARG_ENABLE(irc, [ --disable-irc Turn off IRC plugin (default=compiled)],enable_irc=$enableval,enable_irc=yes)
|
||||
AC_ARG_ENABLE(alias, [ --disable-alias Turn off Alias plugin (default=compiled)],enable_alias=$enableval,enable_alias=yes)
|
||||
AC_ARG_ENABLE(aspell, [ --disable-aspell Turn off Aspell plugin (default=compiled if found)],enable_aspell=$enableval,enable_aspell=yes)
|
||||
AC_ARG_ENABLE(charset, [ --disable-charset Turn off Charset plugin (default=compiled if found)],enable_charset=$enableval,enable_charset=yes)
|
||||
AC_ARG_ENABLE(fifo, [ --disable-fifo Turn off Fifo plugin (default=compiled)],enable_fifo=$enableval,enable_fifo=yes)
|
||||
@ -273,7 +275,7 @@ if test "x$enable_scripts" = "xno" ; then
|
||||
enable_lua="no"
|
||||
fi
|
||||
|
||||
# ------------------------------------ irc -------------------------------------
|
||||
# ----------------------------------- irc --------------------------------------
|
||||
|
||||
if test "x$enable_irc" = "xyes" ; then
|
||||
AC_DEFINE(PLUGIN_IRC)
|
||||
@ -281,6 +283,18 @@ else
|
||||
not_asked="$not_asked irc"
|
||||
fi
|
||||
|
||||
# ---------------------------------- alias -------------------------------------
|
||||
|
||||
if test "x$enable_alias" = "xyes" ; then
|
||||
ALIAS_CFLAGS=""
|
||||
ALIAS_LFLAGS=""
|
||||
AC_SUBST(ALIAS_CFLAGS)
|
||||
AC_SUBST(ALIAS_LFLAGS)
|
||||
AC_DEFINE(PLUGIN_ALIAS)
|
||||
else
|
||||
not_asked="$not_asked alias"
|
||||
fi
|
||||
|
||||
# ---------------------------------- aspell ------------------------------------
|
||||
|
||||
if test "x$enable_aspell" = "xyes" ; then
|
||||
@ -833,6 +847,7 @@ AM_CONDITIONAL(GUI_WXWIDGETS, test "$enable_wxwidgets" = "yes")
|
||||
AM_CONDITIONAL(GUI_GTK, test "$enable_gtk" = "yes")
|
||||
AM_CONDITIONAL(GUI_QT, test "$enable_qt" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_IRC, test "$enable_irc" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_ALIAS, test "$enable_alias" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_ASPELL, test "$enable_aspell" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_CHARSET, test "$enable_charset" = "yes")
|
||||
AM_CONDITIONAL(PLUGIN_FIFO, test "$enable_fifo" = "yes")
|
||||
@ -861,6 +876,7 @@ AC_OUTPUT([Makefile
|
||||
src/core/Makefile
|
||||
src/plugins/Makefile
|
||||
src/plugins/irc/Makefile
|
||||
src/plugins/alias/Makefile
|
||||
src/plugins/aspell/Makefile
|
||||
src/plugins/charset/Makefile
|
||||
src/plugins/fifo/Makefile
|
||||
@ -908,6 +924,9 @@ listplugins=""
|
||||
if test "x$enable_irc" = "xyes" ; then
|
||||
listplugins="$listplugins irc"
|
||||
fi
|
||||
if test "x$enable_alias" = "xyes"; then
|
||||
listplugins="$listplugins alias"
|
||||
fi
|
||||
if test "x$enable_aspell" = "xyes"; then
|
||||
listplugins="$listplugins aspell"
|
||||
fi
|
||||
|
@ -1,5 +1,3 @@
|
||||
./src/core/wee-alias.c
|
||||
./src/core/wee-alias.h
|
||||
./src/core/wee-backtrace.c
|
||||
./src/core/wee-backtrace.h
|
||||
./src/core/weechat.c
|
||||
@ -10,8 +8,6 @@
|
||||
./src/core/wee-config-file.c
|
||||
./src/core/wee-config-file.h
|
||||
./src/core/wee-config.h
|
||||
./src/core/wee-config-option.c
|
||||
./src/core/wee-config-option.h
|
||||
./src/core/wee-hook.c
|
||||
./src/core/wee-hook.h
|
||||
./src/core/wee-input.c
|
||||
@ -20,10 +16,10 @@
|
||||
./src/core/wee-list.h
|
||||
./src/core/wee-log.c
|
||||
./src/core/wee-log.h
|
||||
./src/core/wee-upgrade.c
|
||||
./src/core/wee-upgrade.h
|
||||
./src/core/wee-string.c
|
||||
./src/core/wee-string.h
|
||||
./src/core/wee-upgrade.c
|
||||
./src/core/wee-upgrade.h
|
||||
./src/core/wee-utf8.c
|
||||
./src/core/wee-utf8.h
|
||||
./src/core/wee-util.c
|
||||
@ -68,8 +64,6 @@
|
||||
./src/gui/gui-input.h
|
||||
./src/gui/gui-keyboard.c
|
||||
./src/gui/gui-keyboard.h
|
||||
./src/gui/gui-log.c
|
||||
./src/gui/gui-log.h
|
||||
./src/gui/gui-main.h
|
||||
./src/gui/gui-nicklist.c
|
||||
./src/gui/gui-nicklist.h
|
||||
@ -80,14 +74,19 @@
|
||||
./src/gui/qt/gui-qt.h
|
||||
./src/gui/wxwidgets/gui-display.c
|
||||
./src/gui/wxwidgets/gui-input.c
|
||||
./src/plugins/alias/alias.c
|
||||
./src/plugins/alias/alias.h
|
||||
./src/plugins/aspell/aspell.c
|
||||
./src/plugins/aspell/aspell.h
|
||||
./src/plugins/charset/charset.c
|
||||
./src/plugins/charset/charset.h
|
||||
./src/plugins/demo/demo.c
|
||||
./src/plugins/demo/demo.h
|
||||
./src/plugins/fifo/fifo.c
|
||||
./src/plugins/fifo/fifo.h
|
||||
./src/plugins/irc/irc-buffer.c
|
||||
./src/plugins/irc/irc-buffer.h
|
||||
./src/plugins/irc/irc.c
|
||||
./src/plugins/irc/irc-channel.c
|
||||
./src/plugins/irc/irc-channel.h
|
||||
./src/plugins/irc/irc-color.c
|
||||
@ -96,7 +95,6 @@
|
||||
./src/plugins/irc/irc-command.h
|
||||
./src/plugins/irc/irc-config.c
|
||||
./src/plugins/irc/irc-config.h
|
||||
./src/plugins/irc/irc-core.c
|
||||
./src/plugins/irc/irc-dcc.c
|
||||
./src/plugins/irc/irc-dcc.h
|
||||
./src/plugins/irc/irc-display.c
|
||||
@ -110,12 +108,18 @@
|
||||
./src/plugins/irc/irc-protocol.h
|
||||
./src/plugins/irc/irc-server.c
|
||||
./src/plugins/irc/irc-server.h
|
||||
./src/plugins/logger/logger-buffer.c
|
||||
./src/plugins/logger/logger-buffer.h
|
||||
./src/plugins/logger/logger.c
|
||||
./src/plugins/logger/logger.h
|
||||
./src/plugins/plugin-api.c
|
||||
./src/plugins/plugin-api.h
|
||||
./src/plugins/plugin.c
|
||||
./src/plugins/plugin-config.c
|
||||
./src/plugins/plugin-config.h
|
||||
./src/plugins/plugin.h
|
||||
./src/plugins/plugin-list.c
|
||||
./src/plugins/plugin-list.h
|
||||
./src/plugins/scripts/lua/lua.c
|
||||
./src/plugins/scripts/perl/perl.c
|
||||
./src/plugins/scripts/python/python.c
|
||||
|
@ -1,6 +1,4 @@
|
||||
SET(WEECHAT_SOURCES
|
||||
./src/core/wee-alias.c
|
||||
./src/core/wee-alias.h
|
||||
./src/core/wee-backtrace.c
|
||||
./src/core/wee-backtrace.h
|
||||
./src/core/weechat.c
|
||||
@ -11,8 +9,6 @@ SET(WEECHAT_SOURCES
|
||||
./src/core/wee-config-file.c
|
||||
./src/core/wee-config-file.h
|
||||
./src/core/wee-config.h
|
||||
./src/core/wee-config-option.c
|
||||
./src/core/wee-config-option.h
|
||||
./src/core/wee-hook.c
|
||||
./src/core/wee-hook.h
|
||||
./src/core/wee-input.c
|
||||
@ -21,10 +17,10 @@ SET(WEECHAT_SOURCES
|
||||
./src/core/wee-list.h
|
||||
./src/core/wee-log.c
|
||||
./src/core/wee-log.h
|
||||
./src/core/wee-upgrade.c
|
||||
./src/core/wee-upgrade.h
|
||||
./src/core/wee-string.c
|
||||
./src/core/wee-string.h
|
||||
./src/core/wee-upgrade.c
|
||||
./src/core/wee-upgrade.h
|
||||
./src/core/wee-utf8.c
|
||||
./src/core/wee-utf8.h
|
||||
./src/core/wee-util.c
|
||||
@ -69,8 +65,6 @@ SET(WEECHAT_SOURCES
|
||||
./src/gui/gui-input.h
|
||||
./src/gui/gui-keyboard.c
|
||||
./src/gui/gui-keyboard.h
|
||||
./src/gui/gui-log.c
|
||||
./src/gui/gui-log.h
|
||||
./src/gui/gui-main.h
|
||||
./src/gui/gui-nicklist.c
|
||||
./src/gui/gui-nicklist.h
|
||||
@ -81,14 +75,19 @@ SET(WEECHAT_SOURCES
|
||||
./src/gui/qt/gui-qt.h
|
||||
./src/gui/wxwidgets/gui-display.c
|
||||
./src/gui/wxwidgets/gui-input.c
|
||||
./src/plugins/alias/alias.c
|
||||
./src/plugins/alias/alias.h
|
||||
./src/plugins/aspell/aspell.c
|
||||
./src/plugins/aspell/aspell.h
|
||||
./src/plugins/charset/charset.c
|
||||
./src/plugins/charset/charset.h
|
||||
./src/plugins/demo/demo.c
|
||||
./src/plugins/demo/demo.h
|
||||
./src/plugins/fifo/fifo.c
|
||||
./src/plugins/fifo/fifo.h
|
||||
./src/plugins/irc/irc-buffer.c
|
||||
./src/plugins/irc/irc-buffer.h
|
||||
./src/plugins/irc/irc.c
|
||||
./src/plugins/irc/irc-channel.c
|
||||
./src/plugins/irc/irc-channel.h
|
||||
./src/plugins/irc/irc-color.c
|
||||
@ -97,7 +96,6 @@ SET(WEECHAT_SOURCES
|
||||
./src/plugins/irc/irc-command.h
|
||||
./src/plugins/irc/irc-config.c
|
||||
./src/plugins/irc/irc-config.h
|
||||
./src/plugins/irc/irc-core.c
|
||||
./src/plugins/irc/irc-dcc.c
|
||||
./src/plugins/irc/irc-dcc.h
|
||||
./src/plugins/irc/irc-display.c
|
||||
@ -111,12 +109,18 @@ SET(WEECHAT_SOURCES
|
||||
./src/plugins/irc/irc-protocol.h
|
||||
./src/plugins/irc/irc-server.c
|
||||
./src/plugins/irc/irc-server.h
|
||||
./src/plugins/logger/logger-buffer.c
|
||||
./src/plugins/logger/logger-buffer.h
|
||||
./src/plugins/logger/logger.c
|
||||
./src/plugins/logger/logger.h
|
||||
./src/plugins/plugin-api.c
|
||||
./src/plugins/plugin-api.h
|
||||
./src/plugins/plugin.c
|
||||
./src/plugins/plugin-config.c
|
||||
./src/plugins/plugin-config.h
|
||||
./src/plugins/plugin.h
|
||||
./src/plugins/plugin-list.c
|
||||
./src/plugins/plugin-list.h
|
||||
./src/plugins/scripts/lua/lua.c
|
||||
./src/plugins/scripts/perl/perl.c
|
||||
./src/plugins/scripts/python/python.c
|
||||
|
@ -14,11 +14,11 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
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-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)
|
||||
SET(LIB_CORE_SRC weechat.c weechat.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-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)
|
||||
|
@ -20,8 +20,6 @@ noinst_LIBRARIES = lib_weechat_core.a
|
||||
|
||||
lib_weechat_core_a_SOURCES = weechat.c \
|
||||
weechat.h \
|
||||
wee-alias.c \
|
||||
wee-alias.h \
|
||||
wee-backtrace.c \
|
||||
wee-backtrace.h \
|
||||
wee-command.c \
|
||||
|
@ -1,380 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* wee-alias.c: WeeChat alias */
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "weechat.h"
|
||||
#include "wee-alias.h"
|
||||
#include "wee-config.h"
|
||||
#include "wee-string.h"
|
||||
#include "../gui/gui-chat.h"
|
||||
|
||||
|
||||
struct alias *weechat_alias = NULL;
|
||||
struct alias *weechat_last_alias = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* alias_search: search an alias
|
||||
*/
|
||||
|
||||
struct alias *
|
||||
alias_search (char *alias_name)
|
||||
{
|
||||
struct alias *ptr_alias;
|
||||
|
||||
for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias)
|
||||
{
|
||||
if (string_strcasecmp (alias_name, ptr_alias->name) == 0)
|
||||
return ptr_alias;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_find_pos: find position for an alias (for sorting aliases)
|
||||
*/
|
||||
|
||||
struct alias *
|
||||
alias_find_pos (char *alias_name)
|
||||
{
|
||||
struct alias *ptr_alias;
|
||||
|
||||
for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias)
|
||||
{
|
||||
if (string_strcasecmp (alias_name, ptr_alias->name) < 0)
|
||||
return ptr_alias;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_insert_sorted: insert alias into sorted list
|
||||
*/
|
||||
|
||||
void
|
||||
alias_insert_sorted (struct alias *alias)
|
||||
{
|
||||
struct alias *pos_alias;
|
||||
|
||||
pos_alias = alias_find_pos (alias->name);
|
||||
|
||||
if (weechat_alias)
|
||||
{
|
||||
if (pos_alias)
|
||||
{
|
||||
/* insert alias into the list (before alias found) */
|
||||
alias->prev_alias = pos_alias->prev_alias;
|
||||
alias->next_alias = pos_alias;
|
||||
if (pos_alias->prev_alias)
|
||||
pos_alias->prev_alias->next_alias = alias;
|
||||
else
|
||||
weechat_alias = alias;
|
||||
pos_alias->prev_alias = alias;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* add alias to the end */
|
||||
alias->prev_alias = weechat_last_alias;
|
||||
alias->next_alias = NULL;
|
||||
weechat_last_alias->next_alias = alias;
|
||||
weechat_last_alias = alias;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
alias->prev_alias = NULL;
|
||||
alias->next_alias = NULL;
|
||||
weechat_alias = alias;
|
||||
weechat_last_alias = alias;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_new: create new alias and add it to alias list
|
||||
*/
|
||||
|
||||
struct alias *
|
||||
alias_new (char *name, char *command)
|
||||
{
|
||||
struct alias *new_alias, *ptr_alias;
|
||||
|
||||
while (name[0] == '/')
|
||||
{
|
||||
name++;
|
||||
}
|
||||
|
||||
if (string_strcasecmp (name, "builtin") == 0)
|
||||
return NULL;
|
||||
|
||||
ptr_alias = alias_search (name);
|
||||
if (ptr_alias)
|
||||
{
|
||||
if (ptr_alias->command)
|
||||
free (ptr_alias->command);
|
||||
ptr_alias->command = strdup (command);
|
||||
return ptr_alias;
|
||||
}
|
||||
|
||||
if ((new_alias = ((struct alias *) malloc (sizeof (struct alias)))))
|
||||
{
|
||||
new_alias->name = strdup (name);
|
||||
new_alias->command = (char *) malloc (strlen (command) + 1);
|
||||
new_alias->running = 0;
|
||||
if (new_alias->command)
|
||||
strcpy (new_alias->command, command);
|
||||
alias_insert_sorted (new_alias);
|
||||
return new_alias;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_get_final_command: get final command pointed by an alias
|
||||
*/
|
||||
|
||||
char *
|
||||
alias_get_final_command (struct alias *alias)
|
||||
{
|
||||
struct alias *ptr_alias;
|
||||
char *result;
|
||||
|
||||
if (alias->running)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: circular reference when calling alias "
|
||||
"\"/%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
alias->name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr_alias = alias_search ((alias->command[0] == '/') ?
|
||||
alias->command + 1 : alias->command);
|
||||
if (ptr_alias)
|
||||
{
|
||||
alias->running = 1;
|
||||
result = alias_get_final_command (ptr_alias);
|
||||
alias->running = 0;
|
||||
return result;
|
||||
}
|
||||
return (alias->command[0] == '/') ?
|
||||
alias->command + 1 : alias->command;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_add_word: add word to string and increment length
|
||||
* This function should NOT be called directly.
|
||||
*/
|
||||
|
||||
void
|
||||
alias_add_word (char **alias, int *length, char *word)
|
||||
{
|
||||
int length_word;
|
||||
|
||||
if (!word)
|
||||
return;
|
||||
|
||||
length_word = strlen (word);
|
||||
if (length_word == 0)
|
||||
return;
|
||||
|
||||
if (*alias == NULL)
|
||||
{
|
||||
*alias = (char *) malloc (length_word + 1);
|
||||
strcpy (*alias, word);
|
||||
}
|
||||
else
|
||||
{
|
||||
*alias = realloc (*alias, strlen (*alias) + length_word + 1);
|
||||
strcat (*alias, word);
|
||||
}
|
||||
*length += length_word;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_replace_args: replace arguments ($1, $2, .. or $*) in alias arguments
|
||||
*/
|
||||
|
||||
char *
|
||||
alias_replace_args (char *alias_args, char *user_args)
|
||||
{
|
||||
char **argv, *start, *pos, *res;
|
||||
int argc, length_res, args_count;
|
||||
|
||||
argv = string_explode (user_args, " ", 0, 0, &argc);
|
||||
|
||||
res = NULL;
|
||||
length_res = 0;
|
||||
args_count = 0;
|
||||
start = alias_args;
|
||||
pos = start;
|
||||
while (pos && pos[0])
|
||||
{
|
||||
if ((pos[0] == '\\') && (pos[1] == '$'))
|
||||
{
|
||||
pos[0] = '\0';
|
||||
alias_add_word (&res, &length_res, start);
|
||||
alias_add_word (&res, &length_res, "$");
|
||||
pos[0] = '\\';
|
||||
start = pos + 2;
|
||||
pos = start;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pos[0] == '$')
|
||||
{
|
||||
if (pos[1] == '*')
|
||||
{
|
||||
args_count++;
|
||||
pos[0] = '\0';
|
||||
alias_add_word (&res, &length_res, start);
|
||||
alias_add_word (&res, &length_res, user_args);
|
||||
pos[0] = '$';
|
||||
start = pos + 2;
|
||||
pos = start;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pos[1] >= '1') && (pos[1] <= '9'))
|
||||
{
|
||||
args_count++;
|
||||
pos[0] = '\0';
|
||||
alias_add_word (&res, &length_res, start);
|
||||
if (pos[1] - '0' <= argc)
|
||||
alias_add_word (&res, &length_res, argv[pos[1] - '1']);
|
||||
pos[0] = '$';
|
||||
start = pos + 2;
|
||||
pos = start;
|
||||
}
|
||||
else
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
else
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
if (start < pos)
|
||||
alias_add_word (&res, &length_res, start);
|
||||
|
||||
if ((args_count == 0) && user_args && user_args[0])
|
||||
{
|
||||
alias_add_word (&res, &length_res, " ");
|
||||
alias_add_word (&res, &length_res, user_args);
|
||||
}
|
||||
|
||||
if (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 (struct t_gui_buffer *buffer, char *string)
|
||||
{
|
||||
/* 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;
|
||||
|
||||
var_nick = (server && server->nick) ? server->nick : empty_string;
|
||||
var_channel = (channel) ? channel->name : empty_string;
|
||||
var_server = (server) ? server->name : empty_string;
|
||||
|
||||
temp = weechat_strreplace (string, "$nick", var_nick);
|
||||
if (!temp)
|
||||
return NULL;
|
||||
res = temp;
|
||||
|
||||
temp = weechat_strreplace (res, "$channel", var_channel);
|
||||
free (res);
|
||||
if (!temp)
|
||||
return NULL;
|
||||
res = temp;
|
||||
|
||||
temp = weechat_strreplace (res, "$server", var_server);
|
||||
free (res);
|
||||
if (!temp)
|
||||
return NULL;
|
||||
res = temp;
|
||||
|
||||
return res;*/
|
||||
|
||||
return strdup (string);
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_free: free an alias and reomve it from list
|
||||
*/
|
||||
|
||||
void
|
||||
alias_free (struct alias *alias)
|
||||
{
|
||||
struct alias *new_weechat_alias;
|
||||
|
||||
/* remove alias from list */
|
||||
if (weechat_last_alias == alias)
|
||||
weechat_last_alias = alias->prev_alias;
|
||||
if (alias->prev_alias)
|
||||
{
|
||||
(alias->prev_alias)->next_alias = alias->next_alias;
|
||||
new_weechat_alias = weechat_alias;
|
||||
}
|
||||
else
|
||||
new_weechat_alias = alias->next_alias;
|
||||
|
||||
if (alias->next_alias)
|
||||
(alias->next_alias)->prev_alias = alias->prev_alias;
|
||||
|
||||
/* free data */
|
||||
if (alias->name)
|
||||
free (alias->name);
|
||||
if (alias->command)
|
||||
free (alias->command);
|
||||
free (alias);
|
||||
weechat_alias = new_weechat_alias;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_free_all: free all alias
|
||||
*/
|
||||
|
||||
void
|
||||
alias_free_all ()
|
||||
{
|
||||
while (weechat_alias)
|
||||
alias_free (weechat_alias);
|
||||
}
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include "weechat.h"
|
||||
#include "wee-command.h"
|
||||
#include "wee-alias.h"
|
||||
#include "wee-config.h"
|
||||
#include "wee-hook.h"
|
||||
#include "wee-input.h"
|
||||
@ -53,19 +52,7 @@
|
||||
/* WeeChat internal commands */
|
||||
|
||||
struct command weechat_commands[] =
|
||||
{ { "alias",
|
||||
N_("create an alias for a command"),
|
||||
N_("[alias_name [command [arguments]]]"),
|
||||
N_("alias_name: name of alias\n"
|
||||
" command: command name (WeeChat or IRC command, many commands "
|
||||
"can be separated by semicolons)\n"
|
||||
" arguments: arguments for command\n\n"
|
||||
"Note: in command, special variables $1, $2,..,$9 are replaced by "
|
||||
"arguments given by user, and $* is replaced by all arguments.\n"
|
||||
"Variables $nick, $channel and $server are replaced by current "
|
||||
"nick/channel/server."),
|
||||
"%- %A", 0, MAX_ARGS, 1, command_alias },
|
||||
{ "buffer",
|
||||
{ { "buffer",
|
||||
N_("manage buffers"),
|
||||
N_("[action [args] | number | [[server] [channel]]]"),
|
||||
N_(" action: action to do:\n"
|
||||
@ -178,10 +165,6 @@ struct command weechat_commands[] =
|
||||
" value: value for option\n\n"
|
||||
"Option is format: plugin.option, example: perl.myscript.item1"),
|
||||
"%O = %V", 0, MAX_ARGS, 0, command_setp },
|
||||
{ "unalias",
|
||||
N_("remove an alias"),
|
||||
N_("alias_name"), N_("alias_name: name of alias to remove"),
|
||||
"%a", 1, 1, 0, command_unalias },
|
||||
{ "upgrade",
|
||||
N_("upgrade WeeChat without disconnecting from servers"),
|
||||
N_("[path_to_binary]"),
|
||||
@ -226,23 +209,14 @@ struct t_weelist *weechat_last_index_command;
|
||||
|
||||
/*
|
||||
* command_is_used: return 1 if command is used by weechat
|
||||
* (WeeChat/alias command)
|
||||
* (WeeChat command)
|
||||
*/
|
||||
|
||||
int
|
||||
command_is_used (char *command)
|
||||
{
|
||||
struct alias *ptr_alias;
|
||||
int i;
|
||||
|
||||
/* look for alias */
|
||||
for (ptr_alias = weechat_alias; ptr_alias;
|
||||
ptr_alias = ptr_alias->next_alias)
|
||||
{
|
||||
if (string_strcasecmp (ptr_alias->name, command) == 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* look for WeeChat command */
|
||||
for (i = 0; weechat_commands[i].name; i++)
|
||||
{
|
||||
@ -250,7 +224,7 @@ command_is_used (char *command)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* no command/alias found */
|
||||
/* no command found */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -360,95 +334,6 @@ command_print_stdout (struct command *commands)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* command_alias: display or create alias
|
||||
*/
|
||||
|
||||
int
|
||||
command_alias (struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
char *alias_name;
|
||||
struct alias *ptr_alias;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) buffer;
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
alias_name = (argv[0][0] == '/') ? argv[0] + 1 : argv[0];
|
||||
if (argc > 1)
|
||||
{
|
||||
/* Define new alias */
|
||||
if (!alias_new (alias_name, argv_eol[1]))
|
||||
return -1;
|
||||
|
||||
if (weelist_add (&weechat_index_commands,
|
||||
&weechat_last_index_command,
|
||||
alias_name,
|
||||
WEELIST_POS_SORT))
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sAlias \"%s\" => \"%s\" created"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
|
||||
alias_name, argv_eol[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: not enough memory for creating "
|
||||
"alias \"%s\" => \"%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
alias_name, argv_eol[1]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Display one alias */
|
||||
ptr_alias = alias_search (alias_name);
|
||||
if (ptr_alias)
|
||||
{
|
||||
gui_chat_printf (NULL, "");
|
||||
gui_chat_printf (NULL, _("Alias:"));
|
||||
gui_chat_printf (NULL, " %s %s=>%s %s",
|
||||
ptr_alias->name,
|
||||
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
|
||||
GUI_COLOR(GUI_COLOR_CHAT),
|
||||
ptr_alias->command);
|
||||
}
|
||||
else
|
||||
gui_chat_printf (NULL,
|
||||
_("%sNo alias found."),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* List all aliases */
|
||||
if (weechat_alias)
|
||||
{
|
||||
gui_chat_printf (NULL, "");
|
||||
gui_chat_printf (NULL, _("List of aliases:"));
|
||||
for (ptr_alias = weechat_alias; ptr_alias;
|
||||
ptr_alias = ptr_alias->next_alias)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
" %s %s=>%s %s",
|
||||
ptr_alias->name,
|
||||
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
|
||||
GUI_COLOR(GUI_COLOR_CHAT),
|
||||
ptr_alias->command);
|
||||
}
|
||||
}
|
||||
else
|
||||
gui_chat_printf (NULL,
|
||||
_("%sNo alias defined."),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* command_buffer: manage buffers
|
||||
*/
|
||||
@ -1923,48 +1808,6 @@ command_setp (struct t_gui_buffer *buffer,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* command_unalias: remove an alias
|
||||
*/
|
||||
|
||||
int
|
||||
command_unalias (struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
char *alias_name;
|
||||
struct t_weelist *ptr_weelist;
|
||||
struct alias *ptr_alias;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) buffer;
|
||||
(void) argv_eol;
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
alias_name = (argv[0][0] == '/') ? argv[0] + 1 : argv[0];
|
||||
ptr_alias = alias_search (alias_name);
|
||||
if (!ptr_alias)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sAlias \"%s\" not found"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
alias_name);
|
||||
return -1;
|
||||
}
|
||||
alias_free (ptr_alias);
|
||||
ptr_weelist = weelist_search (weechat_index_commands, alias_name);
|
||||
if (ptr_weelist)
|
||||
weelist_remove (&weechat_index_commands,
|
||||
&weechat_last_index_command,
|
||||
ptr_weelist);
|
||||
gui_chat_printf (NULL,
|
||||
_("%sAlias \"%s\" removed"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
|
||||
alias_name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* command_upgrade: upgrade WeeChat
|
||||
*/
|
||||
|
@ -40,6 +40,26 @@ struct t_config_file *config_files = NULL;
|
||||
struct t_config_file *last_config_file = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* config_file_search: search a configuration file
|
||||
*/
|
||||
|
||||
struct t_config_file *
|
||||
config_file_search (char *filename)
|
||||
{
|
||||
struct t_config_file *ptr_config;
|
||||
|
||||
for (ptr_config = config_files; ptr_config;
|
||||
ptr_config = ptr_config->next_config)
|
||||
{
|
||||
if (strcmp (ptr_config->filename, filename) == 0)
|
||||
return ptr_config;
|
||||
}
|
||||
|
||||
/* configuration file not found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_file_new: create new config options structure
|
||||
*/
|
||||
@ -52,6 +72,10 @@ config_file_new (void *plugin, char *filename)
|
||||
if (!filename)
|
||||
return NULL;
|
||||
|
||||
/* it's NOT authorized to create two config files with same filename */
|
||||
if (config_file_search (filename))
|
||||
return NULL;
|
||||
|
||||
new_config_file = (struct t_config_file *)malloc (sizeof (struct t_config_file));
|
||||
if (new_config_file)
|
||||
{
|
||||
@ -73,6 +97,29 @@ config_file_new (void *plugin, char *filename)
|
||||
return new_config_file;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_file_valid_for_plugin: check if a configuration file pointer exists for a plugin
|
||||
* return 1 if configuration file exists for plugin
|
||||
* 0 if configuration file is not found for plugin
|
||||
*/
|
||||
|
||||
int
|
||||
config_file_valid_for_plugin (void *plugin, struct t_config_file *config_file)
|
||||
{
|
||||
struct t_config_file *ptr_config;
|
||||
|
||||
for (ptr_config = config_files; ptr_config;
|
||||
ptr_config = ptr_config->next_config)
|
||||
{
|
||||
if ((ptr_config == config_file)
|
||||
&& (ptr_config->plugin == (struct t_weechat_plugin *)plugin))
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* configuration file not found */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_file_new_section: create a new section in a config
|
||||
*/
|
||||
@ -1014,6 +1061,127 @@ config_file_write (struct t_config_file *config_file, int default_options)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_file_option_free: free an option
|
||||
*/
|
||||
|
||||
void
|
||||
config_file_option_free (struct t_config_section *section,
|
||||
struct t_config_option *option)
|
||||
{
|
||||
struct t_config_option *new_options;
|
||||
|
||||
/* remove option */
|
||||
if (section->last_option == option)
|
||||
section->last_option = option->prev_option;
|
||||
if (option->prev_option)
|
||||
{
|
||||
(option->prev_option)->next_option = option->next_option;
|
||||
new_options = section->options;
|
||||
}
|
||||
else
|
||||
new_options = option->next_option;
|
||||
|
||||
if (option->next_option)
|
||||
(option->next_option)->prev_option = option->prev_option;
|
||||
|
||||
/* free data */
|
||||
if (option->name)
|
||||
free (option->name);
|
||||
if (option->description)
|
||||
free (option->description);
|
||||
if (option->string_values)
|
||||
string_free_exploded (option->string_values);
|
||||
if (option->default_value)
|
||||
free (option->default_value);
|
||||
if (option->value)
|
||||
free (option->value);
|
||||
|
||||
section->options = new_options;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_file_section_free: free a section
|
||||
*/
|
||||
|
||||
void
|
||||
config_file_section_free (struct t_config_file *config_file,
|
||||
struct t_config_section *section)
|
||||
{
|
||||
struct t_config_section *new_sections;
|
||||
|
||||
/* remove section */
|
||||
if (config_file->last_section == section)
|
||||
config_file->last_section = section->prev_section;
|
||||
if (section->prev_section)
|
||||
{
|
||||
(section->prev_section)->next_section = section->next_section;
|
||||
new_sections = config_file->sections;
|
||||
}
|
||||
else
|
||||
new_sections = section->next_section;
|
||||
|
||||
if (section->next_section)
|
||||
(section->next_section)->prev_section = section->prev_section;
|
||||
|
||||
/* free data */
|
||||
while (section->options)
|
||||
{
|
||||
config_file_option_free (section, section->options);
|
||||
}
|
||||
if (section->name)
|
||||
free (section->name);
|
||||
|
||||
config_file->sections = new_sections;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_file_free: free a configuration file
|
||||
*/
|
||||
|
||||
void
|
||||
config_file_free (struct t_config_file *config_file)
|
||||
{
|
||||
struct t_config_file *new_config_files;
|
||||
|
||||
/* remove config file */
|
||||
if (last_config_file == config_file)
|
||||
last_config_file = config_file->prev_config;
|
||||
if (config_file->prev_config)
|
||||
{
|
||||
(config_file->prev_config)->next_config = config_file->next_config;
|
||||
new_config_files = config_files;
|
||||
}
|
||||
else
|
||||
new_config_files = config_file->next_config;
|
||||
|
||||
if (config_file->next_config)
|
||||
(config_file->next_config)->prev_config = config_file->prev_config;
|
||||
|
||||
/* free data */
|
||||
while (config_file->sections)
|
||||
{
|
||||
config_file_section_free (config_file, config_file->sections);
|
||||
}
|
||||
if (config_file->filename)
|
||||
free (config_file->filename);
|
||||
|
||||
config_files = new_config_files;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_file_free_all: free all configuration files
|
||||
*/
|
||||
|
||||
void
|
||||
config_file_free_all ()
|
||||
{
|
||||
while (config_files)
|
||||
{
|
||||
config_file_free (config_files);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* config_file_print_stdout: print options on standard output
|
||||
*/
|
||||
|
@ -85,6 +85,7 @@ struct t_config_option
|
||||
};
|
||||
|
||||
extern struct t_config_file *config_file_new (void *, char *);
|
||||
extern int config_file_valid_for_plugin (void *, struct t_config_file *);
|
||||
extern struct t_config_section *config_file_new_section (struct t_config_file *,
|
||||
char *,
|
||||
void (*)(void *, char *, char *),
|
||||
@ -126,6 +127,12 @@ extern int config_file_read (struct t_config_file *);
|
||||
extern int config_file_reload (struct t_config_file *);
|
||||
extern void config_file_write_line (struct t_config_file *, char *, char *);
|
||||
extern int config_file_write (struct t_config_file *, int);
|
||||
extern void config_file_option_free (struct t_config_section *,
|
||||
struct t_config_option *);
|
||||
extern void config_file_section_free (struct t_config_file *,
|
||||
struct t_config_section *);
|
||||
extern void config_file_free (struct t_config_file *);
|
||||
extern void config_file_free_all ();
|
||||
extern void config_file_print_stdout (struct t_config_file *);
|
||||
extern void config_file_print_log ();
|
||||
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "weechat.h"
|
||||
#include "wee-config.h"
|
||||
#include "wee-config-file.h"
|
||||
#include "wee-alias.h"
|
||||
#include "wee-command.h"
|
||||
#include "wee-log.h"
|
||||
#include "wee-util.h"
|
||||
@ -319,25 +318,6 @@ config_change_nicks_colors ()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* config_weechat_read_alias: read an alias in configuration file
|
||||
*/
|
||||
|
||||
void
|
||||
config_weechat_read_alias (void *config_file,
|
||||
char *option_name, char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) config_file;
|
||||
|
||||
/* create new alias */
|
||||
if (alias_new (option_name, value))
|
||||
weelist_add (&weechat_index_commands,
|
||||
&weechat_last_index_command,
|
||||
option_name,
|
||||
WEELIST_POS_SORT);
|
||||
}
|
||||
|
||||
/*
|
||||
* config_weechat_read_key: read a key in configuration file
|
||||
*/
|
||||
@ -361,69 +341,6 @@ config_weechat_read_key (void *config_file,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* config_weechat_write_alias: write alias section in configuration file
|
||||
* Return: 0 = successful
|
||||
* -1 = write error
|
||||
*/
|
||||
|
||||
void
|
||||
config_weechat_write_alias (void *config_file)
|
||||
{
|
||||
struct alias *ptr_alias;
|
||||
char *string;
|
||||
|
||||
for (ptr_alias = weechat_alias; ptr_alias;
|
||||
ptr_alias = ptr_alias->next_alias)
|
||||
{
|
||||
string = (char *)malloc (strlen (ptr_alias->command) + 4);
|
||||
if (string)
|
||||
{
|
||||
strcpy (string, "\"");
|
||||
strcat (string, ptr_alias->command);
|
||||
strcat (string, "\"");
|
||||
config_file_write_line (config_file,
|
||||
ptr_alias->name,
|
||||
string);
|
||||
free (string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* config_weechat_write_alias_default_values: write alias section with default values
|
||||
* in configuration file
|
||||
*/
|
||||
|
||||
void
|
||||
config_weechat_write_alias_default_values (void *config_file)
|
||||
{
|
||||
config_file_write_line (config_file, "SAY", "\"msg *\"");
|
||||
config_file_write_line (config_file, "BYE", "\"quit\"");
|
||||
config_file_write_line (config_file, "EXIT", "\"quit\"");
|
||||
config_file_write_line (config_file, "SIGNOFF", "\"quit\"");
|
||||
config_file_write_line (config_file, "C", "\"clear\"");
|
||||
config_file_write_line (config_file, "CL", "\"clear\"");
|
||||
config_file_write_line (config_file, "CLOSE", "\"buffer close\"");
|
||||
config_file_write_line (config_file, "CHAT", "\"dcc chat\"");
|
||||
config_file_write_line (config_file, "IG", "\"ignore\"");
|
||||
config_file_write_line (config_file, "J", "\"join\"");
|
||||
config_file_write_line (config_file, "K", "\"kick\"");
|
||||
config_file_write_line (config_file, "KB", "\"kickban\"");
|
||||
config_file_write_line (config_file, "LEAVE", "\"part\"");
|
||||
config_file_write_line (config_file, "M", "\"msg\"");
|
||||
config_file_write_line (config_file, "MUB", "\"unban *\"");
|
||||
config_file_write_line (config_file, "N", "\"names\"");
|
||||
config_file_write_line (config_file, "Q", "\"query\"");
|
||||
config_file_write_line (config_file, "T", "\"topic\"");
|
||||
config_file_write_line (config_file, "UB", "\"unban\"");
|
||||
config_file_write_line (config_file, "UNIG", "\"unignore\"");
|
||||
config_file_write_line (config_file, "W", "\"who\"");
|
||||
config_file_write_line (config_file, "WC", "\"window merge\"");
|
||||
config_file_write_line (config_file, "WI", "\"whois\"");
|
||||
config_file_write_line (config_file, "WW", "\"whowas\"");
|
||||
}
|
||||
|
||||
/*
|
||||
* config_weechat_write_keys: write alias section in configuration file
|
||||
* Return: 0 = successful
|
||||
@ -1099,13 +1016,7 @@ config_weechat_init ()
|
||||
#endif
|
||||
NULL);
|
||||
}
|
||||
|
||||
/* alias */
|
||||
section = config_file_new_section (weechat_config, "alias",
|
||||
&config_weechat_read_alias,
|
||||
&config_weechat_write_alias,
|
||||
&config_weechat_write_alias_default_values);
|
||||
|
||||
|
||||
/* keys */
|
||||
section = config_file_new_section (weechat_config, "keys",
|
||||
&config_weechat_read_key,
|
||||
@ -1137,9 +1048,6 @@ config_weechat_read ()
|
||||
int
|
||||
config_weechat_reload ()
|
||||
{
|
||||
/* remove all alias */
|
||||
alias_free_all ();
|
||||
|
||||
/* remove all keys */
|
||||
gui_keyboard_free_all ();
|
||||
|
||||
|
@ -119,6 +119,27 @@ hook_valid_for_plugin (void *plugin, struct t_hook *hook)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_search_command: search command hook in list
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
hook_search_command (char *command)
|
||||
{
|
||||
struct t_hook *ptr_hook;
|
||||
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if ((ptr_hook->type == HOOK_TYPE_COMMAND)
|
||||
&& (string_strcasecmp (HOOK_COMMAND(ptr_hook, command), command) == 0))
|
||||
return ptr_hook;
|
||||
}
|
||||
|
||||
/* command hook not found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_command: hook a command
|
||||
*/
|
||||
@ -131,6 +152,10 @@ hook_command (void *plugin, char *command, char *description,
|
||||
{
|
||||
struct t_hook *new_hook;
|
||||
struct t_hook_command *new_hook_command;
|
||||
|
||||
if ((string_strcasecmp (command, "builtin") == 0)
|
||||
&& hook_search_command (command))
|
||||
return NULL;
|
||||
|
||||
new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
|
||||
if (!new_hook)
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
#include "weechat.h"
|
||||
#include "wee-input.h"
|
||||
#include "wee-alias.h"
|
||||
#include "wee-command.h"
|
||||
#include "wee-config.h"
|
||||
#include "wee-hook.h"
|
||||
@ -50,13 +49,9 @@ int
|
||||
input_exec_command (struct t_gui_buffer *buffer, char *string,
|
||||
int only_builtin)
|
||||
{
|
||||
int i, rc, argc, return_code, length1, length2;
|
||||
int i, rc, argc, return_code;
|
||||
char *command, *pos, *ptr_args;
|
||||
char **argv, **argv_eol, *alias_command;
|
||||
char **commands, **ptr_cmd, **ptr_next_cmd;
|
||||
char *args_replaced, *vars_replaced, *new_ptr_cmd;
|
||||
int some_args_replaced;
|
||||
struct alias *ptr_alias;
|
||||
char **argv, **argv_eol;
|
||||
|
||||
if ((!string) || (!string[0]) || (string[0] != '/'))
|
||||
return 0;
|
||||
@ -111,126 +106,6 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
|
||||
argv = string_explode (ptr_args, " ", 0, 0, &argc);
|
||||
argv_eol = string_explode (ptr_args, " ", 1, 0, NULL);
|
||||
|
||||
/* look for alias */
|
||||
if (!only_builtin)
|
||||
{
|
||||
for (ptr_alias = weechat_alias; ptr_alias;
|
||||
ptr_alias = ptr_alias->next_alias)
|
||||
{
|
||||
if (string_strcasecmp (ptr_alias->name, command + 1) == 0)
|
||||
{
|
||||
if (ptr_alias->running == 1)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: circular reference when "
|
||||
"calling alias \"/%s\""),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
ptr_alias->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* an alias can contain many commands separated by ';' */
|
||||
commands = string_split_multi_command (ptr_alias->command,
|
||||
';');
|
||||
if (commands)
|
||||
{
|
||||
some_args_replaced = 0;
|
||||
ptr_alias->running = 1;
|
||||
for (ptr_cmd=commands; *ptr_cmd; ptr_cmd++)
|
||||
{
|
||||
ptr_next_cmd = ptr_cmd;
|
||||
ptr_next_cmd++;
|
||||
|
||||
vars_replaced = alias_replace_vars (buffer,
|
||||
*ptr_cmd);
|
||||
new_ptr_cmd = (vars_replaced) ? vars_replaced : *ptr_cmd;
|
||||
args_replaced = alias_replace_args (new_ptr_cmd,
|
||||
ptr_args);
|
||||
if (args_replaced)
|
||||
{
|
||||
some_args_replaced = 1;
|
||||
if (*ptr_cmd[0] == '/')
|
||||
(void) input_exec_command (buffer,
|
||||
args_replaced,
|
||||
only_builtin);
|
||||
else
|
||||
{
|
||||
alias_command = (char *) malloc (1 + strlen(args_replaced) + 1);
|
||||
if (alias_command)
|
||||
{
|
||||
strcpy (alias_command, "/");
|
||||
strcat (alias_command, args_replaced);
|
||||
(void) input_exec_command (buffer,
|
||||
alias_command,
|
||||
only_builtin);
|
||||
free (alias_command);
|
||||
}
|
||||
}
|
||||
free (args_replaced);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if alias has arguments, they are now
|
||||
arguments of the last command in the list (if no $1,$2,..$*) was found */
|
||||
if ((*ptr_next_cmd == NULL) && ptr_args && (!some_args_replaced))
|
||||
{
|
||||
length1 = strlen (new_ptr_cmd);
|
||||
length2 = strlen (ptr_args);
|
||||
|
||||
alias_command = (char *) malloc ( 1 + length1 + 1 + length2 + 1);
|
||||
if (alias_command)
|
||||
{
|
||||
if (*ptr_cmd[0] != '/')
|
||||
strcpy (alias_command, "/");
|
||||
else
|
||||
strcpy (alias_command, "");
|
||||
|
||||
strcat (alias_command, new_ptr_cmd);
|
||||
strcat (alias_command, " ");
|
||||
strcat (alias_command, ptr_args);
|
||||
|
||||
(void) input_exec_command (buffer,
|
||||
alias_command,
|
||||
only_builtin);
|
||||
free (alias_command);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*ptr_cmd[0] == '/')
|
||||
(void) input_exec_command (buffer,
|
||||
new_ptr_cmd,
|
||||
only_builtin);
|
||||
else
|
||||
{
|
||||
alias_command = (char *) malloc (1 + strlen (new_ptr_cmd) + 1);
|
||||
if (alias_command)
|
||||
{
|
||||
strcpy (alias_command, "/");
|
||||
strcat (alias_command, new_ptr_cmd);
|
||||
(void) input_exec_command (buffer,
|
||||
alias_command,
|
||||
only_builtin);
|
||||
free (alias_command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (vars_replaced)
|
||||
free (vars_replaced);
|
||||
}
|
||||
ptr_alias->running = 0;
|
||||
string_free_multi_command (commands);
|
||||
}
|
||||
}
|
||||
string_free_exploded (argv);
|
||||
string_free_exploded (argv_eol);
|
||||
free (command);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* look for WeeChat command */
|
||||
for (i = 0; weechat_commands[i].name; i++)
|
||||
{
|
||||
|
@ -460,15 +460,15 @@ string_free_exploded (char **exploded_string)
|
||||
}
|
||||
|
||||
/*
|
||||
* string_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
|
||||
* string_split_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
|
||||
*/
|
||||
|
||||
char **
|
||||
string_split_multi_command (char *command, char sep)
|
||||
string_split_command (char *command, char sep)
|
||||
{
|
||||
int nb_substr, arr_idx, str_idx, type;
|
||||
char **array;
|
||||
@ -545,12 +545,12 @@ string_split_multi_command (char *command, char sep)
|
||||
}
|
||||
|
||||
/*
|
||||
* string_free_multi_command : free a list of commands splitted
|
||||
* with split_multi_command
|
||||
* string_free_splitted_command : free a list of commands splitted
|
||||
* with string_split_command
|
||||
*/
|
||||
|
||||
void
|
||||
string_free_multi_command (char **commands)
|
||||
string_free_splitted_command (char **commands)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -33,8 +33,8 @@ extern char *string_remove_quotes (char *, char *);
|
||||
extern char *string_convert_hex_chars (char *);
|
||||
extern char **string_explode (char *, char *, int, int, int *);
|
||||
extern void string_free_exploded (char **);
|
||||
extern char **string_split_multi_command (char *, char);
|
||||
extern void string_free_multi_command (char **);
|
||||
extern char **string_split_command (char *, char);
|
||||
extern void string_free_splitted_command (char **);
|
||||
extern char *string_iconv (int, char *, char *, char *);
|
||||
extern char *string_iconv_to_internal (char *, char *);
|
||||
extern char *string_iconv_from_internal (char *, char *);
|
||||
|
@ -51,7 +51,6 @@
|
||||
#endif
|
||||
|
||||
#include "weechat.h"
|
||||
#include "wee-alias.h"
|
||||
#include "wee-backtrace.h"
|
||||
#include "wee-command.h"
|
||||
#include "wee-config.h"
|
||||
@ -487,7 +486,6 @@ weechat_shutdown (int return_code, int crash)
|
||||
log_close ();
|
||||
if (local_charset)
|
||||
free (local_charset);
|
||||
alias_free_all ();
|
||||
|
||||
if (crash)
|
||||
abort();
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../core/weechat.h"
|
||||
#include "../core/wee-alias.h"
|
||||
#include "../core/wee-command.h"
|
||||
#include "../core/wee-config.h"
|
||||
#include "../core/wee-hook.h"
|
||||
@ -136,43 +135,22 @@ void
|
||||
gui_completion_get_command_infos (struct t_gui_completion *completion,
|
||||
char **template, int *max_arg)
|
||||
{
|
||||
struct alias *ptr_alias;
|
||||
struct t_hook *ptr_hook;
|
||||
char *ptr_command, *ptr_command2, *pos;
|
||||
int i;
|
||||
|
||||
*template = NULL;
|
||||
*max_arg = MAX_ARGS;
|
||||
|
||||
ptr_alias = alias_search (completion->base_command);
|
||||
if (ptr_alias)
|
||||
{
|
||||
ptr_command = alias_get_final_command (ptr_alias);
|
||||
if (!ptr_command)
|
||||
return;
|
||||
}
|
||||
else
|
||||
ptr_command = completion->base_command;
|
||||
|
||||
ptr_command2 = strdup (ptr_command);
|
||||
if (!ptr_command2)
|
||||
return;
|
||||
|
||||
pos = strchr (ptr_command2, ' ');
|
||||
if (pos)
|
||||
pos[0] = '\0';
|
||||
|
||||
/* look for command hooked */
|
||||
for (ptr_hook = weechat_hooks; ptr_hook;
|
||||
ptr_hook = ptr_hook->next_hook)
|
||||
{
|
||||
if ((ptr_hook->type == HOOK_TYPE_COMMAND)
|
||||
&& (string_strcasecmp (HOOK_COMMAND(ptr_hook, command),
|
||||
ptr_command2) == 0))
|
||||
completion->base_command) == 0))
|
||||
{
|
||||
*template = HOOK_COMMAND(ptr_hook, completion);
|
||||
*max_arg = MAX_ARGS;
|
||||
free (ptr_command2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -181,17 +159,13 @@ gui_completion_get_command_infos (struct t_gui_completion *completion,
|
||||
for (i = 0; weechat_commands[i].name; i++)
|
||||
{
|
||||
if (string_strcasecmp (weechat_commands[i].name,
|
||||
ptr_command2) == 0)
|
||||
completion->base_command) == 0)
|
||||
{
|
||||
*template = weechat_commands[i].completion_template;
|
||||
*max_arg = weechat_commands[i].max_arg;
|
||||
free (ptr_command2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
free (ptr_command2);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -289,39 +263,6 @@ gui_completion_list_add (struct t_gui_completion *completion, char *word,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_completion_list_add_alias: add alias to completion list
|
||||
*/
|
||||
|
||||
void
|
||||
gui_completion_list_add_alias (struct t_gui_completion *completion)
|
||||
{
|
||||
struct alias *ptr_alias;
|
||||
|
||||
for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias)
|
||||
{
|
||||
gui_completion_list_add (completion, ptr_alias->name,
|
||||
0, WEELIST_POS_SORT);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_completion_list_add_alias_cmd: add alias and comands to completion list
|
||||
*/
|
||||
|
||||
void
|
||||
gui_completion_list_add_alias_cmd (struct t_gui_completion *completion)
|
||||
{
|
||||
struct t_weelist *ptr_list;
|
||||
|
||||
for (ptr_list = weechat_index_commands; ptr_list;
|
||||
ptr_list = ptr_list->next_weelist)
|
||||
{
|
||||
gui_completion_list_add (completion, ptr_list->data, 0,
|
||||
WEELIST_POS_SORT);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_completion_list_add_channel: add current channel to completion list
|
||||
*/
|
||||
@ -969,12 +910,6 @@ gui_completion_build_list_template (struct t_gui_completion *completion, char *t
|
||||
break;
|
||||
case '*': /* repeat last completion (do nothing there) */
|
||||
break;
|
||||
case 'a': /* alias */
|
||||
gui_completion_list_add_alias (completion);
|
||||
break;
|
||||
case 'A': /* alias or any command */
|
||||
gui_completion_list_add_alias_cmd (completion);
|
||||
break;
|
||||
case 'c': /* current channel */
|
||||
gui_completion_list_add_channel (completion);
|
||||
break;
|
||||
@ -984,7 +919,7 @@ gui_completion_build_list_template (struct t_gui_completion *completion, char *t
|
||||
case 'f': /* filename */
|
||||
gui_completion_list_add_filename (completion);
|
||||
break;
|
||||
case 'h': /* commands hooks */
|
||||
case 'h': /* command hooks */
|
||||
gui_completion_list_add_command_hooks (completion);
|
||||
break;
|
||||
case 'k': /* key cmd/funtcions*/
|
||||
|
@ -628,7 +628,7 @@ gui_keyboard_pressed (char *key_str)
|
||||
gui_key_combo_buffer[0] = '\0';
|
||||
if (ptr_key->command)
|
||||
{
|
||||
commands = string_split_multi_command (ptr_key->command, ';');
|
||||
commands = string_split_command (ptr_key->command, ';');
|
||||
if (commands)
|
||||
{
|
||||
for (ptr_cmd = commands; *ptr_cmd; ptr_cmd++)
|
||||
@ -636,7 +636,7 @@ gui_keyboard_pressed (char *key_str)
|
||||
input_data (gui_current_window->buffer,
|
||||
*ptr_cmd, 0);
|
||||
}
|
||||
string_free_multi_command (commands);
|
||||
string_free_splitted_command (commands);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -28,6 +28,10 @@ IF(NOT DISABLE_IRC)
|
||||
ADD_SUBDIRECTORY( irc )
|
||||
ENDIF(NOT DISABLE_IRC)
|
||||
|
||||
IF(NOT DISABLE_ALIAS)
|
||||
ADD_SUBDIRECTORY( alias )
|
||||
ENDIF(NOT DISABLE_ALIAS)
|
||||
|
||||
IF(NOT DISABLE_ASPELL)
|
||||
# Check for aspell libraries
|
||||
FIND_PACKAGE(Aspell)
|
||||
|
@ -32,6 +32,10 @@ if PLUGIN_IRC
|
||||
irc_dir = irc
|
||||
endif
|
||||
|
||||
if PLUGIN_ALIAS
|
||||
alias_dir = alias
|
||||
endif
|
||||
|
||||
if PLUGIN_ASPELL
|
||||
aspell_dir = aspell
|
||||
endif
|
||||
@ -72,4 +76,5 @@ if PLUGIN_DEMO
|
||||
demo_dir = demo
|
||||
endif
|
||||
|
||||
SUBDIRS = . $(irc_dir) $(aspell_dir) $(charset_dir) $(fifo_dir) $(logger_dir) $(trigger_dir) $(demo_dir) $(script_dir)
|
||||
SUBDIRS = . $(irc_dir) $(alias_dir) $(aspell_dir) $(charset_dir) $(fifo_dir) \
|
||||
$(logger_dir) $(trigger_dir) $(demo_dir) $(script_dir)
|
||||
|
22
src/plugins/alias/CMakeLists.txt
Normal file
22
src/plugins/alias/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
||||
# Copyright (c) 2003-2007 FlashCode <flashcode@flashtux.org>
|
||||
#
|
||||
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
ADD_LIBRARY(alias MODULE alias.c alias.h)
|
||||
SET_TARGET_PROPERTIES(alias PROPERTIES PREFIX "")
|
||||
|
||||
TARGET_LINK_LIBRARIES(alias)
|
||||
|
||||
INSTALL(TARGETS alias LIBRARY DESTINATION lib/${PROJECT_NAME}/plugins)
|
25
src/plugins/alias/Makefile.am
Normal file
25
src/plugins/alias/Makefile.am
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright (c) 2003-2007 FlashCode <flashcode@flashtux.org>
|
||||
#
|
||||
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(ALIAS_CFLAGS)
|
||||
|
||||
libdir = ${weechat_libdir}/plugins
|
||||
|
||||
lib_LTLIBRARIES = alias.la
|
||||
|
||||
alias_la_SOURCES = alias.c alias.h
|
||||
alias_la_LDFLAGS = -module
|
||||
alias_la_LIBADD = $(ALIAS_LFLAGS)
|
730
src/plugins/alias/alias.c
Normal file
730
src/plugins/alias/alias.c
Normal file
@ -0,0 +1,730 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2007 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* alias.c: Alias plugin for WeeChat */
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "alias.h"
|
||||
|
||||
|
||||
static struct t_weechat_plugin *weechat_plugin = NULL;
|
||||
|
||||
static struct t_config_file *alias_config_file = NULL;
|
||||
static struct t_alias *alias_list = NULL;
|
||||
static struct t_alias *last_alias = NULL;
|
||||
static struct t_hook *alias_command = NULL;
|
||||
static struct t_hook *unalias_command = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* alias_search: search an alias
|
||||
*/
|
||||
|
||||
static struct t_alias *
|
||||
alias_search (char *alias_name)
|
||||
{
|
||||
struct t_alias *ptr_alias;
|
||||
|
||||
for (ptr_alias = alias_list; ptr_alias;
|
||||
ptr_alias = ptr_alias->next_alias)
|
||||
{
|
||||
if (weechat_strcasecmp (alias_name, ptr_alias->name) == 0)
|
||||
return ptr_alias;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_add_word: add word to string and increment length
|
||||
* This function should NOT be called directly.
|
||||
*/
|
||||
|
||||
static void
|
||||
alias_add_word (char **alias, int *length, char *word)
|
||||
{
|
||||
int length_word;
|
||||
|
||||
if (!word)
|
||||
return;
|
||||
|
||||
length_word = strlen (word);
|
||||
if (length_word == 0)
|
||||
return;
|
||||
|
||||
if (*alias == NULL)
|
||||
{
|
||||
*alias = (char *) malloc (length_word + 1);
|
||||
strcpy (*alias, word);
|
||||
}
|
||||
else
|
||||
{
|
||||
*alias = realloc (*alias, strlen (*alias) + length_word + 1);
|
||||
strcat (*alias, word);
|
||||
}
|
||||
*length += length_word;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_replace_args: replace arguments ($1, $2, .. or $*) in alias arguments
|
||||
*/
|
||||
|
||||
static char *
|
||||
alias_replace_args (char *alias_args, char *user_args)
|
||||
{
|
||||
char **argv, *start, *pos, *res;
|
||||
int argc, length_res, args_count;
|
||||
|
||||
argv = weechat_string_explode (user_args, " ", 0, 0, &argc);
|
||||
|
||||
res = NULL;
|
||||
length_res = 0;
|
||||
args_count = 0;
|
||||
start = alias_args;
|
||||
pos = start;
|
||||
while (pos && pos[0])
|
||||
{
|
||||
if ((pos[0] == '\\') && (pos[1] == '$'))
|
||||
{
|
||||
pos[0] = '\0';
|
||||
alias_add_word (&res, &length_res, start);
|
||||
alias_add_word (&res, &length_res, "$");
|
||||
pos[0] = '\\';
|
||||
start = pos + 2;
|
||||
pos = start;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pos[0] == '$')
|
||||
{
|
||||
if (pos[1] == '*')
|
||||
{
|
||||
args_count++;
|
||||
pos[0] = '\0';
|
||||
alias_add_word (&res, &length_res, start);
|
||||
alias_add_word (&res, &length_res, user_args);
|
||||
pos[0] = '$';
|
||||
start = pos + 2;
|
||||
pos = start;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pos[1] >= '1') && (pos[1] <= '9'))
|
||||
{
|
||||
args_count++;
|
||||
pos[0] = '\0';
|
||||
alias_add_word (&res, &length_res, start);
|
||||
if (pos[1] - '0' <= argc)
|
||||
alias_add_word (&res, &length_res, argv[pos[1] - '1']);
|
||||
pos[0] = '$';
|
||||
start = pos + 2;
|
||||
pos = start;
|
||||
}
|
||||
else
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
else
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
if (start < pos)
|
||||
alias_add_word (&res, &length_res, start);
|
||||
|
||||
if ((args_count == 0) && user_args && user_args[0])
|
||||
{
|
||||
alias_add_word (&res, &length_res, " ");
|
||||
alias_add_word (&res, &length_res, user_args);
|
||||
}
|
||||
|
||||
if (argv)
|
||||
weechat_string_free_exploded (argv);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_cb: callback for alias (called when user uses an alias)
|
||||
*/
|
||||
|
||||
static int
|
||||
alias_cb (void *data, void *buffer, int argc, char **argv,
|
||||
char **argv_eol)
|
||||
{
|
||||
struct t_alias *ptr_alias;
|
||||
char **commands, **ptr_cmd, **ptr_next_cmd;
|
||||
char *args_replaced, *alias_command;
|
||||
int some_args_replaced, length1, length2;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
ptr_alias = (struct t_alias *)data;
|
||||
|
||||
if (ptr_alias->running)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%sError: circular reference when "
|
||||
"calling alias \"/%s\""),
|
||||
weechat_prefix ("error"),
|
||||
ptr_alias->name);
|
||||
return PLUGIN_RC_FAILED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* an alias can contain many commands separated by ';' */
|
||||
commands = weechat_string_split_command (ptr_alias->command, ';');
|
||||
if (commands)
|
||||
{
|
||||
some_args_replaced = 0;
|
||||
ptr_alias->running = 1;
|
||||
for (ptr_cmd = commands; *ptr_cmd; ptr_cmd++)
|
||||
{
|
||||
ptr_next_cmd = ptr_cmd;
|
||||
ptr_next_cmd++;
|
||||
|
||||
args_replaced = (argc > 1) ?
|
||||
alias_replace_args (*ptr_cmd, argv_eol[1]) : NULL;
|
||||
if (args_replaced)
|
||||
{
|
||||
some_args_replaced = 1;
|
||||
if (*ptr_cmd[0] == '/')
|
||||
weechat_command (buffer, args_replaced);
|
||||
else
|
||||
{
|
||||
alias_command = (char *) malloc (1 + strlen(args_replaced) + 1);
|
||||
if (alias_command)
|
||||
{
|
||||
strcpy (alias_command, "/");
|
||||
strcat (alias_command, args_replaced);
|
||||
weechat_command (buffer, alias_command);
|
||||
free (alias_command);
|
||||
}
|
||||
}
|
||||
free (args_replaced);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if alias has arguments, they are now
|
||||
arguments of the last command in the list (if no $1,$2,..$*) was found */
|
||||
if ((*ptr_next_cmd == NULL) && argv_eol[1] && (!some_args_replaced))
|
||||
{
|
||||
length1 = strlen (*ptr_cmd);
|
||||
length2 = strlen (argv_eol[1]);
|
||||
|
||||
alias_command = (char *) malloc ( 1 + length1 + 1 + length2 + 1);
|
||||
if (alias_command)
|
||||
{
|
||||
if (*ptr_cmd[0] != '/')
|
||||
strcpy (alias_command, "/");
|
||||
else
|
||||
strcpy (alias_command, "");
|
||||
|
||||
strcat (alias_command, *ptr_cmd);
|
||||
strcat (alias_command, " ");
|
||||
strcat (alias_command, argv_eol[1]);
|
||||
|
||||
weechat_command (buffer, alias_command);
|
||||
free (alias_command);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*ptr_cmd[0] == '/')
|
||||
(void) weechat_command(buffer, *ptr_cmd);
|
||||
else
|
||||
{
|
||||
alias_command = (char *) malloc (1 + strlen (*ptr_cmd) + 1);
|
||||
if (alias_command)
|
||||
{
|
||||
strcpy (alias_command, "/");
|
||||
strcat (alias_command, *ptr_cmd);
|
||||
weechat_command (buffer, alias_command);
|
||||
free (alias_command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ptr_alias->running = 0;
|
||||
weechat_string_free_splitted_command (commands);
|
||||
}
|
||||
}
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_new: create new alias and add it to alias list
|
||||
*/
|
||||
|
||||
static struct t_alias *
|
||||
alias_new (char *name, char *command)
|
||||
{
|
||||
struct t_alias *new_alias, *ptr_alias;
|
||||
struct t_hook *new_hook;
|
||||
|
||||
if (!name || !name[0] || !command || !command[0])
|
||||
return NULL;
|
||||
|
||||
while (name[0] == '/')
|
||||
{
|
||||
name++;
|
||||
}
|
||||
|
||||
ptr_alias = alias_search (name);
|
||||
if (ptr_alias)
|
||||
{
|
||||
if (ptr_alias->command)
|
||||
free (ptr_alias->command);
|
||||
ptr_alias->command = strdup (command);
|
||||
return ptr_alias;
|
||||
}
|
||||
|
||||
if ((new_alias = ((struct t_alias *) malloc (sizeof (struct t_alias)))))
|
||||
{
|
||||
new_hook = weechat_hook_command (name, NULL, NULL, NULL, NULL,
|
||||
alias_cb, new_alias);
|
||||
if (!new_hook)
|
||||
{
|
||||
free (new_alias);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_alias->hook = new_hook;
|
||||
new_alias->name = strdup (name);
|
||||
new_alias->command = strdup (command);
|
||||
new_alias->running = 0;
|
||||
|
||||
new_alias->prev_alias = last_alias;
|
||||
new_alias->next_alias = NULL;
|
||||
if (alias_list)
|
||||
last_alias->next_alias = new_alias;
|
||||
else
|
||||
alias_list = new_alias;
|
||||
last_alias = new_alias;
|
||||
|
||||
return new_alias;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_get_final_command: get final command pointed by an alias
|
||||
*/
|
||||
|
||||
static char *
|
||||
alias_get_final_command (struct t_alias *alias)
|
||||
{
|
||||
struct t_alias *ptr_alias;
|
||||
char *result;
|
||||
|
||||
if (alias->running)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%sError: circular reference when calling alias "
|
||||
"\"/%s\""),
|
||||
weechat_prefix ("error"),
|
||||
alias->name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr_alias = alias_search ((alias->command[0] == '/') ?
|
||||
alias->command + 1 : alias->command);
|
||||
if (ptr_alias)
|
||||
{
|
||||
alias->running = 1;
|
||||
result = alias_get_final_command (ptr_alias);
|
||||
alias->running = 0;
|
||||
return result;
|
||||
}
|
||||
return (alias->command[0] == '/') ?
|
||||
alias->command + 1 : alias->command;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_free: free an alias and reomve it from list
|
||||
*/
|
||||
|
||||
static void
|
||||
alias_free (struct t_alias *alias)
|
||||
{
|
||||
struct t_alias *new_alias_list;
|
||||
|
||||
/* remove alias from list */
|
||||
if (last_alias == alias)
|
||||
last_alias = alias->prev_alias;
|
||||
if (alias->prev_alias)
|
||||
{
|
||||
(alias->prev_alias)->next_alias = alias->next_alias;
|
||||
new_alias_list = alias_list;
|
||||
}
|
||||
else
|
||||
new_alias_list = alias->next_alias;
|
||||
|
||||
if (alias->next_alias)
|
||||
(alias->next_alias)->prev_alias = alias->prev_alias;
|
||||
|
||||
/* free data */
|
||||
if (alias->hook)
|
||||
weechat_unhook (alias->hook);
|
||||
if (alias->name)
|
||||
free (alias->name);
|
||||
if (alias->command)
|
||||
free (alias->command);
|
||||
free (alias);
|
||||
alias_list = new_alias_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_free_all: free all alias
|
||||
*/
|
||||
|
||||
static void
|
||||
alias_free_all ()
|
||||
{
|
||||
while (alias_list)
|
||||
alias_free (alias_list);
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_config_read_line: read an alias in configuration file
|
||||
*/
|
||||
|
||||
void
|
||||
alias_config_read_line (void *config_file, char *option_name, char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) config_file;
|
||||
|
||||
/* create new alias */
|
||||
if (!alias_new (option_name, value))
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
"%sAlias: error creating alias \"%s\" => \"%s\"",
|
||||
weechat_prefix ("error"),
|
||||
option_name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_config_write_section: write alias section in configuration file
|
||||
* Return: 0 = successful
|
||||
* -1 = write error
|
||||
*/
|
||||
|
||||
void
|
||||
alias_config_write_section (void *config_file)
|
||||
{
|
||||
struct t_alias *ptr_alias;
|
||||
char *string;
|
||||
|
||||
for (ptr_alias = alias_list; ptr_alias;
|
||||
ptr_alias = ptr_alias->next_alias)
|
||||
{
|
||||
string = (char *)malloc (strlen (ptr_alias->command) + 4);
|
||||
if (string)
|
||||
{
|
||||
strcpy (string, "\"");
|
||||
strcat (string, ptr_alias->command);
|
||||
strcat (string, "\"");
|
||||
weechat_config_write_line (config_file,
|
||||
ptr_alias->name,
|
||||
string);
|
||||
free (string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_config_write_default_aliases: write default aliases in configuration file
|
||||
*/
|
||||
|
||||
void
|
||||
alias_config_write_default_aliases (void *config_file)
|
||||
{
|
||||
weechat_config_write_line (config_file, "SAY", "\"msg *\"");
|
||||
weechat_config_write_line (config_file, "BYE", "\"quit\"");
|
||||
weechat_config_write_line (config_file, "EXIT", "\"quit\"");
|
||||
weechat_config_write_line (config_file, "SIGNOFF", "\"quit\"");
|
||||
weechat_config_write_line (config_file, "C", "\"clear\"");
|
||||
weechat_config_write_line (config_file, "CL", "\"clear\"");
|
||||
weechat_config_write_line (config_file, "CLOSE", "\"buffer close\"");
|
||||
weechat_config_write_line (config_file, "CHAT", "\"dcc chat\"");
|
||||
weechat_config_write_line (config_file, "IG", "\"ignore\"");
|
||||
weechat_config_write_line (config_file, "J", "\"join\"");
|
||||
weechat_config_write_line (config_file, "K", "\"kick\"");
|
||||
weechat_config_write_line (config_file, "KB", "\"kickban\"");
|
||||
weechat_config_write_line (config_file, "LEAVE", "\"part\"");
|
||||
weechat_config_write_line (config_file, "M", "\"msg\"");
|
||||
weechat_config_write_line (config_file, "MUB", "\"unban *\"");
|
||||
weechat_config_write_line (config_file, "N", "\"names\"");
|
||||
weechat_config_write_line (config_file, "Q", "\"query\"");
|
||||
weechat_config_write_line (config_file, "T", "\"topic\"");
|
||||
weechat_config_write_line (config_file, "UB", "\"unban\"");
|
||||
weechat_config_write_line (config_file, "UNIG", "\"unignore\"");
|
||||
weechat_config_write_line (config_file, "W", "\"who\"");
|
||||
weechat_config_write_line (config_file, "WC", "\"window merge\"");
|
||||
weechat_config_write_line (config_file, "WI", "\"whois\"");
|
||||
weechat_config_write_line (config_file, "WW", "\"whowas\"");
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_config_init: init alias configuration file
|
||||
*/
|
||||
|
||||
static int
|
||||
alias_config_init ()
|
||||
{
|
||||
struct t_config_section *ptr_section;
|
||||
|
||||
alias_config_file = weechat_config_new (ALIAS_CONFIG_FILENAME);
|
||||
if (alias_config_file)
|
||||
{
|
||||
ptr_section = weechat_config_new_section (alias_config_file, "alias",
|
||||
alias_config_read_line,
|
||||
alias_config_write_section,
|
||||
alias_config_write_default_aliases);
|
||||
if (ptr_section)
|
||||
return 1;
|
||||
weechat_config_free (alias_config_file);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_config_read: read alias configuration file
|
||||
*/
|
||||
|
||||
static int
|
||||
alias_config_read ()
|
||||
{
|
||||
return weechat_config_read (alias_config_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_config_reaload: reload alias configuration file
|
||||
*/
|
||||
|
||||
static int
|
||||
alias_config_reload ()
|
||||
{
|
||||
alias_free_all ();
|
||||
return weechat_config_reload (alias_config_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_config_write: write alias configuration file
|
||||
*/
|
||||
|
||||
static int
|
||||
alias_config_write ()
|
||||
{
|
||||
return weechat_config_write (alias_config_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_command_cb: display or create alias
|
||||
*/
|
||||
|
||||
static int
|
||||
alias_command_cb (void *data, void *buffer, int argc, char **argv,
|
||||
char **argv_eol)
|
||||
{
|
||||
char *alias_name;
|
||||
struct t_alias *ptr_alias;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
alias_name = (argv[1][0] == '/') ? argv[1] + 1 : argv[1];
|
||||
if (argc > 2)
|
||||
{
|
||||
/* Define new alias */
|
||||
if (!alias_new (alias_name, argv_eol[2]))
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%sAlias: error creating alias \"%s\" "
|
||||
"=> \"%\""),
|
||||
weechat_prefix ("error"),
|
||||
alias_name, argv_eol[2]);
|
||||
return PLUGIN_RC_FAILED;
|
||||
}
|
||||
weechat_printf (NULL,
|
||||
_("%sAlias \"%s\" => \"%s\" created"),
|
||||
weechat_prefix ("info"),
|
||||
alias_name, argv_eol[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Display one alias */
|
||||
ptr_alias = alias_search (alias_name);
|
||||
if (ptr_alias)
|
||||
{
|
||||
weechat_printf (NULL, "");
|
||||
weechat_printf (NULL, _("Alias:"));
|
||||
weechat_printf (NULL, " %s %s=>%s %s",
|
||||
ptr_alias->name,
|
||||
weechat_color ("color_chat_delimiters"),
|
||||
weechat_color ("color_chat"),
|
||||
ptr_alias->command);
|
||||
}
|
||||
else
|
||||
weechat_printf (NULL,
|
||||
_("%sNo alias found."),
|
||||
weechat_prefix ("info"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* List all aliases */
|
||||
if (alias_list)
|
||||
{
|
||||
weechat_printf (NULL, "");
|
||||
weechat_printf (NULL, _("List of aliases:"));
|
||||
for (ptr_alias = alias_list; ptr_alias;
|
||||
ptr_alias = ptr_alias->next_alias)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
" %s %s=>%s %s",
|
||||
ptr_alias->name,
|
||||
weechat_color ("color_chat_delimiters"),
|
||||
weechat_color ("color_chat"),
|
||||
ptr_alias->command);
|
||||
}
|
||||
}
|
||||
else
|
||||
weechat_printf (NULL,
|
||||
_("%sNo alias defined."),
|
||||
weechat_prefix ("info"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* unalias_command_cb: remove an alias
|
||||
*/
|
||||
|
||||
int
|
||||
unalias_command_cb (void *data, void *buffer, int argc, char **argv,
|
||||
char **argv_eol)
|
||||
{
|
||||
char *alias_name;
|
||||
struct t_alias *ptr_alias;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
(void) argv_eol;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
alias_name = (argv[1][0] == '/') ? argv[1] + 1 : argv[1];
|
||||
ptr_alias = alias_search (alias_name);
|
||||
if (!ptr_alias)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%sAlias \"%s\" not found"),
|
||||
weechat_prefix ("error"),
|
||||
alias_name);
|
||||
return -1;
|
||||
}
|
||||
alias_free (ptr_alias);
|
||||
weechat_printf (NULL,
|
||||
_("%sAlias \"%s\" removed"),
|
||||
weechat_prefix ("info"),
|
||||
alias_name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: initialize alias plugin
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
weechat_plugin = plugin;
|
||||
|
||||
if (!alias_config_init ())
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
"%sAlias: error creating configuration file \"%s\"",
|
||||
weechat_prefix("error"),
|
||||
ALIAS_CONFIG_FILENAME);
|
||||
return PLUGIN_RC_FAILED;
|
||||
}
|
||||
alias_config_read ();
|
||||
|
||||
alias_command = weechat_hook_command ("alias",
|
||||
N_("create an alias for a command"),
|
||||
N_("[alias_name [command [arguments]]]"),
|
||||
N_("alias_name: name of alias\n"
|
||||
" command: command name (many "
|
||||
"commands can be separated by "
|
||||
"semicolons)\n"
|
||||
" arguments: arguments for "
|
||||
"command\n\n"
|
||||
"Note: in command, special "
|
||||
"variables $1, $2,..,$9 "
|
||||
"are replaced by arguments given "
|
||||
"by user, and $* "
|
||||
"is replaced by all arguments.\n"
|
||||
"Variables $nick, $channel and "
|
||||
"$server are "
|
||||
"replaced by current nick/channel"
|
||||
"/server."),
|
||||
"%- %h",
|
||||
alias_command_cb, NULL);
|
||||
|
||||
unalias_command = weechat_hook_command ("unalias", N_("remove an alias"),
|
||||
N_("alias_name"),
|
||||
N_("alias_name: name of alias to "
|
||||
"remove"),
|
||||
"%h",
|
||||
unalias_command_cb, NULL);
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_end: end alias plugin
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_plugin_end ()
|
||||
{
|
||||
alias_config_write ();
|
||||
alias_free_all ();
|
||||
weechat_unhook (alias_command);
|
||||
weechat_unhook (unalias_command);
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
@ -20,26 +20,20 @@
|
||||
#ifndef __WEECHAT_ALIAS_H
|
||||
#define __WEECHAT_ALIAS_H 1
|
||||
|
||||
#include "../gui/gui-buffer.h"
|
||||
char plugin_name[] = "alias";
|
||||
char plugin_version[] = "0.1";
|
||||
char plugin_description[] = "Alias plugin for WeeChat";
|
||||
|
||||
struct alias
|
||||
#define ALIAS_CONFIG_FILENAME "alias.rc"
|
||||
|
||||
struct t_alias
|
||||
{
|
||||
char *name;
|
||||
char *command;
|
||||
int running;
|
||||
struct alias *prev_alias;
|
||||
struct alias *next_alias;
|
||||
struct t_hook *hook; /* command hook */
|
||||
char *name; /* alias name */
|
||||
char *command; /* alias command */
|
||||
int running; /* 1 if alias is running */
|
||||
struct t_alias *prev_alias; /* link to previous alias */
|
||||
struct t_alias *next_alias; /* link to next alias */
|
||||
};
|
||||
|
||||
extern struct alias *weechat_alias;
|
||||
extern struct alias *weechat_last_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 (struct t_gui_buffer *, char *);
|
||||
extern void alias_free (struct alias *);
|
||||
extern void alias_free_all ();
|
||||
|
||||
#endif /* wee-alias.h */
|
||||
#endif /* alias.h */
|
@ -2597,7 +2597,7 @@ irc_protocol_cmd_001 (t_irc_server *server, char *irc_message, char *host,
|
||||
if (server->command && server->command[0])
|
||||
{
|
||||
/* splitting command on ';' which can be escaped with '\;' */
|
||||
commands = weechat_split_multi_command (server->command, ';');
|
||||
commands = weechat_split_command (server->command, ';');
|
||||
if (commands)
|
||||
{
|
||||
for (ptr = commands; *ptr; ptr++)
|
||||
@ -2608,7 +2608,7 @@ irc_protocol_cmd_001 (t_irc_server *server, char *irc_message, char *host,
|
||||
if (vars_replaced)
|
||||
free (vars_replaced);
|
||||
}
|
||||
weechat_free_multi_command (commands);
|
||||
weechat_free_splitted_command (commands);
|
||||
}
|
||||
|
||||
if (server->command_delay > 0)
|
||||
|
@ -199,6 +199,34 @@ plugin_api_string_free_exploded (struct t_weechat_plugin *plugin,
|
||||
string_free_exploded (exploded_string);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_string_split_command: split a ocmmanc
|
||||
*/
|
||||
|
||||
char **
|
||||
plugin_api_string_split_command (struct t_weechat_plugin *plugin, char *string,
|
||||
char separator)
|
||||
{
|
||||
if (!plugin || !string)
|
||||
return NULL;
|
||||
|
||||
return string_split_command (string, separator);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_string_free_splitted_command: free splitted command
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_api_string_free_splitted_command (struct t_weechat_plugin *plugin,
|
||||
char **splitted_command)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) plugin;
|
||||
|
||||
string_free_splitted_command (splitted_command);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_mkdir_home: create a directory in WeeChat home
|
||||
*/
|
||||
@ -397,6 +425,70 @@ plugin_api_config_color (struct t_weechat_plugin *plugin, void *option)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_config_read: read a configuration file
|
||||
*/
|
||||
|
||||
int
|
||||
plugin_api_config_read (struct t_weechat_plugin *plugin, void *config_file)
|
||||
{
|
||||
if (plugin && config_file_valid_for_plugin (plugin, config_file))
|
||||
return config_file_read ((struct t_config_file *)config_file);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_config_reload: reload a configuration file
|
||||
*/
|
||||
|
||||
int
|
||||
plugin_api_config_reload (struct t_weechat_plugin *plugin, void *config_file)
|
||||
{
|
||||
if (plugin && config_file_valid_for_plugin (plugin, config_file))
|
||||
return config_file_reload ((struct t_config_file *)config_file);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_config_write: write a configuration file
|
||||
*/
|
||||
|
||||
int
|
||||
plugin_api_config_write (struct t_weechat_plugin *plugin, void *config_file)
|
||||
{
|
||||
if (plugin && config_file_valid_for_plugin (plugin, config_file))
|
||||
return config_file_write ((struct t_config_file *)config_file, 0);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_config_write_line: write a line in configuration file
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_api_config_write_line (struct t_weechat_plugin *plugin,
|
||||
void *config_file, char *option_name,
|
||||
char *value)
|
||||
{
|
||||
if (plugin && config_file_valid_for_plugin (plugin, config_file))
|
||||
config_file_write_line ((struct t_config_file *)config_file,
|
||||
option_name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_config_free: free a configuration file
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_api_config_free (struct t_weechat_plugin *plugin, void *config_file)
|
||||
{
|
||||
if (plugin && config_file_valid_for_plugin (plugin, config_file))
|
||||
config_file_free ((struct t_config_file *)config_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_get_config_str_value: return string value for any option
|
||||
* This function should never be called directly
|
||||
|
@ -38,6 +38,10 @@ extern char **plugin_api_string_explode (struct t_weechat_plugin *, char *,
|
||||
char *, int, int, int *);
|
||||
extern void plugin_api_string_free_exploded (struct t_weechat_plugin *,
|
||||
char **);
|
||||
extern char **plugin_api_string_split_command (struct t_weechat_plugin *,
|
||||
char *, char);
|
||||
extern void plugin_api_string_free_splitted_command (struct t_weechat_plugin *,
|
||||
char **);
|
||||
|
||||
/* directories */
|
||||
extern int plugin_api_mkdir_home (struct t_weechat_plugin *, char *);
|
||||
@ -45,20 +49,29 @@ extern void plugin_api_exec_on_files (struct t_weechat_plugin *, char *,
|
||||
int (*)(char *));
|
||||
|
||||
/* config */
|
||||
extern struct t_config_file *config_new (struct t_weechat_plugin *, char *);
|
||||
extern struct t_config_section *config_new_section (struct t_weechat_plugin *,
|
||||
void *, char *,
|
||||
void (*)(void *, char *, char *),
|
||||
void (*)(void *),
|
||||
void (*)(void *));
|
||||
extern struct t_config_option *config_new_option (struct t_weechat_plugin *,
|
||||
void *, char *, char *,
|
||||
char *, char *, int, int,
|
||||
char *, void (*)());
|
||||
extern char config_boolean (struct t_weechat_plugin *, void *);
|
||||
extern int config_integer (struct t_weechat_plugin *, void *);
|
||||
extern char *config_string (struct t_weechat_plugin *, void *);
|
||||
extern int config_color (struct t_weechat_plugin *, void *);
|
||||
extern struct t_config_file *plugin_api_config_new (struct t_weechat_plugin *,
|
||||
char *);
|
||||
extern struct t_config_section *plugin_api_config_new_section (struct t_weechat_plugin *,
|
||||
void *, char *,
|
||||
void (*)(void *, char *, char *),
|
||||
void (*)(void *),
|
||||
void (*)(void *));
|
||||
extern struct t_config_option *plugin_api_config_new_option (struct t_weechat_plugin *,
|
||||
void *, char *,
|
||||
char *, char *,
|
||||
char *, int, int,
|
||||
char *,
|
||||
void (*)());
|
||||
extern char plugin_api_config_boolean (struct t_weechat_plugin *, void *);
|
||||
extern int plugin_api_config_integer (struct t_weechat_plugin *, void *);
|
||||
extern char *plugin_api_config_string (struct t_weechat_plugin *, void *);
|
||||
extern int plugin_api_config_color (struct t_weechat_plugin *, void *);
|
||||
extern int plugin_api_config_read (struct t_weechat_plugin *, void *);
|
||||
extern int plugin_api_config_reload (struct t_weechat_plugin *, void *);
|
||||
extern int plugin_api_config_write (struct t_weechat_plugin *, void *);
|
||||
extern void plugin_api_config_write_line (struct t_weechat_plugin *, void *,
|
||||
char *, char *);
|
||||
extern void plugin_api_config_free (struct t_weechat_plugin *, void *);
|
||||
extern char *plugin_api_config_get (struct t_weechat_plugin *, char *);
|
||||
extern int plugin_api_config_set (struct t_weechat_plugin *, char *, char *);
|
||||
extern char *plugin_api_plugin_config_get (struct t_weechat_plugin *, char *);
|
||||
|
@ -234,14 +234,32 @@ plugin_load (char *filename)
|
||||
new_plugin->string_replace = &plugin_api_string_replace;
|
||||
new_plugin->string_explode = &plugin_api_string_explode;
|
||||
new_plugin->string_free_exploded = &plugin_api_string_free_exploded;
|
||||
new_plugin->string_split_command = &plugin_api_string_split_command;
|
||||
new_plugin->string_free_splitted_command = &plugin_api_string_free_splitted_command;
|
||||
|
||||
new_plugin->mkdir_home = &plugin_api_mkdir_home;
|
||||
new_plugin->exec_on_files = &plugin_api_exec_on_files;
|
||||
|
||||
new_plugin->printf = &plugin_api_printf;
|
||||
new_plugin->printf_date = &plugin_api_printf_date;
|
||||
|
||||
new_plugin->config_new = &plugin_api_config_new;
|
||||
new_plugin->config_new_section = &plugin_api_config_new_section;
|
||||
new_plugin->config_new_option = &plugin_api_config_new_option;
|
||||
new_plugin->config_boolean = &plugin_api_config_boolean;
|
||||
new_plugin->config_integer = &plugin_api_config_integer;
|
||||
new_plugin->config_string = &plugin_api_config_string;
|
||||
new_plugin->config_color = &plugin_api_config_color;
|
||||
new_plugin->config_read = &plugin_api_config_read;
|
||||
new_plugin->config_reload = &plugin_api_config_reload;
|
||||
new_plugin->config_write = &plugin_api_config_write;
|
||||
new_plugin->config_write_line = &plugin_api_config_write_line;
|
||||
new_plugin->config_get = &plugin_api_config_get;
|
||||
new_plugin->config_set = &plugin_api_config_set;
|
||||
new_plugin->plugin_config_get = &plugin_api_plugin_config_get;
|
||||
new_plugin->plugin_config_set = &plugin_api_plugin_config_set;
|
||||
|
||||
new_plugin->prefix = &plugin_api_prefix;
|
||||
new_plugin->color = &plugin_api_color;
|
||||
new_plugin->printf = &plugin_api_printf;
|
||||
new_plugin->printf_date = &plugin_api_printf_date;
|
||||
new_plugin->print_infobar = &plugin_api_print_infobar;
|
||||
new_plugin->infobar_remove = &plugin_api_infobar_remove;
|
||||
|
||||
@ -275,11 +293,6 @@ plugin_load (char *filename)
|
||||
new_plugin->list_time = &plugin_api_list_time;
|
||||
new_plugin->list_free = &plugin_api_list_free;
|
||||
|
||||
new_plugin->config_get = &plugin_api_config_get;
|
||||
new_plugin->config_set = &plugin_api_config_set;
|
||||
new_plugin->plugin_config_get = &plugin_api_plugin_config_get;
|
||||
new_plugin->plugin_config_set = &plugin_api_plugin_config_set;
|
||||
|
||||
new_plugin->log = &plugin_api_log;
|
||||
|
||||
/* add new plugin to list */
|
||||
|
@ -67,6 +67,8 @@ struct t_weechat_plugin
|
||||
char **(*string_explode) (struct t_weechat_plugin *, char *, char *, int,
|
||||
int, int *);
|
||||
void (*string_free_exploded) (struct t_weechat_plugin *, char **);
|
||||
char **(*string_split_command) (struct t_weechat_plugin *, char *, char);
|
||||
void (*string_free_splitted_command) (struct t_weechat_plugin *, char **);
|
||||
|
||||
/* directories */
|
||||
int (*mkdir_home) (struct t_weechat_plugin *, char *);
|
||||
@ -88,11 +90,16 @@ struct t_weechat_plugin
|
||||
int (*config_integer) (struct t_weechat_plugin *, void *);
|
||||
char *(*config_string) (struct t_weechat_plugin *, void *);
|
||||
int (*config_color) (struct t_weechat_plugin *, void *);
|
||||
int (*config_read) (struct t_weechat_plugin *, void *);
|
||||
int (*config_reload) (struct t_weechat_plugin *, void *);
|
||||
int (*config_write) (struct t_weechat_plugin *, void *);
|
||||
void (*config_write_line) (struct t_weechat_plugin *, void *,
|
||||
char *, char *);
|
||||
void (*config_free) (struct t_weechat_plugin *, void *);
|
||||
char *(*config_get) (struct t_weechat_plugin *, char *);
|
||||
int (*config_set) (struct t_weechat_plugin *, char *, char *);
|
||||
char *(*plugin_config_get) (struct t_weechat_plugin *, char *);
|
||||
int (*plugin_config_set) (struct t_weechat_plugin *, char *, char *);
|
||||
|
||||
|
||||
/* display */
|
||||
char *(*prefix) (struct t_weechat_plugin *, char *);
|
||||
@ -193,6 +200,12 @@ struct t_weechat_plugin
|
||||
__num_items)
|
||||
#define weechat_string_free_exploded(__array_str) \
|
||||
weechat_plugin->string_free_exploded(weechat_plugin, __array_str)
|
||||
#define weechat_string_split_command(__string1, __separator) \
|
||||
weechat_plugin->string_split_command(weechat_plugin, __string1, \
|
||||
__separator)
|
||||
#define weechat_string_free_splitted_command(__array_str) \
|
||||
weechat_plugin->string_free_splitted_command(weechat_plugin, \
|
||||
__array_str)
|
||||
|
||||
/* directories */
|
||||
#define weechat_mkdir_home(__directory) \
|
||||
@ -224,6 +237,18 @@ struct t_weechat_plugin
|
||||
weechat_plugin->config_string(weechat_plugin, __option)
|
||||
#define weechat_config_color(__option) \
|
||||
weechat_plugin->config_color(weechat_plugin, __option)
|
||||
#define weechat_config_read(__config) \
|
||||
weechat_plugin->config_read(weechat_plugin, __config)
|
||||
#define weechat_config_reload(__config) \
|
||||
weechat_plugin->config_reload(weechat_plugin, __config)
|
||||
#define weechat_config_write(__config) \
|
||||
weechat_plugin->config_write(weechat_plugin, __config)
|
||||
#define weechat_config_write_line(__config, __option, __value) \
|
||||
weechat_plugin->config_write_line(weechat_plugin, \
|
||||
__config, __option, \
|
||||
__value)
|
||||
#define weechat_config_free(__config) \
|
||||
weechat_plugin->config_free(weechat_plugin, __config)
|
||||
#define weechat_config_get(__option) \
|
||||
weechat_plugin->config_get(weechat_plugin, __option)
|
||||
#define weechat_config_set(__option, __value) \
|
||||
|
Loading…
x
Reference in New Issue
Block a user