diff options
author | Ariadna Vigo <arivigodr@gmail.com> | 2020-10-01 19:00:45 +0200 |
---|---|---|
committer | Ariadna Vigo <arivigodr@gmail.com> | 2020-10-01 19:00:45 +0200 |
commit | 650b47707cb05cc3f6cbb97c911c78e64a9d3e97 (patch) | |
tree | c7694abfb7550146ede0388c300d75dab89151bf | |
parent | 4b988a705808217595fa9df9fce0c0e1b6e9b0da (diff) |
Delete mode now shows feedback to user
-rw-r--r-- | cras.c | 20 | ||||
-rw-r--r-- | tasklst.c | 15 | ||||
-rw-r--r-- | tasklst.h | 1 |
3 files changed, 9 insertions, 27 deletions
@@ -244,11 +244,16 @@ delete_mode(const char *crasfile, const char *id) tasknum = strtol(id, &endptr, 10); if (endptr[0] != '\0') die("'%s' not a number.", id); + if (tasknum <= 0) + die("Task number must be greater than zero."); task_lst_init(&list); read_crasfile(&list, crasfile); - task_lst_del_task(&list, tasknum - 1); + if (task_lst_del_task(&list, tasknum - 1) < 0) { + task_lst_cleanup(&list); + die("Task #%d does not exist.", tasknum); + } write_crasfile(crasfile, list); task_lst_cleanup(&list); @@ -265,20 +270,13 @@ mark_list_mode(const char *crasfile, const char *id, int value) tasknum = strtol(id, &endptr, 10); if (endptr[0] != '\0') die("'%s' not a number.", id); + if (tasknum <= 0) + die("Task number must be greater than zero."); task_lst_init(&list); read_crasfile(&list, crasfile); - if (tasknum <= 0) { - task_lst_cleanup(&list); - die("Task number must be greater than zero."); - } - - task = NULL; - if (tasknum <= task_lst_get_size(list)) - task = task_lst_get_task(list, tasknum - 1); - - /* If task is still NULL, then it means tasknum wasn't within range. */ + task = task_lst_get_task(list, tasknum - 1); if (task == NULL) { task_lst_cleanup(&list); die("Task #%d does not exist.", tasknum); @@ -62,18 +62,6 @@ task_lst_cleanup(TaskLst *list) } } -int -task_lst_get_size(TaskLst list) -{ - Task *ptr; - int count; - - for (count = 0, ptr = list.first; ptr != NULL; ptr = ptr->next) - ++count; - - return count; -} - void task_lst_set_expiration(TaskLst *list, int64_t delta) { @@ -144,9 +132,6 @@ task_lst_del_task(TaskLst *list, int i) { Task *del, *prev, *next; - if ((i > task_lst_get_size(*list)) || (i < 0)) - return -1; - if ((del = task_lst_get_task(*list, i)) == NULL) return -1; @@ -22,7 +22,6 @@ typedef struct { void task_lst_init(TaskLst *list); void task_lst_cleanup(TaskLst *list); -int task_lst_get_size(TaskLst list); void task_lst_set_expiration(TaskLst *list, int64_t delta); int task_lst_expired(TaskLst list); int task_lst_count_todo(TaskLst list); |