diff options
author | Ariadna Vigo <arivigodr@gmail.com> | 2020-07-21 14:29:47 +0200 |
---|---|---|
committer | Ariadna Vigo <arivigodr@gmail.com> | 2020-07-24 18:59:14 +0200 |
commit | f4b3177bbd0e9b46eb078f199d57fcf120c2f88e (patch) | |
tree | c3dd37437233eec5605d888db52dbea542bd5f09 /tasklst.c | |
parent | 8c50fbcab556ec7f254b8e7b10c28945ca84ef15 (diff) |
New way to add tasks to an already existing task file.
Diffstat (limited to 'tasklst.c')
-rw-r--r-- | tasklst.c | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -65,7 +65,23 @@ tasklst_tasks_done(TaskLst tasks) { return tasklst_tasks_status(tasks, TASK_DONE); } - + +int +tasklst_add_task(TaskLst *tasks, int status, const char *str) +{ + int i; + + for (i = 0; i < TASK_LST_MAX_NUM; ++i) { + if (tasks->status[i] == TASK_VOID) { + strncpy(tasks->tdesc[i], str, TASK_LST_DESC_MAX_SIZE); + tasks->status[i] = status; + return i; + } + } + + return -1; /* We couldn't add any new task, because tasks is full */ +} + int tasklst_read_from_file(TaskLst *tasks, FILE *fp) { @@ -88,16 +104,11 @@ tasklst_read_from_file(TaskLst *tasks, FILE *fp) if (endptr[0] != '\0') return -1; - if (stat_buf == TASK_VOID) - break; - else - tasks->status[i] = stat_buf; - ptr = strtok(NULL, "\n"); if (ptr == NULL) return -1; - strncpy(tasks->tdesc[i], ptr, TASK_LST_DESC_MAX_SIZE); + tasklst_add_task(tasks, stat_buf, ptr); } return 0; |