kocotian.pl

My personal webpage sources
git clone git://git.kocotian.pl/kocotian.pl.git
Log | Files | Refs | README | LICENSE

commit b19930d397c9d4a77f3634a2650723fc53d4b7c3
parent e2706abfc17d597d8a4c52caff771737d08b6f8a
Author: kocotian <kocotian@kocotian.pl>
Date:   Sat, 20 Mar 2021 20:26:04 +0100

Strtrim(), fixed variable bug

Diffstat:
Mgenerate.c | 8+++++---
Mstr.h | 14++++++++++++++
2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/generate.c b/generate.c @@ -118,10 +118,12 @@ main(int argc, char *argv[]) String tok; if (Strtok(readinput, &tok, '=') <= 0) /* TODO: return syntax error */; - vs[vss].name.data = tok.data; + vs[vss].name.data = (idata + (parseinput.data - idata) + 1); vs[vss].name.len = tok.len; - vs[vss].value.data = readinput.data + (tok.len + 1); - vs[vss].value.len = readinput.len - (tok.len + 1); + vs[vss].value.data = (idata + (parseinput.data - idata) + 1) + (tok.len + 1); + vs[vss].value.len = parseinput.len - (tok.len + 1) - 1; + vs[vss].name = Strtrim(vs[vss].name); + vs[vss].value = Strtrim(vs[vss].value); ++vss; } --readinput.data; diff --git a/str.h b/str.h @@ -28,4 +28,18 @@ Strtok(String string, String *out, char c) return (tmpptr - string.data); } +static String +Strtrim(String str) +{ + int i = 0; + while (isspace(*(str.data)) && i < str.len) { + ++str.data; + --str.len; + ++i; + } + while (isspace(*(str.data + (str.len - 1)))) + --str.len; + return str; +} + #endif