stacinhtml

Static C in HTML - simple static site generator
git clone git://git.kocotian.pl/stacinhtml.git
Log | Files | Refs | README | LICENSE

commit a91cc4d304ab147a97133824f5890c1a7458e6ba
parent 6fab71eb13b90630f65eea694fc921f549cf5b69
Author: kocotian <kocotian@kocotian.pl>
Date:   Mon, 22 Mar 2021 22:31:02 +0100

Fixing warnings

Diffstat:
Massemble.c | 3++-
Mcompile.c | 17+++++++++++------
Mstr.h | 4++--
3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/assemble.c b/assemble.c @@ -28,11 +28,12 @@ size_t vss; /* Variable stack size */ String getVariableValue(char *v) { - size_t n; + ssize_t n; String s = { .data = v, .len = strlen(v) }; n = vss; while (--n >= 0) { if (!Strcmp(vs[n].name, s)) return vs[n].value; } + return s; /* TODO: make the function returning pointer and return NULL */ } diff --git a/compile.c b/compile.c @@ -18,6 +18,8 @@ */ +#define _XOPEN_SOURCE 700 + #include <fcntl.h> #include <string.h> #include <sys/stat.h> @@ -62,7 +64,7 @@ generateCode(int fd, String input, int c_mode) if (c_mode) { write(fd, input.data, input.len); } else { - int i = -1; + size_t i = -1; write(fd, "write(fd, \"", 11); while (++i < input.len) { if (*input.data == '\n') @@ -76,13 +78,14 @@ generateCode(int fd, String input, int c_mode) static void generateC(int fd, String input) { - int c_mode, i, li; + int c_mode; + size_t i, li; String ibuf; c_mode = 0; ibuf.data = input.data; ibuf.len = input.len; - for (i = 0; i < input.len; ++i) { + for (i = li = 0; i < input.len; ++i) { if (input.data[i] == '%') { ibuf.len = ++i - li - 1; generateCode(fd, ibuf, c_mode); @@ -98,7 +101,7 @@ generateC(int fd, String input) static String getVariableValue(char *v) { - size_t n; + ssize_t n; String s = { .data = v, .len = strlen(v) }; n = vss; while (--n >= 0) { @@ -120,7 +123,8 @@ main(int argc, char *argv[]) /* Variables: */ /* File names and file descriptors */ char *inputfn = NULL, *outputfn = NULL, *templatefn = NULL; - int inputfd, outputfd, templatefd, viter; + int inputfd, outputfd, templatefd; + size_t viter; /* Read bytes (from nextline()/write()) */ ssize_t rb; @@ -185,8 +189,9 @@ main(int argc, char *argv[]) if (*(readinput.data) == '#'); /* comment */ else { /* variable */ String tok; - if (Strtok(readinput, &tok, '=') <= 0) + if (Strtok(readinput, &tok, '=') <= 0) { /* TODO: return syntax error */; + } vs[vss].name.data = (idata + (parseinput.data - idata) + 1); vs[vss].name.len = tok.len; vs[vss].value.data = (idata + (parseinput.data - idata) + 1) + (tok.len + 1); diff --git a/str.h b/str.h @@ -52,7 +52,7 @@ static ssize_t Strtok(String string, String *out, char c) { char *tmpptr = string.data; - while ((tmpptr - string.data) < string.len) { + while ((unsigned)(tmpptr - string.data) < string.len) { if (*(++tmpptr) == c) break; } string.len = tmpptr - string.data; @@ -63,7 +63,7 @@ Strtok(String string, String *out, char c) static String Strtrim(String str) { - int i = 0; + size_t i = 0; while (isspace(*(str.data)) && i < str.len) { ++str.data; --str.len;