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, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "module.h"
#include "printtext.h"
#define ishighalnum(c) ((unsigned char) (c) >= 128 || i_isalnum(c))
+#define isnickchar(a) \
+ (i_isalnum(a) || (a) == '`' || (a) == '-' || (a) == '_' || \
+ (a) == '[' || (a) == ']' || (a) == '{' || (a) == '}' || \
+ (a) == '|' || (a) == '\\' || (a) == '^')
-static GHashTable *printnicks;
+GHashTable *printnicks;
/* convert _underlined_ and *bold* words (and phrases) to use real
underlining or bolding */
/* check that the beginning marker starts a word, and
that the matching end marker ends a word */
- if ((pos > 0 && !i_isspace(bgn[-1])) || !ishighalnum(bgn[1]))
+ if ((pos > 0 && bgn[-1] != ' ') || !ishighalnum(bgn[1]))
continue;
if ((end = strchr(bgn+1, *bgn)) == NULL)
continue;
use emphasis on them. */
int found;
char c;
+ char *end2;
+ /* check if _foo_ is a nick */
c = end[1];
end[1] = '\0';
found = nicklist_find(CHANNEL(item), bgn) != NULL;
end[1] = c;
if (found) continue;
+
+ /* check if the whole 'word' (e.g. "_foo_^") is a nick
+ in "_foo_^ ", end will be the second _, end2 the ^ */
+ end2 = end;
+ while (isnickchar(end2[1]))
+ end2++;
+ c = end2[1];
+ end2[1] = '\0';
+ found = nicklist_find(CHANNEL(item), bgn) != NULL;
+ end2[1] = c;
+ if (found) continue;
}
/* allow only *word* emphasis, not *multiple words* */
static char *channel_get_nickmode_rec(NICK_REC *nickrec)
{
char *emptystr;
+ char *nickmode;
if (!settings_get_bool("show_nickmode"))
- return "";
+ return g_strdup("");
emptystr = settings_get_bool("show_nickmode_empty") ? " " : "";
- return nickrec == NULL ? emptystr :
- nickrec->op ? "@" :
- nickrec->halfop ? "%" :
- nickrec->voice ? "+" :
- emptystr;
+ if (nickrec == NULL || nickrec->prefixes[0] == '\0')
+ nickmode = g_strdup(emptystr);
+ else {
+ nickmode = g_malloc(2);
+ nickmode[0] = nickrec->prefixes[0];
+ nickmode[1] = '\0';
+ }
+ return nickmode;
}
char *channel_get_nickmode(CHANNEL_REC *channel, const char *nick)
const char *target, NICK_REC *nickrec)
{
CHANNEL_REC *chanrec;
- const char *nickmode, *printnick;
+ const char *printnick;
int for_me, print_channel, level;
- char *color, *freemsg = NULL;
+ char *nickmode, *color, *freemsg = NULL;
+ HILIGHT_REC *hilight;
/* NOTE: this may return NULL if some channel is just closed with
/WINDOW CLOSE and server still sends the few last messages */
for_me = !settings_get_bool("hilight_nick_matches") ? FALSE :
nick_match_msg(chanrec, msg, server->nick);
- color = for_me ? NULL :
+ hilight = for_me ? NULL :
hilight_match_nick(server, target, nick, address, MSGLEVEL_PUBLIC, msg);
+ color = (hilight == NULL) ? NULL : hilight_get_color(hilight);
print_channel = chanrec == NULL ||
!window_item_is_active((WI_ITEM_REC *) chanrec);
print_channel = TRUE;
level = MSGLEVEL_PUBLIC;
- if (for_me || color != NULL)
+ if (for_me)
level |= MSGLEVEL_HILIGHT;
if (settings_get_bool("emphasis"))
if (printnick == NULL)
printnick = nick;
- if (!print_channel) {
- /* message to active channel in window */
- if (color != NULL) {
- /* highlighted nick */
- printformat(server, target, level,
- TXT_PUBMSG_HILIGHT,
- color, printnick, msg, nickmode);
- } else {
+ if (color != NULL) {
+ /* highlighted nick */
+ TEXT_DEST_REC dest;
+ format_create_dest(&dest, server, target, level, NULL);
+ hilight_update_text_dest(&dest,hilight);
+ if (!print_channel) /* message to active channel in window */
+ printformat_dest(&dest, TXT_PUBMSG_HILIGHT, color,
+ printnick, msg, nickmode);
+ else /* message to not existing/active channel */
+ printformat_dest(&dest, TXT_PUBMSG_HILIGHT_CHANNEL,
+ color, printnick, target, msg,
+ nickmode);
+ } else {
+ if (!print_channel)
printformat(server, target, level,
for_me ? TXT_PUBMSG_ME : TXT_PUBMSG,
printnick, msg, nickmode);
- }
- } else {
- /* message to not existing/active channel */
- if (color != NULL) {
- /* highlighted nick */
- printformat(server, target, level,
- TXT_PUBMSG_HILIGHT_CHANNEL,
- color, printnick, target, msg, nickmode);
- } else {
+ else
printformat(server, target, level,
for_me ? TXT_PUBMSG_ME_CHANNEL :
TXT_PUBMSG_CHANNEL,
printnick, target, msg, nickmode);
- }
- }
+ }
- g_free_not_null(freemsg);
+ g_free_not_null(nickmode);
+ g_free_not_null(freemsg);
g_free_not_null(color);
}
{
WINDOW_REC *window;
CHANNEL_REC *channel;
- const char *nickmode;
+ char *nickmode;
char *freemsg = NULL;
int print_channel;
-
channel = channel_find(server, target);
if (channel != NULL)
target = channel->visible_name;
TXT_OWN_MSG_CHANNEL, server->nick, target, msg, nickmode);
}
+ g_free_not_null(nickmode);
g_free_not_null(freemsg);
}
g_return_if_fail(server != NULL);
g_return_if_fail(msg != NULL);
-
if (target == NULL) {
/* this should only happen if some special target failed and
we should display some error message. currently the special
print_channel = rec->visible_name;
if (once)
- g_string_sprintfa(chans, "%s,", rec->visible_name);
+ g_string_append_printf(chans, "%s,", rec->visible_name);
else {
window = window_item_window((WI_ITEM_REC *) rec);
if (g_slist_find(windows, window) == NULL) {
msgprint = FALSE;
- /* Print to each channel/query where the nick is.
+ /* Print to each channel where the nick is.
Don't print more than once to the same window. */
windows = NULL;
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
newnick = g_string_new(NULL);
n = 2;
do {
- g_string_sprintf(newnick, "%s%d", nickhost, n);
+ g_string_printf(newnick, "%s%d", nickhost, n);
n++;
} while (printnick_exists(firstnick, nick, newnick->str));