Commit ce7d8d9d authored by Mark Lindner's avatar Mark Lindner

Merge branch 'master' of https://github.com/hyperrealm/libconfig

parents c3dc9043 7b247671
cmake_minimum_required(VERSION 3.1)
project(libconfig)
option(BUILD_EXAMPLES "Enable examples" ON)
option(BUILD_SHARED_LIBS "Enable shared library" ON)
option(BUILD_TESTS "Enable tests" ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
set(LIB_TYPE STATIC)
if(BUILD_SHARED_LIBS)
set(LIB_TYPE SHARED)
add_definitions(-DLIBCONFIG_EXPORTS)
add_definitions(-DLIBCONFIGXX_EXPORTS)
else()
add_definitions(-DLIBCONFIG_STATIC)
add_definitions(-DLIBCONFIGXX_STATIC)
endif()
include(GNUInstallDirs)
add_subdirectory(lib)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tinytest)
add_subdirectory(tests)
endif()
add_subdirectory(c)
add_subdirectory(c++)
\ No newline at end of file
add_executable(c++_example1 example1.cpp )
add_executable(c++_example2 example2.cpp )
add_executable(c++_example3 example3.cpp )
add_executable(c++_example4 example4.cpp )
target_include_directories(c++_example1 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c++_example2 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c++_example3 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c++_example4 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_link_libraries(c++_example1 libconfig++ )
target_link_libraries(c++_example2 libconfig++ )
target_link_libraries(c++_example3 libconfig++ )
target_link_libraries(c++_example4 libconfig++ )
\ No newline at end of file
add_executable(c_example1 example1.c )
add_executable(c_example2 example2.c )
add_executable(c_example3 example3.c )
target_include_directories(c_example1 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c_example2 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c_example3 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_link_libraries(c_example1 libconfig )
target_link_libraries(c_example2 libconfig )
target_link_libraries(c_example3 libconfig )
\ No newline at end of file
set(libinc
libconfig.h)
set(libsrc
grammar.h
parsectx.h
scanctx.h
scanner.h
win32/stdint.h
strbuf.h
strvec.h
util.h
wincompat.h
grammar.c
libconfig.c
scanctx.c
scanner.c
strbuf.c
strvec.c
util.c)
set(libinc_cpp
libconfig.h++
libconfig.hh)
set(libsrc_cpp
${libsrc}
libconfigcpp.cc)
add_library(libconfig ${LIB_TYPE} ${libsrc} ${libinc})
add_library(libconfig++ ${LIB_TYPE} ${libsrc_cpp} ${libinc_cpp})
set_target_properties(libconfig
PROPERTIES LINKER_LANGUAGE C
PUBLIC_HEADER "${libinc}")
set_target_properties(libconfig++
PROPERTIES LINKER_LANGUAGE CXX
PUBLIC_HEADER "${libinc_cpp}")
target_compile_definitions(libconfig
PRIVATE
_CRT_SECURE_NO_DEPRECATE
_STDLIB_H
YY_NO_UNISTD_H
YY_USE_CONST )
target_compile_definitions(libconfig++
PRIVATE
_CRT_SECURE_NO_DEPRECATE
_STDLIB_H
YY_NO_UNISTD_H
YY_USE_CONST )
if(CMAKE_HOST_WIN32)
target_link_libraries(libconfig Shlwapi.lib)
target_link_libraries(libconfig++ Shlwapi.lib)
endif()
install(TARGETS libconfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(TARGETS libconfig++
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
\ No newline at end of file
......@@ -68,6 +68,7 @@ void strbuf_append_char(strbuf_t *buf, char c)
strbuf_ensure_capacity(buf, 1);
*(buf->string + buf->length) = c;
++(buf->length);
*(buf->string + buf->length) = '\0';
}
/* ------------------------------------------------------------------------- */
add_executable(libconfig_tests
tests.c )
target_link_libraries(libconfig_tests
libconfig
libtinytest )
target_include_directories(libconfig_tests
PRIVATE ${CMAKE_SOURCE_DIR}/lib
${CMAKE_SOURCE_DIR}/tinytest )
add_test(NAME libconfig_tests COMMAND libconfig_tests)
\ No newline at end of file
escape_seqs:
{
str = "abc";
newline = "abc\ndef\n";
cr = "abc\rdef\r";
tab = "abc\tdef\t";
feed = "abc\fdef\f";
backslash = "abc\\def\\";
dquote = "abc\"def\"";
};
......@@ -119,6 +119,7 @@ static const char *read_file_to_string(const char *file)
size = stbuf.st_size;
buf = (char *)malloc(size + 1);
TT_ASSERT_PTR_NOTNULL(buf);
fp = fopen(file, "rt");
TT_ASSERT_PTR_NOTNULL(fp);
......@@ -436,6 +437,57 @@ TT_TEST(RemoveSetting)
/* ------------------------------------------------------------------------- */
TT_TEST(EscapedStrings)
{
config_t cfg;
config_setting_t* rc;
int ok;
const char* str;
config_init(&cfg);
config_set_include_dir(&cfg, "./testdata");
ok = config_read_file(&cfg, "testdata/strings.cfg");
if(!ok)
{
printf("error: %s:%d\n", config_error_text(&cfg),
config_error_line(&cfg));
}
TT_ASSERT_TRUE(ok);
ok = config_lookup_string(&cfg, "escape_seqs.str", &str);
TT_ASSERT_TRUE(ok);
TT_ASSERT_STR_EQ("abc", str);
ok = config_lookup_string(&cfg, "escape_seqs.newline", &str);
TT_ASSERT_TRUE(ok);
TT_ASSERT_STR_EQ("abc\ndef\n", str);
ok = config_lookup_string(&cfg, "escape_seqs.cr", &str);
TT_ASSERT_TRUE(ok);
TT_ASSERT_STR_EQ("abc\rdef\r", str);
ok = config_lookup_string(&cfg, "escape_seqs.tab", &str);
TT_ASSERT_TRUE(ok);
TT_ASSERT_STR_EQ("abc\tdef\t", str);
ok = config_lookup_string(&cfg, "escape_seqs.feed", &str);
TT_ASSERT_TRUE(ok);
TT_ASSERT_STR_EQ("abc\fdef\f", str);
ok = config_lookup_string(&cfg, "escape_seqs.backslash", &str);
TT_ASSERT_TRUE(ok);
TT_ASSERT_STR_EQ("abc\\def\\", str);
ok = config_lookup_string(&cfg, "escape_seqs.dquote", &str);
TT_ASSERT_TRUE(ok);
TT_ASSERT_STR_EQ("abc\"def\"", str);
config_destroy(&cfg);
}
/* ------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
int failures;
......@@ -452,6 +504,7 @@ int main(int argc, char **argv)
TT_SUITE_TEST(LibConfigTests, BigInt6);
TT_SUITE_TEST(LibConfigTests, BigInt7);
TT_SUITE_TEST(LibConfigTests, RemoveSetting);
TT_SUITE_TEST(LibConfigTests, EscapedStrings);
TT_SUITE_RUN(LibConfigTests);
failures = TT_SUITE_NUM_FAILURES(LibConfigTests);
TT_SUITE_END(LibConfigTests);
......
add_library(libtinytest STATIC
tinytest.h
tinytest.c)
if(CMAKE_HOST_WIN32)
if(MSVC)
set_target_properties(libtinytest
PROPERTIES
COMPILE_FLAGS "/wd4996"
)
endif()
endif()
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment