Skip to content

Commit

Permalink
chore: Add variable to control arg_rex debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
tomghuang committed May 18, 2020
1 parent 1e037c9 commit d1f6cde
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 95 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -37,6 +37,7 @@ project(${ARGTABLE3_PROJECT_NAME})

option(ARGTABLE3_ENABLE_CONAN "Enable Conan dependency manager" OFF)
option(ARGTABLE3_ENABLE_TESTS "Enable unit tests" ON)
option(ARGTABLE3_ENABLE_ARG_REX_DEBUG "Enable arg_rex debug output" OFF)
option(ARGTABLE3_BUILD_STATIC_EXAMPLES "Build examples with the static argtable3 library" OFF)

get_filename_component(VERSION_TAG_PATH "version.tag" ABSOLUTE)
Expand Down
4 changes: 4 additions & 0 deletions examples/CMakeLists.txt
Expand Up @@ -28,6 +28,10 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################

if(ARGTABLE3_ENABLE_ARG_REX_DEBUG)
add_compile_definitions(ARG_REX_DEBUG)
endif()

file(GLOB EXAMPLES_SOURCES RELATIVE ${PROJECT_SOURCE_DIR}/examples *.c)

if(UNIX)
Expand Down
8 changes: 6 additions & 2 deletions src/CMakeLists.txt
Expand Up @@ -43,7 +43,11 @@ else(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
endif()

add_definitions(-D_XOPEN_SOURCE=700)
if(ARGTABLE3_ENABLE_ARG_REX_DEBUG)
add_compile_definitions(ARG_REX_DEBUG)
endif()

add_compile_definitions(_XOPEN_SOURCE=700)

if(WIN32)
set(COMPANY_NAME "The Argtable3 Project")
Expand Down Expand Up @@ -83,7 +87,7 @@ install(TARGETS argtable3
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS argtable3_static
EXPORT ${ARGTABLE3_PACKAGE_NAME}Config
EXPORT ${ARGTABLE3_PACKAGE_NAME}Config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES "${PROJECT_SOURCE_DIR}/src/argtable3.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT ${ARGTABLE3_PACKAGE_NAME}Config DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR})
6 changes: 2 additions & 4 deletions src/arg_rex.c
Expand Up @@ -304,7 +304,7 @@ struct arg_rex* arg_rexn(const char* shortopts,
#define _SC(x) (x)
#endif

#ifdef _DEBUG
#ifdef ARG_REX_DEBUG
#include <stdio.h>

static const TRexChar* g_nnames[] = {_SC("NONE"), _SC("OP_GREEDY"), _SC("OP_OR"), _SC("OP_EXPR"), _SC("OP_NOCAPEXPR"),
Expand Down Expand Up @@ -912,12 +912,10 @@ TRex* trex_compile(const TRexChar* pattern, const TRexChar** error, int flags) {
exp->_nodes[exp->_first].left = res;
if (*exp->_p != '\0')
trex_error(exp, _SC("unexpected character"));
#ifdef _DEBUG
#ifdef ARG_REX_DEBUG
{
int nsize, i;
TRexNode* t;
nsize = exp->_nsize;
t = &exp->_nodes[0];
scprintf(_SC("\n"));
for (i = 0; i < nsize; i++) {
if (exp->_nodes[i].type > MAX_CHAR)
Expand Down
182 changes: 93 additions & 89 deletions tests/CMakeLists.txt
@@ -1,89 +1,93 @@
################################################################################
# This file is part of the argtable3 library.
#
# Copyright (C) 2016-2019 Tom G. Huang
# <tomghuang@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of STEWART HEITMANN nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################

set(TEST_PUBLIC_SRC_FILES
testall.c
testarglit.c
testargstr.c
testargint.c
testargdate.c
testargdbl.c
testargfile.c
testargrex.c
testargdstr.c
testargcmd.c
CuTest.c
)

set(TEST_SRC_FILES
${TEST_PUBLIC_SRC_FILES}
testarghashtable.c
)

if(UNIX)
set(ARGTABLE3_EXTRA_LIBS m)
endif()

add_executable(test_shared ${TEST_PUBLIC_SRC_FILES})
target_compile_definitions(test_shared PRIVATE -DARGTABLE3_TEST_PUBLIC_ONLY)
target_include_directories(test_shared PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(test_shared argtable3 ${ARGTABLE3_EXTRA_LIBS})
add_custom_command(TARGET test_shared POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:argtable3>"
"$<TARGET_FILE_DIR:test_shared>"
)

add_executable(test_static ${TEST_SRC_FILES})
target_compile_definitions(test_static PRIVATE -DARGTABLE3_TEST_PUBLIC_ONLY)
target_include_directories(test_static PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(test_static argtable3_static ${ARGTABLE3_EXTRA_LIBS})

add_executable(test_src ${TEST_SRC_FILES} ${ARGTABLE3_SRC_FILES})
target_include_directories(test_src PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(test_src ${ARGTABLE3_EXTRA_LIBS})

add_custom_command(OUTPUT ${ARGTABLE3_AMALGAMATION_SRC_FILE}
COMMAND "${PROJECT_SOURCE_DIR}/tools/build" dist
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/tools"
)

add_executable(test_amalgamation ${TEST_SRC_FILES} ${ARGTABLE3_AMALGAMATION_SRC_FILE})
target_include_directories(test_amalgamation PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(test_amalgamation ${ARGTABLE3_EXTRA_LIBS})
add_custom_command(TARGET test_amalgamation PRE_BUILD
COMMAND "${PROJECT_SOURCE_DIR}/tools/build" dist
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/tools"
)

add_test(NAME test_shared COMMAND "$<TARGET_FILE:test_shared>")
add_test(NAME test_static COMMAND "$<TARGET_FILE:test_static>")
add_test(NAME test_src COMMAND "$<TARGET_FILE:test_src>")
add_test(NAME test_amalgamation COMMAND "$<TARGET_FILE:test_amalgamation>")
################################################################################
# This file is part of the argtable3 library.
#
# Copyright (C) 2016-2019 Tom G. Huang
# <tomghuang@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of STEWART HEITMANN nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################

if(ARGTABLE3_ENABLE_ARG_REX_DEBUG)
add_compile_definitions(ARG_REX_DEBUG)
endif()

set(TEST_PUBLIC_SRC_FILES
testall.c
testarglit.c
testargstr.c
testargint.c
testargdate.c
testargdbl.c
testargfile.c
testargrex.c
testargdstr.c
testargcmd.c
CuTest.c
)

set(TEST_SRC_FILES
${TEST_PUBLIC_SRC_FILES}
testarghashtable.c
)

if(UNIX)
set(ARGTABLE3_EXTRA_LIBS m)
endif()

add_executable(test_shared ${TEST_PUBLIC_SRC_FILES})
target_compile_definitions(test_shared PRIVATE -DARGTABLE3_TEST_PUBLIC_ONLY)
target_include_directories(test_shared PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(test_shared argtable3 ${ARGTABLE3_EXTRA_LIBS})
add_custom_command(TARGET test_shared POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:argtable3>"
"$<TARGET_FILE_DIR:test_shared>"
)

add_executable(test_static ${TEST_SRC_FILES})
target_compile_definitions(test_static PRIVATE -DARGTABLE3_TEST_PUBLIC_ONLY)
target_include_directories(test_static PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(test_static argtable3_static ${ARGTABLE3_EXTRA_LIBS})

add_executable(test_src ${TEST_SRC_FILES} ${ARGTABLE3_SRC_FILES})
target_include_directories(test_src PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(test_src ${ARGTABLE3_EXTRA_LIBS})

add_custom_command(OUTPUT ${ARGTABLE3_AMALGAMATION_SRC_FILE}
COMMAND "${PROJECT_SOURCE_DIR}/tools/build" dist
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/tools"
)

add_executable(test_amalgamation ${TEST_SRC_FILES} ${ARGTABLE3_AMALGAMATION_SRC_FILE})
target_include_directories(test_amalgamation PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(test_amalgamation ${ARGTABLE3_EXTRA_LIBS})
add_custom_command(TARGET test_amalgamation PRE_BUILD
COMMAND "${PROJECT_SOURCE_DIR}/tools/build" dist
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/tools"
)

add_test(NAME test_shared COMMAND "$<TARGET_FILE:test_shared>")
add_test(NAME test_static COMMAND "$<TARGET_FILE:test_static>")
add_test(NAME test_src COMMAND "$<TARGET_FILE:test_src>")
add_test(NAME test_amalgamation COMMAND "$<TARGET_FILE:test_amalgamation>")

0 comments on commit d1f6cde

Please sign in to comment.