#!/bin/sh

#
#  fenris - program execution path analysis tool
#  ---------------------------------------------
#
#  Copyright (C) 2001, 2002 by Bindview Corporation
#  Portions Copyright (C) 2001, 2002 by their respective contributors
#  Developed and maintained by Michal Zalewski <lcamtuf@coredump.cx>
#
#  This program is free software; 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
#  (at your option) 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#

echo "ragnarok output file splitter -- written by negative, fixed by lcamtuf"

if [ "$2" = "" ]; then
  echo "Usage: $0 ragnarok_outfile output_dir"
  echo
  exit 1
fi

WHEREIS=./spliter.pl

if [ ! -x spliter.pl ]; then
  WHEREIS=`which spliter.pl 2>/dev/null`
  if [ "$WHEREIS" = "" ]; then
    echo "Error: 'spliter.pl' must be in current directory or in path."
    echo
    exit 1
  fi
fi

$WHEREIS $1 $2

if [ ! -d $2 ]; then
  echo "Error: no output generated."
  echo
  exit 1
fi

cd $2

RULE='s/#A1/index.html/g;s/#A2/calls.html/g;s/#A3/params.html/g;s/#A4/buffers.html/g;s/#A5/io.html/g;s/#A6/raw.html/g;s/#f/calls.html#f/g;s/#d/io.html#d/g;s/#l/raw.html#l/g;s/#S/params.html#S/g;'

# index.html
cat header.txt > index.html
cat index.txt | sed $RULE >> index.html
cat footer.txt >> index.html

# calls.html
cat header.txt > calls.html
cat calls.txt | sed $RULE >> calls.html
cat footer.txt >> calls.html

# params.html
cat header.txt > params.html
cat params.txt | sed $RULE >> params.html
cat footer.txt >> params.html

# buffers.html
cat header.txt > buffers.html
cat buffers.txt | sed $RULE >> buffers.html
cat footer.txt >> buffers.html

# io.html
cat header.txt > io.html
cat io.txt | sed $RULE >> io.html
cat footer.txt >> io.html

# raw.html
cat header.txt > raw.html
cat raw.txt | sed $RULE >> raw.html
cat footer.txt >> raw.html

# delete the unused
rm -f raw.txt footer.txt header.txt io.txt buffers.txt params.txt calls.txt index.txt


