Search directly for string in text UI - sacc - sacc(omys), simple console gopher client HTML git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/sacc/ DIR Log DIR Files DIR Refs DIR Tags DIR LICENSE --- DIR commit 859b7150efb9e4ae7b0040a36a8e337f36062f48 DIR parent 65bb62ab632f7bbc5eda03595ca58d0f67805ae6 HTML Author: Quentin Rameau <quinq@fifth.space> Date: Mon, 23 Oct 2017 19:25:36 +0200 Search directly for string in text UI Diffstat: M ui_txt.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) --- DIR diff --git a/ui_txt.c b/ui_txt.c @@ -171,7 +171,7 @@ searchinline(const char *searchstr, Item *entry) Dir *dir; size_t i; - if (!(dir = entry->dat)) + if (!searchstr || !*searchstr || !(dir = entry->dat)) return; for (i = 0; i < dir->nitems; ++i) @@ -184,7 +184,7 @@ uiselectitem(Item *entry) { Dir *dir; static char c; - char buf[BUFSIZ], nl, *searchstr; + char buf[BUFSIZ], *sstr, nl; int item, nitems, lines; if (!entry || !(dir = entry->dat)) @@ -210,6 +210,12 @@ uiselectitem(Item *entry) } else if (!strcmp(buf+1, "\n")) { item = -1; c = *buf; + } else if (*buf == '/') { + for (sstr = buf+1; *sstr && *sstr != '\n'; ++sstr) + ; + *sstr = '\0'; + sstr = buf+1; + c = *buf; } else if (isdigit(*(buf+1))) { nl = '\0'; if (sscanf(buf+1, "%d%c", &item, &nl) != 2 || nl != '\n') @@ -255,11 +261,8 @@ uiselectitem(Item *entry) printuri(&dir->items[item-1], item); continue; case '/': - if ((searchstr = uiprompt("Search for: ")) && - searchstr[0]) - searchinline(searchstr, entry); - free(searchstr); - searchstr = NULL; + if (*sstr) + searchinline(sstr, entry); continue; case 'h': case '?':