diff --git a/build-aux/__gendoc.py b/build-aux/__gendoc.py
index 7fef08e..d808167 100644
--- a/build-aux/__gendoc.py
+++ b/build-aux/__gendoc.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python3
#
# gendoc vbeta - Generates docs from source comments
#
@@ -10,7 +11,6 @@
# COMPILATION (Linux - POSIX):
# ./gendoc.sh
#
-#
# LICENSE: BSD-3-Clause
#
# Copyright (c) 2025 GCK
@@ -42,47 +42,75 @@
#
import sys
+import re
import os
-header = '''
-
-
-
-
-
-
-
-
-
-
-
-'''
+def extract_blocks(source):
+ pattern = re.compile(r'/\*-\s*(.*?)\s*-\*/', re.DOTALL)
+ blocks = pattern.findall(source)
+ results = []
+ for block in blocks:
+ lines = [line.strip() for line in block.strip().splitlines() if line.strip()]
+ if not lines:
+ continue
+ decl = lines[0]
+ desc = " ".join(lines[1:]) if len(lines) > 1 else ""
+ results.append([decl, desc])
+ return results
-entry = '''
-%s // %s
-'''
-# TODO: read all files
-# TODO: Parse for /*- -*/
-# TODO: Add entry to entries arr
+def search_directory(directory):
+ collected = []
+ for root, _, files in os.walk(directory):
+ for name in files:
+ if name.endswith(('.c', '.h')):
+ path = os.path.join(root, name)
+ with open(path, 'r', encoding='utf-8', errors='ignore') as f:
+ collected.extend(extract_blocks(f.read()))
+ return collected
-# Entry structure
-#
-# /*- ;Start marker
-# int addTwo(int x) ;Signature
-# Adds two to x ;Description
-# -*/ ;End marker
-def main(args):
- print(f"call {args[0]}"
+def main(argv):
+ source_dir = argv[1] if len(argv) > 1 else "../src"
+ if not os.path.isdir(source_dir):
+ print(f"error: '{source_dir}' is not a directory", file=sys.stderr)
+ return 1
+
+ result = search_directory(source_dir)
+ if not result:
+ return 0
+
+ max_decl_len = max(len(decl) for decl, _ in result)
+ output_path = "gendoc.html"
+
+ header = (
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "Documentation\n"
+ "\n"
+ "\n"
+ "\n\n"
+ )
+
+ footer = (
+ "
\n"
+ "\n"
+ "\n"
+ )
+
+
+ with open(output_path, 'w', encoding='utf-8') as out:
+ out.write(header)
+ for decl, desc in result:
+ out.write(f"{decl.ljust(max_decl_len)} // {desc}\n")
+ out.write(footer)
return 0
+
if __name__ == "__main__":
sys.exit(main(sys.argv))
diff --git a/build-aux/test.c b/build-aux/test/foo.c
similarity index 90%
rename from build-aux/test.c
rename to build-aux/test/foo.c
index 20623ec..24ff358 100644
--- a/build-aux/test.c
+++ b/build-aux/test/foo.c
@@ -1,7 +1,7 @@
#include
/*-
-int foo(int x)
+int foo(int x);
Addes 34 to the provided integer x.
-*/
diff --git a/build-aux/test/test.c b/build-aux/test/test.c
new file mode 100644
index 0000000..cf236db
--- /dev/null
+++ b/build-aux/test/test.c
@@ -0,0 +1,11 @@
+#include
+
+/*-
+bool checkit(bool expr);
+checks if an exprssion is true.
+-*/
+
+_Bool checkit(_Bool expr)
+{
+ return expr;
+}