Change the formatting of --action output
[gregoa/bti.git] / bti.c
diff --git a/bti.c b/bti.c
index 2a94236881e612da136ec5f320d9ce59b63d2c94..abf436c8a149627126ef37fa712b6ab1bba80364 100644 (file)
--- a/bti.c
+++ b/bti.c
@@ -175,31 +175,34 @@ static CURL *curl_init(void)
 
 void parse_statuses(xmlDocPtr doc, xmlNodePtr current)
 {
-       xmlChar *text;
-       xmlChar *user;
+       xmlChar *text = NULL;
+       xmlChar *user = NULL;
        xmlNodePtr userinfo;
+
        current = current->xmlChildrenNode;
        while (current != NULL) {
                if (current->type == XML_ELEMENT_NODE) {
-                       if (!xmlStrcmp(current->name, (const xmlChar *)"text")) {
+                       if (!xmlStrcmp(current->name, (const xmlChar *)"text"))
                                text = xmlNodeListGetString(doc, current->xmlChildrenNode, 1);
-                               printf("%s", text);
-                               xmlFree(text);
-                       }
                        if (!xmlStrcmp(current->name, (const xmlChar *)"user")) {
                                userinfo = current->xmlChildrenNode;
                                while (userinfo != NULL) {
                                        if ((!xmlStrcmp(userinfo->name, (const xmlChar *)"screen_name"))) {
+                                               if (user)
+                                                       xmlFree(user);
                                                user = xmlNodeListGetString(doc, userinfo->xmlChildrenNode, 1);
-                                               printf(" [%s]\n", user);
-                                               xmlFree(user);
                                        }
-
                                        userinfo = userinfo->next;
                                }
                        }
+                       if (user && text) {
+                               printf("[%s] %s\n", user, text);
+                               xmlFree(user);
+                               xmlFree(text);
+                               user = NULL;
+                               text = NULL;
+                       }
                }
-
                current = current->next;
        }