stacinhtml

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

commit ff94dda1a472ea17c38437dbf425fa7f5ef204f1
parent 7c5fdb2d2bd98544c92e3a2cf53475aed9153340
Author: kocotian <kocotian@kocotian.pl>
Date:   Wed,  7 Apr 2021 09:36:58 +0200

Removed most of warnings

Diffstat:
Massemble.h | 6+++++-
Mcompile.c | 23++++++++++++++++-------
Mstr.c | 28++++++----------------------
Mutil.c | 5+++--
Mutil.h | 15++++++++++++---
5 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/assemble.h b/assemble.h @@ -21,10 +21,14 @@ #ifndef _ASSEMBLE_H #define _ASSEMBLE_H -#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> #include <string.h> +#include <sys/types.h> +#include <unistd.h> #include "str.h" +#include "util.h" /* Macros */ #define $(VARNAME) getVariableValue(#VARNAME) diff --git a/compile.c b/compile.c @@ -21,6 +21,7 @@ #define _XOPEN_SOURCE 700 #include <fcntl.h> +#include <stdio.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> @@ -85,7 +86,7 @@ generateCode(int fd, String input, int c_mode) dprintf(fd, "\"\n\""); dprintf(fd, "\\x%02x", *(input.data++)); } - dprintf(fd, "\", %d);", input.len); + dprintf(fd, "\", %ld);", input.len); } } @@ -122,12 +123,20 @@ getVariableByName(char *v) if (!Strcmp(vs[n].name, s)) return vs + n; } + return NULL; } static String getVariableValue(char *v) { - return getVariableByName(v)->value; + Variable *var = getVariableByName(v); + if (var == NULL) { + String s = { + .len = 0 + }; + return s; + } + return var->value; } static void @@ -213,7 +222,7 @@ template(int outputfd, String templatename) char tname[sizeof TEMPLATEDIR + 256]; char input_buf[BUFFER_SIZE]; int fd; - String function = $(function); + /* String function = $(function); -- unused, maybe will for later? */ String fun_iden = Striden(templatename); String input = { .data = input_buf, @@ -242,8 +251,8 @@ template(int outputfd, String templatename) /* Declaring variables */ for (viter = vsscopy; viter < vss; ++viter) dprintf(outputfd, "DECLVAR(%.*s, \"%.*s\"); ", - vs[viter].name.len, vs[viter].name.data, - vs[viter].value.len, vs[viter].value.data); + (int)vs[viter].name.len, vs[viter].name.data, + (int)vs[viter].value.len, vs[viter].value.data); /* Generating C code */ generateC(outputfd, input); @@ -335,8 +344,8 @@ main(int argc, char *argv[]) /* Declaring variables */ for (viter = 0; viter < vss; ++viter) dprintf(outputfd, "DECLVAR(%.*s, \"%.*s\"); ", - vs[viter].name.len, vs[viter].name.data, - vs[viter].value.len, vs[viter].value.data); + (int)vs[viter].name.len, vs[viter].name.data, + (int)vs[viter].value.len, vs[viter].value.data); /* calling function */ caller = Striden($(template)); diff --git a/str.c b/str.c @@ -18,23 +18,9 @@ */ -#ifndef _STR_H -#define _STR_H +#include "str.h" -#include <ctype.h> - -typedef struct { - char *data; - size_t len; -} String; - -static String toString(char *s); -static int Strcmp(String a, String b); -static ssize_t Strtok(String string, String *out, char c); -static String Striden(String string); -static String Strtrim(String str); - -static String +String toString(char *s) { String ret; @@ -42,14 +28,14 @@ toString(char *s) return ret; } -static int +int Strcmp(String a, String b) { if (a.len != b.len) return -1; return strncmp(a.data, b.data, a.len); } -static ssize_t +ssize_t Strtok(String string, String *out, char c) { char *tmpptr = string.data; @@ -64,7 +50,7 @@ Strtok(String string, String *out, char c) return (tmpptr - string.data); } -static String +String Striden(String str) { size_t i; @@ -76,7 +62,7 @@ Striden(String str) return str; } -static String +String Strtrim(String str) { size_t i = 0; @@ -89,5 +75,3 @@ Strtrim(String str) --str.len; return str; } - -#endif diff --git a/util.c b/util.c @@ -17,14 +17,15 @@ ecalloc(size_t nmemb, size_t size) } void -die(const char *fmt, ...) { +die(const char *fmt, ...) +{ va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); - if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { fputc(' ', stderr); perror(NULL); } else { diff --git a/util.h b/util.h @@ -1,8 +1,17 @@ /* See licenses/LIBSL file for copyright and license details. */ -#define MAX(A, B) ((A) > (B) ? (A) : (B)) -#define MIN(A, B) ((A) < (B) ? (A) : (B)) -#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) +#ifndef _UTIL_H +#define _UTIL_H + +#define MAX(A, B) ((signed)(A) > (signed)(B) ? (signed)(A) : (signed)(B)) +#define MIN(A, B) ((signed)(A) < (signed)(B) ? (signed)(A) : (signed)(B)) +#define BETWEEN(X, A, B) ((signed)(A) <= (signed)(X) && (signed)(X) <= (signed)(B)) + +#define UMAX(A, B) ((unsigned)(A) > (unsigned)(B) ? (unsigned)(A) : (unsigned)(B)) +#define UMIN(A, B) ((unsigned)(A) < (unsigned)(B) ? (unsigned)(A) : (unsigned)(B)) +#define UBETWEEN(X, A, B) ((unsigned)(A) <= (unsigned)(X) && (unsigned)(X) <= (unsigned)(B)) void die(const char *fmt, ...); void *ecalloc(size_t nmemb, size_t size); + +#endif