Imported Upstream version 0.0.6
[ptask-pkg-ubuntu.git] / src / tw.c
index 8c68592..5ec2bc4 100644 (file)
--- a/src/tw.c
+++ b/src/tw.c
@@ -26,7 +26,6 @@
 
 #include <json.h>
 
-#include <list.h>
 #include <log.h>
 #include "note.h"
 #include <pstr.h>
@@ -154,6 +153,9 @@ static struct json_object *task_exec_json(const char *opts)
 
        free(cmd);
 
+       if (o && is_error(o))
+               return NULL;
+
        return o;
 }
 
@@ -382,7 +384,7 @@ void tw_add(const char *newdesc, const char *prj, const char *prio)
        log_fct_exit();
 }
 
-void tw_done(const char *uuid)
+void tw_task_done(const char *uuid)
 {
        char *opts;
 
@@ -397,6 +399,36 @@ void tw_done(const char *uuid)
        free(opts);
 }
 
+void tw_task_start(const char *uuid)
+{
+       char *opts;
+
+       opts = malloc(1
+                     + strlen(uuid)
+                     + strlen(" start")
+                     + 1);
+       sprintf(opts, " %s start", uuid);
+
+       tw_exec(opts);
+
+       free(opts);
+}
+
+void tw_task_stop(const char *uuid)
+{
+       char *opts;
+
+       opts = malloc(1
+                     + strlen(uuid)
+                     + strlen(" stop")
+                     + 1);
+       sprintf(opts, " %s stop", uuid);
+
+       tw_exec(opts);
+
+       free(opts);
+}
+
 void tw_task_remove(const char *uuid)
 {
        char *opts;
@@ -489,6 +521,41 @@ static struct project *project_new(const char *name, int count)
        return prj;
 }
 
+static int projects_length(struct project **list)
+{
+       int n;
+
+       if (!list)
+               return 0;
+
+       n = 0;
+       while (*list) {
+               n++;
+               list++;
+       }
+
+       return n;
+}
+
+static struct project **projects_add(struct project **list, void *item)
+{
+       int n;
+       struct project **result;
+
+       n = projects_length(list);
+
+       result = (struct project **)malloc
+               ((n + 1 + 1) * sizeof(struct project *));
+
+       if (list)
+               memcpy(result, list, n * sizeof(struct project *));
+
+       result[n] = item;
+       result[n + 1] = NULL;
+
+       return result;
+}
+
 struct project **tw_get_projects(struct task **tasks)
 {
        struct task **t_cur;
@@ -509,7 +576,7 @@ struct project **tw_get_projects(struct task **tasks)
                } else {
                        prj = project_new(prj_name, 1);
 
-                       tmp = (struct project **)list_add((void **)prjs, prj);
+                       tmp = projects_add(prjs, prj);
 
                        free(prjs);
                        prjs = tmp;