Merge branch 'master' of git.unix7.org:ziggi/cworker
This commit is contained in:
@@ -19,7 +19,9 @@ libcworker_la_SOURCES = \
|
|||||||
logger.c \
|
logger.c \
|
||||||
massert.c \
|
massert.c \
|
||||||
rcache.c \
|
rcache.c \
|
||||||
jblock.c
|
jblock.c \
|
||||||
|
cdynarr.c \
|
||||||
|
cstring.c
|
||||||
|
|
||||||
include_HEADERS = \
|
include_HEADERS = \
|
||||||
cflexer.h \
|
cflexer.h \
|
||||||
@@ -31,21 +33,22 @@ include_HEADERS = \
|
|||||||
logger.h \
|
logger.h \
|
||||||
massert.h \
|
massert.h \
|
||||||
rcache.h \
|
rcache.h \
|
||||||
jblock.h
|
jblock.h \
|
||||||
|
cdynarr.h \
|
||||||
|
cstring.h
|
||||||
|
|
||||||
if HAVE_VALGRIND
|
if HAVE_VALGRIND
|
||||||
VALGRIND_OPT = --tool=memcheck
|
VALGRIND_OPT = --tool=memcheck
|
||||||
endif
|
endif
|
||||||
|
|
||||||
test: $(bin_TESTS)
|
test: valgrind
|
||||||
|
simple: $(bin_TESTS)
|
||||||
@for test in $(bin_TESTS); do \
|
@for test in $(bin_TESTS); do \
|
||||||
echo ====== Test $${test} ======; \
|
echo ====== Test $${test} ======; \
|
||||||
./$${test}; \
|
./$${test}; \
|
||||||
echo ====== Done $${test} ======; \
|
echo ====== Done $${test} ======; \
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
valgrind: $(bin_TESTS)
|
valgrind: $(bin_TESTS)
|
||||||
@for test in $(bin_TESTS); do \
|
@for test in $(bin_TESTS); do \
|
||||||
echo ====== Test $${test} ======; \
|
echo ====== Test $${test} ======; \
|
||||||
@@ -53,10 +56,8 @@ valgrind: $(bin_TESTS)
|
|||||||
echo ====== Done $${test} ======; \
|
echo ====== Done $${test} ======; \
|
||||||
done
|
done
|
||||||
|
|
||||||
common_SOURCES = libcworker.la
|
|
||||||
|
|
||||||
bin_TESTS = \
|
bin_TESTS = \
|
||||||
jblock_test
|
cstring_test
|
||||||
|
|
||||||
noinst_PROGRAMS = \
|
noinst_PROGRAMS = \
|
||||||
cfparser_test \
|
cfparser_test \
|
||||||
@@ -68,19 +69,23 @@ noinst_PROGRAMS = \
|
|||||||
jlexer_test \
|
jlexer_test \
|
||||||
jparser_test \
|
jparser_test \
|
||||||
rcache_test \
|
rcache_test \
|
||||||
jblock_test
|
jblock_test \
|
||||||
|
cdynarr_test \
|
||||||
|
cstring_test \
|
||||||
|
logger_test
|
||||||
|
|
||||||
#TESTS = $(bin_TESTS)
|
#TESTS = $(bin_TESTS)
|
||||||
|
|
||||||
cflexer_test_SOURCES = cflexer_test.c $(common_SOURCES)
|
cflexer_test_SOURCES = cflexer_test.c
|
||||||
cfparser_test_SOURCES = cfparser_test.c $(common_SOURCES)
|
cfparser_test_SOURCES = cfparser_test.c
|
||||||
cllexer_test_SOURCES = cllexer_test.c $(common_SOURCES)
|
cllexer_test_SOURCES = cllexer_test.c
|
||||||
clparser_test_SOURCES = clparser_test.c $(common_SOURCES)
|
clparser_test_SOURCES = clparser_test.c
|
||||||
jlexer_test_SOURCES = jlexer_test.c $(common_SOURCES)
|
jlexer_test_SOURCES = jlexer_test.c
|
||||||
jparser_test_SOURCES = jparser_test.c $(common_SOURCES)
|
jparser_test_SOURCES = jparser_test.c
|
||||||
rcache_test_SOURCES = rcache_test.c $(common_SOURCES)
|
rcache_test_SOURCES = rcache_test.c
|
||||||
jblock_test_SOURCES = jblock_test.c $(common_SOURCES)
|
jblock_test_SOURCES = jblock_test.c
|
||||||
|
cdynarr_test_SOURCES = cdynarr_test.c
|
||||||
|
cstring_test_SOURCES = cstring_test.c
|
||||||
|
|
||||||
cflexer_test_LDADD = libcworker.la
|
cflexer_test_LDADD = libcworker.la
|
||||||
cfparser_test_LDADD = libcworker.la
|
cfparser_test_LDADD = libcworker.la
|
||||||
@@ -90,8 +95,9 @@ jblock_test_LDADD = libcworker.la
|
|||||||
jlexer_test_LDADD = libcworker.la
|
jlexer_test_LDADD = libcworker.la
|
||||||
jparser_test_LDADD = libcworker.la
|
jparser_test_LDADD = libcworker.la
|
||||||
rcache_test_LDADD = libcworker.la
|
rcache_test_LDADD = libcworker.la
|
||||||
|
cdynarr_test_LDADD = libcworker.la
|
||||||
|
cstring_test_LDADD = libcworker.la
|
||||||
|
logger_test_LDADD = libcworker.la
|
||||||
|
|
||||||
clean-local:
|
clean-local:
|
||||||
rm -rf *~
|
rm -rf *~
|
||||||
|
|||||||
@@ -94,7 +94,9 @@ noinst_PROGRAMS = cfparser_test$(EXEEXT) clparser_test$(EXEEXT) \
|
|||||||
cflexer_test$(EXEEXT) cfparser_test$(EXEEXT) \
|
cflexer_test$(EXEEXT) cfparser_test$(EXEEXT) \
|
||||||
cllexer_test$(EXEEXT) clparser_test$(EXEEXT) \
|
cllexer_test$(EXEEXT) clparser_test$(EXEEXT) \
|
||||||
jlexer_test$(EXEEXT) jparser_test$(EXEEXT) \
|
jlexer_test$(EXEEXT) jparser_test$(EXEEXT) \
|
||||||
rcache_test$(EXEEXT) jblock_test$(EXEEXT)
|
rcache_test$(EXEEXT) jblock_test$(EXEEXT) \
|
||||||
|
cdynarr_test$(EXEEXT) cstring_test$(EXEEXT) \
|
||||||
|
logger_test$(EXEEXT)
|
||||||
subdir = clib
|
subdir = clib
|
||||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||||
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
|
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
|
||||||
@@ -114,35 +116,43 @@ LTLIBRARIES = $(noinst_LTLIBRARIES)
|
|||||||
libcworker_la_LIBADD =
|
libcworker_la_LIBADD =
|
||||||
am_libcworker_la_OBJECTS = cflexer.lo cfparser.lo cllexer.lo \
|
am_libcworker_la_OBJECTS = cflexer.lo cfparser.lo cllexer.lo \
|
||||||
clparser.lo jlexer.lo jparser.lo logger.lo massert.lo \
|
clparser.lo jlexer.lo jparser.lo logger.lo massert.lo \
|
||||||
rcache.lo jblock.lo
|
rcache.lo jblock.lo cdynarr.lo cstring.lo
|
||||||
libcworker_la_OBJECTS = $(am_libcworker_la_OBJECTS)
|
libcworker_la_OBJECTS = $(am_libcworker_la_OBJECTS)
|
||||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||||
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
||||||
am__v_lt_0 = --silent
|
am__v_lt_0 = --silent
|
||||||
am__v_lt_1 =
|
am__v_lt_1 =
|
||||||
am__objects_1 =
|
am_cdynarr_test_OBJECTS = cdynarr_test.$(OBJEXT)
|
||||||
am_cflexer_test_OBJECTS = cflexer_test.$(OBJEXT) $(am__objects_1)
|
cdynarr_test_OBJECTS = $(am_cdynarr_test_OBJECTS)
|
||||||
|
cdynarr_test_DEPENDENCIES = libcworker.la
|
||||||
|
am_cflexer_test_OBJECTS = cflexer_test.$(OBJEXT)
|
||||||
cflexer_test_OBJECTS = $(am_cflexer_test_OBJECTS)
|
cflexer_test_OBJECTS = $(am_cflexer_test_OBJECTS)
|
||||||
cflexer_test_DEPENDENCIES = libcworker.la
|
cflexer_test_DEPENDENCIES = libcworker.la
|
||||||
am_cfparser_test_OBJECTS = cfparser_test.$(OBJEXT) $(am__objects_1)
|
am_cfparser_test_OBJECTS = cfparser_test.$(OBJEXT)
|
||||||
cfparser_test_OBJECTS = $(am_cfparser_test_OBJECTS)
|
cfparser_test_OBJECTS = $(am_cfparser_test_OBJECTS)
|
||||||
cfparser_test_DEPENDENCIES = libcworker.la
|
cfparser_test_DEPENDENCIES = libcworker.la
|
||||||
am_cllexer_test_OBJECTS = cllexer_test.$(OBJEXT) $(am__objects_1)
|
am_cllexer_test_OBJECTS = cllexer_test.$(OBJEXT)
|
||||||
cllexer_test_OBJECTS = $(am_cllexer_test_OBJECTS)
|
cllexer_test_OBJECTS = $(am_cllexer_test_OBJECTS)
|
||||||
cllexer_test_DEPENDENCIES = libcworker.la
|
cllexer_test_DEPENDENCIES = libcworker.la
|
||||||
am_clparser_test_OBJECTS = clparser_test.$(OBJEXT) $(am__objects_1)
|
am_clparser_test_OBJECTS = clparser_test.$(OBJEXT)
|
||||||
clparser_test_OBJECTS = $(am_clparser_test_OBJECTS)
|
clparser_test_OBJECTS = $(am_clparser_test_OBJECTS)
|
||||||
clparser_test_DEPENDENCIES = libcworker.la
|
clparser_test_DEPENDENCIES = libcworker.la
|
||||||
am_jblock_test_OBJECTS = jblock_test.$(OBJEXT) $(am__objects_1)
|
am_cstring_test_OBJECTS = cstring_test.$(OBJEXT)
|
||||||
|
cstring_test_OBJECTS = $(am_cstring_test_OBJECTS)
|
||||||
|
cstring_test_DEPENDENCIES = libcworker.la
|
||||||
|
am_jblock_test_OBJECTS = jblock_test.$(OBJEXT)
|
||||||
jblock_test_OBJECTS = $(am_jblock_test_OBJECTS)
|
jblock_test_OBJECTS = $(am_jblock_test_OBJECTS)
|
||||||
jblock_test_DEPENDENCIES = libcworker.la
|
jblock_test_DEPENDENCIES = libcworker.la
|
||||||
am_jlexer_test_OBJECTS = jlexer_test.$(OBJEXT) $(am__objects_1)
|
am_jlexer_test_OBJECTS = jlexer_test.$(OBJEXT)
|
||||||
jlexer_test_OBJECTS = $(am_jlexer_test_OBJECTS)
|
jlexer_test_OBJECTS = $(am_jlexer_test_OBJECTS)
|
||||||
jlexer_test_DEPENDENCIES = libcworker.la
|
jlexer_test_DEPENDENCIES = libcworker.la
|
||||||
am_jparser_test_OBJECTS = jparser_test.$(OBJEXT) $(am__objects_1)
|
am_jparser_test_OBJECTS = jparser_test.$(OBJEXT)
|
||||||
jparser_test_OBJECTS = $(am_jparser_test_OBJECTS)
|
jparser_test_OBJECTS = $(am_jparser_test_OBJECTS)
|
||||||
jparser_test_DEPENDENCIES = libcworker.la
|
jparser_test_DEPENDENCIES = libcworker.la
|
||||||
am_rcache_test_OBJECTS = rcache_test.$(OBJEXT) $(am__objects_1)
|
logger_test_SOURCES = logger_test.c
|
||||||
|
logger_test_OBJECTS = logger_test.$(OBJEXT)
|
||||||
|
logger_test_DEPENDENCIES = libcworker.la
|
||||||
|
am_rcache_test_OBJECTS = rcache_test.$(OBJEXT)
|
||||||
rcache_test_OBJECTS = $(am_rcache_test_OBJECTS)
|
rcache_test_OBJECTS = $(am_rcache_test_OBJECTS)
|
||||||
rcache_test_DEPENDENCIES = libcworker.la
|
rcache_test_DEPENDENCIES = libcworker.la
|
||||||
AM_V_P = $(am__v_P_@AM_V@)
|
AM_V_P = $(am__v_P_@AM_V@)
|
||||||
@@ -178,15 +188,17 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)
|
|||||||
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
|
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
|
||||||
am__v_CCLD_0 = @echo " CCLD " $@;
|
am__v_CCLD_0 = @echo " CCLD " $@;
|
||||||
am__v_CCLD_1 =
|
am__v_CCLD_1 =
|
||||||
SOURCES = $(libcworker_la_SOURCES) $(cflexer_test_SOURCES) \
|
SOURCES = $(libcworker_la_SOURCES) $(cdynarr_test_SOURCES) \
|
||||||
$(cfparser_test_SOURCES) $(cllexer_test_SOURCES) \
|
$(cflexer_test_SOURCES) $(cfparser_test_SOURCES) \
|
||||||
$(clparser_test_SOURCES) $(jblock_test_SOURCES) \
|
$(cllexer_test_SOURCES) $(clparser_test_SOURCES) \
|
||||||
$(jlexer_test_SOURCES) $(jparser_test_SOURCES) \
|
$(cstring_test_SOURCES) $(jblock_test_SOURCES) \
|
||||||
|
$(jlexer_test_SOURCES) $(jparser_test_SOURCES) logger_test.c \
|
||||||
$(rcache_test_SOURCES)
|
$(rcache_test_SOURCES)
|
||||||
DIST_SOURCES = $(libcworker_la_SOURCES) $(cflexer_test_SOURCES) \
|
DIST_SOURCES = $(libcworker_la_SOURCES) $(cdynarr_test_SOURCES) \
|
||||||
$(cfparser_test_SOURCES) $(cllexer_test_SOURCES) \
|
$(cflexer_test_SOURCES) $(cfparser_test_SOURCES) \
|
||||||
$(clparser_test_SOURCES) $(jblock_test_SOURCES) \
|
$(cllexer_test_SOURCES) $(clparser_test_SOURCES) \
|
||||||
$(jlexer_test_SOURCES) $(jparser_test_SOURCES) \
|
$(cstring_test_SOURCES) $(jblock_test_SOURCES) \
|
||||||
|
$(jlexer_test_SOURCES) $(jparser_test_SOURCES) logger_test.c \
|
||||||
$(rcache_test_SOURCES)
|
$(rcache_test_SOURCES)
|
||||||
am__can_run_installinfo = \
|
am__can_run_installinfo = \
|
||||||
case $$AM_UPDATE_INFO_DIR in \
|
case $$AM_UPDATE_INFO_DIR in \
|
||||||
@@ -392,7 +404,9 @@ libcworker_la_SOURCES = \
|
|||||||
logger.c \
|
logger.c \
|
||||||
massert.c \
|
massert.c \
|
||||||
rcache.c \
|
rcache.c \
|
||||||
jblock.c
|
jblock.c \
|
||||||
|
cdynarr.c \
|
||||||
|
cstring.c
|
||||||
|
|
||||||
include_HEADERS = \
|
include_HEADERS = \
|
||||||
cflexer.h \
|
cflexer.h \
|
||||||
@@ -404,23 +418,26 @@ include_HEADERS = \
|
|||||||
logger.h \
|
logger.h \
|
||||||
massert.h \
|
massert.h \
|
||||||
rcache.h \
|
rcache.h \
|
||||||
jblock.h
|
jblock.h \
|
||||||
|
cdynarr.h \
|
||||||
|
cstring.h
|
||||||
|
|
||||||
@HAVE_VALGRIND_TRUE@VALGRIND_OPT = --tool=memcheck
|
@HAVE_VALGRIND_TRUE@VALGRIND_OPT = --tool=memcheck
|
||||||
common_SOURCES = libcworker.la
|
|
||||||
bin_TESTS = \
|
bin_TESTS = \
|
||||||
jblock_test
|
cstring_test
|
||||||
|
|
||||||
|
|
||||||
#TESTS = $(bin_TESTS)
|
#TESTS = $(bin_TESTS)
|
||||||
cflexer_test_SOURCES = cflexer_test.c $(common_SOURCES)
|
cflexer_test_SOURCES = cflexer_test.c
|
||||||
cfparser_test_SOURCES = cfparser_test.c $(common_SOURCES)
|
cfparser_test_SOURCES = cfparser_test.c
|
||||||
cllexer_test_SOURCES = cllexer_test.c $(common_SOURCES)
|
cllexer_test_SOURCES = cllexer_test.c
|
||||||
clparser_test_SOURCES = clparser_test.c $(common_SOURCES)
|
clparser_test_SOURCES = clparser_test.c
|
||||||
jlexer_test_SOURCES = jlexer_test.c $(common_SOURCES)
|
jlexer_test_SOURCES = jlexer_test.c
|
||||||
jparser_test_SOURCES = jparser_test.c $(common_SOURCES)
|
jparser_test_SOURCES = jparser_test.c
|
||||||
rcache_test_SOURCES = rcache_test.c $(common_SOURCES)
|
rcache_test_SOURCES = rcache_test.c
|
||||||
jblock_test_SOURCES = jblock_test.c $(common_SOURCES)
|
jblock_test_SOURCES = jblock_test.c
|
||||||
|
cdynarr_test_SOURCES = cdynarr_test.c
|
||||||
|
cstring_test_SOURCES = cstring_test.c
|
||||||
cflexer_test_LDADD = libcworker.la
|
cflexer_test_LDADD = libcworker.la
|
||||||
cfparser_test_LDADD = libcworker.la
|
cfparser_test_LDADD = libcworker.la
|
||||||
cllexer_test_LDADD = libcworker.la
|
cllexer_test_LDADD = libcworker.la
|
||||||
@@ -429,6 +446,9 @@ jblock_test_LDADD = libcworker.la
|
|||||||
jlexer_test_LDADD = libcworker.la
|
jlexer_test_LDADD = libcworker.la
|
||||||
jparser_test_LDADD = libcworker.la
|
jparser_test_LDADD = libcworker.la
|
||||||
rcache_test_LDADD = libcworker.la
|
rcache_test_LDADD = libcworker.la
|
||||||
|
cdynarr_test_LDADD = libcworker.la
|
||||||
|
cstring_test_LDADD = libcworker.la
|
||||||
|
logger_test_LDADD = libcworker.la
|
||||||
all: all-am
|
all: all-am
|
||||||
|
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
@@ -486,6 +506,10 @@ clean-noinstLTLIBRARIES:
|
|||||||
libcworker.la: $(libcworker_la_OBJECTS) $(libcworker_la_DEPENDENCIES) $(EXTRA_libcworker_la_DEPENDENCIES)
|
libcworker.la: $(libcworker_la_OBJECTS) $(libcworker_la_DEPENDENCIES) $(EXTRA_libcworker_la_DEPENDENCIES)
|
||||||
$(AM_V_CCLD)$(LINK) $(libcworker_la_OBJECTS) $(libcworker_la_LIBADD) $(LIBS)
|
$(AM_V_CCLD)$(LINK) $(libcworker_la_OBJECTS) $(libcworker_la_LIBADD) $(LIBS)
|
||||||
|
|
||||||
|
cdynarr_test$(EXEEXT): $(cdynarr_test_OBJECTS) $(cdynarr_test_DEPENDENCIES) $(EXTRA_cdynarr_test_DEPENDENCIES)
|
||||||
|
@rm -f cdynarr_test$(EXEEXT)
|
||||||
|
$(AM_V_CCLD)$(LINK) $(cdynarr_test_OBJECTS) $(cdynarr_test_LDADD) $(LIBS)
|
||||||
|
|
||||||
cflexer_test$(EXEEXT): $(cflexer_test_OBJECTS) $(cflexer_test_DEPENDENCIES) $(EXTRA_cflexer_test_DEPENDENCIES)
|
cflexer_test$(EXEEXT): $(cflexer_test_OBJECTS) $(cflexer_test_DEPENDENCIES) $(EXTRA_cflexer_test_DEPENDENCIES)
|
||||||
@rm -f cflexer_test$(EXEEXT)
|
@rm -f cflexer_test$(EXEEXT)
|
||||||
$(AM_V_CCLD)$(LINK) $(cflexer_test_OBJECTS) $(cflexer_test_LDADD) $(LIBS)
|
$(AM_V_CCLD)$(LINK) $(cflexer_test_OBJECTS) $(cflexer_test_LDADD) $(LIBS)
|
||||||
@@ -502,6 +526,10 @@ clparser_test$(EXEEXT): $(clparser_test_OBJECTS) $(clparser_test_DEPENDENCIES) $
|
|||||||
@rm -f clparser_test$(EXEEXT)
|
@rm -f clparser_test$(EXEEXT)
|
||||||
$(AM_V_CCLD)$(LINK) $(clparser_test_OBJECTS) $(clparser_test_LDADD) $(LIBS)
|
$(AM_V_CCLD)$(LINK) $(clparser_test_OBJECTS) $(clparser_test_LDADD) $(LIBS)
|
||||||
|
|
||||||
|
cstring_test$(EXEEXT): $(cstring_test_OBJECTS) $(cstring_test_DEPENDENCIES) $(EXTRA_cstring_test_DEPENDENCIES)
|
||||||
|
@rm -f cstring_test$(EXEEXT)
|
||||||
|
$(AM_V_CCLD)$(LINK) $(cstring_test_OBJECTS) $(cstring_test_LDADD) $(LIBS)
|
||||||
|
|
||||||
jblock_test$(EXEEXT): $(jblock_test_OBJECTS) $(jblock_test_DEPENDENCIES) $(EXTRA_jblock_test_DEPENDENCIES)
|
jblock_test$(EXEEXT): $(jblock_test_OBJECTS) $(jblock_test_DEPENDENCIES) $(EXTRA_jblock_test_DEPENDENCIES)
|
||||||
@rm -f jblock_test$(EXEEXT)
|
@rm -f jblock_test$(EXEEXT)
|
||||||
$(AM_V_CCLD)$(LINK) $(jblock_test_OBJECTS) $(jblock_test_LDADD) $(LIBS)
|
$(AM_V_CCLD)$(LINK) $(jblock_test_OBJECTS) $(jblock_test_LDADD) $(LIBS)
|
||||||
@@ -514,6 +542,10 @@ jparser_test$(EXEEXT): $(jparser_test_OBJECTS) $(jparser_test_DEPENDENCIES) $(EX
|
|||||||
@rm -f jparser_test$(EXEEXT)
|
@rm -f jparser_test$(EXEEXT)
|
||||||
$(AM_V_CCLD)$(LINK) $(jparser_test_OBJECTS) $(jparser_test_LDADD) $(LIBS)
|
$(AM_V_CCLD)$(LINK) $(jparser_test_OBJECTS) $(jparser_test_LDADD) $(LIBS)
|
||||||
|
|
||||||
|
logger_test$(EXEEXT): $(logger_test_OBJECTS) $(logger_test_DEPENDENCIES) $(EXTRA_logger_test_DEPENDENCIES)
|
||||||
|
@rm -f logger_test$(EXEEXT)
|
||||||
|
$(AM_V_CCLD)$(LINK) $(logger_test_OBJECTS) $(logger_test_LDADD) $(LIBS)
|
||||||
|
|
||||||
rcache_test$(EXEEXT): $(rcache_test_OBJECTS) $(rcache_test_DEPENDENCIES) $(EXTRA_rcache_test_DEPENDENCIES)
|
rcache_test$(EXEEXT): $(rcache_test_OBJECTS) $(rcache_test_DEPENDENCIES) $(EXTRA_rcache_test_DEPENDENCIES)
|
||||||
@rm -f rcache_test$(EXEEXT)
|
@rm -f rcache_test$(EXEEXT)
|
||||||
$(AM_V_CCLD)$(LINK) $(rcache_test_OBJECTS) $(rcache_test_LDADD) $(LIBS)
|
$(AM_V_CCLD)$(LINK) $(rcache_test_OBJECTS) $(rcache_test_LDADD) $(LIBS)
|
||||||
@@ -771,7 +803,8 @@ uninstall-am: uninstall-includeHEADERS
|
|||||||
.c.o:
|
.c.o:
|
||||||
$(CC) -I. -pthread $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
|
$(CC) -I. -pthread $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
test: $(bin_TESTS)
|
test: valgrind
|
||||||
|
simple: $(bin_TESTS)
|
||||||
@for test in $(bin_TESTS); do \
|
@for test in $(bin_TESTS); do \
|
||||||
echo ====== Test $${test} ======; \
|
echo ====== Test $${test} ======; \
|
||||||
./$${test}; \
|
./$${test}; \
|
||||||
|
|||||||
93
clib/cdynarr.c
Normal file
93
clib/cdynarr.c
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <cdynarr.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define INIT_CAPA 64
|
||||||
|
|
||||||
|
/* Integer array */
|
||||||
|
cintarr_t* new_cintarr(void) {
|
||||||
|
cintarr_t* arr = malloc(sizeof(cintarr_t));
|
||||||
|
if (arr == NULL) return NULL;
|
||||||
|
if (cintarr_init(arr) == NULL) {
|
||||||
|
cintarr_free(arr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* cintarr_init(cintarr_t* array) {
|
||||||
|
array->data = malloc(INIT_CAPA * sizeof(int64_t));
|
||||||
|
if (array->data == NULL) return NULL;
|
||||||
|
memset(array->data, 0, INIT_CAPA);
|
||||||
|
array->capa = INIT_CAPA;
|
||||||
|
array->size = 0;
|
||||||
|
return array->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* cintarr_append(cintarr_t* array, int64_t add) {
|
||||||
|
if (array->size + 1 > array->capa) {
|
||||||
|
size_t newcapa = (array->capa * 10) / 6 ;
|
||||||
|
int64_t* newarray = realloc(array->data, newcapa);
|
||||||
|
if (newarray == NULL) return NULL;
|
||||||
|
array->capa = newcapa;
|
||||||
|
array->data = newarray;
|
||||||
|
}
|
||||||
|
array->data[array->size++] = add;
|
||||||
|
return array->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t* cintarr_getref(cintarr_t* array) {
|
||||||
|
return array->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cintarr_destroy(cintarr_t* array) {
|
||||||
|
if (array == NULL) return;
|
||||||
|
free(array->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cintarr_free(cintarr_t* array) {
|
||||||
|
cintarr_destroy(array);
|
||||||
|
free(array->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Float array */
|
||||||
|
void* cfltarr_init(cfltarr_t* array) {
|
||||||
|
array->data = malloc(INIT_CAPA * sizeof(double));
|
||||||
|
if (array->data == NULL) return NULL;
|
||||||
|
memset(array->data, 0, INIT_CAPA);
|
||||||
|
array->capa = INIT_CAPA;
|
||||||
|
array->size = 0;
|
||||||
|
return array->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* cfltarr_append(cfltarr_t* array, double add) {
|
||||||
|
if (array->size + 1 > array->capa) {
|
||||||
|
size_t newcapa = (array->capa * 10) / 6 ;
|
||||||
|
double* newarray = realloc(array->data, newcapa);
|
||||||
|
if (newarray == NULL) return NULL;
|
||||||
|
array->capa = newcapa;
|
||||||
|
array->data = newarray;
|
||||||
|
}
|
||||||
|
array->data[array->size++] = add;
|
||||||
|
return array->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
double* cfltarr_getref(cfltarr_t* array) {
|
||||||
|
return array->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cfltarr_destroy(cfltarr_t* array) {
|
||||||
|
if (array == NULL) return;
|
||||||
|
free(array->data);
|
||||||
|
}
|
||||||
49
clib/cdynarr.h
Normal file
49
clib/cdynarr.h
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
#ifndef CDYNARR_H_QWERTY
|
||||||
|
#define CDYNARR_H_QWERTY
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t* data;
|
||||||
|
int capa;
|
||||||
|
int size;
|
||||||
|
} cintarr_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool* data;
|
||||||
|
int capa;
|
||||||
|
int size;
|
||||||
|
} cboolarr_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
double* data;
|
||||||
|
int capa;
|
||||||
|
int size;
|
||||||
|
} cfltarr_t;
|
||||||
|
|
||||||
|
|
||||||
|
cintarr_t* new_cintarr(void);
|
||||||
|
void* cintarr_init(cintarr_t* array);
|
||||||
|
void* cintarr_append(cintarr_t* array, int64_t add);
|
||||||
|
int64_t* cintarr_getref(cintarr_t* array);
|
||||||
|
void cintarr_destroy(cintarr_t* array);
|
||||||
|
void cintarr_free(cintarr_t* array);
|
||||||
|
|
||||||
|
cfltarr_t* new_cfltarr(void);
|
||||||
|
void* cfltarr_init(cfltarr_t* array);
|
||||||
|
void* cfltarr_append(cfltarr_t* array, double add);
|
||||||
|
double* cfltarr_getref(cfltarr_t* array);
|
||||||
|
void cfltarr_destroy(cfltarr_t* array);
|
||||||
|
void cfltarr_free(cfltarr_t* array);
|
||||||
|
|
||||||
|
cboolarr_t* new_cboolarr(void);
|
||||||
|
void* cboolarr_init(cboolarr_t* array);
|
||||||
|
void* cboolarr_append(cboolarr_t* array, bool add);
|
||||||
|
bool* cboolarr_getref(cboolarr_t* array);
|
||||||
|
void cboolarr_destroy(cboolarr_t* array);
|
||||||
|
void cboolarr_free(cboolarr_t* array);
|
||||||
|
|
||||||
|
#endif
|
||||||
23
clib/cdynarr_test.c
Normal file
23
clib/cdynarr_test.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 Oleg Borodin <borodin@unix7.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <massert.h>
|
||||||
|
#include <cdynarr.h>
|
||||||
|
|
||||||
|
|
||||||
|
void test01(void) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
#include <clparser.h>
|
#include <clparser.h>
|
||||||
|
|
||||||
#define INIT_BSIZE 64
|
#define INIT_BSIZE 128
|
||||||
|
|
||||||
|
|
||||||
static char* strcopy(char* src) {
|
static char* strcopy(char* src) {
|
||||||
|
|||||||
50
clib/cstring.c
Normal file
50
clib/cstring.c
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <cstring.h>
|
||||||
|
|
||||||
|
#define INIT_CAPA 1
|
||||||
|
|
||||||
|
/* String container */
|
||||||
|
void* cstring_init(cstring_t* str) {
|
||||||
|
str->data = malloc((INIT_CAPA + 1)*sizeof(char));
|
||||||
|
if (str->data == NULL) return NULL;
|
||||||
|
memset(str->data, '\0', INIT_CAPA + 1);
|
||||||
|
str->capa = INIT_CAPA;
|
||||||
|
str->size = 0;
|
||||||
|
return str->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void* cstring_append(cstring_t* str, char* add) {
|
||||||
|
size_t addsize = strlen(add);
|
||||||
|
size_t newsize = str->size + addsize;
|
||||||
|
if (newsize > str->capa) {
|
||||||
|
size_t newcapa = str->capa + addsize;
|
||||||
|
char* newstr = realloc(str->data, (newcapa + 1)*sizeof(char));
|
||||||
|
if (newstr == NULL) return NULL;
|
||||||
|
str->data = newstr;
|
||||||
|
str->capa = newcapa;
|
||||||
|
}
|
||||||
|
strcpy(&(str->data[str->size]), add);
|
||||||
|
str->data[newsize + 1] = '\0';
|
||||||
|
str->size = newsize;
|
||||||
|
return str->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* cstring_getref(cstring_t* str) {
|
||||||
|
return str->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cstring_destroy(cstring_t* str) {
|
||||||
|
if (str == NULL) return;
|
||||||
|
free(str->data);
|
||||||
|
}
|
||||||
17
clib/cstring.h
Normal file
17
clib/cstring.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
#ifndef CSTRING_H_QWERTY
|
||||||
|
#define CSTRING_H_QWERTY
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char* data;
|
||||||
|
int capa;
|
||||||
|
int size;
|
||||||
|
} cstring_t;
|
||||||
|
|
||||||
|
|
||||||
|
void* cstring_init(cstring_t* str);
|
||||||
|
void* cstring_append(cstring_t* str, char* add);
|
||||||
|
char* cstring_getref(cstring_t* str);
|
||||||
|
void cstring_destroy(cstring_t* str);
|
||||||
|
|
||||||
|
#endif
|
||||||
41
clib/cstring_test.c
Normal file
41
clib/cstring_test.c
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 Oleg Borodin <borodin@unix7.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <massert.h>
|
||||||
|
#include <cstring.h>
|
||||||
|
|
||||||
|
|
||||||
|
void test01(void) {
|
||||||
|
|
||||||
|
cstring_t str;
|
||||||
|
cstring_init(&str);
|
||||||
|
cstring_append(&str, "qwerty");
|
||||||
|
cstring_append(&str, "123456\n");
|
||||||
|
|
||||||
|
cstring_append(&str, "qwerty");
|
||||||
|
cstring_append(&str, "123456\n");
|
||||||
|
|
||||||
|
cstring_append(&str, "qwerty");
|
||||||
|
cstring_append(&str, "123456\n");
|
||||||
|
|
||||||
|
cstring_append(&str, "qwerty");
|
||||||
|
cstring_append(&str, "123456\n");
|
||||||
|
|
||||||
|
cstring_append(&str, "qwerty");
|
||||||
|
cstring_append(&str, "123456\n");
|
||||||
|
|
||||||
|
printf("%s\n", cstring_getref(&str));
|
||||||
|
|
||||||
|
cstring_destroy(&str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
172
clib/jblock.c
172
clib/jblock.c
@@ -4,17 +4,17 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <jblock.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <cstring.h>
|
||||||
|
#include <cdynarr.h>
|
||||||
|
#include <jblock.h>
|
||||||
|
|
||||||
#define INIT_CAPA 64
|
#define INIT_CAPA 64
|
||||||
|
|
||||||
static void* jstring_init(jstring_t* str);
|
|
||||||
static void* jstring_append(jstring_t* str, char* add);
|
|
||||||
static char* jstring_getref(jstring_t* str);
|
|
||||||
static char* strcopy(char* src);
|
static char* strcopy(char* src);
|
||||||
|
|
||||||
void jblock_init(jblock_t* jb) {
|
void jblock_init(jblock_t* jb) {
|
||||||
@@ -106,9 +106,9 @@ int jblock_addstr(jblock_t* jb, char* key, char* val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void jblock_outjson(jblock_t* jb, char** res) {
|
void jblock_outjson(jblock_t* jb, char** res) {
|
||||||
jstring_t jstr;
|
cstring_t jstr;
|
||||||
jstring_init(&jstr);
|
cstring_init(&jstr);
|
||||||
jstring_append(&jstr, "{");
|
cstring_append(&jstr, "{");
|
||||||
for (int i = 0; i < jb->kvsize; i++) {
|
for (int i = 0; i < jb->kvsize; i++) {
|
||||||
switch (jb->kvarr[i].type) {
|
switch (jb->kvarr[i].type) {
|
||||||
case JKVTYPE_STR:
|
case JKVTYPE_STR:
|
||||||
@@ -117,7 +117,7 @@ void jblock_outjson(jblock_t* jb, char** res) {
|
|||||||
case JKVTYPE_INT: {
|
case JKVTYPE_INT: {
|
||||||
char* buffer = NULL;
|
char* buffer = NULL;
|
||||||
asprintf(&buffer, "\"%s\":", jb->kvarr[i].key);
|
asprintf(&buffer, "\"%s\":", jb->kvarr[i].key);
|
||||||
jstring_append(&jstr, buffer);
|
cstring_append(&jstr, buffer);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -129,39 +129,39 @@ void jblock_outjson(jblock_t* jb, char** res) {
|
|||||||
case JKVTYPE_INT: {
|
case JKVTYPE_INT: {
|
||||||
char* buffer = NULL;
|
char* buffer = NULL;
|
||||||
asprintf(&buffer, "%ld", jb->kvarr[i].num);
|
asprintf(&buffer, "%ld", jb->kvarr[i].num);
|
||||||
jstring_append(&jstr, buffer);
|
cstring_append(&jstr, buffer);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case JKVTYPE_FLT: {
|
case JKVTYPE_FLT: {
|
||||||
char* buffer = NULL;
|
char* buffer = NULL;
|
||||||
asprintf(&buffer, "%e", jb->kvarr[i].flt);
|
asprintf(&buffer, "%e", jb->kvarr[i].flt);
|
||||||
jstring_append(&jstr, buffer);
|
cstring_append(&jstr, buffer);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case JKVTYPE_BOOL: {
|
case JKVTYPE_BOOL: {
|
||||||
if (jb->kvarr[i].flag) {
|
if (jb->kvarr[i].flag) {
|
||||||
jstring_append(&jstr, "true");
|
cstring_append(&jstr, "true");
|
||||||
} else {
|
} else {
|
||||||
jstring_append(&jstr, "false");
|
cstring_append(&jstr, "false");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case JKVTYPE_STR: {
|
case JKVTYPE_STR: {
|
||||||
char* buffer = NULL;
|
char* buffer = NULL;
|
||||||
asprintf(&buffer, "\"%s\"", jb->kvarr[i].str);
|
asprintf(&buffer, "\"%s\"", jb->kvarr[i].str);
|
||||||
jstring_append(&jstr, buffer);
|
cstring_append(&jstr, buffer);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i < jb->kvsize - 1) {
|
if (i < jb->kvsize - 1) {
|
||||||
jstring_append(&jstr, ",");
|
cstring_append(&jstr, ",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jstring_append(&jstr, "}");
|
cstring_append(&jstr, "}");
|
||||||
*res = jstring_getref(&jstr);
|
*res = cstring_getref(&jstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -205,146 +205,6 @@ void jblock_free(jblock_t* jb) {
|
|||||||
free(jb);
|
free(jb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* String container */
|
|
||||||
static void* jstring_init(jstring_t* str) {
|
|
||||||
str->data = malloc(INIT_CAPA + 1);
|
|
||||||
if (str->data == NULL) return NULL;
|
|
||||||
memset(str->data, '\0', INIT_CAPA + 1);
|
|
||||||
str->capa = INIT_CAPA;
|
|
||||||
str->size = 0;
|
|
||||||
return str->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void* jstring_append(jstring_t* str, char* add) {
|
|
||||||
size_t addsize = strlen(add);
|
|
||||||
size_t newsize = str->size + addsize;
|
|
||||||
if (newsize > str->capa) {
|
|
||||||
char* newstr = realloc(str->data, newsize + 1);
|
|
||||||
if (newstr == NULL) return NULL;
|
|
||||||
}
|
|
||||||
strcpy(&(str->data[str->size]), add);
|
|
||||||
str->data[newsize + 1] = '\0';
|
|
||||||
str->capa = newsize;
|
|
||||||
str->size = newsize;
|
|
||||||
return str->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char* jstring_getref(jstring_t* str) {
|
|
||||||
return str->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Integer array */
|
|
||||||
jintarr_t* new_jintarr(void) {
|
|
||||||
jintarr_t* arr = malloc(sizeof(jintarr_t));
|
|
||||||
if (arr == NULL) return NULL;
|
|
||||||
if (jintarr_init(arr) == NULL) {
|
|
||||||
jintarr_free(arr);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* jintarr_init(jintarr_t* array) {
|
|
||||||
array->data = malloc(INIT_CAPA * sizeof(int64_t));
|
|
||||||
if (array->data == NULL) return NULL;
|
|
||||||
memset(array->data, 0, INIT_CAPA);
|
|
||||||
array->capa = INIT_CAPA;
|
|
||||||
array->size = 0;
|
|
||||||
return array->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* jintarr_append(jintarr_t* array, int64_t add) {
|
|
||||||
if (array->size + 1 > array->capa) {
|
|
||||||
size_t newcapa = (array->capa * 10) / 6 ;
|
|
||||||
int64_t* newarray = realloc(array->data, newcapa);
|
|
||||||
if (newarray == NULL) return NULL;
|
|
||||||
array->capa = newcapa;
|
|
||||||
array->data = newarray;
|
|
||||||
}
|
|
||||||
array->data[array->size++] = add;
|
|
||||||
return array->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t* jintarr_getref(jintarr_t* array) {
|
|
||||||
return array->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void jintarr_destroy(jintarr_t* array) {
|
|
||||||
if (array == NULL) return;
|
|
||||||
free(array->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void jintarr_free(jintarr_t* array) {
|
|
||||||
jintarr_destroy(array);
|
|
||||||
free(array->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Float array */
|
|
||||||
void* jfltarr_init(jfltarr_t* array) {
|
|
||||||
array->data = malloc(INIT_CAPA * sizeof(double));
|
|
||||||
if (array->data == NULL) return NULL;
|
|
||||||
memset(array->data, 0, INIT_CAPA);
|
|
||||||
array->capa = INIT_CAPA;
|
|
||||||
array->size = 0;
|
|
||||||
return array->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* jfltarr_append(jfltarr_t* array, double add) {
|
|
||||||
if (array->size + 1 > array->capa) {
|
|
||||||
size_t newcapa = (array->capa * 10) / 6 ;
|
|
||||||
double* newarray = realloc(array->data, newcapa);
|
|
||||||
if (newarray == NULL) return NULL;
|
|
||||||
array->capa = newcapa;
|
|
||||||
array->data = newarray;
|
|
||||||
}
|
|
||||||
array->data[array->size++] = add;
|
|
||||||
return array->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
double* jfltarr_getref(jfltarr_t* array) {
|
|
||||||
return array->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void jfltarr_destroy(jfltarr_t* array) {
|
|
||||||
if (array == NULL) return;
|
|
||||||
free(array->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Bool array */
|
|
||||||
void* jboolarr_init(jboolarr_t* array) {
|
|
||||||
array->data = malloc(INIT_CAPA * sizeof(bool));
|
|
||||||
if (array->data == NULL) return NULL;
|
|
||||||
memset(array->data, 0, INIT_CAPA);
|
|
||||||
array->capa = INIT_CAPA;
|
|
||||||
array->size = 0;
|
|
||||||
return array->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* jboolarr_append(jboolarr_t* array, bool add) {
|
|
||||||
if (array->size + 1 > array->capa) {
|
|
||||||
size_t newcapa = (array->capa * 10) / 6 ;
|
|
||||||
bool* newarray = realloc(array->data, newcapa);
|
|
||||||
if (newarray == NULL) return NULL;
|
|
||||||
array->capa = newcapa;
|
|
||||||
array->data = newarray;
|
|
||||||
}
|
|
||||||
array->data[array->size++] = add;
|
|
||||||
return array->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool* jboolarr_getref(jboolarr_t* array) {
|
|
||||||
return array->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void jboolarr_destroy(jboolarr_t* array) {
|
|
||||||
if (array == NULL) return;
|
|
||||||
free(array->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Tools */
|
/* Tools */
|
||||||
static char* strcopy(char* src) {
|
static char* strcopy(char* src) {
|
||||||
size_t srcsize = strlen(src) + 1;
|
size_t srcsize = strlen(src) + 1;
|
||||||
|
|||||||
@@ -5,31 +5,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <cdynarr.h>
|
||||||
typedef struct {
|
#include <cstring.h>
|
||||||
char* data;
|
|
||||||
int capa;
|
|
||||||
int size;
|
|
||||||
} jstring_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int64_t* data;
|
|
||||||
int capa;
|
|
||||||
int size;
|
|
||||||
} jintarr_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool* data;
|
|
||||||
int capa;
|
|
||||||
int size;
|
|
||||||
} jboolarr_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
double* data;
|
|
||||||
int capa;
|
|
||||||
int size;
|
|
||||||
} jfltarr_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct jblock jblock_t;
|
typedef struct jblock jblock_t;
|
||||||
|
|
||||||
@@ -41,9 +18,9 @@ typedef struct {
|
|||||||
bool flag;
|
bool flag;
|
||||||
char* str;
|
char* str;
|
||||||
double flt;
|
double flt;
|
||||||
jintarr_t numarr;
|
cintarr_t numarr;
|
||||||
jfltarr_t fltarr;
|
cfltarr_t fltarr;
|
||||||
jboolarr_t flagarr;
|
cboolarr_t flagarr;
|
||||||
jblock_t* blk;
|
jblock_t* blk;
|
||||||
jblock_t* blkarr;
|
jblock_t* blkarr;
|
||||||
char** strarr;
|
char** strarr;
|
||||||
@@ -85,26 +62,5 @@ int jblock_addfloat(jblock_t* block, char* key, double val);
|
|||||||
int jblock_addstr(jblock_t* block, char* key, char* val);
|
int jblock_addstr(jblock_t* block, char* key, char* val);
|
||||||
int jblock_addbool(jblock_t* block, char* key, bool val);
|
int jblock_addbool(jblock_t* block, char* key, bool val);
|
||||||
|
|
||||||
jintarr_t* new_jintarr(void);
|
|
||||||
void* jintarr_init(jintarr_t* array);
|
|
||||||
void* jintarr_append(jintarr_t* array, int64_t add);
|
|
||||||
int64_t* jintarr_getref(jintarr_t* array);
|
|
||||||
void jintarr_destroy(jintarr_t* array);
|
|
||||||
void jintarr_free(jintarr_t* array);
|
|
||||||
|
|
||||||
jfltarr_t* new_jfltarr(void);
|
|
||||||
void* jfltarr_init(jfltarr_t* array);
|
|
||||||
void* jfltarr_append(jfltarr_t* array, double add);
|
|
||||||
double* jfltarr_getref(jfltarr_t* array);
|
|
||||||
void jfltarr_destroy(jfltarr_t* array);
|
|
||||||
void jfltarr_free(jfltarr_t* array);
|
|
||||||
|
|
||||||
jboolarr_t* new_jboolarr(void);
|
|
||||||
void* jboolarr_init(jboolarr_t* array);
|
|
||||||
void* jboolarr_append(jboolarr_t* array, bool add);
|
|
||||||
bool* jboolarr_getref(jboolarr_t* array);
|
|
||||||
void jboolarr_destroy(jboolarr_t* array);
|
|
||||||
void jboolarr_free(jboolarr_t* array);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -30,30 +30,30 @@ void test01(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void test02(void) {
|
void test02(void) {
|
||||||
jintarr_t* arr = new_jintarr();
|
cintarr_t* arr = new_cintarr();
|
||||||
jintarr_init(arr);
|
cintarr_init(arr);
|
||||||
|
|
||||||
for (int64_t i = 0; i < 1024 + 1; i++) {
|
for (int64_t i = 0; i < 1024 + 1; i++) {
|
||||||
jintarr_append(arr, i);
|
cintarr_append(arr, i);
|
||||||
}
|
}
|
||||||
printf("size: %d capa: %d\n", arr->size, arr->capa);
|
printf("size: %d capa: %d\n", arr->size, arr->capa);
|
||||||
printf("last: %ld\n", arr->data[arr->size - 1]);
|
printf("last: %ld\n", arr->data[arr->size - 1]);
|
||||||
|
|
||||||
jintarr_free(arr);
|
cintarr_free(arr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test03(void) {
|
void test03(void) {
|
||||||
jfltarr_t arr;
|
cfltarr_t arr;
|
||||||
jfltarr_init(&arr);
|
cfltarr_init(&arr);
|
||||||
|
|
||||||
for (int64_t i = 0; i < 1024 + 1; i++) {
|
for (int64_t i = 0; i < 1024 + 1; i++) {
|
||||||
jfltarr_append(&arr, i);
|
cfltarr_append(&arr, i);
|
||||||
}
|
}
|
||||||
printf("size: %d capa: %d\n", arr.size, arr.capa);
|
printf("size: %d capa: %d\n", arr.size, arr.capa);
|
||||||
printf("last: %f\n", arr.data[arr.size - 1]);
|
printf("last: %f\n", arr.data[arr.size - 1]);
|
||||||
|
|
||||||
jfltarr_destroy(&arr);
|
cfltarr_destroy(&arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,17 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|
||||||
#define CLOCK_SOURCE CLOCK_MONOTONIC
|
#define CLOCK_SOURCE CLOCK_MONOTONIC
|
||||||
#define MAX_TS_LEN 256
|
#define MAX_TS_LEN 256 * 2
|
||||||
|
|
||||||
|
|
||||||
static pthread_mutex_t logmutex = NULL;
|
static pthread_mutex_t logmutex;
|
||||||
static pthread_mutexattr_t logmutex_attrs;
|
static pthread_mutexattr_t logmutex_attrs;
|
||||||
|
|
||||||
void log_init(void) {
|
void log_init(void) {
|
||||||
@@ -42,9 +43,9 @@ void static set_timestamp(char* buffer) {
|
|||||||
|
|
||||||
clock_gettime(CLOCK_SOURCE, &tv);
|
clock_gettime(CLOCK_SOURCE, &tv);
|
||||||
memset(buffer, '\0', MAX_TS_LEN);
|
memset(buffer, '\0', MAX_TS_LEN);
|
||||||
sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02d.%ld+%s",
|
sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02d.%03ld+%s",
|
||||||
ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,
|
ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,
|
||||||
ptm->tm_min, ptm->tm_sec, tv.tv_nsec, ptm->tm_zone);
|
ptm->tm_min, ptm->tm_sec, tv.tv_nsec/(int64_t)1000000, ptm->tm_zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_error(const char* format, ...) {
|
void log_error(const char* format, ...) {
|
||||||
|
|||||||
25
clib/logger_test.c
Normal file
25
clib/logger_test.c
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 Oleg Borodin <borodin@unix7.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <massert.h>
|
||||||
|
#include <logger.h>
|
||||||
|
|
||||||
|
|
||||||
|
void test01(void) {
|
||||||
|
log_init();
|
||||||
|
log_debug("qwerty");
|
||||||
|
log_debug("qwerty: %s", "12345");
|
||||||
|
log_debug("qwerty: %d", 12345);
|
||||||
|
log_destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
78
cworker.c
78
cworker.c
@@ -94,7 +94,7 @@ static int cworker_readopts(const cworker_t* worker, char** argv, int argc) {
|
|||||||
log_error("Args parsing error");
|
log_error("Args parsing error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
clparser_destroy(&parser);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,53 +269,55 @@ int cworker_run(const cworker_t* worker) {
|
|||||||
int cworker_handler(const cworker_t* worker, int socket) {
|
int cworker_handler(const cworker_t* worker, int socket) {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
rcache_t cache;
|
//rcache_t cache;
|
||||||
jlexer_t lexer;
|
//jlexer_t lexer;
|
||||||
jparser_t parser;
|
//jparser_t parser;
|
||||||
|
|
||||||
rcache_init(&cache, socket);
|
//rcache_init(&cache, socket);
|
||||||
jlexer_init(&lexer, &cache);
|
//jlexer_init(&lexer, &cache);
|
||||||
jparser_init(&parser, &lexer);
|
//jparser_init(&parser, &lexer);
|
||||||
|
|
||||||
if (jparser_parse(&parser) < 0) {
|
//if (jparser_parse(&parser) < 0) {
|
||||||
log_error("Cannot parse json");
|
//log_error("Cannot parse json");
|
||||||
err = -1;
|
//err = -1;
|
||||||
goto exit;
|
//goto exit;
|
||||||
}
|
//}
|
||||||
|
|
||||||
int64_t id = 0;
|
//int64_t id = 0;
|
||||||
char* name = "none";
|
//char* name = "none";
|
||||||
|
|
||||||
if (jparser_bind(&parser, JVALTYPE_NUM, "id", (void *)&id) < 0) {
|
//if (jparser_bind(&parser, JVALTYPE_NUM, "id", (void *)&id) < 0) {
|
||||||
log_error("Cannot bind id");
|
//log_error("Cannot bind id");
|
||||||
}
|
//}
|
||||||
if (jparser_bind(&parser, JVALTYPE_STR, "name", (void *)&name) < 0) {
|
//if (jparser_bind(&parser, JVALTYPE_STR, "name", (void *)&name) < 0) {
|
||||||
log_error("Cannot bind name");
|
//log_error("Cannot bind name");
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
char* msg = NULL;
|
//char* msg = NULL;
|
||||||
asprintf(&msg, "hello, %s!", name);
|
//asprintf(&msg, "hello, %s!", name);
|
||||||
|
|
||||||
jblock_t jb;
|
//jblock_t jb;
|
||||||
jblock_init(&jb);
|
//jblock_init(&jb);
|
||||||
jblock_addstr(&jb, "message", msg);
|
//jblock_addstr(&jb, "message", msg);
|
||||||
jblock_addbool(&jb, "error", false);
|
//jblock_addbool(&jb, "error", false);
|
||||||
|
|
||||||
char* jsonstr = NULL;
|
//char* jsonstr = NULL;
|
||||||
jblock_outjson(&jb, &jsonstr);
|
//jblock_outjson(&jb, &jsonstr);
|
||||||
jblock_destroy(&jb);
|
//jblock_destroy(&jb);
|
||||||
|
|
||||||
write(socket, jsonstr, strlen(jsonstr));
|
//write(socket, jsonstr, strlen(jsonstr));
|
||||||
free(jsonstr);
|
//free(jsonstr);
|
||||||
free(name);
|
//free(name);
|
||||||
free(msg);
|
//free(msg);
|
||||||
|
|
||||||
exit:
|
//exit:
|
||||||
jparser_destroy(&parser);
|
//jparser_destroy(&parser);
|
||||||
jlexer_destroy(&lexer);
|
//jlexer_destroy(&lexer);
|
||||||
rcache_destroy(&cache);
|
//rcache_destroy(&cache);
|
||||||
return err;
|
|
||||||
|
close(socket);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cworker_shutdown(cworker_t* worker) {
|
void cworker_shutdown(cworker_t* worker) {
|
||||||
|
|||||||
Reference in New Issue
Block a user