Blame lasso/extract_sections.py

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