Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support external jsmn implementations #121

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cgltf.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* cgltf - a single-file glTF 2.0 parser written in C99.
*
* Version: 1.7
* Version: 1.8
*
* Website: https://github.com/jkuhlmann/cgltf
*
Expand Down Expand Up @@ -727,6 +727,8 @@ cgltf_result cgltf_copy_extras_json(const cgltf_data* data, const cgltf_extras*
#include <stdlib.h> /* For malloc, free, atoi, atof */
#endif

#ifndef CGLTF_EXTERNAL_JSMN

/* JSMN_PARENT_LINKS is necessary to make parsing large structures linear in input size */
#define JSMN_PARENT_LINKS

Expand Down Expand Up @@ -773,6 +775,8 @@ static int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, jsmntok_t
* -- jsmn.h end --
*/

#endif /* #ifndef CGLTF_EXTERNAL_JSMN */


static const cgltf_size GlbHeaderSize = 12;
static const cgltf_size GlbChunkHeaderSize = 8;
Expand Down Expand Up @@ -5065,7 +5069,7 @@ cgltf_result cgltf_parse_json(cgltf_options* options, const uint8_t* json_chunk,

jsmn_init(&parser);

int token_count = jsmn_parse(&parser, (const char*)json_chunk, size, tokens, options->json_token_count);
int token_count = jsmn_parse(&parser, (const char*)json_chunk, size, tokens, (unsigned int)options->json_token_count);

if (token_count <= 0)
{
Expand Down Expand Up @@ -5272,6 +5276,8 @@ static int cgltf_fixup_pointers(cgltf_data* data)
return 0;
}

#ifndef CGLTF_EXTERNAL_JSMN

/*
* -- jsmn.c start --
* Source: https://github.com/zserge/jsmn
Expand Down Expand Up @@ -5613,6 +5619,8 @@ static void jsmn_init(jsmn_parser *parser) {
* -- jsmn.c end --
*/

#endif /* #ifndef CGLTF_EXTERNAL_JSMN */

#endif /* #ifdef CGLTF_IMPLEMENTATION */

/* cgltf is distributed under MIT license:
Expand Down
11 changes: 11 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ else()
target_compile_options(${EXE_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
endif()
install( TARGETS ${EXE_NAME} RUNTIME DESTINATION bin )

set( EXE_NAME test_external_jsmn )
add_executable( ${EXE_NAME} test_external_jsmn.cpp )
set_property( TARGET ${EXE_NAME} PROPERTY CXX_STANDARD 11 )
if(MSVC)
target_compile_options(${EXE_NAME} PRIVATE /W4 /WX)
add_definitions( -D_CRT_SECURE_NO_WARNINGS)
else()
target_compile_options(${EXE_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
endif()
install( TARGETS ${EXE_NAME} RUNTIME DESTINATION bin )
Loading