Created
September 12, 2018 10:32
-
-
Save yekm/31be8a9249ab6b2cb8f5074c66da4bea to your computer and use it in GitHub Desktop.
dumb bash preprocessor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -evx | |
#replace strings like !sg{int peer_id net/receivethread.cpp} to relevant source:line string like net/receivethread.cpp:123 | |
grep -P -o '!sg\{[^\n]+?\}' $1 | sed -e 's/}$//' -e 's/!sg{//' | while read l | |
do | |
file=$(echo "$l" | rev | cut -f 1 -d' ' | rev) | |
pattern=$(echo "$l" | sed -e "s; $file$;;") | |
pointer=$(grep -FnH "$pattern" $file | cut -f 1-2 -d: | head -n1) | |
echo "$file $pattern $pointer" | |
[ -z "$pointer" -o -z "$pattern" -o -z "$file" ] && exit 1 | |
sed -i -e 's$!sg{'"$l"'}$'"$pointer"'$' $1 || exit 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment