BOSL2/scripts/genindex.sh

66 lines
1.3 KiB
Bash
Raw Normal View History

2019-07-18 06:23:17 +00:00
#!/bin/bash
function ucase
{
echo "$1" | tr '[:lower:]' '[:upper:]'
}
2020-09-01 00:31:55 +00:00
2019-07-18 06:23:17 +00:00
function lcase
{
echo "$1" | tr '[:upper:]' '[:lower:]'
}
2020-09-01 00:31:55 +00:00
function alphaindex
2019-07-18 06:23:17 +00:00
{
alpha="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
2020-09-01 00:31:55 +00:00
TMPFILE=$(mktemp -t $(basename $0).XXXXXX) || exit 1
sort -d -f >> $TMPFILE
2019-07-18 06:23:17 +00:00
for a in $alpha; do
echo -n "[$a](#$(lcase "$a")) "
done
echo
2019-07-18 06:36:55 +00:00
echo
2019-07-18 06:23:17 +00:00
for a in $alpha; do
2019-07-18 06:36:55 +00:00
links=$(cat $TMPFILE | grep -i "^- .[$(lcase "$a")]")
2019-07-18 06:23:17 +00:00
if [ "$links" != "" ]; then
echo "### $(ucase "$a")"
echo "$links"
echo
fi
done
rm -f $TMPFILE
}
2020-09-01 00:31:55 +00:00
function constlist
{
sed 's/([^)]*)//g' | sed 's/[^a-zA-Z0-9_.:$]//g' | awk -F ':' '{printf "- [%s](%s#%s) (in %s)\n", $3, $1, $3, $1}'
}
function constlist2
{
sed 's/ *=.*$//' | sed 's/[^a-zA-Z0-9_.:$]//g' | awk -F ':' '{printf "- [%s](%s#%s) (in %s)\n", $2, $1, $2, $1}'
}
function funclist
{
sed 's/([^)]*)//g' | sed 's/[^a-zA-Z0-9_.:$]//g' | awk -F ':' '{printf "- [%s()](%s#%s) (in %s)\n", $3, $1, $3, $1}'
}
2019-07-18 06:23:17 +00:00
(
2019-07-19 04:58:41 +00:00
echo "## Belfry OpenScad Library Index"
2019-07-18 06:23:17 +00:00
(
2020-09-01 00:31:55 +00:00
(
grep 'Constant: ' *.scad | constlist
grep '^[A-Z]* *=.*//' *.scad | constlist2
) | sort -u
egrep 'Function: |Function&Module: |Module: ' *.scad | sort -u | funclist
) | sort | alphaindex
2019-07-18 06:23:17 +00:00
) > BOSL2.wiki/Index.md