#!/bin/bash

shopt -s nullglob

function html2twiki() {
	declare	-rx	infile=$1
	declare	-rx	outdir=$2
	declare	-rx	fname=$( sed -n 's/.* member="\([a-zA-Z0-9_.]*\)::\([_a-zA-Z0-9]*\)" .*/\2/p' "${infile}" )
	declare -rx	outfile="${outdir}/${fname}.txt"

	grep -q " member=" "${infile}" || return 0

	sed  '/Generated by/,/anchor/d' "${infile}" > "${outfile}"
}

mkdir -p TWiki/h5_core
mkdir -p TWiki/H5
mkdir -p TWiki/H5Part
mkdir -p TWiki/H5Block
mkdir -p TWiki/H5Fed

for f in ReferencePages/group__h5__core_*.html; do
	html2twiki $f  TWiki/h5_core
done
for f in ReferencePages/group__h5__c__api_*.html; do
	html2twiki $f  TWiki/H5
done
for f in ReferencePages/group__h5part__c__api_*.html; do
	html2twiki $f  TWiki/H5Part
done
for f in ReferencePages/group__h5block__c__api_*.html; do
	html2twiki $f  TWiki/H5Block
done
for f in ReferencePages/group__h5fed__c__api_*.html; do
	html2twiki $f  TWiki/H5Fed
done
