' JEXETERM -- vbscript console terminal to run J EXE Server
'    in DOS window command line mode.
' Requires Windows Scripting Host and VBScript.
' This script file needs to be run in console (not window) mode,
'    i.e by cscript.exe rather than wscript.exe
' (C) Copyright Oleg Kobchenko 1998,2001,2004
 
dim JServer, ws, s
 
set ws = WScript
set JServer = CreateObject("JEXEServer.3")
 
ws.StdOut.WriteLine "Welcome to J EXE Terminal. (C) MMIV, olegyk To quit press ^Z [Enter]" & vbCrLf
ws.StdOut.Write "   "
on error resume next
 
jdo "0!:0 <1!:45''"
 
while true
       s = ws.StdIn.ReadLine
       if Err.Number <> 0 then
             ws.StdOut.WriteLine "bye"
             ws.Quit
       end if
 
       wr = jdo(s)
       if Err.Number <> 0 then
             ws.StdOut.WriteLine "|Error " & Err.Number
             ws.StdOut.WriteLine "|" & Err.Description
             Err.Clear
       else
             ws.StdOut.Write wr
       end if
 
       ws.StdOut.Write "   "
wend
 
' set of standard vbscript wrapers to J Automation server
 
Function jdo(exp)
       dim r, er
       er = JServer.DoR(exp, r)
       If er <> 0 then
             jdo = er
             JServer.ErrorTextB er, r
             Err.Clear
             Err.Raise er, exp, r
             Exit Function
       End If
       jdo = r
end Function
 
Function jget(exp)
       dim r, er
       er = JServer.GetB(exp, r)
       If er <> 0 then
             jget = er
             JServer.ErrorTextB er, r
             Err.Clear
             Err.Raise er, exp, r
             Exit Function
       End If
       jget = r
end Function
 
Function jset(v, exp)
       dim r, er
       er = JServer.SetB(v, exp)
       If er <> 0 then
             jset = er
             JServer.ErrorTextB er, r
             Err.Clear
             Err.Raise er, exp, r
             Exit Function
       End If
       jset = 0
end Function
 
Function jscript(exp)
       dim r, er
       er = jset("sexp", exp)
       If er <> 0 then
             jscript = er
             Exit Function
       End If
       er = JServer.DoR("0!:100 sexp", r)
       If er <> 0 then
             jscript = er
             JServer.ErrorTextB er, r
             Err.Clear
             Err.Raise er, exp, r
             Exit Function
       End If
       jscript = 0
end Function