diff options
| -rw-r--r-- | agenda_entry.c | 3 | ||||
| -rw-r--r-- | utils.h | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/agenda_entry.c b/agenda_entry.c index fa933c6..91a23b9 100644 --- a/agenda_entry.c +++ b/agenda_entry.c @@ -1,3 +1,4 @@ +#include "utils.h" #include "agenda_entry.h" char *next_word(char *str) { return strstr(str, " ")+1; } @@ -24,7 +25,7 @@ entry read_agenda_entry(char *agenda) { //find out if there is a tag, and extract it lookahead = strstr(cursor, ":\n"); if (lookahead && (lookahead < nextentry)) { - tmp = strstr(cursor, ":"); + tmp = rstrchr(cursor, lookahead-1, ':'); agenda_entry.tag = (char *)malloc(lookahead - tmp); strncpy(agenda_entry.tag, tmp+1, lookahead - tmp - 1); agenda_entry.tag[lookahead - tmp - 1] = '\0'; // here we're actually modifying lookahead-tmp cause the array is zero indexed @@ -0,0 +1,8 @@ +#include <stddef.h> + +char *rstrchr(const char *s, char *start, char c) { + char *ret = start; + while ((ret > s) && (*ret != c)) ret--; + if ((s == ret) && (*s != c)) return NULL; + else return ret; +} |
