mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 23:36:37 +02:00
add regular expression support for /list command
This commit is contained in:
+2
-2
@@ -55,7 +55,7 @@ AC_CHECK_LIB(ncursesw, initscr, LIBNCURSESW_FOUND=1, LIBNCURSESW_FOUND=0)
|
||||
|
||||
# Checks for header files
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([arpa/inet.h libintl.h limits.h locale.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h sys/types.h unistd.h pwd.h errno.h])
|
||||
AC_CHECK_HEADERS([arpa/inet.h libintl.h limits.h locale.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h sys/types.h unistd.h pwd.h errno.h regex.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics
|
||||
AC_HEADER_TIME
|
||||
@@ -78,7 +78,7 @@ AC_MSG_RESULT($ac_cv_type_socklen_t)
|
||||
# Checks for library functions.
|
||||
AC_FUNC_SELECT_ARGTYPES
|
||||
AC_TYPE_SIGNAL
|
||||
AC_CHECK_FUNCS([gethostbyname gethostname getsockname gettimeofday inet_ntoa memset mkdir select setlocale socket strcasecmp strchr strdup strncasecmp strpbrk strrchr strstr uname])
|
||||
AC_CHECK_FUNCS([gethostbyname gethostname getsockname gettimeofday inet_ntoa memset mkdir select setlocale socket strcasecmp strchr strdup strncasecmp strpbrk strrchr strstr uname regexec])
|
||||
|
||||
# Variables in config.h
|
||||
|
||||
|
||||
+13
-2
@@ -33,6 +33,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
@@ -3661,8 +3662,18 @@ irc_cmd_recv_322 (t_irc_server *server, char *host, char *nick, char *arguments)
|
||||
else
|
||||
pos = arguments;
|
||||
|
||||
irc_display_prefix (server, server->buffer, PREFIX_SERVER);
|
||||
gui_printf (server->buffer, "%s\n", pos);
|
||||
if (server->cmd_list_re)
|
||||
{
|
||||
if (regexec (server->cmd_list_re, pos, 0, NULL, 0) == 0) {
|
||||
irc_display_prefix (server, server->buffer, PREFIX_SERVER);
|
||||
gui_printf (server->buffer, "%s\n", pos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (server, server->buffer, PREFIX_SERVER);
|
||||
gui_printf (server->buffer, "%s\n", pos);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+33
-2
@@ -33,6 +33,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
@@ -1117,11 +1118,41 @@ irc_cmd_send_list (t_irc_server *server, t_irc_channel *channel,
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) channel;
|
||||
char buffer[512];
|
||||
int ret;
|
||||
|
||||
if (server->cmd_list_re)
|
||||
{
|
||||
regfree (server->cmd_list_re);
|
||||
free (server->cmd_list_re);
|
||||
server->cmd_list_re = NULL;
|
||||
}
|
||||
|
||||
if (arguments)
|
||||
server_sendf (server, "LIST %s\r\n", arguments);
|
||||
{
|
||||
server->cmd_list_re = (regex_t *) malloc (sizeof (regex_t));
|
||||
if (server->cmd_list_re)
|
||||
{
|
||||
if ((ret = regcomp (server->cmd_list_re, arguments, REG_NOSUB | REG_ICASE)) != 0)
|
||||
{
|
||||
regerror (ret, server->cmd_list_re, buffer, sizeof(buffer));
|
||||
gui_printf (server->buffer,
|
||||
_("%s \"%s\" is not a valid regular expression (%s)\n"),
|
||||
WEECHAT_ERROR, arguments, buffer);
|
||||
}
|
||||
else
|
||||
server_sendf (server, "LIST\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_printf (server->buffer,
|
||||
_("%s unable to alloc memory for regular expression\n"),
|
||||
WEECHAT_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
server_sendf (server, "LIST\r\n");
|
||||
server_sendf (server, "LIST\r\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,9 @@ server_init (t_irc_server *server)
|
||||
server->saved_buffer = NULL;
|
||||
server->channels = NULL;
|
||||
server->last_channel = NULL;
|
||||
|
||||
/* regexp vars */
|
||||
server->cmd_list_re = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <regex.h>
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
#include <gnutls/gnutls.h>
|
||||
@@ -177,6 +178,9 @@ struct t_irc_server
|
||||
t_irc_channel *last_channel; /* last opened channal on server */
|
||||
t_irc_server *prev_server; /* link to previous server */
|
||||
t_irc_server *next_server; /* link to next server */
|
||||
|
||||
/* regexp vars */
|
||||
regex_t *cmd_list_re; /* compiled Regular Expression for /list */
|
||||
};
|
||||
|
||||
/* irc commands */
|
||||
|
||||
@@ -55,7 +55,7 @@ AC_CHECK_LIB(ncursesw, initscr, LIBNCURSESW_FOUND=1, LIBNCURSESW_FOUND=0)
|
||||
|
||||
# Checks for header files
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([arpa/inet.h libintl.h limits.h locale.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h sys/types.h unistd.h pwd.h errno.h])
|
||||
AC_CHECK_HEADERS([arpa/inet.h libintl.h limits.h locale.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h sys/types.h unistd.h pwd.h errno.h regex.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics
|
||||
AC_HEADER_TIME
|
||||
@@ -78,7 +78,7 @@ AC_MSG_RESULT($ac_cv_type_socklen_t)
|
||||
# Checks for library functions.
|
||||
AC_FUNC_SELECT_ARGTYPES
|
||||
AC_TYPE_SIGNAL
|
||||
AC_CHECK_FUNCS([gethostbyname gethostname getsockname gettimeofday inet_ntoa memset mkdir select setlocale socket strcasecmp strchr strdup strncasecmp strpbrk strrchr strstr uname])
|
||||
AC_CHECK_FUNCS([gethostbyname gethostname getsockname gettimeofday inet_ntoa memset mkdir select setlocale socket strcasecmp strchr strdup strncasecmp strpbrk strrchr strstr uname regexec])
|
||||
|
||||
# Variables in config.h
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
@@ -3661,8 +3662,18 @@ irc_cmd_recv_322 (t_irc_server *server, char *host, char *nick, char *arguments)
|
||||
else
|
||||
pos = arguments;
|
||||
|
||||
irc_display_prefix (server, server->buffer, PREFIX_SERVER);
|
||||
gui_printf (server->buffer, "%s\n", pos);
|
||||
if (server->cmd_list_re)
|
||||
{
|
||||
if (regexec (server->cmd_list_re, pos, 0, NULL, 0) == 0) {
|
||||
irc_display_prefix (server, server->buffer, PREFIX_SERVER);
|
||||
gui_printf (server->buffer, "%s\n", pos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_display_prefix (server, server->buffer, PREFIX_SERVER);
|
||||
gui_printf (server->buffer, "%s\n", pos);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "../common/weechat.h"
|
||||
#include "irc.h"
|
||||
@@ -1117,11 +1118,41 @@ irc_cmd_send_list (t_irc_server *server, t_irc_channel *channel,
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) channel;
|
||||
char buffer[512];
|
||||
int ret;
|
||||
|
||||
if (server->cmd_list_re)
|
||||
{
|
||||
regfree (server->cmd_list_re);
|
||||
free (server->cmd_list_re);
|
||||
server->cmd_list_re = NULL;
|
||||
}
|
||||
|
||||
if (arguments)
|
||||
server_sendf (server, "LIST %s\r\n", arguments);
|
||||
{
|
||||
server->cmd_list_re = (regex_t *) malloc (sizeof (regex_t));
|
||||
if (server->cmd_list_re)
|
||||
{
|
||||
if ((ret = regcomp (server->cmd_list_re, arguments, REG_NOSUB | REG_ICASE)) != 0)
|
||||
{
|
||||
regerror (ret, server->cmd_list_re, buffer, sizeof(buffer));
|
||||
gui_printf (server->buffer,
|
||||
_("%s \"%s\" is not a valid regular expression (%s)\n"),
|
||||
WEECHAT_ERROR, arguments, buffer);
|
||||
}
|
||||
else
|
||||
server_sendf (server, "LIST\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_printf (server->buffer,
|
||||
_("%s unable to alloc memory for regular expression\n"),
|
||||
WEECHAT_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
server_sendf (server, "LIST\r\n");
|
||||
server_sendf (server, "LIST\r\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,9 @@ server_init (t_irc_server *server)
|
||||
server->saved_buffer = NULL;
|
||||
server->channels = NULL;
|
||||
server->last_channel = NULL;
|
||||
|
||||
/* regexp vars */
|
||||
server->cmd_list_re = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <regex.h>
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
#include <gnutls/gnutls.h>
|
||||
@@ -177,6 +178,9 @@ struct t_irc_server
|
||||
t_irc_channel *last_channel; /* last opened channal on server */
|
||||
t_irc_server *prev_server; /* link to previous server */
|
||||
t_irc_server *next_server; /* link to next server */
|
||||
|
||||
/* regexp vars */
|
||||
regex_t *cmd_list_re; /* compiled Regular Expression for /list */
|
||||
};
|
||||
|
||||
/* irc commands */
|
||||
|
||||
Reference in New Issue
Block a user