• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python3
2#
3# Copyright (c) 2017 The Khronos Group Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# makeindex.py - create HTML indices for the OpenGL extension registry
18#
19# Use: makeindex.py key
20# where 'key' is 'arbnumber', 'number', or 'esnumber' for ARB OpenGL,
21# Vendor OpenGL, and OpenGL ES extensions, respectively.
22#
23# Only extensions marked 'public' will be included in the index.
24
25import copy, os, re, string, sys
26
27# Keys in glregistry:
28#   arbnumber   OpenGL ARB extension # (if present)
29#   number      OpenGL vendor/EXT extension # (if present)
30#   esnumber    OpenGL ES extension # (if present)
31#   flags       Set containing one or more of 'public' 'private' 'obsolete' 'incomplete'
32#   url         Relative URL to extension spec
33#   esurl       Relative URL to ES-specific extension spec (if present)
34#   alias       Set of additional extension strings defined in the same document
35#   comments    Arbitrary string with metainformation about the extension
36#   supporters  Set of strings with supporting vendor names (both obsolete
37#               and incomplete - useless save for historical purposes)
38
39def makeLink(name, link):
40    return '<a href="' + url + '">' + name + '</a>'
41
42# See if the specified key of the extension has the specified flag
43def hasFlag(extension, key, flag):
44    return (key in extension and flag in extension[key])
45
46if __name__ == '__main__':
47    if (len(sys.argv) > 1):
48        key = sys.argv[1]
49    else:
50        key = 'number'
51
52    isGLES = (key == 'esnumber')
53
54    # print('makeindex: key =', key)
55
56    # Load the registry
57    file = 'registry.py'
58    exec(open(file).read())
59
60    # Select extensions with the matching key
61    dict = {k:v for k,v in registry.items() if key in v.keys()}
62
63    # print('Filtered', len(dict), 'extensions')
64
65    # Sort matching extensions by the key value
66    sortext = sorted(dict.items(), key = lambda kv : kv[1].get(key))
67
68    # Generate the HTML ordered list of extensions (selecting only public ones)
69    print('<ol>')
70    for (name,ext) in sortext:
71        index = ext.get(key)
72
73        if hasFlag(ext, 'flags', 'public'):
74            # Only select the alternate ES path if we're generating the ES index
75            if (isGLES and 'esurl' in ext):
76                url = ext['esurl']
77            else:
78                url = ext['url']
79
80            # Create the main indexed link
81            print('<li value=', index, '>', makeLink(name, url), sep='')
82
83            if ('alias' in ext):
84                for alias in sorted(ext['alias']):
85                    print('\n    <br> ', makeLink(alias, url), sep='')
86
87            print('</li>')
88    print('</ol>')
89