tIgnore possible extra tab delimited fields - sacc - sacc(omys), simple console gopher client (mirror) HTML git clone https://git.parazyd.org/sacc DIR Log DIR Files DIR Refs DIR LICENSE --- DIR commit 3d2081c17810cae6607b3a265f848e5031002d0a DIR parent bab7585c38f70040c68865455e3fafa552cf9f6c HTML Author: Leonardo Taccari <iamleot@gmail.com> Date: Sat, 18 Aug 2018 15:18:32 +0200 Ignore possible extra tab delimited fields According RFC 1436: > [...] If there are yet other tab delimited fields, the basic > Gopher client should ignore them. [...] Diffstat: M sacc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) --- DIR diff --git a/sacc.c b/sacc.c t@@ -283,11 +283,11 @@ displaytextitem(Item *item) } static char * -pickfield(char **raw, char sep) +pickfield(char **raw, const char *sep) { char *c, *f = *raw; - for (c = *raw; *c && *c != sep; ++c) + for (c = *raw; *c && strchr(sep, *c) == NULL; ++c) ; *c = '\0'; t@@ -309,7 +309,7 @@ invaliditem(char *raw) if (c) *raw++ = '\0'; - return (tabs == 3) ? NULL : raw; + return (tabs >= 3) ? NULL : raw; } static void t@@ -327,10 +327,12 @@ molditem(Item *item, char **raw) } item->type = *raw[0]++; - item->username = pickfield(raw, '\t'); - item->selector = pickfield(raw, '\t'); - item->host = pickfield(raw, '\t'); - item->port = pickfield(raw, '\r'); + item->username = pickfield(raw, "\t"); + item->selector = pickfield(raw, "\t"); + item->host = pickfield(raw, "\t"); + item->port = pickfield(raw, "\t\r"); + while (*raw[0] != '\0') + ++*raw; if (!*raw[0]) ++*raw; }