changeset 27825:bc9da266d25d

This is actually a stack, not a queue, so we can use a simpler data structure.
author Mark Doliner <mark@kingant.net>
date Tue, 04 Aug 2009 21:03:34 +0000
parents 5eca0f387c13
children c859855474ba
files libpurple/protocols/yahoo/util.c
diffstat 1 files changed, 24 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/util.c	Tue Aug 04 20:53:11 2009 +0000
+++ b/libpurple/protocols/yahoo/util.c	Tue Aug 04 21:03:34 2009 +0000
@@ -686,17 +686,16 @@
 	g_free(f);
 }
 
-static void yahoo_htc_queue_cleanup(GQueue *q)
+static void yahoo_htc_list_cleanup(GSList *l)
 {
-	char *tmp;
-
-	while ((tmp = g_queue_pop_tail(q)))
-		g_free(tmp);
-	g_queue_free(q);
+	while (l != NULL) {
+		g_free(l->data);
+		l = g_slist_delete_link(l, l);
+	}
 }
 
 static void _parse_font_tag(const char *src, GString *dest, int *i, int *j,
-				int len, GQueue *colors, GQueue *tags, GQueue *ftattr)
+				int len, GSList **colors, GSList **tags, GQueue *ftattr)
 {
 
 	int m, n, vstart;
@@ -794,7 +793,6 @@
 			gboolean needendtag = 0;
 			fontattr *f;
 			GString *tmp = g_string_new(NULL);
-			char *colorstr;
 
 			if (!g_queue_is_empty(ftattr)) {
 				while ((f = g_queue_pop_tail(ftattr))) {
@@ -834,10 +832,10 @@
 							needendtag = 0;
 						}
 
-						colorstr = g_queue_peek_tail(colors);
-						g_string_append(tmp, colorstr ? colorstr : "\033[#000000m");
+						g_string_append(tmp, *colors ? (*colors)->data : "\033[#000000m");
 						g_string_append_printf(dest, "\033[%sm", f->u.color);
-						g_queue_push_tail(colors, g_strdup_printf("\033[%sm", f->u.color));
+						*colors = g_slist_prepend(*colors,
+								g_strdup_printf("\033[%sm", f->u.color));
 						fontattr_free(f);
 						break;
 					}
@@ -848,10 +846,10 @@
 
 				if (needendtag) {
 					dest->str[dest->len-1] = '>';
-					g_queue_push_tail(tags, g_strdup("</font>"));
+					*tags = g_slist_prepend(*tags, g_strdup("</font>"));
 					g_string_free(tmp, TRUE);
 				} else {
-					g_queue_push_tail(tags, tmp->str);
+					*tags = g_slist_prepend(*tags, tmp->str);
 					g_string_free(tmp, FALSE);
 				}
 			}
@@ -864,7 +862,8 @@
 
 char *yahoo_html_to_codes(const char *src)
 {
-	GQueue *colors, *tags;
+	GSList *colors = NULL;
+	GSList *tags = NULL;
 	size_t src_len;
 	int i, j;
 	GString *dest;
@@ -872,8 +871,6 @@
 	GQueue *ftattr = NULL;
 	gboolean no_more_specials = FALSE;
 
-	colors = g_queue_new();
-	tags = g_queue_new();
 	src_len = strlen(src);
 	dest = g_string_sized_new(src_len);
 
@@ -973,7 +970,7 @@
 							}
 						}
 					} else { /* yay we have a font tag */
-						_parse_font_tag(src, dest, &i, &j, src_len, colors, tags, ftattr);
+						_parse_font_tag(src, dest, &i, &j, src_len, &colors, &tags, ftattr);
 					}
 
 					break;
@@ -1007,16 +1004,18 @@
 							/* mmm, </body> tags. *BURP* */
 						} else if (!g_ascii_strncasecmp(&src[i+1], "/SPAN", sublen)) {
 							/* </span> tags. dangerously close to </spam> */
-						} else if (!g_ascii_strncasecmp(&src[i+1], "/FONT", sublen) && g_queue_peek_tail(tags)) {
-							char *etag, *cl;
+						} else if (!g_ascii_strncasecmp(&src[i+1], "/FONT", sublen) && tags != NULL) {
+							char *etag;
 
-							etag = g_queue_pop_tail(tags);
+							etag = tags->data;
+							tags = g_slist_delete_link(tags, tags);
 							if (etag) {
 								g_string_append(dest, etag);
 								if (!strcmp(etag, "</font>")) {
-									cl = g_queue_pop_tail(colors);
-									if (cl)
-										g_free(cl);
+									if (colors != NULL) {
+										g_free(colors->data);
+										colors = g_slist_delete_link(colors, colors);
+									}
 								}
 								g_free(etag);
 							}
@@ -1059,8 +1058,8 @@
 	purple_debug_misc("yahoo", "yahoo_html_to_codes:  Returning string: '%s'.\n", esc);
 	g_free(esc);
 
-	yahoo_htc_queue_cleanup(colors);
-	yahoo_htc_queue_cleanup(tags);
+	yahoo_htc_list_cleanup(colors);
+	yahoo_htc_list_cleanup(tags);
 
 	return g_string_free(dest, FALSE);
 }