#!/usr/bin/env python3

if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('input', type=argparse.FileType('r'), help='Input stm32****_system.c file')
    args = parser.parse_args()

    print('/* AUTOGENERATED FILE! Do not edit! */')
    print('/* This file was automatically patched by tools/patch_system_init.py */')
    print()
    print('extern unsigned int g_pfnVectors;')
    print()

    for line in args.input:
        if line.strip().startswith('SCB->VTOR'):
            print('    SCB->VTOR = (uint32_t)&g_pfnVectors;')
        else:
            print(line.rstrip())
