* 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 <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;
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;
}
tasks[n] = NULL;
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);
}