Skip to content

Commit fd35f88

Browse files
[libc][docgen] simplify posix links
Usually posix functions have individual doc pages, and each header has its own list of required macro definitions. Use a simpler key of "in-latest-posix" to signal that the URL convention can be followed. Add support for a "removed-in-posix-2008" key which will link to the 2004 docs for functions like bcmp, bcopy, bzero, index, and rindex from strings.h.
1 parent 139e69b commit fd35f88

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

libc/utils/docgen/docgen.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ def check_api(header: Header, api: Dict):
5252
:param api: docgen json file contents parsed into a dict
5353
"""
5454
errors = []
55-
cdef = "c-definition"
56-
pdef = "posix-definition"
55+
# We require entries to have at least one of these.
56+
possible_keys = [
57+
"c-definition",
58+
"in-latest-posix",
59+
"removed-in-posix-2008",
60+
]
5761

5862
# Validate macros
5963
if "macros" in api:
@@ -66,8 +70,8 @@ def check_api(header: Header, api: Dict):
6670
macros = api["macros"]
6771

6872
for name, obj in macros.items():
69-
if not (cdef in obj or pdef in obj):
70-
err = f'error: Macro {name} does not contain at least one required property: "{cdef}" or "{pdef}"'
73+
if (not any(k in obj.keys() for k in possible_keys)):
74+
err = f'error: Macro {name} does not contain at least one required property: {possible_keys}'
7175
errors.append(err)
7276

7377
# Validate functions
@@ -80,8 +84,8 @@ def check_api(header: Header, api: Dict):
8084

8185
fns = api["functions"]
8286
for name, obj in fns.items():
83-
if not (cdef in obj or pdef in obj):
84-
err = f'error: function {name} does not contain at least one required property: "{cdef}" or "{pdef}"'
87+
if (not any(k in obj.keys() for k in possible_keys)):
88+
err = f'error: function {name} does not contain at least one required property: {possible_keys}'
8589
errors.append(err)
8690

8791
if errors:
@@ -104,7 +108,7 @@ def print_tbl_dir(name):
104108
* - {name}
105109
- Implemented
106110
- C23 Standard Section
107-
- POSIX.1-2024 Standard Section"""
111+
- POSIX Docs"""
108112
)
109113

110114

@@ -128,8 +132,10 @@ def print_functions_rst(header: Header, functions: Dict):
128132
else:
129133
print(" -")
130134

131-
if "posix-definition" in functions[name]:
132-
print(f' - {functions[name]["posix-definition"]}')
135+
if "in-latest-posix" in functions[name]:
136+
print(f' - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/{name}.html>`__')
137+
elif "removed-in-posix-2008" in functions[name]:
138+
print(f' - `removed in POSIX.1-2008 <https://pubs.opengroup.org/onlinepubs/007904875/functions/{name}.html>`__')
133139
else:
134140
print(" -")
135141

@@ -154,8 +160,8 @@ def print_macros_rst(header: Header, macros: Dict):
154160
else:
155161
print(" -")
156162

157-
if "posix-definition" in macros[name]:
158-
print(f' - {macros[name]["posix-definition"]}')
163+
if "in-latest-posix" in macros[name]:
164+
print(f' - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/{header.name}.html>`__')
159165
else:
160166
print(" -")
161167
print()

0 commit comments

Comments
 (0)