Skip to content

Instantly share code, notes, and snippets.

@yekm
Created September 12, 2018 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yekm/31be8a9249ab6b2cb8f5074c66da4bea to your computer and use it in GitHub Desktop.
Save yekm/31be8a9249ab6b2cb8f5074c66da4bea to your computer and use it in GitHub Desktop.
dumb bash preprocessor
#!/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