Skip to content

Commit

Permalink
Merge pull request #60 from forderud/gen-rgs
Browse files Browse the repository at this point in the history
Auto-generate RGS files based on IDL file
  • Loading branch information
Jøger Hansegård authored Feb 14, 2018
2 parents abea205 + 66c1d8c commit 19676b4
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions DummyLoader/GenRgsFiles.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

text = """HKCR
{
PROG-NAME.CLASS-NAME.1 = s 'CLASS-NAME Object'
Expand Down Expand Up @@ -50,11 +52,41 @@ def GenRgsFiles(progname, typelib, classes, threadmodel, concat_filename=None):
print('Written '+concat_filename)


if __name__ == "__main__":
# the GUID values here must be unique and in sync with GUIDs in DummyLoader.idl
# Use guidgen.exe to generate them (included with Visual Studio)
classes = [['Image3dFileLoader', '8E754A72-0067-462B-9267-E84AF84828F1'],
['Image3dSource', '6FA82ED5-6332-4344-8417-DEA55E72098C'],
]
def ParseUuidString (str):
uuid = str[str.find('uuid(')+5:]
return uuid[:uuid.find(')')]


def ParseIdl (filename):
'''Parse IDL file to determine library name, typelib GUID and classes with associated GUIDs'''
with open(filename, 'r') as f:
source = f.read()

attribs = '\[[^[]+\]\s*' # detect [...] attribute blocks
name = '\s+[a-zA-Z0-9_]+' # detect coclass/interface name

# find "library" name and associated typelib uuid
for lib_hit in re.findall(attribs+'library'+name, source):
tokens = lib_hit.split()
for token in tokens:
if 'uuid(' in token:
typelib = ParseUuidString(token)
break
libname = tokens[-1]

# find "coclass" names with associated uuids
classes = []
for cls_hit in re.findall(attribs+'coclass'+name, source):
tokens = cls_hit.split()
for token in tokens:
if 'uuid(' in token:
uuid = ParseUuidString(token)
break
classes.append([tokens[-1], uuid])

GenRgsFiles('DummyLoader', '67E59584-3F6A-4852-8051-103A4583CA5E', classes, 'Both')
return libname, typelib, classes


if __name__ == "__main__":
libname, typelib, classes = ParseIdl('DummyLoader.idl')
GenRgsFiles(libname, typelib, classes, 'Both')

0 comments on commit 19676b4

Please sign in to comment.