Skip to content

Instantly share code, notes, and snippets.

@willkill07
Created December 10, 2015 02:32
Show Gist options
  • Save willkill07/decaeaaee5526b182277 to your computer and use it in GitHub Desktop.
Save willkill07/decaeaaee5526b182277 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Regenerating README Table"
if [ -a .commit ]
then
rm -f .commit
cat<<'EOF' > .process.awk
#!/usr/bin/env gawk
BEGIN{
FS = "[| \t]+";
l=0;
s=0;
b=0;
w=0;
t=0;
}
{
print;
l+=$2;
s+=$3;
b+=$4;
w+=$5;
t+=$6;
for (i=8;i<=NF;i++) {
val=$i
arr[val]=val;
}
}
END{
out="";
count = asorti(arr,oarr);
for (v=1; v < count; v++) {
out=out" "oarr[v];
}
print "**TOTAL**|**" l "**|**" s "**|**" b "**|**" w "**|**" t "**| |" out;
}
EOF
(awk 'BEGIN{ p = 1 }/^ Day /{ p = 0 }{ if (p == 1) { print } }' README.md
echo " Day | Lines | Code | Bytes | Chars | Time | Source | Headers"
echo ":---:|:-----:|:----:|:-----:|:-----:| ----:|:------:|:-------") > README2.md
for i in src/*/*.cpp
do
id=$(basename $i .cpp)
(sed -r 's/[^0-9]+//g' <<< $id #day
grep -c '^' $i #lines
grep '^[^#]' $i | grep -c '[A-z0-9]' #code
wc -m < $i # bytes
paste -sd' ' < $i | sed -r 's/\s+//g' | wc -m #chars
make run_$id | sed -r '/timing/!d;s/[^0-9.]+//g' | paste -sd'+' | bc | sed -r 's/^\./0./;s/^(.*)\.(....).*$/\1.\2/' #time
sed -r 's|(.*)/(.*)|[\2](https://github.com/willkill07/adventofcode/blob/master/\1/\2)|' <<< $i #source
grep '^#include[^.]*$' $i | sed -r 's/#include [<"](.*)[">]/`\1`/' | sort -s | paste -sd' ' #headers
) | paste -sd '|' >> .temp_file.txt
done
gawk -f .process.awk < .temp_file.txt >> README2.md && mv README{2,}.md && rm -f .temp_file.txt .process.awk
git add README.md
git commit --amend -C HEAD --no-verify
fi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment