From bb616e0626a067528031580297b790857351fd69 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Sun, 9 Jul 2017 00:08:04 +1000 Subject: [PATCH] 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. --- Changelog | 3 +++ dll/pkga/pkga.c | 4 ++-- dll/xmms/xmms.c | 2 +- include/commands.h | 4 ++-- include/module.h | 2 +- include/modval.h | 2 +- source/cdcc.c | 22 +++++++++++----------- source/commands.c | 27 +++++++++++++-------------- source/commands2.c | 4 ++-- source/ctcp.c | 2 +- source/exec.c | 2 +- source/gtkbitchx.c | 8 ++++---- source/pmbitchx.c | 8 ++++---- source/screen.c | 4 ++-- source/tcl.c | 4 ++-- 15 files changed, 50 insertions(+), 48 deletions(-) diff --git a/Changelog b/Changelog index ec982e0..674c410 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,8 @@ [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 directly). (caf) diff --git a/dll/pkga/pkga.c b/dll/pkga/pkga.c index f6f2590..83fb40a 100644 --- a/dll/pkga/pkga.c +++ b/dll/pkga/pkga.c @@ -74,7 +74,7 @@ static char *Pkga_newctcp (CtcpEntryDll *dll, char *from, char *to, char *args) { char putbuf[500]; 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; } @@ -82,7 +82,7 @@ static char *Pkga_ctcppage (CtcpEntryDll *dll, char *from, char *to, char *args) { char putbuf[500]; 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); return NULL; } diff --git a/dll/xmms/xmms.c b/dll/xmms/xmms.c index 6215a16..6fb1b31 100644 --- a/dll/xmms/xmms.c +++ b/dll/xmms/xmms.c @@ -280,7 +280,7 @@ BUILT_IN_DLL(xmms_cmd) sprintf(putbuf, "%cACTION %s%c", CTCP_DELIM_CHAR, message, 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)) { diff --git a/include/commands.h b/include/commands.h index 7ba3823..dff1c20 100644 --- a/include/commands.h +++ b/include/commands.h @@ -11,7 +11,7 @@ extern char *sent_nick; extern char *sent_body; 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 *); int BX_parse_command (char *, int, char *); 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 unwind_stack (void); 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 *); diff --git a/include/module.h b/include/module.h index 12c7217..8a7c878 100644 --- a/include/module.h +++ b/include/module.h @@ -10,7 +10,7 @@ * if we change the table below, we change this module number to the * current date (YYYYMMDDxx where xx is a serial number). */ -#define MODULE_VERSION 2017071001UL +#define MODULE_VERSION 2017071002UL #include "struct.h" diff --git a/include/modval.h b/include/modval.h index 25e43a8..6c9fc05 100644 --- a/include/modval.h +++ b/include/modval.h @@ -254,7 +254,7 @@ extern Function_ptr *global; #define prepare_command (*(ChannelList *(*)(int *, char *, int))global[PREPARE_COMMAND]) #define convert_output_format (*(char *(*)(const char *, const char *, ...))global[CONVERT_OUTPUT_FORMAT]) #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 */ #define load (*(void (*)(char *, char *, char *, char *))global[FUNC_LOAD]) #define update_clock (*(char *(*)(int ))global[UPDATE_CLOCK]) diff --git a/source/cdcc.c b/source/cdcc.c index 9261e4d..4a80da8 100644 --- a/source/cdcc.c +++ b/source/cdcc.c @@ -843,6 +843,8 @@ char *tmp = NULL; /* display the offerlist to current channel */ 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; char *chan = NULL; char size[20]; @@ -851,7 +853,6 @@ int l_plist(char *args, char *rest) char bytes_out[30]; char bytes_in[30]; char speed_out[30]; - char *type_msg; int maxdccs, blocksize, maxqueue; 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!"); return 0; } - type_msg = (do_notice_list)? "NOTICE":"PRIVMSG"; if (args && *args) chan = LOCAL_COPY(args); @@ -888,14 +888,14 @@ int l_plist(char *args, char *rest) if (get_int_var(QUEUE_SENDS_VAR)) { 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", - do_notice_list?"NOTICE":"PRIVMSG", chan, msg2); + type_msg, chan, msg2); } else { - send_text(chan, msg1, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0); - send_text(chan, msg2, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0); + send_text(chan, msg1, stxt_flags); + send_text(chan, msg2, stxt_flags); } new_free(&msg1); new_free(&msg2); @@ -917,11 +917,11 @@ int l_plist(char *args, char *rest) if (get_int_var(QUEUE_SENDS_VAR)) { queue_send_to_server(from_server, "%s %s :%s", - do_notice_list?"NOTICE":"PRIVMSG", chan, msg); + type_msg, chan, msg); } else { - send_text(chan, msg, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0); + send_text(chan, msg, stxt_flags); } new_free(&msg); } @@ -930,9 +930,9 @@ int l_plist(char *args, char *rest) char *msg = m_sprintf("\t%s", ptr->notes); if (get_int_var(QUEUE_SENDS_VAR)) queue_send_to_server(from_server, "%s %s :%s", - do_notice_list?"NOTICE":"PRIVMSG", chan, msg); + type_msg, chan, msg); else - send_text(chan, msg, do_notice_list?"NOTICE":NULL, do_cdcc_echo, 0); + send_text(chan, msg, stxt_flags); new_free(&msg); } } @@ -981,7 +981,7 @@ static int l_notice(char *args, char *rest) if (get_int_var(QUEUE_SENDS_VAR)) queue_send_to_server(from_server, "NOTICE %s :%s", chan, msg); 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); } diff --git a/source/commands.c b/source/commands.c index 083a341..c35a074 100644 --- a/source/commands.c +++ b/source/commands.c @@ -3313,8 +3313,11 @@ BUILT_IN_COMMAND(e_wall) */ 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) { @@ -3336,7 +3339,7 @@ BUILT_IN_COMMAND(e_privmsg) } else if (!strcmp(nick, "*") && (!(nick = get_current_channel_by_refnum(0)))) 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; } -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; int old_from_server = from_server; @@ -3746,7 +3749,7 @@ static int recursion = 0; * Dont hook /ON REDIRECT if we're being called recursively */ if (allow) - send_text(nick_list, text, command, hook, log); + send_text(nick_list, text, flags); recursion--; 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 * 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; - unsigned flags = (hook ? 0 : STXT_QUIET) | (log ? STXT_LOG : 0); int i, 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); - if (command && !strcmp(command, "NOTICE")) - flags |= STXT_NOTICE; - free_nick = next_nick = m_strdup(nick_list); while ((current_nick = next_nick)) @@ -4071,9 +4070,9 @@ BUILT_IN_COMMAND(do_send_text) else #endif 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")) - send_text(tmp, text, "NOTICE", 1, 1); + send_text(tmp, text, STXT_NOTICE | STXT_LOG); else if (!my_strnicmp(cmd, "WALLO", 5)) e_wall("WALLOPS", text, NULL, NULL); else if (!my_strnicmp(cmd, "SWALLO", 6)) @@ -4087,10 +4086,10 @@ BUILT_IN_COMMAND(do_send_text) cmsg(NULL, text, NULL, NULL); #endif else - send_text(tmp, text, NULL, 1, 1); + send_text(tmp, text, STXT_LOG); } else - send_text(tmp, text, NULL, 1, 1); + send_text(tmp, text, STXT_LOG); } BUILT_IN_COMMAND(do_msay) @@ -4110,7 +4109,7 @@ BUILT_IN_COMMAND(do_msay) } from_server = i; if (channels) - send_text(channels, args, NULL, 1, 1); + send_text(channels, args, STXT_LOG); new_free(&channels); from_server = old_from_server; } else diff --git a/source/commands2.c b/source/commands2.c index 580373b..dda2583 100644 --- a/source/commands2.c +++ b/source/commands2.c @@ -933,7 +933,7 @@ BUILT_IN_COMMAND(show_version) nick = next_arg(args, &args); else 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); } @@ -1979,7 +1979,7 @@ BUILT_IN_COMMAND(pastecmd) if (start_pos && 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; } count--; diff --git a/source/ctcp.c b/source/ctcp.c index 0943bf6..e55e088 100644 --- a/source/ctcp.c +++ b/source/ctcp.c @@ -1584,7 +1584,7 @@ extern void send_ctcp (int type, char *to, int datatag, char *format, ...) putbuf2[len - 2] = CTCP_DELIM_CHAR; 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); } diff --git a/source/exec.c b/source/exec.c index 37e1272..c2d6a41 100644 --- a/source/exec.c +++ b/source/exec.c @@ -860,7 +860,7 @@ static void handle_filedesc (Process *proc, int *fd, int hook_nonl, int hook_nl if (proc->redirect) 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) parse_line("EXEC", proc->stdoutc, exec_buffer, 0, 0, 1); diff --git a/source/gtkbitchx.c b/source/gtkbitchx.c index b39025f..eddd050 100644 --- a/source/gtkbitchx.c +++ b/source/gtkbitchx.c @@ -2832,13 +2832,13 @@ void gtk_main_paste (int refnum) { if(*current_window->query_nick && bit && *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 { if(channel && *channel && bit && *bit) if (do_hook(PASTE_LIST, "%s %s", channel, bit)) - send_text(channel, bit, NULL, 1, 0); + send_text(channel, bit, 0); } } else { @@ -2905,13 +2905,13 @@ void gtk_main_paste (int refnum) { if(*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 { if(channel && *channel && *smart) if (do_hook(PASTE_LIST, "%s %s", channel, smart)) - send_text(channel, smart, NULL, 1, 0); + send_text(channel, smart, 0); } } else diff --git a/source/pmbitchx.c b/source/pmbitchx.c index dc4310a..9cf5eb5 100644 --- a/source/pmbitchx.c +++ b/source/pmbitchx.c @@ -3248,12 +3248,12 @@ void gui_paste(char *args) if(current_window->query_nick) { 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 { if (do_hook(PASTE_LIST, "%s %s", channel, bit)) - send_text(channel, bit, NULL, 1, 0); + send_text(channel, bit, 0); } } else { @@ -3316,12 +3316,12 @@ void gui_paste(char *args) if(current_window->query_nick) { 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 { if (do_hook(PASTE_LIST, "%s %s", channel, smart)) - send_text(channel, smart, NULL, 1, 0); + send_text(channel, smart, 0); } } else diff --git a/source/screen.c b/source/screen.c index 3eb3c33..709b8a9 100644 --- a/source/screen.c +++ b/source/screen.c @@ -206,8 +206,8 @@ void BX_add_to_window(Window *window, const char *str) if (window->server >= 0 && get_server_redirect(window->server)) redirect_text(window->server, - get_server_redirect(window->server), - str, NULL, 0, 0); + get_server_redirect(window->server), str, STXT_QUIET); + if (do_hook(WINDOW_LIST, "%u %s", window->refnum, str)) { char **lines; diff --git a/source/tcl.c b/source/tcl.c index 7aad074..987e731 100644 --- a/source/tcl.c +++ b/source/tcl.c @@ -421,7 +421,7 @@ int i; } for (i = 2; i < argc; 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); return TCL_OK; } @@ -438,7 +438,7 @@ int i; } for (i = 1; i < argc; 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); return TCL_OK; }