1#!/usr/bin/python3 2# 3# Copyright 2017-2021 The Khronos Group Inc. 4# SPDX-License-Identifier: Apache-2.0 5 6# makeindex.py - create HTML indices for the OpenGL extension registry 7# 8# Use: makeindex.py key 9# where 'key' is 'arbnumber', 'number', 'esnumber', or 'scnumber' for ARB 10# OpenGL, Vendor OpenGL, OpenGL ES, and OpenGL SC extensions, respectively. 11# 12# Only extensions marked 'public' will be included in the index. 13 14import copy, os, re, string, sys 15 16# Keys in glregistry: 17# arbnumber OpenGL ARB extension # (if present) 18# number OpenGL vendor/EXT extension # (if present) 19# esnumber OpenGL ES extension # (if present) 20# scregistry OpenGL SC extension # (if present) 21# flags Set containing one or more of 'public' 'private' 'obsolete' 'incomplete' 22# url Relative URL to extension spec 23# esurl Relative URL to ES-specific extension spec (if present) 24# alias Set of additional extension strings defined in the same document 25# comments Arbitrary string with metainformation about the extension 26# supporters Set of strings with supporting vendor names (both obsolete 27# and incomplete - useless save for historical purposes) 28 29def makeLink(name, link): 30 return '<a href="' + url + '">' + name + '</a>' 31 32# See if the specified key of the extension has the specified flag 33def hasFlag(extension, key, flag): 34 return (key in extension and flag in extension[key]) 35 36if __name__ == '__main__': 37 if (len(sys.argv) > 1): 38 key = sys.argv[1] 39 else: 40 key = 'number' 41 42 isGLES = (key == 'esnumber') 43 44 # print('makeindex: key =', key) 45 46 # Load the registry 47 file = 'registry.py' 48 exec(open(file).read()) 49 50 # Select extensions with the matching key 51 dict = { k : v for k,v in registry.items() if key in v.keys()} 52 53 # print('Filtered', len(dict), 'extensions') 54 55 # Sort matching extensions by the key value 56 sortext = sorted(dict.items(), key = lambda kv : kv[1].get(key)) 57 58 # Generate the HTML ordered list of extensions (selecting only public ones) 59 print('<ol>') 60 for (name,ext) in sortext: 61 index = ext.get(key) 62 63 if hasFlag(ext, 'flags', 'public'): 64 # Only select the alternate ES path if we're generating the ES index 65 if (isGLES and 'esurl' in ext): 66 url = ext['esurl'] 67 else: 68 url = ext['url'] 69 70 # Create the main indexed link 71 print('<li value=', index, '>', makeLink(name, url), sep='') 72 73 if ('alias' in ext): 74 for alias in sorted(ext['alias']): 75 print('\n <br> ', makeLink(alias, url), sep='') 76 77 print('</li>') 78 print('</ol>') 79