From 31c47caa0282cbdf43361a3c0f45fff9699a8814 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 27 Nov 2025 12:35:30 -0500 Subject: Only output files that changed somewhere besides the date --- scripts/mandoc_gen.py | 52 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'scripts') diff --git a/scripts/mandoc_gen.py b/scripts/mandoc_gen.py index 8342e253..1009105e 100755 --- a/scripts/mandoc_gen.py +++ b/scripts/mandoc_gen.py @@ -71,54 +71,64 @@ lb lb lbx lb l l l l. Name Type Description Default''' -def write_method(f, name, info): - def add_line(line): f.write(line + "\n") +def write_method(path, name, info): + lines = [] year = datetime.now().strftime("%Y") date = datetime.now().strftime("%Y-%m-%d") signature = get_signature(name, info) - add_line(template.format(year=year, date=date, name=name, short=info["short"], description=info["description"], signature=signature)) + lines.append(template.format(year=year, date=date, name=name, short=info["short"], description=info["description"], signature=signature)) if "args" in info and info["args"]: - add_line(".SH ARGUMENTS") - add_line(arg_prefix) + lines.append(".SH ARGUMENTS") + lines.append(arg_prefix) for arg,arg_info in info["args"].items(): default = escape(arg_info['default'], spaces=True) if 'default' in arg_info else '-' description = arg_info['description'].replace('\n', ' ') - add_line(f"{arg}\t{arg_info.get('type', '')}\t{description}\t{default}") - add_line(".TE") + lines.append(f"{arg}\t{arg_info.get('type', '')}\t{description}\t{default}") + lines.append(".TE") if "return" in info: - add_line(".SH RETURN") - add_line(info['return'].get('description', 'Nothing.')) + lines.append(".SH RETURN") + lines.append(info['return'].get('description', 'Nothing.')) if "note" in info: - add_line(".SH NOTES") - add_line(info["note"]) + lines.append(".SH NOTES") + lines.append(info["note"]) if "errors" in info: - add_line(".SH ERRORS") - add_line(info["errors"]) + lines.append(".SH ERRORS") + lines.append(info["errors"]) if "example" in info: - add_line(".SH EXAMPLES") - add_line(".EX") - add_line(escape(info['example'])) - add_line(".EE") + lines.append(".SH EXAMPLES") + lines.append(".EX") + lines.append(escape(info['example'])) + lines.append(".EE") + + to_write = '\n'.join(lines) + '\n' + try: + with open(path, "r") as f: + existing = f.read() + if to_write.splitlines()[5:] == existing.splitlines()[5:]: + return + except FileNotFoundError: + pass + + with open(path, "w") as f: + f.write(to_write) + print(f"Updated {path}") def convert_to_markdown(yaml_doc:str)->str: data = yaml.safe_load(yaml_doc) for name,info in data.items(): - with open(f"man/man3/tomo-{name}.3", "w") as f: - print(f"Wrote to man/man3/tomo-{name}.3") - write_method(f, name, data[name]) + write_method(f"man/man3/tomo-{name}.3", name, data[name]) if __name__ == "__main__": import sys if len(sys.argv) > 1: all_files = "" for filename in sys.argv[1:]: - print(f"Making mandoc for {filename}") with open(filename, "r") as f: all_files += f.read() convert_to_markdown(all_files) -- cgit v1.2.3 From 353a1a40173d4722809e2cad215ab734bf68b283 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 29 Nov 2025 13:27:11 -0500 Subject: Improved manpages. --- scripts/mandoc_gen.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/mandoc_gen.py b/scripts/mandoc_gen.py index 1009105e..260bc5d0 100755 --- a/scripts/mandoc_gen.py +++ b/scripts/mandoc_gen.py @@ -71,6 +71,25 @@ lb lb lbx lb l l l l. Name Type Description Default''' +type_template = ''''\\" t +.\\" Copyright (c) {year} Bruce Hill +.\\" All rights reserved. +.\\" +.TH {type} 3 {date} "Tomo man-pages" +.SH NAME +{type} \\- a Tomo type +.SH LIBRARY +Tomo Standard Library +.fi +.SH METHODS +{methods} +''' + +def markdown_to_roff(text): + text = text.replace('\n', ' ') + text = re.sub(r'`([^`]*)`', '\\\\fB\\1\\\\fR', text) + return text + def write_method(path, name, info): lines = [] year = datetime.now().strftime("%Y") @@ -83,7 +102,7 @@ def write_method(path, name, info): lines.append(arg_prefix) for arg,arg_info in info["args"].items(): default = escape(arg_info['default'], spaces=True) if 'default' in arg_info else '-' - description = arg_info['description'].replace('\n', ' ') + description = markdown_to_roff(arg_info['description']) lines.append(f"{arg}\t{arg_info.get('type', '')}\t{description}\t{default}") lines.append(".TE") @@ -105,6 +124,11 @@ def write_method(path, name, info): lines.append(escape(info['example'])) lines.append(".EE") + if "." in name: + type,_ = name.split(".") + lines.append(".SH SEE ALSO") + lines.append(f".BR Tomo-{type} (3)") + to_write = '\n'.join(lines) + '\n' try: with open(path, "r") as f: @@ -118,11 +142,62 @@ def write_method(path, name, info): f.write(to_write) print(f"Updated {path}") +fn_summary_template = ''' +.TP +{signature} +{description} + +For more, see: +.BR Tomo-{type}.{name} (3) +''' + +def fn_summary(type, name, info) -> str: + signature = get_signature(type+"."+name, info) + return fn_summary_template.format( + type=type, + name=name, + signature=signature, + description=markdown_to_roff(info["description"]), + ) + +def write_type_manpage(path, type, methods): + year = datetime.now().strftime("%Y") + date = datetime.now().strftime("%Y-%m-%d") + method_summaries = [fn_summary(type, name, methods[name]) for name in sorted(methods.keys())] + type_manpage = type_template.format( + year=year, + date=date, + type=type, + methods='\n'.join(method_summaries), + ) + + try: + with open(path, "r") as f: + existing = f.read() + if type_manpage.splitlines()[5:] == existing.splitlines()[5:]: + return + except FileNotFoundError: + pass + + with open(path, "w") as f: + f.write(type_manpage) + print(f"Updated {path}") + + def convert_to_markdown(yaml_doc:str)->str: data = yaml.safe_load(yaml_doc) + types = {} for name,info in data.items(): write_method(f"man/man3/tomo-{name}.3", name, data[name]) + if "." in name: + type,fn = name.split(".") + if type not in types: + types[type] = {} + types[type][fn] = info + + for type,methods in types.items(): + write_type_manpage(f"man/man3/tomo-{type}.3", type, methods) if __name__ == "__main__": import sys -- cgit v1.2.3 From a50e2df51a63ab809e700c7c8a28c124c6fef95e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 29 Nov 2025 13:31:37 -0500 Subject: No 'default' column for functions with no defaults --- scripts/mandoc_gen.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/mandoc_gen.py b/scripts/mandoc_gen.py index 260bc5d0..b9cf1cc2 100755 --- a/scripts/mandoc_gen.py +++ b/scripts/mandoc_gen.py @@ -71,6 +71,13 @@ lb lb lbx lb l l l l. Name Type Description Default''' +arg_prefix_no_default = ''' +.TS +allbox; +lb lb lbx +l l l. +Name Type Description''' + type_template = ''''\\" t .\\" Copyright (c) {year} Bruce Hill .\\" All rights reserved. @@ -99,11 +106,16 @@ def write_method(path, name, info): if "args" in info and info["args"]: lines.append(".SH ARGUMENTS") - lines.append(arg_prefix) + has_defaults = any('default' in a for a in info['args'].values()) + lines.append(arg_prefix if has_defaults else arg_prefix_no_default) for arg,arg_info in info["args"].items(): - default = escape(arg_info['default'], spaces=True) if 'default' in arg_info else '-' - description = markdown_to_roff(arg_info['description']) - lines.append(f"{arg}\t{arg_info.get('type', '')}\t{description}\t{default}") + if has_defaults: + default = escape(arg_info['default'], spaces=True) if 'default' in arg_info else '-' + description = markdown_to_roff(arg_info['description']) + lines.append(f"{arg}\t{arg_info.get('type', '')}\t{description}\t{default}") + else: + description = markdown_to_roff(arg_info['description']) + lines.append(f"{arg}\t{arg_info.get('type', '')}\t{description}") lines.append(".TE") if "return" in info: -- cgit v1.2.3