Mercurial > pidgin.yaz
comparison libpurple/plugins/log_reader.c @ 17692:0e22098e1421
Rework the Trillian log reader code to make it easier to understand.
References #1344
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 04 Jun 2007 04:33:28 +0000 |
parents | f94251004e7d |
children | beeef78409b2 |
comparison
equal
deleted
inserted
replaced
17691:1aa324c47042 | 17692:0e22098e1421 |
---|---|
1480 * <a href=" | 1480 * <a href=" |
1481 * Then, replace the next ")" with: | 1481 * Then, replace the next ")" with: |
1482 * "> | 1482 * "> |
1483 * Then, replace the next " " (or add this if the end-of-line is reached) with: | 1483 * Then, replace the next " " (or add this if the end-of-line is reached) with: |
1484 * </a> | 1484 * </a> |
1485 * | |
1486 * As implemented, this isn't perfect, but it should cover common cases. | |
1485 */ | 1487 */ |
1486 link_temp_line = NULL; | 1488 link_temp_line = NULL; |
1487 while ((link = strstr(line, "(Link: "))) { | 1489 while ((link = strstr(line, "(Link: "))) |
1488 GString *temp; | 1490 { |
1489 | 1491 char *tmp = link; |
1490 *link = '\0'; | 1492 |
1491 temp = g_string_new(line); | 1493 link += 7; |
1492 g_string_append(temp, "<a href=\""); | 1494 if (*link) |
1493 | 1495 { |
1494 link += (sizeof("(Link: ") - 1); | 1496 char *end_paren; |
1495 if (*link) { | 1497 char *space; |
1496 while (*link && *link != ')') { | 1498 GString *temp; |
1497 g_string_append_c(temp, *link); | 1499 |
1498 link++; | 1500 if (!(end_paren = strstr(link, ")"))) |
1501 { | |
1502 /* Something is not as we expect. Bail out. */ | |
1503 break; | |
1499 } | 1504 } |
1500 if (*link) | 1505 |
1501 link++; | 1506 *tmp = '\0'; |
1502 | 1507 temp = g_string_new(line); |
1508 | |
1509 /* Start an <a> tag. */ | |
1510 g_string_append(temp, "<a href=\""); | |
1511 | |
1512 /* Append up to the ) */ | |
1513 g_string_append_len(temp, link, end_paren - link); | |
1514 | |
1515 /* Finish the <a> tag. */ | |
1503 g_string_append(temp, "\">"); | 1516 g_string_append(temp, "\">"); |
1504 while (*link && *link != ' ') { | 1517 |
1505 g_string_append_c(temp, *link); | 1518 /* The \r is a bit of a hack to keep there from being a \r in |
1506 link++; | 1519 * the link text, which may not matter. */ |
1520 if ((space = strstr(end_paren, " ")) || (space = strstr(end_paren, "\r"))) | |
1521 { | |
1522 g_string_append_len(temp, end_paren + 1, space - end_paren - 1); | |
1523 | |
1524 /* Close the <a> tag. */ | |
1525 g_string_append(temp, "</a>"); | |
1526 | |
1527 space++; | |
1528 if (*space) | |
1529 { | |
1530 g_string_append_c(temp, ' '); | |
1531 /* Keep the rest of the line. */ | |
1532 g_string_append(temp, space); | |
1533 } | |
1507 } | 1534 } |
1508 g_string_append(temp, "</a>"); | 1535 else |
1509 | 1536 { |
1510 g_string_append(temp, link); | 1537 /* There is no space before the end of the line. */ |
1511 | 1538 g_string_append(temp, end_paren + 1); |
1512 /* Free the last round's line. */ | 1539 /* Close the <a> tag. */ |
1513 if (link_temp_line) | 1540 g_string_append(temp, "</a>"); |
1514 g_free(line); | 1541 } |
1515 | 1542 |
1516 line = temp->str; | 1543 g_free(link_temp_line); |
1517 g_string_free(temp, FALSE); | 1544 line = g_string_free(temp, FALSE); |
1518 | 1545 |
1519 /* Save this memory location so we can free it later. */ | 1546 /* Save this memory location so we can free it later. */ |
1520 link_temp_line = line; | 1547 link_temp_line = line; |
1521 } | 1548 } |
1522 } | 1549 } |
1652 if (footer) | 1679 if (footer) |
1653 g_string_append(formatted, footer); | 1680 g_string_append(formatted, footer); |
1654 | 1681 |
1655 g_string_append_c(formatted, '\n'); | 1682 g_string_append_c(formatted, '\n'); |
1656 | 1683 |
1657 if (link_temp_line) | 1684 g_free(link_temp_line); |
1658 g_free(link_temp_line); | |
1659 | 1685 |
1660 c++; | 1686 c++; |
1661 line = c; | 1687 line = c; |
1662 } else | 1688 } else |
1663 c++; | 1689 c++; |