From 2d2583e7579d41730ec6e5a74e4925b6da34f142 Mon Sep 17 00:00:00 2001
From: Munyoki Kilyungi
Date: Mon, 29 Jul 2024 20:47:52 +0300
Subject: Add a script for generating the TTL files.

* generate-ttl-files.scm: New script.

Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
---
 generate-ttl-files.scm | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100755 generate-ttl-files.scm

diff --git a/generate-ttl-files.scm b/generate-ttl-files.scm
new file mode 100755
index 0000000..65db03f
--- /dev/null
+++ b/generate-ttl-files.scm
@@ -0,0 +1,60 @@
+#! ./pre-inst-env
+!#
+(use-modules (ice-9 format)
+             (ice-9 futures)
+             (ice-9 getopt-long)
+             (ice-9 ftw))
+
+(let* ((option-spec
+        '((settings (single-char #\s) (value #t))
+          (output (single-char #\o) (value #t))
+          (documentation (single-char #\d) (value #t))))
+       (options (getopt-long (command-line) option-spec))
+       (settings (option-ref options 'settings #f))
+       (output (option-ref options 'output #f))
+       (documentation (option-ref options 'documentation #f)))
+  (define (enter? name stat result)
+    stat result            ;ignore
+    ;; Skip version control directories if any.
+    (not (member (basename name) '(".git" ".svn" "CVS"))))
+
+  (define (leaf name stat result)
+    stat result                         ;ignore
+    (when (string-suffix? ".scm" name)
+      (let* ((base-file-name (basename name ".scm"))
+             (cmd (format #f " ~a --settings ~a --output ~a --documentation ~a"
+                          name
+                          settings
+                          (string-append output "/" base-file-name ".ttl")
+                          (string-append documentation "/" base-file-name ".md"))))
+        (touch
+         (future
+          (begin
+            (display (format #f "Running ~a" cmd))
+            (display "\n")
+            (system cmd)))))))
+
+  (define (down name stat result)
+    name stat                         ;ignore
+    result)
+
+  (define (up name stat result)
+    name stat                           ;ignore
+    result)
+
+  (define (skip name stat result)
+    name stat                           ;ignore
+    result)
+
+  ;; Ignore unreadable files/directories but warn the user.
+  (define (error name stat errno result)
+    stat                                ;ignore
+    (format (current-error-port) "warning: ~a: ~a~%"
+            name (strerror errno))
+    result)
+
+  (file-system-fold enter? leaf down up skip error
+                    0                  ;initial counter is zero bytes
+                    "./examples"))
+
+
-- 
cgit v1.2.3