#!/bin/bash

DIR="."

if test $# -ne 0 ; then
  DIR="$1"
fi

# edit the shellcmd.cpp file
sed -e "s/static int cmdArgVal(char\* arg, char type, int\* val)/static int cmdArgVal(char\* arg, char type, void\*\* val)/g" $DIR/shellcmd.cpp > $DIR/shellcmd.cpp.new
sed -e "s/\*val = (int)strtoul(arg, \&tmp, 0)/\*val = (void*)strtoul(arg, \&tmp, 0)/g" $DIR/shellcmd.cpp.new > $DIR/shellcmd.cpp
sed -e "s/\*val = (int)arg;/\*val = (void\*)arg;/g" $DIR/shellcmd.cpp > $DIR/shellcmd.cpp.new
sed -e "s/int     args\[MAX_COMMAND_ARGS\]/void*   args\[MAX_COMMAND_ARGS\]/g" $DIR/shellcmd.cpp.new > $DIR/shellcmd.cpp
rm $DIR/shellcmd.cpp.new

# edit the shellCmd.h file
sed -e "s/typedef int (\*cmdDispatch)(int cmd, int odesc, int flags, int args\[\])/typedef int (\*cmdDispatch)(int cmd, int odesc, int flags, void\* args\[\])/g" $DIR/shellCmd.h > $DIR/shellCmd.h.new
mv $DIR/shellCmd.h.new $DIR/shellCmd.h

# find the cpp equivilant of the dsh file
ls -1 $DIR/*.dsh >& temp.txt
FILE=`sed -e "s/\.dsh/\.cpp/g" temp.txt`

# do the edit
sed -e "s/static int disp(int _cmd_, int _odesc_, int _flags_, int _args_\[\])/static int disp(int _cmd_, int _odesc_, int _flags_, void* _args_\[\])/g" $FILE > $FILE.new
mv $FILE.new $FILE

#clean-up temp storage
rm temp.txt

