#!/bin/sh
#
# DOOM startup script		Charles (int@link.xs4all.nl)
#

   doomdir=~/.doom
   doomsndserver=/usr/games/bin/sndserver
   DOOMWADDIR=/usr/games/lib/doom

   prgname=`basename $0`
   args=$*
   newargs=""


   create_doom_dir()
   {
      if type getkeys &> /dev/null
      then
	  echo -n "$prgname: $doomdir does not exist!  create it? "; ch=`getkeys yn`
	  echo ""
	  if [ "$ch" = "n" ]; then exit 1; fi
      fi

      mkdir $doomdir || (echo "$prgname: failed to create $doomdir"; exit 1)
      echo "$prgname: created $doomdir"
   }

   #
   # expand filenames after -file to the full pathname
   #
   process_cmdline()
   {
      while [ "$1" != "" ];
      do
	newargs="$newargs $1"
	if [ "$1" = "-file" ] || [ "$1" = "-playdemo" ]
	then
	    while [ "$1" != "" ];
	    do
	    shift
	      case $1 in
		   -*)
		      break;;
		   "")
		      return;;
		   /*)
		      newargs="$newargs $1"
		      ;;
		    *)
		      newargs="$newargs `pwd`/$1"
		      ;;
	      esac
	    done
	else
	    shift
	fi
      done
   }

   if [ ! -x $doomdir ]; then create_doom_dir; fi

   process_cmdline $args

   cd $doomdir || (echo "$prgname: can't cd to $doomdir"; exit 1)

   ln -sf $doomsndserver .


   sndcvt -s &

   exec linuxsdoom $newargs #< /dev/null

