Change send_text() to combine command, hook and log arguments into one set of flags

This function is exported to modules, so it requires updating a few modules and rolling the module table version.
This commit is contained in:
Kevin Easton
2017-07-09 00:08:04 +10:00
parent 496bbc8b74
commit bb616e0626
15 changed files with 50 additions and 48 deletions

View File

@@ -1,5 +1,8 @@
[Changes 1.2.2] [Changes 1.2.2]
* Change send_text() to combine command, hook and log arguments into one
set of flags. (caf)
* Update to build against modern libtcl (don't access tcl_interp->result * Update to build against modern libtcl (don't access tcl_interp->result
directly). (caf) directly). (caf)

View File

@@ -74,7 +74,7 @@ static char *Pkga_newctcp (CtcpEntryDll *dll, char *from, char *to, char *args)
{ {
char putbuf[500]; char putbuf[500];
sprintf(putbuf, "%c%s %s%c", CTCP_DELIM_CHAR, dll->name, my_ctime(time(NULL)), CTCP_DELIM_CHAR); sprintf(putbuf, "%c%s %s%c", CTCP_DELIM_CHAR, dll->name, my_ctime(time(NULL)), CTCP_DELIM_CHAR);
send_text(from, putbuf, "NOTICE", 0, 0); send_text(from, putbuf, STXT_NOTICE | STXT_QUIET);
return NULL; return NULL;
} }
@@ -82,7 +82,7 @@ static char *Pkga_ctcppage (CtcpEntryDll *dll, char *from, char *to, char *args)
{ {
char putbuf[500]; char putbuf[500];
sprintf(putbuf, "%c%s %s%c", CTCP_DELIM_CHAR, dll->name, my_ctime(time(NULL)), CTCP_DELIM_CHAR); sprintf(putbuf, "%c%s %s%c", CTCP_DELIM_CHAR, dll->name, my_ctime(time(NULL)), CTCP_DELIM_CHAR);
send_text(from, putbuf, "NOTICE", 0, 0); send_text(from, putbuf, STXT_NOTICE | STXT_QUIET);
put_it(" %s is paging you", from); put_it(" %s is paging you", from);
return NULL; return NULL;
} }

View File

@@ -280,7 +280,7 @@ BUILT_IN_DLL(xmms_cmd)
sprintf(putbuf, "%cACTION %s%c", sprintf(putbuf, "%cACTION %s%c",
CTCP_DELIM_CHAR, message, CTCP_DELIM_CHAR, message,
CTCP_DELIM_CHAR); CTCP_DELIM_CHAR);
send_text(target, putbuf, "PRIVMSG", 0, 0); send_text(target, putbuf, STXT_QUIET);
if (do_hook(SEND_ACTION_LIST, "%s %s", target, message)) if (do_hook(SEND_ACTION_LIST, "%s %s", target, message))
{ {

View File

@@ -11,7 +11,7 @@ extern char *sent_nick;
extern char *sent_body; extern char *sent_body;
extern char *recv_nick; extern char *recv_nick;
void BX_send_text (const char *, const char *, char *, int, int); void BX_send_text (const char *, const char *, unsigned);
void eval_inputlist (char *, char *); void eval_inputlist (char *, char *);
int BX_parse_command (char *, int, char *); int BX_parse_command (char *, int, char *);
void BX_parse_line (const char *, char *, const char *, int, int, int); void BX_parse_line (const char *, char *, const char *, int, int, int);
@@ -27,7 +27,7 @@ extern char *recv_nick;
void destroy_call_stack (void); void destroy_call_stack (void);
void unwind_stack (void); void unwind_stack (void);
void wind_stack (char *); void wind_stack (char *);
void redirect_text (int, const char *, const char *, char *, int, int); void redirect_text (int, const char *, const char *, unsigned);
int command_exist (char *); int command_exist (char *);

View File

@@ -10,7 +10,7 @@
* if we change the table below, we change this module number to the * if we change the table below, we change this module number to the
* current date (YYYYMMDDxx where xx is a serial number). * current date (YYYYMMDDxx where xx is a serial number).
*/ */
#define MODULE_VERSION 2017071001UL #define MODULE_VERSION 2017071002UL
#include "struct.h" #include "struct.h"

View File

@@ -254,7 +254,7 @@ extern Function_ptr *global;
#define prepare_command (*(ChannelList *(*)(int *, char *, int))global[PREPARE_COMMAND]) #define prepare_command (*(ChannelList *(*)(int *, char *, int))global[PREPARE_COMMAND])
#define convert_output_format (*(char *(*)(const char *, const char *, ...))global[CONVERT_OUTPUT_FORMAT]) #define convert_output_format (*(char *(*)(const char *, const char *, ...))global[CONVERT_OUTPUT_FORMAT])
#define userage (*(void (*)(char *, char *))global[USERAGE]) #define userage (*(void (*)(char *, char *))global[USERAGE])
#define send_text (*(void (*)(const char *, const char *, char *, int , int ))global[SEND_TEXT]) #define send_text (*(void (*)(const char *, const char *, unsigned))global[SEND_TEXT])
/* this needs to be worked out. it's passed in the IrcVariable * to _Init */ /* this needs to be worked out. it's passed in the IrcVariable * to _Init */
#define load (*(void (*)(char *, char *, char *, char *))global[FUNC_LOAD]) #define load (*(void (*)(char *, char *, char *, char *))global[FUNC_LOAD])
#define update_clock (*(char *(*)(int ))global[UPDATE_CLOCK]) #define update_clock (*(char *(*)(int ))global[UPDATE_CLOCK])

View File

@@ -843,6 +843,8 @@ char *tmp = NULL;
/* display the offerlist to current channel */ /* display the offerlist to current channel */
int l_plist(char *args, char *rest) int l_plist(char *args, char *rest)
{ {
const unsigned stxt_flags = (do_notice_list ? STXT_NOTICE : 0) | (do_cdcc_echo ? 0 : STXT_QUIET);
const char * const type_msg = do_notice_list ? "NOTICE" : "PRIVMSG";
pack *ptr; pack *ptr;
char *chan = NULL; char *chan = NULL;
char size[20]; char size[20];
@@ -851,7 +853,6 @@ int l_plist(char *args, char *rest)
char bytes_out[30]; char bytes_out[30];
char bytes_in[30]; char bytes_in[30];
char speed_out[30]; char speed_out[30];
char *type_msg;
int maxdccs, blocksize, maxqueue; int maxdccs, blocksize, maxqueue;
if (!get_current_channel_by_refnum(0) || !cdcc_numpacks || (args && *args && !is_channel(args))) { if (!get_current_channel_by_refnum(0) || !cdcc_numpacks || (args && *args && !is_channel(args))) {
@@ -860,7 +861,6 @@ int l_plist(char *args, char *rest)
"have no packs offered!"); "have no packs offered!");
return 0; return 0;
} }
type_msg = (do_notice_list)? "NOTICE":"PRIVMSG";
if (args && *args) if (args && *args)
chan = LOCAL_COPY(args); chan = LOCAL_COPY(args);
@@ -888,14 +888,14 @@ int l_plist(char *args, char *rest)
if (get_int_var(QUEUE_SENDS_VAR)) if (get_int_var(QUEUE_SENDS_VAR))
{ {
queue_send_to_server(from_server, "%s %s :%s", queue_send_to_server(from_server, "%s %s :%s",
do_notice_list?"NOTICE":"PRIVMSG", chan, msg1); type_msg, chan, msg1);
queue_send_to_server(from_server, "%s %s :%s", queue_send_to_server(from_server, "%s %s :%s",
do_notice_list?"NOTICE":"PRIVMSG", chan, msg2); type_msg, chan, msg2);
} }
else else
{ {
send_text(chan, msg1, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0); send_text(chan, msg1, stxt_flags);
send_text(chan, msg2, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0); send_text(chan, msg2, stxt_flags);
} }
new_free(&msg1); new_free(&msg1);
new_free(&msg2); new_free(&msg2);
@@ -917,11 +917,11 @@ int l_plist(char *args, char *rest)
if (get_int_var(QUEUE_SENDS_VAR)) if (get_int_var(QUEUE_SENDS_VAR))
{ {
queue_send_to_server(from_server, "%s %s :%s", queue_send_to_server(from_server, "%s %s :%s",
do_notice_list?"NOTICE":"PRIVMSG", chan, msg); type_msg, chan, msg);
} }
else else
{ {
send_text(chan, msg, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0); send_text(chan, msg, stxt_flags);
} }
new_free(&msg); new_free(&msg);
} }
@@ -930,9 +930,9 @@ int l_plist(char *args, char *rest)
char *msg = m_sprintf("\t%s", ptr->notes); char *msg = m_sprintf("\t%s", ptr->notes);
if (get_int_var(QUEUE_SENDS_VAR)) if (get_int_var(QUEUE_SENDS_VAR))
queue_send_to_server(from_server, "%s %s :%s", queue_send_to_server(from_server, "%s %s :%s",
do_notice_list?"NOTICE":"PRIVMSG", chan, msg); type_msg, chan, msg);
else else
send_text(chan, msg, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0); send_text(chan, msg, stxt_flags);
new_free(&msg); new_free(&msg);
} }
} }
@@ -981,7 +981,7 @@ static int l_notice(char *args, char *rest)
if (get_int_var(QUEUE_SENDS_VAR)) if (get_int_var(QUEUE_SENDS_VAR))
queue_send_to_server(from_server, "NOTICE %s :%s", chan, msg); queue_send_to_server(from_server, "NOTICE %s :%s", chan, msg);
else else
send_text(chan, msg, "NOTICE", do_cdcc_echo, 0); send_text(chan, msg, STXT_NOTICE | (do_cdcc_echo ? 0 : STXT_QUIET));
new_free(&msg); new_free(&msg);
} }

View File

@@ -3313,8 +3313,11 @@ BUILT_IN_COMMAND(e_wall)
*/ */
BUILT_IN_COMMAND(e_privmsg) BUILT_IN_COMMAND(e_privmsg)
{ {
char *nick; unsigned stxt_flags = (window_display ? 0 : STXT_QUIET) | STXT_LOG;
char *nick;
if (command && !strcmp(command, "NOTICE"))
stxt_flags |= STXT_NOTICE;
if ((nick = next_arg(args, &args)) != NULL) if ((nick = next_arg(args, &args)) != NULL)
{ {
@@ -3336,7 +3339,7 @@ BUILT_IN_COMMAND(e_privmsg)
} }
else if (!strcmp(nick, "*") && (!(nick = get_current_channel_by_refnum(0)))) else if (!strcmp(nick, "*") && (!(nick = get_current_channel_by_refnum(0))))
nick = zero; nick = zero;
send_text(nick, args, command, window_display, 1); send_text(nick, args, stxt_flags);
} }
} }
@@ -3732,7 +3735,7 @@ int command_exist (char *command)
return 0; return 0;
} }
void redirect_text (int to_server, const char *nick_list, const char *text, char *command, int hook, int log) void redirect_text(int to_server, const char *nick_list, const char *text, unsigned flags)
{ {
static int recursion = 0; static int recursion = 0;
int old_from_server = from_server; int old_from_server = from_server;
@@ -3746,7 +3749,7 @@ static int recursion = 0;
* Dont hook /ON REDIRECT if we're being called recursively * Dont hook /ON REDIRECT if we're being called recursively
*/ */
if (allow) if (allow)
send_text(nick_list, text, command, hook, log); send_text(nick_list, text, flags);
recursion--; recursion--;
from_server = old_from_server; from_server = old_from_server;
@@ -3868,10 +3871,9 @@ int current_target = 0;
* end up in one of the above mentioned buckets get sent out all * end up in one of the above mentioned buckets get sent out all
* at once. * at once.
*/ */
void BX_send_text(const char *nick_list, const char *text, char *command, int hook, int log) void BX_send_text(const char *nick_list, const char *text, unsigned flags)
{ {
static int sent_text_recursion = 0; static int sent_text_recursion = 0;
unsigned flags = (hook ? 0 : STXT_QUIET) | (log ? STXT_LOG : 0);
int i, int i,
done_forward = 0, done_forward = 0,
@@ -3907,9 +3909,6 @@ void BX_send_text(const char *nick_list, const char *text, char *command, int h
window_display = !(flags & STXT_QUIET); window_display = !(flags & STXT_QUIET);
if (command && !strcmp(command, "NOTICE"))
flags |= STXT_NOTICE;
free_nick = next_nick = m_strdup(nick_list); free_nick = next_nick = m_strdup(nick_list);
while ((current_nick = next_nick)) while ((current_nick = next_nick))
@@ -4071,9 +4070,9 @@ BUILT_IN_COMMAND(do_send_text)
else else
#endif #endif
if (!my_stricmp(cmd, "SAY") || !my_stricmp(cmd, "PRIVMSG") || !my_stricmp(cmd, "MSG")) if (!my_stricmp(cmd, "SAY") || !my_stricmp(cmd, "PRIVMSG") || !my_stricmp(cmd, "MSG"))
send_text(tmp, text, NULL, 1, 1); send_text(tmp, text, STXT_LOG);
else if (!my_stricmp(cmd, "NOTICE")) else if (!my_stricmp(cmd, "NOTICE"))
send_text(tmp, text, "NOTICE", 1, 1); send_text(tmp, text, STXT_NOTICE | STXT_LOG);
else if (!my_strnicmp(cmd, "WALLO", 5)) else if (!my_strnicmp(cmd, "WALLO", 5))
e_wall("WALLOPS", text, NULL, NULL); e_wall("WALLOPS", text, NULL, NULL);
else if (!my_strnicmp(cmd, "SWALLO", 6)) else if (!my_strnicmp(cmd, "SWALLO", 6))
@@ -4087,10 +4086,10 @@ BUILT_IN_COMMAND(do_send_text)
cmsg(NULL, text, NULL, NULL); cmsg(NULL, text, NULL, NULL);
#endif #endif
else else
send_text(tmp, text, NULL, 1, 1); send_text(tmp, text, STXT_LOG);
} }
else else
send_text(tmp, text, NULL, 1, 1); send_text(tmp, text, STXT_LOG);
} }
BUILT_IN_COMMAND(do_msay) BUILT_IN_COMMAND(do_msay)
@@ -4110,7 +4109,7 @@ BUILT_IN_COMMAND(do_msay)
} }
from_server = i; from_server = i;
if (channels) if (channels)
send_text(channels, args, NULL, 1, 1); send_text(channels, args, STXT_LOG);
new_free(&channels); new_free(&channels);
from_server = old_from_server; from_server = old_from_server;
} else } else

View File

@@ -933,7 +933,7 @@ BUILT_IN_COMMAND(show_version)
nick = next_arg(args, &args); nick = next_arg(args, &args);
else else
nick = get_current_channel_by_refnum(0); nick = get_current_channel_by_refnum(0);
send_text(nick, version_buf, "PRIVMSG", 1, 0); send_text(nick, version_buf, 0);
new_free(&version_buf); new_free(&version_buf);
} }
@@ -1979,7 +1979,7 @@ BUILT_IN_COMMAND(pastecmd)
if (start_pos && start_pos->line) if (start_pos && start_pos->line)
{ {
if (do_hook(PASTE_LIST, "%s %s", channel, start_pos->line)) if (do_hook(PASTE_LIST, "%s %s", channel, start_pos->line))
send_text(channel, convert_output_format(fget_string_var(FORMAT_PASTE_FSET),"%s %d %s", channel, line, start_pos->line), NULL, 1, 0); send_text(channel, convert_output_format(fget_string_var(FORMAT_PASTE_FSET),"%s %d %s", channel, line, start_pos->line), 0);
start_pos = start_pos->next; start_pos = start_pos->next;
} }
count--; count--;

View File

@@ -1584,7 +1584,7 @@ extern void send_ctcp (int type, char *to, int datatag, char *format, ...)
putbuf2[len - 2] = CTCP_DELIM_CHAR; putbuf2[len - 2] = CTCP_DELIM_CHAR;
putbuf2[len - 1] = 0; putbuf2[len - 1] = 0;
send_text(to, putbuf2, ctcp_type[type], 0, 0); send_text(to, putbuf2, (type == CTCP_NOTICE ? STXT_NOTICE : 0) | STXT_QUIET);
} }

View File

@@ -860,7 +860,7 @@ static void handle_filedesc (Process *proc, int *fd, int hook_nonl, int hook_nl
if (proc->redirect) if (proc->redirect)
redirect_text(proc->server, proc->who, redirect_text(proc->server, proc->who,
exec_buffer, proc->redirect, 1, 0); exec_buffer, !strcmp(proc->redirect, "NOTICE") ? STXT_NOTICE : 0);
if (hook_nl == EXEC_LIST && proc->stdoutc) if (hook_nl == EXEC_LIST && proc->stdoutc)
parse_line("EXEC", proc->stdoutc, exec_buffer, 0, 0, 1); parse_line("EXEC", proc->stdoutc, exec_buffer, 0, 0, 1);

View File

@@ -2832,13 +2832,13 @@ void gtk_main_paste (int refnum)
{ {
if(*current_window->query_nick && bit && *bit) if(*current_window->query_nick && bit && *bit)
if (do_hook(PASTE_LIST, "%s %s", current_window->query_nick, bit)) if (do_hook(PASTE_LIST, "%s %s", current_window->query_nick, bit))
send_text(current_window->query_nick, bit, NULL, 1, 0); send_text(current_window->query_nick, bit, 0);
} }
else else
{ {
if(channel && *channel && bit && *bit) if(channel && *channel && bit && *bit)
if (do_hook(PASTE_LIST, "%s %s", channel, bit)) if (do_hook(PASTE_LIST, "%s %s", channel, bit))
send_text(channel, bit, NULL, 1, 0); send_text(channel, bit, 0);
} }
} else } else
{ {
@@ -2905,13 +2905,13 @@ void gtk_main_paste (int refnum)
{ {
if(*current_window->query_nick && *smart) if(*current_window->query_nick && *smart)
if (do_hook(PASTE_LIST, "%s %s", current_window->query_nick, smart)) if (do_hook(PASTE_LIST, "%s %s", current_window->query_nick, smart))
send_text(current_window->query_nick, smart, NULL, 1, 0); send_text(current_window->query_nick, smart, 0);
} }
else else
{ {
if(channel && *channel && *smart) if(channel && *channel && *smart)
if (do_hook(PASTE_LIST, "%s %s", channel, smart)) if (do_hook(PASTE_LIST, "%s %s", channel, smart))
send_text(channel, smart, NULL, 1, 0); send_text(channel, smart, 0);
} }
} }
else else

View File

@@ -3248,12 +3248,12 @@ void gui_paste(char *args)
if(current_window->query_nick) if(current_window->query_nick)
{ {
if (do_hook(PASTE_LIST, "%s %s", current_window->query_nick, bit)) if (do_hook(PASTE_LIST, "%s %s", current_window->query_nick, bit))
send_text(current_window->query_nick, bit, NULL, 1, 0); send_text(current_window->query_nick, bit, 0);
} }
else else
{ {
if (do_hook(PASTE_LIST, "%s %s", channel, bit)) if (do_hook(PASTE_LIST, "%s %s", channel, bit))
send_text(channel, bit, NULL, 1, 0); send_text(channel, bit, 0);
} }
} else } else
{ {
@@ -3316,12 +3316,12 @@ void gui_paste(char *args)
if(current_window->query_nick) if(current_window->query_nick)
{ {
if (do_hook(PASTE_LIST, "%s %s", current_window->query_nick, smart)) if (do_hook(PASTE_LIST, "%s %s", current_window->query_nick, smart))
send_text(current_window->query_nick, smart, NULL, 1, 0); send_text(current_window->query_nick, smart, 0);
} }
else else
{ {
if (do_hook(PASTE_LIST, "%s %s", channel, smart)) if (do_hook(PASTE_LIST, "%s %s", channel, smart))
send_text(channel, smart, NULL, 1, 0); send_text(channel, smart, 0);
} }
} }
else else

View File

@@ -206,8 +206,8 @@ void BX_add_to_window(Window *window, const char *str)
if (window->server >= 0 && get_server_redirect(window->server)) if (window->server >= 0 && get_server_redirect(window->server))
redirect_text(window->server, redirect_text(window->server,
get_server_redirect(window->server), get_server_redirect(window->server), str, STXT_QUIET);
str, NULL, 0, 0);
if (do_hook(WINDOW_LIST, "%u %s", window->refnum, str)) if (do_hook(WINDOW_LIST, "%u %s", window->refnum, str))
{ {
char **lines; char **lines;

View File

@@ -421,7 +421,7 @@ int i;
} }
for (i = 2; i < argc; i++) for (i = 2; i < argc; i++)
m_s3cat(&buffer, space, argv[i]); m_s3cat(&buffer, space, argv[i]);
send_text(argv[1], buffer, !strcmp(argv[0], "notice")?"NOTICE":"PRIVMSG", 1, 1); send_text(argv[1], buffer, (!strcmp(argv[0], "notice") ? STXT_NOTICE : 0) | STXT_LOG);
new_free(&buffer); new_free(&buffer);
return TCL_OK; return TCL_OK;
} }
@@ -438,7 +438,7 @@ int i;
} }
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
m_s3cat(&buffer, space, argv[i]); m_s3cat(&buffer, space, argv[i]);
send_text(get_current_channel_by_refnum(0), buffer, "PRIVMSG", 1, 1); send_text(get_current_channel_by_refnum(0), buffer, STXT_LOG);
new_free(&buffer); new_free(&buffer);
return TCL_OK; return TCL_OK;
} }