# txtmus with jsc (webkit2gtk)
# search where are the txtmus scripts
c=$0
if [ `dirname $c` = . ]; then
	c=`which $c`
fi
if [ -L $c ]; then
	c=`realpath $c`
fi
c=`dirname $c`

exec jsc -e "var progdir='${c}/'

// interpreter specific functions
var tm = {
    print: function(str) {
	print(str)
    },
    printErr: function(str) {
	printErr(str)
    },
    quit: function() {
	quit(1)
    },
    readFile: function(fname) {
	try {
		return read(fname)
	} catch(e) {
	}
	return null
    },
    loadjs: function(fn, relay, onerror) {
	try {
		load(progdir + fn)
		if (relay)
			relay()
	} catch(e) {
		if (onerror)
			onerror()
		else
			printErr('Cannot read file ' + fn)
	}
    } // loadjs()
} // tm

load(progdir + 'tmcore-2.js')
load(progdir + 'cmdline.js')

function main(args) {
    var	i = '${TMPATH}'

	console = {
		log: printErr
	}

	if (i)
		tm.path = i.split(':')
	tmcmd('tmjsc', args, 'jsc (webkit2gtk)')
}

if (typeof arguments == 'undefined')
	var arguments = ''

main(arguments)
" -- "$@"
