summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAriadna Vigo <arivigodr@gmail.com>2020-10-01 19:00:45 +0200
committerAriadna Vigo <arivigodr@gmail.com>2020-10-01 19:00:45 +0200
commit650b47707cb05cc3f6cbb97c911c78e64a9d3e97 (patch)
treec7694abfb7550146ede0388c300d75dab89151bf
parent4b988a705808217595fa9df9fce0c0e1b6e9b0da (diff)
Delete mode now shows feedback to user
-rw-r--r--cras.c20
-rw-r--r--tasklst.c15
-rw-r--r--tasklst.h1
3 files changed, 9 insertions, 27 deletions
diff --git a/cras.c b/cras.c
index f733323..bc2f197 100644
--- a/cras.c
+++ b/cras.c
@@ -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);
diff --git a/tasklst.c b/tasklst.c
index d22169e..d0916f1 100644
--- a/tasklst.c
+++ b/tasklst.c
@@ -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;
diff --git a/tasklst.h b/tasklst.h
index bb1d94d..317454a 100644
--- a/tasklst.h
+++ b/tasklst.h
@@ -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);