diff options
-rw-r--r-- | src/todo.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -72,6 +72,8 @@ static void process_todo_file(void (*mapper_func)(char *), } } + // i keeps track of the line in the file we are on. + // j is the index of mapped_indices[] that we are currently waiting for. for (size_t i = 1, j = 0; (line_len = getline(&line, &line_buff_size, todo_file)) >= 0; i++) { if (line_len > 5) { @@ -121,15 +123,18 @@ static void print_list(char *line, ssize_t line_len, FILE *ignored, void todo_list(void) { process_todo_file(NULL, NULL, 0, print_list, false); } void todo_add(int argc, char **argv) { - if (argc < 1) { - fprintf(stderr, "todo add takes at least 1 argument\n"); - exit(EXIT_FAILURE); - } - open_todo_file("a"); - for (int i = 0; i < argc; i++) { - fprintf(todo_file, "[ ] %s\n", argv[i]); + if (argc < 1) { + char *line = NULL; + size_t line_buff_size = 0; + while (getline(&line, &line_buff_size, stdin) > 0) { + fprintf(todo_file, "[ ] %s", line); + } + } else { + for (int i = 0; i < argc; i++) { + fprintf(todo_file, "[ ] %s\n", argv[i]); + } } fclose(todo_file); @@ -230,6 +235,7 @@ void todo_sort(void) { pid_t pid = fork(); + // The same as `LC_ALL=C sort < TODO > .TODO` from a shell. if (pid == 0) { open_todo_file("r"); int input_fd = fileno(todo_file); |