From a431bae2f1e97a3a711ea55384caa3d40343bad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 26 Jan 2019 18:42:59 +0100 Subject: Add -Wextra flag, fix resulting warnings. --- Makefile | 2 +- parse.c | 23 +++++++++++------------ strbuf.c | 4 ++-- strbuf.h | 9 +++++---- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 56992ac5..e522316e 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ LEX := flex DIRS := obj -CFLAGS = -Wall -DSAFE_STR -DSAFE_HASH -ggdb +CFLAGS = -std=gnu99 -Wall -Wextra -pedantic -DSAFE_STR -DSAFE_HASH -ggdb #LFLAGS = #LDFLAGS = diff --git a/parse.c b/parse.c index 2850a51c..6b0f835b 100644 --- a/parse.c +++ b/parse.c @@ -66,21 +66,15 @@ int parse_file(FILE* f, vcalendar* cal) { ++line; - /* We just got a value */ - // LINE(line, key.mem, val.mem); - /* - if (strbuf_c(&cline.key, "LOCATION")) { - if (strbuf_c(&cline.val, "")) return 1; - LINE(line, cline.key.mem, cline.val.mem); - } - */ - handle_kv(cal, ev, &cline, line, &s_ctx); strbuf_soft_reset(&str); p_ctx = p_key; continue; } + /* + * TODO context for property_{key,val}. + */ } else if (p_ctx == p_key && c == ':') { /* if (str.ptr + 1 > keylen) { @@ -104,9 +98,11 @@ int parse_file(FILE* f, vcalendar* cal) { ERR("Error parsing", errno); } else { /* - * Close last pair if the file is lacking trailing whitespace. - * A file with trailing whitespace would however fail. - * TODO check the spec and adjust accordingly + * The standard (3.4, l. 2675) says that each icalobject must + * end with CRLF. My files however does not, so we also parse + * the end here. + * TODO this doesn't do anything with its read value + * TODO This might crash if we have the CRLF */ if (str.ptr + 1 > vallen) { vallen = str.ptr + 1; @@ -121,6 +117,9 @@ int parse_file(FILE* f, vcalendar* cal) { return 0; } +/* + * TODO Extend this to handle properties + */ int handle_kv( vcalendar* cal, vevent* ev, diff --git a/strbuf.c b/strbuf.c index 4490ed4a..353b6d84 100644 --- a/strbuf.c +++ b/strbuf.c @@ -83,7 +83,7 @@ int strbuf_c(strbuf* a, char* b) { return strcmp(a->mem, b) == 0; } -char* charat(strbuf* s, int idx) { +char* charat(strbuf* s, unsigned int idx) { #ifdef SAFE_STR if (idx > s->len) { ERR("Index out of bounds"); @@ -106,7 +106,7 @@ int strbuf_reset(strbuf* s) int strbuf_init_copy(strbuf* dest, strbuf* src) { #ifdef SAFE_STR if (dest->alloc != 0) { - printf("%lu ", dest->alloc); + printf("%u ", dest->alloc); ERR("Dest already allocated"); return 1; } diff --git a/strbuf.h b/strbuf.h index 86098e21..678d87ff 100644 --- a/strbuf.h +++ b/strbuf.h @@ -6,9 +6,10 @@ typedef struct { char* mem; - size_t ptr; - size_t alloc; - size_t len; + /* TODO add support for negative ptr */ + int ptr; + unsigned int alloc; + unsigned int len; } strbuf; /* @@ -57,7 +58,7 @@ int strbuf_append(strbuf* s, char c); */ int strbuf_cap(strbuf* s); int strbuf_reset(strbuf* s); -char* charat(strbuf* s, int idx); +char* charat(strbuf* s, unsigned int idx); char* strbuf_cur(strbuf* s); /* -- cgit v1.2.3