folder refactor

This commit is contained in:
rafagafe 2019-03-28 01:24:37 +01:00
parent 93f3b61eb0
commit 58200fff5c
7 changed files with 48 additions and 20 deletions

View File

@ -1,4 +1,5 @@
language: c
sudo: false
script:
- cd test
- make test

View File

@ -35,7 +35,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tiny-json.h"
#include "../tiny-json.h"
/* Parser a json string. */
int main( void ) {

View File

@ -35,7 +35,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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. */

View File

@ -35,9 +35,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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.");

View File

@ -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)

29
test/makefile Normal file
View File

@ -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) >$@

View File

@ -31,7 +31,7 @@
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include "tiny-json.h"
#include "../tiny-json.h"