diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 626c5887b..ffa7965e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,7 +48,7 @@ jobs: linux: name: Ubuntu Latest GCC - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: fail-fast: true steps: @@ -90,7 +90,7 @@ jobs: linux_clang: name: Ubuntu Latest Clang - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: fail-fast: true steps: @@ -164,58 +164,64 @@ jobs: brlcad_linux: name: BRL-CAD Linux step-g Test - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: fail-fast: true steps: - name: Setup - CMake uses: lukka/get-cmake@latest - - name: Setup - Ninja - uses: seanmiddleditch/gha-setup-ninja@master - - name: Setup - System env: DEBIAN_FRONTEND: noninteractive run: | sudo apt-get update - # Install dev tools - sudo apt-get install re2c lemon + sudo apt-get install re2c astyle xsltproc libxml2-utils + sudo apt-get install xserver-xorg-dev libx11-dev libxi-dev libxext-dev libglu1-mesa-dev libfontconfig-dev + sudo apt-get install zlib1g-dev libpng-dev libjpeg-dev libtiff-dev libeigen3-dev libgdal-dev libassimp-dev libopencv-dev sudo apt-get clean - - name: Checkout + - name: Clone bext run: | - git clone --depth 1 https://github.com/BRL-CAD/brlcad.git -b main - cd brlcad/src/other/ext && rm -rf stepcode + git clone https://github.com/BRL-CAD/bext.git + cd bext/stepcode + cmake -E rm -r stepcode git clone --depth 1 https://github.com/stepcode/stepcode.git -b develop - # Ordinarily BRL-CAD keeps track of what files are supposed to be - # present in the repository. In this case we're not interested in - # updating the list to the working stepcode filelist, so use an empty - # list instead - echo "set(stepcode_ignore_files)" > stepcode.dist - cd ../../../../ + cd ../.. + + - name: Build bext + run: | + cmake -E make_directory bext_build + cmake -S bext -B bext_build -DCMAKE_BUILD_TYPE=Release -DUSE_GDAL=OFF -DUSE_TCL=OFF -DUSE_QT=OFF -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\bext_output + cmake --build bext_build --config Release -j2 + # We only need the build ouputs (bext_output) after this point, so + # clean up to save space for the main BRL-CAD build. + cmake -E rm -rf bext + cmake -E rm -rf bext_build + - name: Checkout + run: | + git clone --depth 1 https://github.com/BRL-CAD/brlcad.git -b main + - name: Configure run: | - export PATH=$ENV{GITHUB_WORKSPACE}:$PATH - cd brlcad - cmake -S . -G Ninja -B build -DENABLE_ALL=ON -DCMAKE_BUILD_TYPE=Release -DEXT_BUILD_VERBOSE=ON + cmake -E make_directory brlcad_build + cd brlcad_build + cmake -S ../brlcad -DBRLCAD_EXT_DIR=${{ github.workspace }}\bext_output -DBRLCAD_ENABLE_GDAL=OFF -DBRLCAD_ENABLE_TCL=OFF -DBRLCAD_ENABLE_QT=OFF -G Ninja cd .. - name: Build run: | - export PATH=$ENV{GITHUB_WORKSPACE}:$PATH - cd brlcad - cmake --build build --config Release --target step-g + cd brlcad_build + cmake --build . --target step-g cd .. - name: Test run: | - export PATH=$ENV{GITHUB_WORKSPACE}:$PATH - cd brlcad/build - ./bin/step-g ../db/nist/NIST_MBE_PMI_3.stp -o nist3.g - cd ../.. + cd brlcad_build + ./bin/step-g ../brlcad/db/nist/NIST_MBE_PMI_3.stp -o nist3.g + cd .. brlcad_windows: @@ -227,9 +233,6 @@ jobs: - name: Setup - CMake uses: lukka/get-cmake@latest - - name: Setup - Ninja - uses: seanmiddleditch/gha-setup-ninja@master - - name: Add github workspace to path # https://github.community/t/deprecated-add-path/136621 run: echo "$ENV{GITHUB_WORKSPACE}" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 @@ -240,38 +243,44 @@ jobs: - name: Add cl.exe to PATH uses: ilammy/msvc-dev-cmd@v1 - - name: Checkout + - name: Clone bext run: | - git clone --depth 1 https://github.com/BRL-CAD/brlcad.git -b main - cd brlcad/src/other/ext + git clone https://github.com/BRL-CAD/bext.git + cd bext/stepcode cmake -E rm -r stepcode git clone --depth 1 https://github.com/stepcode/stepcode.git -b develop - # Ordinarily BRL-CAD keeps track of what files are supposed to be - # present in the repository. In this case we're not interested in - # updating the list to the working stepcode filelist, so use an empty - # list instead - echo "set(stepcode_ignore_files)" > stepcode.dist - cd ../../../../ + cd ../.. + + - name: Build bext + shell: powershell + run: | + cmake -E make_directory bext_build + cmake -S bext -B bext_build -DCMAKE_BUILD_TYPE=Release -DUSE_GDAL=OFF -DUSE_TCL=OFF -DUSE_QT=OFF -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\bext_output + cmake --build bext_build --config Release -j2 + # We only need the build ouputs (bext_output) after this point, so + # clean up to save space for the main BRL-CAD build. + cmake -E rm -rf bext + cmake -E rm -rf bext_build + + + - name: Checkout + run: | + git clone --depth 1 https://github.com/BRL-CAD/brlcad.git -b main - name: Configure run: | - cd brlcad && cmake -S . -B build -G Ninja -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -DSC_ENABLE_TESTING=ON - cd .. - # We do the following in order to help ensure files are "flushed" - # to disk before compilation is attempted - # https://superuser.com/a/1553374/1286142 - powershell Write-VolumeCache C - powershell Write-VolumeCache D + cmake -E make_directory brlcad_build + cmake -S brlcad -B brlcad_build -DCMAKE_BUILD_TYPE=Release -DBRLCAD_EXT_DIR=${{ github.workspace }}\bext_output -DBRLCAD_ENABLE_GDAL=OFF -DBRLCAD_ENABLE_TCL=OFF -DBRLCAD_ENABLE_QT=OFF -G Ninja -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" - name: Build run: | - cd brlcad/build - ninja -j1 -v step-g - cd ../.. + cd brlcad_build + cmake --build . --config Release --target step-g + cd .. - name: Test run: | - cd brlcad/build - ./bin/step-g.exe ../db/nist/NIST_MBE_PMI_3.stp -o nist3.g - cd ../.. + cd brlcad_build + ./bin/step-g.exe ../brlcad/db/nist/NIST_MBE_PMI_3.stp -o nist3.g + cd .. diff --git a/.gitignore b/.gitignore index c39a631c2..1d9da5722 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ # Common build directories used in the source tree /build +/build-* /.build + # Temporary files *~ \#*\# diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d3f0b180..bced0837b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,6 @@ option(BUILD_STATIC_LIBS "Build static libraries" OFF) option(SC_PYTHON_GENERATOR "Compile exp2python" ON) option(SC_CPP_GENERATOR "Compile exp2cxx" ON) -option(SC_MEMMGR_ENABLE_CHECKS "Enable sc_memmgr's memory leak detection" OFF) option(SC_TRACE_FPRINTF "Enable extra comments in generated code so the code's source in exp2cxx may be located" OFF) option(SC_ENABLE_COVERAGE "Enable code coverage test" OFF) @@ -189,7 +188,6 @@ include_directories( ${SC_BINARY_DIR}/include ) -add_subdirectory(src/base) add_subdirectory(src/express) add_subdirectory(src/exppp) add_subdirectory(src/exp2cxx) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b8d1f443e..62e9503db 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,9 +11,12 @@ We love contributions! * Encouraged but not enforced: each commit should stand alone, in the sense that the code should compile and run at that point. * One major topic per pull request. Commits that fix small things (typos, formatting) are perfectly acceptable in a PR fixing a bug or adding a feature. * Tests are good. Tests are required unless you're fixing something simple or that was obviously broken. + * Do not change EXPRESS schema definition without reference to an upstream change. * Make your changes and push them to your GitHub repo * Once your branch is pushed, submit a pull request. -* We'll look at the PR and either merge or add feedback. If there isn't any activity within several days, send a message to the mailing list - `scl-dev` AT `groups.google.com`. + - enable github option on each PR 'Allow edits from maintainers', refer to github help if necessary +* We'll look at the PR and either merge (possibly after rebase) or add feedback. + - If there isn't any activity within several days send a message to the mailing list - `scl-dev` AT `groups.google.com`. ## Coding Standards diff --git a/ChangeLog b/ChangeLog index 39c815bb2..c319eed22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,7 +5,7 @@ This repo was moved and renamed in May 2012. Previously, it was at http://github.com/mpictor/StepClassLibrary Some are duplicates of changes recorded in the BRL-CAD repo: -http://brlcad.svn.sourceforge.net/viewvc/brlcad/brlcad/trunk/src/other/step/?view=log +https://github.com/BRL-CAD/brlcad/tree/158beae4556d94821938368951546384cba53107/src/other/ext/stepcode Pre-BRL-CAD changes: ************************************************************************ diff --git a/INSTALL b/INSTALL index 3060da905..7b61e14f9 100644 --- a/INSTALL +++ b/INSTALL @@ -51,7 +51,7 @@ Installation -DSC_BUILD_SCHEMAS=ALL - Added to make use of ctest easier. If SC_BUILD_SCHEMAS == ALL, then CMake adds each *.exp file found in data/. - -DSC_BUILD_TYPE=Release + -DCMAKE_BUILD_TYPE=Release - this causes binaries to be built without debugging information - without this, cmake defaults to a Debug build diff --git a/cmake/FindLEMON.cmake b/cmake/FindLEMON.cmake index 7ad58984e..83c63c487 100644 --- a/cmake/FindLEMON.cmake +++ b/cmake/FindLEMON.cmake @@ -141,7 +141,7 @@ if (LEMON_EXECUTABLE) # execute lemon add_custom_command( - OUTPUT ${_out_src_file} + OUTPUT ${_out_src_file} ${_basename}.h COMMAND ${LEMON_EXECUTABLE} -T${LEMON_TEMPLATE} ${LEMON_EXECUTABLE_opts} ${_in_y_file} DEPENDS ${Name}_input_cpy WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} @@ -152,7 +152,7 @@ if (LEMON_EXECUTABLE) add_custom_command( OUTPUT ${_out_hdr_file} COMMAND ${CMAKE_COMMAND} ARGS -E rename ${_basename}.h ${_out_hdr_file} - DEPENDS ${_out_src_file} + DEPENDS ${_out_src_file} ${_basename}.h WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) diff --git a/cmake/SC_CXX_schema_macros.cmake b/cmake/SC_CXX_schema_macros.cmake index 016450c2c..54e252c80 100644 --- a/cmake/SC_CXX_schema_macros.cmake +++ b/cmake/SC_CXX_schema_macros.cmake @@ -27,16 +27,16 @@ endmacro(P21_TESTS sfile) # create p21read_sdai_*, lazy_sdai_*, any exes listed in SC_SDAI_ADDITIONAL_EXES_SRCS macro(SCHEMA_EXES) RELATIVE_PATH_TO_TOPLEVEL(${CMAKE_CURRENT_SOURCE_DIR} RELATIVE_PATH_COMPONENT) - SC_ADDEXEC(p21read_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/test/p21read/p21read.cc" LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils base TESTABLE) + SC_ADDEXEC(p21read_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/test/p21read/p21read.cc;${RELATIVE_PATH_COMPONENT}/src/test/p21read/sc_benchmark.cc" LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils TESTABLE) if(NOT WIN32) - SC_ADDEXEC(lazy_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/cllazyfile/lazy_test.cc" LINK_LIBRARIES ${PROJECT_NAME} steplazyfile stepdai stepcore stepeditor steputils base TESTABLE) + SC_ADDEXEC(lazy_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/cllazyfile/lazy_test.cc;${RELATIVE_PATH_COMPONENT}/src/cllazyfile/sc_benchmark.cc" LINK_LIBRARIES ${PROJECT_NAME} steplazyfile stepdai stepcore stepeditor steputils TESTABLE) endif(NOT WIN32) #add user-defined executables foreach(src ${SC_SDAI_ADDITIONAL_EXES_SRCS}) get_filename_component(name ${src} NAME_WE) get_filename_component(path ${src} ABSOLUTE) - SC_ADDEXEC(${name}_${PROJECT_NAME} SOURCES ${src} LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils base TESTABLE) + SC_ADDEXEC(${name}_${PROJECT_NAME} SOURCES ${src} LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils TESTABLE) #set_target_properties(${name}_${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${${PROJECT_NAME}_COMPILE_FLAGS} -I${path}") endforeach(src ${SC_SDAI_ADDITIONAL_EXES_SRCS}) ENDMACRO(SCHEMA_EXES) @@ -89,12 +89,12 @@ macro(SCHEMA_TARGETS expFile schemaName sourceFiles) ) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${SC_SOURCE_DIR}/src/cldai ${SC_SOURCE_DIR}/src/cleditor - ${SC_SOURCE_DIR}/src/clutils ${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/base - ${SC_SOURCE_DIR}/src/base/judy/src + ${SC_SOURCE_DIR}/src/clutils ${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/cllazyfile + ${SC_SOURCE_DIR}/src/cllazyfile/judy/src ) - # if testing is enabled, "TESTABLE" sets property EXCLUDE_FROM_ALL and prevents installation + # Schema libraries should be installed by default if(BUILD_SHARED_LIBS) - SC_ADDLIB(${PROJECT_NAME} SHARED SOURCES ${sourceFiles} LINK_LIBRARIES stepdai stepcore stepeditor steputils base TESTABLE) + SC_ADDLIB(${PROJECT_NAME} SHARED SOURCES ${sourceFiles} LINK_LIBRARIES stepdai stepcore stepeditor steputils) add_dependencies(${PROJECT_NAME} generate_cpp_${PROJECT_NAME}) if(WIN32) target_compile_definitions("${PROJECT_NAME}" PRIVATE SC_SCHEMA_DLL_EXPORTS) @@ -110,10 +110,10 @@ macro(SCHEMA_TARGETS expFile schemaName sourceFiles) endif() endif() - if($CACHE{SC_BUILD_STATIC_LIBS}) - SC_ADDLIB(${PROJECT_NAME}-static STATIC SOURCES ${sourceFiles} LINK_LIBRARIES stepdai-static stepcore-static stepeditor-static steputils-static base-static TESTABLE) + if(BUILD_STATIC_LIBS) + SC_ADDLIB(${PROJECT_NAME}-static STATIC SOURCES ${sourceFiles} LINK_LIBRARIES stepdai-static stepcore-static stepeditor-static steputils-static) add_dependencies(${PROJECT_NAME}-static generate_cpp_${PROJECT_NAME}) - target_compile_defines("${PROJECT_NAME}-static" PRIVATE SC_STATIC) + target_compile_definitions("${PROJECT_NAME}-static" PRIVATE SC_STATIC) if(MSVC) target_compile_options("${PROJECT_NAME}-static" PRIVATE "/bigobj") endif() diff --git a/cmake/schema_scanner/CMakeLists.txt b/cmake/schema_scanner/CMakeLists.txt index 16219eb9a..20968ddb0 100644 --- a/cmake/schema_scanner/CMakeLists.txt +++ b/cmake/schema_scanner/CMakeLists.txt @@ -16,7 +16,6 @@ set(SC_BINARY_DIR ${SC_BUILDDIR}) include(${CMAKE_CURRENT_SOURCE_DIR}/../SC_Outdirs.cmake) set(schema_scanner_src - ${SC_ROOT}/src/base/sc_mkdir.c ${SC_ROOT}/src/exp2cxx/genCxxFilenames.c ${SC_ROOT}/src/exp2cxx/class_strings.c ${SC_ROOT}/src/express/generated/expparse.c @@ -52,7 +51,6 @@ include_directories( ${SC_ROOT}/include/ ${SC_ROOT}/src/express/ ${SC_ROOT}/src/express/generated - ${SC_ROOT}/src/base ${SC_ROOT}/src/exp2cxx ${SC_BUILDDIR}/include ) diff --git a/cmake/schema_scanner/schemaScanner.cc b/cmake/schema_scanner/schemaScanner.cc index 7f1d167c0..e37238415 100644 --- a/cmake/schema_scanner/schemaScanner.cc +++ b/cmake/schema_scanner/schemaScanner.cc @@ -14,20 +14,25 @@ */ extern "C" { -# include "expparse.h" -# include "expscan.h" -# include "express/scope.h" -# include "genCxxFilenames.h" -# include "sc_mkdir.h" - -# include - -# ifdef _WIN32 -# include -# define getcwd _getcwd -# else -# include -# endif +#define _XOPEN_SOURCE /* for S_IFDIR */ + +#include +#include +#include + +#include "expparse.h" +#include "expscan.h" +#include "express/scope.h" +#include "genCxxFilenames.h" + +#include + +#ifdef _WIN32 +# include +# define getcwd _getcwd +#else +# include +#endif } #include @@ -125,6 +130,30 @@ string makeShortName( const char * longName ) { return filename; } +/* cross-platform mkdir */ +int sc_mkdir( const char * path ) { + #ifdef _WIN32 + return mkdir( path ); + #else + return mkdir( path, 0777 ); + #endif /* _WIN32 */ +} + +/* return -1 if error, 0 if created, 1 if dir existed already */ +static int mkDirIfNone( const char * path ) { + struct stat s; + if( stat( path, &s ) != 0 ) { + if( errno == ENOENT ) { + return sc_mkdir( path ); + } + } else if( s.st_mode & S_IFDIR ) { + return 1; + } + /* either stat returned an error other than ENOENT, or 'path' exists but isn't a dir */ + return -1; +} + + /** write a CMakeLists.txt file for the schema; print its directory to stdout for CMake's add_subdirectory() command */ void writeLists( const char * schemaName, stringstream & eh, stringstream & ei, int ecount, stringstream & th, stringstream & ti, int tcount ) { diff --git a/ctest_matrix.cmake b/ctest_matrix.cmake index d2288acb5..d052e38aa 100644 --- a/ctest_matrix.cmake +++ b/ctest_matrix.cmake @@ -9,7 +9,7 @@ set(CTEST_INITIAL_CACHE " SITE:STRING=${CTEST_SITE} BUILDNAME:STRING=${CTEST_BUILD_NAME} SC_ENABLE_TESTING:BOOL=ON -SC_BUILD_TYPE:STRING=Debug +CMAKE_BUILD_TYPE:STRING=Debug ") diff --git a/example/ap203min/CMakeLists.txt b/example/ap203min/CMakeLists.txt index 52bbe7028..4f3682dd1 100644 --- a/example/ap203min/CMakeLists.txt +++ b/example/ap203min/CMakeLists.txt @@ -31,7 +31,6 @@ set(SC_IS_SUBBUILD TRUE) if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif(NOT DEFINED CMAKE_BUILD_TYPE) -set(SC_BUILD_TYPE ${CMAKE_BUILD_TYPE}) # Path to STEPcode set(STEPCODE_BUILD_DIR ${CMAKE_BINARY_DIR}/sc CACHE PATH "STEPcode build subdir") @@ -51,18 +50,13 @@ endif(NOT EXISTS ${SCHEMA_FILE}) get_filename_component(SCHEMA_SN ${SCHEMA_FILE} NAME) string(REGEX REPLACE "\(.*\).[Ee][Xx][Pp]" "sdai_\\1" SCHEMA_LINK_NAME ${SCHEMA_SN}) -set(STEPCODE_LIBRARIES base stepcore stepeditor stepdai steputils ${SCHEMA_LINK_NAME}) +set(STEPCODE_LIBRARIES stepcore stepeditor stepdai steputils ${SCHEMA_LINK_NAME}) # Add STEPCode project to CMake build. add_subdirectory(${STEPCODE_ROOT_DIR} "${CMAKE_CURRENT_BINARY_DIR}/sc" EXCLUDE_FROM_ALL) # Set up STEPcode include directories. set(STEPCODE_INCLUDE_DIR - ${STEPCODE_ROOT_DIR}/src/base - ${STEPCODE_ROOT_DIR}/src/clstepcore - ${STEPCODE_ROOT_DIR}/src/cldai - ${STEPCODE_ROOT_DIR}/src/clutils - ${STEPCODE_ROOT_DIR}/src/cleditor ${STEPCODE_BUILD_DIR}/include ${STEPCODE_ROOT_DIR}/include ${CMAKE_BINARY_DIR} diff --git a/example/ap203min/ExternalProjectBuild/CMakeLists.txt b/example/ap203min/ExternalProjectBuild/CMakeLists.txt index 3a5409088..45cce97e9 100644 --- a/example/ap203min/ExternalProjectBuild/CMakeLists.txt +++ b/example/ap203min/ExternalProjectBuild/CMakeLists.txt @@ -19,7 +19,6 @@ INCLUDE( External_STEPCode ) IF(NOT WIN32) set( STEPCODE_LIBRARIES - ${STEPCODE_INSTALL_DIR}/lib/libbase.a ${STEPCODE_INSTALL_DIR}/lib/libstepcore.a ${STEPCODE_INSTALL_DIR}/lib/libstepeditor.a ${STEPCODE_INSTALL_DIR}/lib/libstepdai.a @@ -28,7 +27,6 @@ IF(NOT WIN32) ) ELSE() set( STEPCODE_LIBRARIES - ${STEPCODE_INSTALL_DIR}/lib/libbase.lib ${STEPCODE_INSTALL_DIR}/lib/libstepcore.lib ${STEPCODE_INSTALL_DIR}/lib/libstepeditor.lib ${STEPCODE_INSTALL_DIR}/lib/libstepdai.lib @@ -44,7 +42,6 @@ MESSAGE( STATUS "STEPCODE_INSTALL_DIR: " ${STEPCODE_INSTALL_DIR} ) set( STEPCODE_INCLUDE_DIR ${STEPCODE_INSTALL_DIR}/include/stepcode -${STEPCODE_INSTALL_DIR}/include/stepcode/base ${STEPCODE_INSTALL_DIR}/include/stepcode/clstepcore ${STEPCODE_INSTALL_DIR}/include/stepcode/cldai ${STEPCODE_INSTALL_DIR}/include/stepcode/clutils diff --git a/example/ap203min/ExternalProjectBuild/cmake/External_STEPCode.cmake b/example/ap203min/ExternalProjectBuild/cmake/External_STEPCode.cmake index 96fca295b..08a5e306f 100644 --- a/example/ap203min/ExternalProjectBuild/cmake/External_STEPCode.cmake +++ b/example/ap203min/ExternalProjectBuild/cmake/External_STEPCode.cmake @@ -4,9 +4,9 @@ ExternalProject_Add( STEPCODE -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} - -DSC_BUILD_TYPE=Debug + -DCMAKE_BUILD_TYPE=Debug -DSC_BUILD_SCHEMAS=ap203/ap203.exp - -DSC_BUILD_STATIC_LIBS=ON + -DBUILD_STATIC_LIBS=ON -DSC_PYTHON_GENERATOR=OFF -DSC_INSTALL_PREFIX:PATH= ) diff --git a/example/ap203min/ap203min.cpp b/example/ap203min/ap203min.cpp index 5e05b7b59..1a6039f83 100644 --- a/example/ap203min/ap203min.cpp +++ b/example/ap203min/ap203min.cpp @@ -49,15 +49,15 @@ // $./AP203Minimum // AP203Minimum outfile.stp -#include -#include -#include -#include -#include -#include - -#include -#include +#include +#include +#include +#include +#include +#include + +#include +#include #include "schema.h" diff --git a/example/ap203min/include/config.h.in b/example/ap203min/include/config.h.in index 67d88c433..63ccc4ed1 100644 --- a/example/ap203min/include/config.h.in +++ b/example/ap203min/include/config.h.in @@ -15,7 +15,6 @@ #cmakedefine HAVE_IO_H 1 #cmakedefine SC_TRACE_FPRINTF 1 -#cmakedefine SC_MEMMGR_ENABLE_CHECKS 1 #cmakedefine HAVE_ABS 1 #cmakedefine HAVE_MEMCPY 1 diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 9ad25faeb..5f39f0ba9 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -37,6 +37,12 @@ install(FILES ordered_attrs.h install(FILES ${SC_BINARY_DIR}/${INCLUDE_DIR}/config.h DESTINATION ${INCLUDE_DIR}/stepcode) +add_subdirectory(cldai) +add_subdirectory(cleditor) +add_subdirectory(cllazyfile) +add_subdirectory(clstepcore) +add_subdirectory(clutils) + # Local Variables: # tab-width: 8 # mode: cmake diff --git a/include/cldai/CMakeLists.txt b/include/cldai/CMakeLists.txt new file mode 100644 index 000000000..471671fbd --- /dev/null +++ b/include/cldai/CMakeLists.txt @@ -0,0 +1,24 @@ +set(DAI_HDRS + sdaiApplication_instance_set.h + sdaiBinary.h + sdaiDaObject.h + sdaiEntity_extent.h + sdaiEntity_extent_set.h + sdaiEnum.h + sdaiModel_contents.h + sdaiModel_contents_list.h + sdaiObject.h + sdaiSession_instance.h + sdaiString.h + ) + +install(FILES ${DAI_HDRS} + DESTINATION ${INCLUDE_DIR}/stepcode/cldai) + +# Local Variables: +# tab-width: 8 +# mode: cmake +# indent-tabs-mode: t +# End: +# ex: shiftwidth=2 tabstop=8 + diff --git a/src/cldai/sdaiApplication_instance_set.h b/include/cldai/sdaiApplication_instance_set.h similarity index 100% rename from src/cldai/sdaiApplication_instance_set.h rename to include/cldai/sdaiApplication_instance_set.h diff --git a/src/cldai/sdaiBinary.h b/include/cldai/sdaiBinary.h similarity index 100% rename from src/cldai/sdaiBinary.h rename to include/cldai/sdaiBinary.h diff --git a/src/cldai/sdaiDaObject.h b/include/cldai/sdaiDaObject.h similarity index 99% rename from src/cldai/sdaiDaObject.h rename to include/cldai/sdaiDaObject.h index 168c7bfbc..3bb0c20f4 100644 --- a/src/cldai/sdaiDaObject.h +++ b/include/cldai/sdaiDaObject.h @@ -1,9 +1,9 @@ #ifndef SDAIDAOBJECT_H #define SDAIDAOBJECT_H 1 -#include -#include -#include +#include "cldai/sdaiObject.h" +#include "cldai/sdaiString.h" +#include "cldai/sdaiEnum.h" #include diff --git a/src/cldai/sdaiEntity_extent.h b/include/cldai/sdaiEntity_extent.h similarity index 100% rename from src/cldai/sdaiEntity_extent.h rename to include/cldai/sdaiEntity_extent.h diff --git a/src/cldai/sdaiEntity_extent_set.h b/include/cldai/sdaiEntity_extent_set.h similarity index 100% rename from src/cldai/sdaiEntity_extent_set.h rename to include/cldai/sdaiEntity_extent_set.h diff --git a/src/cldai/sdaiEnum.h b/include/cldai/sdaiEnum.h similarity index 100% rename from src/cldai/sdaiEnum.h rename to include/cldai/sdaiEnum.h diff --git a/src/cldai/sdaiModel_contents.h b/include/cldai/sdaiModel_contents.h similarity index 100% rename from src/cldai/sdaiModel_contents.h rename to include/cldai/sdaiModel_contents.h diff --git a/src/cldai/sdaiModel_contents_list.h b/include/cldai/sdaiModel_contents_list.h similarity index 100% rename from src/cldai/sdaiModel_contents_list.h rename to include/cldai/sdaiModel_contents_list.h diff --git a/src/cldai/sdaiObject.h b/include/cldai/sdaiObject.h similarity index 100% rename from src/cldai/sdaiObject.h rename to include/cldai/sdaiObject.h diff --git a/src/cldai/sdaiSession_instance.h b/include/cldai/sdaiSession_instance.h similarity index 94% rename from src/cldai/sdaiSession_instance.h rename to include/cldai/sdaiSession_instance.h index fcc8fad15..7aa9a1502 100644 --- a/src/cldai/sdaiSession_instance.h +++ b/include/cldai/sdaiSession_instance.h @@ -3,7 +3,7 @@ #define SESSION_INSTANCE_H 1 #include -//#include +//#include "clstepcore/sdai.h" class SC_DAI_EXPORT SDAI_Session_instance : public SDAI_sdaiObject { diff --git a/src/cldai/sdaiString.h b/include/cldai/sdaiString.h similarity index 100% rename from src/cldai/sdaiString.h rename to include/cldai/sdaiString.h diff --git a/include/cleditor/CMakeLists.txt b/include/cleditor/CMakeLists.txt new file mode 100644 index 000000000..1d128c8fa --- /dev/null +++ b/include/cleditor/CMakeLists.txt @@ -0,0 +1,20 @@ +set(EDITOR_HDRS + STEPfile.h + cmdmgr.h + editordefines.h + SdaiHeaderSchema.h + SdaiHeaderSchemaClasses.h + SdaiSchemaInit.h + seeinfodefault.h + ) + +install(FILES ${EDITOR_HDRS} + DESTINATION ${INCLUDE_DIR}/stepcode/cleditor) + +# Local Variables: +# tab-width: 8 +# mode: cmake +# indent-tabs-mode: t +# End: +# ex: shiftwidth=2 tabstop=8 + diff --git a/src/cleditor/STEPfile.h b/include/cleditor/STEPfile.h similarity index 98% rename from src/cleditor/STEPfile.h rename to include/cleditor/STEPfile.h index 37c7d20bc..1ecfb67c2 100644 --- a/src/cleditor/STEPfile.h +++ b/include/cleditor/STEPfile.h @@ -15,14 +15,14 @@ #include #include -#include -#include +#include "clstepcore/instmgr.h" +#include "clstepcore/Registry.h" #include -#include -#include +#include "clutils/dirobj.h" +#include "clutils/errordesc.h" #include -#include +#include "clstepcore/read_func.h" //error reporting level #define READ_COMPLETE 10 diff --git a/src/cleditor/SdaiHeaderSchema.h b/include/cleditor/SdaiHeaderSchema.h similarity index 97% rename from src/cleditor/SdaiHeaderSchema.h rename to include/cleditor/SdaiHeaderSchema.h index 7cd45d848..5979202f0 100644 --- a/src/cleditor/SdaiHeaderSchema.h +++ b/include/cleditor/SdaiHeaderSchema.h @@ -5,11 +5,11 @@ // regenerate it. #include -#include -#include -#include -#include -#include +#include "clstepcore/sdai.h" +#include "clstepcore/Registry.h" +#include "clstepcore/STEPaggregate.h" +#include "cleditor/SdaiHeaderSchemaClasses.h" +#include "cleditor/SdaiSchemaInit.h" ///////// ENTITY section_language diff --git a/src/cleditor/SdaiHeaderSchemaClasses.h b/include/cleditor/SdaiHeaderSchemaClasses.h similarity index 100% rename from src/cleditor/SdaiHeaderSchemaClasses.h rename to include/cleditor/SdaiHeaderSchemaClasses.h diff --git a/src/cleditor/SdaiSchemaInit.h b/include/cleditor/SdaiSchemaInit.h similarity index 60% rename from src/cleditor/SdaiSchemaInit.h rename to include/cleditor/SdaiSchemaInit.h index a0868fbc6..862f297bd 100644 --- a/src/cleditor/SdaiSchemaInit.h +++ b/include/cleditor/SdaiSchemaInit.h @@ -9,16 +9,16 @@ #endif #include -#include -#include -#include -#include -#include -#include -#include +#include "clstepcore/sdai.h" +#include "clstepcore/Registry.h" +#include "clstepcore/STEPaggregate.h" +#include "clstepcore/STEPundefined.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/complexSupport.h" -#include -#include +#include "cleditor/SdaiHeaderSchemaClasses.h" +#include "cleditor/SdaiHeaderSchema.h" SC_EDITOR_EXPORT void HeaderSchemaInit( Registry & ); SC_EDITOR_EXPORT void HeaderInitSchemasAndEnts( Registry & ); diff --git a/src/cleditor/cmdmgr.h b/include/cleditor/cmdmgr.h similarity index 94% rename from src/cleditor/cmdmgr.h rename to include/cleditor/cmdmgr.h index c9c45b404..4f420467b 100644 --- a/src/cleditor/cmdmgr.h +++ b/include/cleditor/cmdmgr.h @@ -13,16 +13,16 @@ */ #include -#include -#include -#include - -#include -#include -#include -#include -#include -#include +#include "clutils/gennode.h" +#include "clutils/gennodelist.h" +#include "clutils/gennodearray.h" + +#include "cleditor/editordefines.h" +#include "clstepcore/mgrnode.h" +#include "clstepcore/mgrnodelist.h" +#include "clstepcore/dispnode.h" +#include "clstepcore/dispnodelist.h" +#include "clstepcore/SingleLinkList.h" //#define NUM_CMDMGR_CMDS 9 // this is the number of columns that contain cmds (as opposed diff --git a/src/cleditor/editordefines.h b/include/cleditor/editordefines.h similarity index 100% rename from src/cleditor/editordefines.h rename to include/cleditor/editordefines.h diff --git a/src/cleditor/seeinfodefault.h b/include/cleditor/seeinfodefault.h similarity index 94% rename from src/cleditor/seeinfodefault.h rename to include/cleditor/seeinfodefault.h index 51198eac8..202c5eb1a 100644 --- a/src/cleditor/seeinfodefault.h +++ b/include/cleditor/seeinfodefault.h @@ -20,10 +20,10 @@ class MgrNode; class DisplayNode; class DisplayNodelist; -#include +#include "clstepcore/sdai.h" //class SDAI_Application_instance; -#include +#include "cleditor/editordefines.h" class SC_EDITOR_EXPORT seeInfo : public DisplayNode { public: diff --git a/include/cllazyfile/CMakeLists.txt b/include/cllazyfile/CMakeLists.txt new file mode 100644 index 000000000..853aa98b9 --- /dev/null +++ b/include/cllazyfile/CMakeLists.txt @@ -0,0 +1,27 @@ +set(LAZY_HDRS + headerSectionReader.h + lazyFileReader.h + lazyP21DataSectionReader.h + p21HeaderSectionReader.h + lazyDataSectionReader.h + lazyInstMgr.h + lazyTypes.h + sectionReader.h + instMgrHelper.h + judy.h + judyL2Array.h + judyLArray.h + judyS2Array.h + judySArray.h + ) + +install(FILES ${LAZY_HDRS} + DESTINATION ${INCLUDE_DIR}/stepcode/cllazyfile) + +# Local Variables: +# tab-width: 8 +# mode: cmake +# indent-tabs-mode: t +# End: +# ex: shiftwidth=2 tabstop=8 + diff --git a/src/cllazyfile/headerSectionReader.h b/include/cllazyfile/headerSectionReader.h similarity index 90% rename from src/cllazyfile/headerSectionReader.h rename to include/cllazyfile/headerSectionReader.h index 1e42d0440..e3a9f5725 100644 --- a/src/cllazyfile/headerSectionReader.h +++ b/include/cllazyfile/headerSectionReader.h @@ -5,10 +5,9 @@ #include #include "judyL2Array.h" -#include "lazyFileReader.h" -#include "sectionReader.h" -#include "lazyTypes.h" -#include "sc_memmgr.h" +#include "cllazyfile/lazyFileReader.h" +#include "cllazyfile/sectionReader.h" +#include "cllazyfile/lazyTypes.h" #include "sc_export.h" diff --git a/src/cllazyfile/instMgrHelper.h b/include/cllazyfile/instMgrHelper.h similarity index 94% rename from src/cllazyfile/instMgrHelper.h rename to include/cllazyfile/instMgrHelper.h index 659f1ec8e..1af698160 100644 --- a/src/cllazyfile/instMgrHelper.h +++ b/include/cllazyfile/instMgrHelper.h @@ -3,9 +3,9 @@ #include -#include -#include -#include +#include "clstepcore/mgrnode.h" +#include "cllazyfile/lazyInstMgr.h" +#include "clstepcore/instmgr.h" /** * \file instMgrHelper.h helper classes for the lazyInstMgr. Allows use of SDAI_Application_instance class diff --git a/src/base/judy/src/judy.h b/include/cllazyfile/judy.h similarity index 100% rename from src/base/judy/src/judy.h rename to include/cllazyfile/judy.h diff --git a/src/base/judy/src/judyL2Array.h b/include/cllazyfile/judyL2Array.h similarity index 100% rename from src/base/judy/src/judyL2Array.h rename to include/cllazyfile/judyL2Array.h diff --git a/src/base/judy/src/judyLArray.h b/include/cllazyfile/judyLArray.h similarity index 100% rename from src/base/judy/src/judyLArray.h rename to include/cllazyfile/judyLArray.h diff --git a/src/base/judy/src/judyS2Array.h b/include/cllazyfile/judyS2Array.h similarity index 97% rename from src/base/judy/src/judyS2Array.h rename to include/cllazyfile/judyS2Array.h index 726a6449a..c9b25db35 100644 --- a/src/base/judy/src/judyS2Array.h +++ b/include/cllazyfile/judyS2Array.h @@ -51,8 +51,8 @@ class judyS2Array { explicit judyS2Array( const judyS2Array< JudyValue > & other ): _maxKeyLen( other._maxKeyLen ), _success( other._success ) { _judyarray = judy_clone( other._judyarray ); _buff = new unsigned char[_maxKeyLen]; - strncpy( _buff, other._buff, _maxKeyLen ); - _buff[ _maxKeyLen ] = '\0'; //ensure that _buff is null-terminated, since strncpy won't necessarily do so + strncpy( reinterpret_cast< char * >( _buff ), reinterpret_cast< const char * >( other._buff ), _maxKeyLen - 1 ); + _buff[ _maxKeyLen - 1 ] = '\0'; //ensure that _buff is null-terminated find( _buff ); //set _lastSlot } diff --git a/src/base/judy/src/judySArray.h b/include/cllazyfile/judySArray.h similarity index 96% rename from src/base/judy/src/judySArray.h rename to include/cllazyfile/judySArray.h index db75ec91c..f95716ec8 100644 --- a/src/base/judy/src/judySArray.h +++ b/include/cllazyfile/judySArray.h @@ -39,8 +39,8 @@ class judySArray { explicit judySArray( const judySArray< JudyValue > & other ): _maxKeyLen( other._maxKeyLen ), _success( other._success ) { _judyarray = judy_clone( other._judyarray ); _buff = new unsigned char[_maxKeyLen]; - strncpy( _buff, other._buff, _maxKeyLen ); - _buff[ _maxKeyLen ] = '\0'; //ensure that _buff is null-terminated, since strncpy won't necessarily do so + strncpy( reinterpret_cast< char * >( _buff ), reinterpret_cast< const char * >( other._buff ), _maxKeyLen - 1 ); + _buff[ _maxKeyLen - 1 ] = '\0'; //ensure that _buff is null-terminated find( _buff ); //set _lastSlot } diff --git a/src/cllazyfile/lazyDataSectionReader.h b/include/cllazyfile/lazyDataSectionReader.h similarity index 92% rename from src/cllazyfile/lazyDataSectionReader.h rename to include/cllazyfile/lazyDataSectionReader.h index f2dc9dee4..6fad4e0b8 100644 --- a/src/cllazyfile/lazyDataSectionReader.h +++ b/include/cllazyfile/lazyDataSectionReader.h @@ -3,9 +3,8 @@ #include #include -#include "sectionReader.h" -#include "lazyTypes.h" -#include "sc_memmgr.h" +#include "cllazyfile/sectionReader.h" +#include "cllazyfile/lazyTypes.h" #include "sc_export.h" diff --git a/src/cllazyfile/lazyFileReader.h b/include/cllazyfile/lazyFileReader.h similarity index 90% rename from src/cllazyfile/lazyFileReader.h rename to include/cllazyfile/lazyFileReader.h index 49eea5b50..9a5fccb5e 100644 --- a/src/cllazyfile/lazyFileReader.h +++ b/include/cllazyfile/lazyFileReader.h @@ -8,16 +8,14 @@ #include "sc_export.h" // PART 21 -#include "lazyP21DataSectionReader.h" -#include "p21HeaderSectionReader.h" -#include "headerSectionReader.h" +#include "cllazyfile/lazyP21DataSectionReader.h" +#include "cllazyfile/p21HeaderSectionReader.h" +#include "cllazyfile/headerSectionReader.h" /* // PART 28 * #include "lazyP28DataSectionReader.h" * #include "p28HeaderSectionReader.h" */ -#include "sc_memmgr.h" - class lazyInstMgr; class Registry; class headerSectionReader; diff --git a/src/cllazyfile/lazyInstMgr.h b/include/cllazyfile/lazyInstMgr.h similarity index 98% rename from src/cllazyfile/lazyInstMgr.h rename to include/cllazyfile/lazyInstMgr.h index 78444a756..e3445660a 100644 --- a/src/cllazyfile/lazyInstMgr.h +++ b/include/cllazyfile/lazyInstMgr.h @@ -5,12 +5,11 @@ #include #include -#include "lazyDataSectionReader.h" -#include "lazyFileReader.h" -#include "lazyTypes.h" +#include "cllazyfile/lazyDataSectionReader.h" +#include "cllazyfile/lazyFileReader.h" +#include "cllazyfile/lazyTypes.h" -#include "Registry.h" -#include "sc_memmgr.h" +#include "clstepcore/Registry.h" #include "sc_export.h" #include "judyLArray.h" diff --git a/src/cllazyfile/lazyP21DataSectionReader.h b/include/cllazyfile/lazyP21DataSectionReader.h similarity index 89% rename from src/cllazyfile/lazyP21DataSectionReader.h rename to include/cllazyfile/lazyP21DataSectionReader.h index 423679142..c14376fc0 100644 --- a/src/cllazyfile/lazyP21DataSectionReader.h +++ b/include/cllazyfile/lazyP21DataSectionReader.h @@ -1,9 +1,8 @@ #ifndef LAZYP21DATASECTIONREADER_H #define LAZYP21DATASECTIONREADER_H -#include "lazyDataSectionReader.h" -#include "lazyFileReader.h" -#include "sc_memmgr.h" +#include "cllazyfile/lazyDataSectionReader.h" +#include "cllazyfile/lazyFileReader.h" #include "sc_export.h" class SC_LAZYFILE_EXPORT lazyP21DataSectionReader: public lazyDataSectionReader { diff --git a/src/cllazyfile/lazyTypes.h b/include/cllazyfile/lazyTypes.h similarity index 100% rename from src/cllazyfile/lazyTypes.h rename to include/cllazyfile/lazyTypes.h diff --git a/src/cllazyfile/p21HeaderSectionReader.h b/include/cllazyfile/p21HeaderSectionReader.h similarity index 91% rename from src/cllazyfile/p21HeaderSectionReader.h rename to include/cllazyfile/p21HeaderSectionReader.h index b5ce04948..ab91fb2bd 100644 --- a/src/cllazyfile/p21HeaderSectionReader.h +++ b/include/cllazyfile/p21HeaderSectionReader.h @@ -1,8 +1,7 @@ #ifndef P21HEADERSECTIONREADER_H #define P21HEADERSECTIONREADER_H -#include "headerSectionReader.h" -#include "sc_memmgr.h" +#include "cllazyfile/headerSectionReader.h" #include "sc_export.h" class SC_LAZYFILE_EXPORT p21HeaderSectionReader: public headerSectionReader { diff --git a/src/cllazyfile/sectionReader.h b/include/cllazyfile/sectionReader.h similarity index 97% rename from src/cllazyfile/sectionReader.h rename to include/cllazyfile/sectionReader.h index 88c5e1ceb..74f1fa5bf 100644 --- a/src/cllazyfile/sectionReader.h +++ b/include/cllazyfile/sectionReader.h @@ -3,11 +3,10 @@ #include #include -#include "lazyTypes.h" -#include "sc_memmgr.h" +#include "cllazyfile/lazyTypes.h" #include "sc_export.h" -#include "errordesc.h" -#include "STEPcomplex.h" +#include "clutils/errordesc.h" +#include "clstepcore/STEPcomplex.h" class SDAI_Application_instance; class lazyFileReader; diff --git a/include/clstepcore/CMakeLists.txt b/include/clstepcore/CMakeLists.txt new file mode 100644 index 000000000..a8447cea3 --- /dev/null +++ b/include/clstepcore/CMakeLists.txt @@ -0,0 +1,71 @@ +set(CORE_HDRS + aggrTypeDescriptor.h + attrDescriptor.h + attrDescriptorList.h + baseType.h + complexSupport.h + create_Aggr.h + derivedAttribute.h + dictSchema.h + dictdefs.h + dictionaryInstance.h + dispnode.h + dispnodelist.h + entityDescriptor.h + entityDescriptorList.h + enumTypeDescriptor.h + ExpDict.h + explicitItemId.h + globalRule.h + implicitItemId.h + instmgr.h + interfaceSpec.h + interfacedItem.h + inverseAttribute.h + inverseAttributeList.h + mgrnode.h + mgrnodearray.h + mgrnodelist.h + needFunc.h + read_func.h + realTypeDescriptor.h + Registry.h + schRename.h + sdai.h + sdaiApplication_instance.h + sdaiSelect.h + selectTypeDescriptor.h + SingleLinkList.h + STEPaggregate.h + STEPaggrBinary.h + STEPaggrEntity.h + STEPaggrEnum.h + STEPaggrGeneric.h + STEPaggrInt.h + STEPaggrReal.h + STEPaggrSelect.h + STEPaggrString.h + STEPattribute.h + STEPattributeList.h + STEPcomplex.h + STEPinvAttrList.h + STEPundefined.h + stringTypeDescriptor.h + SubSuperIterators.h + typeDescriptor.h + typeDescriptorList.h + typeOrRuleVar.h + uniquenessRule.h + whereRule.h +) + +install(FILES ${CORE_HDRS} + DESTINATION ${INCLUDE_DIR}/stepcode/clstepcore) + +# Local Variables: +# tab-width: 8 +# mode: cmake +# indent-tabs-mode: t +# End: +# ex: shiftwidth=2 tabstop=8 + diff --git a/src/clstepcore/ExpDict.h b/include/clstepcore/ExpDict.h similarity index 70% rename from src/clstepcore/ExpDict.h rename to include/clstepcore/ExpDict.h index e73b8dd01..c8c71258b 100644 --- a/src/clstepcore/ExpDict.h +++ b/include/clstepcore/ExpDict.h @@ -15,20 +15,20 @@ */ #include -#include +#include "clstepcore/sdai.h" #include #include #include -#include +#include "clstepcore/SingleLinkList.h" -#include -#include -#include +#include "clstepcore/baseType.h" +#include "clstepcore/dictdefs.h" +#include "clutils/Str.h" // each of these contains linked list, list node, iterator -#include "attrDescriptorList.h" +#include "clstepcore/attrDescriptorList.h" #include "inverseAttributeList.h" #include "typeDescriptorList.h" #include "entityDescriptorList.h" @@ -37,12 +37,12 @@ #include "typeDescriptor.h" #include "entityDescriptor.h" #include "enumTypeDescriptor.h" -#include "attrDescriptor.h" -#include "derivedAttribute.h" +#include "clstepcore/attrDescriptor.h" +#include "clstepcore/derivedAttribute.h" #include "inverseAttribute.h" -#include "create_Aggr.h" -#include "dictionaryInstance.h" +#include "clstepcore/create_Aggr.h" +#include "clstepcore/dictionaryInstance.h" #include "uniquenessRule.h" #include "whereRule.h" @@ -53,10 +53,10 @@ #include "interfaceSpec.h" #include "typeOrRuleVar.h" #include "globalRule.h" -#include "dictSchema.h" +#include "clstepcore/dictSchema.h" #include "schRename.h" -#include "aggrTypeDescriptor.h" +#include "clstepcore/aggrTypeDescriptor.h" #include "selectTypeDescriptor.h" #include "stringTypeDescriptor.h" #include "realTypeDescriptor.h" diff --git a/src/clstepcore/Registry.h b/include/clstepcore/Registry.h similarity index 95% rename from src/clstepcore/Registry.h rename to include/clstepcore/Registry.h index d4d4d4db0..099015686 100644 --- a/src/clstepcore/Registry.h +++ b/include/clstepcore/Registry.h @@ -13,11 +13,11 @@ */ #include -#include -#include -#include -#include -#include +#include "clstepcore/sdai.h" +#include "clutils/errordesc.h" +#include "clutils/sc_hash.h" +#include "clutils/Str.h" +#include "clstepcore/complexSupport.h" // defined and created in Registry.cc diff --git a/src/clstepcore/STEPaggrBinary.h b/include/clstepcore/STEPaggrBinary.h similarity index 97% rename from src/clstepcore/STEPaggrBinary.h rename to include/clstepcore/STEPaggrBinary.h index cd4991bbb..59ea61ab5 100644 --- a/src/clstepcore/STEPaggrBinary.h +++ b/include/clstepcore/STEPaggrBinary.h @@ -1,7 +1,7 @@ #ifndef STEPAGGRBINARY_H #define STEPAGGRBINARY_H -#include "STEPaggregate.h" +#include "clstepcore/STEPaggregate.h" #include /** \file STEPaggrBinary.h diff --git a/src/clstepcore/STEPaggrEntity.h b/include/clstepcore/STEPaggrEntity.h similarity index 98% rename from src/clstepcore/STEPaggrEntity.h rename to include/clstepcore/STEPaggrEntity.h index f18bc3d0f..8338fc8f8 100644 --- a/src/clstepcore/STEPaggrEntity.h +++ b/include/clstepcore/STEPaggrEntity.h @@ -5,7 +5,7 @@ * classes EntityAggregate, EntityNode */ -#include "STEPaggregate.h" +#include "clstepcore/STEPaggregate.h" #include class SC_CORE_EXPORT EntityAggregate : public STEPaggregate { diff --git a/src/clstepcore/STEPaggrEnum.h b/include/clstepcore/STEPaggrEnum.h similarity index 92% rename from src/clstepcore/STEPaggrEnum.h rename to include/clstepcore/STEPaggrEnum.h index 161706a48..cf16fb0e6 100644 --- a/src/clstepcore/STEPaggrEnum.h +++ b/include/clstepcore/STEPaggrEnum.h @@ -1,7 +1,7 @@ #ifndef STEPAGGRENUM_H #define STEPAGGRENUM_H -#include "STEPaggregate.h" +#include "clstepcore/STEPaggregate.h" #include "sc_export.h" /** \file StepaggrEnum.h * classes EnumAggregate, LOGICALS, BOOLEANS, EnumNode @@ -9,7 +9,7 @@ /** * \class EnumAggregate - * This is a minimal representions for a collection of SDAI_Enum + * This is a minimal representation for a collection of SDAI_Enum */ class SC_CORE_EXPORT EnumAggregate : public STEPaggregate { public: @@ -55,7 +55,7 @@ SC_CORE_EXPORT BOOLEANS * create_BOOLEANS(); /** * * \class EnumNode - ** This is a minimal representions for node in lists of SDAI_Enum + ** This is a minimal representation for node in lists of SDAI_Enum */ class SC_CORE_EXPORT EnumNode : public STEPnode { public: diff --git a/src/clstepcore/STEPaggrGeneric.h b/include/clstepcore/STEPaggrGeneric.h similarity index 97% rename from src/clstepcore/STEPaggrGeneric.h rename to include/clstepcore/STEPaggrGeneric.h index 76190406e..ecb286d00 100644 --- a/src/clstepcore/STEPaggrGeneric.h +++ b/include/clstepcore/STEPaggrGeneric.h @@ -1,7 +1,7 @@ #ifndef STEPAGGRGENERIC_H #define STEPAGGRGENERIC_H -#include "STEPaggregate.h" +#include "clstepcore/STEPaggregate.h" #include /** \file STEPaggrGeneric.h diff --git a/src/clstepcore/STEPaggrInt.h b/include/clstepcore/STEPaggrInt.h similarity index 97% rename from src/clstepcore/STEPaggrInt.h rename to include/clstepcore/STEPaggrInt.h index 726d07c0e..11bf57464 100644 --- a/src/clstepcore/STEPaggrInt.h +++ b/include/clstepcore/STEPaggrInt.h @@ -1,7 +1,7 @@ #ifndef STEPAGGRINT_H #define STEPAGGRINT_H -#include "STEPaggregate.h" +#include "clstepcore/STEPaggregate.h" #include class SC_CORE_EXPORT IntAggregate : public STEPaggregate { diff --git a/src/clstepcore/STEPaggrReal.h b/include/clstepcore/STEPaggrReal.h similarity index 97% rename from src/clstepcore/STEPaggrReal.h rename to include/clstepcore/STEPaggrReal.h index 48cd90e51..920c98907 100644 --- a/src/clstepcore/STEPaggrReal.h +++ b/include/clstepcore/STEPaggrReal.h @@ -1,7 +1,7 @@ #ifndef STEPAGGRREAL_H #define STEPAGGRREAL_H -#include "STEPaggregate.h" +#include "clstepcore/STEPaggregate.h" #include class SC_CORE_EXPORT RealAggregate : public STEPaggregate { diff --git a/src/clstepcore/STEPaggrSelect.h b/include/clstepcore/STEPaggrSelect.h similarity index 95% rename from src/clstepcore/STEPaggrSelect.h rename to include/clstepcore/STEPaggrSelect.h index b62a9c3fe..dd6621caa 100644 --- a/src/clstepcore/STEPaggrSelect.h +++ b/include/clstepcore/STEPaggrSelect.h @@ -1,7 +1,7 @@ #ifndef STEPAGGRSELECT_H #define STEPAGGRSELECT_H -#include "STEPaggregate.h" +#include "clstepcore/STEPaggregate.h" #include /** \file STEPaggrSelect.h @@ -11,7 +11,7 @@ /** * * \class SelectAggregate - ** This is a minimal represention for a collection of SDAI_Select + ** This is a minimal representation for a collection of SDAI_Select */ class SC_CORE_EXPORT SelectAggregate : public STEPaggregate { public: @@ -35,7 +35,7 @@ typedef SelectAggregate_ptr SelectAggregate_var; /** * * \class SelectNode - ** This is a minimal representions for node in lists of SDAI_Select + ** This is a minimal representation for node in lists of SDAI_Select */ class SC_CORE_EXPORT SelectNode : public STEPnode { public: diff --git a/src/clstepcore/STEPaggrString.h b/include/clstepcore/STEPaggrString.h similarity index 97% rename from src/clstepcore/STEPaggrString.h rename to include/clstepcore/STEPaggrString.h index 6f5cc8331..93aa1636e 100644 --- a/src/clstepcore/STEPaggrString.h +++ b/include/clstepcore/STEPaggrString.h @@ -1,7 +1,7 @@ #ifndef STEPAGGRSTRING_H #define STEPAGGRSTRING_H -#include "STEPaggregate.h" +#include "clstepcore/STEPaggregate.h" #include /** \file STEPaggrString.h diff --git a/src/clstepcore/STEPaggregate.h b/include/clstepcore/STEPaggregate.h similarity index 89% rename from src/clstepcore/STEPaggregate.h rename to include/clstepcore/STEPaggregate.h index df2178ee9..0acb638d6 100644 --- a/src/clstepcore/STEPaggregate.h +++ b/include/clstepcore/STEPaggregate.h @@ -17,11 +17,11 @@ class STEPaggregate; class TypeDescriptor; #include -#include -#include -#include -#include -#include +#include "clutils/errordesc.h" +#include "clstepcore/SingleLinkList.h" +#include "clstepcore/baseType.h" +#include "clstepcore/sdai.h" +#include "clstepcore/STEPundefined.h" #include #define AGGR_NULL &NilSTEPaggregate @@ -110,14 +110,14 @@ class SC_CORE_EXPORT STEPnode : public SingleLinkNode { }; typedef STEPnode * STEPnodeH; -#include "STEPaggrGeneric.h" -#include "STEPaggrEntity.h" -#include "STEPaggrSelect.h" -#include "STEPaggrString.h" -#include "STEPaggrBinary.h" -#include "STEPaggrEnum.h" -#include "STEPaggrReal.h" -#include "STEPaggrInt.h" +#include "clstepcore/STEPaggrGeneric.h" +#include "clstepcore/STEPaggrEntity.h" +#include "clstepcore/STEPaggrSelect.h" +#include "clstepcore/STEPaggrString.h" +#include "clstepcore/STEPaggrBinary.h" +#include "clstepcore/STEPaggrEnum.h" +#include "clstepcore/STEPaggrReal.h" +#include "clstepcore/STEPaggrInt.h" /****************************************************************** ** FIXME The following classes are currently stubs diff --git a/src/clstepcore/STEPattribute.h b/include/clstepcore/STEPattribute.h similarity index 99% rename from src/clstepcore/STEPattribute.h rename to include/clstepcore/STEPattribute.h index 47b99e025..f496fa46c 100644 --- a/src/clstepcore/STEPattribute.h +++ b/include/clstepcore/STEPattribute.h @@ -15,10 +15,10 @@ #include #include -#include -#include +#include "clutils/errordesc.h" +#include "clstepcore/baseType.h" -#include +#include "clstepcore/sdai.h" /** \def REAL_NUM_PRECISION * this is used to set a const int Real_Num_Precision diff --git a/src/clstepcore/STEPattributeList.h b/include/clstepcore/STEPattributeList.h similarity index 97% rename from src/clstepcore/STEPattributeList.h rename to include/clstepcore/STEPattributeList.h index 9159f4664..54aca69b4 100644 --- a/src/clstepcore/STEPattributeList.h +++ b/include/clstepcore/STEPattributeList.h @@ -16,7 +16,7 @@ class STEPattribute; #include -#include +#include "clstepcore/SingleLinkList.h" class STEPattributeList; diff --git a/src/clstepcore/STEPcomplex.h b/include/clstepcore/STEPcomplex.h similarity index 95% rename from src/clstepcore/STEPcomplex.h rename to include/clstepcore/STEPcomplex.h index caf7ea255..3c8a75fc3 100644 --- a/src/clstepcore/STEPcomplex.h +++ b/include/clstepcore/STEPcomplex.h @@ -2,11 +2,11 @@ #define STEPCOMPLEX_H #include -#include -#include -#include -#include -#include +#include "clutils/errordesc.h" +#include "clstepcore/sdai.h" +#include "clstepcore/baseType.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/Registry.h" #include diff --git a/src/clstepcore/STEPinvAttrList.h b/include/clstepcore/STEPinvAttrList.h similarity index 98% rename from src/clstepcore/STEPinvAttrList.h rename to include/clstepcore/STEPinvAttrList.h index 342720065..ccbb733b0 100644 --- a/src/clstepcore/STEPinvAttrList.h +++ b/include/clstepcore/STEPinvAttrList.h @@ -15,7 +15,7 @@ class Inverse_attribute; #include -#include +#include "clstepcore/SingleLinkList.h" class STEPinvAttrList; class EntityAggregate; diff --git a/src/clstepcore/STEPundefined.h b/include/clstepcore/STEPundefined.h similarity index 95% rename from src/clstepcore/STEPundefined.h rename to include/clstepcore/STEPundefined.h index 306eb0ef2..9cbb87ee7 100644 --- a/src/clstepcore/STEPundefined.h +++ b/include/clstepcore/STEPundefined.h @@ -13,9 +13,9 @@ */ #include -#include +#include "clutils/errordesc.h" #include -#include +#include "clstepcore/read_func.h" class SC_CORE_EXPORT SCLundefined { protected: diff --git a/src/clstepcore/SingleLinkList.h b/include/clstepcore/SingleLinkList.h similarity index 100% rename from src/clstepcore/SingleLinkList.h rename to include/clstepcore/SingleLinkList.h diff --git a/src/clstepcore/SubSuperIterators.h b/include/clstepcore/SubSuperIterators.h similarity index 99% rename from src/clstepcore/SubSuperIterators.h rename to include/clstepcore/SubSuperIterators.h index 9ca78765b..ccc059d28 100644 --- a/src/clstepcore/SubSuperIterators.h +++ b/include/clstepcore/SubSuperIterators.h @@ -1,8 +1,8 @@ #ifndef SUB_SUPER_ITERATORS #define SUB_SUPER_ITERATORS -#include "ExpDict.h" -#include "ExpDict.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/ExpDict.h" #include #include diff --git a/src/clstepcore/aggrTypeDescriptor.h b/include/clstepcore/aggrTypeDescriptor.h similarity index 99% rename from src/clstepcore/aggrTypeDescriptor.h rename to include/clstepcore/aggrTypeDescriptor.h index 44282bb6c..0031adf2d 100644 --- a/src/clstepcore/aggrTypeDescriptor.h +++ b/include/clstepcore/aggrTypeDescriptor.h @@ -2,7 +2,7 @@ #define AGGRTYPEDESCRIPTOR_H #include "typeDescriptor.h" -#include "create_Aggr.h" +#include "clstepcore/create_Aggr.h" #include "assert.h" diff --git a/src/clstepcore/attrDescriptor.h b/include/clstepcore/attrDescriptor.h similarity index 99% rename from src/clstepcore/attrDescriptor.h rename to include/clstepcore/attrDescriptor.h index cee4d13bc..c3d6493dd 100644 --- a/src/clstepcore/attrDescriptor.h +++ b/include/clstepcore/attrDescriptor.h @@ -3,7 +3,7 @@ #include "typeDescriptor.h" -#include "sdaiEnum.h" +#include "cldai/sdaiEnum.h" #include "sc_export.h" diff --git a/src/clstepcore/attrDescriptorList.h b/include/clstepcore/attrDescriptorList.h similarity index 100% rename from src/clstepcore/attrDescriptorList.h rename to include/clstepcore/attrDescriptorList.h diff --git a/src/clstepcore/baseType.h b/include/clstepcore/baseType.h similarity index 100% rename from src/clstepcore/baseType.h rename to include/clstepcore/baseType.h diff --git a/src/clstepcore/complexSupport.h b/include/clstepcore/complexSupport.h similarity index 99% rename from src/clstepcore/complexSupport.h rename to include/clstepcore/complexSupport.h index f7d3db734..34e78814e 100644 --- a/src/clstepcore/complexSupport.h +++ b/include/clstepcore/complexSupport.h @@ -18,7 +18,7 @@ #include #include using namespace std; -#include "Str.h" +#include "clutils/Str.h" #define LISTEND 999 /** \def LISTEND diff --git a/src/clstepcore/create_Aggr.h b/include/clstepcore/create_Aggr.h similarity index 97% rename from src/clstepcore/create_Aggr.h rename to include/clstepcore/create_Aggr.h index a0483fa66..7e5fdb0b3 100644 --- a/src/clstepcore/create_Aggr.h +++ b/include/clstepcore/create_Aggr.h @@ -3,7 +3,7 @@ //typedef's for aggregate creators -#include "sdai.h" +#include "clstepcore/sdai.h" #include "sc_export.h" diff --git a/src/clstepcore/derivedAttribute.h b/include/clstepcore/derivedAttribute.h similarity index 95% rename from src/clstepcore/derivedAttribute.h rename to include/clstepcore/derivedAttribute.h index 234521a07..69e0a37cf 100644 --- a/src/clstepcore/derivedAttribute.h +++ b/include/clstepcore/derivedAttribute.h @@ -1,7 +1,7 @@ #ifndef DERIVEDATTRIBUTE_H #define DERIVEDATTRIBUTE_H -#include "attrDescriptor.h" +#include "clstepcore/attrDescriptor.h" #include "sc_export.h" diff --git a/src/clstepcore/dictSchema.h b/include/clstepcore/dictSchema.h similarity index 100% rename from src/clstepcore/dictSchema.h rename to include/clstepcore/dictSchema.h diff --git a/src/clstepcore/dictdefs.h b/include/clstepcore/dictdefs.h similarity index 100% rename from src/clstepcore/dictdefs.h rename to include/clstepcore/dictdefs.h diff --git a/src/clstepcore/dictionaryInstance.h b/include/clstepcore/dictionaryInstance.h similarity index 100% rename from src/clstepcore/dictionaryInstance.h rename to include/clstepcore/dictionaryInstance.h diff --git a/src/clstepcore/dispnode.h b/include/clstepcore/dispnode.h similarity index 92% rename from src/clstepcore/dispnode.h rename to include/clstepcore/dispnode.h index 1209b9c3e..fccde675c 100644 --- a/src/clstepcore/dispnode.h +++ b/include/clstepcore/dispnode.h @@ -17,14 +17,14 @@ #include -/*#include */ +/*#include "clstepcore/STEPattribute.h"*/ /*#include */ -#include +#include "clstepcore/sdai.h" -#include -#include +#include "clutils/gennode.h" +#include "clutils/gennodelist.h" //#include -#include +#include "cleditor/editordefines.h" //#include class MgrNode; diff --git a/src/clstepcore/dispnodelist.h b/include/clstepcore/dispnodelist.h similarity index 92% rename from src/clstepcore/dispnodelist.h rename to include/clstepcore/dispnodelist.h index c4fe4dde3..6dfc697bd 100644 --- a/src/clstepcore/dispnodelist.h +++ b/include/clstepcore/dispnodelist.h @@ -17,12 +17,12 @@ #include -#include +#include "clutils/gennode.h" //#include -#include -#include -#include -#include +#include "cleditor/editordefines.h" +#include "clstepcore/mgrnode.h" +#include "clstepcore/dispnode.h" +#include "clutils/gennodelist.h" /////////////////////////////////////////////////////////////////////////////// // class DisplayNodeList diff --git a/src/clstepcore/entityDescriptor.h b/include/clstepcore/entityDescriptor.h similarity index 98% rename from src/clstepcore/entityDescriptor.h rename to include/clstepcore/entityDescriptor.h index e0bd25ec8..a51810c3f 100644 --- a/src/clstepcore/entityDescriptor.h +++ b/include/clstepcore/entityDescriptor.h @@ -2,9 +2,9 @@ #define ENTITYDESCRIPTOR_H #include "typeDescriptor.h" -#include "attrDescriptor.h" +#include "clstepcore/attrDescriptor.h" #include "uniquenessRule.h" -#include "attrDescriptorList.h" +#include "clstepcore/attrDescriptorList.h" #include "inverseAttributeList.h" #include "sc_export.h" diff --git a/src/clstepcore/entityDescriptorList.h b/include/clstepcore/entityDescriptorList.h similarity index 100% rename from src/clstepcore/entityDescriptorList.h rename to include/clstepcore/entityDescriptorList.h diff --git a/src/clstepcore/enumTypeDescriptor.h b/include/clstepcore/enumTypeDescriptor.h similarity index 100% rename from src/clstepcore/enumTypeDescriptor.h rename to include/clstepcore/enumTypeDescriptor.h diff --git a/src/clstepcore/explicitItemId.h b/include/clstepcore/explicitItemId.h similarity index 100% rename from src/clstepcore/explicitItemId.h rename to include/clstepcore/explicitItemId.h diff --git a/src/clstepcore/globalRule.h b/include/clstepcore/globalRule.h similarity index 97% rename from src/clstepcore/globalRule.h rename to include/clstepcore/globalRule.h index ffd1200fd..0987fbfbd 100644 --- a/src/clstepcore/globalRule.h +++ b/include/clstepcore/globalRule.h @@ -1,7 +1,7 @@ #ifndef GLOBALRULE_H #define GLOBALRULE_H -#include "dictionaryInstance.h" +#include "clstepcore/dictionaryInstance.h" #include "whereRule.h" #include "entityDescriptorList.h" diff --git a/src/clstepcore/implicitItemId.h b/include/clstepcore/implicitItemId.h similarity index 100% rename from src/clstepcore/implicitItemId.h rename to include/clstepcore/implicitItemId.h diff --git a/src/clstepcore/instmgr.h b/include/clstepcore/instmgr.h similarity index 93% rename from src/clstepcore/instmgr.h rename to include/clstepcore/instmgr.h index 3f185b3fb..86ed28603 100644 --- a/src/clstepcore/instmgr.h +++ b/include/clstepcore/instmgr.h @@ -27,17 +27,17 @@ // IT IS VERY IMPORTANT THAT THE ORDER OF THE FOLLOWING INCLUDE FILES // BE PRESERVED -#include -#include -#include +#include "clutils/gennode.h" +#include "clutils/gennodelist.h" +#include "clutils/gennodearray.h" -#include -#include +#include "clstepcore/mgrnode.h" +#include "clstepcore/mgrnodelist.h" -#include -#include +#include "clstepcore/dispnode.h" +#include "clstepcore/dispnodelist.h" -#include +#include "clstepcore/mgrnodearray.h" class SC_CORE_EXPORT InstMgrBase { public: diff --git a/src/clstepcore/interfaceSpec.h b/include/clstepcore/interfaceSpec.h similarity index 97% rename from src/clstepcore/interfaceSpec.h rename to include/clstepcore/interfaceSpec.h index 0b61b4b04..9eeea3f85 100644 --- a/src/clstepcore/interfaceSpec.h +++ b/include/clstepcore/interfaceSpec.h @@ -1,8 +1,8 @@ #ifndef INTERFACESPEC_H #define INTERFACESPEC_H -#include "dictionaryInstance.h" -#include "explicitItemId.h" +#include "clstepcore/dictionaryInstance.h" +#include "clstepcore/explicitItemId.h" #include "implicitItemId.h" #include "sc_export.h" diff --git a/src/clstepcore/interfacedItem.h b/include/clstepcore/interfacedItem.h similarity index 89% rename from src/clstepcore/interfacedItem.h rename to include/clstepcore/interfacedItem.h index 00401b68b..238969836 100644 --- a/src/clstepcore/interfacedItem.h +++ b/include/clstepcore/interfacedItem.h @@ -1,9 +1,9 @@ #ifndef INTERFACEDITEM_H #define INTERFACEDITEM_H -#include "dictionaryInstance.h" +#include "clstepcore/dictionaryInstance.h" -#include "sdai.h" +#include "clstepcore/sdai.h" #include "sc_export.h" diff --git a/src/clstepcore/inverseAttribute.h b/include/clstepcore/inverseAttribute.h similarity index 98% rename from src/clstepcore/inverseAttribute.h rename to include/clstepcore/inverseAttribute.h index 0d02b793d..4008cdaf8 100644 --- a/src/clstepcore/inverseAttribute.h +++ b/include/clstepcore/inverseAttribute.h @@ -1,7 +1,7 @@ #ifndef INVERSEATTRIBUTE_H #define INVERSEATTRIBUTE_H -#include "attrDescriptor.h" +#include "clstepcore/attrDescriptor.h" class SC_CORE_EXPORT Inverse_attribute : public AttrDescriptor { diff --git a/src/clstepcore/inverseAttributeList.h b/include/clstepcore/inverseAttributeList.h similarity index 100% rename from src/clstepcore/inverseAttributeList.h rename to include/clstepcore/inverseAttributeList.h diff --git a/src/clstepcore/mgrnode.h b/include/clstepcore/mgrnode.h similarity index 97% rename from src/clstepcore/mgrnode.h rename to include/clstepcore/mgrnode.h index eca3e19e7..9bc96ef1d 100644 --- a/src/clstepcore/mgrnode.h +++ b/include/clstepcore/mgrnode.h @@ -18,12 +18,12 @@ class GenericNode; class DisplayNode; -#include +#include "clstepcore/sdai.h" -#include -#include +#include "clutils/gennode.h" +#include "clutils/gennodelist.h" -#include +#include "cleditor/editordefines.h" class InstMgr; diff --git a/src/clstepcore/mgrnodearray.h b/include/clstepcore/mgrnodearray.h similarity index 95% rename from src/clstepcore/mgrnodearray.h rename to include/clstepcore/mgrnodearray.h index 22019d071..c09f6995f 100644 --- a/src/clstepcore/mgrnodearray.h +++ b/include/clstepcore/mgrnodearray.h @@ -19,14 +19,14 @@ #include -#include -#include +#include "clutils/gennode.h" +#include "clutils/gennodelist.h" //#include -#include -#include +#include "clstepcore/mgrnode.h" +#include "clstepcore/mgrnodelist.h" -#include +#include "clutils/gennodearray.h" #define ARRAY_DEFAULT_SIZE (1024) diff --git a/src/clstepcore/mgrnodelist.h b/include/clstepcore/mgrnodelist.h similarity index 94% rename from src/clstepcore/mgrnodelist.h rename to include/clstepcore/mgrnodelist.h index be822c798..e085b66c5 100644 --- a/src/clstepcore/mgrnodelist.h +++ b/include/clstepcore/mgrnodelist.h @@ -17,10 +17,10 @@ #include -#include +#include "clutils/gennode.h" //#include -#include -#include +#include "clutils/gennodelist.h" +#include "cleditor/editordefines.h" ////////////////////////////////////////////////////////////////////////////// // class MgrNodeList diff --git a/src/clstepcore/needFunc.h b/include/clstepcore/needFunc.h similarity index 100% rename from src/clstepcore/needFunc.h rename to include/clstepcore/needFunc.h diff --git a/src/clstepcore/read_func.h b/include/clstepcore/read_func.h similarity index 99% rename from src/clstepcore/read_func.h rename to include/clstepcore/read_func.h index 92cff5705..448297164 100644 --- a/src/clstepcore/read_func.h +++ b/include/clstepcore/read_func.h @@ -2,7 +2,7 @@ #define READ_FUNC_H #include -#include +#include "clstepcore/sdai.h" /// This was 512. According to 10303-21:2002 section 5.6: comment length is unlimited. FIXME need to check the code for potential problems before eliminating this limit completely. #define MAX_COMMENT_LENGTH 8192 diff --git a/src/clstepcore/realTypeDescriptor.h b/include/clstepcore/realTypeDescriptor.h similarity index 100% rename from src/clstepcore/realTypeDescriptor.h rename to include/clstepcore/realTypeDescriptor.h diff --git a/src/clstepcore/schRename.h b/include/clstepcore/schRename.h similarity index 98% rename from src/clstepcore/schRename.h rename to include/clstepcore/schRename.h index b5ffdbaa1..b3f7fdefd 100644 --- a/src/clstepcore/schRename.h +++ b/include/clstepcore/schRename.h @@ -4,7 +4,7 @@ #include #include -#include "Str.h" +#include "clutils/Str.h" #include "sc_export.h" diff --git a/src/clstepcore/sdai.h b/include/clstepcore/sdai.h similarity index 92% rename from src/clstepcore/sdai.h rename to include/clstepcore/sdai.h index 46ae3996b..f063653ce 100644 --- a/src/clstepcore/sdai.h +++ b/include/clstepcore/sdai.h @@ -27,11 +27,11 @@ extern const char * SCLversion; #include -#include "dictdefs.h" +#include "clstepcore/dictdefs.h" -#include "baseType.h" -#include "Str.h" -#include "errordesc.h" +#include "clstepcore/baseType.h" +#include "clutils/Str.h" +#include "clutils/errordesc.h" typedef std::string Express_id; @@ -40,8 +40,8 @@ class EntityDescriptor; class SelectTypeDescriptor; class InstMgrBase; -#include "STEPattributeList.h" -#include "STEPinvAttrList.h" +#include "clstepcore/STEPattributeList.h" +#include "clstepcore/STEPinvAttrList.h" class STEPattributeList; class STEPattribute; @@ -155,12 +155,12 @@ typedef char * SDAI_Time_stamp; typedef char * SDAI_Entity_name; typedef char * SDAI_Schema_name; -#include +#include "cldai/sdaiString.h" -#include +#include "cldai/sdaiBinary.h" // define Object which I am calling sdaiObject for now - DAS -#include +#include "cldai/sdaiObject.h" /****************************************************************************** ENUMERATION @@ -172,7 +172,7 @@ ENUMERATION * the value ENUM_NULL is used to represent NULL for all enumerated types *****************************************************************************/ -#include +#include "cldai/sdaiEnum.h" /****************************************************************************** BOOLEAN and LOGICAL @@ -185,11 +185,11 @@ BOOLEAN and LOGICAL // ***note*** this file needs classes from sdaiEnum.h // define DAObjectID and classes PID, PID_DA, PID_SDAI, DAObject, DAObject_SDAI -#include +#include "cldai/sdaiDaObject.h" -#include -#include +#include "clstepcore/sdaiApplication_instance.h" +#include "cldai/sdaiApplication_instance_set.h" /****************************************************************************** SELECT @@ -198,18 +198,18 @@ SELECT sdaiSelect.h ******************************************************************************/ -#include +#include "clstepcore/sdaiSelect.h" class SDAI_Model_contents; typedef SDAI_Model_contents * SDAI_Model_contents_ptr; typedef SDAI_Model_contents_ptr SDAI_Model_contents_var; -#include +#include "cldai/sdaiModel_contents_list.h" -#include -#include -#include -#include +#include "cldai/sdaiSession_instance.h" +#include "cldai/sdaiEntity_extent.h" +#include "cldai/sdaiEntity_extent_set.h" +#include "cldai/sdaiModel_contents.h" // ENTITY extern SC_CORE_EXPORT SDAI_Application_instance NilSTEPentity; diff --git a/src/clstepcore/sdaiApplication_instance.h b/include/clstepcore/sdaiApplication_instance.h similarity index 99% rename from src/clstepcore/sdaiApplication_instance.h rename to include/clstepcore/sdaiApplication_instance.h index 405964c24..4e764f593 100644 --- a/src/clstepcore/sdaiApplication_instance.h +++ b/include/clstepcore/sdaiApplication_instance.h @@ -16,7 +16,7 @@ #include #include -#include +#include "cldai/sdaiDaObject.h" class EntityAggregate; class Inverse_attribute; diff --git a/src/clstepcore/sdaiSelect.h b/include/clstepcore/sdaiSelect.h similarity index 100% rename from src/clstepcore/sdaiSelect.h rename to include/clstepcore/sdaiSelect.h diff --git a/src/clstepcore/selectTypeDescriptor.h b/include/clstepcore/selectTypeDescriptor.h similarity index 100% rename from src/clstepcore/selectTypeDescriptor.h rename to include/clstepcore/selectTypeDescriptor.h diff --git a/src/clstepcore/stringTypeDescriptor.h b/include/clstepcore/stringTypeDescriptor.h similarity index 100% rename from src/clstepcore/stringTypeDescriptor.h rename to include/clstepcore/stringTypeDescriptor.h diff --git a/src/clstepcore/typeDescriptor.h b/include/clstepcore/typeDescriptor.h similarity index 99% rename from src/clstepcore/typeDescriptor.h rename to include/clstepcore/typeDescriptor.h index 7fb53a53c..51a815593 100644 --- a/src/clstepcore/typeDescriptor.h +++ b/include/clstepcore/typeDescriptor.h @@ -3,7 +3,7 @@ #include "schRename.h" #include "whereRule.h" -#include "dictSchema.h" +#include "clstepcore/dictSchema.h" #include "sc_export.h" diff --git a/src/clstepcore/typeDescriptorList.h b/include/clstepcore/typeDescriptorList.h similarity index 100% rename from src/clstepcore/typeDescriptorList.h rename to include/clstepcore/typeDescriptorList.h diff --git a/src/clstepcore/typeOrRuleVar.h b/include/clstepcore/typeOrRuleVar.h similarity index 89% rename from src/clstepcore/typeOrRuleVar.h rename to include/clstepcore/typeOrRuleVar.h index 09f78da59..c698c5bd5 100644 --- a/src/clstepcore/typeOrRuleVar.h +++ b/include/clstepcore/typeOrRuleVar.h @@ -1,7 +1,7 @@ #ifndef TYPEORRULEVAR_H #define TYPEORRULEVAR_H -#include "dictionaryInstance.h" +#include "clstepcore/dictionaryInstance.h" #include "sc_export.h" diff --git a/src/clstepcore/uniquenessRule.h b/include/clstepcore/uniquenessRule.h similarity index 96% rename from src/clstepcore/uniquenessRule.h rename to include/clstepcore/uniquenessRule.h index 4751ce97b..b42a7414d 100644 --- a/src/clstepcore/uniquenessRule.h +++ b/include/clstepcore/uniquenessRule.h @@ -1,9 +1,9 @@ #ifndef UNIQUENESSRULE_H #define UNIQUENESSRULE_H -#include "dictionaryInstance.h" +#include "clstepcore/dictionaryInstance.h" -#include "sdai.h" +#include "clstepcore/sdai.h" #include "sc_export.h" diff --git a/src/clstepcore/whereRule.h b/include/clstepcore/whereRule.h similarity index 96% rename from src/clstepcore/whereRule.h rename to include/clstepcore/whereRule.h index ef9043a4b..98952d049 100644 --- a/src/clstepcore/whereRule.h +++ b/include/clstepcore/whereRule.h @@ -2,8 +2,8 @@ #define WHERERULE_H #include -#include "sdai.h" -#include "dictionaryInstance.h" +#include "clstepcore/sdai.h" +#include "clstepcore/dictionaryInstance.h" #include "typeOrRuleVar.h" #include "sc_export.h" diff --git a/include/clutils/CMakeLists.txt b/include/clutils/CMakeLists.txt new file mode 100644 index 000000000..9992890bc --- /dev/null +++ b/include/clutils/CMakeLists.txt @@ -0,0 +1,20 @@ +set(UTILS_HDRS + dirobj.h + errordesc.h + gennodearray.h + gennode.h + gennodelist.h + sc_hash.h + Str.h + ) + +install(FILES ${UTILS_HDRS} + DESTINATION ${INCLUDE_DIR}/stepcode/clutils) + +# Local Variables: +# tab-width: 8 +# mode: cmake +# indent-tabs-mode: t +# End: +# ex: shiftwidth=2 tabstop=8 + diff --git a/src/clutils/Str.h b/include/clutils/Str.h similarity index 98% rename from src/clutils/Str.h rename to include/clutils/Str.h index f605bfdda..487a2c9e2 100644 --- a/src/clutils/Str.h +++ b/include/clutils/Str.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include "clutils/errordesc.h" #ifndef STRING_DELIM #define STRING_DELIM '\'' diff --git a/src/clutils/dirobj.h b/include/clutils/dirobj.h similarity index 100% rename from src/clutils/dirobj.h rename to include/clutils/dirobj.h diff --git a/src/clutils/errordesc.h b/include/clutils/errordesc.h similarity index 100% rename from src/clutils/errordesc.h rename to include/clutils/errordesc.h diff --git a/src/clutils/gennode.h b/include/clutils/gennode.h similarity index 100% rename from src/clutils/gennode.h rename to include/clutils/gennode.h diff --git a/src/clutils/gennodearray.h b/include/clutils/gennodearray.h similarity index 98% rename from src/clutils/gennodearray.h rename to include/clutils/gennodearray.h index 4c0ee075a..1643f05e6 100644 --- a/src/clutils/gennodearray.h +++ b/include/clutils/gennodearray.h @@ -26,7 +26,7 @@ #include #include // to get bcopy for CenterLine -#include +#include "clutils/gennode.h" // the initial size of the array #define ARRAY_DEFAULT_SIZE (1024) diff --git a/src/clutils/gennodelist.h b/include/clutils/gennodelist.h similarity index 100% rename from src/clutils/gennodelist.h rename to include/clutils/gennodelist.h diff --git a/src/clutils/sc_hash.h b/include/clutils/sc_hash.h similarity index 100% rename from src/clutils/sc_hash.h rename to include/clutils/sc_hash.h diff --git a/include/config.h.in b/include/config.h.in index 67d88c433..63ccc4ed1 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -15,7 +15,6 @@ #cmakedefine HAVE_IO_H 1 #cmakedefine SC_TRACE_FPRINTF 1 -#cmakedefine SC_MEMMGR_ENABLE_CHECKS 1 #cmakedefine HAVE_ABS 1 #cmakedefine HAVE_MEMCPY 1 diff --git a/include/express/alloc.h b/include/express/alloc.h index 79199773a..1c95792d4 100644 --- a/include/express/alloc.h +++ b/include/express/alloc.h @@ -58,7 +58,7 @@ struct freelist_head { #endif }; -char * nnew(); +char * nnew(void); #include "error.h" diff --git a/include/express/basic.h b/include/express/basic.h index 3318ffc19..191924812 100644 --- a/include/express/basic.h +++ b/include/express/basic.h @@ -93,8 +93,11 @@ /* function pointer types */ /**************************/ -typedef void ( *voidFuncptr )(); -typedef int ( *intFuncptr )(); +typedef void ( *voidFuncptr )(void); +typedef int ( *intFuncptr )(void); + +/* Option index - can we get rid of this? */ +extern SC_EXPRESS_EXPORT int sc_optind; #endif /* BASIC_H */ diff --git a/include/express/factory.h b/include/express/factory.h index 4942256fe..f4400d9e7 100644 --- a/include/express/factory.h +++ b/include/express/factory.h @@ -3,6 +3,6 @@ #include "sc_export.h" -SC_EXPRESS_EXPORT void FACTORYinitialize(); +SC_EXPRESS_EXPORT void FACTORYinitialize(void); #endif /* __FACTORY_H_ */ diff --git a/include/express/memory.h b/include/express/memory.h index 3d1e58c74..02adac89e 100644 --- a/include/express/memory.h +++ b/include/express/memory.h @@ -3,6 +3,6 @@ #include "sc_export.h" -SC_EXPRESS_EXPORT void MEMORYinitialize(); +SC_EXPRESS_EXPORT void MEMORYinitialize(void); #endif // __MEMORY_H diff --git a/include/express/object.h b/include/express/object.h index e5736f45b..15e4a435f 100644 --- a/include/express/object.h +++ b/include/express/object.h @@ -68,7 +68,7 @@ /***************************/ struct Object { - struct Symbol_ * ( *get_symbol )(); + struct Symbol_ * ( *get_symbol )( void * ); char * type; /**< should complete the phrase "X is ..." - i.e., "an entity", "a type", "of unknown type" */ int bits; /**< a bitwise selector of a type, i.e. OBJ_XX_BITS */ }; diff --git a/lcov.cmake b/lcov.cmake index 4ca1388db..74adc1576 100644 --- a/lcov.cmake +++ b/lcov.cmake @@ -15,7 +15,7 @@ BUILDNAME:STRING=${CTEST_BUILD_NAME} SC_ENABLE_TESTING:BOOL=ON SC_ENABLE_COVERAGE:BOOL=ON SC_BUILD_SCHEMAS:STRING=ALL -SC_BUILD_TYPE:STRING=Debug +CMAKE_BUILD_TYPE:STRING=Debug ") set(LCOV_OUT "${CTEST_BINARY_DIRECTORY}/lcov_html") diff --git a/misc/header_mv.sh b/misc/header_mv.sh new file mode 100755 index 000000000..0d2be0f0f --- /dev/null +++ b/misc/header_mv.sh @@ -0,0 +1,10 @@ +#!/bin/bash +find . -type f -path "*/cl*" -not -path "*.git/*" -not -path "*/exp*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include \"$1\"/include \"utils\/$1\"/g" {} \; +find . -type f -path "*/cl*" -not -path "*.git/*" -not -path "*/exp*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include <$1>/include \"utils\/$1\"/g" {} \; + +find . -type f -path "*/include*" -not -path "*.git/*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include \"$1\"/include \"utils\/$1\"/g" {} \; +find . -type f -path "*/include*" -not -path "*.git/*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include <$1>/include \"utils\/$1\"/g" {} \; + +find . -type f -path "*/test*" -not -path "*.git/*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include \"$1\"/include \"utils\/$1\"/g" {} \; +find . -type f -path "*/test*" -not -path "*.git/*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include <$1>/include \"utils\/$1\"/g" {} \; + diff --git a/run_ctest.cmake b/run_ctest.cmake index 7533d7c17..a8d833789 100644 --- a/run_ctest.cmake +++ b/run_ctest.cmake @@ -9,7 +9,7 @@ set(CTEST_INITIAL_CACHE " SITE:STRING=${CTEST_SITE} BUILDNAME:STRING=${CTEST_BUILD_NAME} SC_ENABLE_TESTING:BOOL=ON -SC_BUILD_TYPE:STRING=Debug +CMAKE_BUILD_TYPE:STRING=Debug ") diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt deleted file mode 100644 index 5aad0a929..000000000 --- a/src/base/CMakeLists.txt +++ /dev/null @@ -1,72 +0,0 @@ - -set(SC_BASE_SOURCES - sc_memmgr.cc - sc_trace_fprintf.c - sc_getopt.cc - sc_benchmark.cc - sc_mkdir.c - path2str.c - judy/src/judy.c - ) - -set(SC_BASE_HDRS - sc_benchmark.h - sc_memmgr.h - sc_getopt.h - sc_trace_fprintf.h - sc_mkdir.h - path2str.h - judy/src/judy.h - judy/src/judyLArray.h - judy/src/judyL2Array.h - judy/src/judySArray.h - judy/src/judyS2Array.h - ) - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/judy/src - ) - -if($CACHE{SC_MEMMGR_ENABLE_CHECKS}) - add_definitions(-DSC_MEMMGR_ENABLE_CHECKS) -endif() - -if(BUILD_SHARED_LIBS) - SC_ADDLIB(base SHARED SOURCES ${SC_BASE_SOURCES}) - if(WIN32) - target_link_libraries(base psapi) - target_compile_definitions(base PRIVATE SC_BASE_DLL_EXPORTS) - endif() -endif() - -if(BUILD_STATIC_LIBS) - SC_ADDLIB(base-static STATIC SOURCES ${SC_BASE_SOURCES}) - if(WIN32) - target_link_libraries(base-static psapi) - endif() -endif() - -if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/judy/src") - message("Judy array source code not found. Downloading (don't sweat, it's public domain)...") - file(DOWNLOAD "http://github.com/mpictor/judy-template/archive/master.tar.gz" - "${CMAKE_CURRENT_SOURCE_DIR}/judy.tar.gz" SHOW_PROGRESS) - execute_process( - COMMAND ${CMAKE_COMMAND} -E tar xzf "${CMAKE_CURRENT_SOURCE_DIR}/judy.tar.gz" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/" - ) - file(RENAME judy-template-master judy) - file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/judy.tar.gz") - message("Judy array source code extracted.") -endif(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/judy/src") - -install(FILES ${SC_BASE_HDRS} - DESTINATION ${INCLUDE_DIR}/stepcode/base) - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 - diff --git a/src/base/judy/CMakeLists.txt b/src/base/judy/CMakeLists.txt deleted file mode 100644 index 3c26e4df2..000000000 --- a/src/base/judy/CMakeLists.txt +++ /dev/null @@ -1,78 +0,0 @@ - -cmake_minimum_required(VERSION 3.12) -project( JudyTemplates ) - -if( NOT DEFINED CMAKE_BUILD_TYPE ) - # set( CMAKE_BUILD_TYPE "RelWithDebInfo" ) #optimize, but include debug info - set( CMAKE_BUILD_TYPE "Release" ) -endif( NOT DEFINED CMAKE_BUILD_TYPE ) - -SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) -SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) -SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) - -if( NOT DEFINED JUDY_OPTIMIZE_FLAGS ) - if( CMAKE_COMPILER_IS_GNUCC ) - set( JUDY_OPTIMIZE_FLAGS "-march=native" ) - - #test for LTO; this uses an internal variable so it may break - if( DEFINED CMAKE_C_COMPILER_VERSION ) - if( ${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 4.7.0 ) - set( JUDY_OPTIMIZE_FLAGS "${JUDY_OPTIMIZE_FLAGS} -flto" ) - message( " -- GCC version: ${CMAKE_C_COMPILER_VERSION}. Enabling link-time optimization." ) - endif( ${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 4.7.0 ) - endif( DEFINED CMAKE_C_COMPILER_VERSION ) - #elseif( MSVC ) - # set( JUDY_OPTIMIZE_FLAGS "..." ) # <--- set MSVC flags here <--- - else() - message( "Unrecognized compiler - no optimization flags set. Edit CMakeLists.txt or set JUDY_OPTIMIZE_FLAGS." ) - set( JUDY_OPTIMIZE_FLAGS "" ) - endif( CMAKE_COMPILER_IS_GNUCC ) -endif( NOT DEFINED JUDY_OPTIMIZE_FLAGS ) -add_definitions( ${JUDY_OPTIMIZE_FLAGS} ) - -set( JUDYS_SOURCES src/judy.c src/judy.h ) - -if( CMAKE_COMPILER_IS_GNUCC ) - add_definitions( -pedantic -W -Wall -Wundef -Wfloat-equal -Wshadow -Winline -Wno-long-long ) -endif( CMAKE_COMPILER_IS_GNUCC ) - -add_library( judy_lib STATIC ${JUDYS_SOURCES} ) - -include_directories( src ) - -if( ENABLE_TESTING ) - include( CTest ) - include_directories( test ) - enable_testing() - - add_executable( pennysort test/pennySort.c test/sort.c ${JUDYS_SOURCES} ) - add_executable( hexsort test/hexSort.c test/sort.c ${JUDYS_SOURCES} ) - set_target_properties( pennysort hexsort PROPERTIES COMPILE_FLAGS "-DSTANDALONE" ) - - - add_executable( judyLtest test/judyLtest.cc ) - target_link_libraries( judyLtest judy_lib ) - add_test( judyLtest judyLtest ) - - add_executable( judyL2test test/judyL2test.cc ) - target_link_libraries( judyL2test judy_lib ) - add_test( judyL2test judyL2test ) - - add_executable( judyStest test/judyStest.cc ) - target_link_libraries( judyStest judy_lib ) - add_test( judyStest judyStest ) - - add_executable( judyS2test test/judyS2test.cc ) - target_link_libraries( judyS2test judy_lib ) - add_test( judyS2test judyS2test ) - -endif( ENABLE_TESTING ) - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 - diff --git a/src/base/judy/README.md b/src/base/judy/README.md deleted file mode 100644 index 5fc134587..000000000 --- a/src/base/judy/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Judy Array Templates -The Judy Array is a sparse dynamic array. It is a particular kind of trie that is highly efficient in space and time, and does not require tuning. - -This uses [Karl Malbrain's implementation](http://code.google.com/p/judyarray/) of the Judy Array. Additional information can be found with Doug Baskins' [original implementation](http://judy.sourceforge.net/) on sourceforge, or on [Wikipedia](http://en.wikipedia.org/wiki/Judy_array). -## The templates -* `judyLArray` - a C++ template wrapper for an int-int Judy Array. JudyKey and JudyValue must be integer types and the same size as a pointer (i.e. 32- or 64-bit) -* `judySArray` - Same as judyLArray, but with string-int mapping. The above restrictions on JudyValue apply here as well. -* **TODO** - single-key, multi-value versions of the above -* **TODO** - single-key, n-value versions of the above *(?)* - -## Comparison between this and the versions Karl and Doug wrote -* Doug Baskins' code is licenced under the LGPL. While more permissive than the GPL, it's still not always acceptable. His code is very fast but weighs in at ~20k lines. -* Karl Malbrain's code is ~1250 lines, in a single file containing the judy array and the test code; use requires creating a header. -* Both of the above are written in C, so they don't fit neatly into object-oriented C++. -* Unlike Doug's code, this is ~1250 lines. Unlike Karl's, this is split into several files. - -## Files -* `CMakeLists.txt` - CMake build logic. If you don't have CMake, it should be quite easy to write a file for the build system of your choice. -* **src/** - * `judy.c`, `judy.h` - implementation of the Judy Array - * `judyLArray.h` - the judyLArray template - * `judySArray.h` - the judySArray template -* **test/** - * `hexSort.c` - Sorts a file where each line contains 32 hex chars. Compiles to `hexsort`, which is the same executable as compiling Karl's code with `-DHEXSORT -DSTANDALONE` - * `pennySort.c` - Sorts strings; compiles to `pennysort`. Same as compiling Karl's code with `-DSTANDALONE`. - * `sort.c`, `sort.h` - Karl's sorting functions. Only used by `hexsort` and `pennysort`. - * `judyLtest.cc` - an incomplete test of the judyLArray template. - * `judyStest.cc` - an incomplete test of the judySArray template. - - -## Compiling -* requires C and C++ compilers, CMake. -* from the command line: - * `mkdir build; cd build` - * `cmake .. -DENABLE_TESTING=TRUE` - * `make` - -## License - -Karl Malbrain's judy array code is public domain; what I've added is public domain as well. - -## Contact -mpictor -a-t- gmail diff --git a/src/base/judy/misc/astyle.cfg b/src/base/judy/misc/astyle.cfg deleted file mode 100644 index eec1dd399..000000000 --- a/src/base/judy/misc/astyle.cfg +++ /dev/null @@ -1,29 +0,0 @@ -#astyle config file - -#run astyle on one or a few files: use -# astyle --options=misc/astyle.cfg path/to/file - -#run astyle on all files: from the root dir, use -# astyle --options=misc/astyle.cfg --recursive "src/*.c" "src/*.h" "test/*.c" "test/*.h" -# in the above line, the double quotes *are* necessary - - -suffix=none #don't create backup files - -style=java #compact bracket style - -indent=spaces=4 - -indent-preprocessor -indent-classes -indent-switches -indent-namespaces -pad-oper #pad (space) around operators -pad-paren-in #pad inside parenthesis -unpad-paren #remove parenthesis padding other than requested above - -add-brackets #add brackets on one-line conditionals -convert-tabs #convert all tabs to spaces -align-pointer=middle #char * foo - -lineend=linux #lines end with LF (linux), not CRLF (windows) diff --git a/src/base/judy/misc/hextest.sh b/src/base/judy/misc/hextest.sh deleted file mode 100755 index ee8606d48..000000000 --- a/src/base/judy/misc/hextest.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -#generates a file of hex keys and runs hexsort on it. No verification is done. -#hex data comes from /dev/urandom, so it isn't all that random. - -hexdump -v -e '2/8 "%08x"' -e '"\n"' /dev/urandom |head -n 1000000 >ukeys -#a.out [in-file] [out-file] [keysize] [recordlen] [keyoffset] [mergerecs] -time bin/hexsort ukeys skeys \ No newline at end of file diff --git a/src/base/judy/misc/judy64n.c b/src/base/judy/misc/judy64n.c deleted file mode 100644 index 8dc8f909a..000000000 --- a/src/base/judy/misc/judy64n.c +++ /dev/null @@ -1,2084 +0,0 @@ -// Judy arrays 23 NOV 2012 - -// Author Karl Malbrain, malbrain@yahoo.com -// with assistance from Jan Weiss. - -// Simplified judy arrays for strings and integers -// Adapted from the ideas of Douglas Baskins of HP. - -// The -D ASKITIS benchmarking option was implemented with -// assistance from Dr. Nikolas Askitis (www.naskitis.com). - -// Map a set of keys to corresponding memory cells (unsigned ints). -// Each cell must be set to a non-zero value by the caller. - -// STANDALONE is defined to compile into a string sorter. - -// String mappings are denoted by calling judy_open with zero as -// the second argument. Integer mappings are denoted by calling -// judy_open with the Integer depth of the Judy Trie as the second -// argument. - -//#define STANDALONE - -// functions: -// judy_open: open a new judy array returning a judy object. -// judy_close: close an open judy array, freeing all memory. -// judy_clone: clone an open judy array, duplicating the stack. -// judy_data: allocate data memory within judy array for external use. -// judy_cell: insert a string into the judy array, return cell pointer. -// judy_strt: retrieve the cell pointer greater than or equal to given key -// judy_slot: retrieve the cell pointer, or return NULL for a given key. -// judy_key: retrieve the string value for the most recent judy query. -// judy_end: retrieve the cell pointer for the last string in the array. -// judy_nxt: retrieve the cell pointer for the next string in the array. -// judy_prv: retrieve the cell pointer for the prev string in the array. -// judy_del: delete the key and cell for the current stack entry. - -#include -#include -#include - -#ifdef linux - #define _FILE_OFFSET_BITS 64 - #define _LARGEFILE_SOURCE - #define __USE_FILE_OFFSET64 - - #include -#else - #ifdef __BIG_ENDIAN__ - #ifndef BYTE_ORDER - #define BYTE_ORDER 4321 - #endif - #else - #ifndef BYTE_ORDER - #define BYTE_ORDER 1234 - #endif - #endif - #ifndef BIG_ENDIAN - #define BIG_ENDIAN 4321 - #endif -#endif - - - -#define PRIuint "u" - -#if defined(__LP64__) || \ - defined(__x86_64__) || \ - defined(__amd64__) || \ - defined(_WIN64) || \ - defined(__sparc64__) || \ - defined(__arch64__) || \ - defined(__powerpc64__) || \ - defined (__s390x__) - // defines for 64 bit - - typedef unsigned long long judyvalue; - typedef unsigned long long JudySlot; - #define JUDY_key_mask (0x07) - #define JUDY_key_size 8 - #define JUDY_slot_size 8 - #define JUDY_span_bytes (3 * JUDY_key_size) - #define JUDY_span_equiv JUDY_2 - #define JUDY_radix_equiv JUDY_8 - - #define PRIjudyvalue "llu" - -#else - // defines for 32 bit - - typedef unsigned int judyvalue; - typedef unsigned int JudySlot; - #define JUDY_key_mask (0x03) - #define JUDY_key_size 4 - #define JUDY_slot_size 4 - #define JUDY_span_bytes (7 * JUDY_key_size) - #define JUDY_span_equiv JUDY_4 - #define JUDY_radix_equiv JUDY_8 - - #define PRIjudyvalue "u" - -#endif - -#define JUDY_mask (~(JudySlot)0x07) - -// define the alignment factor for judy nodes and allocations -// to enable this feature, set to 64 - -#define JUDY_cache_line 8 // minimum size is 8 bytes - -#if defined(STANDALONE) || defined(ASKITIS) -#include -#include - -unsigned int MaxMem = 0; - -// void judy_abort (char *msg) __attribute__ ((noreturn)); // Tell static analyser that this function will not return -void judy_abort (char *msg) -{ - fprintf(stderr, "%s\n", msg); - exit(1); -} -#endif - -#define JUDY_seg 65536 - -enum JUDY_types { - JUDY_radix = 0, // inner and outer radix fan-out - JUDY_1 = 1, // linear list nodes of designated count - JUDY_2 = 2, - JUDY_4 = 3, - JUDY_8 = 4, - JUDY_16 = 5, - JUDY_32 = 6, -#ifdef ASKITIS - JUDY_64 = 7 -#else - JUDY_span = 7 // up to 28 tail bytes of key contiguously stored -#endif -}; - -int JudySize[] = { - (JUDY_slot_size * 16), // JUDY_radix node size - (JUDY_slot_size + JUDY_key_size), // JUDY_1 node size - (2 * JUDY_slot_size + 2 * JUDY_key_size), - (4 * JUDY_slot_size + 4 * JUDY_key_size), - (8 * JUDY_slot_size + 8 * JUDY_key_size), - (16 * JUDY_slot_size + 16 * JUDY_key_size), - (32 * JUDY_slot_size + 32 * JUDY_key_size), -#ifndef ASKITIS - (JUDY_span_bytes + JUDY_slot_size) -#else - (64 * JUDY_slot_size + 64 * JUDY_key_size) -#endif -}; - -judyvalue JudyMask[9] = { -0, 0xff, 0xffff, 0xffffff, 0xffffffff, -#if JUDY_key_size > 4 -0xffffffffffULL, 0xffffffffffffULL, 0xffffffffffffffULL, 0xffffffffffffffffULL -#endif -}; - -typedef struct { - void *seg; // next used allocator - unsigned int next; // next available offset -} JudySeg; - -typedef struct { - JudySlot next; // judy object - unsigned int off; // offset within key - int slot; // slot within object -} JudyStack; - -typedef struct { - JudySlot root[1]; // root of judy array - void **reuse[8]; // reuse judy blocks - JudySeg *seg; // current judy allocator - unsigned int level; // current height of stack - unsigned int max; // max height of stack - unsigned int depth; // number of Integers in a key, or zero for string keys - JudyStack stack[1]; // current cursor -} Judy; - -#ifdef ASKITIS -int Words = 0; -int Inserts = 0; -int Found = 0; - -#if JUDY_key_size < 8 -#define JUDY_max JUDY_16 -#else -#define JUDY_max JUDY_64 -#endif -#else -#define JUDY_max JUDY_32 -#endif - -// open judy object -// call with max key size -// and Integer tree depth. - -void *judy_open (unsigned int max, unsigned int depth) -{ -JudySeg *seg; -Judy *judy; -unsigned int amt; - - max++; // allow for zero terminator on keys - - if( (seg = malloc(JUDY_seg)) ) { - seg->seg = NULL; - seg->next = JUDY_seg; - } else { -#if defined(STANDALONE) || defined(ASKITIS) - judy_abort ("No virtual memory"); -#else - return NULL; -#endif - } - - amt = sizeof(Judy) + max * sizeof(JudyStack); - - if( amt & (JUDY_cache_line - 1) ) - amt |= JUDY_cache_line - 1, amt++; - -#if defined(STANDALONE) || defined(ASKITIS) - MaxMem += JUDY_seg; -#endif - - seg->next -= (JudySlot)seg & (JUDY_cache_line - 1); - seg->next -= amt; - - judy = (Judy *)((unsigned char *)seg + seg->next); - memset(judy, 0, amt); - judy->depth = depth; - judy->seg = seg; - judy->max = max; - return judy; -} - -void judy_close (Judy *judy) -{ -JudySeg *seg, *nxt = judy->seg; - - while( (seg = nxt) ) - nxt = seg->seg, free (seg); -} - -// allocate judy node - -void *judy_alloc (Judy *judy, unsigned int type) -{ -unsigned int amt, idx, min; -JudySeg *seg; -void **block; -void **rtn; - - if( !judy->seg ) -#if defined(STANDALONE) || defined(ASKITIS) - judy_abort("illegal allocation from judy clone"); -#else - return NULL; -#endif - - if( type == JUDY_radix ) - type = JUDY_radix_equiv; - -#ifndef ASKITIS - if( type == JUDY_span ) - type = JUDY_span_equiv; -#endif - - amt = JudySize[type]; - - if( amt & 0x07 ) - amt |= 0x07, amt += 1; - - // see if free block is already available - - if( (block = judy->reuse[type]) ) { - judy->reuse[type] = *block; - memset (block, 0, amt); - return (void *)block; - } - - // break down available larger block - // for reuse into smaller blocks - - if( type >= JUDY_1 ) - for( idx = type; idx++ < JUDY_max; ) - if( block = judy->reuse[idx] ) { - judy->reuse[idx] = *block; - while( idx-- > type) { - judy->reuse[idx] = block + JudySize[idx] / sizeof(void *); - block[JudySize[idx] / sizeof(void *)] = 0; - } - memset (block, 0, amt); - return (void *)block; - } - - min = amt < JUDY_cache_line ? JUDY_cache_line : amt; - - if( judy->seg->next < min + sizeof(*seg) ) { - if( (seg = malloc (JUDY_seg)) ) { - seg->next = JUDY_seg; - seg->seg = judy->seg; - judy->seg = seg; - seg->next -= (JudySlot)seg & (JUDY_cache_line - 1); - } else { -#if defined(STANDALONE) || defined(ASKITIS) - judy_abort("Out of virtual memory"); -#else - return NULL; -#endif - } - -#if defined(STANDALONE) || defined(ASKITIS) - MaxMem += JUDY_seg; -#endif - } - - // generate additional free blocks - // to fill up to cache line size - - rtn = (void **)((unsigned char *)judy->seg + judy->seg->next - amt); - - for( idx = type; amt & (JUDY_cache_line - 1); amt <<= 1 ) { - block = (void **)((unsigned char *)judy->seg + judy->seg->next - 2 * amt); - judy->reuse[idx++] = block; - *block = 0; - } - - judy->seg->next -= amt; - memset (rtn, 0, JudySize[type]); - return (void *)rtn; -} - -void *judy_data (Judy *judy, unsigned int amt) - -{ -JudySeg *seg; -void *block; - - if( !judy->seg ) -#if defined(STANDALONE) || defined(ASKITIS) - judy_abort("illegal allocation from judy clone"); -#else - return NULL; -#endif - - if( amt & (JUDY_cache_line - 1)) - amt |= (JUDY_cache_line - 1), amt += 1; - - if( judy->seg->next < amt + sizeof(*seg) ) { - if( (seg = malloc (JUDY_seg)) ) { - seg->next = JUDY_seg; - seg->seg = judy->seg; - judy->seg = seg; - seg->next -= (JudySlot)seg & (JUDY_cache_line - 1); - } else { -#if defined(STANDALONE) || defined(ASKITIS) - judy_abort("Out of virtual memory"); -#else - return NULL; -#endif - } - -#if defined(STANDALONE) || defined(ASKITIS) - MaxMem += JUDY_seg; -#endif - } - - judy->seg->next -= amt; - - block = (void *)((unsigned char *)judy->seg + judy->seg->next); - memset (block, 0, amt); - return block; -} - -void *judy_clone (Judy *judy) -{ -Judy *clone; -unsigned int amt; - - amt = sizeof(Judy) + judy->max * sizeof(JudyStack); - clone = judy_data (judy, amt); - memcpy (clone, judy, amt); - clone->seg = NULL; // stop allocations from cloned array - return clone; -} - -void judy_free (Judy *judy, void *block, int type) -{ - if( type == JUDY_radix ) - type = JUDY_radix_equiv; - -#ifndef ASKITIS - if( type == JUDY_span ) - type = JUDY_span_equiv; -#endif - - *((void **)(block)) = judy->reuse[type]; - judy->reuse[type] = (void **)block; - return; -} - -// assemble key from current path - -unsigned int judy_key (Judy *judy, unsigned char *buff, unsigned int max) -{ -judyvalue *dest = (judyvalue *)buff; -unsigned int len = 0, idx = 0, depth; -int slot, off, type; -judyvalue value; -unsigned char *base; -int keysize; - - if( judy->depth ) - max = judy->depth * JUDY_key_size; - else - max--; // leave room for zero terminator - - while( len < max && ++idx <= judy->level ) { - type = judy->stack[idx].next & 0x07; - slot = judy->stack[idx].slot; - depth = len / JUDY_key_size; - - if( judy->depth ) - if( !(len & JUDY_key_mask) ) - dest[depth] = 0; - - switch( type ) { - case JUDY_1: - case JUDY_2: - case JUDY_4: - case JUDY_8: - case JUDY_16: - case JUDY_32: -#ifdef ASKITIS - case JUDY_64: -#endif - keysize = JUDY_key_size - (judy->stack[idx].off & JUDY_key_mask); - base = (unsigned char *)(judy->stack[idx].next & JUDY_mask); - - if( judy->depth ) { - value = *(judyvalue *)(base + slot * keysize); - value &= JudyMask[keysize]; - dest[depth++] |= value; - len += keysize; - - if( depth < judy->depth ) - continue; - - return len; - } - -#if BYTE_ORDER != BIG_ENDIAN - off = keysize; - - while( off-- && len < max ) - if( buff[len] = base[slot * keysize + off] ) - len++; - else - break; -#else - for( off = 0; off < keysize && len < max; off++ ) - if( buff[len] = base[slot * keysize + off] ) - len++; - else - break; -#endif - continue; - - case JUDY_radix: - if( judy->depth ) { - dest[depth] |= (judyvalue)slot << (JUDY_key_size - (++len & JUDY_key_mask)) * 8; - if( !(len & JUDY_key_mask) ) - depth++; - if( depth < judy->depth ) - continue; - - return len; - } - - if( !slot ) - break; - buff[len++] = (unsigned char)slot; - continue; - -#ifndef ASKITIS - case JUDY_span: - base = (unsigned char *)(judy->stack[idx].next & JUDY_mask); - - for( slot = 0; slot < JUDY_span_bytes && base[slot]; slot++ ) - if( len < max ) - buff[len++] = base[slot]; - continue; -#endif - } - } - buff[len] = 0; - return len; -} - -// find slot & setup cursor - -JudySlot *judy_slot (Judy *judy, unsigned char *buff, unsigned int max) -{ -judyvalue *src = (judyvalue *)buff; -int slot, size, keysize, tst, cnt; -JudySlot next = *judy->root; -judyvalue value, test = 0; -JudySlot *table; -JudySlot *node; -unsigned int depth = 0; -unsigned int off = 0; -unsigned char *base; - -#ifndef ASKITIS - judy->level = 0; -#endif - - while( next ) { -#ifndef ASKITIS - if( judy->level < judy->max ) - judy->level++; - - judy->stack[judy->level].next = next; - judy->stack[judy->level].off = off; -#endif - size = JudySize[next & 0x07]; - - switch( next & 0x07 ) { - - case JUDY_1: - case JUDY_2: - case JUDY_4: - case JUDY_8: - case JUDY_16: - case JUDY_32: -#ifdef ASKITIS - case JUDY_64: -#endif - base = (unsigned char *)(next & JUDY_mask); - node = (JudySlot *)((next & JUDY_mask) + size); - keysize = JUDY_key_size - (off & JUDY_key_mask); - cnt = size / (sizeof(JudySlot) + keysize); - slot = cnt; - value = 0; - - if( judy->depth ) { - value = src[depth++]; - off |= JUDY_key_mask; - off++; - value &= JudyMask[keysize]; - } else - do { - value <<= 8; - if( off < max ) - value |= buff[off]; - } while( ++off & JUDY_key_mask ); - - // find slot > key - - while( slot-- ) { - test = *(judyvalue *)(base + slot * keysize); -#if BYTE_ORDER == BIG_ENDIAN - test >>= 8 * (JUDY_key_size - keysize); -#else - test &= JudyMask[keysize]; -#endif - if( test <= value ) - break; - } -#ifndef ASKITIS - judy->stack[judy->level].slot = slot; -#endif - if( test == value ) { - - // is this a leaf? - - if( !judy->depth && !(value & 0xFF) || judy->depth && depth == judy->depth ) - return &node[-slot-1]; - - next = node[-slot-1]; - continue; - } - - return NULL; - - case JUDY_radix: - table = (JudySlot *)(next & JUDY_mask); // outer radix - - if( judy->depth ) - slot = (src[depth] >> ((JUDY_key_size - off++ & JUDY_key_mask) * 8)) & 0xff; - else if( off < max ) - slot = buff[off++]; - else - slot = 0; -#ifndef ASKITIS - // put radix slot on judy stack - - judy->stack[judy->level].slot = slot; -#endif - if( (next = table[slot >> 4]) ) - table = (JudySlot *)(next & JUDY_mask); // inner radix - else - return NULL; - - if( judy->depth ) - if( !(off & JUDY_key_mask) ) - depth++; - - if( !judy->depth && !slot || judy->depth && depth == judy->depth ) // leaf? - if( table[slot & 0x0F] ) // occupied? - return &table[slot & 0x0F]; - else - return NULL; - - next = table[slot & 0x0F]; - continue; - -#ifndef ASKITIS - case JUDY_span: - node = (JudySlot *)((next & JUDY_mask) + JudySize[JUDY_span]); - base = (unsigned char *)(next & JUDY_mask); - cnt = tst = JUDY_span_bytes; - if( tst > (int)(max - off) ) - tst = max - off; - value = strncmp((const char *)base, (const char *)(buff + off), tst); - if( !value && tst < cnt && !base[tst] ) // leaf? - return &node[-1]; - - if( !value && tst == cnt ) { - next = node[-1]; - off += cnt; - continue; - } - return NULL; -#endif - } - } - - return NULL; -} - -// promote full nodes to next larger size - -JudySlot *judy_promote (Judy *judy, JudySlot *next, int idx, judyvalue value, int keysize) -{ -unsigned char *base = (unsigned char *)(*next & JUDY_mask); -int oldcnt, newcnt, slot; -#if BYTE_ORDER == BIG_ENDIAN - int i; -#endif -JudySlot *newnode, *node; -JudySlot *result; -unsigned char *newbase; -unsigned int type; - - type = (*next & 0x07) + 1; - node = (JudySlot *)((*next & JUDY_mask) + JudySize[type-1]); - oldcnt = JudySize[type-1] / (sizeof(JudySlot) + keysize); - newcnt = JudySize[type] / (sizeof(JudySlot) + keysize); - - // promote node to next larger size - - newbase = judy_alloc (judy, type); - newnode = (JudySlot *)(newbase + JudySize[type]); - *next = (JudySlot)newbase | type; - - // open up slot at idx - - memcpy(newbase + (newcnt - oldcnt - 1) * keysize, base, idx * keysize); // copy keys - - for( slot = 0; slot < idx; slot++ ) - newnode[-(slot + newcnt - oldcnt)] = node[-(slot + 1)]; // copy ptr - - // fill in new node - -#if BYTE_ORDER != BIG_ENDIAN - memcpy(newbase + (idx + newcnt - oldcnt - 1) * keysize, &value, keysize); // copy key -#else - i = keysize; - - while( i-- ) - newbase[(idx + newcnt - oldcnt - 1) * keysize + i] = value, value >>= 8; -#endif - result = &newnode[-(idx + newcnt - oldcnt)]; - - // copy rest of old node - - memcpy(newbase + (idx + newcnt - oldcnt) * keysize, base + (idx * keysize), (oldcnt - slot) * keysize); // copy keys - - for( ; slot < oldcnt; slot++ ) - newnode[-(slot + newcnt - oldcnt + 1)] = node[-(slot + 1)]; // copy ptr - -#ifndef ASKITIS - judy->stack[judy->level].next = *next; - judy->stack[judy->level].slot = idx + newcnt - oldcnt - 1; -#endif - judy_free (judy, (void **)base, type - 1); - return result; -} - -// construct new node for JUDY_radix entry -// make node with slot - start entries -// moving key over one offset - -void judy_radix (Judy *judy, JudySlot *radix, unsigned char *old, int start, int slot, int keysize, unsigned char key, unsigned int depth) -{ -int size, idx, cnt = slot - start, newcnt; -JudySlot *node, *oldnode; -unsigned int type = JUDY_1 - 1; -JudySlot *table; -unsigned char *base; - - // if necessary, setup inner radix node - - if( !(table = (JudySlot *)(radix[key >> 4] & JUDY_mask)) ) { - table = judy_alloc (judy, JUDY_radix); - radix[key >> 4] = (JudySlot)table | JUDY_radix; - } - - oldnode = (JudySlot *)(old + JudySize[JUDY_max]); - - // is this slot a leaf? - - if( !judy->depth && (!key || !keysize) || judy->depth && !keysize && depth == judy->depth) { - table[key & 0x0F] = oldnode[-start-1]; - return; - } - - // calculate new node big enough to contain slots - - do { - type++; - size = JudySize[type]; - newcnt = size / (sizeof(JudySlot) + keysize); - } while( cnt > newcnt && type < JUDY_max ); - - // store new node pointer in inner table - - base = judy_alloc (judy, type); - node = (JudySlot *)(base + size); - table[key & 0x0F] = (JudySlot)base | type; - - // allocate node and copy old contents - // shorten keys by 1 byte during copy - - for( idx = 0; idx < cnt; idx++ ) { -#if BYTE_ORDER != BIG_ENDIAN - memcpy (base + (newcnt - idx - 1) * keysize, old + (start + cnt - idx - 1) * (keysize + 1), keysize); -#else - memcpy (base + (newcnt - idx - 1) * keysize, old + (start + cnt - idx - 1) * (keysize + 1) + 1, keysize); -#endif - node[-(newcnt - idx)] = oldnode[-(start + cnt - idx)]; - } -} - -// decompose full node to radix nodes - -void judy_splitnode (Judy *judy, JudySlot *next, unsigned int size, unsigned int keysize, unsigned int depth) -{ -int cnt, slot, start = 0; -unsigned int key = 0x0100, nxt; -JudySlot *newradix; -unsigned char *base; - - base = (unsigned char *)(*next & JUDY_mask); - cnt = size / (sizeof(JudySlot) + keysize); - - // allocate outer judy_radix node - - newradix = judy_alloc (judy, JUDY_radix); - *next = (JudySlot)newradix | JUDY_radix; - - for( slot = 0; slot < cnt; slot++ ) { -#if BYTE_ORDER != BIG_ENDIAN - nxt = base[slot * keysize + keysize - 1]; -#else - nxt = base[slot * keysize]; -#endif - - if( key > 0xFF ) - key = nxt; - if( nxt == key ) - continue; - - // decompose portion of old node into radix nodes - - judy_radix (judy, newradix, base, start, slot, keysize - 1, (unsigned char)key, depth); - start = slot; - key = nxt; - } - - judy_radix (judy, newradix, base, start, slot, keysize - 1, (unsigned char)key, depth); - judy_free (judy, (void **)base, JUDY_max); -} - -// return first leaf - -JudySlot *judy_first (Judy *judy, JudySlot next, unsigned int off, unsigned int depth) -{ -JudySlot *table, *inner; -unsigned int keysize, size; -JudySlot *node; -int slot, cnt; -unsigned char *base; - - while( next ) { - if( judy->level < judy->max ) - judy->level++; - - judy->stack[judy->level].off = off; - judy->stack[judy->level].next = next; - size = JudySize[next & 0x07]; - - switch( next & 0x07 ) { - case JUDY_1: - case JUDY_2: - case JUDY_4: - case JUDY_8: - case JUDY_16: - case JUDY_32: -#ifdef ASKITIS - case JUDY_64: -#endif - keysize = JUDY_key_size - (off & JUDY_key_mask); - node = (JudySlot *)((next & JUDY_mask) + size); - base = (unsigned char *)(next & JUDY_mask); - cnt = size / (sizeof(JudySlot) + keysize); - - for( slot = 0; slot < cnt; slot++ ) - if( node[-slot-1] ) - break; - - judy->stack[judy->level].slot = slot; -#if BYTE_ORDER != BIG_ENDIAN - if( !judy->depth && !base[slot * keysize] || judy->depth && ++depth == judy->depth ) - return &node[-slot-1]; -#else - if( !judy->depth && !base[slot * keysize + keysize - 1] || judy->depth && ++depth == judy->depth ) - return &node[-slot-1]; -#endif - next = node[-slot - 1]; - off = (off | JUDY_key_mask) + 1; - continue; - case JUDY_radix: - off++; - - if( judy->depth ) - if( !(off & JUDY_key_mask) ) - depth++; - - table = (JudySlot *)(next & JUDY_mask); - for( slot = 0; slot < 256; slot++ ) - if( (inner = (JudySlot *)(table[slot >> 4] & JUDY_mask)) ) { - if( (next = inner[slot & 0x0F]) ) { - judy->stack[judy->level].slot = slot; - if( !judy->depth && !slot || judy->depth && depth == judy->depth ) - return &inner[slot & 0x0F]; - else - break; - } - } else - slot |= 0x0F; - continue; -#ifndef ASKITIS - case JUDY_span: - node = (JudySlot *)((next & JUDY_mask) + JudySize[JUDY_span]); - base = (unsigned char *)(next & JUDY_mask); - cnt = JUDY_span_bytes; - if( !base[cnt - 1] ) // leaf node? - return &node[-1]; - next = node[-1]; - off += cnt; - continue; -#endif - } - } - return NULL; -} - -// return last leaf cell pointer - -JudySlot *judy_last (Judy *judy, JudySlot next, unsigned int off, unsigned int depth) -{ -JudySlot *table, *inner; -unsigned int keysize, size; -JudySlot *node; -int slot, cnt; -unsigned char *base; - - while( next ) { - if( judy->level < judy->max ) - judy->level++; - - judy->stack[judy->level].next = next; - judy->stack[judy->level].off = off; - size = JudySize[next & 0x07]; - switch( next & 0x07 ) { - case JUDY_1: - case JUDY_2: - case JUDY_4: - case JUDY_8: - case JUDY_16: - case JUDY_32: -#ifdef ASKITIS - case JUDY_64: -#endif - keysize = JUDY_key_size - (off & JUDY_key_mask); - slot = size / (sizeof(JudySlot) + keysize); - base = (unsigned char *)(next & JUDY_mask); - node = (JudySlot *)((next & JUDY_mask) + size); - judy->stack[judy->level].slot = --slot; - -#if BYTE_ORDER != BIG_ENDIAN - if( !judy->depth && !base[slot * keysize] || judy->depth && ++depth == judy->depth ) -#else - if( !judy->depth && !base[slot * keysize + keysize - 1] || judy->depth && ++depth == judy->depth ) -#endif - return &node[-slot-1]; - - next = node[-slot-1]; - off += keysize; - continue; - - case JUDY_radix: - table = (JudySlot *)(next & JUDY_mask); - off++; - - if( judy->depth ) - if( !(off & JUDY_key_mask) ) - depth++; - - for( slot = 256; slot--; ) { - judy->stack[judy->level].slot = slot; - if( (inner = (JudySlot *)(table[slot >> 4] & JUDY_mask)) ) { - if( (next = inner[slot & 0x0F]) ) - if( !judy->depth && !slot || judy->depth && depth == judy->depth ) - return &inner[0]; - else - break; - } else - slot &= 0xF0; - } - continue; - -#ifndef ASKITIS - case JUDY_span: - node = (JudySlot *)((next & JUDY_mask) + JudySize[JUDY_span]); - base = (unsigned char *)(next & JUDY_mask); - cnt = JUDY_span_bytes; - if( !base[cnt - 1] ) // leaf node? - return &node[-1]; - next = node[-1]; - off += cnt; - continue; -#endif - } - } - return NULL; -} - -// judy_end: return last entry - -JudySlot *judy_end (Judy *judy) -{ - judy->level = 0; - return judy_last (judy, *judy->root, 0, 0); -} // judy_nxt: return next entry - -JudySlot *judy_nxt (Judy *judy) -{ -JudySlot *table, *inner; -int slot, size, cnt; -JudySlot *node; -JudySlot next; -unsigned int keysize; -unsigned char *base; -unsigned int depth; -unsigned int off; - - if( !judy->level ) - return judy_first (judy, *judy->root, 0, 0); - - while( judy->level ) { - next = judy->stack[judy->level].next; - slot = judy->stack[judy->level].slot; - off = judy->stack[judy->level].off; - keysize = JUDY_key_size - (off & JUDY_key_mask); - size = JudySize[next & 0x07]; - depth = off / JUDY_key_size; - - switch( next & 0x07 ) { - case JUDY_1: - case JUDY_2: - case JUDY_4: - case JUDY_8: - case JUDY_16: - case JUDY_32: -#ifdef ASKITIS - case JUDY_64: -#endif - cnt = size / (sizeof(JudySlot) + keysize); - node = (JudySlot *)((next & JUDY_mask) + size); - base = (unsigned char *)(next & JUDY_mask); - if( ++slot < cnt ) -#if BYTE_ORDER != BIG_ENDIAN - if( !judy->depth && !base[slot * keysize] || judy->depth && ++depth == judy->depth ) -#else - if( !judy->depth && !base[slot * keysize + keysize - 1] || judy->depth && ++depth == judy->depth ) -#endif - { - judy->stack[judy->level].slot = slot; - return &node[-slot - 1]; - } else { - judy->stack[judy->level].slot = slot; - return judy_first (judy, node[-slot-1], (off | JUDY_key_mask) + 1, depth); - } - judy->level--; - continue; - - case JUDY_radix: - table = (JudySlot *)(next & JUDY_mask); - - if( judy->depth ) - if( !((off+1) & JUDY_key_mask) ) - depth++; - - while( ++slot < 256 ) - if( (inner = (JudySlot *)(table[slot >> 4] & JUDY_mask)) ) { - if( inner[slot & 0x0F] ) { - judy->stack[judy->level].slot = slot; - if( !judy->depth || depth < judy->depth ) - return judy_first(judy, inner[slot & 0x0F], off + 1, depth); - return &inner[slot & 0x0F]; - } - } else - slot |= 0x0F; - - judy->level--; - continue; -#ifndef ASKITIS - case JUDY_span: - judy->level--; - continue; -#endif - } - } - return NULL; -} - -// judy_prv: return ptr to previous entry - -JudySlot *judy_prv (Judy *judy) -{ -int slot, size, keysize; -JudySlot *table, *inner; -JudySlot *node, next; -unsigned char *base; -unsigned int depth; -unsigned int off; - - if( !judy->level ) - return judy_last (judy, *judy->root, 0, 0); - - while( judy->level ) { - next = judy->stack[judy->level].next; - slot = judy->stack[judy->level].slot; - off = judy->stack[judy->level].off; - size = JudySize[next & 0x07]; - depth = off / JUDY_key_size; - - switch( next & 0x07 ) { - case JUDY_1: - case JUDY_2: - case JUDY_4: - case JUDY_8: - case JUDY_16: - case JUDY_32: -#ifdef ASKITIS - case JUDY_64: -#endif - node = (JudySlot *)((next & JUDY_mask) + size); - if( !slot || !node[-slot] ) { - judy->level--; - continue; - } - - base = (unsigned char *)(next & JUDY_mask); - judy->stack[judy->level].slot--; - keysize = JUDY_key_size - (off & JUDY_key_mask); - -#if BYTE_ORDER != BIG_ENDIAN - if( !judy->depth && !base[(slot - 1) * keysize] || judy->depth && ++depth == judy->depth ) -#else - if( !judy->depth && !base[(slot - 1) * keysize + keysize - 1] || judy->depth && ++depth == judy->depth ) -#endif - return &node[-slot]; - return judy_last (judy, node[-slot], (off | JUDY_key_mask) + 1, depth); - - case JUDY_radix: - table = (JudySlot *)(next & JUDY_mask); - - if( judy->depth ) - if( !((off + 1) & JUDY_key_mask) ) - depth++; - - while( slot-- ) { - judy->stack[judy->level].slot--; - if( (inner = (JudySlot *)(table[slot >> 4] & JUDY_mask)) ) - if( inner[slot & 0x0F] ) - if( !judy->depth && !slot || judy->depth && depth == judy->depth ) - return &inner[0]; - else - return judy_last(judy, inner[slot & 0x0F], off + 1, depth); - } - - judy->level--; - continue; - -#ifndef ASKITIS - case JUDY_span: - judy->level--; - continue; -#endif - } - } - return NULL; -} - -// judy_del: delete string from judy array -// returning previous entry. - -JudySlot *judy_del (Judy *judy) -{ -int slot, off, size, type, high; -JudySlot *table, *inner; -JudySlot next, *node; -int keysize, cnt; -unsigned char *base; - - while( judy->level ) { - next = judy->stack[judy->level].next; - slot = judy->stack[judy->level].slot; - off = judy->stack[judy->level].off; - size = JudySize[next & 0x07]; - - switch( type = next & 0x07 ) { - case JUDY_1: - case JUDY_2: - case JUDY_4: - case JUDY_8: - case JUDY_16: - case JUDY_32: -#ifdef ASKITIS - case JUDY_64: -#endif - keysize = JUDY_key_size - (off & JUDY_key_mask); - cnt = size / (sizeof(JudySlot) + keysize); - node = (JudySlot *)((next & JUDY_mask) + size); - base = (unsigned char *)(next & JUDY_mask); - - // move deleted slot to first slot - - while( slot ) { - node[-slot-1] = node[-slot]; - memcpy (base + slot * keysize, base + (slot - 1) * keysize, keysize); - slot--; - } - - // zero out first slot - - node[-1] = 0; - memset (base, 0, keysize); - - if( node[-cnt] ) { // does node have any slots left? - judy->stack[judy->level].slot++; - return judy_prv (judy); - } - - judy_free (judy, base, type); - judy->level--; - continue; - - case JUDY_radix: - table = (JudySlot *)(next & JUDY_mask); - inner = (JudySlot *)(table[slot >> 4] & JUDY_mask); - inner[slot & 0x0F] = 0; - high = slot & 0xF0; - - for( cnt = 16; cnt--; ) - if( inner[cnt] ) - return judy_prv (judy); - - judy_free (judy, inner, JUDY_radix); - table[slot >> 4] = 0; - - for( cnt = 16; cnt--; ) - if( table[cnt] ) - return judy_prv (judy); - - judy_free (judy, table, JUDY_radix); - judy->level--; - continue; - -#ifndef ASKITIS - case JUDY_span: - base = (unsigned char *)(next & JUDY_mask); - judy_free (judy, base, type); - judy->level--; - continue; -#endif - } - } - - // tree is now empty - - *judy->root = 0; - return NULL; -} - -// return cell for first key greater than or equal to given key - -JudySlot *judy_strt (Judy *judy, unsigned char *buff, unsigned int max) -{ -JudySlot *cell; - - judy->level = 0; - - if( !max ) - return judy_first (judy, *judy->root, 0, 0); - - if( (cell = judy_slot (judy, buff, max)) ) - return cell; - - return judy_nxt (judy); -} - -// split open span node - -#ifndef ASKITIS -void judy_splitspan (Judy *judy, JudySlot *next, unsigned char *base) -{ -JudySlot *node = (JudySlot *)(base + JudySize[JUDY_span]); -unsigned int cnt = JUDY_span_bytes; -unsigned char *newbase; -unsigned int off = 0; -#if BYTE_ORDER != BIG_ENDIAN -int i; -#endif - - do { - newbase = judy_alloc (judy, JUDY_1); - *next = (JudySlot)newbase | JUDY_1; - -#if BYTE_ORDER != BIG_ENDIAN - i = JUDY_key_size; - while( i-- ) - *newbase++ = base[off + i]; -#else - memcpy (newbase, base + off, JUDY_key_size); - newbase += JUDY_key_size; -#endif - next = (JudySlot *)newbase; - - off += JUDY_key_size; - cnt -= JUDY_key_size; - } while( cnt && base[off - 1] ); - - *next = node[-1]; - judy_free (judy, base, JUDY_span); -} -#endif - -// judy_cell: add string to judy array - -JudySlot *judy_cell (Judy *judy, unsigned char *buff, unsigned int max) -{ -judyvalue *src = (judyvalue *)buff; -int size, idx, slot, cnt, tst; -JudySlot *next = judy->root; -judyvalue test, value; -unsigned int off = 0, start; -JudySlot *table; -JudySlot *node; -unsigned int depth = 0; -unsigned int keysize; -unsigned char *base; - - judy->level = 0; -#ifdef ASKITIS - Words++; -#endif - - while( *next ) { -#ifndef ASKITIS - if( judy->level < judy->max ) - judy->level++; - - judy->stack[judy->level].next = *next; - judy->stack[judy->level].off = off; -#endif - switch( *next & 0x07 ) { - default: - size = JudySize[*next & 0x07]; - keysize = JUDY_key_size - (off & JUDY_key_mask); - cnt = size / (sizeof(JudySlot) + keysize); - base = (unsigned char *)(*next & JUDY_mask); - node = (JudySlot *)((*next & JUDY_mask) + size); - start = off; - slot = cnt; - value = 0; - - if( judy->depth ) { - value = src[depth++]; - off |= JUDY_key_mask; - off++; - value &= JudyMask[keysize]; - } else - do { - value <<= 8; - if( off < max ) - value |= buff[off]; - } while( ++off & JUDY_key_mask ); - - // find slot > key - - while( slot-- ) { - test = *(judyvalue *)(base + slot * keysize); -#if BYTE_ORDER == BIG_ENDIAN - test >>= 8 * (JUDY_key_size - keysize); -#else - test &= JudyMask[keysize]; -#endif - if( test <= value ) - break; - } -#ifndef ASKITIS - judy->stack[judy->level].slot = slot; -#endif - if( test == value ) { // new key is equal to slot key - next = &node[-slot-1]; - - // is this a leaf? - - if( !judy->depth && !(value & 0xFF) || judy->depth && depth == judy->depth ) { -#ifdef ASKITIS - if( *next ) - Found++; - else - Inserts++; -#endif - return next; - } - - continue; - } - - // if this node is not full - // open up cell after slot - - if( !node[-1] ) { - memmove(base, base + keysize, slot * keysize); // move keys less than new key down one slot -#if BYTE_ORDER != BIG_ENDIAN - memcpy(base + slot * keysize, &value, keysize); // copy new key into slot -#else - test = value; - idx = keysize; - - while( idx-- ) - base[slot * keysize + idx] = test, test >>= 8; -#endif - for( idx = 0; idx < slot; idx++ ) - node[-idx-1] = node[-idx-2];// copy tree ptrs/cells down one slot - - node[-slot-1] = 0; // set new tree ptr/cell - next = &node[-slot-1]; - - if( !judy->depth && !(value & 0xFF) || judy->depth && depth == judy->depth ) { -#ifdef ASKITIS - if( *next ) - Found++; - else - Inserts++; -#endif - return next; - } - - continue; - } - - if( size < JudySize[JUDY_max] ) { - next = judy_promote (judy, next, slot+1, value, keysize); - - if( !judy->depth && !(value & 0xFF) || judy->depth && depth == judy->depth ) { -#ifdef ASKITIS - if( *next ) - Found++; - else - Inserts++; -#endif - return next; - } - - continue; - } - - // split full maximal node into JUDY_radix nodes - // loop to reprocess new insert - - judy_splitnode (judy, next, size, keysize, depth); -#ifndef ASKITIS - judy->level--; -#endif - off = start; - if( judy->depth ) - depth--; - continue; - - case JUDY_radix: - table = (JudySlot *)(*next & JUDY_mask); // outer radix - - if( judy->depth ) - slot = (src[depth] >> ((JUDY_key_size - ++off & JUDY_key_mask) * 8)) & 0xff; - else if( off < max ) - slot = buff[off++]; - else - slot = 0, off++; - - if( judy->depth ) - if( !(off & JUDY_key_mask) ) - depth++; - - // allocate inner radix if empty - - if( !table[slot >> 4] ) - table[slot >> 4] = (JudySlot)judy_alloc (judy, JUDY_radix) | JUDY_radix; - - table = (JudySlot *)(table[slot >> 4] & JUDY_mask); -#ifndef ASKITIS - judy->stack[judy->level].slot = slot; -#endif - next = &table[slot & 0x0F]; - - if( !judy->depth && !slot || judy->depth && depth == judy->depth ) { // leaf? -#ifdef ASKITIS - if( *next ) - Found++; - else - Inserts++; -#endif - return next; - } - - continue; - -#ifndef ASKITIS - case JUDY_span: - base = (unsigned char *)(*next & JUDY_mask); - node = (JudySlot *)((*next & JUDY_mask) + JudySize[JUDY_span]); - cnt = JUDY_span_bytes; - tst = cnt; - - if( tst > (int)(max - off) ) - tst = max - off; - - value = strncmp((const char *)base, (const char *)(buff + off), tst); - - if( !value && tst < cnt && !base[tst] ) // leaf? - return &node[-1]; - - if( !value && tst == cnt ) { - next = &node[-1]; - off += cnt; - continue; - } - - // bust up JUDY_span node and produce JUDY_1 nodes - // then loop to reprocess insert - - judy_splitspan (judy, next, base); - judy->level--; - continue; -#endif - } - } - - // place JUDY_1 node under JUDY_radix node(s) - -#ifndef ASKITIS - if( off & JUDY_key_mask ) - if( judy->depth || off <= max ) { -#else - while( off <= max ) { -#endif - base = judy_alloc (judy, JUDY_1); - keysize = JUDY_key_size - (off & JUDY_key_mask); - node = (JudySlot *)(base + JudySize[JUDY_1]); - *next = (JudySlot)base | JUDY_1; - - // fill in slot 0 with bytes of key - - if( judy->depth ) { - value = src[depth]; -#if BYTE_ORDER != BIG_ENDIAN - memcpy(base, &value, keysize); // copy new key into slot -#else - while( keysize-- ) - base[keysize] = value, value >>= 8; -#endif - } else { -#if BYTE_ORDER != BIG_ENDIAN - while( keysize ) - if( off + keysize <= max ) - *base++ = buff[off + --keysize]; - else - base++, --keysize; -#else - tst = keysize; - - if( tst > (int)(max - off) ) - tst = max - off; - - memcpy (base, buff + off, tst); -#endif - } -#ifndef ASKITIS - if( judy->level < judy->max ) - judy->level++; - judy->stack[judy->level].next = *next; - judy->stack[judy->level].slot = 0; - judy->stack[judy->level].off = off; -#endif - next = &node[-1]; - - off |= JUDY_key_mask; - depth++; - off++; - } - - // produce span nodes to consume rest of key - // or judy_1 nodes if not string tree - -#ifndef ASKITIS - if( !judy->depth ) - while( off <= max ) { - base = judy_alloc (judy, JUDY_span); - *next = (JudySlot)base | JUDY_span; - node = (JudySlot *)(base + JudySize[JUDY_span]); - cnt = tst = JUDY_span_bytes; - if( tst > (int)(max - off) ) - tst = max - off; - memcpy (base, buff + off, tst); - - if( judy->level < judy->max ) - judy->level++; - judy->stack[judy->level].next = *next; - judy->stack[judy->level].slot = 0; - judy->stack[judy->level].off = off; - next = &node[-1]; - off += tst; - depth++; - - if( !base[cnt-1] ) // done on leaf - break; - } - else - while( depth < judy->depth ) { - base = judy_alloc (judy, JUDY_1); - node = (JudySlot *)(base + JudySize[JUDY_1]); - *next = (JudySlot)base | JUDY_1; - - // fill in slot 0 with bytes of key - - *(judyvalue *)base = src[depth]; - - if( judy->level < judy->max ) - judy->level++; - judy->stack[judy->level].next = *next; - judy->stack[judy->level].slot = 0; - judy->stack[judy->level].off = off; - next = &node[-1]; - off |= JUDY_key_mask; - depth++; - off++; - } -#endif - -#ifdef ASKITIS - Inserts++; -#endif - return next; -} - -#if defined(STANDALONE) || defined(ASKITIS) - -#if defined(__APPLE__) || defined(linux) -#include -#include -#include -#include -#include -#else -#include -#include -#endif - -#include - -// memory map input file and sort - -// define pennysort parameters - -unsigned int PennyRecs = (4096 * 400); // records to sort to temp files -unsigned int PennyLine = 100; // length of input record -unsigned int PennyKey = 10; // length of input key -unsigned int PennyOff = 0; // key offset in input record - -unsigned long long PennyMerge; // PennyRecs * PennyLine = file map length -unsigned int PennyPasses; // number of intermediate files created -unsigned int PennySortTime; // cpu time to run sort -unsigned int PennyMergeTime; // cpu time to run merge - -typedef struct { - void *buff; // record pointer in input file map - void *next; // duplicate chain -} PennySort; - -void sort (FILE *infile, char *outname) -{ -unsigned long long size, off, offset, part; -int ifd = fileno (infile); -char filename[512]; -PennySort *line; -JudySlot *cell; -unsigned char *inbuff; -void *judy; -FILE *out; -#if defined(_WIN32) -HANDLE hndl, fm; -DWORD hiword; -FILETIME dummy[1]; -FILETIME user[1]; -#else -struct tms buff[1]; -#endif -time_t start = time(NULL); - - if( PennyOff + PennyKey > PennyLine ) - fprintf (stderr, "Key Offset + Key Length > Record Length\n"), exit(1); - - offset = 0; - PennyPasses = 0; - -#if defined(_WIN32) - hndl = (HANDLE)_get_osfhandle(ifd); - size = GetFileSize (hndl, &hiword); - fm = CreateFileMapping(hndl, NULL, PAGE_READONLY, hiword, (DWORD)size, NULL); - if( !fm ) - fprintf (stderr, "CreateFileMapping error %d\n", GetLastError()), exit(1); - size |= (unsigned long long)hiword << 32; -#else - size = lseek (ifd, 0L, 2); -#endif - - while( offset < size ) { -#if defined(_WIN32) - part = offset + PennyMerge > size ? size - offset : PennyMerge; - inbuff = MapViewOfFile( fm, FILE_MAP_READ, offset >> 32, offset, part); - if( !inbuff ) - fprintf (stderr, "MapViewOfFile error %d\n", GetLastError()), exit(1); -#else - inbuff = mmap (NULL, PennyMerge, PROT_READ, MAP_SHARED, ifd, offset); - - if( inbuff == MAP_FAILED ) - fprintf (stderr, "mmap error %d\n", errno), exit(1); - - if( madvise (inbuff, PennyMerge, MADV_WILLNEED | MADV_SEQUENTIAL) < 0 ) - fprintf (stderr, "madvise error %d\n", errno); -#endif - judy = judy_open (PennyKey, 0); - - off = 0; - - // build judy array from mapped input chunk - - while( offset + off < size && off < PennyMerge ) { - line = judy_data (judy, sizeof(PennySort)); - cell = judy_cell (judy, inbuff + off + PennyOff, PennyKey); - line->next = *(void **)cell; - line->buff = inbuff + off; - - *(PennySort **)cell = line; - off += PennyLine; - } - - sprintf (filename, "%s.%d", outname, PennyPasses); - out = fopen (filename, "wb"); - setvbuf (out, NULL, _IOFBF, 4096 * 1024); - -#ifndef _WIN32 - if( madvise (inbuff, PennyMerge, MADV_WILLNEED | MADV_RANDOM) < 0 ) - fprintf (stderr, "madvise error %d\n", errno); -#endif - - // write judy array in sorted order to temporary file - - cell = judy_strt (judy, NULL, 0); - - if( cell ) do { - line = *(PennySort **)cell; - do fwrite (line->buff, PennyLine, 1, out); - while( line = line->next ); - } while( cell = judy_nxt (judy) ); - -#if defined(_WIN32) - UnmapViewOfFile (inbuff); -#else - munmap (inbuff, PennyMerge); -#endif - judy_close (judy); - offset += off; - fflush (out); - fclose (out); - PennyPasses++; - } - fprintf (stderr, "End Sort %d secs", time(NULL) - start); -#if defined(_WIN32) - CloseHandle (fm); - GetProcessTimes (GetCurrentProcess(), dummy, dummy, dummy, user); - PennySortTime = *(unsigned long long*)user / 10000000; -#else - times (buff); - PennySortTime = buff->tms_utime/100; -#endif - fprintf (stderr, " Cpu %d\n", PennySortTime); -} - -int merge (FILE *out, char *outname) -{ -time_t start = time(NULL); -char filename[512]; -JudySlot *cell; -unsigned int nxt, idx; -unsigned char **line; -unsigned int *next; -void *judy; -FILE **in; - - next = calloc (PennyPasses + 1, sizeof(unsigned int)); - line = calloc (PennyPasses, sizeof(void *)); - in = calloc (PennyPasses, sizeof(void *)); - - judy = judy_open (PennyKey, 0); - - // initialize merge with one record from each temp file - - for( idx = 0; idx < PennyPasses; idx++ ) { - sprintf (filename, "%s.%d", outname, idx); - in[idx] = fopen (filename, "rb"); - line[idx] = malloc (PennyLine); - setvbuf (in[idx], NULL, _IOFBF, 4096 * 1024); - fread (line[idx], PennyLine, 1, in[idx]); - cell = judy_cell (judy, line[idx] + PennyOff, PennyKey); - next[idx + 1] = *(unsigned int *)cell; - *cell = idx + 1; - } - - // output records, replacing smallest each time - - while( cell = judy_strt (judy, NULL, 0) ) { - nxt = *(unsigned int *)cell; - judy_del (judy); - - // process duplicates - - while( idx = nxt ) { - nxt = next[idx--]; - fwrite (line[idx], PennyLine, 1, out); - - if( fread (line[idx], PennyLine, 1, in[idx]) ) { - cell = judy_cell (judy, line[idx] + PennyOff, PennyKey); - next[idx + 1] = *(unsigned int *)cell; - *cell = idx + 1; - } else - next[idx + 1] = 0; - } - } - - for( idx = 0; idx < PennyPasses; idx++ ) { - fclose (in[idx]); - free (line[idx]); - } - - free (line); - free (next); - free (in); - - fprintf (stderr, "End Merge %d secs", time(NULL) - start); -#ifdef _WIN32 - { - FILETIME dummy[1]; - FILETIME user[1]; - GetProcessTimes (GetCurrentProcess(), dummy, dummy, dummy, user); - PennyMergeTime = *(unsigned long long*)user / 10000000; - } -#else - { - struct tms buff[1]; - times (buff); - PennyMergeTime = buff->tms_utime/100; - } -#endif - fprintf (stderr, " Cpu %d\n", PennyMergeTime - PennySortTime); - judy_close (judy); - fflush (out); - fclose (out); - return 0; -} - -// compilation: -// cc -O3 judy64j.c - -// usage: -// a.out [in-file] [out-file] [keysize] [recordlen] [keyoffset] [mergerecs] -// where keysize is 10 to indicate pennysort files - -#if !defined(_WIN32) -typedef struct timeval timer; -#endif - -// ASKITIS compilation: -// cc -O3 judy64n.c - -// usage: -// a.out [in-file] [out-file] [keysize] [recordlen] [keyoffset] [mergerecs] -// where keysize is 10 to indicate pennysort files - -// naskitis.com. -// g++ -O3 -fpermissive -fomit-frame-pointer -w -D STANDALONE -D ASKITIS -o judy64n judy64n.c -// ./judy64n [input-file-to-build-judy] e.g. distinct_1 or skew1_1 - -// note: the judy array is an in-memory data structure. As such, make sure you -// have enough memory to hold the entire input file + data structure, otherwise -// you'll have to break the input file into smaller pieces and load them in -// on-by-one. - -// Also, the file to search judy is hardcoded to skew1_1. - -int main (int argc, char **argv) -{ -unsigned char buff[1024]; -JudySlot max = 0; -JudySlot *cell; -FILE *in, *out; -void *judy; -unsigned int len; -unsigned int idx; -#ifdef ASKITIS -char *askitis; -int prev, off; -float insert_real_time=0.0; -float search_real_time=0.0; -int size; -#if !defined(_WIN32) -timer start, stop; -#else -time_t start[1], stop[1]; -#endif -#endif - - if( argc > 1 ) - in = fopen (argv[1], "rb"); - else - in = stdin; - - if( argc > 2 ) - out = fopen (argv[2], "wb"); - else - out = stdout; - - setvbuf (out, NULL, _IOFBF, 4096 * 1024); - - if( !in ) - fprintf (stderr, "unable to open input file\n"); - - if( !out ) - fprintf (stderr, "unable to open output file\n"); - - if( argc > 6 ) - PennyRecs = atoi(argv[6]); - - if( argc > 5 ) - PennyOff = atoi(argv[5]); - - if( argc > 4 ) - PennyLine = atoi(argv[4]); - - PennyMerge = (unsigned long long)PennyLine * PennyRecs; - - if( argc > 3 ) { - PennyKey = atoi(argv[3]); - sort (in, argv[2]); - return merge (out, argv[2]); - } - -#ifdef ASKITIS - judy = judy_open (1024, 0); - -// build judy array - size = lseek (fileno(in), 0L, 2); - askitis = malloc(size); - lseek (fileno(in), 0L, 0); - read (fileno(in), askitis,size); - prev = 0; -// naskitis.com: -// Start the timer. - -#if !defined(_WIN32) - gettimeofday(&start, NULL); -#else - time(start); -#endif - - for( off = 0; off < size; off++ ) - if( askitis[off] == '\n' ) { - *(judy_cell (judy, askitis+prev, off - prev)) += 1; // count instances of string - prev = off + 1; - } -// naskitis.com: -// Stop the timer and do some math to compute the time required to insert the strings into the judy array. - -#if !defined(_WIN32) - gettimeofday(&stop, NULL); - - insert_real_time = 1000.0 * ( stop.tv_sec - start.tv_sec ) + 0.001 * (stop.tv_usec - start.tv_usec ); - insert_real_time = insert_real_time/1000.0; -#else - time (stop); - insert_real_time = *stop - *start; -#endif - -// naskitis.com: -// Free the input buffer used to store the first file. We must do this before we get the process size below. - free (askitis); - fprintf(stderr, "JudyArray@Karl_Malbrain\nDASKITIS option enabled\n-------------------------------\n%-20s %.2f MB\n%-20s %.2f sec\n", - "Judy Array size:", MaxMem/1000000., "Time to insert:", insert_real_time); - fprintf(stderr, "%-20s %d\n", "Words:", Words); - fprintf(stderr, "%-20s %d\n", "Inserts:", Inserts); - fprintf(stderr, "%-20s %d\n", "Found:", Found); - - Words = 0; - Inserts = 0; - Found = 0; - -// search judy array - if( in = freopen ("skew1_1", "rb", in) ) - size = lseek (fileno(in), 0L, 2); - else - exit(0); - askitis = malloc(size); - lseek (fileno(in), 0L, 0); - read (fileno(in), askitis,size); - prev = 0; - -#if !defined(_WIN32) - gettimeofday(&start, NULL); -#else - time(start); -#endif - - for( off = 0; off < size; off++ ) - if( askitis[off] == '\n' ) { - *judy_cell (judy, askitis+prev, off - prev) += 1; - prev = off + 1; - } -// naskitis.com: -// Stop the timer and do some math to compute the time required to search the judy array. - -#if !defined(_WIN32) - gettimeofday(&stop, NULL); - search_real_time = 1000.0 * ( stop.tv_sec - start.tv_sec ) + 0.001 - * (stop.tv_usec - start.tv_usec ); - search_real_time = search_real_time/1000.0; -#else - time(stop); - search_real_time = *stop - *start; -#endif - -// naskitis.com: -// To do: report a count on the number of strings found. - - fprintf(stderr,"\n%-20s %.2f MB\n%-20s %.2f sec\n", - "Judy Array size:", MaxMem/1000000., "Time to search:", search_real_time); - fprintf(stderr, "%-20s %d\n", "Words:", Words); - fprintf(stderr, "%-20s %d\n", "Inserts:", Inserts); - fprintf(stderr, "%-20s %d\n", "Found:", Found); - exit(0); -#endif -#ifdef HEXKEYS - judy = judy_open (1024, 16/JUDY_key_size); - - while( fgets((char *)buff, sizeof(buff), in) ) { - judyvalue key[16/JUDY_key_size]; - if( len = strlen((const char *)buff) ) - buff[--len] = 0; // remove LF -#if JUDY_key_size == 4 - key[3] = strtoul (buff + 24, NULL, 16); - buff[24] = 0; - key[2] = strtoul (buff + 16, NULL, 16); - buff[16] = 0; - key[1] = strtoul (buff + 8, NULL, 16); - buff[8] = 0; - key[0] = strtoul (buff, NULL, 16); -#else - key[1] = strtoull (buff + 16, NULL, 16); - buff[16] = 0; - key[0] = strtoull (buff, NULL, 16); -#endif - *(judy_cell (judy, (void *)key, 0)) += 1; // count instances of string - max++; - } - - fprintf(stderr, "%" PRIuint " memory used\n", MaxMem); - - cell = judy_strt (judy, NULL, 0); - - if( cell ) do { - judyvalue key[16/JUDY_key_size]; - len = judy_key(judy, (void *)key, 0); - for( idx = 0; idx < *cell; idx++ ){ // spit out duplicates -#if JUDY_key_size == 4 - fprintf (out, "%.8X", key[0]); - fprintf (out, "%.8X", key[1]); - fprintf (out, "%.8X", key[2]); - fprintf (out, "%.8X", key[3]); -#else - fprintf (out, "%.16llX", key[0]); - fprintf (out, "%.16llX", key[1]); -#endif - fputc('\n', out); - } - } while( cell = judy_nxt (judy) ); - -#else - judy = judy_open (1024, 0); - - while( fgets((char *)buff, sizeof(buff), in) ) { - if( len = strlen((const char *)buff) ) - buff[--len] = 0; // remove LF - *(judy_cell (judy, buff, len)) += 1; // count instances of string - max++; - } - - fprintf(stderr, "%" PRIuint " memory used\n", MaxMem); - - cell = judy_strt (judy, NULL, 0); - - if( cell ) do { - len = judy_key(judy, buff, sizeof(buff)); - for( idx = 0; idx < *cell; idx++ ){ // spit out duplicates - fwrite(buff, len, 1, out); - fputc('\n', out); - } - } while( cell = judy_nxt (judy) ); -#endif -#if 0 - // test deletion all the way to an empty tree - - if( cell = judy_prv (judy) ) - do max -= *cell; - while( cell = judy_del (judy) ); - - assert (max == 0); -#endif - judy_close(judy); - return 0; -} -#endif - diff --git a/src/base/judy/test/hexSort.c b/src/base/judy/test/hexSort.c deleted file mode 100644 index 0d770d752..000000000 --- a/src/base/judy/test/hexSort.c +++ /dev/null @@ -1,124 +0,0 @@ -// Judy arrays 13 DEC 2012 (judy64n.c from http://code.google.com/p/judyarray/ ) -// This code is public domain. - -// Author Karl Malbrain, malbrain AT yahoo.com -// with assistance from Jan Weiss. -// modifications (and any bugs) by Mark Pictor, mpictor at gmail - -// Simplified judy arrays for strings and integers -// Adapted from the ideas of Douglas Baskins of HP. - -// Map a set of keys to corresponding memory cells (uints). -// Each cell must be set to a non-zero value by the caller. - - -// Integer mappings are denoted by calling judy_open with the -// Integer depth of the Judy Trie as the second argument. - -#ifndef STANDALONE -# error must define STANDALONE while compiling this file and judy64.c -#endif - -#include "judy.h" -#include "sort.h" - -unsigned int MaxMem = 0; -/** - usage: - a.out [in-file] [out-file] - where all lines of in-file are 32 chars, hexadecimal - On linux, a 1M-line file can be created with the following: - hexdump -v -e '2/8 "%08x"' -e '"\n"' /dev/urandom |head -n 1000000 >in-file -*/ -int main( int argc, char ** argv ) { - unsigned char buff[1024]; - JudySlot max = 0; - JudySlot * cell; - FILE * in, *out; - void * judy; - unsigned int len; - unsigned int idx; - - if( argc > 1 ) { - in = fopen( argv[1], "rb" ); - } else { - in = stdin; - } - - if( argc > 2 ) { - out = fopen( argv[2], "wb" ); - } else { - out = stdout; - } - - setvbuf( out, NULL, _IOFBF, 4096 * 1024 ); - - if( !in ) { - fprintf( stderr, "unable to open input file\n" ); - } - - if( !out ) { - fprintf( stderr, "unable to open output file\n" ); - } - - PennyMerge = ( unsigned long long )PennyLine * PennyRecs; - - judy = judy_open( 1024, 16 / JUDY_key_size ); - - while( fgets( ( char * )buff, sizeof( buff ), in ) ) { - judyvalue key[16 / JUDY_key_size]; - if( len = strlen( ( const char * )buff ) ) { - buff[--len] = 0; // remove LF - } -#if JUDY_key_size == 4 - key[3] = strtoul( buff + 24, NULL, 16 ); - buff[24] = 0; - key[2] = strtoul( buff + 16, NULL, 16 ); - buff[16] = 0; - key[1] = strtoul( buff + 8, NULL, 16 ); - buff[8] = 0; - key[0] = strtoul( buff, NULL, 16 ); -#else - key[1] = strtoull( buff + 16, NULL, 16 ); - buff[16] = 0; - key[0] = strtoull( buff, NULL, 16 ); -#endif - *( judy_cell( judy, ( void * )key, 0 ) ) += 1; // count instances of string - max++; - } - - fprintf( stderr, "%" PRIuint " memory used\n", MaxMem ); - - cell = judy_strt( judy, NULL, 0 ); - - if( cell ) do { - judyvalue key[16 / JUDY_key_size]; - len = judy_key( judy, ( void * )key, 0 ); - for( idx = 0; idx < *cell; idx++ ) { // spit out duplicates -#if JUDY_key_size == 4 - fprintf( out, "%.8X", key[0] ); - fprintf( out, "%.8X", key[1] ); - fprintf( out, "%.8X", key[2] ); - fprintf( out, "%.8X", key[3] ); -#else - fprintf( out, "%.16llX", key[0] ); - fprintf( out, "%.16llX", key[1] ); -#endif - fputc( '\n', out ); - } - } while( cell = judy_nxt( judy ) ); - -#if 0 - // test deletion all the way to an empty tree - - if( cell = judy_prv( judy ) ) - do { - max -= *cell; - } while( cell = judy_del( judy ) ); - - assert( max == 0 ); -#endif - judy_close( judy ); - return 0; -} - diff --git a/src/base/judy/test/judyL2test.cc b/src/base/judy/test/judyL2test.cc deleted file mode 100644 index 20ef559a9..000000000 --- a/src/base/judy/test/judyL2test.cc +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include - -#include "judyL2Array.h" -typedef judyL2Array< uint64_t, uint64_t > jl2a; - -bool testFind( jl2a & j, uint64_t key, unsigned int count ) { - jl2a::cvector * v = j.find( key ); - std::cout << "find: key " << key << " ..." << std::endl; - if( count > 0 ) { - if( !v || !j.success() || ( v->size() != count ) ) { - std::cout << " false negative - v: " << v << " success: " << j.success(); - if( v ) { - std::cout << " expected count: " << count << " actual: " << v->size(); - } - std::cout << std::endl; - return false; - } else { - // note - this doesn't verify that the right keys are returned, just the right number! - jl2a::vector::const_iterator it = v->begin(); - std::cout << " correct number of values -"; - for( ; it != v->end(); it++ ) { - std::cout << " " << *it; - } - std::cout << std::endl; - } - } else { - if( v || j.success() ) { - std::cout << " false positive - v: " << v << " success: " << j.success() << std::endl; - return false; - } else { - std::cout << " not found, as expected." << std::endl; - } - } - return true; -} - -int main() { - bool pass = true; - jl2a jl; - std::cout.setf( std::ios::boolalpha ); -// std::cout << "size of judyL2Array: " << sizeof( jl ) << std::endl; - jl.insert( 5, 12 ); - jl.insert( 6, 2 ); - jl.insert( 7, 312 ); - jl.insert( 11, 412 ); - jl.insert( 7, 313 ); - jl2a::cpair kv = jl.atOrAfter( 4 ); - std::cout << "atOrAfter test ..." << std::endl; - if( kv.value != 0 && jl.success() ) { - std::cout << " key " << kv.key << " value " << kv.value->at( 0 ) << std::endl; - } else { - std::cout << " failed" << std::endl; - pass = false; - } - - pass &= testFind( jl, 8, 0 ); - pass &= testFind( jl, 11, 1 ); - pass &= testFind( jl, 7, 2 ); - - jl.clear(); - - //TODO test all of judyL2Array - if( pass ) { - std::cout << "All tests passed." << std::endl; - exit( EXIT_SUCCESS ); - } else { - std::cout << "At least one test failed." << std::endl; - exit( EXIT_FAILURE ); - } -} \ No newline at end of file diff --git a/src/base/judy/test/judyLtest.cc b/src/base/judy/test/judyLtest.cc deleted file mode 100644 index 01ae3d5d7..000000000 --- a/src/base/judy/test/judyLtest.cc +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include - -#include "judyLArray.h" - -int main() { - std::cout.setf( std::ios::boolalpha ); - judyLArray< uint64_t, uint64_t > jl; - std::cout << "size of judyLArray: " << sizeof( jl ) << std::endl; - jl.insert( 5, 12 ); - jl.insert( 6, 2 ); - jl.insert( 7, 312 ); - jl.insert( 8, 412 ); - judyLArray< uint64_t, uint64_t >::pair kv = jl.atOrAfter( 4 ); - std::cout << "k " << kv.key << " v " << kv.value << std::endl; - - long v = jl.find( 11 ); - if( v != 0 || jl.success() ) { - std::cout << "find: false positive - v: " << v << " success: " << jl.success() << std::endl; - exit( EXIT_FAILURE ); - } - v = jl.find( 7 ); - if( v != 312 || !jl.success() ) { - std::cout << "find: false negative - v: " << v << " success: " << jl.success() << std::endl; - exit( EXIT_FAILURE ); - } - - jl.clear(); - - //TODO test all of judyLArray - exit( EXIT_SUCCESS ); -} \ No newline at end of file diff --git a/src/base/judy/test/judyS2test.cc b/src/base/judy/test/judyS2test.cc deleted file mode 100644 index ec25f960b..000000000 --- a/src/base/judy/test/judyS2test.cc +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include - -#include "judyS2Array.h" - -typedef judyS2Array< uint64_t > js2a; - -bool testFind( js2a & j, const char * key, unsigned int count ) { - js2a::cvector * v = j.find( key ); - std::cout << "find: key " << key << " ..." << std::endl; - if( count > 0 ) { - if( !v || !j.success() || ( v->size() != count ) ) { - std::cout << " false negative - v: " << v << " success: " << j.success(); - if( v ) { - std::cout << " expected count: " << count << " actual: " << v->size(); - } - std::cout << std::endl; - return false; - } else { - // note - this doesn't verify that the right keys are returned, just the right number! - js2a::vector::const_iterator it = v->begin(); - std::cout << " correct number of values -"; - for( ; it != v->end(); it++ ) { - std::cout << " " << *it; - } - std::cout << std::endl; - } - } else { - if( v || j.success() ) { - std::cout << " false positive - v: " << v << " success: " << j.success() << std::endl; - return false; - } else { - std::cout << " not found, as expected." << std::endl; - } - } - return true; -} - -int main() { - bool pass = true; - std::cout.setf( std::ios::boolalpha ); - - js2a js( 255 ); - js.insert( "blah", 1234 ); - js.insert( "bah", 124 ); - js.insert( "blh", 123 ); - js.insert( "blh", 4123 ); - js.insert( "bla", 134 ); - js.insert( "bh", 234 ); - - js2a::cpair kv = js.atOrAfter( "ab" ); - std::cout << "atOrAfter test ..." << std::endl; - if( kv.value != 0 && js.success() ) { - std::cout << " key " << kv.key << " value " << kv.value->at( 0 ) << std::endl; - } else { - std::cout << " failed" << std::endl; - pass = false; - } - - pass &= testFind( js, "sdafsd", 0 ); - pass &= testFind( js, "bah", 1 ); - pass &= testFind( js, "blh", 2 ); - - js.clear(); - - //TODO test all of judyS2Array - if( pass ) { - std::cout << "All tests passed." << std::endl; - exit( EXIT_SUCCESS ); - } else { - std::cout << "At least one test failed." << std::endl; - exit( EXIT_FAILURE ); - } -} \ No newline at end of file diff --git a/src/base/judy/test/judyStest.cc b/src/base/judy/test/judyStest.cc deleted file mode 100644 index 3d620b015..000000000 --- a/src/base/judy/test/judyStest.cc +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include - -#include "judySArray.h" - -int main() { - bool pass = true; - std::cout.setf( std::ios::boolalpha ); - - judySArray< uint64_t > js( 255 ); - js.insert( "blah", 1234 ); - js.insert( "bah", 124 ); - js.insert( "blh", 123 ); - js.insert( "bla", 134 ); - js.insert( "bh", 234 ); - - - judySArray< uint64_t >::pair kv = js.atOrAfter( "ab" ); - //TODO if()... - std::cout << "k " << kv.key << " v " << kv.value << std::endl; - - long v = js.find( "sdafsd" ); - if( v != 0 || js.success() ) { - std::cout << "find: false positive - v: " << v << " success: " << js.success() << std::endl; - pass = false; - } - v = js.find( "bah" ); - if( v != 124 || !js.success() ) { - std::cout << "find: false negative - v: " << v << " success: " << js.success() << std::endl; - pass = false; - } - - - //TODO test all of judySArray - if( pass ) { - std::cout << "All tests passed." << std::endl; - exit( EXIT_SUCCESS ); - } else { - std::cout << "At least one test failed." << std::endl; - exit( EXIT_FAILURE ); - } -} \ No newline at end of file diff --git a/src/base/judy/test/pennySort.c b/src/base/judy/test/pennySort.c deleted file mode 100644 index a279b1a70..000000000 --- a/src/base/judy/test/pennySort.c +++ /dev/null @@ -1,236 +0,0 @@ -// Judy arrays 13 DEC 2012 (judy64n.c from http://code.google.com/p/judyarray/ ) -// This code is public domain. - -// Author Karl Malbrain, malbrain AT yahoo.com -// with assistance from Jan Weiss. -// modifications (and any bugs) by Mark Pictor, mpictor at gmail - -// Simplified judy arrays for strings and integers -// Adapted from the ideas of Douglas Baskins of HP. - -// Map a set of keys to corresponding memory cells (uints). -// Each cell must be set to a non-zero value by the caller. - -// STANDALONE is defined to compile into a string sorter. - -// String mappings are denoted by calling judy_open with zero as -// the second argument. - -#ifndef STANDALONE -# error must define STANDALONE while compiling this file and judy64.c -#endif - -#include "judy.h" -#include "sort.h" - -unsigned int MaxMem = 0; - -// usage: -// a.out [in-file] [out-file] [keysize] [recordlen] [keyoffset] [mergerecs] -// where keysize is 10 to indicate pennysort files - -// ASKITIS compilation: -// g++ -O3 -fpermissive -fomit-frame-pointer -w -D STANDALONE -D ASKITIS -o judy64n judy64n.c -// ./judy64n [input-file-to-build-judy] e.g. distinct_1 or skew1_1 - -// note: the judy array is an in-memory data structure. As such, make sure you -// have enough memory to hold the entire input file + data structure, otherwise -// you'll have to break the input file into smaller pieces and load them in -// on-by-one. - -// Also, the file to search judy is hardcoded to skew1_1. - -int main( int argc, char ** argv ) { - unsigned char buff[1024]; - JudySlot max = 0; - JudySlot * cell; - FILE * in, *out; - void * judy; - unsigned int len; - unsigned int idx; -#ifdef ASKITIS - char * askitis; - int prev, off; - float insert_real_time = 0.0; - float search_real_time = 0.0; - int size; -#if !defined(_WIN32) - timer start, stop; -#else - time_t start[1], stop[1]; -#endif -#endif - - if( argc > 1 ) { - in = fopen( argv[1], "rb" ); - } else { - in = stdin; - } - - if( argc > 2 ) { - out = fopen( argv[2], "wb" ); - } else { - out = stdout; - } - - setvbuf( out, NULL, _IOFBF, 4096 * 1024 ); - - if( !in ) { - fprintf( stderr, "unable to open input file\n" ); - } - - if( !out ) { - fprintf( stderr, "unable to open output file\n" ); - } - - if( argc > 6 ) { - PennyRecs = atoi( argv[6] ); - } - - if( argc > 5 ) { - PennyOff = atoi( argv[5] ); - } - - if( argc > 4 ) { - PennyLine = atoi( argv[4] ); - } - - PennyMerge = ( unsigned long long )PennyLine * PennyRecs; - - if( argc > 3 ) { - PennyKey = atoi( argv[3] ); - sort( in, argv[2] ); - return merge( out, argv[2] ); - } - -#ifdef ASKITIS - judy = judy_open( 1024, 0 ); - -// build judy array - size = lseek( fileno( in ), 0L, 2 ); - askitis = malloc( size ); - lseek( fileno( in ), 0L, 0 ); - read( fileno( in ), askitis, size ); - prev = 0; -// naskitis.com: -// Start the timer. - -#if !defined(_WIN32) - gettimeofday( &start, NULL ); -#else - time( start ); -#endif - - for( off = 0; off < size; off++ ) - if( askitis[off] == '\n' ) { - *( judy_cell( judy, askitis + prev, off - prev ) ) += 1; // count instances of string - prev = off + 1; - } -// naskitis.com: -// Stop the timer and do some math to compute the time required to insert the strings into the judy array. - -#if !defined(_WIN32) - gettimeofday( &stop, NULL ); - - insert_real_time = 1000.0 * ( stop.tv_sec - start.tv_sec ) + 0.001 * ( stop.tv_usec - start.tv_usec ); - insert_real_time = insert_real_time / 1000.0; -#else - time( stop ); - insert_real_time = *stop - *start; -#endif - -// naskitis.com: -// Free the input buffer used to store the first file. We must do this before we get the process size below. - free( askitis ); - fprintf( stderr, "JudyArray@Karl_Malbrain\nDASKITIS option enabled\n-------------------------------\n%-20s %.2f MB\n%-20s %.2f sec\n", - "Judy Array size:", MaxMem / 1000000., "Time to insert:", insert_real_time ); - fprintf( stderr, "%-20s %d\n", "Words:", Words ); - fprintf( stderr, "%-20s %d\n", "Inserts:", Inserts ); - fprintf( stderr, "%-20s %d\n", "Found:", Found ); - - Words = 0; - Inserts = 0; - Found = 0; - -// search judy array - if( in = freopen( "skew1_1", "rb", in ) ) { - size = lseek( fileno( in ), 0L, 2 ); - } else { - exit( 0 ); - } - askitis = malloc( size ); - lseek( fileno( in ), 0L, 0 ); - read( fileno( in ), askitis, size ); - prev = 0; - -#if !defined(_WIN32) - gettimeofday( &start, NULL ); -#else - time( start ); -#endif - - for( off = 0; off < size; off++ ) - if( askitis[off] == '\n' ) { - *judy_cell( judy, askitis + prev, off - prev ) += 1; - prev = off + 1; - } -// naskitis.com: -// Stop the timer and do some math to compute the time required to search the judy array. - -#if !defined(_WIN32) - gettimeofday( &stop, NULL ); - search_real_time = 1000.0 * ( stop.tv_sec - start.tv_sec ) + 0.001 - * ( stop.tv_usec - start.tv_usec ); - search_real_time = search_real_time / 1000.0; -#else - time( stop ); - search_real_time = *stop - *start; -#endif - -// naskitis.com: -// To do: report a count on the number of strings found. - - fprintf( stderr, "\n%-20s %.2f MB\n%-20s %.2f sec\n", - "Judy Array size:", MaxMem / 1000000., "Time to search:", search_real_time ); - fprintf( stderr, "%-20s %d\n", "Words:", Words ); - fprintf( stderr, "%-20s %d\n", "Inserts:", Inserts ); - fprintf( stderr, "%-20s %d\n", "Found:", Found ); - exit( 0 ); -#endif - - judy = judy_open( 1024, 0 ); - - while( fgets( ( char * )buff, sizeof( buff ), in ) ) { - if( len = strlen( ( const char * )buff ) ) { - buff[--len] = 0; // remove LF - } - *( judy_cell( judy, buff, len ) ) += 1; // count instances of string - max++; - } - - fprintf( stderr, "%" PRIuint " memory used\n", MaxMem ); - - cell = judy_strt( judy, NULL, 0 ); - - if( cell ) do { - len = judy_key( judy, buff, sizeof( buff ) ); - for( idx = 0; idx < *cell; idx++ ) { // spit out duplicates - fwrite( buff, len, 1, out ); - fputc( '\n', out ); - } - } while( cell = judy_nxt( judy ) ); - -#if 0 - // test deletion all the way to an empty tree - - if( cell = judy_prv( judy ) ) - do { - max -= *cell; - } while( cell = judy_del( judy ) ); - - assert( max == 0 ); -#endif - judy_close( judy ); - return 0; -} - diff --git a/src/base/judy/test/sort.c b/src/base/judy/test/sort.c deleted file mode 100644 index e483b92e0..000000000 --- a/src/base/judy/test/sort.c +++ /dev/null @@ -1,233 +0,0 @@ -// Judy arrays 13 DEC 2012 (judy64n.c from http://code.google.com/p/judyarray/ ) -// This code is public domain. - -// Author Karl Malbrain, malbrain AT yahoo.com -// with assistance from Jan Weiss. -// modifications (and any bugs) by Mark Pictor, mpictor at gmail - -// Simplified judy arrays for strings and integers -// Adapted from the ideas of Douglas Baskins of HP. - -// Map a set of keys to corresponding memory cells (uints). -// Each cell must be set to a non-zero value by the caller. - -// STANDALONE is defined to compile into a string sorter. - -// String mappings are denoted by calling judy_open with zero as -// the second argument. Integer mappings are denoted by calling -// judy_open with the Integer depth of the Judy Trie as the second -// argument. - -#include "judy.h" -#include "sort.h" - -// memory map input file and sort - -// define pennysort parameters -unsigned int PennyRecs = ( 4096 * 400 ); // records to sort to temp files -unsigned int PennyLine = 100; // length of input record -unsigned int PennyKey = 10; // length of input key -unsigned int PennyOff = 0; // key offset in input record - -unsigned long long PennyMerge; // PennyRecs * PennyLine = file map length -unsigned int PennyPasses; // number of intermediate files created -unsigned int PennySortTime; // cpu time to run sort -unsigned int PennyMergeTime; // cpu time to run merge - -void sort( FILE * infile, char * outname ) { - unsigned long long size, off, offset, part; - int ifd = fileno( infile ); - char filename[512]; - PennySort * line; - JudySlot * cell; - unsigned char * inbuff; - void * judy; - FILE * out; -#if defined(_WIN32) - HANDLE hndl, fm; - DWORD hiword; - FILETIME dummy[1]; - FILETIME user[1]; -#else - struct tms buff[1]; -#endif - time_t start = time( NULL ); - - if( PennyOff + PennyKey > PennyLine ) { - fprintf( stderr, "Key Offset + Key Length > Record Length\n" ), exit( 1 ); - } - - offset = 0; - PennyPasses = 0; - -#if defined(_WIN32) - hndl = ( HANDLE )_get_osfhandle( ifd ); - size = GetFileSize( hndl, &hiword ); - fm = CreateFileMapping( hndl, NULL, PAGE_READONLY, hiword, ( DWORD )size, NULL ); - if( !fm ) { - fprintf( stderr, "CreateFileMapping error %d\n", GetLastError() ), exit( 1 ); - } - size |= ( unsigned long long )hiword << 32; -#else - size = lseek( ifd, 0L, 2 ); -#endif - - while( offset < size ) { -#if defined(_WIN32) - part = offset + PennyMerge > size ? size - offset : PennyMerge; - inbuff = MapViewOfFile( fm, FILE_MAP_READ, offset >> 32, offset, part ); - if( !inbuff ) { - fprintf( stderr, "MapViewOfFile error %d\n", GetLastError() ), exit( 1 ); - } -#else - inbuff = mmap( NULL, PennyMerge, PROT_READ, MAP_SHARED, ifd, offset ); - - if( inbuff == MAP_FAILED ) { - fprintf( stderr, "mmap error %d\n", errno ), exit( 1 ); - } - - if( madvise( inbuff, PennyMerge, MADV_WILLNEED | MADV_SEQUENTIAL ) < 0 ) { - fprintf( stderr, "madvise error %d\n", errno ); - } -#endif - judy = judy_open( PennyKey, 0 ); - - off = 0; - - // build judy array from mapped input chunk - - while( offset + off < size && off < PennyMerge ) { - line = judy_data( judy, sizeof( PennySort ) ); - cell = judy_cell( judy, inbuff + off + PennyOff, PennyKey ); - line->next = *( void ** )cell; - line->buff = inbuff + off; - - *( PennySort ** )cell = line; - off += PennyLine; - } - - sprintf( filename, "%s.%d", outname, PennyPasses ); - out = fopen( filename, "wb" ); - setvbuf( out, NULL, _IOFBF, 4096 * 1024 ); - -#ifndef _WIN32 - if( madvise( inbuff, PennyMerge, MADV_WILLNEED | MADV_RANDOM ) < 0 ) { - fprintf( stderr, "madvise error %d\n", errno ); - } -#endif - - // write judy array in sorted order to temporary file - - cell = judy_strt( judy, NULL, 0 ); - - if( cell ) do { - line = *( PennySort ** )cell; - do { - fwrite( line->buff, PennyLine, 1, out ); - } while( line = line->next ); - } while( cell = judy_nxt( judy ) ); - -#if defined(_WIN32) - UnmapViewOfFile( inbuff ); -#else - munmap( inbuff, PennyMerge ); -#endif - judy_close( judy ); - offset += off; - fflush( out ); - fclose( out ); - PennyPasses++; - } - fprintf( stderr, "End Sort %llu secs", ( unsigned long long ) time( NULL ) - start ); -#if defined(_WIN32) - CloseHandle( fm ); - GetProcessTimes( GetCurrentProcess(), dummy, dummy, dummy, user ); - PennySortTime = *( unsigned long long * )user / 10000000; -#else - times( buff ); - PennySortTime = buff->tms_utime / 100; -#endif - fprintf( stderr, " Cpu %d\n", PennySortTime ); -} - -int merge( FILE * out, char * outname ) { - time_t start = time( NULL ); - char filename[512]; - JudySlot * cell; - unsigned int nxt, idx; - unsigned char ** line; - unsigned int * next; - void * judy; - FILE ** in; - - next = calloc( PennyPasses + 1, sizeof( unsigned int ) ); - line = calloc( PennyPasses, sizeof( void * ) ); - in = calloc( PennyPasses, sizeof( void * ) ); - - judy = judy_open( PennyKey, 0 ); - - // initialize merge with one record from each temp file - - for( idx = 0; idx < PennyPasses; idx++ ) { - sprintf( filename, "%s.%d", outname, idx ); - in[idx] = fopen( filename, "rb" ); - line[idx] = malloc( PennyLine ); - setvbuf( in[idx], NULL, _IOFBF, 4096 * 1024 ); - fread( line[idx], PennyLine, 1, in[idx] ); - cell = judy_cell( judy, line[idx] + PennyOff, PennyKey ); - next[idx + 1] = *( unsigned int * )cell; - *cell = idx + 1; - } - - // output records, replacing smallest each time - - while( cell = judy_strt( judy, NULL, 0 ) ) { - nxt = *( unsigned int * )cell; - judy_del( judy ); - - // process duplicates - - while( idx = nxt ) { - nxt = next[idx--]; - fwrite( line[idx], PennyLine, 1, out ); - - if( fread( line[idx], PennyLine, 1, in[idx] ) ) { - cell = judy_cell( judy, line[idx] + PennyOff, PennyKey ); - next[idx + 1] = *( unsigned int * )cell; - *cell = idx + 1; - } else { - next[idx + 1] = 0; - } - } - } - - for( idx = 0; idx < PennyPasses; idx++ ) { - fclose( in[idx] ); - free( line[idx] ); - } - - free( line ); - free( next ); - free( in ); - - fprintf( stderr, "End Merge %llu secs", ( unsigned long long ) time( NULL ) - start ); -#ifdef _WIN32 - { - FILETIME dummy[1]; - FILETIME user[1]; - GetProcessTimes( GetCurrentProcess(), dummy, dummy, dummy, user ); - PennyMergeTime = *( unsigned long long * )user / 10000000; - } -#else - { - struct tms buff[1]; - times( buff ); - PennyMergeTime = buff->tms_utime / 100; - } -#endif - fprintf( stderr, " Cpu %d\n", PennyMergeTime - PennySortTime ); - judy_close( judy ); - fflush( out ); - fclose( out ); - return 0; -} diff --git a/src/base/judy/test/sort.h b/src/base/judy/test/sort.h deleted file mode 100644 index 785e58d69..000000000 --- a/src/base/judy/test/sort.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef SORT_H -#define SORT_H - -// Judy arrays 13 DEC 2012 (judy64n.c from http://code.google.com/p/judyarray/ ) -// This code is public domain. - -// Author Karl Malbrain, malbrain AT yahoo.com -// with assistance from Jan Weiss. -// modifications (and any bugs) by Mark Pictor, mpictor at gmail - -// Simplified judy arrays for strings and integers -// Adapted from the ideas of Douglas Baskins of HP. - -// Map a set of keys to corresponding memory cells (uints). -// Each cell must be set to a non-zero value by the caller. - -// STANDALONE is defined to compile into a string sorter. - -// String mappings are denoted by calling judy_open with zero as -// the second argument. Integer mappings are denoted by calling -// judy_open with the Integer depth of the Judy Trie as the second -// argument. - -#include -#include -#include -#include -#include "judy.h" - -#ifdef linux -# include -# include -# include -# include -# include -#else -# include -# include -#endif - -#include - -#define PRIuint "u" - - -//these are initialized in penny.c -extern unsigned int PennyRecs; -extern unsigned int PennyLine; -extern unsigned int PennyKey; -extern unsigned int PennyOff; -extern unsigned long long PennyMerge; - -typedef struct { - void * buff; // record pointer in input file map - void * next; // duplicate chain -} PennySort; - -#endif //SORT_H \ No newline at end of file diff --git a/src/base/path2str.c b/src/base/path2str.c deleted file mode 100644 index 6f5aedd7c..000000000 --- a/src/base/path2str.c +++ /dev/null @@ -1,29 +0,0 @@ - -#include "path2str.h" -#include "sc_memmgr.h" -#include - -/* for windows, rewrite backslashes in paths - * that will be written to generated code - */ -const char * path2str_fn( const char * fileMacro ) { - static char * result = 0; - static size_t rlen = 0; - char * p; - if( rlen < strlen( fileMacro ) ) { - if( result ) { - sc_free( result ); - } - rlen = strlen( fileMacro ); - result = ( char * )sc_malloc( rlen * sizeof( char ) + 1 ); - } - strcpy( result, fileMacro ); - p = result; - while( *p ) { - if( *p == '\\' ) { - *p = '/'; - } - p++; - } - return result; -} diff --git a/src/base/path2str.h b/src/base/path2str.h deleted file mode 100644 index 84155cd9f..000000000 --- a/src/base/path2str.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef PATH2STR_H -#define PATH2STR_H - -#include - -/** windows only: rewrite backslashes in paths as forward slashes - * call as path2str(__FILE__) to take advantage of macro - * - * silence "unknown escape sequence" warning when contents of __FILE__ - * are fprintf'd into string in generated code - */ -SC_BASE_EXPORT const char * path2str_fn( const char * fileMacro ); - -#ifdef _WIN32 -# define path2str(path) path2str_fn(path) -#else -# define path2str(path) path -#endif - -#endif /* PATH2STR_H */ diff --git a/src/base/sc_getopt.cc b/src/base/sc_getopt.cc deleted file mode 100644 index 01e925b56..000000000 --- a/src/base/sc_getopt.cc +++ /dev/null @@ -1,214 +0,0 @@ -/****** RENAMED from xgetopt.cc to sc_getopt.cc ***********/ - -// XGetopt.cpp Version 1.2 -// -// Author: Hans Dietrich -// hdietrich2@hotmail.com -// -// Description: -// XGetopt.cpp implements sc_getopt(), a function to parse command lines. -// -// History -// Version 1.2 - 2003 May 17 -// - Added Unicode support -// -// Version 1.1 - 2002 March 10 -// - Added example to XGetopt.cpp module header -// -// This software is released into the public domain. -// You are free to use it in any way you like. -// -// This software is provided "as is" with no expressed -// or implied warranty. I accept no liability for any -// damage or loss of business that this software may cause. -// -/////////////////////////////////////////////////////////////////////////////// - - -/////////////////////////////////////////////////////////////////////////////// -// if you are using precompiled headers then include this line: -//#include "stdafx.h" -/////////////////////////////////////////////////////////////////////////////// - - -/////////////////////////////////////////////////////////////////////////////// -// if you are not using precompiled headers then include these lines: -//#include -#include -#include -/////////////////////////////////////////////////////////////////////////////// - -#include "sc_getopt.h" - -/////////////////////////////////////////////////////////////////////////////// -// -// X G e t o p t . c p p -// -// -// NAME -// sc_getopt -- parse command line options -// -// SYNOPSIS -// int sc_getopt(int argc, char *argv[], char *optstring) -// -// extern char *sc_optarg; -// extern int sc_optind; -// -// DESCRIPTION -// The sc_getopt() function parses the command line arguments. Its -// arguments argc and argv are the argument count and array as -// passed into the application on program invocation. In the case -// of Visual C++ programs, argc and argv are available via the -// variables __argc and __argv (double underscores), respectively. -// sc_getopt returns the next option letter in argv that matches a -// letter in optstring. (Note: Unicode programs should use -// __targv instead of __argv. Also, all character and string -// literals should be enclosed in _T( ) ). -// -// optstring is a string of recognized option letters; if a letter -// is followed by a colon, the option is expected to have an argument -// that may or may not be separated from it by white space. sc_optarg -// is set to point to the start of the option argument on return from -// sc_getopt. -// -// Option letters may be combined, e.g., "-ab" is equivalent to -// "-a -b". Option letters are case sensitive. -// -// sc_getopt places in the external variable sc_optind the argv index -// of the next argument to be processed. sc_optind is initialized -// to 0 before the first call to sc_getopt. -// -// When all options have been processed (i.e., up to the first -// non-option argument), sc_getopt returns EOF, sc_optarg will point -// to the argument, and sc_optind will be set to the argv index of -// the argument. If there are no non-option arguments, sc_optarg -// will be set to NULL. -// -// The special option "--" may be used to delimit the end of the -// options; EOF will be returned, and "--" (and everything after it) -// will be skipped. -// -// RETURN VALUE -// For option letters contained in the string optstring, sc_getopt -// will return the option letter. sc_getopt returns a question mark (?) -// when it encounters an option letter not included in optstring. -// EOF is returned when processing is finished. -// -// BUGS -// 1) Long options are not supported. -// 2) The GNU double-colon extension is not supported. -// 3) The environment variable POSIXLY_CORRECT is not supported. -// 4) The + syntax is not supported. -// 5) The automatic permutation of arguments is not supported. -// 6) This implementation of sc_getopt() returns EOF if an error is -// encountered, instead of -1 as the latest standard requires. -// -// EXAMPLE -// BOOL CMyApp::ProcessCommandLine(int argc, char *argv[]) -// { -// int c; -// -// while ((c = sc_getopt(argc, argv, _T("aBn:"))) != EOF) -// { -// switch (c) -// { -// case _T('a'): -// TRACE(_T("option a\n")); -// // -// // set some flag here -// // -// break; -// -// case _T('B'): -// TRACE( _T("option B\n")); -// // -// // set some other flag here -// // -// break; -// -// case _T('n'): -// TRACE(_T("option n: value=%d\n"), atoi(sc_optarg)); -// // -// // do something with value here -// // -// break; -// -// case _T('?'): -// TRACE(_T("ERROR: illegal option %s\n"), argv[sc_optind-1]); -// return FALSE; -// break; -// -// default: -// TRACE(_T("WARNING: no handler for option %c\n"), c); -// return FALSE; -// break; -// } -// } -// // -// // check for non-option args here -// // -// return TRUE; -// } -// -/////////////////////////////////////////////////////////////////////////////// - -char * sc_optarg; // global argument pointer -int sc_optind = 0; // global argv index - -int sc_getopt( int argc, char * argv[], char * optstring ) { - static char * next = NULL; - if( sc_optind == 0 ) { - next = NULL; - } - - sc_optarg = NULL; - - if( next == NULL || *next == '\0' ) { - if( sc_optind == 0 ) { - sc_optind++; - } - - if( sc_optind >= argc || argv[sc_optind][0] != '-' || argv[sc_optind][1] == '\0' ) { - sc_optarg = NULL; - if( sc_optind < argc ) { - sc_optarg = argv[sc_optind]; - } - return EOF; - } - - if( strcmp( argv[sc_optind], "--" ) == 0 ) { - sc_optind++; - sc_optarg = NULL; - if( sc_optind < argc ) { - sc_optarg = argv[sc_optind]; - } - return EOF; - } - - next = argv[sc_optind]; - next++; // skip past - - sc_optind++; - } - - char c = *next++; - char * cp = strchr( optstring, c ); - - if( cp == NULL || c == ':' ) { - return '?'; - } - - cp++; - if( *cp == ':' ) { - if( *next != '\0' ) { - sc_optarg = next; - next = NULL; - } else if( sc_optind < argc ) { - sc_optarg = argv[sc_optind]; - sc_optind++; - } else { - return '?'; - } - } - - return c; -} diff --git a/src/base/sc_getopt.h b/src/base/sc_getopt.h deleted file mode 100644 index e1421a7bf..000000000 --- a/src/base/sc_getopt.h +++ /dev/null @@ -1,32 +0,0 @@ -/** \file sc_getopt.h - * this was xgetopt.h - * XGetopt.h Version 1.2 - * - * Author: Hans Dietrich - * hdietrich2@hotmail.com - * - * This software is released into the public domain. - * You are free to use it in any way you like. - * - * This software is provided "as is" with no expressed - * or implied warranty. I accept no liability for any - * damage or loss of business that this software may cause. - */ -#ifndef XGETOPT_H -#define XGETOPT_H -#include "sc_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - - extern SC_BASE_EXPORT int sc_optind, sc_opterr; - extern SC_BASE_EXPORT char * sc_optarg; - - int SC_BASE_EXPORT sc_getopt( int argc, char * argv[], char * optstring ); - -#ifdef __cplusplus -} -#endif - -#endif /* XGETOPT_H */ diff --git a/src/base/sc_memmgr.cc b/src/base/sc_memmgr.cc deleted file mode 100644 index 61d89a5ed..000000000 --- a/src/base/sc_memmgr.cc +++ /dev/null @@ -1,405 +0,0 @@ - -#define SC_MEMMGR_CC - -#include "config.h" -#include "sc_memmgr.h" - -#include -#include - -#include -#include - -#ifdef SC_MEMMGR_ENABLE_CHECKS - -/** - sc_memmgr_error definition -*/ -class sc_memmgr_error { - private: - std::string _srcfile; - unsigned int _srcline; - unsigned int _occurences; - public: - sc_memmgr_error( const std::string & file, const unsigned int line ); - sc_memmgr_error( const sc_memmgr_error & rhs ); - ~sc_memmgr_error( void ); - - bool operator<( const sc_memmgr_error & rhs ) const; - - std::string getsrcfile( void ) const; - unsigned int getsrcline( void ) const; - unsigned int getoccurences( void ) const; -}; - -typedef std::set sc_memmgr_errors; -typedef std::set::iterator sc_memmgr_error_iterator; - -/** - sc_memmgr_record definition -*/ -class sc_memmgr_record { - private: - void * _addr; - size_t _size; - std::string _srcfile; - unsigned int _srcline; - public: - sc_memmgr_record( void * addr, size_t size, const char * file, const unsigned int line ); - sc_memmgr_record( void * addr ); - sc_memmgr_record( const sc_memmgr_record & rhs ); - ~sc_memmgr_record( void ); - - bool operator<( const sc_memmgr_record & rhs ) const; - - void * getaddr( void ) const; - size_t getsize( void ) const; - std::string getsrcfile( void ) const; - unsigned int getsrcline( void ) const; -}; - -typedef std::set sc_memmgr_records; -typedef std::set::iterator sc_memmgr_record_iterator; - -#endif /* SC_MEMMGR_ENABLE_CHECKS */ - -/** - sc_memmgr definition -*/ -class sc_memmgr { - private: -#ifdef SC_MEMMGR_ENABLE_CHECKS - bool _record_insert_busy, _record_erase_busy; - // memory allocation/reallocation records, inserted at allocation, erased at deallocation. - sc_memmgr_records _records; - // memory stats - unsigned int _allocated; // amount of memory allocated simultaniously - unsigned int _maximum_allocated; // maximum amount of memory allocated simultaniously - unsigned int _allocated_total; // total amount of memory allocated in bytes - unsigned int _reallocated_total; // total amount of memory reallocated in bytes - unsigned int _deallocated_total; // total amount of memory deallocated in bytes -#endif /* SC_MEMMGR_ENABLE_CHECKS */ - protected: - public: - sc_memmgr( void ); - ~sc_memmgr( void ); - - void * allocate( size_t size, const char * file, const int line ); - void * reallocate( void * addr, size_t size, const char * file, const int line ); - void deallocate( void * addr, const char * file, const int line ); -}; - -/** - sc_memmgr instance. - There should be one static instance of memmgr. - This instance is automatically destroyed when application exits, so this allows us to add - memory leak detection in it's destructor. -*/ -sc_memmgr memmgr; - -/** - c memory functions implementation -*/ -extern "C" { - - void * sc_malloc_fn( unsigned int size, const char * file, const int line ) { - return memmgr.allocate( size, file, line ); - } - - void * sc_calloc_fn( unsigned int count, unsigned int size, const char * file, const int line ) { - return memmgr.allocate( count * size, file, line ); - } - - void * sc_realloc_fn( void * addr, unsigned int size, const char * file, const int line ) { - return memmgr.reallocate( addr, size, file, line ); - } - - void sc_free_fn( void * addr ) { - memmgr.deallocate( addr, "", 0 ); - } - -} - -/** - c++ memory operators implementation -*/ -void * sc_operator_new( size_t size, const char * file, const int line ) { - return memmgr.allocate( size, file, line ); -} - -void sc_operator_delete( void * addr, const char * file, const int line ) { - memmgr.deallocate( addr, file, line ); -} - -void sc_operator_delete( void * addr ) { - memmgr.deallocate( addr, "", 0 ); -} - -/** - sc_memmgr implementation -*/ -sc_memmgr::sc_memmgr( void ) { -#ifdef SC_MEMMGR_ENABLE_CHECKS - _record_insert_busy = false; - _record_erase_busy = false; - - _allocated = 0; - _maximum_allocated = 0; - _allocated_total = 0; - _reallocated_total = 0; - _deallocated_total = 0; -#endif /* SC_MEMMGR_ENABLE_CHECKS */ -} - -/** - Destructor: - sc_memmgr::~sc_memmgr(void) - Description: - The sc_memmgr destructor is used to check for memory leaks when enabled. - All records still present when sc_memmgr instance is destroyed can be considered as - memory leaks. -*/ -sc_memmgr::~sc_memmgr( void ) { -#ifdef SC_MEMMGR_ENABLE_CHECKS - sc_memmgr_record_iterator irecord; - sc_memmgr_errors errors; - sc_memmgr_error_iterator ierror; - - // Check if total allocated equals total deallocated - if( _allocated_total != _deallocated_total ) { - // todo: generate warning for possible memory leaks, enable full memory leak checking - fprintf( stderr, "sc_memmgr warning: Possible memory leaks detected (%d of %d bytes)\n", _allocated_total - _deallocated_total, _allocated_total ); - } - - // Compact leaks into an error list to prevent same leak being reported multiple times. - _record_insert_busy = true; - _record_erase_busy = true; - for( irecord = _records.begin(); - irecord != _records.end(); - irecord ++ ) { - sc_memmgr_error error( irecord->getsrcfile(), irecord->getsrcline() ); - ierror = errors.find( error ); - if( ierror == errors.end() ) { - errors.insert( error ); - } - //else - // ierror->occurences ++; - } - _record_insert_busy = false; - _record_erase_busy = false; - - // Loop through memory leaks to generate/buffer errors - for( ierror = errors.begin(); - ierror != errors.end(); - ierror ++ ) { - // todo: generate error for memory leak - fprintf( stderr, "sc_memmgr warning: Possible memory leak in %s line %d\n", ierror->getsrcfile().c_str(), ierror->getsrcline() ); - } - - // Clear remaining records - _record_erase_busy = true; - _records.clear(); - errors.clear(); - _record_erase_busy = false; -#endif /* SC_MEMMGR_ENABLE_CHECKS */ -} - -void * sc_memmgr::allocate( size_t size, const char * file, const int line ) { - void * addr; - - // Allocate - addr = malloc( size ); - if( addr == NULL ) { - // todo: error allocation failed - fprintf( stderr, "sc_memmgr error: Memory allocation failed in %s line %d\n", file, line ); - } - - // Some stl implementations (for example debian gcc) use the new operator to construct - // new elements when inserting sc_memmgr_record. When this our new operator gets used - // for this operation, this would result in an infinite loop. This is fixed by the - // _record_insert_busy flag. -#ifdef SC_MEMMGR_ENABLE_CHECKS - if( !_record_insert_busy ) { - // Store record for this allocation - _record_insert_busy = true; - _records.insert( sc_memmgr_record( addr, size, file, line ) ); - _record_insert_busy = false; - - // Update stats - _allocated += size; - if( _allocated > _maximum_allocated ) { - _maximum_allocated = _allocated; - } - _allocated_total += size; - } -#endif /* SC_MEMMGR_ENABLE_CHECKS */ - - return addr; -} - -void * sc_memmgr::reallocate( void * addr, size_t size, const char * file, const int line ) { -#ifdef SC_MEMMGR_ENABLE_CHECKS - sc_memmgr_record_iterator record; - - if( !_record_insert_busy ) { - // Find record of previous allocation/reallocation - record = _records.find( sc_memmgr_record( addr ) ); - if( record == _records.end() ) { - // todo: error reallocating memory not allocated? - fprintf( stderr, "sc_memmgr warning: Reallocation of not allocated memory at %s line %d\n", file, line ); - } else { - // Update stats - _allocated -= record->getsize(); - _deallocated_total += record->getsize(); - - // Erase previous allocation/reallocation - _record_erase_busy = true; - _records.erase( record ); - _record_erase_busy = false; - } - } -#endif /* SC_MEMMGR_ENABLE_CHECKS */ - - // Reallocate - addr = realloc( addr, size ); - if( addr == NULL ) { - // todo: error reallocation failed - fprintf( stderr, "sc_memmgr error: Reallocation failed at %s line %d\n", file, line ); - } - -#ifdef SC_MEMMGR_ENABLE_CHECKS - if( !_record_insert_busy ) { - // Store record for this reallocation - _record_insert_busy = true; - _records.insert( sc_memmgr_record( addr, size, file, line ) ); - _record_insert_busy = false; - - // Update stats - _allocated += size; - if( _allocated > _maximum_allocated ) { - _maximum_allocated = _allocated; - } - _allocated_total += size; - _reallocated_total += size; - } -#endif /* SC_MEMMGR_ENABLE_CHECKS */ - - return addr; -} - -void sc_memmgr::deallocate( void * addr, const char * file, const int line ) { -#ifdef SC_MEMMGR_ENABLE_CHECKS - sc_memmgr_record_iterator record; - - if( !_record_erase_busy ) { - // Find record of previous allocation/reallocation - record = _records.find( sc_memmgr_record( addr ) ); - if( record == _records.end() ) { - // todo: error free called for not allocated memory? - fprintf( stderr, "sc_memmgr warning: Deallocate of not allocated memory at %s line %d\n", file, line ); - } else { - // Update stats - _allocated -= record->getsize(); - _deallocated_total += record->getsize(); - - // Erase record - _record_erase_busy = true; - _records.erase( record ); - _record_erase_busy = false; - } - } -#else - (void) file; // quell unused param warnings - (void) line; -#endif /* SC_MEMMGR_ENABLE_CHECKS */ - - // Deallocate - free( addr ); -} - -#ifdef SC_MEMMGR_ENABLE_CHECKS -/** - sc_memmgr_error implementation -*/ -sc_memmgr_error::sc_memmgr_error( const std::string & file, const unsigned int line ) { - _srcfile = file; - _srcline = line; - _occurences = 1; -} - -sc_memmgr_error::sc_memmgr_error( const sc_memmgr_error & rhs ) { - _srcfile = rhs._srcfile; - _srcline = rhs._srcline; - _occurences = rhs._occurences; -} - -sc_memmgr_error::~sc_memmgr_error( void ) { -} - -bool sc_memmgr_error::operator<( const sc_memmgr_error & rhs ) const { - if( _srcfile == rhs._srcfile ) { - return _srcline < rhs._srcline; - } - return _srcfile < rhs._srcfile; -} - -std::string sc_memmgr_error::getsrcfile( void ) const { - return _srcfile; -} - -unsigned int sc_memmgr_error::getsrcline( void ) const { - return _srcline; -} - -unsigned int sc_memmgr_error::getoccurences( void ) const { - return _occurences; -} - -/** - sc_memmgr_record implementation -*/ -sc_memmgr_record::sc_memmgr_record( void * addr, size_t size, const char * file, const unsigned int line ) { - _addr = addr; - _size = size; - _srcfile = file; - _srcline = line; -} - -sc_memmgr_record::sc_memmgr_record( void * addr ) { - _addr = addr; - _size = 0; - _srcfile = ""; - _srcline = -1; -} - -sc_memmgr_record::sc_memmgr_record( const sc_memmgr_record & rhs ) { - _addr = rhs._addr; - _size = rhs._size; - _srcfile = rhs._srcfile; - _srcline = rhs._srcline; -} - -sc_memmgr_record::~sc_memmgr_record( void ) { -} - -bool sc_memmgr_record::operator<( const sc_memmgr_record & rhs ) const { - return _addr < rhs._addr; -} - -void * sc_memmgr_record::getaddr( void ) const { - return _addr; -} - -size_t sc_memmgr_record::getsize( void ) const { - return _size; -} - -std::string sc_memmgr_record::getsrcfile( void ) const { - return _srcfile; -} - -unsigned int sc_memmgr_record::getsrcline( void ) const { - return _srcline; -} - -#endif /* SC_MEMMGR_ENABLE_CHECKS */ diff --git a/src/base/sc_memmgr.h b/src/base/sc_memmgr.h deleted file mode 100644 index 9517a20bc..000000000 --- a/src/base/sc_memmgr.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef SC_MEMMGR_H -#define SC_MEMMGR_H - -#include -#include - -#if defined(SC_MEMMGR_ENABLE_CHECKS) - -#ifdef __cplusplus -#include -extern "C" { -#endif /* __cplusplus */ - - SC_BASE_EXPORT void * sc_malloc_fn( unsigned int size, const char * file, const int line ); - SC_BASE_EXPORT void * sc_calloc_fn( unsigned int count, unsigned int size, const char * file, const int line ); - SC_BASE_EXPORT void * sc_realloc_fn( void * addr, unsigned int size, const char * file, const int line ); - SC_BASE_EXPORT void sc_free_fn( void * addr ); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#ifdef __cplusplus - -SC_BASE_EXPORT void * sc_operator_new( size_t size, const char * file, const int line ); -SC_BASE_EXPORT void sc_operator_delete( void * addr, const char * file, const int line ); -SC_BASE_EXPORT void sc_operator_delete( void * addr ); - -#endif /* __cplusplus */ - -#ifndef SC_MEMMGR_CC - -#define sc_malloc(size) sc_malloc_fn(size, __FILE__, __LINE__) -#define sc_calloc(count, size) sc_calloc_fn(count, size, __FILE__, __LINE__) -#define sc_realloc(addr, size) sc_realloc_fn(addr, size, __FILE__, __LINE__) -#define sc_free(addr) sc_free_fn(addr) - -#ifdef __cplusplus - -#include - -inline void * operator new( size_t size, const char * file, const int line ) throw (std::bad_alloc) { - return sc_operator_new( size, file, line ); -} - -inline void * operator new[]( size_t size, const char * file, const int line ) throw (std::bad_alloc) { - return sc_operator_new( size, file, line ); -} - -inline void operator delete( void * addr, const char * file, const int line ) throw (std::bad_alloc) { - sc_operator_delete( addr, file, line ); -} - -inline void operator delete[]( void * addr, const char * file, const int line ) throw (std::bad_alloc) { - sc_operator_delete( addr, file, line ); -} - -inline void operator delete( void * addr ) throw () { - sc_operator_delete( addr ); -} - -inline void operator delete[]( void * addr ) throw () { - sc_operator_delete( addr ); -} - -#define new new(__FILE__, __LINE__) - -#endif /* __cplusplus */ - -#endif /* SC_MEMMGR_CC */ - -#else -#define sc_malloc(size) malloc(size) -#define sc_calloc(count, size) calloc(count, size) -#define sc_realloc(addr, size) realloc(addr, size) -#define sc_free(addr) free(addr) -#endif /* SC_MEMMGR_ENABLE_CHECKS */ - -#endif /* SC_MEMMGR_H */ diff --git a/src/base/sc_mkdir.c b/src/base/sc_mkdir.c deleted file mode 100644 index d0866f6e3..000000000 --- a/src/base/sc_mkdir.c +++ /dev/null @@ -1,32 +0,0 @@ -#define _XOPEN_SOURCE /* for S_IFDIR */ -#include "sc_mkdir.h" - -#include -#include -#include -#ifdef _WIN32 -# include -#endif /* _WIN32 */ - -/* cross-platform mkdir */ -int sc_mkdir( const char * path ) { - #ifdef _WIN32 - return mkdir( path ); - #else - return mkdir( path, 0777 ); - #endif /* _WIN32 */ -} - -/* return -1 if error, 0 if created, 1 if dir existed already */ -int mkDirIfNone( const char * path ) { - struct stat s; - if( stat( path, &s ) != 0 ) { - if( errno == ENOENT ) { - return sc_mkdir( path ); - } - } else if( s.st_mode & S_IFDIR ) { - return 1; - } - /* either stat returned an error other than ENOENT, or 'path' exists but isn't a dir */ - return -1; -} diff --git a/src/base/sc_mkdir.h b/src/base/sc_mkdir.h deleted file mode 100644 index 21c8d9c5c..000000000 --- a/src/base/sc_mkdir.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SC_MKDIR -#define SC_MKDIR - -#include - -/** cross-platform mkdir() */ -SC_BASE_EXPORT int sc_mkdir( const char * path ); - -/** create a dir 'path' if 'path' doesn't exist - * \return -1 if error, 0 if created, 1 if dir existed already - * if it returns -1, check errno - */ -SC_BASE_EXPORT int mkDirIfNone( const char * path ); - -#endif /* SC_MKDIR */ diff --git a/src/base/sc_stdio.h b/src/base/sc_stdio.h deleted file mode 100644 index 78fefc53b..000000000 --- a/src/base/sc_stdio.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __SC_STDIO_H -#define __SC_STDIO_H - -/* - * https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 - * (NOTE: MSVC defines va_list as a char*, so this should be safe) - */ -#if defined(_MSC_VER) && _MSC_VER < 1900 - -#include - -static __inline int -c99_vsnprintf(char *buffer, size_t sz, const char *format, va_list ap) { - int count = -1; - - if (sz != 0) - count = _vsnprintf_s(buffer, sz, _TRUNCATE, format, ap); - if (count == -1) - count = _vscprintf(format, ap); - - return count; -} - -static __inline int -c99_snprintf(char *buffer, size_t sz, const char *format, ...) { - int count; - va_list ap; - - va_start(ap, format); - count = c99_vsnprintf(buffer, sz, format, ap); - va_end(ap); - - return count; -} - -#endif - -#endif /* __SC_STDIO_H */ - diff --git a/src/base/sc_strtoull.h b/src/base/sc_strtoull.h deleted file mode 100644 index b68b76707..000000000 --- a/src/base/sc_strtoull.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef SC_STRTOULL_H -#define SC_STRTOULL_H - -#include - -#ifdef _WIN32 -# define strtoull _strtoui64 -# define ULLONG_MAX _UI64_MAX -#endif - -#endif /* SC_STRTOULL_H */ diff --git a/src/cldai/CMakeLists.txt b/src/cldai/CMakeLists.txt index 023ce1ab6..e37ac06d2 100644 --- a/src/cldai/CMakeLists.txt +++ b/src/cldai/CMakeLists.txt @@ -1,5 +1,4 @@ - -set(LIBSTEPDAI_SRCS +set(DAI_SRCS sdaiApplication_instance_set.cc sdaiBinary.cc sdaiDaObject.cc @@ -13,43 +12,24 @@ set(LIBSTEPDAI_SRCS sdaiString.cc ) -SET(SC_CLDAI_HDRS - sdaiApplication_instance_set.h - sdaiBinary.h - sdaiDaObject.h - sdaiEntity_extent.h - sdaiEntity_extent_set.h - sdaiEnum.h - sdaiModel_contents.h - sdaiModel_contents_list.h - sdaiObject.h - sdaiSession_instance.h - sdaiString.h - ) - include_directories( ${CMAKE_CURRENT_SOURCE_DIR} - ${SC_SOURCE_DIR}/src/base - ${SC_SOURCE_DIR}/src/clstepcore - ${SC_SOURCE_DIR}/src/clutils + ${CMAKE_SOURCE_DIR}/include/stepcode ) -set(_libdeps steputils base) +set(_libdeps steputils) if(BUILD_SHARED_LIBS) - SC_ADDLIB(stepdai SHARED SOURCES ${LIBSTEPDAI_SRCS} LINK_LIBRARIES ${_libdeps}) + SC_ADDLIB(stepdai SHARED SOURCES ${DAI_SRCS} LINK_LIBRARIES ${_libdeps}) if(WIN32) target_compile_definitions(stepdai PRIVATE SC_DAI_DLL_EXPORTS) endif() endif() if(BUILD_STATIC_LIBS) - SC_ADDLIB(stepdai-static STATIC SOURCES ${LIBSTEPDAI_SRCS} LINK_LIBRARIES $-static) + SC_ADDLIB(stepdai-static STATIC SOURCES ${DAI_SRCS} LINK_LIBRARIES $-static) endif() -install(FILES ${SC_CLDAI_HDRS} - DESTINATION ${INCLUDE_DIR}/stepcode/cldai) - # Local Variables: # tab-width: 8 # mode: cmake diff --git a/src/cldai/sdaiApplication_instance_set.cc b/src/cldai/sdaiApplication_instance_set.cc index 30a9103f4..f1733d40d 100644 --- a/src/cldai/sdaiApplication_instance_set.cc +++ b/src/cldai/sdaiApplication_instance_set.cc @@ -24,14 +24,13 @@ * UArray implementation. */ -//#include -#include +//#include "cldai/sdaiApplication_instance_set.h" +#include "clstepcore/sdai.h" #include #include -#include "sc_memmgr.h" -#include "sdaiApplication_instance.h" +#include "clstepcore/sdaiApplication_instance.h" // to help ObjectCenter #ifndef HAVE_MEMMOVE diff --git a/src/cldai/sdaiBinary.cc b/src/cldai/sdaiBinary.cc index 678add01c..d165d1ac0 100644 --- a/src/cldai/sdaiBinary.cc +++ b/src/cldai/sdaiBinary.cc @@ -10,8 +10,7 @@ */ #include -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" SDAI_Binary::SDAI_Binary( const char * str, int max ) { content = std::string( str, max ); @@ -122,17 +121,17 @@ Severity SDAI_Binary::ReadBinary( istream & in, ErrorDescriptor * err, int Assig if( !validDelimiters ) { err->GreaterSeverity( SEVERITY_WARNING ); if( needDelims ) - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), "Binary value missing double quote delimiters.\n" ); else - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), "Mismatched double quote delimiters for binary.\n" ); err->AppendToDetailMsg( messageBuf ); err->AppendToUserMsg( messageBuf ); } } else { err->GreaterSeverity( SEVERITY_WARNING ); - sprintf( messageBuf, "Invalid binary value.\n" ); + snprintf( messageBuf, sizeof(messageBuf), "Invalid binary value.\n" ); err->AppendToDetailMsg( messageBuf ); err->AppendToUserMsg( messageBuf ); } diff --git a/src/cldai/sdaiDaObject.cc b/src/cldai/sdaiDaObject.cc index 2f43ab284..52f06fc16 100644 --- a/src/cldai/sdaiDaObject.cc +++ b/src/cldai/sdaiDaObject.cc @@ -2,8 +2,7 @@ #include #include -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" // to help ObjectCenter #ifndef HAVE_MEMMOVE diff --git a/src/cldai/sdaiEntity_extent.cc b/src/cldai/sdaiEntity_extent.cc index 22db4e61b..7c27ea6e4 100644 --- a/src/cldai/sdaiEntity_extent.cc +++ b/src/cldai/sdaiEntity_extent.cc @@ -2,8 +2,7 @@ //#include -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" SDAI_Entity_extent::SDAI_Entity_extent( ) : _definition( 0 ), _definition_name( 0 ), _owned_by( 0 ) { diff --git a/src/cldai/sdaiEntity_extent_set.cc b/src/cldai/sdaiEntity_extent_set.cc index e472de06f..4080e336b 100644 --- a/src/cldai/sdaiEntity_extent_set.cc +++ b/src/cldai/sdaiEntity_extent_set.cc @@ -26,8 +26,7 @@ #include #include -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" /* #include diff --git a/src/cldai/sdaiEnum.cc b/src/cldai/sdaiEnum.cc index b0336ac2d..2291144ac 100644 --- a/src/cldai/sdaiEnum.cc +++ b/src/cldai/sdaiEnum.cc @@ -1,6 +1,5 @@ -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" /* * NIST STEP Core Class Library @@ -212,10 +211,10 @@ Severity SDAI_LOGICAL::ReadEnum( istream & in, ErrorDescriptor * err, int Assign if( !validDelimiters ) { err->GreaterSeverity( SEVERITY_WARNING ); if( needDelims ) - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), "Enumerated value has invalid period delimiters.\n" ); else - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), "Mismatched period delimiters for enumeration.\n" ); err->AppendToDetailMsg( messageBuf ); err->AppendToUserMsg( messageBuf ); @@ -242,7 +241,7 @@ Severity SDAI_LOGICAL::ReadEnum( istream & in, ErrorDescriptor * err, int Assign } else { in.putback( c ); err->GreaterSeverity( SEVERITY_WARNING ); - sprintf( messageBuf, "Invalid enumeration value.\n" ); + snprintf( messageBuf, sizeof(messageBuf), "Invalid enumeration value.\n" ); err->AppendToDetailMsg( messageBuf ); err->AppendToUserMsg( messageBuf ); } @@ -490,10 +489,10 @@ Severity SDAI_Enum::ReadEnum( istream & in, ErrorDescriptor * err, int AssignVal if( !validDelimiters ) { err->GreaterSeverity( SEVERITY_WARNING ); if( needDelims ) - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), "Enumerated value has invalid period delimiters.\n" ); else - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), "Mismatched period delimiters for enumeration.\n" ); err->AppendToDetailMsg( messageBuf ); err->AppendToUserMsg( messageBuf ); @@ -520,7 +519,7 @@ Severity SDAI_Enum::ReadEnum( istream & in, ErrorDescriptor * err, int AssignVal } else { in.putback( c ); err->GreaterSeverity( SEVERITY_WARNING ); - sprintf( messageBuf, "Invalid enumeration value.\n" ); + snprintf( messageBuf, sizeof(messageBuf), "Invalid enumeration value.\n" ); err->AppendToDetailMsg( messageBuf ); err->AppendToUserMsg( messageBuf ); } diff --git a/src/cldai/sdaiModel_contents.cc b/src/cldai/sdaiModel_contents.cc index abe0386b2..3cb0828a0 100644 --- a/src/cldai/sdaiModel_contents.cc +++ b/src/cldai/sdaiModel_contents.cc @@ -1,6 +1,5 @@ -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" ///////// SDAI_Model_contents_instances diff --git a/src/cldai/sdaiModel_contents_list.cc b/src/cldai/sdaiModel_contents_list.cc index 8f6440e8e..62197b190 100644 --- a/src/cldai/sdaiModel_contents_list.cc +++ b/src/cldai/sdaiModel_contents_list.cc @@ -23,8 +23,7 @@ /* * UArray implementation. */ -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" // to help ObjectCenter #ifndef HAVE_MEMMOVE diff --git a/src/cldai/sdaiObject.cc b/src/cldai/sdaiObject.cc index 14cf6c26a..fd930881c 100644 --- a/src/cldai/sdaiObject.cc +++ b/src/cldai/sdaiObject.cc @@ -1,5 +1,4 @@ -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" SDAI_sdaiObject::SDAI_sdaiObject() { } diff --git a/src/cldai/sdaiSession_instance.cc b/src/cldai/sdaiSession_instance.cc index 6f48be442..291c0c21b 100644 --- a/src/cldai/sdaiSession_instance.cc +++ b/src/cldai/sdaiSession_instance.cc @@ -1,5 +1,4 @@ -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" SDAI_Session_instance::SDAI_Session_instance() { } diff --git a/src/cldai/sdaiString.cc b/src/cldai/sdaiString.cc index 87f29eebd..06f94d9e6 100644 --- a/src/cldai/sdaiString.cc +++ b/src/cldai/sdaiString.cc @@ -9,9 +9,8 @@ * and is not subject to copyright. */ -#include +#include "clstepcore/sdai.h" #include -#include "sc_memmgr.h" SDAI_String::SDAI_String( const char * str, size_t max ) { if( !str ) { diff --git a/src/cleditor/CMakeLists.txt b/src/cleditor/CMakeLists.txt index 6370bcacb..2b306068e 100644 --- a/src/cleditor/CMakeLists.txt +++ b/src/cleditor/CMakeLists.txt @@ -1,5 +1,4 @@ - -set(LIBSTEPEDITOR_SRCS +set(EDITOR_SRCS STEPfile.cc STEPfile.inline.cc cmdmgr.cc @@ -9,38 +8,22 @@ set(LIBSTEPEDITOR_SRCS SdaiSchemaInit.cc ) -SET(SC_CLEDITOR_HDRS - STEPfile.h - cmdmgr.h - editordefines.h - SdaiHeaderSchema.h - SdaiHeaderSchemaClasses.h - SdaiSchemaInit.h - seeinfodefault.h - ) - include_directories( ${CMAKE_CURRENT_SOURCE_DIR} - ${SC_SOURCE_DIR}/src/base - ${SC_SOURCE_DIR}/src/cldai - ${SC_SOURCE_DIR}/src/clstepcore - ${SC_SOURCE_DIR}/src/clutils + ${CMAKE_SOURCE_DIR}/include/stepcode ) if(BUILD_SHARED_LIBS) - SC_ADDLIB(stepeditor SHARED SOURCES ${LIBSTEPEDITOR_SRCS} LINK_LIBRARIES stepcore stepdai steputils base) + SC_ADDLIB(stepeditor SHARED SOURCES ${EDITOR_SRCS} LINK_LIBRARIES stepcore stepdai steputils) if(WIN32) target_compile_definitions(stepeditor PRIVATE SC_EDITOR_DLL_EXPORTS) endif() endif() if(BUILD_STATIC_LIBS) - SC_ADDLIB(stepeditor-static STATIC SOURCES ${LIBSTEPEDITOR_SRCS} LINK_LIBRARIES stepcore-static stepdai-static steputils-static base-static) + SC_ADDLIB(stepeditor-static STATIC SOURCES ${EDITOR_SRCS} LINK_LIBRARIES stepcore-static stepdai-static steputils-static) endif() -install(FILES ${SC_CLEDITOR_HDRS} - DESTINATION ${INCLUDE_DIR}/stepcode/cleditor) - # Local Variables: # tab-width: 8 # mode: cmake diff --git a/src/cleditor/STEPfile.cc b/src/cleditor/STEPfile.cc index b8936d761..7254e8935 100644 --- a/src/cleditor/STEPfile.cc +++ b/src/cleditor/STEPfile.cc @@ -24,17 +24,15 @@ #include #include -#include -#include -#include -#include -#include +#include "cleditor/STEPfile.h" +#include "clstepcore/sdai.h" +#include "clstepcore/STEPcomplex.h" +#include "clstepcore/STEPattribute.h" +#include "cleditor/SdaiHeaderSchema.h" // STEPundefined contains // void PushPastString (istream& in, std::string &s, ErrorDescriptor *err) -#include - -#include "sc_memmgr.h" +#include "clstepcore/STEPundefined.h" /** * \returns The new file name for the class. @@ -530,7 +528,7 @@ int STEPfile::ReadData1( istream & in ) { } // end while loop if( _entsNotCreated ) { - sprintf( buf, + snprintf( buf, sizeof(buf), "STEPfile Reading File: Unable to create %d instances.\n\tIn first pass through DATA section. Check for invalid entity types.\n", _entsNotCreated ); _error.AppendToUserMsg( buf ); @@ -649,7 +647,7 @@ int STEPfile::ReadData2( istream & in, bool useTechCor ) { } // end while loop if( _entsInvalid ) { - sprintf( buf, + snprintf( buf, sizeof(buf), "%s \n\tTotal instances: %d \n\tInvalid instances: %d \n\tIncomplete instances (includes invalid instances): %d \n\t%s: %d.\n", "Second pass complete - instance summary:", total_instances, _entsInvalid, _entsIncomplete, "Warnings", @@ -1323,7 +1321,7 @@ SDAI_Application_instance * STEPfile::ReadInstance( istream & in, ostream & out, } } else { if( node->CurrState() == completeSE ) { - sprintf( errbuf, "WARNING in WORKING FILE: changing instance #%d state from completeSE to incompleteSE.\n", fileid ); + snprintf( errbuf, sizeof(errbuf), "WARNING in WORKING FILE: changing instance #%d state from completeSE to incompleteSE.\n", fileid ); _error.AppendToUserMsg( errbuf ); if( _fileType != WORKING_SESSION ) { node->ChangeState( incompleteSE ); @@ -1645,7 +1643,7 @@ Severity STEPfile::AppendFile( istream * in, bool useTechCor ) { } SetFileType( WORKING_SESSION ); } else { - sprintf( errbuf, + snprintf( errbuf, sizeof(errbuf), "Faulty input at beginning of file. \"ISO-10303-21;\" or" " \"STEP_WORKING_SESSION;\" expected. File not read: %s\n", ( ( FileName().compare( "-" ) == 0 ) ? "standard input" : FileName().c_str() ) ); @@ -1660,14 +1658,14 @@ Severity STEPfile::AppendFile( istream * in, bool useTechCor ) { rval = ReadHeader( *in ); cout << "\nHEADER read:"; if( rval < SEVERITY_WARNING ) { - sprintf( errbuf, + snprintf( errbuf, sizeof(errbuf), "Error: non-recoverable error in reading header section. " "There were %d errors encountered. Rest of file is ignored.\n", _errorCount ); _error.AppendToUserMsg( errbuf ); return rval; } else if( rval != SEVERITY_NULL ) { - sprintf( errbuf, " %d ERRORS\t %d WARNINGS\n\n", + snprintf( errbuf, sizeof(errbuf), " %d ERRORS\t %d WARNINGS\n\n", _errorCount, _warningCount ); cout << errbuf; } else { @@ -1685,7 +1683,7 @@ Severity STEPfile::AppendFile( istream * in, bool useTechCor ) { cout << "\nFIRST PASS complete: " << total_insts << " instances created.\n"; - sprintf( errbuf, + snprintf( errbuf, sizeof(errbuf), " %d ERRORS\t %d WARNINGS\n\n", _errorCount, _warningCount ); cout << errbuf; @@ -1729,7 +1727,7 @@ Severity STEPfile::AppendFile( istream * in, bool useTechCor ) { //check for "ENDSEC;" ReadTokenSeparator( *in2 ); if( total_insts != valid_insts ) { - sprintf( errbuf, "%d invalid instances in file: %s\n", + snprintf( errbuf, sizeof(errbuf), "%d invalid instances in file: %s\n", total_insts - valid_insts, ( ( FileName().compare( "-" ) == 0 ) ? "standard input" : FileName().c_str() ) ); _error.AppendToUserMsg( errbuf ); CloseInputFile( in2 ); @@ -1738,7 +1736,7 @@ Severity STEPfile::AppendFile( istream * in, bool useTechCor ) { cout << "\nSECOND PASS complete: " << valid_insts << " instances valid.\n"; - sprintf( errbuf, + snprintf( errbuf, sizeof(errbuf), " %d ERRORS\t %d WARNINGS\n\n", _errorCount, _warningCount ); _error.AppendToUserMsg( errbuf ); diff --git a/src/cleditor/STEPfile.inline.cc b/src/cleditor/STEPfile.inline.cc index f67bc3978..a34149048 100644 --- a/src/cleditor/STEPfile.inline.cc +++ b/src/cleditor/STEPfile.inline.cc @@ -11,13 +11,12 @@ * and is not subject to copyright. */ -#include -#include -#include +#include "cleditor/STEPfile.h" +#include "cleditor/SdaiHeaderSchema.h" +#include "clstepcore/STEPaggregate.h" #include #include -#include "sc_memmgr.h" extern void HeaderSchemaInit( Registry & reg ); @@ -180,7 +179,7 @@ istream * STEPfile::OpenInputFile( const std::string filename ) { } else { if( SetFileName( filename ).empty() && ( filename.compare( "-" ) != 0 ) ) { char msg[BUFSIZ+1]; - sprintf( msg, "Unable to find file for input: \'%s\'. File not read.\n", filename.c_str() ); + snprintf( msg, sizeof(msg), "Unable to find file for input: \'%s\'. File not read.\n", filename.c_str() ); _error.AppendToUserMsg( msg ); _error.GreaterSeverity( SEVERITY_INPUT_ERROR ); return( 0 ); @@ -197,7 +196,7 @@ istream * STEPfile::OpenInputFile( const std::string filename ) { if( !in || !( in -> good() ) ) { char msg[BUFSIZ+1]; - sprintf( msg, "Unable to open file for input: \'%s\'. File not read.\n", filename.c_str() ); + snprintf( msg, sizeof(msg), "Unable to open file for input: \'%s\'. File not read.\n", filename.c_str() ); _error.AppendToUserMsg( msg ); _error.GreaterSeverity( SEVERITY_INPUT_ERROR ); return ( 0 ); @@ -232,7 +231,7 @@ ofstream * STEPfile::OpenOutputFile( std::string filename ) { } else { if( SetFileName( filename ).empty() ) { char msg[BUFSIZ+1]; - sprintf( msg, "can't find file: %s\nFile not written.\n", filename.c_str() ); + snprintf( msg, sizeof(msg), "can't find file: %s\nFile not written.\n", filename.c_str() ); _error.AppendToUserMsg( msg ); _error.GreaterSeverity( SEVERITY_INPUT_ERROR ); } diff --git a/src/cleditor/SdaiHeaderSchema.cc b/src/cleditor/SdaiHeaderSchema.cc index cea95b42f..73212bc48 100644 --- a/src/cleditor/SdaiHeaderSchema.cc +++ b/src/cleditor/SdaiHeaderSchema.cc @@ -10,10 +10,9 @@ extern ofstream * logStream; #define SCLLOGFILE "scl.log" #endif -#include -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/STEPattribute.h" +#include "cleditor/SdaiHeaderSchema.h" Schema * s_header_section_schema = 0; diff --git a/src/cleditor/SdaiHeaderSchemaAll.cc b/src/cleditor/SdaiHeaderSchemaAll.cc index 3a469c7d3..cf88eb3aa 100644 --- a/src/cleditor/SdaiHeaderSchemaAll.cc +++ b/src/cleditor/SdaiHeaderSchemaAll.cc @@ -4,8 +4,7 @@ // it since your modifications will be lost if exp2cxx is used to // regenerate it. -#include -#include "sc_memmgr.h" +#include "cleditor/SdaiHeaderSchema.h" void HeaderInitSchemasAndEnts( Registry & reg ) { Uniqueness_rule_ptr ur; diff --git a/src/cleditor/SdaiHeaderSchemaInit.cc b/src/cleditor/SdaiHeaderSchemaInit.cc index 35099d805..32b1655d1 100644 --- a/src/cleditor/SdaiHeaderSchemaInit.cc +++ b/src/cleditor/SdaiHeaderSchemaInit.cc @@ -4,11 +4,10 @@ // it since your modifications will be lost if exp2cxx is used to // regenerate it. -#include -#include -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/Registry.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/STEPattribute.h" +#include "cleditor/SdaiHeaderSchema.h" void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) { header_section_schemat_time_stamp_text->ReferentType( t_sdaiSTRING ); diff --git a/src/cleditor/SdaiSchemaInit.cc b/src/cleditor/SdaiSchemaInit.cc index 05790a09c..82323987a 100644 --- a/src/cleditor/SdaiSchemaInit.cc +++ b/src/cleditor/SdaiSchemaInit.cc @@ -4,8 +4,7 @@ // it since your modifications will be lost if exp2cxx is used to // regenerate it. -#include -#include "sc_memmgr.h" +#include "cleditor/SdaiSchemaInit.h" void HeaderSchemaInit( Registry & reg ) { HeaderInitSchemasAndEnts( reg ); diff --git a/src/cleditor/cmdmgr.cc b/src/cleditor/cmdmgr.cc index 3044790de..4b78d4f90 100644 --- a/src/cleditor/cmdmgr.cc +++ b/src/cleditor/cmdmgr.cc @@ -10,8 +10,7 @@ * and is not subject to copyright. */ -#include -#include "sc_memmgr.h" +#include "cleditor/cmdmgr.h" ReplicateLinkNode * ReplicateList::FindNode( MgrNode * mn ) { ReplicateLinkNode * rln = ( ReplicateLinkNode * )GetHead(); diff --git a/src/cllazyfile/CMakeLists.txt b/src/cllazyfile/CMakeLists.txt index b5e763628..c56e8dbbc 100644 --- a/src/cllazyfile/CMakeLists.txt +++ b/src/cllazyfile/CMakeLists.txt @@ -1,55 +1,35 @@ - -set( clLazyFile_SRCS +set(LAZY_SRCS lazyDataSectionReader.cc lazyFileReader.cc lazyInstMgr.cc p21HeaderSectionReader.cc sectionReader.cc lazyP21DataSectionReader.cc - ) - -set( SC_CLLAZYFILE_HDRS - headerSectionReader.h - lazyFileReader.h - lazyP21DataSectionReader.h - p21HeaderSectionReader.h - lazyDataSectionReader.h - lazyInstMgr.h - lazyTypes.h - sectionReader.h - instMgrHelper.h + judy.c ) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} - ${SC_SOURCE_DIR}/src/cleditor - ${SC_SOURCE_DIR}/src/cldai - ${SC_SOURCE_DIR}/src/clstepcore - ${SC_SOURCE_DIR}/src/clutils - ${SC_SOURCE_DIR}/src/base - ${SC_SOURCE_DIR}/src/base/judy/src + ${CMAKE_SOURCE_DIR}/include/stepcode ) -set(_libdeps stepcore stepdai steputils base stepeditor) +set(_libdeps stepcore stepdai steputils stepeditor) if(BUILD_SHARED_LIBS) - SC_ADDLIB(steplazyfile SHARED SOURCES ${clLazyFile_SRCS} LINK_LIBRARIES ${_libdeps}) + SC_ADDLIB(steplazyfile SHARED SOURCES ${LAZY_SRCS} LINK_LIBRARIES ${_libdeps}) if(WIN32) target_compile_definitions(steplazyfile PRIVATE SC_LAZYFILE_DLL_EXPORTS) endif() endif() if(BUILD_STATIC_LIBS) - set(_libdeps stepcore-static stepdai-static steputils-static base-static stepeditor-static) - SC_ADDLIB(steplazyfile-static STATIC SOURCES ${clLazyFile_SRCS} LINK_LIBRARIES ${_libdeps}) + set(_libdeps stepcore-static stepdai-static steputils-static stepeditor-static) + SC_ADDLIB(steplazyfile-static STATIC SOURCES ${LAZY_SRCS} LINK_LIBRARIES ${_libdeps}) endif() -SC_ADDEXEC(lazy_test SOURCES lazy_test.cc LINK_LIBRARIES steplazyfile stepeditor NO_INSTALL) +SC_ADDEXEC(lazy_test SOURCES "lazy_test.cc;sc_benchmark.cc" LINK_LIBRARIES steplazyfile stepeditor NO_INSTALL) target_compile_definitions(lazy_test PRIVATE NO_REGISTRY) -install(FILES ${SC_CLLAZYFILE_HDRS} - DESTINATION ${INCLUDE_DIR}/stepcode/cllazyfile) - # Local Variables: # tab-width: 8 # mode: cmake diff --git a/src/base/judy/src/judy.c b/src/cllazyfile/judy.c similarity index 99% rename from src/base/judy/src/judy.c rename to src/cllazyfile/judy.c index 91380cead..f3bba2b7e 100644 --- a/src/base/judy/src/judy.c +++ b/src/cllazyfile/judy.c @@ -60,7 +60,7 @@ # endif #endif -#include "judy.h" +#include "cllazyfile/judy.h" #include #include diff --git a/src/cllazyfile/lazyDataSectionReader.cc b/src/cllazyfile/lazyDataSectionReader.cc index 4b1bc1785..6de006fe4 100644 --- a/src/cllazyfile/lazyDataSectionReader.cc +++ b/src/cllazyfile/lazyDataSectionReader.cc @@ -1,6 +1,6 @@ -#include "lazyDataSectionReader.h" -#include "lazyFileReader.h" -#include "lazyInstMgr.h" +#include "cllazyfile/lazyDataSectionReader.h" +#include "cllazyfile/lazyFileReader.h" +#include "cllazyfile/lazyInstMgr.h" #include lazyDataSectionReader::lazyDataSectionReader( lazyFileReader * parent, std::ifstream & file, diff --git a/src/cllazyfile/lazyFileReader.cc b/src/cllazyfile/lazyFileReader.cc index 9cc294df0..fed35c6f5 100644 --- a/src/cllazyfile/lazyFileReader.cc +++ b/src/cllazyfile/lazyFileReader.cc @@ -1,10 +1,10 @@ #include -#include "lazyFileReader.h" -#include "lazyDataSectionReader.h" -#include "headerSectionReader.h" -#include "lazyInstMgr.h" +#include "cllazyfile/lazyFileReader.h" +#include "cllazyfile/lazyDataSectionReader.h" +#include "cllazyfile/headerSectionReader.h" +#include "cllazyfile/lazyInstMgr.h" void lazyFileReader::initP21() { _header = new p21HeaderSectionReader( this, _file, 0, -1 ); diff --git a/src/cllazyfile/lazyInstMgr.cc b/src/cllazyfile/lazyInstMgr.cc index 7ce253ee9..65f3e7558 100644 --- a/src/cllazyfile/lazyInstMgr.cc +++ b/src/cllazyfile/lazyInstMgr.cc @@ -1,12 +1,12 @@ -#include "lazyTypes.h" -#include "lazyInstMgr.h" -#include "Registry.h" -#include -#include "SdaiSchemaInit.h" -#include "instMgrHelper.h" +#include "cllazyfile/lazyTypes.h" +#include "cllazyfile/lazyInstMgr.h" +#include "clstepcore/Registry.h" +#include "clstepcore/SubSuperIterators.h" +#include "cleditor/SdaiSchemaInit.h" +#include "cllazyfile/instMgrHelper.h" #include "lazyRefs.h" -#include "sdaiApplication_instance.h" +#include "clstepcore/sdaiApplication_instance.h" lazyInstMgr::lazyInstMgr() { _headerRegistry = new Registry( HeaderSchemaInit ); diff --git a/src/cllazyfile/lazyP21DataSectionReader.cc b/src/cllazyfile/lazyP21DataSectionReader.cc index baecb260e..0716f5c5f 100644 --- a/src/cllazyfile/lazyP21DataSectionReader.cc +++ b/src/cllazyfile/lazyP21DataSectionReader.cc @@ -1,7 +1,7 @@ #include #include -#include "lazyP21DataSectionReader.h" -#include "lazyInstMgr.h" +#include "cllazyfile/lazyP21DataSectionReader.h" +#include "cllazyfile/lazyInstMgr.h" lazyP21DataSectionReader::lazyP21DataSectionReader( lazyFileReader * parent, std::ifstream & file, std::streampos start, sectionID sid ): diff --git a/src/cllazyfile/lazyRefs.h b/src/cllazyfile/lazyRefs.h index 723dd0998..b8daff295 100644 --- a/src/cllazyfile/lazyRefs.h +++ b/src/cllazyfile/lazyRefs.h @@ -7,12 +7,12 @@ #include #include "sc_export.h" -#include "lazyTypes.h" -#include "lazyInstMgr.h" -#include "ExpDict.h" -#include "SubSuperIterators.h" -#include -#include +#include "cllazyfile/lazyTypes.h" +#include "cllazyfile/lazyInstMgr.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/SubSuperIterators.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/STEPaggregate.h" #ifdef _WIN32 #define strcasecmp _strcmpi diff --git a/src/cllazyfile/lazy_test.cc b/src/cllazyfile/lazy_test.cc index c41003e9b..d5ce6081a 100644 --- a/src/cllazyfile/lazy_test.cc +++ b/src/cllazyfile/lazy_test.cc @@ -1,7 +1,6 @@ -#include "lazyInstMgr.h" -#include -#include "SdaiSchemaInit.h" -#include "sc_memmgr.h" +#include "cllazyfile/lazyInstMgr.h" +#include "./sc_benchmark.h" +#include "cleditor/SdaiSchemaInit.h" #include "config.h" #ifndef NO_REGISTRY diff --git a/src/cllazyfile/p21HeaderSectionReader.cc b/src/cllazyfile/p21HeaderSectionReader.cc index a01e47c3d..037604fc4 100644 --- a/src/cllazyfile/p21HeaderSectionReader.cc +++ b/src/cllazyfile/p21HeaderSectionReader.cc @@ -1,11 +1,11 @@ #include #include -#include "p21HeaderSectionReader.h" -#include "headerSectionReader.h" -#include "sectionReader.h" -#include "lazyInstMgr.h" -#include "judyL2Array.h" +#include "cllazyfile/p21HeaderSectionReader.h" +#include "cllazyfile/headerSectionReader.h" +#include "cllazyfile/sectionReader.h" +#include "cllazyfile/lazyInstMgr.h" +#include "cllazyfile/judyL2Array.h" void p21HeaderSectionReader::findSectionStart() { diff --git a/src/base/sc_benchmark.cc b/src/cllazyfile/sc_benchmark.cc similarity index 99% rename from src/base/sc_benchmark.cc rename to src/cllazyfile/sc_benchmark.cc index 44f085f2f..2f00cd5a4 100644 --- a/src/base/sc_benchmark.cc +++ b/src/cllazyfile/sc_benchmark.cc @@ -1,7 +1,6 @@ /// \file sc_benchmark.cc memory info, timers, etc for benchmarking -#include "sc_benchmark.h" -#include "sc_memmgr.h" +#include "./sc_benchmark.h" #ifdef _WIN32 #include diff --git a/src/base/sc_benchmark.h b/src/cllazyfile/sc_benchmark.h similarity index 93% rename from src/base/sc_benchmark.h rename to src/cllazyfile/sc_benchmark.h index 8512bd892..5b77317c4 100644 --- a/src/base/sc_benchmark.h +++ b/src/cllazyfile/sc_benchmark.h @@ -2,14 +2,11 @@ #define SC_BENCHMARK_H /// \file sc_benchmark.h memory info, timers, etc for benchmarking -#include "sc_export.h" - #ifdef __cplusplus #include #include #include -#include "sc_memmgr.h" extern "C" { #endif @@ -23,7 +20,7 @@ extern "C" { * * not yet implemented for OSX or Windows. */ - SC_BASE_EXPORT benchVals getMemAndTime( ); + benchVals getMemAndTime( ); #ifdef __cplusplus } @@ -39,7 +36,7 @@ extern "C" { * depends on getMemAndTime() above - may not work on all platforms. */ -class SC_BASE_EXPORT benchmark { +class benchmark { protected: benchVals initialVals, laterVals; #ifdef _MSC_VER diff --git a/src/cllazyfile/sectionReader.cc b/src/cllazyfile/sectionReader.cc index fe3bd4b2a..bfa8a2a12 100644 --- a/src/cllazyfile/sectionReader.cc +++ b/src/cllazyfile/sectionReader.cc @@ -5,18 +5,23 @@ #include #include #include +#include -#include "Registry.h" -#include "sc_strtoull.h" -#include "sdaiApplication_instance.h" -#include "read_func.h" -#include "SdaiSchemaInit.h" -#include "STEPcomplex.h" +#ifdef _WIN32 +# define strtoull _strtoui64 +# define ULLONG_MAX _UI64_MAX +#endif -#include "sectionReader.h" -#include "lazyFileReader.h" -#include "lazyInstMgr.h" -#include "lazyTypes.h" +#include "clstepcore/Registry.h" +#include "clstepcore/sdaiApplication_instance.h" +#include "clstepcore/read_func.h" +#include "cleditor/SdaiSchemaInit.h" +#include "clstepcore/STEPcomplex.h" + +#include "cllazyfile/sectionReader.h" +#include "cllazyfile/lazyFileReader.h" +#include "cllazyfile/lazyInstMgr.h" +#include "cllazyfile/lazyTypes.h" #include "current_function.hpp" diff --git a/src/clstepcore/CMakeLists.txt b/src/clstepcore/CMakeLists.txt index 910235973..e31f8ad8e 100644 --- a/src/clstepcore/CMakeLists.txt +++ b/src/clstepcore/CMakeLists.txt @@ -1,5 +1,4 @@ - -set(LIBSTEPCORE_SRCS +set(CORE_SRCS aggrTypeDescriptor.cc attrDescriptor.cc attrDescriptorList.cc @@ -62,91 +61,24 @@ set(LIBSTEPCORE_SRCS whereRule.cc ) -set(SC_CLSTEPCORE_HDRS - aggrTypeDescriptor.h - attrDescriptor.h - attrDescriptorList.h - baseType.h - complexSupport.h - create_Aggr.h - derivedAttribute.h - dictSchema.h - dictdefs.h - dictionaryInstance.h - dispnode.h - dispnodelist.h - entityDescriptor.h - entityDescriptorList.h - enumTypeDescriptor.h - ExpDict.h - explicitItemId.h - globalRule.h - implicitItemId.h - instmgr.h - interfaceSpec.h - interfacedItem.h - inverseAttribute.h - inverseAttributeList.h - mgrnode.h - mgrnodearray.h - mgrnodelist.h - needFunc.h - read_func.h - realTypeDescriptor.h - Registry.h - schRename.h - sdai.h - sdaiApplication_instance.h - sdaiSelect.h - selectTypeDescriptor.h - SingleLinkList.h - STEPaggregate.h - STEPaggrBinary.h - STEPaggrEntity.h - STEPaggrEnum.h - STEPaggrGeneric.h - STEPaggrInt.h - STEPaggrReal.h - STEPaggrSelect.h - STEPaggrString.h - STEPattribute.h - STEPattributeList.h - STEPcomplex.h - STEPinvAttrList.h - STEPundefined.h - stringTypeDescriptor.h - SubSuperIterators.h - typeDescriptor.h - typeDescriptorList.h - typeOrRuleVar.h - uniquenessRule.h - whereRule.h -) - include_directories( ${CMAKE_CURRENT_SOURCE_DIR} - ${SC_SOURCE_DIR}/src/base - ${SC_SOURCE_DIR}/src/cldai - ${SC_SOURCE_DIR}/src/cleditor - ${SC_SOURCE_DIR}/src/clutils + ${CMAKE_SOURCE_DIR}/include/stepcode ) -set(_libdeps steputils stepdai base) +set(_libdeps steputils stepdai) if(BUILD_SHARED_LIBS) - SC_ADDLIB(stepcore SHARED SOURCES ${LIBSTEPCORE_SRCS} LINK_LIBRARIES ${_libdeps}) + SC_ADDLIB(stepcore SHARED SOURCES ${CORE_SRCS} LINK_LIBRARIES ${_libdeps}) if(WIN32) target_compile_definitions(stepcore PRIVATE SC_CORE_DLL_EXPORTS) endif() endif() if(BUILD_STATIC_LIBS) - SC_ADDLIB(stepcore-static STATIC SOURCES ${LIBSTEPCORE_SRCS} LINK_LIBRARIES $-static) + SC_ADDLIB(stepcore-static STATIC SOURCES ${CORE_SRCS} LINK_LIBRARIES $-static) endif() -install(FILES ${SC_CLSTEPCORE_HDRS} - DESTINATION ${INCLUDE_DIR}/stepcode/clstepcore) - if(SC_ENABLE_TESTING) add_subdirectory(test) endif(SC_ENABLE_TESTING) diff --git a/src/clstepcore/Registry.cc b/src/clstepcore/Registry.cc index b9b9f6103..9eeb975e0 100644 --- a/src/clstepcore/Registry.cc +++ b/src/clstepcore/Registry.cc @@ -9,9 +9,8 @@ * and is not subject to copyright. */ -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/Registry.h" /* these may be shared between multiple Registry instances, so don't create/destroy in Registry ctor/dtor * Name, FundamentalType, Originating Schema, Description */ diff --git a/src/clstepcore/STEPaggrBinary.cc b/src/clstepcore/STEPaggrBinary.cc index fd7302748..f1170926c 100644 --- a/src/clstepcore/STEPaggrBinary.cc +++ b/src/clstepcore/STEPaggrBinary.cc @@ -1,4 +1,4 @@ -#include "STEPaggrBinary.h" +#include "clstepcore/STEPaggrBinary.h" #include /** \file STEPaggrBinary.cc diff --git a/src/clstepcore/STEPaggrEntity.cc b/src/clstepcore/STEPaggrEntity.cc index c0fddfbbb..a29150873 100644 --- a/src/clstepcore/STEPaggrEntity.cc +++ b/src/clstepcore/STEPaggrEntity.cc @@ -1,6 +1,6 @@ -#include "STEPaggrEntity.h" -#include "STEPattribute.h" -#include "typeDescriptor.h" +#include "clstepcore/STEPaggrEntity.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/typeDescriptor.h" #include /** \file STEPaggrEntity.cc @@ -91,7 +91,7 @@ Severity EntityAggregate::ReadValue( istream & in, ErrorDescriptor * err, CheckRemainingInput( in, &errdesc, buf, ",)" ); if( errdesc.severity() < SEVERITY_INCOMPLETE ) { - sprintf( errmsg, " index: %d\n", value_cnt ); + snprintf( errmsg, sizeof(errmsg), " index: %d\n", value_cnt ); errdesc.PrependToDetailMsg( errmsg ); err->AppendFromErrorArg( &errdesc ); } @@ -221,7 +221,7 @@ const char * EntityNode::asStr( std::string & s ) { return ""; } else { // otherwise return entity id char tmp [64]; - sprintf( tmp, "#%d", node->STEPfile_id ); + snprintf( tmp, sizeof(tmp), "#%d", node->STEPfile_id ); s = tmp; } return const_cast( s.c_str() ); diff --git a/src/clstepcore/STEPaggrEnum.cc b/src/clstepcore/STEPaggrEnum.cc index 41b77aa21..01ac21e4a 100644 --- a/src/clstepcore/STEPaggrEnum.cc +++ b/src/clstepcore/STEPaggrEnum.cc @@ -1,4 +1,4 @@ -#include "STEPaggrEnum.h" +#include "clstepcore/STEPaggrEnum.h" #include /** \file StepaggrEnum.cc diff --git a/src/clstepcore/STEPaggrGeneric.cc b/src/clstepcore/STEPaggrGeneric.cc index 899d6c656..5db812b27 100644 --- a/src/clstepcore/STEPaggrGeneric.cc +++ b/src/clstepcore/STEPaggrGeneric.cc @@ -1,4 +1,4 @@ -#include "STEPaggrGeneric.h" +#include "clstepcore/STEPaggrGeneric.h" #include /** \file STEPaggrGeneric.cc diff --git a/src/clstepcore/STEPaggrInt.cc b/src/clstepcore/STEPaggrInt.cc index 3989e82f9..7d9e86884 100644 --- a/src/clstepcore/STEPaggrInt.cc +++ b/src/clstepcore/STEPaggrInt.cc @@ -1,4 +1,4 @@ -#include "STEPaggrInt.h" +#include "clstepcore/STEPaggrInt.h" IntAggregate::IntAggregate() { @@ -96,7 +96,7 @@ const char * IntNode::asStr( std::string & s ) { const char * IntNode::STEPwrite( std::string & s, const char * ) { char tmp[BUFSIZ+1]; if( value != S_INT_NULL ) { - sprintf( tmp, "%ld", value ); + snprintf( tmp, sizeof(tmp), "%ld", value ); s = tmp; } else { s.clear(); diff --git a/src/clstepcore/STEPaggrReal.cc b/src/clstepcore/STEPaggrReal.cc index 7d05c1333..96ae53406 100644 --- a/src/clstepcore/STEPaggrReal.cc +++ b/src/clstepcore/STEPaggrReal.cc @@ -1,4 +1,4 @@ -#include "STEPaggrReal.h" +#include "clstepcore/STEPaggrReal.h" /** \file STEPaggrReal.cc * implementation of classes RealAggregate and RealNode diff --git a/src/clstepcore/STEPaggrSelect.cc b/src/clstepcore/STEPaggrSelect.cc index 2e02113d7..5047e8bf3 100644 --- a/src/clstepcore/STEPaggrSelect.cc +++ b/src/clstepcore/STEPaggrSelect.cc @@ -1,5 +1,5 @@ -#include "STEPaggrSelect.h" -#include "typeDescriptor.h" +#include "clstepcore/STEPaggrSelect.h" +#include "clstepcore/typeDescriptor.h" #include /** \file STEPaggrSelect.cc @@ -87,7 +87,7 @@ Severity SelectAggregate::ReadValue( istream & in, ErrorDescriptor * err, CheckRemainingInput( in, &errdesc, buf, ",)" ); if( errdesc.severity() < SEVERITY_INCOMPLETE ) { - sprintf( errmsg, " index: %d\n", value_cnt ); + snprintf( errmsg, sizeof(errmsg), " index: %d\n", value_cnt ); errdesc.PrependToDetailMsg( errmsg ); err->AppendFromErrorArg( &errdesc ); } diff --git a/src/clstepcore/STEPaggrString.cc b/src/clstepcore/STEPaggrString.cc index fd9285ad3..1aaf752e1 100644 --- a/src/clstepcore/STEPaggrString.cc +++ b/src/clstepcore/STEPaggrString.cc @@ -1,4 +1,4 @@ -#include "STEPaggrString.h" +#include "clstepcore/STEPaggrString.h" #include /** \file STEPaggrString.cc diff --git a/src/clstepcore/STEPaggregate.cc b/src/clstepcore/STEPaggregate.cc index 960a7866c..ef08778a4 100644 --- a/src/clstepcore/STEPaggregate.cc +++ b/src/clstepcore/STEPaggregate.cc @@ -12,12 +12,11 @@ #include -#include -#include -#include -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/read_func.h" +#include "clstepcore/STEPaggregate.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/instmgr.h" +#include "clstepcore/ExpDict.h" /** @@ -175,7 +174,7 @@ Severity STEPaggregate::ReadValue( istream & in, ErrorDescriptor * err, CheckRemainingInput( in, &errdesc, buf, ",)" ); if( errdesc.severity() < SEVERITY_INCOMPLETE ) { - sprintf( errmsg, " index: %d\n", value_cnt ); + snprintf( errmsg, sizeof(errmsg), " index: %d\n", value_cnt ); errdesc.PrependToDetailMsg( errmsg ); err->AppendFromErrorArg( &errdesc ); } diff --git a/src/clstepcore/STEPattribute.cc b/src/clstepcore/STEPattribute.cc index dcfeb2486..487865687 100644 --- a/src/clstepcore/STEPattribute.cc +++ b/src/clstepcore/STEPattribute.cc @@ -12,14 +12,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/read_func.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/instmgr.h" +#include "clstepcore/STEPundefined.h" +#include "clstepcore/STEPaggregate.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/sdai.h" // REAL_NUM_PRECISION is defined in STEPattribute.h, and is also used // in aggregate real handling (STEPaggregate.cc) -- IMS 6 Jun 95 @@ -1267,15 +1266,15 @@ void STEPattribute::AddErrorInfo() { errStr[0] = '\0'; if( SEVERITY_INPUT_ERROR < _error.severity() && _error.severity() < SEVERITY_NULL ) { - sprintf( errStr, " Warning: ATTRIBUTE '%s : %s : %d' - ", + snprintf( errStr, sizeof(errStr), " Warning: ATTRIBUTE '%s : %s : %d' - ", Name(), TypeName().c_str(), Type() ); _error.PrependToDetailMsg( errStr ); } else if( _error.severity() == SEVERITY_INPUT_ERROR ) { - sprintf( errStr, " Error: ATTRIBUTE '%s : %s : %d' - ", + snprintf( errStr, sizeof(errStr), " Error: ATTRIBUTE '%s : %s : %d' - ", Name(), TypeName().c_str(), Type() ); _error.PrependToDetailMsg( errStr ); } else if( _error.severity() <= SEVERITY_BUG ) { - sprintf( errStr, " BUG: ATTRIBUTE '%s : %s : %d' - ", + snprintf( errStr, sizeof(errStr), " BUG: ATTRIBUTE '%s : %s : %d' - ", Name(), TypeName().c_str(), Type() ); _error.PrependToDetailMsg( errStr ); } @@ -1303,12 +1302,12 @@ char STEPattribute::SkipBadAttr( istream & in, char * StopChars ) { } if( in.eof() ) { _error.GreaterSeverity( SEVERITY_INPUT_ERROR ); - sprintf( errStr, " Error: attribute '%s : %s : %d' - %s.\n", + snprintf( errStr, sizeof(errStr), " Error: attribute '%s : %s : %d' - %s.\n", Name(), TypeName().c_str(), Type(), "Unexpected EOF when skipping bad attr value" ); _error.AppendToDetailMsg( errStr ); } else { - sprintf( errStr, " Error: attribute '%s : %s : %d' - %s.\n", + snprintf( errStr, sizeof(errStr), " Error: attribute '%s : %s : %d' - %s.\n", Name(), TypeName().c_str(), Type(), "Invalid value" ); _error.AppendToDetailMsg( errStr ); } diff --git a/src/clstepcore/STEPattributeList.cc b/src/clstepcore/STEPattributeList.cc index 7774321b2..2fce6592b 100644 --- a/src/clstepcore/STEPattributeList.cc +++ b/src/clstepcore/STEPattributeList.cc @@ -10,9 +10,8 @@ * and is not subject to copyright. */ -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/STEPattributeList.h" +#include "clstepcore/STEPattribute.h" AttrListNode::AttrListNode( STEPattribute * a ) { attr = a; @@ -42,10 +41,14 @@ STEPattribute & STEPattributeList::operator []( int n ) { return *( a->attr ); } - // else + // else - error case: return a static error object to avoid undefined behavior + // The error object allows calling code to detect the error condition + static STEPattribute errorAttr; cerr << "\nERROR in STEP Core library: " << __FILE__ << ":" << __LINE__ << "\n" << _POC_ << "\n\n"; - return *( STEPattribute * ) 0; + errorAttr.Error().AppendToDetailMsg( "STEPattributeList::operator[] - index out of bounds" ); + errorAttr.Error().severity( SEVERITY_BUG ); + return errorAttr; } int STEPattributeList::list_length() { diff --git a/src/clstepcore/STEPcomplex.cc b/src/clstepcore/STEPcomplex.cc index 1178a7ca3..719ffb1c4 100644 --- a/src/clstepcore/STEPcomplex.cc +++ b/src/clstepcore/STEPcomplex.cc @@ -1,12 +1,11 @@ #include -#include -#include -#include -#include +#include "clstepcore/STEPcomplex.h" +#include "clstepcore/complexSupport.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/STEPaggregate.h" #include -#include "sc_memmgr.h" extern const char * ReadStdKeyword( istream & in, std::string & buf, int skipInitWS ); @@ -662,7 +661,7 @@ void STEPcomplex::CopyAs( SDAI_Application_instance * se ) { char errStr[BUFSIZ+1]; cerr << "STEPcomplex::CopyAs() called with non-complex entity: " << __FILE__ << __LINE__ << "\n" << _POC_ "\n"; - sprintf( errStr, + snprintf( errStr, sizeof(errStr), "STEPcomplex::CopyAs(): %s - entity #%d.\n", "Programming ERROR - called with non-complex entity", STEPfile_id ); @@ -703,7 +702,7 @@ SDAI_Application_instance * STEPcomplex::Replicate() { char errStr[BUFSIZ+1]; cerr << "STEPcomplex::Replicate() name buffer too small: " << __FILE__ << __LINE__ << "\n" << _POC_ "\n"; - sprintf( errStr, + snprintf( errStr, sizeof(errStr), "STEPcomplex::Replicate(): %s - entity #%d.\n", "Programming ERROR - name buffer too small", STEPfile_id ); diff --git a/src/clstepcore/STEPinvAttrList.cc b/src/clstepcore/STEPinvAttrList.cc index 52bdf1ee5..3eaa9d352 100644 --- a/src/clstepcore/STEPinvAttrList.cc +++ b/src/clstepcore/STEPinvAttrList.cc @@ -3,9 +3,8 @@ * derived from STEPattributeList.cc */ -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/STEPinvAttrList.h" +#include "clstepcore/ExpDict.h" invAttrListNodeI::invAttrListNodeI(Inverse_attribute* a, setterI_t s, getterI_t g): invAttrListNode(a), set( s ), get( g ) {} invAttrListNodeA::invAttrListNodeA(Inverse_attribute* a, setterA_t s, getterA_t g): invAttrListNode(a), set( s ), get( g ) {} diff --git a/src/clstepcore/STEPundefined.cc b/src/clstepcore/STEPundefined.cc index 6ca378099..19c63f37d 100644 --- a/src/clstepcore/STEPundefined.cc +++ b/src/clstepcore/STEPundefined.cc @@ -11,9 +11,8 @@ */ #include // to get the BUFSIZ #define -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/STEPundefined.h" /** \class SCLundefined ** helper functions for reading unknown types diff --git a/src/clstepcore/SingleLinkList.cc b/src/clstepcore/SingleLinkList.cc index 890e423b8..19a1f82e7 100644 --- a/src/clstepcore/SingleLinkList.cc +++ b/src/clstepcore/SingleLinkList.cc @@ -10,8 +10,7 @@ * and is not subject to copyright. */ -#include -#include "sc_memmgr.h" +#include "clstepcore/SingleLinkList.h" #include diff --git a/src/clstepcore/aggrTypeDescriptor.cc b/src/clstepcore/aggrTypeDescriptor.cc index 91bed40be..b61b08f72 100644 --- a/src/clstepcore/aggrTypeDescriptor.cc +++ b/src/clstepcore/aggrTypeDescriptor.cc @@ -1,4 +1,4 @@ -#include "aggrTypeDescriptor.h" +#include "clstepcore/aggrTypeDescriptor.h" STEPaggregate * AggrTypeDescriptor::CreateAggregate() { if( CreateNewAggr ) { diff --git a/src/clstepcore/attrDescriptor.cc b/src/clstepcore/attrDescriptor.cc index 329d90393..a6a71b65a 100644 --- a/src/clstepcore/attrDescriptor.cc +++ b/src/clstepcore/attrDescriptor.cc @@ -1,4 +1,4 @@ -#include "attrDescriptor.h" +#include "clstepcore/attrDescriptor.h" AttrDescriptor::AttrDescriptor( const char * name, const TypeDescriptor * domainType, Logical optional, Logical unique, AttrType_Enum at, diff --git a/src/clstepcore/attrDescriptorList.cc b/src/clstepcore/attrDescriptorList.cc index c197ac5e2..903180c5b 100644 --- a/src/clstepcore/attrDescriptorList.cc +++ b/src/clstepcore/attrDescriptorList.cc @@ -1,6 +1,6 @@ -#include "attrDescriptorList.h" +#include "clstepcore/attrDescriptorList.h" -#include "attrDescriptor.h" +#include "clstepcore/attrDescriptor.h" AttrDescriptorList::AttrDescriptorList() { } diff --git a/src/clstepcore/collect.cc b/src/clstepcore/collect.cc index b6abef73c..7a952f556 100644 --- a/src/clstepcore/collect.cc +++ b/src/clstepcore/collect.cc @@ -11,8 +11,7 @@ * Date: 11/14/96 * *****************************************************************************/ -#include "complexSupport.h" -#include "sc_memmgr.h" +#include "clstepcore/complexSupport.h" /** * Inserts a new ComplexList to our list. The ComplexLists are ordered by diff --git a/src/clstepcore/complexlist.cc b/src/clstepcore/complexlist.cc index 2fc289381..3dcdff482 100644 --- a/src/clstepcore/complexlist.cc +++ b/src/clstepcore/complexlist.cc @@ -10,8 +10,7 @@ * Date: 01/07/97 * *****************************************************************************/ -#include "complexSupport.h" -#include "sc_memmgr.h" +#include "clstepcore/complexSupport.h" /** * Destructor for ComplexList. diff --git a/src/clstepcore/create_Aggr.cc b/src/clstepcore/create_Aggr.cc index 72f6adb53..e71cfbc86 100644 --- a/src/clstepcore/create_Aggr.cc +++ b/src/clstepcore/create_Aggr.cc @@ -1,5 +1,5 @@ -#include "create_Aggr.h" -#include +#include "clstepcore/create_Aggr.h" +#include "clstepcore/STEPaggregate.h" EnumAggregate * create_EnumAggregate() { return new EnumAggregate; diff --git a/src/clstepcore/derivedAttribute.cc b/src/clstepcore/derivedAttribute.cc index 7fca3b16f..8d21b0884 100644 --- a/src/clstepcore/derivedAttribute.cc +++ b/src/clstepcore/derivedAttribute.cc @@ -1,4 +1,4 @@ -#include "derivedAttribute.h" +#include "clstepcore/derivedAttribute.h" Derived_attribute::Derived_attribute( const char * name, const TypeDescriptor * domainType, Logical optional, Logical unique, AttrType_Enum at, const EntityDescriptor & owner ) diff --git a/src/clstepcore/dictSchema.cc b/src/clstepcore/dictSchema.cc index 11170d4df..aa87b4586 100644 --- a/src/clstepcore/dictSchema.cc +++ b/src/clstepcore/dictSchema.cc @@ -1,7 +1,7 @@ -#include "dictSchema.h" +#include "clstepcore/dictSchema.h" -#include "typeDescriptor.h" -#include "entityDescriptor.h" +#include "clstepcore/typeDescriptor.h" +#include "clstepcore/entityDescriptor.h" Schema::Schema( const char * schemaName ) : _use_interface_list( new Interface_spec__set ), diff --git a/src/clstepcore/dispnode.cc b/src/clstepcore/dispnode.cc index 2590e034c..15f249d37 100644 --- a/src/clstepcore/dispnode.cc +++ b/src/clstepcore/dispnode.cc @@ -12,13 +12,12 @@ /* $Id: dispnode.cc,v 3.0.1.2 1997/11/05 22:11:39 sauderd DP3.1 $ */ -#include -#include +#include "clutils/gennode.h" +#include "clutils/gennodelist.h" //#include -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/dispnode.h" +#include "clstepcore/dispnodelist.h" // define this to be the name of the display object class StepEntityEditor; diff --git a/src/clstepcore/dispnodelist.cc b/src/clstepcore/dispnodelist.cc index f4d00a6aa..7fbd788c3 100644 --- a/src/clstepcore/dispnodelist.cc +++ b/src/clstepcore/dispnodelist.cc @@ -12,14 +12,13 @@ /* $Id: dispnodelist.cc,v 3.0.1.2 1997/11/05 22:11:40 sauderd DP3.1 $ */ -#include -#include - -#include -#include -#include -#include -#include "sc_memmgr.h" +#include "clutils/gennode.h" +#include "clutils/gennodelist.h" + +#include "clstepcore/mgrnode.h" +#include "clstepcore/mgrnodelist.h" +#include "clstepcore/dispnode.h" +#include "clstepcore/dispnodelist.h" void DisplayNodeList::Remove( GenericNode * node ) { GenNodeList::Remove( node ); diff --git a/src/clstepcore/entityDescriptor.cc b/src/clstepcore/entityDescriptor.cc index 0e58c4db6..764d77066 100644 --- a/src/clstepcore/entityDescriptor.cc +++ b/src/clstepcore/entityDescriptor.cc @@ -1,10 +1,10 @@ #include -#include "entityDescriptor.h" -#include "Registry.h" -#include "attrDescriptor.h" -#include "inverseAttribute.h" -#include "SubSuperIterators.h" +#include "clstepcore/entityDescriptor.h" +#include "clstepcore/Registry.h" +#include "clstepcore/attrDescriptor.h" +#include "clstepcore/inverseAttribute.h" +#include "clstepcore/SubSuperIterators.h" EntityDescriptor::EntityDescriptor( ) : _abstractEntity( LUnknown ), _extMapping( LUnknown ), diff --git a/src/clstepcore/entityDescriptorList.cc b/src/clstepcore/entityDescriptorList.cc index 86d937c76..e23baeabb 100644 --- a/src/clstepcore/entityDescriptorList.cc +++ b/src/clstepcore/entityDescriptorList.cc @@ -1,4 +1,4 @@ -#include "entityDescriptorList.h" +#include "clstepcore/entityDescriptorList.h" EntityDescLinkNode::EntityDescLinkNode() { _entityDesc = 0; diff --git a/src/clstepcore/entlist.cc b/src/clstepcore/entlist.cc index 0dd35803a..e7c0d7c89 100644 --- a/src/clstepcore/entlist.cc +++ b/src/clstepcore/entlist.cc @@ -13,8 +13,7 @@ * Date: 9/18/96 * *****************************************************************************/ -#include "complexSupport.h" -#include "sc_memmgr.h" +#include "clstepcore/complexSupport.h" /** * Returns the number of EntLists in this's list (EntList->next, next->next diff --git a/src/clstepcore/entnode.cc b/src/clstepcore/entnode.cc index 792489e4b..bc2141360 100644 --- a/src/clstepcore/entnode.cc +++ b/src/clstepcore/entnode.cc @@ -11,8 +11,7 @@ * Date: 9/18/96 * *****************************************************************************/ -#include "complexSupport.h" -#include "sc_memmgr.h" +#include "clstepcore/complexSupport.h" /** * Given a list of entity names, creates a sorted linked list of EntNodes diff --git a/src/clstepcore/enumTypeDescriptor.cc b/src/clstepcore/enumTypeDescriptor.cc index 9598702f0..61c4eef0f 100644 --- a/src/clstepcore/enumTypeDescriptor.cc +++ b/src/clstepcore/enumTypeDescriptor.cc @@ -1,4 +1,4 @@ -#include "enumTypeDescriptor.h" +#include "clstepcore/enumTypeDescriptor.h" /* * why have EnumTypeDescriptor + EnumerationTypeDescriptor ??? diff --git a/src/clstepcore/explicitItemId.cc b/src/clstepcore/explicitItemId.cc index c229f6369..b7177c189 100644 --- a/src/clstepcore/explicitItemId.cc +++ b/src/clstepcore/explicitItemId.cc @@ -1,4 +1,4 @@ -#include "explicitItemId.h" +#include "clstepcore/explicitItemId.h" Explicit_item_id::Explicit_item_id() { _local_definition = 0; diff --git a/src/clstepcore/globalRule.cc b/src/clstepcore/globalRule.cc index b6fdeb19a..227562faa 100644 --- a/src/clstepcore/globalRule.cc +++ b/src/clstepcore/globalRule.cc @@ -1,4 +1,4 @@ -#include "globalRule.h" +#include "clstepcore/globalRule.h" Global_rule::Global_rule() : _entities( 0 ), _where_rules( 0 ), _parent_schema( 0 ) { diff --git a/src/clstepcore/implicitItemId.cc b/src/clstepcore/implicitItemId.cc index 1961727af..963844314 100644 --- a/src/clstepcore/implicitItemId.cc +++ b/src/clstepcore/implicitItemId.cc @@ -1,4 +1,4 @@ -#include "implicitItemId.h" +#include "clstepcore/implicitItemId.h" Implicit_item_id::Implicit_item_id() { _local_definition = 0; diff --git a/src/clstepcore/instmgr.cc b/src/clstepcore/instmgr.cc index 0f74b27c0..61212d4d6 100644 --- a/src/clstepcore/instmgr.cc +++ b/src/clstepcore/instmgr.cc @@ -16,9 +16,8 @@ // ////////////////////////////////////////////////////////////////////////////// -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" +#include "clstepcore/instmgr.h" /////////////////////////////////////////////////////////////////////////////// // debug_level >= 2 => tells when a command is chosen @@ -116,11 +115,11 @@ InstMgr::VerifyInstances( ErrorDescriptor & err ) { if( !mn ) { ++errorCount; if( errorCount == 1 ) - sprintf( errbuf, + snprintf( errbuf, sizeof(errbuf), "VerifyInstances: Unable to verify the following instances: node %d", i ); else { - sprintf( errbuf, ", node %d", i ); + snprintf( errbuf, sizeof(errbuf), ", node %d", i ); } err.AppendToDetailMsg( errbuf ); @@ -140,18 +139,18 @@ InstMgr::VerifyInstances( ErrorDescriptor & err ) { } ++errorCount; if( errorCount == 1 ) - sprintf( errbuf, + snprintf( errbuf, sizeof(errbuf), "VerifyInstances: Unable to verify the following instances: #%d", se->StepFileId() ); else { - sprintf( errbuf, ", #%d", se->StepFileId() ); + snprintf( errbuf, sizeof(errbuf), ", #%d", se->StepFileId() ); } err.AppendToDetailMsg( errbuf ); } } } if( errorCount ) { - sprintf( errbuf, + snprintf( errbuf, sizeof(errbuf), "VerifyInstances: %d invalid instances in list.\n", errorCount ); err.AppendToUserMsg( errbuf ); diff --git a/src/clstepcore/interfaceSpec.cc b/src/clstepcore/interfaceSpec.cc index eb0fecf3a..b0ed39bc5 100644 --- a/src/clstepcore/interfaceSpec.cc +++ b/src/clstepcore/interfaceSpec.cc @@ -1,4 +1,4 @@ -#include "interfaceSpec.h" +#include "clstepcore/interfaceSpec.h" Interface_spec__set::Interface_spec__set( int defaultSize ) { _bufsize = defaultSize; diff --git a/src/clstepcore/interfacedItem.cc b/src/clstepcore/interfacedItem.cc index 749a5922e..9ddb5b5a5 100644 --- a/src/clstepcore/interfacedItem.cc +++ b/src/clstepcore/interfacedItem.cc @@ -1,4 +1,4 @@ -#include "interfacedItem.h" +#include "clstepcore/interfacedItem.h" Interfaced_item::Interfaced_item() { } diff --git a/src/clstepcore/inverseAttribute.cc b/src/clstepcore/inverseAttribute.cc index eeccec90a..512c71c34 100644 --- a/src/clstepcore/inverseAttribute.cc +++ b/src/clstepcore/inverseAttribute.cc @@ -1,4 +1,4 @@ -#include "inverseAttribute.h" +#include "clstepcore/inverseAttribute.h" #include const char * Inverse_attribute::AttrExprDefStr( std::string & s ) const { diff --git a/src/clstepcore/inverseAttributeList.cc b/src/clstepcore/inverseAttributeList.cc index 22591d41c..2dd7d46b0 100644 --- a/src/clstepcore/inverseAttributeList.cc +++ b/src/clstepcore/inverseAttributeList.cc @@ -1,5 +1,5 @@ -#include "inverseAttributeList.h" -#include "inverseAttribute.h" +#include "clstepcore/inverseAttributeList.h" +#include "clstepcore/inverseAttribute.h" Inverse_attributeLinkNode::Inverse_attributeLinkNode() { _invAttr = 0; diff --git a/src/clstepcore/match-ors.cc b/src/clstepcore/match-ors.cc index 5f17f7d93..72427ca6b 100644 --- a/src/clstepcore/match-ors.cc +++ b/src/clstepcore/match-ors.cc @@ -13,8 +13,7 @@ * Date: 10/17/96 * *****************************************************************************/ -#include "complexSupport.h" -#include "sc_memmgr.h" +#include "clstepcore/complexSupport.h" /** * Loops through descendants of this, invoking their matchOR functions. diff --git a/src/clstepcore/mgrnode.cc b/src/clstepcore/mgrnode.cc index 8e44443ee..a7d13b538 100644 --- a/src/clstepcore/mgrnode.cc +++ b/src/clstepcore/mgrnode.cc @@ -12,17 +12,16 @@ /* $Id: mgrnode.cc,v 3.0.1.3 1997/11/05 22:11:37 sauderd DP3.1 $ */ -#include -#include -#include -#include +#include "clstepcore/mgrnode.h" +#include "clstepcore/mgrnodelist.h" +#include "clstepcore/dispnode.h" +#include "clstepcore/dispnodelist.h" -#include +#include "clstepcore/instmgr.h" //#include -#include +#include "clstepcore/sdai.h" #include -#include "sc_memmgr.h" void * MgrNode::SEE() { return ( di ? di->SEE() : 0 ); diff --git a/src/clstepcore/mgrnodearray.cc b/src/clstepcore/mgrnodearray.cc index 23069f02b..d777b596f 100644 --- a/src/clstepcore/mgrnodearray.cc +++ b/src/clstepcore/mgrnodearray.cc @@ -32,12 +32,11 @@ static int PrintFunctionTrace = 2; // values within functions get printed out //static int PrintValues = 3; -#include +#include "clstepcore/mgrnodearray.h" //#include -#include +#include "clstepcore/sdai.h" #include // to get bcopy() - ANSI -#include "sc_memmgr.h" ////////////////////////////////////////////////////////////////////////////// // class MgrNodeArray member functions diff --git a/src/clstepcore/mgrnodelist.cc b/src/clstepcore/mgrnodelist.cc index 9bff8e254..77ee20100 100644 --- a/src/clstepcore/mgrnodelist.cc +++ b/src/clstepcore/mgrnodelist.cc @@ -12,11 +12,10 @@ /* $Id: mgrnodelist.cc,v 3.0.1.2 1997/11/05 22:11:39 sauderd DP3.1 $ */ -#include -#include -#include -#include -#include "sc_memmgr.h" +#include "clstepcore/mgrnode.h" +#include "clstepcore/mgrnodelist.h" +#include "clstepcore/dispnode.h" +#include "clstepcore/dispnodelist.h" MgrNodeList::MgrNodeList( stateEnum type ) : GenNodeList( new MgrNode() ) { // if(debug_level >= PrintFunctionTrace) diff --git a/src/clstepcore/multlist.cc b/src/clstepcore/multlist.cc index 959720ed0..b36488377 100644 --- a/src/clstepcore/multlist.cc +++ b/src/clstepcore/multlist.cc @@ -13,8 +13,7 @@ * Date: 9/18/96 * *****************************************************************************/ -#include "complexSupport.h" -#include "sc_memmgr.h" +#include "clstepcore/complexSupport.h" /** * Deletes the childList of this, before this is deleted. diff --git a/src/clstepcore/needFunc.cc b/src/clstepcore/needFunc.cc index eea46ddb5..e72215fed 100644 --- a/src/clstepcore/needFunc.cc +++ b/src/clstepcore/needFunc.cc @@ -1,5 +1,4 @@ -#include -#include "sc_memmgr.h" +#include "clstepcore/needFunc.h" /////////////////////////////////////////////////////////////////////////////// // Function defined as a stub (necessary to use the scl) diff --git a/src/clstepcore/non-ors.cc b/src/clstepcore/non-ors.cc index 14607f606..14b6a4f6c 100644 --- a/src/clstepcore/non-ors.cc +++ b/src/clstepcore/non-ors.cc @@ -10,8 +10,7 @@ * Date: 10/17/96 * *****************************************************************************/ -#include "complexSupport.h" -#include "sc_memmgr.h" +#include "clstepcore/complexSupport.h" /** * Checks if we match the nodes of ents. If only one unmarked is left diff --git a/src/clstepcore/orlist.cc b/src/clstepcore/orlist.cc index b820bea53..f5fa185b0 100644 --- a/src/clstepcore/orlist.cc +++ b/src/clstepcore/orlist.cc @@ -10,8 +10,7 @@ * Date: 9/18/96 * *****************************************************************************/ -#include "complexSupport.h" -#include "sc_memmgr.h" +#include "clstepcore/complexSupport.h" /** * Check if we matched nm. We have two possibilities here: If we have a diff --git a/src/clstepcore/print.cc b/src/clstepcore/print.cc index 2139d1f61..63759b9fc 100644 --- a/src/clstepcore/print.cc +++ b/src/clstepcore/print.cc @@ -7,8 +7,7 @@ * Date: 10/31/96 * *****************************************************************************/ -#include "complexSupport.h" -#include "sc_memmgr.h" +#include "clstepcore/complexSupport.h" // Local function prototypes: static char * joinText( JoinType, char * ); diff --git a/src/clstepcore/read_func.cc b/src/clstepcore/read_func.cc index a0c47dc2a..f834251a7 100644 --- a/src/clstepcore/read_func.cc +++ b/src/clstepcore/read_func.cc @@ -1,11 +1,10 @@ -#include +#include "clutils/errordesc.h" #include -#include -#include -#include -#include "Str.h" -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" +#include "clstepcore/read_func.h" +#include "clstepcore/STEPattribute.h" +#include "clutils/Str.h" const int RealNumPrecision = REAL_NUM_PRECISION; @@ -154,7 +153,7 @@ std::string WriteReal( SDAI_Real val ) { // Also use G instead of g since G writes uppercase E (E instead of e // is also required by Part 21) when scientific notation is used - DAS - sprintf( rbuf, "%.*G", ( int ) RealNumPrecision, val ); + snprintf( rbuf, sizeof(rbuf), "%.*G", ( int ) RealNumPrecision, val ); if( !strchr( rbuf, '.' ) ) { if( strchr( rbuf, 'E' ) || strchr( rbuf, 'e' ) ) { char * expon = strchr( rbuf, 'E' ); @@ -491,7 +490,7 @@ void PushPastImbedAggr( istream & in, std::string & s, ErrorDescriptor * err ) { } if( c != ')' ) { err->GreaterSeverity( SEVERITY_INPUT_ERROR ); - sprintf( messageBuf, "Invalid aggregate value.\n" ); + snprintf( messageBuf, sizeof(messageBuf), "Invalid aggregate value.\n" ); err->AppendToDetailMsg( messageBuf ); s.append( ")" ); } else { @@ -519,7 +518,7 @@ void PushPastAggr1Dim( istream & in, std::string & s, ErrorDescriptor * err ) { while( in.good() && ( c != ')' ) ) { if( c == '(' ) { err->GreaterSeverity( SEVERITY_WARNING ); - sprintf( messageBuf, "Invalid aggregate value.\n" ); + snprintf( messageBuf, sizeof(messageBuf), "Invalid aggregate value.\n" ); err->AppendToDetailMsg( messageBuf ); } @@ -533,7 +532,7 @@ void PushPastAggr1Dim( istream & in, std::string & s, ErrorDescriptor * err ) { } if( c != ')' ) { err->GreaterSeverity( SEVERITY_INPUT_ERROR ); - sprintf( messageBuf, "Invalid aggregate value.\n" ); + snprintf( messageBuf, sizeof(messageBuf), "Invalid aggregate value.\n" ); err->AppendToDetailMsg( messageBuf ); s.append( ")" ); } else { diff --git a/src/clstepcore/schRename.cc b/src/clstepcore/schRename.cc index b7159a6e0..6e5e12686 100644 --- a/src/clstepcore/schRename.cc +++ b/src/clstepcore/schRename.cc @@ -1,4 +1,4 @@ -#include "schRename.h" +#include "clstepcore/schRename.h" /** diff --git a/src/clstepcore/sdai.cc b/src/clstepcore/sdai.cc index 731a381f5..ec96a63b3 100644 --- a/src/clstepcore/sdai.cc +++ b/src/clstepcore/sdai.cc @@ -1,8 +1,7 @@ #include #include -#include -#include "sc_memmgr.h" +#include "clstepcore/sdai.h" const char * SCLversion = "STEPcode, github.com/stepcode/stepcode"; diff --git a/src/clstepcore/sdaiApplication_instance.cc b/src/clstepcore/sdaiApplication_instance.cc index de5d19b76..0b0b4427a 100644 --- a/src/clstepcore/sdaiApplication_instance.cc +++ b/src/clstepcore/sdaiApplication_instance.cc @@ -11,13 +11,13 @@ */ #include -#include -#include -#include -#include -#include //for ReadTokenSeparator, used when comments are inside entities +#include "clstepcore/sdai.h" +#include "clstepcore/instmgr.h" +#include "clstepcore/STEPcomplex.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/read_func.h" //for ReadTokenSeparator, used when comments are inside entities -#include "sdaiApplication_instance.h" +#include "clstepcore/sdaiApplication_instance.h" #include "superInvAttrIter.h" SDAI_Application_instance NilSTEPentity; @@ -106,7 +106,7 @@ SDAI_Application_instance * SDAI_Application_instance::Replicate() { if( IsComplex() ) { cerr << "STEPcomplex::Replicate() should be called: " << __FILE__ << __LINE__ << "\n" << _POC_ "\n"; - sprintf( errStr, + snprintf( errStr, sizeof(errStr), "SDAI_Application_instance::Replicate(): %s - entity #%d.\n", "Programming ERROR - STEPcomplex::Replicate() should be called", STEPfile_id ); @@ -151,7 +151,7 @@ void SDAI_Application_instance::STEPwrite_reference( ostream & out ) { const char * SDAI_Application_instance::STEPwrite_reference( std::string & buf ) { char tmp[64]; - sprintf( tmp, "#%d", STEPfile_id ); + snprintf( tmp, sizeof(tmp), "#%d", STEPfile_id ); buf = tmp; return const_cast( buf.c_str() ); } @@ -419,7 +419,7 @@ const char * SDAI_Application_instance::STEPwrite( std::string & buf, const char char instanceInfo[BUFSIZ+1]; std::string tmp; - sprintf( instanceInfo, "#%d=%s(", STEPfile_id, StrToUpper( EntityName( currSch ), tmp ) ); + snprintf( instanceInfo, sizeof(instanceInfo), "#%d=%s(", STEPfile_id, StrToUpper( EntityName( currSch ), tmp ) ); buf.append( instanceInfo ); int n = attributes.list_length(); @@ -443,7 +443,7 @@ void SDAI_Application_instance::PrependEntityErrMsg() { if( _error.severity() == SEVERITY_NULL ) { // if there is not an error already - sprintf( errStr, "\nERROR: ENTITY #%d %s\n", GetFileId(), + snprintf( errStr, sizeof(errStr), "\nERROR: ENTITY #%d %s\n", GetFileId(), EntityName() ); _error.PrependToDetailMsg( errStr ); } @@ -464,14 +464,14 @@ void SDAI_Application_instance::STEPread_error( char c, int i, istream & in, con if( _error.severity() == SEVERITY_NULL ) { // if there is not an error already - sprintf( errStr, "\nERROR: ENTITY #%d %s\n", GetFileId(), + snprintf( errStr, sizeof(errStr), "\nERROR: ENTITY #%d %s\n", GetFileId(), EntityName() ); _error.PrependToDetailMsg( errStr ); } if( ( i >= 0 ) && ( i < attributes.list_length() ) ) { // i is an attribute Error().GreaterSeverity( SEVERITY_WARNING ); - sprintf( errStr, " invalid data before type \'%s\'\n", + snprintf( errStr, sizeof(errStr), " invalid data before type \'%s\'\n", attributes[i].TypeName().c_str() ); _error.AppendToDetailMsg( errStr ); } else { @@ -487,7 +487,7 @@ void SDAI_Application_instance::STEPread_error( char c, int i, istream & in, con _error.AppendToDetailMsg( c ); _error.AppendToDetailMsg( '\n' ); - sprintf( errStr, "\nfinished reading #%d\n", STEPfile_id ); + snprintf( errStr, sizeof(errStr), "\nfinished reading #%d\n", STEPfile_id ); _error.AppendToDetailMsg( errStr ); return; } @@ -552,7 +552,7 @@ Severity SDAI_Application_instance::STEPread( int id, int idIncr, // set the severity for this entity _error.GreaterSeverity( severe ); - sprintf( errStr, " %s : ", attributes[i].Name() ); + snprintf( errStr, sizeof(errStr), " %s : ", attributes[i].Name() ); _error.AppendToDetailMsg( errStr ); // add attr name _error.AppendToDetailMsg( "Since using pre-technical corrigendum... missing asterisk for redefined attr.\n" ); @@ -583,7 +583,7 @@ Severity SDAI_Application_instance::STEPread( int id, int idIncr, // set the severity for this entity _error.GreaterSeverity( severe ); - sprintf( errStr, " %s : ", attributes[i].Name() ); + snprintf( errStr, sizeof(errStr), " %s : ", attributes[i].Name() ); _error.AppendToDetailMsg( errStr ); // add attr name _error.AppendToDetailMsg( attributes[i].Error().DetailMsg() ); // add attr error _error.AppendToUserMsg( attributes[i].Error().UserMsg() ); @@ -653,7 +653,7 @@ Severity SDAI_Application_instance::STEPread( int id, int idIncr, } } _error.AppendToDetailMsg( tmp.c_str() ); - sprintf( errStr, "\nfinished reading #%d\n", STEPfile_id ); + snprintf( errStr, sizeof(errStr), "\nfinished reading #%d\n", STEPfile_id ); _error.AppendToDetailMsg( errStr ); // end of imported code return _error.severity(); @@ -678,7 +678,7 @@ SDAI_Application_instance * ReadEntityRef( istream & in, ErrorDescriptor * err, int id = -1; in >> id; if( in.fail() ) { // there's been an error in input - sprintf( errStr, "Invalid entity reference value.\n" ); + snprintf( errStr, sizeof(errStr), "Invalid entity reference value.\n" ); err->AppendToDetailMsg( errStr ); err->AppendToUserMsg( errStr ); err->GreaterSeverity( SEVERITY_WARNING ); @@ -692,7 +692,7 @@ SDAI_Application_instance * ReadEntityRef( istream & in, ErrorDescriptor * err, if( !instances ) { cerr << "Internal error: " << __FILE__ << __LINE__ << "\n" << _POC_ "\n"; - sprintf( errStr, + snprintf( errStr, sizeof(errStr), "STEPread_reference(): %s - entity #%d %s.\n", "BUG - cannot read reference without the InstMgr", id, "is unknown" ); @@ -714,7 +714,7 @@ SDAI_Application_instance * ReadEntityRef( istream & in, ErrorDescriptor * err, } else { cerr << "Internal error: " << __FILE__ << __LINE__ << "\n" << _POC_ "\n"; - sprintf( errStr, + snprintf( errStr, sizeof(errStr), "STEPread_reference(): %s - entity #%d %s.\n", "BUG - MgrNode::GetSTEPentity returned NULL pointer", id, "is unknown" ); @@ -724,7 +724,7 @@ SDAI_Application_instance * ReadEntityRef( istream & in, ErrorDescriptor * err, return S_ENTITY_NULL; } } else { - sprintf( errStr, "Reference to non-existent ENTITY #%d.\n", + snprintf( errStr, sizeof(errStr), "Reference to non-existent ENTITY #%d.\n", id ); err->AppendToDetailMsg( errStr ); err->AppendToUserMsg( errStr ); @@ -761,7 +761,7 @@ Severity EntityValidLevel( SDAI_Application_instance * se, if( !ed || ( ed->NonRefType() != ENTITY_TYPE ) ) { err->GreaterSeverity( SEVERITY_BUG ); - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), " BUG: EntityValidLevel() called with %s", "missing or invalid EntityDescriptor\n" ); err->AppendToUserMsg( messageBuf ); @@ -772,7 +772,7 @@ Severity EntityValidLevel( SDAI_Application_instance * se, } if( !se || ( se == S_ENTITY_NULL ) ) { err->GreaterSeverity( SEVERITY_BUG ); - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), " BUG: EntityValidLevel() called with null pointer %s\n", "for SDAI_Application_instance argument." ); err->AppendToUserMsg( messageBuf ); @@ -800,7 +800,7 @@ Severity EntityValidLevel( SDAI_Application_instance * se, } } err->GreaterSeverity( SEVERITY_WARNING ); - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), " Entity #%d exists but is not a %s or descendant.\n", se->STEPfile_id, ed->Name() ); err->AppendToUserMsg( messageBuf ); @@ -809,7 +809,7 @@ Severity EntityValidLevel( SDAI_Application_instance * se, } } else { err->GreaterSeverity( SEVERITY_BUG ); - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), " BUG: EntityValidLevel(): SDAI_Application_instance #%d has a %s", se->STEPfile_id, "missing or invalid EntityDescriptor\n" ); err->AppendToUserMsg( messageBuf ); @@ -893,7 +893,7 @@ Severity EntityValidLevel( const char * attrValue, // string contain entity ref SDAI_Application_instance * se = mn->GetSTEPentity(); return EntityValidLevel( se, ed, err ); } else { - sprintf( messageBuf, + snprintf( messageBuf, sizeof(messageBuf), " Attribute's Entity Reference %s does not exist.\n", attrValue ); err->AppendToUserMsg( messageBuf ); @@ -908,7 +908,7 @@ Severity EntityValidLevel( const char * attrValue, // string contain entity ref return err->severity(); } - sprintf( messageBuf, "Invalid attribute entity reference value: '%s'.\n", + snprintf( messageBuf, sizeof(messageBuf), "Invalid attribute entity reference value: '%s'.\n", attrValue ); err->AppendToUserMsg( messageBuf ); err->AppendToDetailMsg( messageBuf ); diff --git a/src/clstepcore/sdaiSelect.cc b/src/clstepcore/sdaiSelect.cc index 08e789a6d..95e6d83bc 100644 --- a/src/clstepcore/sdaiSelect.cc +++ b/src/clstepcore/sdaiSelect.cc @@ -11,11 +11,11 @@ */ #include // to get the BUFSIZ #define -#include +#include "clstepcore/ExpDict.h" #include #include -#include -#include +#include "clstepcore/sdai.h" +#include "clstepcore/STEPattribute.h" #ifdef SC_LOGGING #include diff --git a/src/clstepcore/selectTypeDescriptor.cc b/src/clstepcore/selectTypeDescriptor.cc index a7c0ad032..e143a3a30 100644 --- a/src/clstepcore/selectTypeDescriptor.cc +++ b/src/clstepcore/selectTypeDescriptor.cc @@ -1,4 +1,4 @@ -#include "selectTypeDescriptor.h" +#include "clstepcore/selectTypeDescriptor.h" /////////////////////////////////////////////////////////////////////////////// // SelectTypeDescriptor functions diff --git a/src/clstepcore/superInvAttrIter.h b/src/clstepcore/superInvAttrIter.h index bfe73dc17..6228b67be 100644 --- a/src/clstepcore/superInvAttrIter.h +++ b/src/clstepcore/superInvAttrIter.h @@ -1,8 +1,8 @@ #ifndef SUPERINVATTRITER_H #define SUPERINVATTRITER_H -#include "SubSuperIterators.h" -#include "ExpDict.h" +#include "clstepcore/SubSuperIterators.h" +#include "clstepcore/ExpDict.h" /** * this class implements an iterator for inverse attributes in an EntityDescriptor's supertypes diff --git a/src/clstepcore/test/CMakeLists.txt b/src/clstepcore/test/CMakeLists.txt index f9f353e26..ea37cb0cd 100644 --- a/src/clstepcore/test/CMakeLists.txt +++ b/src/clstepcore/test/CMakeLists.txt @@ -3,7 +3,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.12) include_directories( ${SC_SOURCE_DIR}/src/cldai ${SC_SOURCE_DIR}/src/cleditor - ${SC_SOURCE_DIR}/src/clutils ${SC_SOURCE_DIR}/src/base ${SC_SOURCE_DIR}/src/clstepcore ) @@ -21,10 +20,10 @@ function(add_stepcore_test name libs) set_tests_properties(test_${name} PROPERTIES LABELS cpp_unit_stepcore DEPENDS build_cpp_${name}) endfunction(add_stepcore_test name libs) -add_stepcore_test("SupertypesIterator" "stepcore;steputils;stepeditor;stepdai;base") #all these libs are necessary? -add_stepcore_test("operators_STEPattribute" "stepcore;steputils;stepeditor;stepdai;base") -add_stepcore_test("operators_SDAI_Select" "stepcore;steputils;stepeditor;stepdai;base") -add_stepcore_test("null_attr" "stepcore;steputils;stepeditor;stepdai;base") +add_stepcore_test("SupertypesIterator" "stepcore;steputils;stepeditor;stepdai") #all these libs are necessary? +add_stepcore_test("operators_STEPattribute" "stepcore;steputils;stepeditor;stepdai") +add_stepcore_test("operators_SDAI_Select" "stepcore;steputils;stepeditor;stepdai") +add_stepcore_test("null_attr" "stepcore;steputils;stepeditor;stepdai") # Local Variables: # tab-width: 8 diff --git a/src/clstepcore/test/test_SupertypesIterator.cc b/src/clstepcore/test/test_SupertypesIterator.cc index f557d7c72..084189bf0 100644 --- a/src/clstepcore/test/test_SupertypesIterator.cc +++ b/src/clstepcore/test/test_SupertypesIterator.cc @@ -4,8 +4,8 @@ //subtypesiterator shouldn't need tested separately from supertypesiterator since there is very little difference -#include "SubSuperIterators.h" -#include "ExpDict.h" +#include "clstepcore/SubSuperIterators.h" +#include "clstepcore/ExpDict.h" #include int main( int /*argc*/, char ** /*argv*/ ) { diff --git a/src/clstepcore/test/test_null_attr.cc b/src/clstepcore/test/test_null_attr.cc index 0c96c5798..95c7dcd02 100644 --- a/src/clstepcore/test/test_null_attr.cc +++ b/src/clstepcore/test/test_null_attr.cc @@ -1,6 +1,6 @@ -#include -#include -#include +#include "clstepcore/ExpDict.h" +#include "clstepcore/STEPattribute.h" +#include "cldai/sdaiString.h" AttrDescriptor *ad = 0; EntityDescriptor *ed = 0; diff --git a/src/clstepcore/test/test_operators_SDAI_Select.cc b/src/clstepcore/test/test_operators_SDAI_Select.cc index fcb6cde4d..b82d20ddc 100644 --- a/src/clstepcore/test/test_operators_SDAI_Select.cc +++ b/src/clstepcore/test/test_operators_SDAI_Select.cc @@ -6,9 +6,9 @@ #include -#include "ExpDict.h" -#include "baseType.h" -#include "sdaiSelect.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/baseType.h" +#include "clstepcore/sdaiSelect.h" using namespace std; diff --git a/src/clstepcore/test/test_operators_STEPattribute.cc b/src/clstepcore/test/test_operators_STEPattribute.cc index abd396816..a64d274de 100644 --- a/src/clstepcore/test/test_operators_STEPattribute.cc +++ b/src/clstepcore/test/test_operators_STEPattribute.cc @@ -1,7 +1,7 @@ ///test constructors, destructor, shallow copy, assignment operators for STEPattribute -#include -#include +#include "clstepcore/STEPattribute.h" +#include "clstepcore/ExpDict.h" #include diff --git a/src/clstepcore/trynext.cc b/src/clstepcore/trynext.cc index 145af7699..dd2941edd 100644 --- a/src/clstepcore/trynext.cc +++ b/src/clstepcore/trynext.cc @@ -11,8 +11,7 @@ * Date: 10/24/96 * *****************************************************************************/ -#include "complexSupport.h" -#include "sc_memmgr.h" +#include "clstepcore/complexSupport.h" // Local function prototypes: static EntList * firstCandidate( EntList * ); diff --git a/src/clstepcore/typeDescriptor.cc b/src/clstepcore/typeDescriptor.cc index 31ead1662..1d654f609 100644 --- a/src/clstepcore/typeDescriptor.cc +++ b/src/clstepcore/typeDescriptor.cc @@ -1,4 +1,4 @@ -#include "typeDescriptor.h" +#include "clstepcore/typeDescriptor.h" TypeDescriptor::TypeDescriptor( ) : _name( 0 ), altNames( 0 ), _fundamentalType( UNKNOWN_TYPE ), @@ -75,7 +75,7 @@ bool TypeDescriptor::CurrName( const char * other, const char * schNm ) const { // other better = the alt name. return ( !StrCmpIns( _altname, other ) ); } else { - // If we have no desginated alternate name when the current schema = + // If we have no designated alternate name when the current schema = // schNm, other must = our _name. return ( OurName( other ) ); } diff --git a/src/clstepcore/typeDescriptorList.cc b/src/clstepcore/typeDescriptorList.cc index f47e8f502..bbc91de9e 100644 --- a/src/clstepcore/typeDescriptorList.cc +++ b/src/clstepcore/typeDescriptorList.cc @@ -1,4 +1,4 @@ -#include "typeDescriptorList.h" +#include "clstepcore/typeDescriptorList.h" TypeDescLinkNode::TypeDescLinkNode() { _typeDesc = 0; diff --git a/src/clstepcore/typeOrRuleVar.cc b/src/clstepcore/typeOrRuleVar.cc index 0b06f1949..c9b823cbf 100644 --- a/src/clstepcore/typeOrRuleVar.cc +++ b/src/clstepcore/typeOrRuleVar.cc @@ -1,4 +1,4 @@ -#include "typeOrRuleVar.h" +#include "clstepcore/typeOrRuleVar.h" #include diff --git a/src/clstepcore/uniquenessRule.cc b/src/clstepcore/uniquenessRule.cc index 038f1a68f..d22bf2c2c 100644 --- a/src/clstepcore/uniquenessRule.cc +++ b/src/clstepcore/uniquenessRule.cc @@ -1,4 +1,4 @@ -#include "uniquenessRule.h" +#include "clstepcore/uniquenessRule.h" #include diff --git a/src/clstepcore/whereRule.cc b/src/clstepcore/whereRule.cc index e60c64940..191b1ec36 100644 --- a/src/clstepcore/whereRule.cc +++ b/src/clstepcore/whereRule.cc @@ -1,4 +1,4 @@ -#include "whereRule.h" +#include "clstepcore/whereRule.h" Where_rule::Where_rule() { _type_or_rule = 0; diff --git a/src/clutils/CMakeLists.txt b/src/clutils/CMakeLists.txt index 514980ad9..27cb08745 100644 --- a/src/clutils/CMakeLists.txt +++ b/src/clutils/CMakeLists.txt @@ -1,5 +1,4 @@ - -set(LIBSTEPUTILS_SRCS +set(UTILS_SRCS Str.cc dirobj.cc gennode.cc @@ -9,24 +8,13 @@ set(LIBSTEPUTILS_SRCS errordesc.cc ) -set(SC_CLUTILS_HDRS - dirobj.h - errordesc.h - gennodearray.h - gennode.h - gennodelist.h - sc_hash.h - Str.h - ) - include_directories( - ${SC_SOURCE_DIR}/src/base ${SC_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR} ) if(BUILD_SHARED_LIBS) - SC_ADDLIB(steputils SHARED SOURCES ${LIBSTEPUTILS_SRCS} LINK_LIBRARIES base) + SC_ADDLIB(steputils SHARED SOURCES ${UTILS_SRCS}) if(WIN32) target_compile_definitions(steputils PRIVATE SC_UTILS_DLL_EXPORTS) target_link_libraries(steputils shlwapi) @@ -34,15 +22,12 @@ if(BUILD_SHARED_LIBS) endif() if(BUILD_STATIC_LIBS) - SC_ADDLIB(steputils-static STATIC SOURCES ${LIBSTEPUTILS_SRCS} LINK_LIBRARIES base-static) + SC_ADDLIB(steputils-static STATIC SOURCES ${UTILS_SRCS}) if(WIN32) target_link_libraries(steputils-static shlwapi) endif() endif() -install(FILES ${SC_CLUTILS_HDRS} - DESTINATION ${INCLUDE_DIR}/stepcode/clutils) - # Local Variables: # tab-width: 8 # mode: cmake diff --git a/src/clutils/Str.cc b/src/clutils/Str.cc index 4ae8ef69c..1f6a3dce3 100644 --- a/src/clutils/Str.cc +++ b/src/clutils/Str.cc @@ -9,7 +9,7 @@ * and is not subject to copyright. */ -#include "Str.h" +#include "clutils/Str.h" #include #include diff --git a/src/clutils/dirobj.cc b/src/clutils/dirobj.cc index 657a9ab5c..e0e3f970a 100644 --- a/src/clutils/dirobj.cc +++ b/src/clutils/dirobj.cc @@ -40,7 +40,7 @@ */ #include "config.h" -#include +#include "clutils/dirobj.h" #ifdef HAVE_DIRENT_H # include #endif @@ -58,8 +58,6 @@ #include #endif -#include - /////////////////////////////////////////////////////////////////////////////// // // Create a new DirObj object. diff --git a/src/clutils/errordesc.cc b/src/clutils/errordesc.cc index c5a998c8c..17a2de465 100644 --- a/src/clutils/errordesc.cc +++ b/src/clutils/errordesc.cc @@ -10,9 +10,8 @@ * and is not subject to copyright. */ -#include -#include -#include +#include "clutils/errordesc.h" +#include "clutils/Str.h" DebugLevel ErrorDescriptor::_debug_level = DEBUG_OFF; ostream * ErrorDescriptor::_out = 0; diff --git a/src/clutils/gennode.cc b/src/clutils/gennode.cc index 3036ab19d..c8a993632 100644 --- a/src/clutils/gennode.cc +++ b/src/clutils/gennode.cc @@ -12,9 +12,8 @@ /* $Id: gennode.cc,v 3.0.1.4 1997/11/05 22:33:47 sauderd DP3.1 $ */ -#include -#include -#include +#include "clutils/gennode.h" +#include "clutils/gennodelist.h" ////////////////////////////////////////////////////////////////////////////// // class GenericNode inline functions that depend on other classes diff --git a/src/clutils/gennodearray.cc b/src/clutils/gennodearray.cc index 0111794fb..22a9a73d3 100644 --- a/src/clutils/gennodearray.cc +++ b/src/clutils/gennodearray.cc @@ -13,10 +13,9 @@ #include "config.h" -#include -#include -#include -#include +#include "clutils/gennode.h" +#include "clutils/gennodelist.h" +#include "clutils/gennodearray.h" #ifndef HAVE_MEMMOVE extern "C" { diff --git a/src/clutils/gennodelist.cc b/src/clutils/gennodelist.cc index 9560a72b1..c75d7a712 100644 --- a/src/clutils/gennodelist.cc +++ b/src/clutils/gennodelist.cc @@ -12,11 +12,10 @@ /* $Id: gennodelist.cc,v 3.0.1.2 1997/11/05 22:33:49 sauderd DP3.1 $ */ -#include -#include +#include "clutils/gennode.h" +#include "clutils/gennodelist.h" //#include -#include -#include +#include "clutils/gennodearray.h" // inserts after existNode void GenNodeList::InsertAfter( GenericNode * newNode, diff --git a/src/clutils/sc_hash.cc b/src/clutils/sc_hash.cc index 1839b6707..8ed4c54ab 100644 --- a/src/clutils/sc_hash.cc +++ b/src/clutils/sc_hash.cc @@ -5,11 +5,10 @@ * also, hcreate/hdestroy routines added to simulate hsearch(3). */ -#include +#include "clutils/sc_hash.h" #include #include #include -#include /* constants */ #define HASH_NULL (Hash_TableP)NULL diff --git a/src/exp2cxx/CMakeLists.txt b/src/exp2cxx/CMakeLists.txt index 93cf8c911..d8fae04cc 100644 --- a/src/exp2cxx/CMakeLists.txt +++ b/src/exp2cxx/CMakeLists.txt @@ -5,6 +5,7 @@ set(FEDEX_COMMON_SRCS set(exp2cxx_SOURCES ${FEDEX_COMMON_SRCS} + trace_fprintf.c fedex_main.c classes_wrapper.cc classes.c @@ -31,13 +32,17 @@ set(exp2cxx_SOURCES ) include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} ${SC_SOURCE_DIR}/include ${SC_SOURCE_DIR}/include/exppp ${SC_SOURCE_DIR}/include/express - ${SC_SOURCE_DIR}/src/base ) -SC_ADDEXEC(exp2cxx SOURCES ${exp2cxx_SOURCES} LINK_LIBRARIES libexppp express base) +if(BUILD_SHARED_LIBS) + SC_ADDEXEC(exp2cxx SOURCES ${exp2cxx_SOURCES} LINK_LIBRARIES libexppp express) +else() + SC_ADDEXEC(exp2cxx SOURCES ${exp2cxx_SOURCES} LINK_LIBRARIES libexppp-static express-static) +endif() if(SC_ENABLE_TESTING) add_subdirectory(test) diff --git a/src/exp2cxx/classes.c b/src/exp2cxx/classes.c index 26e39a909..42f6c02c0 100644 --- a/src/exp2cxx/classes.c +++ b/src/exp2cxx/classes.c @@ -25,14 +25,12 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. /* this is used to add new dictionary calls */ /* #define NEWDICT */ -#include #include #include -#include #include "classes.h" #include -#include +#include "./trace_fprintf.h" int multiple_inheritance = 1; int print_logging = 0; @@ -96,7 +94,7 @@ void format_for_std_stringout( FILE * f, char * orig_buf ) { optr++; } fprintf( f, "%s", s_end ); - sc_free( orig_buf ); + free( orig_buf ); } void USEREFout( Schema schema, Dictionary refdict, Linked_List reflist, char * type, FILE * file ) { @@ -161,19 +159,19 @@ void USEREFout( Schema schema, Dictionary refdict, Linked_List reflist, char * t first_time = false; } if( re->type == OBJ_TYPE ) { - sprintf( td_name, "%s", TYPEtd_name( ( Type )re->object ) ); + snprintf( td_name, sizeof(td_name), "%s", TYPEtd_name( ( Type )re->object ) ); } else if( re->type == OBJ_FUNCTION ) { - sprintf( td_name, "/* Function not implemented */ 0" ); + snprintf( td_name, sizeof(td_name), "/* Function not implemented */ 0" ); } else if( re->type == OBJ_PROCEDURE ) { - sprintf( td_name, "/* Procedure not implemented */ 0" ); + snprintf( td_name, sizeof(td_name), "/* Procedure not implemented */ 0" ); } else if( re->type == OBJ_RULE ) { - sprintf( td_name, "/* Rule not implemented */ 0" ); + snprintf( td_name, sizeof(td_name), "/* Rule not implemented */ 0" ); } else if( re->type == OBJ_ENTITY ) { - sprintf( td_name, "%s%s%s", + snprintf( td_name, sizeof(td_name), "%s%s%s", SCOPEget_name( ( ( Entity )re->object )->superscope ), ENT_PREFIX, ENTITYget_name( ( Entity )re->object ) ); } else { - sprintf( td_name, "/* %c from OBJ_? in expbasic.h not implemented */ 0", re->type ); + snprintf( td_name, sizeof(td_name), "/* %c from OBJ_? in expbasic.h not implemented */ 0", re->type ); } if( re->old != re->nnew ) { fprintf( file, " // object %s AS %s\n", re->old->name, diff --git a/src/exp2cxx/classes_attribute.c b/src/exp2cxx/classes_attribute.c index 95dd8e861..cf2de189d 100644 --- a/src/exp2cxx/classes_attribute.c +++ b/src/exp2cxx/classes_attribute.c @@ -10,22 +10,15 @@ The conventions used in this binding follow the proposed specification for the STEP Standard Data Access Interface as defined in document N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. *******************************************************************/ -#include #include #include #include -#include #include #include #include "classes.h" #include "classes_attribute.h" -#include - -#if defined(_MSC_VER) && _MSC_VER < 1900 -# include "sc_stdio.h" -# define snprintf c99_snprintf -#endif +#include "./trace_fprintf.h" extern int old_accessors; extern int print_logging; @@ -64,7 +57,7 @@ char * generate_attribute_name( Variable a, char * out ) { } } *q = '\0'; - sc_free( temp ); + free( temp ); return out; } diff --git a/src/exp2cxx/classes_entity.c b/src/exp2cxx/classes_entity.c index 0bd8feaf4..fe8b8e113 100644 --- a/src/exp2cxx/classes_entity.c +++ b/src/exp2cxx/classes_entity.c @@ -14,11 +14,16 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. /* this is used to add new dictionary calls */ /* #define NEWDICT */ -#include +#define _XOPEN_SOURCE /* for S_IFDIR */ +#include +#include +#include +#ifdef _WIN32 +# include +#endif /* _WIN32 */ #include #include #include -#include #include "classes.h" #include "classes_entity.h" #include "class_strings.h" @@ -26,11 +31,34 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. #include #include "rules.h" -#include +#include "./trace_fprintf.h" extern int multiple_inheritance; extern int old_accessors; +/* cross-platform mkdir */ +static int sc_mkdir( const char * path ) { + #ifdef _WIN32 + return mkdir( path ); + #else + return mkdir( path, 0777 ); + #endif /* _WIN32 */ +} + +/* return -1 if error, 0 if created, 1 if dir existed already */ +static int mkDirIfNone( const char * path ) { + struct stat s; + if( stat( path, &s ) != 0 ) { + if( errno == ENOENT ) { + return sc_mkdir( path ); + } + } else if( s.st_mode & S_IFDIR ) { + return 1; + } + /* either stat returned an error other than ENOENT, or 'path' exists but isn't a dir */ + return -1; +} + /* attribute numbering used to use a global variable attr_count. * it could be tricky keep the numbering consistent when making * changes, so this has been replaced with an added member in the @@ -676,7 +704,7 @@ char * generate_dict_attr_name( Variable a, char * out ) { } *q = '\0'; - sc_free( temp ); + free( temp ); return out; } @@ -828,7 +856,7 @@ void ENTITYincode_print( Entity entity, FILE * header, FILE * impl, Schema schem } else { /* manufacture new one(s) on the spot */ char typename_buf[MAX_LEN+1]; - print_typechain( header, impl, v->type, typename_buf, schema, v->name->symbol.name ); + print_typechain( header, impl, v->type, typename_buf, sizeof(typename_buf), schema, v->name->symbol.name ); fprintf( impl, " %s::%s%d%s%s =\n new %s" "(\"%s\",%s,%s,%s%s,\n *%s::%s%s);\n", SCHEMAget_name( schema ), ATTR_PREFIX, v->idx, @@ -864,15 +892,15 @@ void ENTITYincode_print( Entity entity, FILE * header, FILE * impl, Schema schem if( VARis_derived( v ) && v->initializer ) { tmp = EXPRto_string( v->initializer ); - tmp2 = ( char * )sc_malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) ); + tmp2 = ( char * )malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) ); fprintf( impl, " %s::%s%d%s%s->initializer_(\"%s\");\n", schema_name, ATTR_PREFIX, v->idx, ( VARis_derived( v ) ? "D" : ( VARis_type_shifter( v ) ? "R" : ( VARget_inverse( v ) ? "I" : "" ) ) ), attrnm, format_for_stringout( tmp, tmp2 ) ); - sc_free( tmp ); - sc_free( tmp2 ); + free( tmp ); + free( tmp2 ); } if( VARget_inverse( v ) ) { fprintf( impl, " %s::%s%d%s%s->inverted_attr_id_(\"%s\");\n", @@ -957,7 +985,6 @@ void ENTITYPrint_cc( const Entity entity, FILE * createall, FILE * header, FILE DEBUG( "Entering ENTITYPrint_cc for %s\n", name ); fprintf( impl, "#include \"schema.h\"\n" ); - fprintf( impl, "#include \"sc_memmgr.h\"\n" ); fprintf( impl, "#include \"entity/%s.h\"\n\n", name ); LIBdescribe_entity( entity, impl, schema ); diff --git a/src/exp2cxx/classes_misc.c b/src/exp2cxx/classes_misc.c index 8399826c5..2b492a124 100644 --- a/src/exp2cxx/classes_misc.c +++ b/src/exp2cxx/classes_misc.c @@ -1,9 +1,7 @@ #define CLASSES_MISC_C -#include #include #include "classes.h" -#include #include "class_strings.h" /** \file classes_misc.c @@ -217,7 +215,7 @@ const char * TypeDescriptorName( Type t ) { ** by following through the entity they reference, as above. */ } - sprintf( b, "%s::%s%s", SCHEMAget_name( parent ), TYPEprefix( t ), + snprintf( b, sizeof(b), "%s::%s%s", SCHEMAget_name( parent ), TYPEprefix( t ), TYPEget_name( t ) ); return b; } @@ -322,7 +320,7 @@ Entity ENTITYput_superclass( Entity entity ) { LISTod; } - tag = ( EntityTag ) sc_malloc( sizeof( struct EntityTag_ ) ); + tag = ( EntityTag ) malloc( sizeof( struct EntityTag_ ) ); tag -> superclass = super; TYPEput_clientData( ENTITYget_type( entity ), ( ClientData ) tag ); return super; @@ -386,10 +384,10 @@ Variable VARis_type_shifter( Variable a ) { temp = EXPRto_string( VARget_name( a ) ); if( ! strncmp( StrToLower( temp ), "self\\", 5 ) ) { /* a is a type shifter */ - sc_free( temp ); + free( temp ); return a; } - sc_free( temp ); + free( temp ); return 0; } diff --git a/src/exp2cxx/classes_type.c b/src/exp2cxx/classes_type.c index 5ac968207..b4abdb034 100644 --- a/src/exp2cxx/classes_type.c +++ b/src/exp2cxx/classes_type.c @@ -14,18 +14,25 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. /* this is used to add new dictionary calls */ /* #define NEWDICT */ -#include -#include +#define _XOPEN_SOURCE /* for S_IFDIR */ +#include +#include +#include +#ifdef _WIN32 +# include +#endif /* _WIN32 */ + +#include #include +#include #include -#include #include "classes.h" #include "class_strings.h" #include "genCxxFilenames.h" #include #include "rules.h" -#include +#include "./trace_fprintf.h" static int type_count; /**< number each temporary type for same reason as \sa attr_count */ @@ -36,13 +43,66 @@ static void printEnumCreateBody( FILE *, const Type ); static void printEnumAggrCrHdr( FILE *, const Type ); static void printEnumAggrCrBody( FILE *, const Type ); -int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ); +int TYPEget_RefTypeVarNm( const Type t, char * buf, size_t buflen, Schema schema ); int isMultiDimAggregateType( const Type t ); void Type_Description( const Type, char * ); void TypeBody_Description( TypeBody body, char * buf ); +/* cross-platform mkdir */ +static int sc_mkdir( const char * path ) { + #ifdef _WIN32 + return mkdir( path ); + #else + return mkdir( path, 0777 ); + #endif /* _WIN32 */ +} + +/* return -1 if error, 0 if created, 1 if dir existed already */ +static int mkDirIfNone( const char * path ) { + struct stat s; + if( stat( path, &s ) != 0 ) { + if( errno == ENOENT ) { + return sc_mkdir( path ); + } + } else if( s.st_mode & S_IFDIR ) { + return 1; + } + /* either stat returned an error other than ENOENT, or 'path' exists but isn't a dir */ + return -1; +} + +#ifdef _WIN32 +/* for windows, rewrite backslashes in paths + * that will be written to generated code + */ +static const char * path2str_fn( const char * fileMacro ) { + static char * result = 0; + static size_t rlen = 0; + char * p; + if( rlen < strlen( fileMacro ) ) { + if( result ) { + free( result ); + } + rlen = strlen( fileMacro ); + result = ( char * )malloc( rlen * sizeof( char ) + 1 ); + } + strcpy( result, fileMacro ); + p = result; + while( *p ) { + if( *p == '\\' ) { + *p = '/'; + } + p++; + } + return result; +} +# define path2str(path) path2str_fn(path) +#else +# define path2str(path) path +#endif + /** write representation of expression to end of buf * * TODO: add buflen arg and check for overflow @@ -62,7 +122,7 @@ void strcat_expr( Expression e, char * buf ) { strcat( buf, TYPEget_name( e ) ); } else if( TYPEget_body( e->type )->type == integer_ ) { char tmpbuf[30]; - sprintf( tmpbuf, "%d", e->u.integer ); + snprintf( tmpbuf, sizeof(tmpbuf), "%d", e->u.integer ); strcat( buf, tmpbuf ); } else { strcat( buf, "??" ); @@ -102,7 +162,7 @@ void strcat_bounds( TypeBody b, char * buf ) { ******************************************************************/ const char * EnumCElementName( Type type, Expression expr ) { static char buf [BUFSIZ+1]; - sprintf( buf, "%s__", + snprintf( buf, sizeof(buf), "%s__", EnumName( TYPEget_name( type ) ) ); strncat( buf, StrToLower( EXPget_name( expr ) ), BUFSIZ ); return buf; @@ -220,7 +280,7 @@ void TYPEenum_inc_print( const Type type, FILE * inc ) { /* DAS brandnew above */ /* print things for aggregate class */ - sprintf( enumAggrNm, "%s_agg", n ); + snprintf( enumAggrNm, sizeof(enumAggrNm), "%s_agg", n ); fprintf( inc, "\nclass %s_agg : public EnumAggregate {\n", n ); @@ -317,7 +377,6 @@ void TYPEPrint_cc( const Type type, const filenames_t * names, FILE * hdr, FILE DEBUG( "Entering TYPEPrint_cc for %s\n", names->impl ); fprintf( impl, "#include \"schema.h\"\n" ); - fprintf( impl, "#include \"sc_memmgr.h\"\n" ); fprintf( impl, "#include \"%s\"\n\n", names->header ); if ( TYPEis_enumeration( type ) ) { @@ -551,7 +610,7 @@ void TYPEprint_descriptions( const Type type, FILES * files, Schema schema ) { return; } - if( !TYPEget_RefTypeVarNm( type, typename_buf, schema ) ) { + if( !TYPEget_RefTypeVarNm( type, typename_buf, sizeof(typename_buf), schema ) ) { if( TYPEis_enumeration( type ) ) { TYPEPrint( type, files, schema ); } /* so we don't do anything for non-enums??? */ @@ -574,7 +633,7 @@ void TYPEprint_init( const Type type, FILE * header, FILE * impl, Schema schema /* fill in the TD's values in the SchemaInit function (it is already declared with basic values) */ - if( TYPEget_RefTypeVarNm( type, typename_buf, schema ) ) { + if( TYPEget_RefTypeVarNm( type, typename_buf, sizeof(typename_buf), schema ) ) { fprintf( impl, " %s->ReferentType(%s);\n", tdnm, typename_buf ); } else { switch( TYPEget_body( type )->type ) { @@ -585,7 +644,7 @@ void TYPEprint_init( const Type type, FILE * header, FILE * impl, Schema schema case list_: { if( isMultiDimAggregateType( type ) ) { print_typechain( header, impl, TYPEget_body( type )->base, - typename_buf, schema, type->symbol.name ); + typename_buf, sizeof(typename_buf), schema, type->symbol.name ); fprintf( impl, " %s->ReferentType(%s);\n", tdnm, typename_buf ); } @@ -634,7 +693,7 @@ void TYPEprint_new( const Type type, FILE * create, Schema schema, bool needWR ) char * temp; temp = non_unique_types_string( type ); fprintf( create, " %s = new SelectTypeDescriptor (\n ~%s, //unique elements,\n", TYPEtd_name( type ), temp ); - sc_free( temp ); + free( temp ); TYPEprint_nm_ft_desc( schema, type, create, "," ); fprintf( create, " (SelectCreator) create_%s); // Creator function\n", SelectName( TYPEget_name( type ) ) ); } else { @@ -705,7 +764,10 @@ void TYPEprint_new( const Type type, FILE * create, Schema schema, bool needWR ) Nov 2011 - MAP - modified to insert scope operator into variable name. Reason: use of namespace for global variables */ -int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ) { +int TYPEget_RefTypeVarNm( const Type t, char * buf, size_t buflen, Schema schema ) { + + if (!buf || !buflen) + return 0; /* It looks like TYPEget_head(t) is true when processing a type that refers to another type. e.g. when processing "name" in: @@ -715,7 +777,7 @@ int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ) { it refers to another Express TYPE stmt */ /* it would be a reference_ type */ /* a TypeDescriptor of the form t_ */ - sprintf( buf, "%s::%s%s", + snprintf( buf, buflen, "%s::%s%s", SCHEMAget_name( TYPEget_head( t )->superscope ), TYPEprefix( t ), TYPEget_name( TYPEget_head( t ) ) ); return 1; @@ -730,7 +792,7 @@ int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ) { case number_: /* one of the SCL builtin TypeDescriptors of the form t_STRING_TYPE, or t_REAL_TYPE */ - sprintf( buf, "%s%s", TD_PREFIX, FundamentalType( t, 0 ) ); + snprintf( buf, buflen, "%s%s", TD_PREFIX, FundamentalType( t, 0 ) ); return 1; break; @@ -741,7 +803,7 @@ int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ) { break; case entity_: - sprintf( buf, "%s", TYPEtd_name( t ) ); + snprintf( buf, buflen, "%s", TYPEtd_name( t ) ); /* following assumes we are not in a nested entity */ /* otherwise we should search upward for schema */ return 1; @@ -757,7 +819,7 @@ int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ) { if( isMultiDimAggregateType( t ) ) { if( TYPEget_name( TYPEget_body( t )->base ) ) { - sprintf( buf, "%s::%s%s", + snprintf( buf, buflen, "%s::%s%s", SCHEMAget_name( TYPEget_body( t )->base->superscope ), TYPEprefix( t ), TYPEget_name( TYPEget_body( t )->base ) ); return 1; @@ -774,19 +836,19 @@ int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ) { if( TYPEget_body( TYPEget_body( t )->base )->type == enumeration_ || TYPEget_body( TYPEget_body( t )->base )->type == select_ ) { - sprintf( buf, "%s", TYPEtd_name( TYPEget_body( t )->base ) ); + snprintf( buf, buflen, "%s", TYPEtd_name( TYPEget_body( t )->base ) ); return 1; } else if( TYPEget_name( TYPEget_body( t )->base ) ) { if( TYPEget_body( TYPEget_body( t )->base )->type == entity_ ) { - sprintf( buf, "%s", TYPEtd_name( TYPEget_body( t )->base ) ); + snprintf( buf, buflen, "%s", TYPEtd_name( TYPEget_body( t )->base ) ); return 1; } - sprintf( buf, "%s::%s%s", + snprintf( buf, buflen, "%s::%s%s", SCHEMAget_name( TYPEget_body( t )->base->superscope ), TYPEprefix( t ), TYPEget_name( TYPEget_body( t )->base ) ); return 1; } - return TYPEget_RefTypeVarNm( TYPEget_body( t )->base, buf, schema ); + return TYPEget_RefTypeVarNm( TYPEget_body( t )->base, buf, buflen, schema ); } break; default: @@ -824,7 +886,7 @@ int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ) { that can be referenced to refer to the type that was created for Type t. */ -void print_typechain( FILE * header, FILE * impl, const Type t, char * buf, Schema schema, const char * type_name ) { +void print_typechain( FILE * header, FILE * impl, const Type t, char * buf, size_t buflen, Schema schema, const char * type_name ) { /* if we've been called, current type has no name */ /* nor is it a built-in type */ /* the type_count variable is there for debugging purposes */ @@ -849,7 +911,7 @@ void print_typechain( FILE * header, FILE * impl, const Type t, char * buf, Sche " %s%d->AssignAggrCreator((AggregateCreator) create_%s);%s", TD_PREFIX, count, ctype, " // Creator function\n" ); - s = sprintf( name_buf, "%s%d", TD_PREFIX, count ); + s = snprintf( name_buf, sizeof(name_buf), "%s%d", TD_PREFIX, count ); assert( ( s > 0 ) && ( s < MAX_LEN ) ); AGGRprint_init( header, impl, t, name_buf, type_name ); @@ -872,7 +934,7 @@ void print_typechain( FILE * header, FILE * impl, const Type t, char * buf, Sche /* DAS ORIG SCHEMA FIX */ fprintf( impl, " %s%d->OriginatingSchema(%s::schema);\n", TD_PREFIX, count, SCHEMAget_name( schema ) ); - if( TYPEget_RefTypeVarNm( t, name_buf, schema ) ) { + if( TYPEget_RefTypeVarNm( t, name_buf, sizeof(name_buf), schema ) ) { fprintf( impl, " %s%d->ReferentType(%s);\n", TD_PREFIX, count, name_buf ); } else { Type base = 0; @@ -881,10 +943,10 @@ void print_typechain( FILE * header, FILE * impl, const Type t, char * buf, Sche if( TYPEget_body( t ) ) { base = TYPEget_body( t )->base; } - print_typechain( header, impl, base, callee_buffer, schema, type_name ); + print_typechain( header, impl, base, callee_buffer, sizeof(callee_buffer), schema, type_name ); fprintf( impl, " %s%d->ReferentType(%s);\n", TD_PREFIX, count, callee_buffer ); } - sprintf( buf, "%s%d", TD_PREFIX, count ); + snprintf( buf, buflen, "%s%d", TD_PREFIX, count ); /* Types */ fprintf( impl, " %s::schema->AddUnnamedType(%s%d);\n", SCHEMAget_name( schema ), TD_PREFIX, count ); @@ -1266,12 +1328,12 @@ char * TYPEget_express_type( const Type t ) { aggr_type = "Bag"; } - sprintf( retval, "%s of %s", + snprintf( retval, sizeof(retval), "%s of %s", aggr_type, TYPEget_express_type( bt ) ); /* this will declare extra memory when aggregate is > 1D */ - permval = ( char * )sc_malloc( strlen( retval ) * sizeof( char ) + 1 ); + permval = ( char * )malloc( strlen( retval ) * sizeof( char ) + 1 ); strcpy( permval, retval ); return permval; @@ -1290,7 +1352,7 @@ void AGGRprint_bound( FILE * header, FILE * impl, const char * var_name, const c if( bound->type == Type_Funcall ) { char *bound_str = EXPRto_string(bound); fprintf( impl, " %s->SetBound%dFromExpressFuncall( \"%s\" );\n", var_name, boundNr, bound_str ); - sc_free(bound_str); + free(bound_str); } else { fprintf( impl, " %s->SetBound%d( %d );\n", var_name, boundNr, bound->u.integer ); } diff --git a/src/exp2cxx/classes_type.h b/src/exp2cxx/classes_type.h index a15815b07..f2fc0370c 100644 --- a/src/exp2cxx/classes_type.h +++ b/src/exp2cxx/classes_type.h @@ -26,6 +26,6 @@ void TYPEselect_lib_print( const Type type, FILE * f ); void AGGRprint_init( FILE * header, FILE * impl, const Type t, const char * var_name, const char * aggr_name ); -void print_typechain( FILE * header, FILE * impl, const Type t, char * buf, Schema schema, const char * type_name ); +void print_typechain( FILE * header, FILE * impl, const Type t, char * buf, size_t buflen, Schema schema, const char * type_name ); #endif diff --git a/src/exp2cxx/classes_wrapper.cc b/src/exp2cxx/classes_wrapper.cc index 180067b1e..e99f27e39 100644 --- a/src/exp2cxx/classes_wrapper.cc +++ b/src/exp2cxx/classes_wrapper.cc @@ -4,9 +4,8 @@ #include "complexSupport.h" #include "class_strings.h" -#include -#include +#include "./trace_fprintf.h" /******************************************************************* ** FedEx parser output module for generating C++ class definitions @@ -76,12 +75,12 @@ void print_file_header( FILES * files ) { fprintf( files->incall, "#include \n" ); fprintf( files->incall, "#endif\n" ); - fprintf( files->incall, "#include \n\n" ); - fprintf( files->incall, "\n#include \n" ); - fprintf( files->incall, "\n#include \n" ); - fprintf( files->incall, "\n#include \n" ); - fprintf( files->incall, "\n#include \n" ); - fprintf( files->incall, "\n#include \n" ); + fprintf( files->incall, "#include \"clstepcore/sdai.h\"\n\n" ); + fprintf( files->incall, "\n#include \"clstepcore/Registry.h\"\n" ); + fprintf( files->incall, "\n#include \"clstepcore/STEPaggregate.h\"\n" ); + fprintf( files->incall, "\n#include \"clstepcore/STEPundefined.h\"\n" ); + fprintf( files->incall, "\n#include \"clstepcore/ExpDict.h\"\n" ); + fprintf( files->incall, "\n#include \"clstepcore/STEPattribute.h\"\n" ); fprintf( files->incall, "\n#include \n" ); @@ -91,7 +90,6 @@ void print_file_header( FILES * files ) { files -> initall = FILEcreate( "schema.cc" ); fprintf( files->initall, "\n// in the exp2cxx source code, this file is generally referred to as files->initall or schemainit\n" ); fprintf( files->initall, "#include \"schema.h\"\n" ); - fprintf( files->initall, "#include \"sc_memmgr.h\"\n" ); fprintf( files->initall, "class Registry;\n" ); fprintf( files->initall, "\nvoid SchemaInit (Registry & reg) {\n" ); @@ -105,7 +103,6 @@ void print_file_header( FILES * files ) { files -> create = FILEcreate( "SdaiAll.cc" ); fprintf( files->create, "\n// in the exp2cxx source code, this file is generally referred to as files->create or createall\n" ); fprintf( files->create, "#include \"schema.h\"\n" ); - fprintf( files->create, "#include \"sc_memmgr.h\"\n" ); fprintf( files->create, "\nvoid InitSchemasAndEnts (Registry & reg) {\n" ); // This file declares all entity classes as incomplete types. This will @@ -386,6 +383,7 @@ void INITFileFinish( FILE * initfile, Schema schema ) { ******************************************************************/ void SCHEMAprint( Schema schema, FILES * files, void * complexCol, int suffix ) { int ocnt = 0; + size_t remaining; char schnm[MAX_LEN+1], sufnm[MAX_LEN+1], fnm[MAX_LEN+1], *np; /* sufnm = schema name + suffix */ FILE * libfile, @@ -401,7 +399,7 @@ void SCHEMAprint( Schema schema, FILES * files, void * complexCol, int suffix ) /********** create files based on name of schema ***********/ /* return if failure */ /* 1. header file */ - sprintf( schnm, "%s%s", SCHEMA_FILE_PREFIX, StrToUpper( SCHEMAget_name( schema ) ) ); //TODO change file names to CamelCase? + snprintf( schnm, sizeof(schnm), "%s%s", SCHEMA_FILE_PREFIX, StrToUpper( SCHEMAget_name( schema ) ) ); //TODO change file names to CamelCase? if( suffix == 0 ) { ocnt = snprintf( sufnm, MAX_LEN, "%s", schnm ); if( ocnt > MAX_LEN ) { @@ -424,14 +422,14 @@ void SCHEMAprint( Schema schema, FILES * files, void * complexCol, int suffix ) fprintf( files->inc, "\n// in the exp2cxx source code, this file is generally referred to as files->inc or incfile\n" ); fprintf( incfile, "#include \"schema.h\"\n" ); - fprintf( incfile, "#include \"sc_memmgr.h\"\n" ); np = fnm + strlen( fnm ) - 1; /* point to end of constant part of string */ + remaining = (size_t)(fnm + sizeof(fnm) - np); /* 1.9 open/init unity files which allow faster compilation with fewer translation units */ initUnityFiles( sufnm, files ); /* 2. class source file */ - sprintf( np, "cc" ); + snprintf( np, remaining, "cc" ); if( !( libfile = ( files -> lib ) = FILEcreate( fnm ) ) ) { return; } @@ -440,12 +438,11 @@ void SCHEMAprint( Schema schema, FILES * files, void * complexCol, int suffix ) //TODO: Looks like this switches between 'schema.h' and a non-generic name. What is that name, //and how do we fully enable this feature (i.e. how to write the file with different name)? #ifdef SCHEMA_HANDLING - sprintf( np, "h" ); + snprintf( np, remaining, "h" ); fprintf( libfile, "#include <%s.h> \n", sufnm ); #else fprintf( libfile, "#include \"schema.h\"\n" ); #endif - fprintf( libfile, "#include \"sc_memmgr.h\"\n" ); fprintf( libfile, "\n#ifdef SC_LOGGING \n" @@ -499,8 +496,7 @@ void SCHEMAprint( Schema schema, FILES * files, void * complexCol, int suffix ) "#include \"schema.h\"\n" "#endif\n" ); #endif - fprintf( initfile, "#include \n#include \n" ); - fprintf( initfile, "#include \n" ); + fprintf( initfile, "#include \"clstepcore/Registry.h\"\n#include \n" ); fprintf( initfile, "\nvoid %sInit (Registry& reg) {\n", schnm ); @@ -629,6 +625,7 @@ void getMCPrint( Express express, FILE * schema_h, FILE * schema_cc ) { ******************************************************************/ void EXPRESSPrint( Express express, ComplexCollect & col, FILES * files ) { char fnm [MAX_LEN+1], *np; + size_t remaining; const char * schnm; /* schnm is really "express name" */ FILE * libfile; FILE * incfile; @@ -643,19 +640,20 @@ void EXPRESSPrint( Express express, ComplexCollect & col, FILES * files ) { /********** create files based on name of schema ***********/ /* return if failure */ /* 1. header file */ - sprintf( fnm, "%s.h", schnm = ClassName( EXPRESSget_basename( express ) ) ); + snprintf( fnm, sizeof(fnm), "%s.h", schnm = ClassName( EXPRESSget_basename( express ) ) ); if( !( incfile = ( files -> inc ) = FILEcreate( fnm ) ) ) { return; } fprintf( files->inc, "\n// in the exp2cxx source code, this file is generally referred to as files->inc or incfile\n" ); - fprintf( incfile, "#include \n" ); + fprintf( incfile, "#include \"core/sdai.h\" \n" ); np = fnm + strlen( fnm ) - 1; /* point to end of constant part of string */ + remaining = (size_t)(fnm + sizeof(fnm) - np); /* 1.9 init unity files (large translation units, faster compilation) */ initUnityFiles( schnm, files ); /* 2. class source file */ - sprintf( np, "cc" ); + snprintf( np, remaining, "cc" ); if( !( libfile = ( files -> lib ) = FILEcreate( fnm ) ) ) { return; } @@ -664,7 +662,7 @@ void EXPRESSPrint( Express express, ComplexCollect & col, FILES * files ) { fprintf( libfile, "#include \"%s.h\" n", schnm ); // 3. header for namespace to contain all formerly-global variables - sprintf( fnm, "%sNames.h", schnm ); + snprintf( fnm, sizeof(fnm), "%sNames.h", schnm ); if( !( files->names = FILEcreate( fnm ) ) ) { return; } @@ -676,7 +674,7 @@ void EXPRESSPrint( Express express, ComplexCollect & col, FILES * files ) { /* 4. source code to initialize entity registry */ /* prints header of file for input function */ - sprintf( np, "init.cc" ); + snprintf( np, remaining, "init.cc" ); if( !( initfile = ( files -> init ) = FILEcreate( fnm ) ) ) { return; } diff --git a/src/exp2cxx/collect.cc b/src/exp2cxx/collect.cc index d12db7346..a50b808be 100644 --- a/src/exp2cxx/collect.cc +++ b/src/exp2cxx/collect.cc @@ -12,7 +12,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include void ComplexCollect::insert( ComplexList * c ) /* diff --git a/src/exp2cxx/complexlist.cc b/src/exp2cxx/complexlist.cc index 2a42c6d96..485f0609d 100644 --- a/src/exp2cxx/complexlist.cc +++ b/src/exp2cxx/complexlist.cc @@ -11,7 +11,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include ComplexList::~ComplexList() /* diff --git a/src/exp2cxx/entlist.cc b/src/exp2cxx/entlist.cc index e27114294..bd45be671 100644 --- a/src/exp2cxx/entlist.cc +++ b/src/exp2cxx/entlist.cc @@ -14,7 +14,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include int EntList::siblings() /* diff --git a/src/exp2cxx/entnode.cc b/src/exp2cxx/entnode.cc index 50f3a8659..569dcde87 100644 --- a/src/exp2cxx/entnode.cc +++ b/src/exp2cxx/entnode.cc @@ -12,7 +12,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include EntNode::EntNode( char * namelist[] ) /* diff --git a/src/exp2cxx/expressbuild.cc b/src/exp2cxx/expressbuild.cc index 42458c31a..d55465eef 100644 --- a/src/exp2cxx/expressbuild.cc +++ b/src/exp2cxx/expressbuild.cc @@ -12,7 +12,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include // Local function prototypes: static void initEnts( Express ); diff --git a/src/exp2cxx/fedex_main.c b/src/exp2cxx/fedex_main.c index 81c6f1515..b83976daf 100644 --- a/src/exp2cxx/fedex_main.c +++ b/src/exp2cxx/fedex_main.c @@ -72,13 +72,12 @@ * Added * to typedefs. Replaced warning kludges with ERRORoption. */ -#include #include #include #include "../express/express.h" #include "../express/resolve.h" -#include +#include "./trace_fprintf.h" extern void print_fedex_version( void ); diff --git a/src/exp2cxx/genCxxFilenames.c b/src/exp2cxx/genCxxFilenames.c index 3b90d1cf2..14bee4295 100644 --- a/src/exp2cxx/genCxxFilenames.c +++ b/src/exp2cxx/genCxxFilenames.c @@ -1,11 +1,6 @@ #include "genCxxFilenames.h" #include "class_strings.h" -#if defined(_MSC_VER) && _MSC_VER < 1900 -# include "sc_stdio.h" -# define snprintf c99_snprintf -#endif - /** \file genCxxFilenames.c * functions shared by exp2cxx and the schema scanner. * The latter creates, at configuration time, a list diff --git a/src/exp2cxx/match-ors.cc b/src/exp2cxx/match-ors.cc index 1b86622e4..41d5af88c 100644 --- a/src/exp2cxx/match-ors.cc +++ b/src/exp2cxx/match-ors.cc @@ -14,7 +14,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include MatchType AndOrList::matchORs( EntNode * ents ) /* diff --git a/src/exp2cxx/multlist.cc b/src/exp2cxx/multlist.cc index fb74cf5d1..5d2cade84 100644 --- a/src/exp2cxx/multlist.cc +++ b/src/exp2cxx/multlist.cc @@ -13,7 +13,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include MultList::~MultList() /* diff --git a/src/exp2cxx/multpass.c b/src/exp2cxx/multpass.c index 5028c8246..03e1eb885 100644 --- a/src/exp2cxx/multpass.c +++ b/src/exp2cxx/multpass.c @@ -31,11 +31,10 @@ * Date: 04/09/97 * *****************************************************************************/ -#include #include #include "classes.h" -#include +#include "./trace_fprintf.h" int isAggregateType( const Type t ); @@ -160,7 +159,7 @@ void print_schemas_separate( Express express, void * complexCol, FILES * files ) // which hasn't been closed yet. (That's done on 2nd line below.)) */ fprintf( files->initall, " reg.SetCompCollect( gencomplex() );\n" ); fprintf( files->initall, "}\n\n" ); - fprintf( files->incall, "\n#include \n" ); + fprintf( files->incall, "\n#include \"clstepcore/complexSupport.h\"\n" ); fprintf( files->incall, "ComplexCollect *gencomplex();\n" ); /* Function GetModelContents() is printed at the end of the schema.xx @@ -189,7 +188,7 @@ static void initializeMarks( Express express ) DICTdo_type_init( express->symbol_table, &de_sch, OBJ_SCHEMA ); while( ( schema = ( Scope )DICTdo( &de_sch ) ) != 0 ) { schema->search_id = UNPROCESSED; - schema->clientData = ( int * )sc_malloc( sizeof( int ) ); + schema->clientData = ( int * )malloc( sizeof( int ) ); *( int * )schema->clientData = 0; SCOPEdo_entities( schema, ent, de_ent ) ent->search_id = NOTKNOWN; @@ -207,7 +206,7 @@ static void cleanupMarks( Express express ) { DICTdo_type_init( express->symbol_table, &de_sch, OBJ_SCHEMA ); while( ( schema = ( Scope )DICTdo( &de_sch ) ) != 0 ) { if( schema->clientData ) { - sc_free( schema->clientData ); + free( schema->clientData ); schema->clientData = NULL; } } diff --git a/src/exp2cxx/non-ors.cc b/src/exp2cxx/non-ors.cc index 2ef5dd803..6b05bb378 100644 --- a/src/exp2cxx/non-ors.cc +++ b/src/exp2cxx/non-ors.cc @@ -11,7 +11,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include MatchType SimpleList::matchNonORs( EntNode * ents ) /* diff --git a/src/exp2cxx/orlist.cc b/src/exp2cxx/orlist.cc index dd0c9db88..809804320 100644 --- a/src/exp2cxx/orlist.cc +++ b/src/exp2cxx/orlist.cc @@ -11,7 +11,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include int OrList::hit( const char * nm ) /* diff --git a/src/exp2cxx/print.cc b/src/exp2cxx/print.cc index 0b1398a6d..b338c5954 100644 --- a/src/exp2cxx/print.cc +++ b/src/exp2cxx/print.cc @@ -8,7 +8,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include // Local function prototypes: static char * joinText( JoinType, char * ); diff --git a/src/exp2cxx/selects.c b/src/exp2cxx/selects.c index 6377c8e80..5d975cdde 100644 --- a/src/exp2cxx/selects.c +++ b/src/exp2cxx/selects.c @@ -16,13 +16,12 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. extern int multiple_inheritance; -#include #include #include "classes.h" #include "classes_type.h" #include "classes_attribute.h" -#include +#include "./trace_fprintf.h" #define BASE_SELECT "SDAI_Select" @@ -397,7 +396,7 @@ char * non_unique_types_string( const Type type ) { non_unique_types_vector( type, tvec ); /* build type string from vector */ - typestr = ( char * )sc_malloc( BUFSIZ + 1 ); + typestr = ( char * )malloc( BUFSIZ + 1 ); typestr[0] = '\0'; strcat( typestr, ( char * )"(" ); for( i = 0; i <= tnumber; i++ ) { @@ -1866,7 +1865,7 @@ void TYPEselect_print( Type t, FILES * files, Schema schema ) { } /* mark the type as being processed */ - tag = ( SelectTag ) sc_malloc( sizeof( struct SelectTag_ ) ); + tag = ( SelectTag ) malloc( sizeof( struct SelectTag_ ) ); tag -> started = 1; tag -> complete = 0; TYPEput_clientData( t, ( ClientData ) tag ); @@ -1938,7 +1937,7 @@ void TYPEselect_print( Type t, FILES * files, Schema schema ) { DAR - moved to TYPEprint_init() - to keep init info together. */ tag -> complete = 1; - sc_free( tag ); + free( tag ); } #undef BASE_SELECT diff --git a/src/base/sc_trace_fprintf.c b/src/exp2cxx/trace_fprintf.c similarity index 92% rename from src/base/sc_trace_fprintf.c rename to src/exp2cxx/trace_fprintf.c index 95ca6b9c6..3a3838d67 100644 --- a/src/base/sc_trace_fprintf.c +++ b/src/exp2cxx/trace_fprintf.c @@ -1,8 +1,7 @@ - #include #include -#include "sc_trace_fprintf.h" +#include "trace_fprintf.h" void trace_fprintf( char const * sourcefile, int line, FILE * file, const char * format, ... ) { va_list args; diff --git a/src/base/sc_trace_fprintf.h b/src/exp2cxx/trace_fprintf.h similarity index 85% rename from src/base/sc_trace_fprintf.h rename to src/exp2cxx/trace_fprintf.h index b7aa05fa2..9e5c2f073 100644 --- a/src/base/sc_trace_fprintf.h +++ b/src/exp2cxx/trace_fprintf.h @@ -1,7 +1,7 @@ #ifndef SC_TRACE_FPRINTF_H #define SC_TRACE_FPRINTF_H -/** \file sc_trace_fprintf.h +/** \file trace_fprintf.h * Used to track the source file and line where generated code is printed from * When enabled, comments are printed into the generated files for every 'fprintf': * / * source: scl/src/exp2cxx/selects.c:1375 * / @@ -20,7 +20,7 @@ extern "C" { /** Used to find where generated c++ originates from in exp2cxx. * To enable, configure with 'cmake .. -DSC_TRACE_FPRINTF=ON' */ - SC_BASE_EXPORT void trace_fprintf( char const * sourcefile, int line, FILE * file, const char * format, ... ); + void trace_fprintf( char const * sourcefile, int line, FILE * file, const char * format, ... ); #ifdef __cplusplus } #endif diff --git a/src/exp2cxx/trynext.cc b/src/exp2cxx/trynext.cc index 97cacc8a3..e2c0a0edf 100644 --- a/src/exp2cxx/trynext.cc +++ b/src/exp2cxx/trynext.cc @@ -12,7 +12,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include // Local function prototypes: static EntList * firstCandidate( EntList * ); diff --git a/src/exp2cxx/write.cc b/src/exp2cxx/write.cc index 964aca652..da1ecb747 100644 --- a/src/exp2cxx/write.cc +++ b/src/exp2cxx/write.cc @@ -11,7 +11,6 @@ *****************************************************************************/ #include "complexSupport.h" -#include // Local function prototypes: static void writeheader( ostream &, int ); @@ -117,7 +116,7 @@ static void writeheader( ostream & os, int noLists ) << " * file, however, there are no complex entities, so this\n" << " * function is a stub.\n" << " */" << endl << endl; - os << "#include \"complexSupport.h\"\n#include \"sc_memmgr.h\"\n\n"; + os << "#include \"clstepcore/complexSupport.h\"\n\n"; os << "ComplexCollect *gencomplex()" << endl; os << "{" << endl; return; @@ -129,7 +128,7 @@ static void writeheader( ostream & os, int noLists ) << " * support structures. The structures will be used in the SCL to\n" << " * validate user requests to instantiate complex entities.\n" << " */" << endl << endl; - os << "#include \"complexSupport.h\"\n#include \"sc_memmgr.h\"\n\n"; + os << "#include \"clstepcore/complexSupport.h\"\n\n"; os << "ComplexCollect *gencomplex()" << endl; os << " /*" << endl << " * This function contains instantiation statements for all the\n" diff --git a/src/exp2python/CMakeLists.txt b/src/exp2python/CMakeLists.txt index a9feb39d2..1395e75a6 100644 --- a/src/exp2python/CMakeLists.txt +++ b/src/exp2python/CMakeLists.txt @@ -3,7 +3,6 @@ if(SC_PYTHON_GENERATOR) include_directories( ${SC_SOURCE_DIR}/include ${SC_SOURCE_DIR}/include/express - ${SC_SOURCE_DIR}/src/base ) add_definitions(-DHAVE_CONFIG_H) @@ -29,7 +28,11 @@ if(SC_PYTHON_GENERATOR) ../exp2cxx/write.cc ../exp2cxx/print.cc ) - SC_ADDEXEC(exp2python SOURCES ${exp2python_SOURCES} LINK_LIBRARIES express base) + if(BUILD_SHARED_LIBS) + SC_ADDEXEC(exp2python SOURCES ${exp2python_SOURCES} LINK_LIBRARIES express) + else() + SC_ADDEXEC(exp2python SOURCES ${exp2python_SOURCES} LINK_LIBRARIES express-static) + endif() endif(SC_PYTHON_GENERATOR) diff --git a/src/exp2python/python/LICENSE b/src/exp2python/python/LICENSE index 80934a9d5..6e4fe3b3b 100644 --- a/src/exp2python/python/LICENSE +++ b/src/exp2python/python/LICENSE @@ -4,7 +4,7 @@ # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/README.md b/src/exp2python/python/README.md index 470e626a3..20278a512 100644 --- a/src/exp2python/python/README.md +++ b/src/exp2python/python/README.md @@ -1,21 +1,21 @@ -# SCL - A Python3 STEP Class Library +# stepcode - A Python3 STEP Library -SCL is a Python3-based library for parsing and manipulating ISO 10303 Part 21 ("STEP") files. +STEPCODE Python is a Python3-based library for parsing and manipulating ISO 10303 Part 21 ("STEP") files. # Use -To parse a ISO 10303 Part 21 file, use the `Parser` class of `SCL.Part21`. On a successful parse, the result will be a Part 21 parse tree and associated STEP instances. +To parse a ISO 10303 Part 21 file, use the `Parser` class of `stepcode.Part21`. On a successful parse, the result will be a Part 21 parse tree and associated STEP instances. -See [test_parser](tests/test_parser.py) for use of the `SCL.Part21` parser with a sample STEP file. +See [test_parser](tests/test_parser.py) for use of the `stepcode.Part21` parser with a sample STEP file. # Building -The SCL Python package can be built directly using [PyPA's build module](https://github.com/pypa/build). Run `python3 -m build` from this directory. +The stepcode Python package can be built directly using [PyPA's build module](https://github.com/pypa/build). Run `python3 -m build` from this directory. # Testing -SCL comes with a small test suite (additions welcome!) From this directory, `python3 -m unittest discover`. +STEPCODE Python comes with a small test suite (additions welcome!) From this directory, `python3 -m unittest discover`. # License diff --git a/src/exp2python/python/setup.cfg b/src/exp2python/python/setup.cfg index ef47b03e0..3a05fbf27 100644 --- a/src/exp2python/python/setup.cfg +++ b/src/exp2python/python/setup.cfg @@ -1,8 +1,8 @@ [metadata] -name = SCL -version = 0.6.1 +name = stepcode +version = 0.7.0 author = Thomas Paviot , Christopher HORLER (cshorler@googlemail.com), Devon Sparks (devonsparks.com) -description = SCL is a Python3-based library for parsing and manipulating ISO 10303 Part 21 ("STEP") files. +description = stepcode is a Python3-based library for parsing and manipulating ISO 10303 Part 21 ("STEP") files. long_description = file: README.md long_description_content_type = text/markdown @@ -15,7 +15,7 @@ classifiers = [options] package_dir = =. -packages = SCL +packages = stepcode python_requires = >=3.6 install_requires = ply diff --git a/src/exp2python/python/SCL/AggregationDataTypes.py b/src/exp2python/python/stepcode/AggregationDataTypes.py similarity index 99% rename from src/exp2python/python/SCL/AggregationDataTypes.py rename to src/exp2python/python/stepcode/AggregationDataTypes.py index 5ed1409ab..9dfd1b1a0 100644 --- a/src/exp2python/python/SCL/AggregationDataTypes.py +++ b/src/exp2python/python/stepcode/AggregationDataTypes.py @@ -1,7 +1,7 @@ # Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/BaseType.py b/src/exp2python/python/stepcode/BaseType.py similarity index 98% rename from src/exp2python/python/SCL/BaseType.py rename to src/exp2python/python/stepcode/BaseType.py index 93b931de2..64bf779f2 100644 --- a/src/exp2python/python/SCL/BaseType.py +++ b/src/exp2python/python/stepcode/BaseType.py @@ -1,7 +1,7 @@ # Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/Builtin.py b/src/exp2python/python/stepcode/Builtin.py similarity index 99% rename from src/exp2python/python/SCL/Builtin.py rename to src/exp2python/python/stepcode/Builtin.py index fb2910a2f..0d71466a1 100644 --- a/src/exp2python/python/SCL/Builtin.py +++ b/src/exp2python/python/stepcode/Builtin.py @@ -1,7 +1,7 @@ # Copyright (c) 2011-2012, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/ConstructedDataTypes.py b/src/exp2python/python/stepcode/ConstructedDataTypes.py similarity index 98% rename from src/exp2python/python/SCL/ConstructedDataTypes.py rename to src/exp2python/python/stepcode/ConstructedDataTypes.py index 0e9393333..9b9d8bc5e 100644 --- a/src/exp2python/python/SCL/ConstructedDataTypes.py +++ b/src/exp2python/python/stepcode/ConstructedDataTypes.py @@ -1,7 +1,7 @@ # Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/Model.py b/src/exp2python/python/stepcode/Model.py similarity index 97% rename from src/exp2python/python/SCL/Model.py rename to src/exp2python/python/stepcode/Model.py index 036a435da..0a2d20aca 100644 --- a/src/exp2python/python/SCL/Model.py +++ b/src/exp2python/python/stepcode/Model.py @@ -1,7 +1,7 @@ # Copyright (c) 2011-2012, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/Part21.py b/src/exp2python/python/stepcode/Part21.py similarity index 99% rename from src/exp2python/python/SCL/Part21.py rename to src/exp2python/python/stepcode/Part21.py index f2e70a3ba..8c8be8fef 100644 --- a/src/exp2python/python/SCL/Part21.py +++ b/src/exp2python/python/stepcode/Part21.py @@ -6,7 +6,7 @@ # # All rights reserved. # -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/Rules.py b/src/exp2python/python/stepcode/Rules.py similarity index 97% rename from src/exp2python/python/SCL/Rules.py rename to src/exp2python/python/stepcode/Rules.py index 1b94f6e0b..4c01e15a0 100644 --- a/src/exp2python/python/SCL/Rules.py +++ b/src/exp2python/python/stepcode/Rules.py @@ -1,7 +1,7 @@ # Copyright (c) 2011-2012, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/SCLBase.py b/src/exp2python/python/stepcode/SCLBase.py similarity index 97% rename from src/exp2python/python/SCL/SCLBase.py rename to src/exp2python/python/stepcode/SCLBase.py index ff8413e8b..aebc880f3 100644 --- a/src/exp2python/python/SCL/SCLBase.py +++ b/src/exp2python/python/stepcode/SCLBase.py @@ -2,7 +2,7 @@ # Copyright (c) 2022, Chris Horler (cshorler@googlemail.com) # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/SimpleDataTypes.py b/src/exp2python/python/stepcode/SimpleDataTypes.py similarity index 99% rename from src/exp2python/python/SCL/SimpleDataTypes.py rename to src/exp2python/python/stepcode/SimpleDataTypes.py index 3cd28cbc2..4e1d0a508 100644 --- a/src/exp2python/python/SCL/SimpleDataTypes.py +++ b/src/exp2python/python/stepcode/SimpleDataTypes.py @@ -1,7 +1,7 @@ # Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/TypeChecker.py b/src/exp2python/python/stepcode/TypeChecker.py similarity index 99% rename from src/exp2python/python/SCL/TypeChecker.py rename to src/exp2python/python/stepcode/TypeChecker.py index 0a77716fb..c97d7c11f 100644 --- a/src/exp2python/python/SCL/TypeChecker.py +++ b/src/exp2python/python/stepcode/TypeChecker.py @@ -1,7 +1,7 @@ # Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/Utils.py b/src/exp2python/python/stepcode/Utils.py similarity index 98% rename from src/exp2python/python/SCL/Utils.py rename to src/exp2python/python/stepcode/Utils.py index 73b789cc9..76e352fc3 100644 --- a/src/exp2python/python/SCL/Utils.py +++ b/src/exp2python/python/stepcode/Utils.py @@ -3,7 +3,7 @@ # All rights reserved. -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/__init__.py b/src/exp2python/python/stepcode/__init__.py similarity index 100% rename from src/exp2python/python/SCL/__init__.py rename to src/exp2python/python/stepcode/__init__.py diff --git a/src/exp2python/python/SCL/_cPart21.c b/src/exp2python/python/stepcode/_cPart21.c similarity index 99% rename from src/exp2python/python/SCL/_cPart21.c rename to src/exp2python/python/stepcode/_cPart21.c index 1bdcfa24a..2b93ac7ca 100644 --- a/src/exp2python/python/SCL/_cPart21.c +++ b/src/exp2python/python/stepcode/_cPart21.c @@ -6,7 +6,7 @@ * * All rights reserved. * - * This file is part of the StepClassLibrary (SCL). + * This file is part of the STEPCODE project. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/_cPart21.l b/src/exp2python/python/stepcode/_cPart21.l similarity index 99% rename from src/exp2python/python/SCL/_cPart21.l rename to src/exp2python/python/stepcode/_cPart21.l index 25cced1ba..2a8ded85a 100644 --- a/src/exp2python/python/SCL/_cPart21.l +++ b/src/exp2python/python/stepcode/_cPart21.l @@ -5,7 +5,7 @@ * * All rights reserved. * - * This file is part of the StepClassLibrary (SCL). + * This file is part of the STEPCODE project. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/cPart21.py b/src/exp2python/python/stepcode/cPart21.py similarity index 99% rename from src/exp2python/python/SCL/cPart21.py rename to src/exp2python/python/stepcode/cPart21.py index 94eeedc61..6e4b9a697 100644 --- a/src/exp2python/python/SCL/cPart21.py +++ b/src/exp2python/python/stepcode/cPart21.py @@ -5,7 +5,7 @@ # # All rights reserved. # -# This file is part of the StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/SCL/essa_par.py b/src/exp2python/python/stepcode/essa_par.py similarity index 100% rename from src/exp2python/python/SCL/essa_par.py rename to src/exp2python/python/stepcode/essa_par.py diff --git a/src/exp2python/python/SCL/p21sql.c b/src/exp2python/python/stepcode/p21sql.c similarity index 100% rename from src/exp2python/python/SCL/p21sql.c rename to src/exp2python/python/stepcode/p21sql.c diff --git a/src/exp2python/python/SCL/p21sql.l b/src/exp2python/python/stepcode/p21sql.l similarity index 100% rename from src/exp2python/python/SCL/p21sql.l rename to src/exp2python/python/stepcode/p21sql.l diff --git a/src/exp2python/python/tests/test_SCL.py b/src/exp2python/python/tests/test_SCL.py index 0c3e8703f..9759980c0 100644 --- a/src/exp2python/python/tests/test_SCL.py +++ b/src/exp2python/python/tests/test_SCL.py @@ -1,7 +1,7 @@ # Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/src/exp2python/python/tests/test_base.py b/src/exp2python/python/tests/test_base.py index fb3ea6e2d..deb9c7301 100644 --- a/src/exp2python/python/tests/test_base.py +++ b/src/exp2python/python/tests/test_base.py @@ -1,7 +1,7 @@ # Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -32,10 +32,10 @@ import sys import unittest -from SCL.SimpleDataTypes import * -from SCL.TypeChecker import * -from SCL.ConstructedDataTypes import * -from SCL.AggregationDataTypes import * +from stepcode.SimpleDataTypes import * +from stepcode.TypeChecker import * +from stepcode.ConstructedDataTypes import * +from stepcode.AggregationDataTypes import * # # Simple data types diff --git a/src/exp2python/python/tests/test_builtin.py b/src/exp2python/python/tests/test_builtin.py index 983c01610..1a6fa5c73 100644 --- a/src/exp2python/python/tests/test_builtin.py +++ b/src/exp2python/python/tests/test_builtin.py @@ -1,7 +1,7 @@ # Copyright (c) 2011-2012, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -32,11 +32,11 @@ import sys import unittest -from SCL.SimpleDataTypes import * -from SCL.TypeChecker import * -from SCL.ConstructedDataTypes import * -from SCL.AggregationDataTypes import * -from SCL.Builtin import * +from stepcode.SimpleDataTypes import * +from stepcode.TypeChecker import * +from stepcode.ConstructedDataTypes import * +from stepcode.AggregationDataTypes import * +from stepcode.Builtin import * float_epsilon = 1e-8 # diff --git a/src/exp2python/python/tests/test_parser.py b/src/exp2python/python/tests/test_parser.py index 20344d787..b17470b47 100644 --- a/src/exp2python/python/tests/test_parser.py +++ b/src/exp2python/python/tests/test_parser.py @@ -1,7 +1,7 @@ # Copyright (c) 2021, Devon Sparks (devonsparks.com) # All rights reserved. -# This file is part StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -30,7 +30,7 @@ # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import unittest -from SCL.Part21 import Parser +from stepcode.Part21 import Parser ShapesSample =""" ISO-10303-21; diff --git a/src/exp2python/python/tests/test_unitary_schemas.py b/src/exp2python/python/tests/test_unitary_schemas.py index 66b2a7d25..077644253 100644 --- a/src/exp2python/python/tests/test_unitary_schemas.py +++ b/src/exp2python/python/tests/test_unitary_schemas.py @@ -1,7 +1,7 @@ # Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) # All rights reserved. -# This file is part StepClassLibrary (SCL). +# This file is part of the STEPCODE project. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -36,11 +36,11 @@ here = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(here, "..", "..", "examples", "unitary_schemas")) -from SCL.SCLBase import * -from SCL.SimpleDataTypes import * -from SCL.ConstructedDataTypes import * -from SCL.AggregationDataTypes import * -from SCL.TypeChecker import check_type +from stepcode.SCLBase import * +from stepcode.SimpleDataTypes import * +from stepcode.ConstructedDataTypes import * +from stepcode.AggregationDataTypes import * +from stepcode.TypeChecker import check_type class TestSelectDataType(unittest.TestCase): ''' diff --git a/src/exp2python/src/classes_misc_python.c b/src/exp2python/src/classes_misc_python.c index 5a34c5fa7..7c57c5257 100644 --- a/src/exp2python/src/classes_misc_python.c +++ b/src/exp2python/src/classes_misc_python.c @@ -1,5 +1,7 @@ #define CLASSES_MISC_C +#define _POSIX_C_SOURCE 200809L #include +#include #include "classes.h" /******************************************************************* ** FedEx parser output module for generating C++ class definitions @@ -345,7 +347,7 @@ const char * TypeDescriptorName( Type t ) { ** by following through the entity they reference, as above. */ } - sprintf( b, "%s%s%s", SCHEMAget_name( parent ), TYPEprefix( t ), + snprintf( b, sizeof(b), "%s%s%s", SCHEMAget_name( parent ), TYPEprefix( t ), TYPEget_name( t ) ); return b; } diff --git a/src/exp2python/src/classes_python.c b/src/exp2python/src/classes_python.c index b844985e3..74001dfcd 100644 --- a/src/exp2python/src/classes_python.c +++ b/src/exp2python/src/classes_python.c @@ -24,10 +24,11 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. /* this is used to add new dictionary calls */ /* #define NEWDICT */ +#define _POSIX_C_SOURCE 200809L #include +#include #include -#include "sc_memmgr.h" #include "classes.h" #include "expr.h" @@ -44,11 +45,6 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. #define PAD 1 #define NOPAD 0 -#if defined(_MSC_VER) && _MSC_VER < 1900 -# include "sc_stdio.h" -# define snprintf c99_snprintf -#endif - int isAggregateType( const Type t ); int isAggregate( Variable a ); Variable VARis_type_shifter( Variable a ); @@ -368,7 +364,7 @@ char* EXPRto_python( Expression e ) { char * temp; unsigned int bufsize = BIGBUFSIZ; - buf = ( char * )sc_malloc( bufsize ); + buf = ( char * )malloc( bufsize ); if( !buf ) { fprintf( stderr, "%s failed to allocate buffer: %s\n", __func__, strerror( errno ) ); abort(); @@ -465,7 +461,7 @@ char* EXPRto_python( Expression e ) { abort(); } - temp = ( char * )sc_realloc( buf, 1 + strlen(buf) ); + temp = ( char * )realloc( buf, 1 + strlen(buf) ); if( temp == 0 ) { fprintf( stderr, "%s failed to realloc buffer: %s\n", __func__, strerror( errno ) ); abort(); @@ -1774,7 +1770,7 @@ void strcat_expr( Expression e, char * buf ) { strcat( buf, TYPEget_name( e ) ); } else if( TYPEget_body( e->type )->type == integer_ ) { char tmpbuf[30]; - sprintf( tmpbuf, "%d", e->u.integer ); + snprintf( tmpbuf, sizeof(tmpbuf), "%d", e->u.integer ); strcat( buf, tmpbuf ); } else { strcat( buf, "??" ); diff --git a/src/exp2python/src/classes_wrapper_python.cc b/src/exp2python/src/classes_wrapper_python.cc index c6842ba44..266f650e7 100644 --- a/src/exp2python/src/classes_wrapper_python.cc +++ b/src/exp2python/src/classes_wrapper_python.cc @@ -170,9 +170,9 @@ void SCHEMAprint( Schema schema, FILES * files, int suffix ) { /********** create files based on name of schema ***********/ /* return if failure */ /* 1. header file */ - sprintf( schnm, "%s", SCHEMAget_name( schema ) ); + snprintf( schnm, sizeof(schnm), "%s", SCHEMAget_name( schema ) ); if( suffix == 0 ) { - sprintf( sufnm, "%s", schnm ); + snprintf( sufnm, sizeof(sufnm), "%s", schnm ); } else { ocnt = snprintf( sufnm, MAX_LEN, "%s_%d", schnm, suffix ); if( ocnt > MAX_LEN ) { @@ -185,9 +185,10 @@ void SCHEMAprint( Schema schema, FILES * files, int suffix ) { } np = fnm + strlen( fnm ) - 1; /* point to end of constant part of string */ + size_t remaining = (size_t)(fnm + sizeof(fnm) - np); /* 2. class source file */ - sprintf( np, "py" ); + snprintf( np, remaining, "py" ); if( !( libfile = ( files -> lib ) = FILEcreate( fnm ) ) ) { return; } @@ -296,10 +297,11 @@ EXPRESSPrint( Express express, FILES * files ) { /********** create files based on name of schema ***********/ /* return if failure */ /* 1. header file */ - sprintf( fnm, "%s.h", schnm = ClassName( EXPRESSget_basename( express ) ) ); + snprintf( fnm, sizeof(fnm), "%s.h", schnm = ClassName( EXPRESSget_basename( express ) ) ); /* 2. class source file */ - //sprintf( np, "cc" ); + //size_t remaining = (size_t)(fnm + sizeof(fnm) - np); + //snprintf( np, remaining, "cc" ); if( !( libfile = ( files -> lib ) = FILEcreate( fnm ) ) ) { return; } diff --git a/src/exp2python/src/multpass_python.c b/src/exp2python/src/multpass_python.c index bbc8a6611..a4204c1c8 100644 --- a/src/exp2python/src/multpass_python.c +++ b/src/exp2python/src/multpass_python.c @@ -150,7 +150,7 @@ void print_schemas_separate( Express express, FILES * files ) // which hasn't been closed yet. (That's done on 2nd line below.)) * / //fprintf( files->initall, "\t reg.SetCompCollect( gencomplex() );\n" ); //fprintf( files->initall, "}\n\n" ); - //fprintf( files->incall, "\n#include \n" ); + //fprintf( files->incall, "\n#include \"core/complexSupport.h\"\n" ); //fprintf( files->incall, "ComplexCollect *gencomplex();\n" ); */ /* Function GetModelContents() is printed at the end of the schema.xx diff --git a/src/exppp/CMakeLists.txt b/src/exppp/CMakeLists.txt index 0d1fb9649..7b8d87c51 100644 --- a/src/exppp/CMakeLists.txt +++ b/src/exppp/CMakeLists.txt @@ -3,7 +3,7 @@ set(LIBEXPPP_SOURCES pretty_alg.c pretty_case.c pretty_entity.c - pretty_expr.c + pretty_expr.cc pretty_express.c pretty_func.c pretty_loop.c @@ -26,12 +26,11 @@ SET(EXPPP_SOURCES include_directories( ${SC_SOURCE_DIR}/include ${SC_SOURCE_DIR}/include/exppp - ${SC_SOURCE_DIR}/src/base ${SC_SOURCE_DIR}/src/express ) if(BUILD_SHARED_LIBS) - SC_ADDLIB(libexppp SHARED SOURCES ${LIBEXPPP_SOURCES} LINK_LIBRARIES express base) + SC_ADDLIB(libexppp SHARED SOURCES ${LIBEXPPP_SOURCES} LINK_LIBRARIES express) set_target_properties(libexppp PROPERTIES PREFIX "") if(WIN32) target_compile_definitions(libexppp PRIVATE SC_EXPPP_DLL_EXPORTS) @@ -39,11 +38,15 @@ if(BUILD_SHARED_LIBS) endif() if(BUILD_STATIC_LIBS) - SC_ADDLIB(libexppp-static STATIC SOURCES ${LIBEXPPP_SOURCES} LINK_LIBRARIES express-static base-static) + SC_ADDLIB(libexppp-static STATIC SOURCES ${LIBEXPPP_SOURCES} LINK_LIBRARIES express-static) set_target_properties(libexppp-static PROPERTIES PREFIX "") endif() -SC_ADDEXEC(exppp SOURCES ${EXPPP_SOURCES} LINK_LIBRARIES libexppp express base) +if(BUILD_SHARED_LIBS) + SC_ADDEXEC(exppp SOURCES ${EXPPP_SOURCES} LINK_LIBRARIES libexppp express) +else() + SC_ADDEXEC(exppp SOURCES ${EXPPP_SOURCES} LINK_LIBRARIES libexppp-static express-static) +endif() if(SC_ENABLE_TESTING) add_subdirectory(test) diff --git a/src/exppp/exppp.c b/src/exppp/exppp.c index 70ba63d7f..dd236066a 100644 --- a/src/exppp/exppp.c +++ b/src/exppp/exppp.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -13,12 +12,6 @@ #include "pp.h" #include "exppp.h" - -#if defined(_MSC_VER) && _MSC_VER < 1900 -# include "sc_stdio.h" -# define snprintf c99_snprintf -#endif - /* PP_SMALL_BUF_SZ is a macro used in a few places where const int causes * "warning: ISO C90 forbids variable length array 'buf' [-Wvla]" * @@ -161,7 +154,7 @@ void wrap( const char * fmt, ... ) { || ( ( exppp_linelength == indent2 ) && ( curpos > indent2 ) ) ) { /* move to new continuation line */ char line[1000]; - sprintf( line, "\n%*s", indent2, "" ); + snprintf( line, sizeof(line), "\n%*s", indent2, "" ); exp_output( line, 1 + indent2 ); curpos = indent2; /* reset current position */ @@ -435,7 +428,7 @@ int prep_string() { } string_func_in_use = true; - exppp_buf = exppp_bufp = ( char * )sc_malloc( BIGBUFSIZ + 1 ); + exppp_buf = exppp_bufp = ( char * )malloc( BIGBUFSIZ + 1 ); if( !exppp_buf ) { fprintf( stderr, "failed to allocate exppp buffer\n" ); return 1; @@ -453,7 +446,7 @@ int prep_string() { } char * finish_string() { - char * b = ( char * )sc_realloc( exppp_buf, 1 + exppp_maxbuflen - exppp_buflen ); + char * b = ( char * )realloc( exppp_buf, 1 + exppp_maxbuflen - exppp_buflen ); if( b == 0 ) { fprintf( stderr, "failed to reallocate exppp buffer\n" ); diff --git a/src/exppp/pretty_expr.c b/src/exppp/pretty_expr.cc similarity index 77% rename from src/exppp/pretty_expr.c rename to src/exppp/pretty_expr.cc index 1b9aeda7b..2db7267b0 100644 --- a/src/exppp/pretty_expr.c +++ b/src/exppp/pretty_expr.cc @@ -7,11 +7,16 @@ #include #include +#include +#include +#include + +extern "C" { #include "exppp.h" #include "pp.h" #include "pretty_expr.h" - +} /** print array bounds */ void EXPRbounds_out( TypeBody tb ) { @@ -224,7 +229,7 @@ void EXPRop__out( struct Op_Subexpression * oe, int paren, unsigned int previous } } -void EXPRop2__out( struct Op_Subexpression * eo, char * opcode, int paren, int pad, unsigned int previous_op ) { +void EXPRop2__out( struct Op_Subexpression * eo, const char * opcode, int paren, int pad, unsigned int previous_op ) { if( pad && paren && ( eo->op_code != previous_op ) ) { wrap( "( " ); } @@ -245,7 +250,7 @@ void EXPRop2__out( struct Op_Subexpression * eo, char * opcode, int paren, int p /** Print out a one-operand operation. If there were more than two of these * I'd generalize it to do padding, but it's not worth it. */ -void EXPRop1_out( struct Op_Subexpression * eo, char * opcode, int paren ) { +void EXPRop1_out( struct Op_Subexpression * eo, const char * opcode, int paren ) { if( paren ) { wrap( "( " ); } @@ -268,89 +273,124 @@ int EXPRop_length( struct Op_Subexpression * oe ) { return 0; } -/** returns printable representation of expression rather than printing it - * originally only used for general references, now being expanded to handle - * any kind of expression - * contains fragment of string, adds to it - */ -void EXPRstring( char * buffer, Expression e ) { +/* ---- C++ string-based builder (replaces unsafe EXPRstring/EXPRop_string) ---- */ + +static void appendf( std::string & out, const char * fmt, ... ) { + va_list ap; + va_start( ap, fmt ); + + va_list ap2; + va_copy( ap2, ap ); + + int n = std::vsnprintf( NULL, 0, fmt, ap ); + va_end( ap ); + + if( n > 0 ) { + size_t old = out.size(); + out.resize( old + ( size_t )n ); + std::vsnprintf( &out[0] + old, ( size_t )n + 1, fmt, ap2 ); + } + + va_end( ap2 ); +} + +static void EXPRstring_cpp( std::string & out, Expression e ); + +static void EXPRop_string_cpp( std::string & out, struct Op_Subexpression * oe ) { + EXPRstring_cpp( out, oe->op1 ); + switch( oe->op_code ) { + case OP_DOT: + out.push_back( '.' ); + break; + case OP_GROUP: + out.push_back( '\\' ); + break; + default: + out.append( "(* unknown op-expression *)" ); + } + EXPRstring_cpp( out, oe->op2 ); +} + +static void EXPRstring_cpp( std::string & out, Expression e ) { int i; switch( TYPEis( e->type ) ) { case integer_: if( e == LITERAL_INFINITY ) { - strcpy( buffer, "?" ); + out.append( "?" ); } else { - sprintf( buffer, "%d", e->u.integer ); + appendf( out, "%d", e->u.integer ); } break; case real_: if( e == LITERAL_PI ) { - strcpy( buffer, "PI" ); + out.append( "PI" ); } else if( e == LITERAL_E ) { - strcpy( buffer, "E" ); + out.append( "E" ); } else { - sprintf( buffer, "%s", real2exp( e->u.real ) ); + appendf( out, "%s", real2exp( e->u.real ) ); } break; case binary_: - sprintf( buffer, "%%%s", e->u.binary ); /* put "%" back */ + appendf( out, "%%%s", e->u.binary ); /* put "%" back */ break; case logical_: case boolean_: switch( e->u.logical ) { case Ltrue: - strcpy( buffer, "TRUE" ); + out.append( "TRUE" ); break; case Lfalse: - strcpy( buffer, "FALSE" ); + out.append( "FALSE" ); break; default: - strcpy( buffer, "UNKNOWN" ); + out.append( "UNKNOWN" ); break; } break; case string_: if( TYPEis_encoded( e->type ) ) { - sprintf( buffer, "\"%s\"", e->symbol.name ); + appendf( out, "\"%s\"", e->symbol.name ); } else { - sprintf( buffer, "%s", e->symbol.name ); + appendf( out, "%s", e->symbol.name ); } break; case entity_: case identifier_: case attribute_: case enumeration_: - strcpy( buffer, e->symbol.name ); + if( e->symbol.name ) { + out.append( e->symbol.name ); + } break; case query_: - sprintf( buffer, "QUERY ( %s <* ", e->u.query->local->name->symbol.name ); - EXPRstring( buffer + strlen( buffer ), e->u.query->aggregate ); - strcat( buffer, " | " ); - EXPRstring( buffer + strlen( buffer ), e->u.query->expression ); - strcat( buffer, " )" ); + appendf( out, "QUERY ( %s <* ", e->u.query->local->name->symbol.name ); + EXPRstring_cpp( out, e->u.query->aggregate ); + out.append( " | " ); + EXPRstring_cpp( out, e->u.query->expression ); + out.append( " )" ); break; case self_: - strcpy( buffer, "SELF" ); + out.append( "SELF" ); break; case funcall_: - sprintf( buffer, "%s( ", e->symbol.name ); + appendf( out, "%s( ", e->symbol.name ); i = 0; LISTdo( e->u.funcall.list, arg, Expression ) i++; if( i != 1 ) { - strcat( buffer, ", " ); + out.append( ", " ); } - EXPRstring( buffer + strlen( buffer ), arg ); + EXPRstring_cpp( out, arg ); LISTod - strcat( buffer, " )" ); + out.append( " )" ); break; case op_: - EXPRop_string( buffer, &e->e ); + EXPRop_string_cpp( out, &e->e ); break; case aggregate_: - strcpy( buffer, "[" ); + out.append( "[" ); i = 0; LISTdo( e->u.list, arg, Expression ) { bool repeat = arg->type->u.type->body->flags.repeat; @@ -358,48 +398,33 @@ void EXPRstring( char * buffer, Expression e ) { i++; if( i != 1 ) { if( repeat ) { - strcat( buffer, " : " ); + out.append( " : " ); } else { - strcat( buffer, ", " ); + out.append( ", " ); } } - EXPRstring( buffer + strlen( buffer ), arg ); + EXPRstring_cpp( out, arg ); } LISTod - strcat( buffer, "]" ); + out.append( "]" ); break; case oneof_: - strcpy( buffer, "ONEOF ( " ); + out.append( "ONEOF ( " ); i = 0; LISTdo( e->u.list, arg, Expression ) { i++; if( i != 1 ) { - strcat( buffer, ", " ); + out.append( ", " ); } - EXPRstring( buffer + strlen( buffer ), arg ); + EXPRstring_cpp( out, arg ); } LISTod - strcat( buffer, " )" ); - break; - default: - sprintf( buffer, "EXPRstring: unknown expression, type %d", TYPEis( e->type ) ); - fprintf( stderr, "%s", buffer ); - } -} - -void EXPRop_string( char * buffer, struct Op_Subexpression * oe ) { - EXPRstring( buffer, oe->op1 ); - switch( oe->op_code ) { - case OP_DOT: - strcat( buffer, "." ); - break; - case OP_GROUP: - strcat( buffer, "\\" ); + out.append( " )" ); break; default: - strcat( buffer, "(* unknown op-expression *)" ); + appendf( out, "EXPRstring: unknown expression, type %d", TYPEis( e->type ) ); + fprintf( stderr, "%s", out.c_str() ); } - EXPRstring( buffer + strlen( buffer ), oe->op2 ); } /** returns length of printable representation of expression w.o. printing it @@ -407,10 +432,10 @@ void EXPRop_string( char * buffer, struct Op_Subexpression * oe ) { * WARNING this *does* change the global 'curpos'! */ int EXPRlength( Expression e ) { - char buffer[10000]; - *buffer = '\0'; - EXPRstring( buffer, e ); - return( strlen( buffer ) ); + std::string out; + out.reserve( 256 ); + EXPRstring_cpp( out, e ); + return( ( int )out.size() ); } char * EXPRto_string( Expression e ) { diff --git a/src/exppp/pretty_expr.h b/src/exppp/pretty_expr.h index 633bdf3f1..6769780fa 100644 --- a/src/exppp/pretty_expr.h +++ b/src/exppp/pretty_expr.h @@ -1,36 +1,27 @@ #ifndef PRETTY_EXPR_H #define PRETTY_EXPR_H +#ifdef __cplusplus +extern "C" { +#endif + #include "../express/expbasic.h" #include "../express/express.h" - #define EXPR_out(e,p) EXPR__out(e,p,OP_UNKNOWN) #define EXPRop2_out(oe,string,paren,pad) \ EXPRop2__out(oe,string,paren,pad,OP_UNKNOWN) #define EXPRop_out(oe,paren) EXPRop__out(oe,paren,OP_UNKNOWN) void EXPRop__out( struct Op_Subexpression * oe, int paren, unsigned int previous_op ); -void EXPRop_string( char * buffer, struct Op_Subexpression * oe ); -void EXPRop1_out( struct Op_Subexpression * eo, char * opcode, int paren ); -void EXPRop2__out( struct Op_Subexpression * eo, char * opcode, int paren, int pad, unsigned int previous_op ); +void EXPRop1_out( struct Op_Subexpression * eo, const char * opcode, int paren ); +void EXPRop2__out( struct Op_Subexpression * eo, const char * opcode, int paren, int pad, unsigned int previous_op ); void EXPR__out( Expression e, int paren, unsigned int previous_op ); void EXPRbounds_out( TypeBody tb ); -int EXPRlength( Expression e ); + +#ifdef __cplusplus +} /* extern "C" */ +#endif #endif /* PRETTY_EXPR_H */ -/* -char * EXPRto_string( Expression e ); -void EXPR__out( Expression e, int paren, unsigned int previous_op ); -void EXPRbounds_out( TypeBody tb ); -int EXPRlength( Expression e ); -void EXPRop1_out( struct Op_Subexpression * eo, char * opcode, int paren ); -void EXPRop2__out( struct Op_Subexpression * eo, char * opcode, int paren, int pad, unsigned int previous_op ); -void EXPRop__out( struct Op_Subexpression * oe, int paren, unsigned int previous_op ); -int EXPRop_length( struct Op_Subexpression * oe ); -void EXPRop_string( char * buffer, struct Op_Subexpression * oe ); -void EXPRout( Expression e ); -void EXPRstring( char * buffer, Expression e ); -int EXPRto_buffer( Expression e, char * buffer, int length ); -*/ diff --git a/src/exppp/pretty_schema.c b/src/exppp/pretty_schema.c index c17ebe5be..ae2ad2d7c 100644 --- a/src/exppp/pretty_schema.c +++ b/src/exppp/pretty_schema.c @@ -69,7 +69,7 @@ char * SCHEMAout( Schema s ) { /* since we have to generate a filename, make sure we don't */ /* overwrite a valuable file */ - sprintf( exppp_filename_buffer, "%s.exp", s->symbol.name ); + snprintf( exppp_filename_buffer, sizeof(exppp_filename_buffer), "%s.exp", s->symbol.name ); if( 0 != ( f = fopen( exppp_filename_buffer, "r" ) ) ) { char * result = fgets( buf, PP_SMALL_BUF_SZ, f ); diff --git a/src/exppp/pretty_subtype.c b/src/exppp/pretty_subtype.c index d47298e49..f21d6c620 100644 --- a/src/exppp/pretty_subtype.c +++ b/src/exppp/pretty_subtype.c @@ -2,8 +2,6 @@ * split out of exppp.c 9/21/13 */ -#include - #include "exppp.h" #include "pp.h" diff --git a/src/exppp/pretty_type.c b/src/exppp/pretty_type.c index b5fda9301..678d2b87a 100644 --- a/src/exppp/pretty_type.c +++ b/src/exppp/pretty_type.c @@ -5,7 +5,6 @@ #include #include -#include #include "exppp.h" #include "pp.h" @@ -151,7 +150,7 @@ void TYPE_body_out( Type t, int level ) { while( 0 != ( expr = ( Expression )DICTdo( &de ) ) ) { count++; } - names = ( char ** )sc_calloc( count, sizeof( char * ) ); + names = ( char ** )calloc( count, sizeof( char * ) ); DICTdo_type_init( t->symbol_table, &de, OBJ_EXPRESSION ); while( 0 != ( expr = ( Expression )DICTdo( &de ) ) ) { names[expr->u.integer - 1] = expr->symbol.name; @@ -175,7 +174,7 @@ void TYPE_body_out( Type t, int level ) { raw( names[i] ); } raw( " )" ); - sc_free( ( char * )names ); + free( ( char * )names ); } break; case select_: diff --git a/src/exppp/test/CMakeLists.txt b/src/exppp/test/CMakeLists.txt index 0d911e590..e13a480e0 100644 --- a/src/exppp/test/CMakeLists.txt +++ b/src/exppp/test/CMakeLists.txt @@ -14,7 +14,7 @@ add_test(NAME build_exppp ) # this executable doesn't really check the results, just ensures no segfaults. ought to improve it... -SC_ADDEXEC(tst_breakLongStr SOURCES ${breakLongStr_SRCS} LINK_LIBRARIES express base TESTABLE) +SC_ADDEXEC(tst_breakLongStr SOURCES ${breakLongStr_SRCS} LINK_LIBRARIES express TESTABLE) add_test(NAME build_tst_breakLongStr WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_COMMAND} --build . diff --git a/src/exppp/test/exppp_supertype_andor.cmake b/src/exppp/test/exppp_supertype_andor.cmake index 547ad70a5..5c03a02a5 100644 --- a/src/exppp/test/exppp_supertype_andor.cmake +++ b/src/exppp/test/exppp_supertype_andor.cmake @@ -1,5 +1,5 @@ -cmake_minimum_required( VERSION 2.8 ) +cmake_minimum_required( VERSION 3.12 ) # executable is ${EXPPP}, input file is ${INFILE} diff --git a/src/express/CMakeLists.txt b/src/express/CMakeLists.txt index 2a3aa4299..e5c0dfe04 100644 --- a/src/express/CMakeLists.txt +++ b/src/express/CMakeLists.txt @@ -1,7 +1,6 @@ include_directories( ${CMAKE_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR} - ${SC_SOURCE_DIR}/src/base ) # Depending on whether we're using pre-generated sources or building them on @@ -19,6 +18,7 @@ if(SC_GENERATE_LP_SOURCES) add_library(objlib_expparse_c OBJECT ${LEMON_ExpParser_OUTPUTS}) set_property(TARGET objlib_expparse_c PROPERTY POSITION_INDEPENDENT_CODE ON) + set_source_files_properties(${LEMON_ExpParser_OUTPUTS} PROPERTIES OBJECT_DEPENDS "${PERPLEX_ExpScanner_HDR}") else(SC_GENERATE_LP_SOURCES) add_subdirectory(generated) @@ -93,7 +93,6 @@ endif() if(BUILD_SHARED_LIBS OR NOT BUILD_STATIC_LIBS) add_library(express SHARED ${EXPRESS_OBJS}) - target_link_libraries(express base) if(OPENBSD) set_target_properties(express PROPERTIES VERSION ${SC_VERSION_MAJOR}.${SC_VERSION_MINOR}) else(OPENBSD) @@ -137,9 +136,9 @@ set(CHECK_EXPRESS_SOURCES add_executable(check-express ${CHECK_EXPRESS_SOURCES}) if(BUILD_SHARED_LIBS OR NOT BUILD_STATIC_LIBS) - target_link_libraries(check-express express base) + target_link_libraries(check-express express) else() - target_link_libraries(check-express express-static base-static) + target_link_libraries(check-express express-static) endif() install(TARGETS check-express RUNTIME DESTINATION ${BIN_DIR} diff --git a/src/express/alloc.c b/src/express/alloc.c index e20cfa943..2a3979ba2 100644 --- a/src/express/alloc.c +++ b/src/express/alloc.c @@ -76,7 +76,7 @@ Freelist * create_freelist( struct freelist_head * flh, int bytes ) { } void -_ALLOCinitialize() { +_ALLOCinitialize(void) { #ifdef DEBUG_MALLOC malloc_debug( 2 ); #endif diff --git a/src/express/entity.c b/src/express/entity.c index 507b2c23f..7b26a7833 100644 --- a/src/express/entity.c +++ b/src/express/entity.c @@ -292,7 +292,7 @@ Entity ENTITYcopy( Entity e ) { } /** Initialize the Entity module. */ -void ENTITYinitialize() { +void ENTITYinitialize(void) { } /** diff --git a/src/express/error.c b/src/express/error.c index c151a2d87..9367f0629 100644 --- a/src/express/error.c +++ b/src/express/error.c @@ -58,17 +58,11 @@ #include #include -#include "sc_memmgr.h" #include "express/express.h" #include "express/error.h" #include "express/info.h" #include "express/linklist.h" -#if defined(_MSC_VER) && _MSC_VER < 1900 -# include "sc_stdio.h" -# define vsnprintf c99_vsnprintf -#endif - static struct Error_ LibErrors[] = { /* dict.c */ [DUPLICATE_DECL] = {SEVERITY_ERROR, "Redeclaration of %s. Previous declaration was on line %d.", NULL, false}, @@ -224,7 +218,7 @@ static int ERROR_printf( const char *format, ... ) { return result; } -static void ERROR_nexterror() { +static void ERROR_nexterror(void) { if( ERROR_string == ERROR_string_end ) { return; } @@ -233,7 +227,7 @@ static void ERROR_nexterror() { /** Initialize the Error module */ void ERRORinitialize( void ) { - ERROR_string_base = ( char * )sc_malloc( ERROR_MAX_SPACE ); + ERROR_string_base = ( char * )malloc( ERROR_MAX_SPACE ); ERROR_string_end = ERROR_string_base + ERROR_MAX_SPACE; ERROR_start_message_buffer(); @@ -253,7 +247,7 @@ void ERRORinitialize( void ) { /** Clean up the Error module */ void ERRORcleanup( void ) { - sc_free( ERROR_string_base ); + free( ERROR_string_base ); } void ERRORset_warning(char * name, bool warn_only) { @@ -296,7 +290,7 @@ char * ERRORget_warnings_help(const char* prefix, const char *eol) { clen = strlen(prefix) + strlen(eol) + 1; - buf = sc_malloc(sz); + buf = malloc(sz); if (!buf) { fprintf(error_file, "failed to allocate memory for warnings help!\n"); } @@ -308,7 +302,7 @@ char * ERRORget_warnings_help(const char* prefix, const char *eol) { len = strlen(buf) + strlen(err->name) + clen; if (len > sz) { sz *= 2; - nbuf = sc_realloc(buf, sz); + nbuf = realloc(buf, sz); if (!nbuf) { fprintf(error_file, "failed to reallocate / grow memory for warnings help!\n"); } @@ -461,7 +455,7 @@ ERRORreport_with_symbol( enum ErrorCode errnum, Symbol * sym, ... ) { va_end( args ); } -void ERRORnospace() { +void ERRORnospace(void) { fprintf( stderr, "%s: out of space\n", EXPRESSprogram_name ); ERRORabort( 0 ); } @@ -542,6 +536,6 @@ void ERRORsafe( jmp_buf env ) { memcpy( ERROR_safe_env, env, sizeof( jmp_buf ) ); } -void ERRORunsafe() { +void ERRORunsafe(void) { ERROR_unsafe = true; } diff --git a/src/express/expparse.y b/src/express/expparse.y index f6bc296c2..92a9bfcca 100644 --- a/src/express/expparse.y +++ b/src/express/expparse.y @@ -51,7 +51,7 @@ YYSTYPE yylval; Express yyexpresult; /* hook to everything built by parser */ Symbol *interface_schema; /* schema of interest in use/ref clauses */ - void (*interface_func)(); /* func to attach rename clauses */ + void (*interface_func)(struct Scope_ *, Symbol *, Symbol *, Symbol *); /* func to attach rename clauses */ /* record schemas found in a single parse here, allowing them to be */ /* differentiated from other schemas parsed earlier */ @@ -106,7 +106,7 @@ YYSTYPE yylval; #define ERROR(code) ERRORreport(code, yylineno) -void parserInitState() +void parserInitState( void ) { scope = scopes; /* no need to define scope->this */ @@ -402,8 +402,7 @@ aggregate_type(A) ::= TOK_AGGREGATE TOK_OF parameter_type(B). Symbol sym; sym.line = yylineno; sym.filename = current_filename; - ERRORreport_with_symbol(UNLABELLED_PARAM_TYPE, &sym, - CURRENT_SCOPE_NAME); + ERRORreport_with_symbol(UNLABELLED_PARAM_TYPE, &sym, CURRENT_SCOPE_NAME); } } aggregate_type(A) ::= TOK_AGGREGATE TOK_COLON TOK_IDENTIFIER(B) TOK_OF diff --git a/src/express/expr.c b/src/express/expr.c index 19ab0af91..c48ec5909 100644 --- a/src/express/expr.c +++ b/src/express/expr.c @@ -85,7 +85,7 @@ Expression LITERAL_PI = EXPRESSION_NULL; Expression LITERAL_ZERO = EXPRESSION_NULL; Expression LITERAL_ONE; -void EXPop_init(); +void EXPop_init(void); static inline int OPget_number_of_operands( Op_Code op ) { if( ( op == OP_NEGATE ) || ( op == OP_NOT ) ) { @@ -760,7 +760,7 @@ void EXPop_create( int token_number, char * string, Resolve_expr_func * resolve_ EXPop_table[token_number].resolve = resolve_func; } -void EXPop_init() { +void EXPop_init(void) { EXPop_create( OP_AND, "AND", EXPresolve_op_logical ); EXPop_create( OP_ANDOR, "ANDOR", EXPresolve_op_logical ); EXPop_create( OP_ARRAY_ELEMENT, "[array element]", EXPresolve_op_array_like ); diff --git a/src/express/express.c b/src/express/express.c index 82e7b7889..f8f4c4fc8 100644 --- a/src/express/express.c +++ b/src/express/express.c @@ -73,7 +73,6 @@ #include #include -#include "sc_memmgr.h" #include "express/memory.h" #include "express/basic.h" #include "express/express.h" @@ -107,7 +106,7 @@ bool EXPRESSignore_duplicate_schemas = false; Function funcdef(char *name, int pcount, Type ret_typ); void procdef(char *name, int pcount); -void BUILTINSinitialize(); +void BUILTINSinitialize(void); Dictionary EXPRESSbuiltins; /* procedures/functions */ @@ -144,20 +143,20 @@ int EXPRESS_succeed( Express model ) { return 0; } -Express EXPRESScreate() { +Express EXPRESScreate(void) { Express model = SCOPEcreate( OBJ_EXPRESS ); - model->u.express = ( struct Express_ * )sc_calloc( 1, sizeof( struct Express_ ) ); + model->u.express = ( struct Express_ * )calloc( 1, sizeof( struct Express_ ) ); return model; } void EXPRESSdestroy( Express model ) { if( model->u.express->basename ) { - sc_free( model->u.express->basename ); + free( model->u.express->basename ); } if( model->u.express->filename ) { - sc_free( model->u.express->filename ); + free( model->u.express->filename ); } - sc_free( model->u.express ); + free( model->u.express ); SCOPEdestroy( model ); } @@ -167,7 +166,7 @@ typedef struct Dir { char * leaf; } Dir; -static void EXPRESS_PATHinit() { +static void EXPRESS_PATHinit(void) { char * p; Dir * dir; @@ -175,7 +174,7 @@ static void EXPRESS_PATHinit() { p = getenv( "EXPRESS_PATH" ); if( !p ) { /* if no EXPRESS_PATH, search current directory anyway */ - dir = ( Dir * )sc_malloc( sizeof( Dir ) ); + dir = ( Dir * )malloc( sizeof( Dir ) ); dir->leaf = dir->full; LISTadd_last( EXPRESS_path, dir ); } else { @@ -208,7 +207,7 @@ static void EXPRESS_PATHinit() { } p++; /* leave p after terminating null */ - dir = ( Dir * )sc_malloc( sizeof( Dir ) ); + dir = ( Dir * )malloc( sizeof( Dir ) ); /* if it's just ".", make it as if it was */ /* just "" to make error messages cleaner */ @@ -228,7 +227,7 @@ static void EXPRESS_PATHinit() { strcpy( dir->full, start ); dir->leaf = dir->full + length; } else { - sprintf( dir->full, "%s/", start ); + snprintf( dir->full, sizeof(dir->full), "%s/", start ); dir->leaf = dir->full + length + 1; } LISTadd_last( EXPRESS_path, dir ); @@ -240,13 +239,13 @@ static void EXPRESS_PATHinit() { static void EXPRESS_PATHfree( void ) { LISTdo( EXPRESS_path, dir, Dir * ) - sc_free( dir ); + free( dir ); LISTod LISTfree( EXPRESS_path ); } /** inform object system about bit representation for handling pass diagnostics */ -void PASSinitialize() { +void PASSinitialize(void) { } /** Initialize the Express package. */ @@ -312,7 +311,9 @@ void EXPRESSparse( Express model, FILE * fp, char * filename ) { if( !fp ) { /* go down path looking for file */ LISTdo( EXPRESS_path, dir, Dir * ) - sprintf( dir->leaf, "%s", filename ); + + size_t rem = (size_t)( dir->full + sizeof( dir->full ) - dir->leaf ); + snprintf( dir->leaf, rem, "%s", filename ); if( 0 != ( fp = fopen( dir->full, "r" ) ) ) { filename = dir->full; break; @@ -339,7 +340,7 @@ void EXPRESSparse( Express model, FILE * fp, char * filename ) { length -= 4; } - model->u.express->basename = ( char * )sc_malloc( length + 1 ); + model->u.express->basename = ( char * )malloc( length + 1 ); memcpy( model->u.express->basename, filename, length ); model->u.express->basename[length] = '\0'; @@ -354,7 +355,7 @@ void EXPRESSparse( Express model, FILE * fp, char * filename ) { } /* TODO LEMON ought to put this in expparse.h */ -void parserInitState(); +void parserInitState(void); /** start parsing a new schema file */ static Express PARSERrun( char * filename, FILE * fp ) { @@ -531,7 +532,9 @@ Schema EXPRESSfind_schema( Dictionary modeldict, char * name ) { /* go down path looking for file */ LISTdo( EXPRESS_path, dir, Dir * ) - sprintf( dir->leaf, "%s.exp", lower ); + + size_t rem = (size_t)( dir->full + sizeof( dir->full ) - dir->leaf ); + snprintf( dir->leaf, rem, "%s.exp", lower ); if( print_objects_while_running & OBJ_SCHEMA_BITS ) { fprintf( stderr, "pass %d: %s (schema file?)\n", EXPRESSpass, dir->full ); @@ -799,7 +802,7 @@ void procdef(char *name, int pcount) { DICTdefine(EXPRESSbuiltins, name, p, 0, OBJ_PROCEDURE); } -void BUILTINSinitialize() { +void BUILTINSinitialize(void) { EXPRESSbuiltins = DICTcreate( 35 ); procdef("INSERT", 3 ); procdef("REMOVE", 2 ); diff --git a/src/express/expscan.l b/src/express/expscan.l index cbd56c535..755e21fc1 100644 --- a/src/express/expscan.l +++ b/src/express/expscan.l @@ -98,9 +98,12 @@ * * Revision 4.1 90/09/13 16:29:00 clark * BPR 2.1 alpha - * + * */ - +#include +#if !defined(isascii) && defined(__isascii) +# define isascii __isascii +#endif #include "express/basic.h" #include "express/error.h" #include "express/lexact.h" diff --git a/src/express/factory.c b/src/express/factory.c index daf6ee7d3..3e8a6727b 100644 --- a/src/express/factory.c +++ b/src/express/factory.c @@ -34,7 +34,7 @@ Type Type_Set_Of_String; Type Type_Set_Of_Generic; Type Type_Bag_Of_Generic; -void FACTORYinitialize() { +void FACTORYinitialize(void) { /* Very commonly-used read-only types */ Type_Unknown = TYPEcreate( unknown_ ); Type_Dont_Care = TYPEcreate( special_ ); diff --git a/src/express/fedex.c b/src/express/fedex.c index 7ccae40d4..efca9ddd1 100644 --- a/src/express/fedex.c +++ b/src/express/fedex.c @@ -75,9 +75,7 @@ #include #include "config.h" -#include "sc_memmgr.h" #include "sc_export.h" -#include "sc_getopt.h" #include "express/error.h" #include "express/express.h" #include "express/resolve.h" @@ -87,6 +85,68 @@ extern int exp_yydebug; #endif /*YYDEBUG*/ +char * sc_optarg; // global argument pointer +int sc_optind = 0; // global argv index + +int sc_getopt( int argc, char * argv[], char * optstring ) { + static char * next = NULL; + if( sc_optind == 0 ) { + next = NULL; + } + + sc_optarg = NULL; + + if( next == NULL || *next == '\0' ) { + if( sc_optind == 0 ) { + sc_optind++; + } + + if( sc_optind >= argc || argv[sc_optind][0] != '-' || argv[sc_optind][1] == '\0' ) { + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + if( strcmp( argv[sc_optind], "--" ) == 0 ) { + sc_optind++; + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + next = argv[sc_optind]; + next++; // skip past - + sc_optind++; + } + + char c = *next++; + char * cp = strchr( optstring, c ); + + if( cp == NULL || c == ':' ) { + return '?'; + } + + cp++; + if( *cp == ':' ) { + if( *next != '\0' ) { + sc_optarg = next; + next = NULL; + } else if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + sc_optind++; + } else { + return '?'; + } + } + + return c; +} + + char EXPRESSgetopt_options[256] = "Bbd:e:i:w:p:rvz"; /* larger than the string because exp2cxx, exppp, etc may append their own options */ static int no_need_to_work = 0; /* TRUE if we can exit gracefully without doing any work */ diff --git a/src/express/generated/expparse.c b/src/express/generated/expparse.c index 217c349d6..393d5c303 100644 --- a/src/express/generated/expparse.c +++ b/src/express/generated/expparse.c @@ -57,7 +57,7 @@ YYSTYPE yylval; Express yyexpresult; /* hook to everything built by parser */ Symbol *interface_schema; /* schema of interest in use/ref clauses */ - void (*interface_func)(); /* func to attach rename clauses */ + void (*interface_func)(struct Scope_ *, Symbol *, Symbol *, Symbol *); /* func to attach rename clauses */ /* record schemas found in a single parse here, allowing them to be */ /* differentiated from other schemas parsed earlier */ @@ -112,7 +112,7 @@ YYSTYPE yylval; #define ERROR(code) ERRORreport(code, yylineno) -void parserInitState() +void parserInitState( void ) { scope = scopes; /* no need to define scope->this */ @@ -2348,8 +2348,7 @@ static void yy_reduce( Symbol sym; sym.line = yylineno; sym.filename = current_filename; - ERRORreport_with_symbol(UNLABELLED_PARAM_TYPE, &sym, - CURRENT_SCOPE_NAME); + ERRORreport_with_symbol(UNLABELLED_PARAM_TYPE, &sym, CURRENT_SCOPE_NAME); } } #line 2356 "expparse.c" diff --git a/src/express/generated/expscan.c b/src/express/generated/expscan.c index b78b863a5..86893459a 100644 --- a/src/express/generated/expscan.c +++ b/src/express/generated/expscan.c @@ -99,6 +99,10 @@ * Revision 4.1 90/09/13 16:29:00 clark * BPR 2.1 alpha * */ +#include +#if !defined(isascii) && defined(__isascii) +# define isascii __isascii +#endif #include "express/basic.h" #include "express/error.h" #include "express/lexact.h" @@ -275,8 +279,9 @@ buf_prints(struct Buf *buf, const char *fmt, const char *s) { char *t; - t = (char*)malloc(strlen(fmt) + strlen(s) + 1); - sprintf(t, fmt, s); + size_t len = strlen(fmt) + strlen(s) + 1; + t = (char*)malloc(len); + snprintf(t, len, fmt, s); buf = buf_strappend(buf, t); free(t); return buf; @@ -311,9 +316,10 @@ buf_linedir(struct Buf *buf, const char* filename, int lineno) { char *t; const char fmt[] = "#line %d \"%s\"\n"; - - t = (char*)malloc(strlen(fmt) + strlen(filename) + numDigits(lineno) + 1); - sprintf(t, fmt, lineno, filename); + + size_t len = strlen(fmt) + strlen(filename) + numDigits(lineno) + 1; + t = (char*)malloc(len); + snprintf(t, len, fmt, lineno, filename); buf = buf_strappend(buf, t); free(t); return buf; @@ -378,9 +384,11 @@ buf_m4_define(struct Buf *buf, const char* def, const char* val) char *str; val = val ? val : ""; - str = (char*)malloc(strlen(fmt) + strlen(def) + strlen(val) + 2); - sprintf(str, fmt, def, val); + size_t len = strlen(fmt) + strlen(def) + strlen(val) + 2; + str = (char*)malloc(len); + + snprintf(str, len, fmt, def, val); buf_append(buf, &str, 1); return buf; } @@ -396,9 +404,9 @@ buf_m4_undefine(struct Buf *buf, const char* def) const char *fmt = "m4_undefine( [[%s]])m4_dnl\n"; char *str; - str = (char*)malloc(strlen(fmt) + strlen(def) + 2); - - sprintf(str, fmt, def); + size_t len = strlen(fmt) + strlen(def) + 2; + str = (char*)malloc(len); + snprintf(str, len, fmt, def); buf_append(buf, &str, 1); return buf; } @@ -617,7 +625,7 @@ getTokenText(perplex_t scanner) #define yyextra scanner->extra static perplex_t -newScanner() +newScanner(void) { perplex_t scanner; scanner = (perplex_t)calloc(1, sizeof(struct perplex)); diff --git a/src/express/hash.c b/src/express/hash.c index 5556ade92..fabe6ba0f 100644 --- a/src/express/hash.c +++ b/src/express/hash.c @@ -109,7 +109,6 @@ #include #include -#include "sc_memmgr.h" #include "express/hash.h" /* @@ -132,7 +131,7 @@ static long HashAccesses, HashCollisions; */ void -HASHinitialize() { +HASHinitialize(void) { } Hash_Table @@ -293,7 +292,7 @@ HASHdestroy( Hash_Table table ) { p = q; } } - sc_free( table->Directory[i] ); + free( table->Directory[i] ); } } HASH_Table_destroy( table ); diff --git a/src/express/lexact.c b/src/express/lexact.c index abcde3176..3f521850c 100644 --- a/src/express/lexact.c +++ b/src/express/lexact.c @@ -55,7 +55,6 @@ #include #include -#include "sc_memmgr.h" #include "express/lexact.h" #include "express/linklist.h" #include "stack.h" @@ -221,7 +220,7 @@ static void SCANpush_buffer( char * filename, FILE * fp ) { SCANbuffer.filename = current_filename = filename; } -static void SCANpop_buffer() { +static void SCANpop_buffer(void) { if( SCANbuffer.file != NULL ) { fclose( SCANbuffer.file ); } @@ -273,7 +272,7 @@ int SCANprocess_logical_literal( char * string ) { break; /* default will actually be triggered by 'UNKNOWN' keyword */ } - sc_free( string ); + free( string ); return TOK_LOGICAL_LITERAL; } @@ -285,7 +284,7 @@ int SCANprocess_identifier_or_keyword( const char * yytext ) { /* make uppercase copy */ len = strlen( yytext ); - dest = test_string = ( char * )sc_malloc( len + 1 ); + dest = test_string = ( char * )malloc( len + 1 ); for( src = yytext; *src; src++, dest++ ) { *dest = ( islower( *src ) ? toupper( *src ) : *src ); } @@ -301,7 +300,7 @@ int SCANprocess_identifier_or_keyword( const char * yytext ) { case TOK_LOGICAL_LITERAL: return SCANprocess_logical_literal( test_string ); default: - sc_free( test_string ); + free( test_string ); return k->token; } } @@ -474,7 +473,7 @@ void SCANupperize( char * s ) { } char * SCANstrdup( const char * s ) { - char * s2 = ( char * )sc_malloc( strlen( s ) + 1 ); + char * s2 = ( char * )malloc( strlen( s ) + 1 ); if( !s2 ) { return 0; } @@ -483,6 +482,6 @@ char * SCANstrdup( const char * s ) { return s2; } -long SCANtell() { +long SCANtell(void) { return yylineno; } diff --git a/src/express/linklist.c b/src/express/linklist.c index 7089dd81d..6acbea90d 100644 --- a/src/express/linklist.c +++ b/src/express/linklist.c @@ -29,7 +29,7 @@ void LISTinitialize( void ) { void LISTcleanup( void ) { } -Linked_List LISTcreate() { +Linked_List LISTcreate(void) { Linked_List list = LIST_new(); list->mark = LINK_new(); list->mark->next = list->mark->prev = list->mark; diff --git a/src/express/memory.c b/src/express/memory.c index da4db3751..6c3b1c5b6 100644 --- a/src/express/memory.c +++ b/src/express/memory.c @@ -47,7 +47,7 @@ struct freelist_head PCALL_fl; struct freelist_head RET_fl; struct freelist_head INCR_fl; -void MEMORYinitialize() { +void MEMORYinitialize(void) { _ALLOCinitialize(); ALLOCinitialize( &HASH_Table_fl, sizeof( struct Hash_Table_ ), 50, 50 ); diff --git a/src/express/resolve.c b/src/express/resolve.c index fa5797917..157529a5f 100644 --- a/src/express/resolve.c +++ b/src/express/resolve.c @@ -1203,7 +1203,7 @@ int WHEREresolve( Linked_List list, Scope scope, int need_self ) { } } -struct tag * TAGcreate_tags() { +struct tag * TAGcreate_tags(void) { extern int tag_count; return( ( struct tag * )calloc( tag_count, sizeof( struct tag ) ) ); diff --git a/src/express/test/CMakeLists.txt b/src/express/test/CMakeLists.txt index 6d2615a9b..413761fd3 100644 --- a/src/express/test/CMakeLists.txt +++ b/src/express/test/CMakeLists.txt @@ -74,8 +74,8 @@ add_test(NAME test_plib_parse_err set_tests_properties( test_plib_parse_err PROPERTIES DEPENDS "build_check_express;$" ) set_tests_properties( test_plib_parse_err build_check_express PROPERTIES LABELS parser ) -sc_addexec(print_schemas SOURCES ../fedex.c print_schemas.c LINK_LIBRARIES express base) -sc_addexec(print_attrs SOURCES ../fedex.c print_attrs.c LINK_LIBRARIES express base) +sc_addexec(print_schemas SOURCES ../fedex.c print_schemas.c LINK_LIBRARIES express) +sc_addexec(print_attrs SOURCES ../fedex.c print_attrs.c LINK_LIBRARIES express) # Local Variables: # tab-width: 8 diff --git a/src/express/type.c b/src/express/type.c index ffcba5915..c4b6a7104 100644 --- a/src/express/type.c +++ b/src/express/type.c @@ -220,7 +220,7 @@ return( false ); #endif /** Initialize the Type module */ -void TYPEinitialize() { +void TYPEinitialize(void) { } /** Clean up the Type module */ diff --git a/src/express/variable.c b/src/express/variable.c index b3ec9f88a..c15a41706 100644 --- a/src/express/variable.c +++ b/src/express/variable.c @@ -90,7 +90,7 @@ char * opcode_print( Op_Code o ); /** Initialize the Variable module. */ -void VARinitialize() { +void VARinitialize(void) { } /** VARget_simple_name diff --git a/src/test/p21read/p21read.cc b/src/test/p21read/p21read.cc index cbdbcaa02..cf96b86dd 100644 --- a/src/test/p21read/p21read.cc +++ b/src/test/p21read/p21read.cc @@ -13,12 +13,12 @@ */ extern void SchemaInit( class Registry & ); -#include -#include -#include -#include -#include -#include +#include "cleditor/STEPfile.h" +#include "clstepcore/sdai.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/Registry.h" +#include "clutils/errordesc.h" #include #include #include "sc_benchmark.h" @@ -26,7 +26,66 @@ extern void SchemaInit( class Registry & ); # include #endif -#include +char * sc_optarg; // global argument pointer +int sc_optind = 0; // global argv index + +int sc_getopt( int argc, char * argv[], char * optstring ) { + static char * next = NULL; + if( sc_optind == 0 ) { + next = NULL; + } + + sc_optarg = NULL; + + if( next == NULL || *next == '\0' ) { + if( sc_optind == 0 ) { + sc_optind++; + } + + if( sc_optind >= argc || argv[sc_optind][0] != '-' || argv[sc_optind][1] == '\0' ) { + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + if( strcmp( argv[sc_optind], "--" ) == 0 ) { + sc_optind++; + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + next = argv[sc_optind]; + next++; // skip past - + sc_optind++; + } + + char c = *next++; + char * cp = strchr( optstring, c ); + + if( cp == NULL || c == ':' ) { + return '?'; + } + + cp++; + if( *cp == ':' ) { + if( *next != '\0' ) { + sc_optarg = next; + next = NULL; + } else if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + sc_optind++; + } else { + return '?'; + } + } + + return c; +} /** * Compare the schema names from the lib (generated by exp2cxx) and diff --git a/src/test/p21read/sc_benchmark.cc b/src/test/p21read/sc_benchmark.cc new file mode 100644 index 000000000..2f00cd5a4 --- /dev/null +++ b/src/test/p21read/sc_benchmark.cc @@ -0,0 +1,149 @@ +/// \file sc_benchmark.cc memory info, timers, etc for benchmarking + +#include "./sc_benchmark.h" + +#ifdef _WIN32 +#include +#include +#else +#include +#include +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +/// mem values in kb, times in ms (granularity may be higher than 1ms) +benchVals getMemAndTime( ) { + benchVals vals; +#ifdef __linux__ + // adapted from http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c + std::ifstream stat_stream( "/proc/self/stat", std::ios_base::in ); + + // dummy vars for leading entries in stat that we don't care about + std::string pid, comm, state, ppid, pgrp, session, tty_nr; + std::string tpgid, flags, minflt, cminflt, majflt, cmajflt; + std::string /*utime, stime,*/ cutime, cstime, priority, nice; + std::string O, itrealvalue, starttime; + + // the fields we want + unsigned long utime, stime, vsize; + long rss; + + stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr + >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt + >> utime >> stime >> cutime >> cstime >> priority >> nice + >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest + + long page_size_kb = sysconf( _SC_PAGE_SIZE ) / 1024; // in case x86-64 is configured to use 2MB pages + vals.physMemKB = rss * page_size_kb; + vals.virtMemKB = ( vsize / 1024 ) - vals.physMemKB; + vals.userMilliseconds = ( utime * 1000 ) / sysconf( _SC_CLK_TCK ); + vals.sysMilliseconds = ( stime * 1000 ) / sysconf( _SC_CLK_TCK ); +#elif defined(__APPLE__) + // http://stackoverflow.com/a/1911863/382458 +#elif defined(_WIN32) + // http://stackoverflow.com/a/282220/382458 and http://stackoverflow.com/a/64166/382458 + PROCESS_MEMORY_COUNTERS MemoryCntrs; + FILETIME CreationTime, ExitTime, KernelTime, UserTime; + long page_size_kb = 1024; + ULARGE_INTEGER kTime, uTime; + + if( GetProcessMemoryInfo( GetCurrentProcess(), &MemoryCntrs, sizeof( MemoryCntrs ) ) ) { + vals.physMemKB = MemoryCntrs.PeakWorkingSetSize / page_size_kb; + vals.virtMemKB = MemoryCntrs.PeakPagefileUsage / page_size_kb; + } else { + vals.physMemKB = 0; + vals.virtMemKB = 0; + } + + if( GetProcessTimes( GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime ) ) { + assert( sizeof( FILETIME ) == sizeof( ULARGE_INTEGER ) ); + memcpy( &kTime, &KernelTime, sizeof( FILETIME ) ); + memcpy( &uTime, &UserTime, sizeof( FILETIME ) ); + vals.userMilliseconds = ( long )( uTime.QuadPart / 100000L ); + vals.sysMilliseconds = ( long )( kTime.QuadPart / 100000L ); + } else { + vals.userMilliseconds = 0; + vals.sysMilliseconds = 0; + } +#else +#warning Unknown platform! +#endif // __linux__ + return vals; +} + +// --------------------- benchmark class --------------------- + +benchmark::benchmark( std::string description, bool debugMessages, std::ostream & o_stream ): ostr( o_stream ), + descr( description ), debug( debugMessages ), stopped( false ) { + initialVals = getMemAndTime( ); +} + +benchmark::~benchmark() { + if( !stopped ) { + stop( ); + if( debug ) { + ostr << "benchmark::~benchmark(): stop was not called before destructor!" << std::endl; + } + out( ); + } +} + +void benchmark::stop( ) { + if( stopped ) { + std::cerr << "benchmark::stop(): tried to stop a benchmark that was already stopped!" << std::endl; + } else { + laterVals = getMemAndTime( ); + stopped = true; + } +} + +benchVals benchmark::get( ) { + if( !stopped ) { + laterVals = getMemAndTime( ); + } + benchVals delta; + delta.physMemKB = laterVals.physMemKB - initialVals.physMemKB; + delta.virtMemKB = laterVals.virtMemKB - initialVals.virtMemKB; + delta.sysMilliseconds = laterVals.sysMilliseconds - initialVals.sysMilliseconds; + delta.userMilliseconds = laterVals.userMilliseconds - initialVals.userMilliseconds; + + //If vm is negative, the memory had been requested before initialVals was set. Don't count it + if( delta.virtMemKB < 0 ) { + delta.physMemKB -= delta.virtMemKB; + delta.virtMemKB = 0; + } + return delta; +} + +void benchmark::reset( std::string description ) { + descr = description; + reset(); +} +void benchmark::reset( ) { + stopped = false; + initialVals = getMemAndTime(); +} + +std::string benchmark::str( ) { + return str( get( ) ); +} + +void benchmark::out() { + ostr << str( ) << std::endl; +} + +std::string benchmark::str( const benchVals & bv ) { + std::stringstream ss; + ss << descr << " Physical memory: " << bv.physMemKB << "kb; Virtual memory: " << bv.virtMemKB; + ss << "kb; User CPU time: " << bv.userMilliseconds << "ms; System CPU time: " << bv.sysMilliseconds << "ms"; + return ss.str(); +} + diff --git a/src/test/p21read/sc_benchmark.h b/src/test/p21read/sc_benchmark.h new file mode 100644 index 000000000..5b77317c4 --- /dev/null +++ b/src/test/p21read/sc_benchmark.h @@ -0,0 +1,74 @@ +#ifndef SC_BENCHMARK_H +#define SC_BENCHMARK_H +/// \file sc_benchmark.h memory info, timers, etc for benchmarking + +#ifdef __cplusplus +#include +#include +#include + +extern "C" { +#endif + + typedef struct { + long virtMemKB, physMemKB, userMilliseconds, sysMilliseconds; + } benchVals; + + /** return a benchVals struct with four current statistics for this process: + * virtual and physical memory use in kb, + * user and system cpu time in ms + * + * not yet implemented for OSX or Windows. + */ + benchVals getMemAndTime( ); + +#ifdef __cplusplus +} + + +/** reports the difference in memory and cpu use between when the + * constructor is called and when stop() or the destructor is called. + * + * if the destructor is called and stop() had not previously been + * called, the results are printed to the ostream given in the + * constructor, prefixed by the description. + * + * depends on getMemAndTime() above - may not work on all platforms. + */ + +class benchmark { + protected: + benchVals initialVals, laterVals; +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4251 ) +#endif + std::ostream & ostr; + std::string descr; +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + bool debug, stopped; + public: + benchmark( std::string description = "", bool debugMessages = true, std::ostream & o_stream = std::cout ); + + /// if 'stopped' is false, uses str(true) to print to ostream + ~benchmark( ); + void reset( ); + void reset( std::string description ); + benchVals get( ); + void stop( ); + + /// converts data member 'laterVals' into a string and returns it + std::string str( ); + + /// outputs result of str() on ostream 'ostr' + void out( ); + + /// converts 'bv' into a string, prefixed by data member 'descr' + std::string str( const benchVals & bv ); +}; + + +#endif //__cplusplus +#endif //SC_BENCHMARK_H diff --git a/src/test/scl2html/scl2html.cc b/src/test/scl2html/scl2html.cc index f597b36e4..afe65b11f 100644 --- a/src/test/scl2html/scl2html.cc +++ b/src/test/scl2html/scl2html.cc @@ -49,7 +49,7 @@ void PrintAttrTypeWithAnchor( const TypeDescriptor * typeDesc, ofstream & outhtml ) { std::string buf; - // The type. See src/clstepcore/baseType.h for info + // The type. See clstepcore/baseType.h for info PrimitiveType base = typeDesc->Type(); // the type descriptor for the "referent type," if any. diff --git a/src/test/tests.h b/src/test/tests.h index 52fcb3a59..0494b55d2 100644 --- a/src/test/tests.h +++ b/src/test/tests.h @@ -16,10 +16,10 @@ #include /* General SCL stuff */ -#include -#include -#include -#include +#include "clstepcore/ExpDict.h" +#include "cleditor/STEPfile.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/sdai.h" /* Stuff more or less specifically for the Example schema */ /* The only program that needs this is tstatic. Since the other programs */ diff --git a/test/cpp/schema_specific/CMakeLists.txt b/test/cpp/schema_specific/CMakeLists.txt index 44fa4e5bc..e1bd06e10 100644 --- a/test/cpp/schema_specific/CMakeLists.txt +++ b/test/cpp/schema_specific/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12) #c++ tests that depend on a particular schema include_directories( ${SC_SOURCE_DIR}/src/cldai ${SC_SOURCE_DIR}/src/cleditor ${SC_SOURCE_DIR}/src/clutils - ${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/base ) + ${SC_SOURCE_DIR}/src/clstepcore ) # helper function for add_schema_dependent_test # given an sdai target, set out_path_var to the include dir @@ -92,7 +92,7 @@ set_tests_properties( test_aggregate_bound_runtime_FAIL1 PROPERTIES add_schema_dependent_test( "inverse_attr1" "inverse_attr" "${SC_SOURCE_DIR}/test/p21/test_inverse_attr.p21" ) add_schema_dependent_test( "inverse_attr2" "inverse_attr" "${SC_SOURCE_DIR}/test/p21/test_inverse_attr.p21" ) add_schema_dependent_test( "inverse_attr3" "inverse_attr" "${SC_SOURCE_DIR}/test/p21/test_inverse_attr.p21" - "${SC_SOURCE_DIR}/src/cllazyfile;${SC_SOURCE_DIR}/src/base/judy/src" "" "steplazyfile" ) + "${SC_SOURCE_DIR}/src/cllazyfile;${SC_SOURCE_DIR}/src/cllazyfile/judy/src" "" "steplazyfile" ) add_schema_dependent_test( "attribute" "inverse_attr" "${SC_SOURCE_DIR}/test/p21/test_inverse_attr.p21" ) if(HAVE_STD_THREAD) diff --git a/test/cpp/schema_specific/aggregate_bound_runtime.cc b/test/cpp/schema_specific/aggregate_bound_runtime.cc index fe103ab8e..f459697e6 100644 --- a/test/cpp/schema_specific/aggregate_bound_runtime.cc +++ b/test/cpp/schema_specific/aggregate_bound_runtime.cc @@ -1,10 +1,10 @@ -#include -#include -#include -#include -#include -#include +#include "cleditor/STEPfile.h" +#include "clstepcore/sdai.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/Registry.h" +#include "clutils/errordesc.h" #include #include #ifdef HAVE_UNISTD_H diff --git a/test/cpp/schema_specific/attribute.cc b/test/cpp/schema_specific/attribute.cc index dc819f029..4fab32933 100644 --- a/test/cpp/schema_specific/attribute.cc +++ b/test/cpp/schema_specific/attribute.cc @@ -3,21 +3,79 @@ * Test attribute access; uses a tiny schema similar to a subset of IFC2x3 */ #include "config.h" -#include -#include -#include -#include -#include -#include +#include "cleditor/STEPfile.h" +#include "clstepcore/sdai.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/Registry.h" +#include "clutils/errordesc.h" #include #include #ifdef HAVE_UNISTD_H # include #endif -#include #include "schema.h" +char * sc_optarg; // global argument pointer +int sc_optind = 0; // global argv index +int sc_getopt( int argc, char * argv[], char * optstring ) { + static char * next = NULL; + if( sc_optind == 0 ) { + next = NULL; + } + + sc_optarg = NULL; + + if( next == NULL || *next == '\0' ) { + if( sc_optind == 0 ) { + sc_optind++; + } + + if( sc_optind >= argc || argv[sc_optind][0] != '-' || argv[sc_optind][1] == '\0' ) { + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + if( strcmp( argv[sc_optind], "--" ) == 0 ) { + sc_optind++; + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + next = argv[sc_optind]; + next++; // skip past - + sc_optind++; + } + + char c = *next++; + char * cp = strchr( optstring, c ); + + if( cp == NULL || c == ':' ) { + return '?'; + } + + cp++; + if( *cp == ':' ) { + if( *next != '\0' ) { + sc_optarg = next; + next = NULL; + } else if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + sc_optind++; + } else { + return '?'; + } + } + + return c; +} int main( int argc, char * argv[] ) { Registry registry( SchemaInit ); InstMgr instance_list; diff --git a/test/cpp/schema_specific/inverse_attr1.cc b/test/cpp/schema_specific/inverse_attr1.cc index 27a383ab6..9f776a37a 100644 --- a/test/cpp/schema_specific/inverse_attr1.cc +++ b/test/cpp/schema_specific/inverse_attr1.cc @@ -4,21 +4,81 @@ ** */ #include "config.h" -#include "SubSuperIterators.h" -#include -#include -#include -#include -#include -#include +#include "clstepcore/SubSuperIterators.h" +#include "cleditor/STEPfile.h" +#include "clstepcore/sdai.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/Registry.h" +#include "clutils/errordesc.h" #include #include #ifdef HAVE_UNISTD_H # include #endif -#include #include "schema.h" +char * sc_optarg; // global argument pointer +int sc_optind = 0; // global argv index + +int sc_getopt( int argc, char * argv[], char * optstring ) { + static char * next = NULL; + if( sc_optind == 0 ) { + next = NULL; + } + + sc_optarg = NULL; + + if( next == NULL || *next == '\0' ) { + if( sc_optind == 0 ) { + sc_optind++; + } + + if( sc_optind >= argc || argv[sc_optind][0] != '-' || argv[sc_optind][1] == '\0' ) { + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + if( strcmp( argv[sc_optind], "--" ) == 0 ) { + sc_optind++; + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + next = argv[sc_optind]; + next++; // skip past - + sc_optind++; + } + + char c = *next++; + char * cp = strchr( optstring, c ); + + if( cp == NULL || c == ':' ) { + return '?'; + } + + cp++; + if( *cp == ':' ) { + if( *next != '\0' ) { + sc_optarg = next; + next = NULL; + } else if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + sc_optind++; + } else { + return '?'; + } + } + + return c; +} + ///first way of finding inverse attrs bool findInverseAttrs1( InverseAItr iai, InstMgr & instList ) { const Inverse_attribute * ia; diff --git a/test/cpp/schema_specific/inverse_attr2.cc b/test/cpp/schema_specific/inverse_attr2.cc index 00cd7da0c..cdf8dbbd0 100644 --- a/test/cpp/schema_specific/inverse_attr2.cc +++ b/test/cpp/schema_specific/inverse_attr2.cc @@ -4,20 +4,79 @@ ** */ #include "config.h" -#include -#include -#include -#include -#include -#include +#include "cleditor/STEPfile.h" +#include "clstepcore/sdai.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/Registry.h" +#include "clutils/errordesc.h" #include #include #ifdef HAVE_UNISTD_H # include #endif -#include #include "schema.h" +char * sc_optarg; // global argument pointer +int sc_optind = 0; // global argv index + +int sc_getopt( int argc, char * argv[], char * optstring ) { + static char * next = NULL; + if( sc_optind == 0 ) { + next = NULL; + } + + sc_optarg = NULL; + + if( next == NULL || *next == '\0' ) { + if( sc_optind == 0 ) { + sc_optind++; + } + + if( sc_optind >= argc || argv[sc_optind][0] != '-' || argv[sc_optind][1] == '\0' ) { + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + if( strcmp( argv[sc_optind], "--" ) == 0 ) { + sc_optind++; + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + next = argv[sc_optind]; + next++; // skip past - + sc_optind++; + } + + char c = *next++; + char * cp = strchr( optstring, c ); + + if( cp == NULL || c == ':' ) { + return '?'; + } + + cp++; + if( *cp == ':' ) { + if( *next != '\0' ) { + sc_optarg = next; + next = NULL; + } else if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + sc_optind++; + } else { + return '?'; + } + } + + return c; +} ///second way of finding inverse attrs bool findInverseAttrs2( InverseAItr iai, InstMgr & instList, Registry & reg ) { const Inverse_attribute * ia; diff --git a/test/cpp/schema_specific/inverse_attr3.cc b/test/cpp/schema_specific/inverse_attr3.cc index 2a55efc66..bb4ce0929 100644 --- a/test/cpp/schema_specific/inverse_attr3.cc +++ b/test/cpp/schema_specific/inverse_attr3.cc @@ -5,13 +5,13 @@ * This test originally used STEPfile, which didn't work. Fixing STEPfile would have been very difficult, it uses lazyInstMgr now. */ #include "config.h" -#include +#include "cllazyfile/lazyInstMgr.h" #include -#include -#include -#include -#include -#include +#include "clstepcore/sdai.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/Registry.h" +#include "clutils/errordesc.h" #include #include #include @@ -19,9 +19,70 @@ #ifdef HAVE_UNISTD_H # include #endif -#include #include "schema.h" +char * sc_optarg; // global argument pointer +int sc_optind = 0; // global argv index + +int sc_getopt( int argc, char * argv[], char * optstring ) { + static char * next = NULL; + if( sc_optind == 0 ) { + next = NULL; + } + + sc_optarg = NULL; + + if( next == NULL || *next == '\0' ) { + if( sc_optind == 0 ) { + sc_optind++; + } + + if( sc_optind >= argc || argv[sc_optind][0] != '-' || argv[sc_optind][1] == '\0' ) { + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + if( strcmp( argv[sc_optind], "--" ) == 0 ) { + sc_optind++; + sc_optarg = NULL; + if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + } + return EOF; + } + + next = argv[sc_optind]; + next++; // skip past - + sc_optind++; + } + + char c = *next++; + char * cp = strchr( optstring, c ); + + if( cp == NULL || c == ':' ) { + return '?'; + } + + cp++; + if( *cp == ':' ) { + if( *next != '\0' ) { + sc_optarg = next; + next = NULL; + } else if( sc_optind < argc ) { + sc_optarg = argv[sc_optind]; + sc_optind++; + } else { + return '?'; + } + } + + return c; +} + + int main( int argc, char * argv[] ) { int exitStatus = EXIT_SUCCESS; if( argc != 2 ) { diff --git a/test/cpp/schema_specific/stepfile_rw_progress.cc b/test/cpp/schema_specific/stepfile_rw_progress.cc index e007c7f37..1fe5cb0dc 100644 --- a/test/cpp/schema_specific/stepfile_rw_progress.cc +++ b/test/cpp/schema_specific/stepfile_rw_progress.cc @@ -1,10 +1,10 @@ -#include -#include -#include -#include -#include -#include +#include "cleditor/STEPfile.h" +#include "clstepcore/sdai.h" +#include "clstepcore/STEPattribute.h" +#include "clstepcore/ExpDict.h" +#include "clstepcore/Registry.h" +#include "clutils/errordesc.h" #include #include