gendoc sorta works
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# gendoc vbeta - Generates docs from source comments
|
# gendoc vbeta - Generates docs from source comments
|
||||||
#
|
#
|
||||||
@@ -10,7 +11,6 @@
|
|||||||
# COMPILATION (Linux - POSIX):
|
# COMPILATION (Linux - POSIX):
|
||||||
# ./gendoc.sh
|
# ./gendoc.sh
|
||||||
#
|
#
|
||||||
#
|
|
||||||
# LICENSE: BSD-3-Clause
|
# LICENSE: BSD-3-Clause
|
||||||
#
|
#
|
||||||
# Copyright (c) 2025 GCK
|
# Copyright (c) 2025 GCK
|
||||||
@@ -42,47 +42,75 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
import os
|
import os
|
||||||
|
|
||||||
header = '''
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<style>
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="header"></div>
|
|
||||||
<div class="reference">
|
|
||||||
<pre><code>
|
|
||||||
'''
|
|
||||||
|
|
||||||
footer = '''
|
def extract_blocks(source):
|
||||||
</code></pre>
|
pattern = re.compile(r'/\*-\s*(.*?)\s*-\*/', re.DOTALL)
|
||||||
</div>
|
blocks = pattern.findall(source)
|
||||||
</body>
|
results = []
|
||||||
</html>
|
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
|
def search_directory(directory):
|
||||||
# TODO: Parse for /*- -*/
|
collected = []
|
||||||
# TODO: Add entry to entries arr
|
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):
|
def main(argv):
|
||||||
print(f"call {args[0]}"
|
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 = (
|
||||||
|
"<!DOCTYPE html>\n"
|
||||||
|
"<html>\n"
|
||||||
|
"<head>\n"
|
||||||
|
"<meta charset='utf-8'>\n"
|
||||||
|
"<title>Documentation</title>\n"
|
||||||
|
"<style>\n"
|
||||||
|
"body { font-family: monospace; white-space: pre; }\n"
|
||||||
|
"</style>\n"
|
||||||
|
"</head>\n"
|
||||||
|
"<body>\n<pre><code>\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
footer = (
|
||||||
|
"</code></pre>\n"
|
||||||
|
"</body>\n"
|
||||||
|
"</html>\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
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main(sys.argv))
|
sys.exit(main(sys.argv))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
int foo(int x)
|
int foo(int x);
|
||||||
Addes 34 to the provided integer x.
|
Addes 34 to the provided integer x.
|
||||||
-*/
|
-*/
|
||||||
|
|
||||||
11
build-aux/test/test.c
Normal file
11
build-aux/test/test.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*-
|
||||||
|
bool checkit(bool expr);
|
||||||
|
checks if an exprssion is true.
|
||||||
|
-*/
|
||||||
|
|
||||||
|
_Bool checkit(_Bool expr)
|
||||||
|
{
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user