/* StartGnuplot.cmd , startgp.cmd */

/*
   Utility to _temporarily_ set the necessary environment variables for
   the gnuplot binary in the same directory of this utility (often
   called "startgp.cmd").
   You may start it from an arbitrary directory then.
   It passes all command line parameters to the gnuplot executable.
*/

Parse Arg param
Parse Source os env full_name

call setlocal
bindir   = FileSpec("path", full_name)
bindrive = FileSpec("drive", full_name)
binpath  = bindrive || bindir
p = lastpos('\', strip(binpath, 'T', '\'))
gproot   = left(binpath, p)
sharedir = gproot || "share\"
demodir  = gproot || "demo"
path     = Value('PATH',,'OS2ENVIRONMENT')
libpath  = Value('BEGINLIBPATH',,'OS2ENVIRONMENT')
helpfile = binpath || 'gnuplot.gih'
call Value 'GNUHELP', helpfile, 'OS2ENVIRONMENT'
call Value 'GNUPLOT', bindir,   'OS2ENVIRONMENT'
call Value 'BEGINLIBPATH', strip(binpath, 'T', '\')';'libpath, 'OS2ENVIRONMENT'
call Value 'GNUPLOT_DRIVER_DIR', bindir, 'OS2ENVIRONMENT'
call Value 'GNUPLOT_PS_DIR', sharedir || "PostScript", 'OS2ENVIRONMENT'
call Value 'GNUPLOT_LUA_DIR', sharedir || "lua", 'OS2ENVIRONMENT'
call Value 'PATH', path';'binpath, 'OS2ENVIRONMENT'
call Value 'GNUPLOT_LIB', demodir, 'OS2ENVIRONMENT'

/* the actual call to gnuplot */
'@'binpath'gnuplot.exe 'param

call endlocal
exit
