#!/bin/bash

fixinfo() {
	BASEFILE=$(basename $1 .info)
	INFOFILE=info/$BASEFILE.info
	SGMLFILE=doc/$BASEFILE.sgml

	TITLE=$(sed -ne "s/<title>\(.*\)/\1/p" $SGMLFILE)
	TITLE=${TITLE//&nbsp;/ }
	TITLE=${TITLE//&rsqb;/]}
	TITLE=${TITLE//&lsqb;/[}

	if [ -z "$(grep "^INFO-DIR-SECTION" $INFOFILE)" ]; then
		sed -i "3aINFO-DIR-SECTION Cross-platform development\nSTART-INFO-DIR-ENTRY\n* $BASEFILE: ($BASEFILE).	$TITLE.\nEND-INFO-DIR-ENTRY\n" $INFOFILE
	fi
}

for FILE in "$@"; do
	fixinfo "$FILE"
done
