nt

Unnamed repository; edit this file 'description' to name the repository.
git clone git://edryd.org/nt
Log | Files | Refs | LICENSE

commit c2d5b35390055f66e3c607457e2d337d54df29c2
parent faa0a5d6d6471dfbab401b20819a416f5e0bb553
Author: Ed van Bruggen <edvb54@gmail.com>
Date:   Sun, 26 Mar 2017 13:50:18 -0700

Add config to change tag delimiter character

Also clean up bugs with -t option

Diffstat:
config.def.h | 2++
nt.c | 26+++++++++++++++++++++++---
2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -1,3 +1,5 @@ char *fname = "todo"; /* default notes file name, overridden with -f */ int yes = 0; /* 0: prompt to confirm actions such as delete, 1: no prompt */ + +char tagdelim = ':'; diff --git a/nt.c b/nt.c @@ -27,6 +27,7 @@ char *get_tag(char *str); char *strconcat(char **s, int c); char *strtrim(char *s); int strinlist(char *str, char **list, int listc); +int charinstr(char c, char *str); void nt_del(void); void nt_del_all(void); @@ -106,8 +107,15 @@ char * get_tag(char *str) { if (!str) die("get_tag: given null pointer"); + char *tag = estrdup(str); - strtok(tag, ":"); + char delim[2] = { tagdelim, 0 }; + + if (charinstr(tagdelim, str)) + strtok(tag, delim); + else + tag = NULL; + return tag; } @@ -160,9 +168,20 @@ strtrim(char *s) int strinlist(char *str, char **list, int listc) { + if (!str || !list) return 0; int i; for (i = 0; i < listc; i++) - if (strcmp(str, list[i]) == 0) + if (list[i] && strcmp(str, list[i]) == 0) + return 1; + return 0; +} + +int +charinstr(char c, char *str) +{ + if (!str) return 0; + for (; *str; str++) + if (*str == c) return 1; return 0; } @@ -271,7 +290,8 @@ nt_tag(void) for (; cur; cur = cur->next, tagc++) { tag = erealloc(tag, (tagc+2) * sizeof(char*)); - tag[tagc] = get_tag(cur->str); + if (!(tag[tagc] = get_tag(cur->str))) + continue; if (strcmp(sub, "") == 0 && !strinlist(tag[tagc], tag, tagc)) printf("%s\n", tag[tagc]); else if (strcmp(sub, tag[tagc]) == 0)