# HG changeset patch # User Richard Laager # Date 1180931608 0 # Node ID 0e22098e142137b7df1e1faf2b0a8db75ad9e528 # Parent 1aa324c47042bc1a0e05dab5aa7752658429c1b6 Rework the Trillian log reader code to make it easier to understand. References #1344 diff -r 1aa324c47042 -r 0e22098e1421 libpurple/plugins/log_reader.c --- a/libpurple/plugins/log_reader.c Mon Jun 04 01:41:23 2007 +0000 +++ b/libpurple/plugins/log_reader.c Mon Jun 04 04:33:28 2007 +0000 @@ -1482,39 +1482,66 @@ * "> * Then, replace the next " " (or add this if the end-of-line is reached) with: * + * + * As implemented, this isn't perfect, but it should cover common cases. */ link_temp_line = NULL; - while ((link = strstr(line, "(Link: "))) { - GString *temp; + while ((link = strstr(line, "(Link: "))) + { + char *tmp = link; - *link = '\0'; - temp = g_string_new(line); - g_string_append(temp, " tag. */ + g_string_append(temp, " tag. */ g_string_append(temp, "\">"); - while (*link && *link != ' ') { - g_string_append_c(temp, *link); - link++; - } - g_string_append(temp, ""); + + /* The \r is a bit of a hack to keep there from being a \r in + * the link text, which may not matter. */ + if ((space = strstr(end_paren, " ")) || (space = strstr(end_paren, "\r"))) + { + g_string_append_len(temp, end_paren + 1, space - end_paren - 1); + + /* Close the tag. */ + g_string_append(temp, ""); - g_string_append(temp, link); + space++; + if (*space) + { + g_string_append_c(temp, ' '); + /* Keep the rest of the line. */ + g_string_append(temp, space); + } + } + else + { + /* There is no space before the end of the line. */ + g_string_append(temp, end_paren + 1); + /* Close the tag. */ + g_string_append(temp, ""); + } - /* Free the last round's line. */ - if (link_temp_line) - g_free(line); - - line = temp->str; - g_string_free(temp, FALSE); + g_free(link_temp_line); + line = g_string_free(temp, FALSE); /* Save this memory location so we can free it later. */ link_temp_line = line; @@ -1654,8 +1681,7 @@ g_string_append_c(formatted, '\n'); - if (link_temp_line) - g_free(link_temp_line); + g_free(link_temp_line); c++; line = c;