From 1037262ae6f96c2522f587784a2b12c78eb8dc56 Mon Sep 17 00:00:00 2001 From: anirban Date: Wed, 4 Mar 2026 12:29:32 +0530 Subject: [PATCH 1/8] changed the JSON output to use parson lib --- raster/r.geomorphon/Makefile | 2 +- raster/r.geomorphon/profile.c | 113 ++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 32 deletions(-) diff --git a/raster/r.geomorphon/Makefile b/raster/r.geomorphon/Makefile index 614658c51bb..8845a0297fb 100644 --- a/raster/r.geomorphon/Makefile +++ b/raster/r.geomorphon/Makefile @@ -2,7 +2,7 @@ MODULE_TOPDIR = ../.. PGM = r.geomorphon -LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB) +LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB) $(PARSONLIB) DEPENDENCIES = $(RASTERDEP) $(GISDEP) include $(MODULE_TOPDIR)/include/Make/Module.make diff --git a/raster/r.geomorphon/profile.c b/raster/r.geomorphon/profile.c index 9be85bb2945..c8f4eeea06c 100644 --- a/raster/r.geomorphon/profile.c +++ b/raster/r.geomorphon/profile.c @@ -1,4 +1,5 @@ #include +#include #include "local_proto.h" #define JSON_MIN_INDENT 1 @@ -251,46 +252,96 @@ static const char *format_token_common(const struct token *t) */ static unsigned write_json(FILE *f) { - unsigned i, indent = JSON_MIN_INDENT; + unsigned i; + G_JSON_Value *root_value = NULL; + G_JSON_Object *obj = NULL; + G_JSON_Object *obj_stack[MAX_STACK_ELEMS]; + unsigned obj_depth = 0; + char *serialized = NULL; + unsigned ok = 0; + + root_value = G_json_value_init_object(); + if (!root_value) + goto cleanup; + obj = G_json_object(root_value); + if (!obj) + goto cleanup; - WRITE_VAL(f, "%s\n", "{"); for (i = 0; i < size; i++) { - const char *val; - - /* Add a comma unless there is no data tokens immediately after. */ - const char *comma = - (i + 1 == size) || (i + 1 < size && token[i + 1].type == T_ESO) - ? "" - : ","; - switch (token[i].type) { - case T_SSO: - WRITE_INDENT(f, indent); - indent++; - WRITE_VAL(f, "\"%s\": {\n", token[i].key); + case T_SSO: { + G_JSON_Value *sub_value; + G_JSON_Object *sub_obj; + + if (obj_depth == MAX_STACK_ELEMS) + goto cleanup; + sub_value = G_json_value_init_object(); + if (!sub_value) + goto cleanup; + if (G_json_object_set_value(obj, token[i].key, sub_value) != + G_JSONSuccess) { + G_json_value_free(sub_value); + goto cleanup; + } + sub_obj = G_json_object(sub_value); + if (!sub_obj) + goto cleanup; + obj_stack[obj_depth++] = obj; + obj = sub_obj; continue; + } case T_ESO: - if (indent == JSON_MIN_INDENT) - return 0; - indent--; - WRITE_INDENT(f, indent); - WRITE_VAL(f, "}%s\n", comma); + if (obj_depth == 0) + goto cleanup; + obj = obj_stack[--obj_depth]; + continue; + case T_BLN: + if (G_json_object_set_boolean(obj, token[i].key, + token[i].int_val ? 1 : 0) != + G_JSONSuccess) + goto cleanup; + continue; + case T_INT: + if (G_json_object_set_number(obj, token[i].key, token[i].int_val) != + G_JSONSuccess) + goto cleanup; + continue; + case T_STR: + if (G_json_object_set_string(obj, token[i].key, token[i].str_val) != + G_JSONSuccess) + goto cleanup; + continue; + case T_DBL: + case T_MTR: + if (isnan(token[i].dbl_val)) { + if (G_json_object_set_null(obj, token[i].key) != G_JSONSuccess) + goto cleanup; + } + else if (G_json_object_set_number(obj, token[i].key, + token[i].dbl_val) != + G_JSONSuccess) + goto cleanup; continue; default: - val = quote_val(token[i].type, format_token_common(token + i)); - break; + goto cleanup; } - if (!val) - return 0; - WRITE_INDENT(f, indent); - WRITE_VAL(f, "\"%s\": ", token[i].key); - WRITE_VAL(f, "%s", val); - WRITE_VAL(f, "%s\n", comma); } - if (indent != JSON_MIN_INDENT || overflow) - return 0; - WRITE_VAL(f, "%s\n", "}"); - return 1; + if (obj_depth != 0 || overflow) + goto cleanup; + + serialized = G_json_serialize_to_string_pretty(root_value); + if (!serialized) + goto cleanup; + if (fprintf(f, "%s\n", serialized) < 0) + goto cleanup; + ok = 1; + +cleanup: + if (serialized) + G_json_free_serialized_string(serialized); + if (root_value) + G_json_value_free(root_value); + return ok; } static unsigned write_yaml(FILE *f) From 45fe3d2d91d5cfbe57d50ae3d72edbe11500335c Mon Sep 17 00:00:00 2001 From: anirban Date: Thu, 19 Mar 2026 09:09:51 +0530 Subject: [PATCH 2/8] apply clang format changes --- raster/r.geomorphon/profile.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/raster/r.geomorphon/profile.c b/raster/r.geomorphon/profile.c index c8f4eeea06c..80909c1ee27 100644 --- a/raster/r.geomorphon/profile.c +++ b/raster/r.geomorphon/profile.c @@ -317,9 +317,8 @@ static unsigned write_json(FILE *f) if (G_json_object_set_null(obj, token[i].key) != G_JSONSuccess) goto cleanup; } - else if (G_json_object_set_number(obj, token[i].key, - token[i].dbl_val) != - G_JSONSuccess) + else if (G_json_object_set_number( + obj, token[i].key, token[i].dbl_val) != G_JSONSuccess) goto cleanup; continue; default: From 56980a8f4aaf62d62e92ec093723317cdfaef7ff Mon Sep 17 00:00:00 2001 From: anirban Date: Thu, 19 Mar 2026 21:24:57 +0530 Subject: [PATCH 3/8] fixes cmake errors --- .github/workflows/cmake.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index c695834a2dd..30d2665fdf5 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -78,7 +78,8 @@ jobs: cmake --install "${GITHUB_WORKSPACE}/build" --verbose - name: Add the bin directory to PATH run: | - echo "${HOME}/install/bin" >> "${GITHUB_PATH}" + GRASS_BIN=$(dirname $(which grass)) + echo "$GRASS_BIN" >> "${GITHUB_PATH}" - name: Print installed versions if: always() run: .github/workflows/print_versions.sh From 0c32eb98ea88a10c6aa63f47c5d2d91fe86447e9 Mon Sep 17 00:00:00 2001 From: anirban Date: Fri, 20 Mar 2026 07:31:10 +0530 Subject: [PATCH 4/8] links grass_parson to CMakeLists.txt --- raster/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raster/CMakeLists.txt b/raster/CMakeLists.txt index 1e0a989350a..575b2fa1710 100644 --- a/raster/CMakeLists.txt +++ b/raster/CMakeLists.txt @@ -241,7 +241,7 @@ build_program_in_subdir( grass_bitmap ${LIBM}) -build_program_in_subdir(r.geomorphon DEPENDS grass_gis grass_raster grass_gmath +build_program_in_subdir(r.geomorphon DEPENDS grass_gis grass_raster grass_gmath grass_parson ${LIBM}) build_program_in_subdir(r.grow.distance DEPENDS grass_gis grass_raster ${LIBM}) From 35389a12bbb4ca7ad86fd44b670a5c367d717ebd Mon Sep 17 00:00:00 2001 From: anirban Date: Fri, 20 Mar 2026 14:06:42 +0530 Subject: [PATCH 5/8] fixed ci build errors --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 30d2665fdf5..2ba83c2a958 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -78,7 +78,7 @@ jobs: cmake --install "${GITHUB_WORKSPACE}/build" --verbose - name: Add the bin directory to PATH run: | - GRASS_BIN=$(dirname $(which grass)) + GRASS_BIN=$(dirname "$(which grass)") echo "$GRASS_BIN" >> "${GITHUB_PATH}" - name: Print installed versions if: always() From 3b2212956c878f4f230f963d9e89c1eebca38861 Mon Sep 17 00:00:00 2001 From: anirban Date: Sat, 21 Mar 2026 18:59:01 +0530 Subject: [PATCH 6/8] updated cmake.yml to install and add grass to path in same step --- .github/workflows/cmake.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 2ba83c2a958..609885dcc4b 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -73,13 +73,13 @@ jobs: - name: Build run: | cmake --build build --verbose -j"$(nproc)" - - name: Install + - name: Install and add to PATH run: | cmake --install "${GITHUB_WORKSPACE}/build" --verbose - - name: Add the bin directory to PATH - run: | GRASS_BIN=$(dirname "$(which grass)") echo "$GRASS_BIN" >> "${GITHUB_PATH}" + export PATH="GRASS_BIN:$PATH" + which grass # to verify it works - name: Print installed versions if: always() run: .github/workflows/print_versions.sh From 0ccda70fed2ed5cf2bd50f37042d5a072adb8e47 Mon Sep 17 00:00:00 2001 From: anirban Date: Sat, 21 Mar 2026 19:59:29 +0530 Subject: [PATCH 7/8] updated cmake.yml to install and add grass to path --- .github/workflows/cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 609885dcc4b..b3aa8c6124f 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -77,8 +77,8 @@ jobs: run: | cmake --install "${GITHUB_WORKSPACE}/build" --verbose GRASS_BIN=$(dirname "$(which grass)") - echo "$GRASS_BIN" >> "${GITHUB_PATH}" - export PATH="GRASS_BIN:$PATH" + echo "$GRASS_BIN" >> ${GITHUB_PATH} + export PATH="$GRASS_BIN:$PATH" which grass # to verify it works - name: Print installed versions if: always() From e81e651e954f7ad01a8917c65c3c0b2d1307cd7f Mon Sep 17 00:00:00 2001 From: anirban Date: Sat, 21 Mar 2026 20:11:49 +0530 Subject: [PATCH 8/8] reverted all changes made to cmake.yml --- .github/workflows/cmake.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b3aa8c6124f..c695834a2dd 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -73,13 +73,12 @@ jobs: - name: Build run: | cmake --build build --verbose -j"$(nproc)" - - name: Install and add to PATH + - name: Install run: | cmake --install "${GITHUB_WORKSPACE}/build" --verbose - GRASS_BIN=$(dirname "$(which grass)") - echo "$GRASS_BIN" >> ${GITHUB_PATH} - export PATH="$GRASS_BIN:$PATH" - which grass # to verify it works + - name: Add the bin directory to PATH + run: | + echo "${HOME}/install/bin" >> "${GITHUB_PATH}" - name: Print installed versions if: always() run: .github/workflows/print_versions.sh