2 * Copyright (C) 2010-2012 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 char *task_exec(char *opts)
30 char *str, *tmp, *cmd, buf[1024];
32 cmd = malloc(strlen("task rc.json.array=on ") + strlen(opts) + 1);
33 strcpy(cmd, "task rc.json.array=on ");
36 printf("execute: %s\n", cmd);
47 while ((s = fread(buf, 1, 1024, f))) {
48 tmp = malloc(strlen(str) + s + (size_t)1);
49 memcpy(tmp, str, strlen(str));
50 memcpy(tmp + strlen(str), buf, s);
51 tmp[strlen(str) + s] = '\0';
59 printf("pclose fails\n");
69 #include <json/json.h>
73 static struct json_object *task_exec_json(char *opts)
75 struct json_object *o;
78 str = task_exec(opts);
81 o = json_tokener_parse(str);
89 struct task **tw_get_all_tasks(const char *status)
92 struct json_object *jtasks, *jtask, *json;
96 opts = malloc(strlen("export status:") + strlen(status) + 1);
97 sprintf(opts, "export status:%s", status);
99 jtasks = task_exec_json(opts);
105 n = json_object_array_length(jtasks);
107 tasks = malloc((n + 1) * sizeof(struct task *));
109 for (i = 0; i < n; i++) {
110 jtask = json_object_array_get_idx(jtasks, i);
112 tasks[i] = malloc(sizeof(struct task));
114 json = json_object_object_get(jtask, "id");
115 tasks[i]->id = json_object_get_int(json);
117 json = json_object_object_get(jtask, "description");
118 tasks[i]->description = strdup(json_object_get_string(json));
120 json = json_object_object_get(jtask, "status");
121 tasks[i]->status = strdup(json_object_get_string(json));
123 json = json_object_object_get(jtask, "project");
126 = strdup(json_object_get_string(json));
128 tasks[i]->project = NULL;
130 json = json_object_object_get(jtask, "uuid");
131 tasks[i]->uuid = strdup(json_object_get_string(json));
133 tasks[i]->note = NULL;
138 json_object_put(jtasks);
143 char *escape(const char *txt)
148 result = malloc(2*strlen(txt)+1);
177 void tw_modify_description(const char *uuid, const char *newdesc)
182 str = escape(newdesc);
186 + strlen(" modify :\"")
190 sprintf(opts, " %s modify \"%s\"", uuid, str);
198 void tw_modify_project(const char *uuid, const char *newproject)
203 str = escape(newproject);
207 + strlen(" modify project:\"")
211 sprintf(opts, " %s modify project:\"%s\"", uuid, str);