* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <time.h>
-#include <json/json.h>
+#include <json.h>
-#include <list.h>
#include <log.h>
#include "note.h"
#include <pstr.h>
#include "tw.h"
+struct tm *parse_time(const char *t)
+{
+ struct tm *tm;
+
+ tm = malloc(sizeof(struct tm));
+ memset(tm, 0, sizeof(struct tm));
+ strptime(t, "%Y%m%dT%H%M%S%Z", tm);
+
+ return tm;
+}
+
static char *task_exec(char *opts)
{
FILE *f;
log_debug("task version: %s", ver);
- if (!strcmp(ver, "2.2.0") || !strcmp(ver, "2.0.0"))
+ if (!strcmp(ver, "2.2.0")
+ || !strcmp(ver, "2.0.0")
+ || !strcmp(ver, "2.3.0"))
return 1;
else
return 0;
free(cmd);
+ if (o && is_error(o))
+ return NULL;
+
return o;
}
struct json_object *jtasks, *jtask, *json;
struct task **tasks;
char *opts;
+ const char *urg;
opts = malloc(strlen("export status:") + strlen(status) + 1);
json = json_object_object_get(jtask, "uuid");
tasks[i]->uuid = strdup(json_object_get_string(json));
+ json = json_object_object_get(jtask, "urgency");
+ urg = json_object_get_string(json);
+ if (urg)
+ tasks[i]->urgency = strdup(urg);
+ else
+ tasks[i]->urgency = NULL;
+
tasks[i]->note = note_get(tasks[i]->uuid);
+
+ json = json_object_object_get(jtask, "entry");
+ tasks[i]->entry = parse_time(json_object_get_string(json));
+
+ json = json_object_object_get(jtask, "due");
+ if (json)
+ tasks[i]->due
+ = parse_time(json_object_get_string(json));
+ else
+ tasks[i]->due = NULL;
+
+ json = json_object_object_get(jtask, "start");
+ if (json)
+ tasks[i]->start
+ = parse_time(json_object_get_string(json));
+ else
+ tasks[i]->start = NULL;
+
+ json = json_object_object_get(jtask, "recur");
+ if (json)
+ tasks[i]->recur = strdup(json_object_get_string(json));
+ else
+ tasks[i]->recur = NULL;
}
tasks[n] = NULL;
log_fct_exit();
}
-void tw_done(const char *uuid)
+void tw_task_done(const char *uuid)
{
char *opts;
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;
+
+ opts = malloc(1
+ + strlen(uuid)
+ + strlen(" delete")
+ + 1);
+ sprintf(opts, " %s delete", uuid);
+
+ tw_exec(opts);
+
+ free(opts);
+}
+
static void task_free(struct task *task)
{
if (!task)
free(task->note);
free(task->project);
free(task->priority);
+ free(task->urgency);
+ free(task->entry);
+ free(task->due);
+ free(task->start);
+ free(task->recur);
free(task);
}
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;
} else {
prj = project_new(prj_name, 1);
- tmp = (struct project **)list_add((void **)prjs, prj);
+ tmp = projects_add(prjs, prj);
free(prjs);
prjs = tmp;