Commit 3a2af8b1 authored by norvell's avatar norvell
Browse files

Added scripts/prepare_mem_dryrun.py to prepare memory dry run

parent 8c548cc6
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
#!/bin/python3

import re, os, fnmatch

sub = ['free','malloc','calloc']
dirs = ['./lib_com','./lib_enc','./lib_dec','./lib_rend']
suffix = '*.c'

skip = 0

for d in dirs:
    print(d)
    for path, ds, files in os.walk(d):
        for filename in fnmatch.filter(files, suffix):
            fileIn = os.path.join(path, filename)
            with open(fileIn, 'r') as f_in:
                lines = f_in.readlines()
            with open(fileIn, 'w') as f_out:
                for line in lines:
                    if re.search(r'#define\W+WMC_TOOL_SKIP', line):
                        skip = 1
                    elif re.search(r'#undef\W+WMC_TOOL_SKIP', line):
                        skip = 0
                    else:
                        if not skip:
                            for s in sub:
                                line = re.sub(r'\b%s\b' % (s), '%s' % (s+'_'), line)
                    f_out.write(line)