# Regenerates the "Entity notes" table in notes/README.md from the "## " headings of notes/**/*.md. # A heading is indexed when it names an address (6-8 hex digits). Usage: notes_index.py notesdir import glob, os, re, sys d = sys.argv[1] rows = [] for p in sorted(glob.glob(f'{d}/*/*.md')): if '/_tools/' in p: continue for line in open(p): if not line.startswith('## '): continue addrs = re.findall(r'\b(?:0x)?(00[4-9a][0-9a-f]{5}|[4-9a][0-9a-f]{5})\b', line) if not addrs: continue h = line[3:].strip().replace('|', '/') name = re.split(r'[:(—@]| - ', h)[0].strip(' .') rows.append(f"| {name} | {' '.join('0x' + a.lstrip('0') for a in dict.fromkeys(addrs))} | {h} | [{os.path.relpath(p, d)}]({os.path.relpath(p, d)}) |") readme = f'{d}/README.md' s = open(readme).read() a, b = s.index('') + len(''), s.index('') table = '\n| entity | address | heading (what the note covers, status) | file |\n|---|---|---|---|\n' + '\n'.join(sorted(rows, key=str.lower)) + '\n' open(readme, 'w').write(s[:a] + table + s[b:]) print(f'notes_index: {len(rows)} rows')