Blame lasso/extract_sections.py

Packit 228f82
Packit 228f82
import glob
Packit 228f82
import re
Packit 228f82
import sys
Packit 228f82
import os
Packit 228f82
import os.path
Packit 228f82
Packit 228f82
enable_wsf = False
Packit 228f82
Packit 228f82
if '-wsf' in sys.argv:
Packit 228f82
    enable_wsf = True
Packit 228f82
Packit 228f82
if len(sys.argv) == 2+enable_wsf:
Packit 228f82
    srcdir = sys.argv[1]
Packit 228f82
else:
Packit 228f82
    srcdir = '.'
Packit 228f82
Packit 228f82
for root, dirs, files in os.walk(srcdir):
Packit 228f82
    prefixes = list()
Packit 228f82
    for file in files:
Packit 228f82
        if file.endswith('.c'):
Packit 228f82
            prefixes.append(os.path.splitext(file)[0])
Packit 228f82
    for prefix in prefixes:
Packit 228f82
        try:
Packit 228f82
            header = open(os.path.join(root, prefix + '.h')).read()
Packit 228f82
            implementation = open(os.path.join(root, prefix + '.c')).read()
Packit 228f82
            exported_functions = re.findall('LASSO_EXPORT.*(lasso_\w*)', header)
Packit 228f82
            normal_functions = sorted ([ x for x in exported_functions if not x.endswith('get_type') ])
Packit 228f82
            get_type = [ x for x in exported_functions if x.endswith('get_type') ][0]
Packit 228f82
            file_name = re.findall('lasso_(.*)_get_type', get_type)[0]
Packit 228f82
            try:
Packit 228f82
                macro_type = re.findall('LASSO_(\w*)_CLASS\(', header)[0]
Packit 228f82
            except:
Packit 228f82
                macro_type = None
Packit 228f82
            try:
Packit 228f82
                type = re.findall(r'^struct _(Lasso\w*)', header, re.MULTILINE)[0]
Packit 228f82
            except:
Packit 228f82
                type = None
Packit 228f82
            types = re.findall('^} (Lasso\w*);', header)
Packit 228f82
            def convert(x):
Packit 228f82
                if '%s' in x:
Packit 228f82
                    return x % macro_type
Packit 228f82
                else:
Packit 228f82
                    return x
Packit 228f82
            if type and macro_type:
Packit 228f82
                standard_decl = [ convert(x) for x in [ 'LASSO_%s', 'LASSO_IS_%s', 'LASSO_TYPE_%s', get_type, 'LASSO_%s_CLASS', 'LASSO_IS_%s_CLASS', 'LASSO_%s_GET_CLASS' ] ]
Packit 228f82
                print
Packit 228f82
                print '<SECTION>'
Packit 228f82
                print '<FILE>%s</FILE>' % file_name
Packit 228f82
                print '<TITLE>%s</TITLE>' % type
Packit 228f82
                print type
Packit 228f82
                for x in types + normal_functions:
Packit 228f82
                    print x
Packit 228f82
                print '<SUBSECTION Standard>'
Packit 228f82
                for x in standard_decl:
Packit 228f82
                    print x
Packit 228f82
                print '</SECTION>'
Packit 228f82
        except:
Packit 228f82
            continue
Packit 228f82