escape can be static
[ptask.git] / src / tw.c
index 1e9a23c..890449f 100644 (file)
--- a/src/tw.c
+++ b/src/tw.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2012 jeanfi@gmail.com
+ * Copyright (C) 2012-2013 jeanfi@gmail.com
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
 #include <stdlib.h>
 #include <string.h>
 
+#include <json/json.h>
+
+#include "note.h"
+#include "tw.h"
 
-char *task_exec(char *opts)
+static char *task_exec(char *opts)
 {
        FILE *f;
        int ret;
@@ -66,10 +70,6 @@ char *task_exec(char *opts)
        return str;
 }
 
-#include <json/json.h>
-
-#include "tw.h"
-
 static struct json_object *task_exec_json(char *opts)
 {
        struct json_object *o;
@@ -137,7 +137,7 @@ struct task **tw_get_all_tasks(const char *status)
                json = json_object_object_get(jtask, "uuid");
                tasks[i]->uuid = strdup(json_object_get_string(json));
 
-               tasks[i]->note = NULL;
+               tasks[i]->note = note_get(tasks[i]->uuid);
        }
 
        tasks[n] = NULL;
@@ -147,7 +147,7 @@ struct task **tw_get_all_tasks(const char *status)
        return tasks;
 }
 
-char *escape(const char *txt)
+static char *escape(const char *txt)
 {
        char *result;
        char *c;
@@ -278,3 +278,31 @@ void tw_done(const char *uuid)
 
        free(opts);
 }
+
+static void task_free(struct task *task)
+{
+       if (!task)
+               return ;
+
+       free(task->description);
+       free(task->status);
+       free(task->uuid);
+       free(task->note);
+       free(task->project);
+       free(task->priority);
+
+       free(task);
+}
+
+void tw_task_list_free(struct task **tasks)
+{
+       struct task **cur;
+
+       if (!tasks)
+               return ;
+
+       for (cur = tasks; *cur; cur++)
+               task_free(*cur);
+
+       free(tasks);
+}