degesch: fix logging

This commit is contained in:
Přemysl Eric Janouch 2015-04-19 23:05:49 +02:00
parent 158f188646
commit d01618ceb7
1 changed files with 30 additions and 8 deletions

View File

@ -551,6 +551,8 @@ app_context_free (struct app_context *self)
} }
static void refresh_prompt (struct app_context *ctx); static void refresh_prompt (struct app_context *ctx);
static char *irc_cut_nickname (const char *prefix);
static const char *irc_find_userhost (const char *prefix);
// --- Attributed output ------------------------------------------------------- // --- Attributed output -------------------------------------------------------
@ -884,27 +886,37 @@ buffer_line_display (struct app_context *ctx, struct buffer_line *line)
// and formatting into. We could have a varargs function to make it a bit // and formatting into. We could have a varargs function to make it a bit
// more friendly, e.g. push(&x, ATTR_JOIN, "--> ", ATTR_RESET, who, NULL) // more friendly, e.g. push(&x, ATTR_JOIN, "--> ", ATTR_RESET, who, NULL)
char *nick = NULL;
const char *userhost = NULL;
if (who)
{
nick = irc_cut_nickname (who);
userhost = irc_find_userhost (who);
}
switch (line->type) switch (line->type)
{ {
case BUFFER_LINE_PRIVMSG: case BUFFER_LINE_PRIVMSG:
str_append_printf (&text, "<%s> %s", who, object); str_append_printf (&text, "<%s> %s", nick, object);
break; break;
case BUFFER_LINE_ACTION: case BUFFER_LINE_ACTION:
str_append_printf (&text, " * %s %s", who, object); str_append_printf (&text, " * %s %s", nick, object);
break; break;
case BUFFER_LINE_NOTICE: case BUFFER_LINE_NOTICE:
str_append_printf (&text, " - Notice(%s): %s", who, object); str_append_printf (&text, " - Notice(%s): %s", nick, object);
break; break;
case BUFFER_LINE_JOIN: case BUFFER_LINE_JOIN:
if (who) if (who)
str_append_printf (&text, "--> %s has joined %s", who, object); str_append_printf (&text, "--> %s (%s) has joined %s",
nick, userhost, object);
else else
str_append_printf (&text, "--> You have joined %s", object); str_append_printf (&text, "--> You have joined %s", object);
break; break;
case BUFFER_LINE_PART: case BUFFER_LINE_PART:
if (who) if (who)
str_append_printf (&text, "<-- %s has left %s (%s)", str_append_printf (&text, "<-- %s (%s) has left %s (%s)",
who, object, reason); nick, userhost, object, reason);
else else
str_append_printf (&text, "<-- You have left %s (%s)", str_append_printf (&text, "<-- You have left %s (%s)",
object, reason); object, reason);
@ -912,14 +924,15 @@ buffer_line_display (struct app_context *ctx, struct buffer_line *line)
case BUFFER_LINE_KICK: case BUFFER_LINE_KICK:
if (who) if (who)
str_append_printf (&text, "<-- %s has kicked %s (%s)", str_append_printf (&text, "<-- %s has kicked %s (%s)",
who, object, reason); nick, object, reason);
else else
str_append_printf (&text, "<-- You have kicked %s (%s)", str_append_printf (&text, "<-- You have kicked %s (%s)",
object, reason); object, reason);
break; break;
case BUFFER_LINE_QUIT: case BUFFER_LINE_QUIT:
if (who) if (who)
str_append_printf (&text, "<-- %s has quit (%s)", who, reason); str_append_printf (&text, "<-- %s (%s) has quit (%s)",
nick, userhost, reason);
else else
str_append_printf (&text, "<-- You have quit (%s)", reason); str_append_printf (&text, "<-- You have quit (%s)", reason);
break; break;
@ -930,6 +943,8 @@ buffer_line_display (struct app_context *ctx, struct buffer_line *line)
str_append_printf (&text, "=!= %s", object); str_append_printf (&text, "=!= %s", object);
} }
free (nick);
free (who); free (who);
free (object); free (object);
free (reason); free (reason);
@ -1212,6 +1227,13 @@ irc_cut_nickname (const char *prefix)
return xstrndup (prefix, strcspn (prefix, "!@")); return xstrndup (prefix, strcspn (prefix, "!@"));
} }
static const char *
irc_find_userhost (const char *prefix)
{
const char *p = strchr (prefix, '!');
return p ? p + 1 : NULL;
}
static bool static bool
irc_is_this_us (struct app_context *ctx, const char *prefix) irc_is_this_us (struct app_context *ctx, const char *prefix)
{ {