-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_docs.py
More file actions
83 lines (73 loc) · 2.58 KB
/
Copy pathgen_docs.py
File metadata and controls
83 lines (73 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import re
import glob
# Map C file to category name
cat_names = {
'help_flow.c': 'Control Flow',
'help_io.c': 'Input / Output',
'help_math.c': 'Arithmetic / Math',
'help_strings.c': 'String Functions',
'help_varmem.c': 'Variables & Memory',
'help_fileio.c': 'File I/O',
'help_gfx.c': 'Graphics',
'help_sound.c': 'Sound',
'help_sysenv.c': 'System & Environ',
'help_testing.c': 'Debug & Testing',
'help_progmgmt.c': 'Program Mgmt & Editing',
'help_devices.c': 'Devices & Network',
'help_misc.c': 'Operators',
'help_intro.c': 'Introspection',
'help_sysvar.c': 'System Variables'
}
db = {}
files = glob.glob('source/help/help_*.c')
for file in files:
cat = cat_names.get(os.path.basename(file), 'Uncategorized')
if cat not in db:
db[cat] = []
with open(file, 'r', encoding='utf-8') as f:
for line in f:
match = re.search(r'\{\s*"([^"]+)",\s*"([^"]+)",\s*"([^"]+)"', line)
if match:
kw, desc, usage = match.groups()
db[cat].append((kw, desc, usage))
# Sort everything alphabetically
for cat in db:
db[cat].sort(key=lambda x: x[0])
# Generate CATALOG.TXT
with open('CATALOG.TXT', 'w', encoding='utf-8') as f:
f.write("=== BASIC++ CATALOG ===\n\n")
for cat in sorted(db.keys()):
f.write(f"[{cat}]\n")
kws = [x[0] for x in db[cat]]
col_width = 15
for i in range(0, len(kws), 5):
row = kws[i:i+5]
f.write(" " + "".join(w.ljust(col_width) for w in row) + "\n")
f.write("\n")
# Generate HELP.txt
with open('HELP.txt', 'w', encoding='utf-8') as f:
f.write("=== BASIC++ COMMAND REFERENCE ===\n\n")
for cat in sorted(db.keys()):
f.write(f"[{cat}]\n")
for kw, desc, usage in db[cat]:
f.write(f" {kw.ljust(12)} {desc}\n")
f.write("\n")
# Generate help/quick_reference.TXT
with open('help/quick_reference.TXT', 'w', encoding='utf-8') as f:
f.write("BASIC++ Quick Reference\n\n")
for cat in sorted(db.keys()):
f.write(f"{cat.replace(' ', '')}\n")
for kw, desc, usage in db[cat]:
f.write(f"- {kw}\n")
f.write("\n")
# Generate docs/quick_reference.md
os.makedirs('docs', exist_ok=True)
with open('docs/quick_reference.md', 'w', encoding='utf-8') as f:
f.write("# BASIC++ Quick Reference\n\n")
for cat in sorted(db.keys()):
f.write(f"## {cat}\n")
for kw, desc, usage in db[cat]:
f.write(f"- **{kw}** - {desc}\n")
f.write("\n")
print("Generated documentation files successfully!")