summaryrefslogtreecommitdiff
path: root/samples/make_contents.cmake
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /samples/make_contents.cmake
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'samples/make_contents.cmake')
-rw-r--r--samples/make_contents.cmake107
1 files changed, 107 insertions, 0 deletions
diff --git a/samples/make_contents.cmake b/samples/make_contents.cmake
new file mode 100644
index 00000000..42f2bead
--- /dev/null
+++ b/samples/make_contents.cmake
@@ -0,0 +1,107 @@
+string (REPLACE " " ";" FILES ${FILES}) # make back into a list
+
+function(JOIN VALUES GLUE OUTPUT)
+ string (REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
+ string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
+ set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
+endfunction()
+
+function (indent)
+ foreach (temp RANGE ${level})
+ file (APPEND ${contents_file} " ")
+ endforeach ()
+endfunction ()
+
+function (end_entry)
+ file (APPEND ${contents_file} "\n")
+ set(first 0 PARENT_SCOPE)
+ math (EXPR level "${level} - 1")
+ indent ()
+ file (APPEND ${contents_file} "]\n")
+ math (EXPR level "${level} - 2")
+ indent ()
+ file (APPEND ${contents_file} "}")
+ string (FIND "${dirs}" "${cwd}" pos)
+ set (level ${level} PARENT_SCOPE)
+endfunction ()
+
+file (WRITE ${contents_file} "[")
+set (cwd)
+set (level 0)
+set (first 1)
+list (SORT FILES)
+foreach (file IN LISTS FILES)
+ string (REGEX MATCHALL "[^/]*/" dirs "${file}")
+ string (REPLACE "/" "" dirs "${dirs}")
+ string (REGEX MATCH "[^/]*$" name "${file}")
+ string (FIND "${dirs}" "${cwd}" pos)
+ list (LENGTH cwd cwd_count)
+ if (${pos} EQUAL 0)
+ # same root
+ while (${cwd_count} GREATER 0)
+ list (REMOVE_AT dirs 0)
+ math (EXPR cwd_count "${cwd_count} - 1")
+ endwhile ()
+ else ()
+ # reduce cwd until matched
+ while ((NOT ${pos} EQUAL 0) AND ${cwd_count} GREATER 0)
+ math (EXPR cwd_count "${cwd_count} - 1")
+ list (REMOVE_AT cwd ${cwd_count})
+ string (FIND "${dirs}" "${cwd}" pos)
+ end_entry ()
+ endwhile ()
+ # back to same root
+ while (${cwd_count} GREATER 0)
+ list (REMOVE_AT dirs 0)
+ math (EXPR cwd_count "${cwd_count} - 1")
+ endwhile ()
+ endif ()
+ list (LENGTH cwd cwd_count)
+ list (LENGTH dirs path_count)
+ while (${path_count} GREATER 0)
+ list (GET dirs 0 dir)
+ list (APPEND cwd "${dir}")
+ list (REMOVE_AT dirs 0)
+ if (${first})
+ file (APPEND ${contents_file} "\n")
+ set (first 0)
+ else ()
+ file (APPEND ${contents_file} ",\n")
+ endif ()
+ indent ()
+ file (APPEND ${contents_file} "{\n")
+ math (EXPR level "${level} + 1")
+ indent ()
+ file (APPEND ${contents_file} "\"type\": \"directory\",\n")
+ indent ()
+ file (APPEND ${contents_file} "\"name\": \"${dir}\",\n")
+ indent ()
+ file (APPEND ${contents_file} "\"entries\": [")
+ set (first 1)
+ math (EXPR level "${level} + 2")
+ math (EXPR path_count "${path_count} - 1")
+ endwhile ()
+ JOIN ("${cwd}" "/" path)
+ file (COPY "${file}" DESTINATION "${DEST}/web/samples/${path}")
+ if (${first})
+ file (APPEND ${contents_file} "\n")
+ set (first 0)
+ else ()
+ file (APPEND ${contents_file} ",\n")
+ endif ()
+ indent ()
+ file (APPEND ${contents_file} "{\n")
+ math (EXPR level "${level} + 1")
+ indent ()
+ file (APPEND ${contents_file} "\"type\": \"file\",\n")
+ indent ()
+ file (APPEND ${contents_file} "\"name\": \"${name}\"\n")
+ math (EXPR level "${level} - 1")
+ indent ()
+ file (APPEND ${contents_file} "}")
+ set (first 0)
+endforeach ()
+if (${level} GREATER 1)
+ end_entry ()
+endif ()
+file (APPEND ${contents_file} "\n]\n")