Commit ce46312e authored by Michael Hanus 's avatar Michael Hanus

Clean up pakcs help and tool invocation

parent e4046422
......@@ -3,9 +3,7 @@
##############################################################################
# the scripts to be installed
BINS = $(BINDIR)/pakcs $(BINDIR)/pakcs-makecgi \
$(BINDIR)/cleancurry \
$(BINDIR)/pakcs-fcypp
BINS = $(BINDIR)/pakcs $(BINDIR)/cleancurry $(BINDIR)/pakcs-fcypp
.PHONY: all
......
#!/bin/sh
# Compile a Curry program (using the HTML library) into a cgi script
PAKCSBUILDDIR=`echo PAKCSBUILDDIR must be defined here!`
PAKCSINSTALLDIR=
# Define the main directory where PAKCS is installed:
if [ -d "$PAKCSINSTALLDIR" ] ; then
CURRYROOT=$PAKCSINSTALLDIR
else
CURRYROOT=$PAKCSBUILDDIR
fi
# Standard suffix that will be added to the main script:
CGISUFFIX="_CGIMAIN_$$"
# Name of the main function in the main script (should not be in conflict
# with any exported name of the Curry program)
MAINCALL="main_cgi_9999_$$"
CPMEXEC="cypm exec"
ERROR=
HELP=no
CURRYDOPTIONS=
CURRYOPTIONS=":set -time :set -interactive :set -verbose"
COMPACT=no
DEBUG=no
DEBUGFILE=
ULIMIT="-t 120"
MAIN=main
CGIFILE=
WUIJS=no
WUIMODULES=
SERVERTIMEOUT=
STANDALONE=no
LOADBALANCE="-loadbalance standard"
ARGS=
while [ $# -gt 0 -a -z "$ERROR" ]; do
case $1 in
-help | -h | -\? ) HELP=yes ;;
-D* ) CURRYDOPTIONS="$CURRYDOPTIONS $1" ;;
-cpm ) echo 'Option "-cpm" deprecated.' ;;
-cpmexec ) shift ; CPMEXEC=$1 ;;
-compact ) COMPACT=yes ;;
-debug ) DEBUG=yes ;;
-debugfile ) shift ; DEBUGFILE=$1 ;;
-servertimeout ) shift ; SERVERTIMEOUT="-servertimeout $1" ;;
-multipleservers ) LOADBALANCE="-loadbalance multiple" ;; # backward compt.
-loadbalance ) shift ; LOADBALANCE="-loadbalance $1" ;;
-standalone ) STANDALONE=yes ;;
-ulimit ) shift; ULIMIT=$1 ;;
-wuijs ) WUIJS=yes ;;
-wui ) shift; WUIMODULES="$WUIMODULES $1" ;;
-m ) shift; MAIN=$1 ;;
-o ) shift; CGIFILE=$1 ;;
-* ) ERROR="Unknown option: $1" ;;
* ) ARGS="$ARGS $1" ;; # collect non-option arguments
esac
shift
done
if test -n "$ARGS" ; then
set $ARGS
fi
if [ $HELP = yes ] ; then
set "1" ; shift # to show next usage message
fi
if test -n "$ERROR" ; then
echo "ERROR: $ERROR"
set "1" ; shift # to show next usage message
fi
if [ $# != 1 -a $# != 3 ] ; then
echo "USAGE: $0 [options] <curry>"
echo
echo "MAIN OPTIONS:"
echo "-o <cgi> : name of the file (with suffix .cgi) where the cgi program should"
echo " be stored (default: <curry>.cgi)."
echo "-m <form> : Curry expression (of type IO HtmlForm) computing the HTML form"
echo " (default: main)."
echo "<curry> : name of the Curry program (without suffix) containing the script"
echo
echo "FURTHER OPTIONS:"
echo '-Dname=val : define pakcsrc property "name" as "val"'
echo "-cpmexec <c>: set the command to execute programs with the Curry Package"
echo " Manager (default: 'cypm exec')"
echo "-compact : reduce size of generated cgi program by deleting unused functions"
echo "-debug : include code for showing failures"
echo " (= PAKCS options '+printfail/+allfails')"
echo "-debugfile f: include code for storing failure trace in file f"
echo " (= PAKCS options '+consfail file:f')"
echo "-ulimit <l> : set 'ulimit <l>' when executing the cgi program"
echo " (default: '-t 120')"
echo "-servertimeout <ms>: set the timeout for the cgi server process to"
echo " <ms> milliseconds (default: 7200000 / two hours)"
echo "-loadbalance <t>: start new server process if load for one server is"
echo " high where <t> specifies the kind of high load."
echo " Current possible values for <t>:"
echo " no: no load balance"
echo " standard: some standard load balancing (default)"
echo " multiple: new server process for each initial call to"
echo " a cgi script (only reasonable with short timeout)"
echo "-standalone : generate standalone script (i.e., copy programs"
echo " required from PAKCS system to local directory)"
echo "-wuijs : generate JavaScript support code for WUIs"
echo "-wui <mod> : consider also imported module <mod> (that contains WUI"
echo " specifications) when generating JavaScript support code"
exit 1
fi
# Try to locate WUI/JavaScript translator:
WUIJS_PREPROCESSOR=`which curry2js`
if [ ! -x "$WUIJS_PREPROCESSOR" ] ; then
# try to set curry2js to the CPM standard location:
WUIJS_PREPROCESSOR=$HOME/.cpm/bin/curry2js
if [ ! -x "$WUIJS_PREPROCESSOR" ] ; then
WUIJS_PREPROCESSOR=
fi
fi
if [ -z "$WUIJS_PREPROCESSOR" -a $WUIJS = yes ] ; then
echo "No support for JavaScript possible!"
echo "Please install the Curry->JavaScript translator curry2js by:"
echo "> cypm update && cypm install curry2js"
exit 1
fi
# remove possible suffix:
PROG=`expr $1 : '\(.*\)\.lcurry' \| $1`
PROG=`expr $PROG : '\(.*\)\.curry' \| $PROG`
if test -z "$CGIFILE" ; then
CGIFILE=$PROG.cgi
fi
MAINMOD=$PROG$CGISUFFIX
MAINCURRY=$MAINMOD.curry
# compute (relative) name of cgi program:
CGIDIR=`dirname $CGIFILE`
if [ $CGIDIR = "." ] ; then
CGIPROG=$CGIFILE
else
CGIPROG=`expr $CGIFILE : "$CGIDIR/\(.*\)"`
fi
# name of the server:
CGIFILEPATHNAME=`(cd $CGIDIR > /dev/null ; pwd)`
CGISERVERPROG=$CGIPROG.server
CGISERVEREXEC=$CGIFILEPATHNAME/$CGIPROG.server
# unique key for this cgi script:
CGIKEY="$CGIFILEPATHNAME/$CGIPROG `date '+%m/%d/%y/%H/%M/%S'`"
# generate server program implementing the cgi script application:
rm -f $MAINCURRY
echo "module $MAINMOD($MAINCALL) where" >> $MAINCURRY
echo "import $PROG" >> $MAINCURRY
echo "import HTML.Base" >> $MAINCURRY
echo "import HTML.CgiServer" >> $MAINCURRY
echo "$MAINCALL :: IO ()" >> $MAINCURRY
if [ $WUIJS = no ] ; then
echo "$MAINCALL = runFormServerWithKey \"$CGIPROG\" \"$CGIKEY\" ($MAIN)" >> $MAINCURRY
else
CGIBASE=`expr $CGIPROG : '\(.*\)\.cgi' \| $CGIPROG`
JSFILE=$CGIBASE\_wui.js
$CPMEXEC $WUIJS_PREPROCESSOR -wui -o $JSFILE $PROG $WUIMODULES
if [ $? != 0 ] ; then
rm -f $MAINCURRY
exit $?
fi
chmod 644 $JSFILE
if [ $CGIDIR != "." ] ; then
mv $JSFILE $CGIDIR/$JSFILE
fi
echo "$MAINCALL = runFormServerWithKeyAndFormParams \"$CGIPROG\" \"$CGIKEY\" [FormJScript \"$JSFILE\",FormOnSubmit \"return submissionAllowed()\"] ($MAIN)" >> $MAINCURRY
fi
# compile main module:
echo "Generating saved state for initial expression: $MAIN"
echo
if [ $DEBUG = yes ] ; then
PRINTFAIL=":set +allfails :set +printfail"
elif [ -n "$DEBUGFILE" ] ; then
PRINTFAIL=":set +consfail file:$DEBUGFILE"
else
PRINTFAIL=
fi
if [ $COMPACT = yes ] ; then
FCYPP="$FCYPP -compactexport " ; export FCYPP
fi
$CPMEXEC $CURRYROOT/bin/curry --nocypm $CURRYDOPTIONS $CURRYOPTIONS $PRINTFAIL :l $MAINMOD :save $MAINCALL :q
# now the file $MAINMOD should contain the executable computing the HTML form:
if test ! -f $MAINMOD ; then
echo "Error occurred, generation aborted."
$CURRYROOT/bin/cleancurry $MAINMOD
rm -f $MAINMOD.curry
exit 1
fi
# stop old server, if necessary:
if [ -f $CGISERVEREXEC ] ; then
echo "Stop old version of the server '$CGISERVEREXEC'..."
$CURRYROOT/currytools/www/Registry stopscript "$CGISERVEREXEC"
fi
SUBMITFORM="$CURRYROOT/currytools/www/SubmitForm"
# copy executable from the Curry system (if required):
if [ $STANDALONE = yes ] ; then
cp -p "$SUBMITFORM" $CGIFILEPATHNAME/SubmitForm
SUBMITFORM="./SubmitForm"
fi
# generate cgi script:
rm -f $CGIFILE
echo "#!/bin/sh" >> $CGIFILE
echo "$SUBMITFORM $SERVERTIMEOUT $LOADBALANCE \"$CGIPROG\" \"$CGIKEY\" \"$CGISERVEREXEC\" 2> /dev/null" >> $CGIFILE
chmod 755 $CGIFILE
# move compiled executable to final position:
if test -n "$ULIMIT" ; then
TMPFILE=TMPCGIPROLOG$$
echo "#!/bin/sh" > $TMPFILE
echo "ulimit $ULIMIT" >> $TMPFILE
cat $TMPFILE $MAINMOD > $CGISERVEREXEC
rm -f $TMPFILE $MAINMOD
else
mv $MAINMOD $CGISERVEREXEC
fi
chmod 755 $CGISERVEREXEC
$CURRYROOT/bin/cleancurry $MAINMOD
rm -f $MAINMOD.curry
echo "`date`: cgi script compiled" > $CGIFILE.log
echo
echo "New files \"$CGIFILE[.server]\" with compiled cgi script generated."
......@@ -12,77 +12,42 @@ else
fi
export PAKCSHOME
# Add PAKCS bin directory to path so that currypp can be found:
PATH=$PATH:$PAKCSHOME/bin
export PATH
# The bin directory of PAKCS:
PAKCSBIN=$PAKCSHOME/bin
# The directory where CPM installs the binaries:
CPMBIN="$HOME/.cpm/bin"
# check whether some tool is installed by CPM. If yes, execute it,
# otherwise inform the user to install it
check_and_call_tool() {
TOOLPACKAGE=$1
shift
# check whether a requested tool is installed.
# If yes, execute it, otherwise exit with error.
check_and_exec_tool() {
TOOLNAME=$1
TOOLBIN="$CPMBIN"/$TOOLNAME
shift
shift
TOOLBIN="$PAKCSBIN/pakcs-$TOOLNAME"
if [ -x "$TOOLBIN" ] ; then
shift
if [ "$TOOLNAME" = cypm ] ; then
TOOLOPTS="-d curry_bin=$PAKCSHOME/bin/pakcs"
TOOLOPTS="-d curry_bin=$PAKCSBIN/pakcs"
else
TOOLOPTS=
fi
echo "Executing CPM installed tool:" "$TOOLBIN" $TOOLOPTS ${1+"$@"}
# Extend CURRYPATH with system libraries of this installation:
if [ -n "$CURRYPATH" ] ; then
CURRYPATH=$CURRYPATH:$PAKCSHOME/lib
else
CURRYPATH=$PAKCSHOME/lib
fi
export CURRYPATH
#echo "Executing:" "$TOOLBIN" $TOOLOPTS ${1+"$@"}
exec "$TOOLBIN" $TOOLOPTS ${1+"$@"}
else
echo "Curry tool '$TOOLNAME' is not installed!"
echo "Please install it with the Curry Package Manager by:"
echo "> cypm update && cypm install $TOOLPACKAGE"
echo "Incomplete installation: '$TOOLBIN' not installed!"
echo "Please run: cd $PAKCSHOME && make" >&2
exit 1
fi
}
# check whether the real program name and the first argument is a tool
# in the distribution and, if yes, exec the tool
DISTTOOL="$0-$1"
if [ -x "$DISTTOOL" ] ; then
shift
exec "$DISTTOOL" ${1+"$@"}
fi
# check whether the first argument is a tool packaged with CPM and, if yes,
# exec this tool or require its installation (for backward compatibility):
# check whether a tool of the distribution should be executed
case $1 in
addtypes ) check_and_call_tool addtypes curry-addtypes ${1+"$@"} ;;
analyze ) check_and_call_tool cass cass ${1+"$@"} ;;
browse ) check_and_call_tool currybrowse curry-browse ${1+"$@"} ;;
check ) check_and_call_tool currycheck curry-check ${1+"$@"} ;;
cypm ) check_and_call_tool cpm cypm ${1+"$@"} ;;
data2xml ) check_and_call_tool xmldata curry-data2xml ${1+"$@"} ;;
doc ) check_and_call_tool currydoc curry-doc ${1+"$@"} ;;
erd2curry ) check_and_call_tool ertools erd2curry ${1+"$@"} ;;
genmake ) check_and_call_tool makefile curry-genmake ${1+"$@"} ;;
pp ) check_and_call_tool currypp currypp ${1+"$@"} ;;
run ) check_and_call_tool runcurry runcurry ${1+"$@"} ;;
spiceup ) check_and_call_tool spicey curry-spiceup ${1+"$@"} ;;
style ) check_and_call_tool casc curry-style ${1+"$@"} ;;
verify ) check_and_call_tool verify curry-verify ${1+"$@"} ;;
cypm | frontend ) check_and_exec_tool ${1+"$@"} ;;
esac
# check whether we should call CPM to compute the correct load path:
if [ ! -d "$HOME" ] ; then
USECPM=no # do not use CPM without a home directory
elif [ -x $PAKCSHOME/bin/cypm ] ; then
CYPMBIN=$PAKCSHOME/bin/cypm
elif [ -x $PAKCSBIN/cypm ] ; then
CYPMBIN=$PAKCSBIN/cypm
USECPM=yes
elif [ -x $CPMBIN/cypm ] ; then
CYPMBIN=$CPMBIN/cypm
......@@ -90,17 +55,21 @@ elif [ -x $CPMBIN/cypm ] ; then
else
USECPM=no
fi
# check arguments for appropriate settings:
for i in $* ; do
case $i in
--help | -h | -\? ) USECPM=no ;;
--version | -V ) USECPM=no ;;
--nocypm | --numeric-version | --compiler-name | --base-version ) USECPM=no ;;
--numeric-version | --compiler-name | --base-version ) USECPM=no ;;
--nocypm ) USECPM=no ;;
--noreadline ) USERLWRAP=no
esac
done
if [ $USECPM = yes ] ; then
# set CURRYPATH with 'deps' command of CPM
CPMPATH=`"$CYPMBIN" -v quiet -d CURRYBIN="$PAKCSHOME/bin/pakcs" deps -p`
CPMPATH=`"$CYPMBIN" -v quiet -d CURRYBIN="$PAKCSBIN/pakcs" deps -p`
if [ $? -gt 0 ] ; then
echo $CPMPATH
exit 1
......@@ -126,17 +95,11 @@ fi
USERLWRAP=no
if tty -s ; then
RLWRAP=`which rlwrap`
if [ -f "$PAKCSHOME/bin/sicstusprolog" -a -x "$RLWRAP" -a -d "$HOME" ] ; then
if [ -f "$PAKCSBIN/sicstusprolog" -a -x "$RLWRAP" -a -d "$HOME" ] ; then
USERLWRAP=yes
fi
fi
for i in $* ; do
if [ $i = "--noreadline" ] ; then
USERLWRAP=no
fi
done
# do not use rlwrap inside emacs:
if [ "$TERM" = dumb ] ; then
USERLWRAP=no
......
......@@ -231,12 +231,8 @@ writeMainHelp :-
nlErr,
writeLnErr('where <tool> is one of:'),
nlErr,
writeLnErr('browse : browse and analyze'),
writeLnErr('check : check properties'),
writeLnErr('doc : generate documentation for Curry programs'),
writeLnErr('frontend : Curry front end'),
writeLnErr('makecgi : translate Curry HTML program into CGI program'),
writeLnErr('pp : Curry preprocessor'),
writeLnErr('cypm : Curry package manager'),
writeLnErr('frontend : Curry front end'),
nlErr,
writeLnErr('To get more help about the usage of a tool, type'),
nlErr,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment