#!/bin/sh

# chmdeco -- extract files from ITS/CHM files and decompile CHM files
# Copyright (C) 2003 Pabs

# This file is part of chmdeco; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA, 02111-1307, USA or visit:
# http://www.gnu.org

# Decompile
chmdeco $1

# Enter the directory
cd $1

{
	# Print the section name
	/bin/echo -en \\n[TEXT\ POPUPS]\\n;

	# Find text files with the required strings in them
	find -iname \*.txt | xargs grep -l '^[[:space:]]*\.topic[[:space:]]\+[_a-zA-Z0-9]\+'

# Remove the ./, Convert / to \, Convert \n to \r\n and Append to the hhp.
} | sed -e 's/[.]\///g' | tr / '\\' | awk 'BEGIN { ORS = "\r\n" } { print }' >> `find \#recreated -iname \*.hhp`
