#include <pstr.h>
#include "tw.h"
-
-static int has_taskrc()
-{
- char *home, *path;
- int ret;
- struct stat st;
-
- home = getenv("HOME");
-
- if (!home) {
- log_err("HOME environment variable not defined");
- return 0;
- }
-
- path = malloc(strlen(home) + 1 + strlen(".taskrc") + 1);
- sprintf(path, "%s/%s", home, ".taskrc");
-
- ret = lstat(path, &st);
-
- free(path);
-
- return ret == 0;
-}
-
static char *task_exec(char *opts)
{
FILE *f;
log_debug("task version: %s", ver);
- if (!strcmp(ver, "2.2.0"))
+ if (!strcmp(ver, "2.2.0") || !strcmp(ver, "2.0.0"))
return 1;
else
return 0;
static char *tw_exec(char *opts)
{
- if (!has_taskrc())
- return NULL;
+ char *opts2;
if (!task_check_version()) {
log_err("ptask is not compatible with the installed version of"
return NULL;
}
- return task_exec(opts);
+ opts2 = malloc(strlen("rc.confirmation:no ")
+ + strlen(opts)
+ + 1);
+ strcpy(opts2, "rc.confirmation:no ");
+ strcat(opts2, opts);
+
+ return task_exec(opts2);
}
-static struct json_object *task_exec_json(char *opts)
+static struct json_object *task_exec_json(const char *opts)
{
struct json_object *o;
char *str, *cmd;
char *opts;
opts = malloc(strlen("export status:") + strlen(status) + 1);
- sprintf(opts, "export status:%s", status);
+
+ strcpy(opts, "export status:");
+ strcat(opts, status);
jtasks = task_exec_json(opts);
free(opts);
while (*txt) {
switch (*txt) {
case '"':
- *c = '\\'; c++;
- *c = '"';
- break;
case '$':
- *c = '\\'; c++;
- *c = '$';
- break;
case '&':
+ case '<':
+ case '>':
*c = '\\'; c++;
- *c = '&';
+ *c = *txt;
break;
default:
*c = *txt;
free(opts);
}
-void tw_add(const char *newdesc)
+void tw_add(const char *newdesc, const char *prj, const char *prio)
{
- char *str;
- char *opts;
-
- str = escape(newdesc);
-
- opts = malloc(1
- + strlen(" add \"")
- + strlen(str)
+ char *opts, *eprj;
+
+ eprj = escape(prj);
+
+ opts = malloc(strlen(" add")
+ + strlen(" priority:")
+ + 1
+ + strlen(" project:\\\"")
+ + strlen(eprj)
+ + strlen("\\\"")
+ + strlen(" \"")
+ + strlen(newdesc)
+ strlen("\"")
+ 1);
- sprintf(opts, " add \"%s\"", str);
+
+ strcpy(opts, " add");
+
+ if (prio && strlen(prio) == 1) {
+ strcat(opts, " priority:");
+ strcat(opts, prio);
+ }
+
+ if (eprj && strlen(prj)) {
+ strcat(opts, " project:\\\"");
+ strcat(opts, eprj);
+ strcat(opts, "\\\"");
+ }
+
+ strcat(opts, " \"");
+ strcat(opts, newdesc);
+ strcat(opts, " \"");
tw_exec(opts);
- free(str);
free(opts);
+ free(eprj);
}
void tw_done(const char *uuid)