void test_search() /* {{{ */ { /* test search functionality */ char *addcmdstr, *testcmdstr, *tmp; const char *proj = "test123"; const char pri = 'H'; const char *unique = "simple"; FILE *cmdout; task *this; bool pass; asprintf(&addcmdstr, "task add pro:%s pri:%c %s", proj, pri, unique); cmdout = popen(addcmdstr, "r"); pclose(cmdout); free_tasks(head); head = get_tasks(NULL); stdout = devnull; searchstring = strdup(unique); find_next_search_result(head, head); stdout = out; this = get_task_by_position(selline); pass = strcmp(this->project, proj)==0 && this->priority==pri; test_result("search", pass); if (!pass) { puts(addcmdstr); tmp = var_value_message(find_var("search_string"), 1); puts(tmp); free(tmp); puts("selected:"); printf("uuid: %s\n", this->uuid); printf("description: %s\n", this->description); printf("project: %s\n", this->project); printf("tags: %s\n", this->tags); fflush(stdout); asprintf(&testcmdstr, "task list %s", unique); system(testcmdstr); free(testcmdstr); } cmdout = popen("task undo", "r"); pclose(cmdout); free(addcmdstr); } /* }}} */
void run_command_show(const char *arg) /* {{{ */ { /** * display a variable in the statusbar * syntax: variable */ var *this_var; char *message = NULL; int ret = 0; /* parse arg */ if (arg != NULL) ret = sscanf(arg, "%m[^\n]", &message); if (ret != 1) { statusbar_message(cfg.statusbar_timeout, "syntax: show <variable>"); tnc_fprintf(logfp, LOG_ERROR, "syntax: show <variable> [%d](%s)", ret, arg); goto cleanup; } /* check for a variable */ if (arg == NULL) { statusbar_message(cfg.statusbar_timeout, "no variable specified!"); goto cleanup; } /* find the variable */ this_var = (var *)find_var(arg); if (this_var==NULL) { statusbar_message(cfg.statusbar_timeout, "variable not found: %s", arg); goto cleanup; } /* acquire the value string and print it */ message = var_value_message(this_var, 1); statusbar_message(cfg.statusbar_timeout, message); cleanup: free(message); return; } /* }}} */
void run_command_set(char *args) /* {{{ */ { /** * set a variable in the statusbar * syntax: variable value */ var *this_var; char *message = NULL, *varname = NULL, *value = NULL; int ret = 0; /* parse args */ if (args != NULL) ret = sscanf(args, "%ms %m[^\n]", &varname, &value); if (ret != 2) { statusbar_message(cfg.statusbar_timeout, "syntax: set <variable> <value>"); tnc_fprintf(logfp, LOG_ERROR, "syntax: set <variable> <value> [%d](%s)", ret, args); goto cleanup; } /* find the variable */ this_var = (var *)find_var(varname); if (this_var==NULL) { statusbar_message(cfg.statusbar_timeout, "variable not found: %s", varname); goto cleanup; } /* check for permission */ if (this_var->perms == VAR_RO) { statusbar_message(cfg.statusbar_timeout, "variable is read only: %s", varname); goto cleanup; } if (this_var->perms == VAR_RC && tasklist != NULL) { statusbar_message(cfg.statusbar_timeout, "variable must be set in config: %s", varname); goto cleanup; } /* set the value */ switch (this_var->type) { case VAR_INT: ret = sscanf(value, "%d", (int *)this_var->ptr); break; case VAR_CHAR: ret = sscanf(value, "%c", (char *)this_var->ptr); break; case VAR_STR: if (*(char **)(this_var->ptr)!=NULL) free(*(char **)(this_var->ptr)); *(char **)(this_var->ptr) = calloc(strlen(value)+1, sizeof(char)); ret = NULL!=strcpy(*(char **)(this_var->ptr), value); if (ret) strip_quotes((char **)this_var->ptr, 1); break; default: ret = 0; break; } if (ret<=0) tnc_fprintf(logfp, LOG_ERROR, "failed to parse value from command: set %s %s", varname, value); /* acquire the value string and print it */ message = var_value_message(this_var, 1); statusbar_message(cfg.statusbar_timeout, message); cleanup: free(message); free(varname); free(value); return; } /* }}} */