# HG changeset patch # User Richard Laager # Date 1181193811 0 # Node ID beeef78409b21cffd0aa67d8006b309dcb3a9955 # Parent 89adae2f1a6e516d13198befa0445f20235435f2 A patch from o_sukhodolsky to restructure the Trillian log formatting code to avoid warnings. diff -r 89adae2f1a6e -r beeef78409b2 libpurple/plugins/log_reader.c --- a/libpurple/plugins/log_reader.c Thu Jun 07 02:28:34 2007 +0000 +++ b/libpurple/plugins/log_reader.c Thu Jun 07 05:23:31 2007 +0000 @@ -1425,7 +1425,7 @@ char *escaped; GString *formatted; char *c; - char *line; + const char *line; g_return_val_if_fail(log != NULL, g_strdup("")); @@ -1463,230 +1463,218 @@ formatted = g_string_new(""); c = read; line = read; - while (*c) + while (c) { - if (*c == '\n') - { - char *link_temp_line; - char *link; - char *timestamp; - char *footer = NULL; - *c = '\0'; + const char *link; + const char *footer = NULL; + GString *temp; - /* Convert links. - * - * The format is (Link: URL)URL - * So, I want to find each occurance of "(Link: " and replace that chunk with: - * - * 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: "))) - { - char *tmp = link; + c = strstr(c, "\n"); - link += 7; - if (*link) - { - char *end_paren; - char *space; - GString *temp; - - if (!(end_paren = strstr(link, ")"))) - { - /* Something is not as we expect. Bail out. */ - break; - } - - *tmp = '\0'; - temp = g_string_new(line); - - /* Start an tag. */ - g_string_append(temp, " tag. */ - 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, ""); + /* Convert links. + * + * The format is (Link: URL)URL + * So, I want to find each occurance of "(Link: " and replace that chunk with: + * + * 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. + */ + temp = g_string_sized_new(strlen(line)); + while (line && (link = strstr(line, "(Link: "))) + { + const char *tmp = 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, ""); - } - - g_free(link_temp_line); - line = g_string_free(temp, FALSE); + link += 7; + if (*link) + { + char *end_paren; + char *space; - /* Save this memory location so we can free it later. */ - link_temp_line = line; - } - } - - timestamp = ""; - if (*line == '[') { - timestamp = line; - while (*timestamp && *timestamp != ']') - timestamp++; - if (*timestamp == ']') { - *timestamp = '\0'; - line++; - /* TODO: Parse the timestamp and convert it to Purple's format. */ - g_string_append_printf(formatted, - "(%s) ", line); - line = timestamp; - if (line[1] && line[2]) - line += 2; + if (!(end_paren = strstr(link, ")"))) + { + /* Something is not as we expect. Bail out. */ + break; } - if (purple_str_has_prefix(line, "*** ")) { - line += (sizeof("*** ") - 1); - g_string_append(formatted, ""); - footer = ""; - if (purple_str_has_prefix(line, "NOTE: This user is offline.")) { - line = _("User is offline."); - } else if (purple_str_has_prefix(line, - "NOTE: Your status is currently set to ")) { + g_string_append_len(temp, line, (tmp - line)); + + /* Start an tag. */ + g_string_append(temp, " tag. */ + 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, ""); + + 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, ""); + } + line = space; + } + } + + if (line) { + g_string_append(temp, line); + } + line = temp->str; + + if (*line == '[') { + const char *timestamp; + + if ((timestamp = strstr(line, "]"))) { + line++; + /* TODO: Parse the timestamp and convert it to Purple's format. */ + g_string_append(formatted, "("); + g_string_append_len(formatted, line, (timestamp - line)); + g_string_append(formatted,") "); + line = timestamp + 1; + if (line[0] && line[1]) + line++; + } + + if (purple_str_has_prefix(line, "*** ")) { + line += (sizeof("*** ") - 1); + g_string_append(formatted, ""); + footer = ""; + if (purple_str_has_prefix(line, "NOTE: This user is offline.")) { + line = _("User is offline."); + } else if (purple_str_has_prefix(line, + "NOTE: Your status is currently set to ")) { - line += (sizeof("NOTE: ") - 1); - } else if (purple_str_has_prefix(line, "Auto-response sent to ")) { - g_string_append(formatted, _("Auto-response sent:")); - while (*line && *line != ':') - line++; - if (*line) - line++; - g_string_append(formatted, ""); - footer = NULL; - } else if (strstr(line, " signed off ")) { - if (buddy != NULL && buddy->alias) - g_string_append_printf(formatted, - _("%s has signed off."), buddy->alias); - else - g_string_append_printf(formatted, - _("%s has signed off."), log->name); - line = ""; - } else if (strstr(line, " signed on ")) { - if (buddy != NULL && buddy->alias) - g_string_append(formatted, buddy->alias); - else - g_string_append(formatted, log->name); - line = " logged in."; - } else if (purple_str_has_prefix(line, - "One or more messages may have been undeliverable.")) { + line += (sizeof("NOTE: ") - 1); + } else if (purple_str_has_prefix(line, "Auto-response sent to ")) { + g_string_append(formatted, _("Auto-response sent:")); + while (*line && *line != ':') + line++; + if (*line) + line++; + g_string_append(formatted, ""); + footer = NULL; + } else if (strstr(line, " signed off ")) { + if (buddy != NULL && buddy->alias) + g_string_append_printf(formatted, + _("%s has signed off."), buddy->alias); + else + g_string_append_printf(formatted, + _("%s has signed off."), log->name); + line = ""; + } else if (strstr(line, " signed on ")) { + if (buddy != NULL && buddy->alias) + g_string_append(formatted, buddy->alias); + else + g_string_append(formatted, log->name); + line = " logged in."; + } else if (purple_str_has_prefix(line, + "One or more messages may have been undeliverable.")) { - g_string_append(formatted, - ""); - g_string_append(formatted, - _("One or more messages may have been " - "undeliverable.")); - line = ""; - footer = ""; - } else if (purple_str_has_prefix(line, - "You have been disconnected.")) { + g_string_append(formatted, + ""); + g_string_append(formatted, + _("One or more messages may have been " + "undeliverable.")); + line = ""; + footer = ""; + } else if (purple_str_has_prefix(line, + "You have been disconnected.")) { - g_string_append(formatted, - ""); - g_string_append(formatted, - _("You were disconnected from the server.")); - line = ""; - footer = ""; - } else if (purple_str_has_prefix(line, - "You are currently disconnected.")) { + g_string_append(formatted, + ""); + g_string_append(formatted, + _("You were disconnected from the server.")); + line = ""; + footer = ""; + } else if (purple_str_has_prefix(line, + "You are currently disconnected.")) { + + g_string_append(formatted, + ""); + line = _("You are currently disconnected. Messages " + "will not be received unless you are " + "logged in."); + footer = ""; + } else if (purple_str_has_prefix(line, + "Your previous message has not been sent.")) { + + g_string_append(formatted, + ""); + + if (purple_str_has_prefix(line, + "Your previous message has not been sent. " + "Reason: Maximum length exceeded.")) { g_string_append(formatted, - ""); - line = _("You are currently disconnected. Messages " - "will not be received unless you are " - "logged in."); - footer = ""; - } else if (purple_str_has_prefix(line, - "Your previous message has not been sent.")) { - + _("Message could not be sent because " + "the maximum length was exceeded.")); + line = ""; + } else { g_string_append(formatted, - ""); - - if (purple_str_has_prefix(line, - "Your previous message has not been sent. " - "Reason: Maximum length exceeded.")) { + _("Message could not be sent.")); + line += (sizeof( + "Your previous message " + "has not been sent. ") - 1); + } - g_string_append(formatted, - _("Message could not be sent because " - "the maximum length was exceeded.")); - line = ""; - } else { - g_string_append(formatted, - _("Message could not be sent.")); - line += (sizeof( - "Your previous message " - "has not been sent. ") - 1); - } + footer = ""; + } + } else if (purple_str_has_prefix(line, data->their_nickname)) { + if (buddy != NULL && buddy->alias) { + line += strlen(data->their_nickname) + 2; + g_string_append_printf(formatted, + "" + "%s: ", buddy->alias); + } + } else { + const char *line2 = strstr(line, ":"); + if (line2) { + const char *acct_name; + line2++; + line = line2; + acct_name = purple_account_get_alias(log->account); + if (!acct_name) + acct_name = purple_account_get_username(log->account); - footer = ""; - } - } else if (purple_str_has_prefix(line, data->their_nickname)) { - if (buddy != NULL && buddy->alias) { - line += strlen(data->their_nickname) + 2; - g_string_append_printf(formatted, - "" - "%s: ", buddy->alias); - } - } else { - char *line2 = line; - while (*line2 && *line2 != ':') - line2++; - if (*line2 == ':') { - const char *acct_name; - line2++; - line = line2; - acct_name = purple_account_get_alias(log->account); - if (!acct_name) - acct_name = purple_account_get_username(log->account); - - g_string_append_printf(formatted, - "" - "%s:", acct_name); - } + g_string_append_printf(formatted, + "" + "%s:", acct_name); } } - - g_string_append(formatted, line); + } - if (footer) - g_string_append(formatted, footer); + g_string_append(formatted, line); - g_string_append_c(formatted, '\n'); - - g_free(link_temp_line); + if (footer) + g_string_append(formatted, footer); - c++; - line = c; - } else - c++; + g_string_append_c(formatted, '\n'); + + g_string_free(temp, TRUE); + + line = c; } g_free(read);