#!/bin/bash set -eu src="$1" dst="$2" extern_anchor='extern void _tx_timer_interrupt(void);' call_anchor='_tx_timer_interrupt();' mkdir -p "$(dirname "$dst")" tmp1="${dst}.tmp1" line=$(grep -n -F "$extern_anchor" "$src" | head -n 1 | cut -d: -f1) if [ -z "$line" ]; then echo "failed to find _tx_timer_interrupt declaration anchor in input source" >&2 exit 1 fi sed "${line}a\\ void test_interrupt_dispatch(void) __attribute__((weak));\nvoid test_interrupt_dispatch(void) {}" "$src" > "$tmp1" line=$(grep -n -F "$call_anchor" "$tmp1" | head -n 1 | cut -d: -f1) if [ -z "$line" ]; then echo "failed to find _tx_timer_interrupt call anchor in input source" >&2 rm -f "$tmp1" exit 1 fi sed "${line}i\\ test_interrupt_dispatch();" "$tmp1" > "$dst" rm -f "$tmp1"