#!/bin/sh
#
# Copyright (C) 2005-2009 FAUmachine Team <info@faumachine.org>.
# This program is free software. You can redistribute it and/or modify it
# under the terms of the GNU General Public License, either version 2 of
# the License, or (at your option) any later version. See COPYING.
#

rom=$1
lst=$2

if [ ! -f ${lst} ] ; then
	touch ${lst}
fi

for start in `grep '^....   -' ${lst} \
		| awk '{ print $1 }' \
		| sort -u`; do
	parm="${parm} -s ${start}h"
done

(
	for start in `grep '^....   ---' ${lst} \
			| awk '{ print $1 }' \
			| sort -u`; do
		echo "${start}   ----------------------------------------"
	done

	grep '^....   -' ${lst} \
	| grep -v -- '-----'

	ndisasm ${parm} ${rom} \
	| grep -v '^ ' \
	| sed -e 's/^0000//'
) \
| sort -u \
> /tmp/xx.$$
mv /tmp/xx.$$ ${lst}
