#! /bin/sh
#
# compile/run/debug project files
#
# this script is invoked via chroot+setuidgid
#
# R. Perry, Jan. 2003
#
# ZZ marks local customization sections
PATH="/vecr/local-bin:/opt/bin:/usr/bin:/usr/ccs/bin"
export PATH
# user PATH, includes ".", by popular demand, in spite of insecurity
#
UPATH="$PATH:."
mode="$1"
top="$2"
sub="$3"
file="$4"
args="$5"
dir="$top/$sub"
cd "$dir" || exit 1
TMP="/htdocs/tmp"
ULAW="/vecr/local-bin/ulaw"
###
# function to present audio
#
view_audio() {
echo "Content-type: text/html\n
VECR/Audio
${user} - ${COURSE}
- ${sub}/${file}
- ${sub}
- Home"
#
umask 022
exec 2>/dev/null
#
if [ "$1" = "file" ]; then
fname="${user}-${COURSE}-${sub}-${file}"
"$ULAW" -e < "$file" > "${TMP}/${fname}"
else
fname="${user}-${COURSE}-${sub}-${file}-$$.audio"
eval $run $args | "$ULAW" -e > "${TMP}/${fname}"
fi
#
echo "
"
exit
}
#
###
text_type="Content-type: text/plain\n"
html_type="Content-type: text/html\n"
type="$text_type"
# ZZ - osp/a9/p1.c runs p1.sh
#
# if [ "$COURSE" = "osp" -a "$sub" = "a9" -a "$file" = "p1.c" -a "$mode" = "run" ]; then
# file="p1.sh"
# fi
case "$file" in
*.c)
name=`basename "$file" .c`
compile="make $name"
preproc="gcc -E -ansi -pedantic -Wall $file | sed '/^ *$/d'"
asm="gcc -S -ansi -pedantic -Wall $file"
asmopt="gcc -S -O3 -ansi -pedantic -Wall $file"
run="./$name"
debug="gdb -x ./gdb.batch -batch ./$name"
;;
*.java)
if [ "$mode" = "debug" ]; then
echo "Content-type: text/plain\n"
echo "debug mode not available for java"
exit 1
fi
name=`basename "$file" .java`
compile="make $name.class"
preproc="echo preproc not available for java"
asm="echo asm not available for java"
asmopt="echo asmopt not available for java"
run="java $name"
;;
*.ss)
if [ "$mode" = "debug" ]; then
echo "Content-type: text/plain\n"
echo "debug mode not available for spreadsheet"
exit 1
fi
name=`basename "$file" .ss`
compile="echo compile not available for spreadsheet"
preproc="echo preproc not available for spreadsheet"
asm="echo asm not available for spreadsheet"
asmopt="echo asmopt not available for spreadsheet"
run="./$name"
;;
*.sh)
name=""
compile="echo can not compile shell script"
preproc="echo preproc not available for sh"
asm="echo asm not available for sh"
asmopt="echo asmopt not available for sh"
run="/opt/bin/ksh ./$file"
debug="/opt/bin/ksh -x ./$file"
;;
*)
if [ "$mode" = "view" -o "$mode" = "cmd" ]; then
:
# file=`echo "$file" | sed -e 's/\.\.//g' -e 's;/;;g'`
else
echo "Content-type: text/plain\n"
echo "Bad file"
exit 1
fi
esac
case "$mode" in
view)
case "$file" in
*.gif) echo "Content-type: image/gif\n";;
*.html) echo "Content-type: text/html\n";;
*.audio) view_audio file; exit;;
*) echo "Content-type: text/plain\n";;
esac
if [ -d "$file" ]; then
cd "$file"
ls -al
else
cat "$file"
fi
;;
compile)
echo "Content-type: text/plain\n"
echo "$compile\n---\n"
$compile # 2>&1 | fmt -25
echo "\n\n---\nDone."
;;
cerr)
echo "Content-type: text/plain\n"
echo "$compile 2>&1 | error\n---\n"
$compile 2>&1 | error
echo "\n\n---\nDone."
;;
preproc)
echo "Content-type: text/plain\n"
echo "$preproc\n---\n"
eval "$preproc"
echo "\n\n---\nDone."
;;
asm)
echo "Content-type: text/plain\n"
echo "$asm\n---\n"
$asm
echo "\n\n---\nDone."
echo "\ncat $name.s\n---\n"
cat "$name.s"
;;
asmopt)
echo "Content-type: text/plain\n"
echo "$asmopt\n---\n"
$asmopt
echo "\n\n---\nDone."
echo "\ncat $name.s\n---\n"
cat "$name.s"
;;
run)
case "$sub" in
iPlot|HTML|SS) type="$html_type" ;;
esac
#
echo "$type"
PATH="$UPATH"
if [ "$type" = "$text_type" ]; then
echo "$run $args\n---\n"
eval $run $args
echo "\n\n---\nExit status = $?"
else
eval $run $args
fi
;;
crun)
echo "Content-type: text/plain\n"
echo "$compile\n---\n"
$compile # 2>&1 | fmt -25
PATH="$UPATH"
echo "\n$run $args\n---\n"
eval $run $args
echo "\n\n---\nExit status = $?"
;;
plot|splot)
echo "Content-type: image/gif\nPragma: no-cache\nExpires: Thu, 01 Dec 1994 16:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0\n"
PATH="$UPATH"
# ZZ
# if [ "$COURSE" = "osp" -a "$sub" = "a7" ]; then
# eval $run $args | "/vecr/local-bin/mazeplot"
# else
# eval $run $args | "/vecr/local-bin/$mode"
# fi
eval $run $args | "/vecr/local-bin/$mode"
;;
audio)
view_audio run
;;
debug)
echo "Content-type: text/plain\n"
echo "$debug"
if [ -n "$name" ]; then # was compiled
echo "run $args\nwhere\nquit" > gdb.batch
cat gdb.batch
fi
echo "---\n"
PATH="$UPATH"
$debug
echo "\n\n---\nDone."
;;
tester)
case "$file" in
p1.*) tester="./test1" ;;
p2.*) tester="./test2" ;;
p3.*) tester="./test3" ;;
p4.*) tester="./test4" ;;
*) tester="echo Bad test request" ;;
esac
echo "Content-type: text/plain\n"
PATH="$UPATH"
echo "$tester"
eval $tester
;;
cmd)
echo "Content-type: text/plain\n"
echo "$args\n---\n"
PATH="$UPATH"
eval $args
;;
*)
echo "Content-type: text/plain\n"
echo "Bad mode"
exit 1
;;
esac