From 58200fff5cc0df857f9aca7e53fbc4a8db88ef19 Mon Sep 17 00:00:00 2001 From: rafagafe Date: Thu, 28 Mar 2019 01:24:37 +0100 Subject: [PATCH] folder refactor --- .travis.yml | 1 + example-01.c => examples/example-01.c | 2 +- example-02.c => examples/example-02.c | 2 +- example-03.c => examples/example-03.c | 8 ++++---- makefile => examples/makefile | 24 ++++++++++------------ test/makefile | 29 +++++++++++++++++++++++++++ tests.c => test/tests.c | 2 +- 7 files changed, 48 insertions(+), 20 deletions(-) rename example-01.c => examples/example-01.c (99%) rename example-02.c => examples/example-02.c (99%) rename example-03.c => examples/example-03.c (95%) rename makefile => examples/makefile (51%) create mode 100644 test/makefile rename tests.c => test/tests.c (99%) diff --git a/.travis.yml b/.travis.yml index 1c8ebd3..cdd74dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: c sudo: false script: + - cd test - make test diff --git a/example-01.c b/examples/example-01.c similarity index 99% rename from example-01.c rename to examples/example-01.c index 50babe3..a3f9f2c 100644 --- a/example-01.c +++ b/examples/example-01.c @@ -35,7 +35,7 @@ #include #include #include -#include "tiny-json.h" +#include "../tiny-json.h" /* Parser a json string. */ int main( void ) { diff --git a/example-02.c b/examples/example-02.c similarity index 99% rename from example-02.c rename to examples/example-02.c index 229c840..f94fa16 100644 --- a/example-02.c +++ b/examples/example-02.c @@ -35,7 +35,7 @@ #include #include #include -#include "tiny-json.h" +#include "../tiny-json.h" /** Print the value os a json object or array. * @param json The handler of the json object or array. */ diff --git a/example-03.c b/examples/example-03.c similarity index 95% rename from example-03.c rename to examples/example-03.c index df5c83a..db0948f 100644 --- a/example-03.c +++ b/examples/example-03.c @@ -35,9 +35,9 @@ #include #include #include -#include "tiny-json.h" +#include "../tiny-json.h" -typedef struct jsonStaticPool_s { +typedef struct { json_t mem[32]; unsigned int nextFree; jsonPool_t pool; @@ -49,7 +49,7 @@ static json_t* poolInit( jsonPool_t* pool ) { return &spool->mem[0]; } -static json_t* poolNew( jsonPool_t* pool ) { +static json_t* poolAlloc( jsonPool_t* pool ) { jsonStaticPool_t* spool = json_containerOf(pool, jsonStaticPool_t, pool); if ( spool->nextFree >= sizeof spool->mem / sizeof spool->mem[0] ) return 0; return &spool->mem[spool->nextFree++]; @@ -73,7 +73,7 @@ int main( void ) { "\t]\n" "}\n"; puts( str ); - jsonStaticPool_t spool = { .pool = { .init = poolInit, .new = poolNew } }; + jsonStaticPool_t spool = { .pool = { .init = poolInit, .alloc = poolAlloc } }; json_t const *json = json_createWithPool( str, &spool.pool ); if ( !json ) { puts("Error json create."); diff --git a/makefile b/examples/makefile similarity index 51% rename from makefile rename to examples/makefile index 7e2c7ce..4a1f78e 100644 --- a/makefile +++ b/examples/makefile @@ -3,31 +3,29 @@ CC = gcc CFLAGS = -std=c99 -Wall -pedantic src = $(wildcard *.c) +src += $(wildcard ../*.c) obj = $(src:.c=.o) dep = $(obj:.o=.d) -build: example-01.exe example-02.exe example-03.exe +.PHONY: build all clean -clean: - rm -rf *.d - rm -rf *.o - rm -rf *.exe +build: example-01.exe example-02.exe example-03.exe all: clean build -test: test.exe - ./test.exe +clean:: + rm -rf $(dep) + rm -rf $(obj) + rm -rf *.exe + -example-01.exe: example-01.o tiny-json.o +example-01.exe: example-01.o ../tiny-json.o gcc $(CFLAGS) -o $@ $^ -example-02.exe: example-02.o tiny-json.o +example-02.exe: example-02.o ../tiny-json.o gcc $(CFLAGS) -o $@ $^ -example-03.exe: example-03.o tiny-json.o - gcc $(CFLAGS) -o $@ $^ - -test.exe: tests.o tiny-json.o +example-03.exe: example-03.o ../tiny-json.o gcc $(CFLAGS) -o $@ $^ -include $(dep) diff --git a/test/makefile b/test/makefile new file mode 100644 index 0000000..b45e0af --- /dev/null +++ b/test/makefile @@ -0,0 +1,29 @@ +CC = gcc +CFLAGS = -O3 -std=c99 -Wall -pedantic + +src = $(wildcard *.c) +src += $(wildcard ../*.c) +obj = $(src:.c=.o) +dep = $(obj:.o=.d) + +.PHONY: build all clean + +build: test.exe + +all: clean build + +clean:: + rm -rf $(dep) + rm -rf $(obj) + rm -rf *.exe + +test: test.exe + ./test.exe + +test.exe: $(obj) + gcc $(CFLAGS) -o $@ $^ + +-include $(dep) + +%.d: %.c + $(CC) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ diff --git a/tests.c b/test/tests.c similarity index 99% rename from tests.c rename to test/tests.c index f826cf3..4043663 100644 --- a/tests.c +++ b/test/tests.c @@ -31,7 +31,7 @@ #include #include #include -#include "tiny-json.h" +#include "../tiny-json.h"