... | ... |
@@ -64,6 +64,8 @@ Usage: |
64 | 64 |
glregistry params-tree [<group>] |
65 | 65 |
glregistry audit [<path>] |
66 | 66 |
glregistry audit-tree [<path>] |
67 |
+ glregistry refs <name> |
|
68 |
+ glregistry refs-all <name> |
|
67 | 69 |
glregistry -h|--help |
68 | 70 |
|
69 | 71 |
Commands: |
... | ... |
@@ -115,6 +117,11 @@ Commands: |
115 | 117 |
Search files in <path> if given, or the current directory if omitted, |
116 | 118 |
recursively for OpenGL API names and print them sorted on support, name, |
117 | 119 |
and location, in a tree. |
120 |
+ refs <name> |
|
121 |
+ Print the URLs of all reference pages with name <name>. |
|
122 |
+ refs-all <name> |
|
123 |
+ Print the URLs of all reference pages that mention <name>, sorted on |
|
124 |
+ support, in a tree. |
|
118 | 125 |
|
119 | 126 |
Environment variables: |
120 | 127 |
GLREGISTRY_CACHE |
... | ... |
@@ -27,6 +27,8 @@ Usage: |
27 | 27 |
glregistry params-tree [<group>] |
28 | 28 |
glregistry audit [<path>] |
29 | 29 |
glregistry audit-tree [<path>] |
30 |
+ glregistry refs <name> |
|
31 |
+ glregistry refs-all <name> |
|
30 | 32 |
glregistry -h|--help |
31 | 33 |
|
32 | 34 |
Commands: |
... | ... |
@@ -78,6 +80,11 @@ Commands: |
78 | 80 |
Search files in <path> if given, or the current directory if omitted, |
79 | 81 |
recursively for OpenGL API names and print them sorted on support, name, |
80 | 82 |
and location, in a tree. |
83 |
+ refs <name> |
|
84 |
+ Print all URLs of all reference pages with name <name>. |
|
85 |
+ refs-all <name> |
|
86 |
+ Print all URLs of all reference pages that mention <name>, sorted on |
|
87 |
+ support, in a tree. |
|
81 | 88 |
|
82 | 89 |
Environment variables: |
83 | 90 |
GLREGISTRY_CACHE |
... | ... |
@@ -109,7 +116,9 @@ from lxml import etree |
109 | 116 |
|
110 | 117 |
|
111 | 118 |
## Constants |
119 |
+REFPAGES_URL = 'https://registry.khronos.org/OpenGL-Refpages/' |
|
112 | 120 |
REGISTRY_URL = 'https://registry.khronos.org/OpenGL/' |
121 |
+REFPAGES_GIT = 'https://github.com/KhronosGroup/OpenGL-Refpages' |
|
113 | 122 |
XML_PATH = 'xml/gl.xml' |
114 | 123 |
REGEX = r'\b(gl|GL_)[0-9A-Z][0-9A-Za-z_]+\b' |
115 | 124 |
EXCLUDE_DIRS = ['.?*', '_*'] |
... | ... |
@@ -469,6 +478,49 @@ def audit_tree(xml, path=None): |
469 | 478 |
]) |
470 | 479 |
|
471 | 480 |
|
481 |
+### `refs_` |
|
482 |
+def refs_(name): |
|
483 |
+ local = os.path.join(CACHE, os.path.basename(REFPAGES_GIT)) |
|
484 |
+ if not os.path.exists(local): |
|
485 |
+ os.makedirs(os.path.dirname(local), exist_ok=True) |
|
486 |
+ subprocess.run(['git', 'clone', REFPAGES_GIT, local]) |
|
487 |
+ refs_ = collections.defaultdict(set) |
|
488 |
+ for file, *_ in grep(local, rf'\b{name}\b', [], [], True): |
|
489 |
+ file = removeprefix(f'{local}{os.path.sep}', file) |
|
490 |
+ try: |
|
491 |
+ support, *_, dir, base = os.path.normpath(file).split(os.path.sep) |
|
492 |
+ except: |
|
493 |
+ continue |
|
494 |
+ if support.startswith('gl') and dir.endswith('html'): |
|
495 |
+ support = removeprefix('gl', support) |
|
496 |
+ name, ext = os.path.splitext(base) |
|
497 |
+ url = urllib.parse.urljoin(REFPAGES_URL, file) |
|
498 |
+ if ext in ['.xml', '.xhtml']: |
|
499 |
+ refs_[support].add((name, url)) |
|
500 |
+ return refs_ |
|
501 |
+ |
|
502 |
+ |
|
503 |
+### `refs` |
|
504 |
+def refs(name): |
|
505 |
+ return sorted( |
|
506 |
+ url |
|
507 |
+ for support, locations in refs_(name).items() |
|
508 |
+ for name_, url in locations |
|
509 |
+ if name_ == name |
|
510 |
+ ) |
|
511 |
+ |
|
512 |
+ |
|
513 |
+### `refs_all` |
|
514 |
+def refs_all(name): |
|
515 |
+ for support, locations in sorted(refs_(name).items()): |
|
516 |
+ yield indentjoin(0, ',', [support]) |
|
517 |
+ for name_, url in sorted(locations): |
|
518 |
+ yield indentjoin(1, ':', [ |
|
519 |
+ name_, |
|
520 |
+ url, |
|
521 |
+ ]) |
|
522 |
+ |
|
523 |
+ |
|
472 | 524 |
## Main |
473 | 525 |
def main(): |
474 | 526 |
args = docopt.docopt(__doc__) |
... | ... |
@@ -491,6 +543,8 @@ def main(): |
491 | 543 |
if args['params-tree']: page(params_tree (xml_(), args['<group>'])) |
492 | 544 |
if args['audit']: page(audit (xml_(), args['<path>'])) |
493 | 545 |
if args['audit-tree']: page(audit_tree (xml_(), args['<path>'])) |
546 |
+ if args['refs']: page(refs (args['<name>'])) |
|
547 |
+ if args['refs-all']: page(refs_all (args['<name>'])) |
|
494 | 548 |
|
495 | 549 |
|
496 | 550 |
if __name__ == '__main__': |