#!/usr/local/bin/bash JFLAGS="-d classes" ## remove the ## comment in function show below to ## see in more detail what this script is doing. function show { # echo $name: $* echo_this=mesg_line } function mesg { echo $name: $* } function fail { echo $name: $* exit 1 } function test_args { if [ $# -eq 0 ] then fail no files to compile else show args = $* fi } function test_null { if [ -z "$2" ] then mesg $1 not set? else show $1 = $2 fi } function test_next { test_null $1 $2 if [ -d $2 ] then show $1 = $2 else fail $1 = "$2" is not a directory fi } function test_dirs { test_null CLASSPATH $CLASSPATH test_next DLP_ROOT $DLP_ROOT test_next SWI_EXEC $SWI_EXEC test_next JAVA_ROOT $JAVA_ROOT test_next JIKES_EXEC $JIKES_EXEC } function test_temp { declare -x temp=`pwd`/classes if [ -d $temp ] then show directory $temp exists else mesg creating directory $temp mkdir $temp fi } function test_tool { declare -x dlp_boot=$SWI_EXEC/pl if [ -e $dlp_boot ] then show pl = $dlp_boot else fail no pl command found fi dlp_comp=$DLP_ROOT/lib/execomp.qlf if [ -e $dlp_comp ] then show DLP_COMP = $dlp_comp else fail $dlp_comp doesnt exist fi } function test_java { declare -r javac=$JAVA_ROOT/bin/javac declare -r jikes=$JIKES_EXEC/jikes if [ -e $jikes ] then java_comp=$jikes elif [ -e $javac ] then java_comp=$javac else java_comp="unknown" mesg no java compiler found fail check PATH and JAVA_ROOT or JIKES_EXEC environment variable fi show java compiler = $java_comp } function comp_dtoc { if [ -f $1.pl ] then show compiling $1.pl to classes/$1.java mesg pl -f $dlp_comp -g "(comp('$1.pl','classes/$1.java'),halt)" if pl -f $dlp_comp -g "(comp('$1.pl','classes/$1.java'),halt)" then show compiling classes/$1.java to classes/$1.class mesg $java_comp $JFLAGS classes/$1.java $java_comp $JFLAGS classes/$1.java else rm classes/$1.java fail compilation errors fi else fail file $1.pl doesnt exist fi } function comp_jtoc { if [ -f $1.java ] then show compiling $1.java to classes/$1.class mesg $java_comp $JFLAGS $1.java $java_comp $JFLAGS $1.java else fail file $1.java doesnt exist fi } function comp_list { for i do case $i in *.pl) base=`basename $i .pl` comp_dtoc $base ;; *.java) base=`basename $i .java` comp_jtoc $base ;; *) mesg skipping file $i, unknown file extension skip=skip+1 ;; esac done } declare -i -x file=0 skip=0 declare -r -x name=`basename $0` declare -x java_comp declare -x java_path declare -x dlp_comp test_args $* test_dirs test_temp test_tool test_java comp_list $*