Here's a version of NetRexxC.cmd that is somewhat more sofisticated as it's based on my javarun code that tries to find and use the available java engine on the machine.
//Jan-Erik
/* Translate and compile a NetRexx program */
/* */
/* use as: NetRexxC hello [file2]... */
/* */
/* which will use the NetRexx translator to */
/* translate hello.nrx to hello.java */
/* then will use javac to compile hello.java */
/* */
/* OPTIONS keywords may be added (with a -) before or */
/* after the file specification, along with the extra */
/* flags known to NetRexxC (such as -keep). For */
/* example: */
/* */
/* NetRexxC -keep -format -comments hello */
/* */
/* Invoke with no parameters for a full list of flags. */
/* */
/* To run the class after compilation, specify -run as */
/* an option word. Each file will be run in turn. */
/* */
/* NetRexxC -run hello */
/* */
/* Multiple programs may be specified; in this case */
/* they are all run (if requested) after all compiles. */
/* */
/* ---------- */
/* 1996.09.02 -- handle Warnings from NetRexxC (rc=1) */
/* 1996.12.14 -- use COM.ibm.netrexx.process */
/* 1998.05.25 -- pass NETREXX_JAVA setting to java.exe */
/* 2011.09.01 -- use org.netrexx.process */
/* 2011.09.01 -- remove -xms4M */
parse arg args
w=wordpos('-run', args)
if w>0 then do; run=1; args=delword(args,w,1); end; else run=0
w=wordpos('-nocompile', args)
if w>0 then do; noc=1; end; else noc=0
/* ----- Translate & Compile ----- */
parse source system .
select /* system-specific options */
when system='OS/2' then do
'@echo off'
PARSE SOURCE . . this
CALL SysGetEA this, 'J_PATH', 'j_path'
if LENGTH( j_path ) < 2 THEN DO
SAY 'Searching for installed version of JAVA'
PARSE UPPER VALUE rxFind( 'JAVA.EXE', ' -version', 'OPENJDK VERSION "1.' ) WITH j_path'\BIN'.
IF LENGTH( j_path ) > 0 THEN
CALL SysPutEA this, 'J_PATH', j_path
end
IF TRANSLATE( RIGHT( j_path, 4 ) ) = '\BIN' THEN
j_path = LEFT( j_path, LENGTH( j_path ) - 4 )
CALL SysGetEA this, 'NETRX_PATH', 'netrx_path'
if LENGTH( netrx_path ) < 2 THEN DO
SAY 'Searching for installed version of NetRexx'
PARSE UPPER VALUE rxFind( 'NetRexxC.jar' ) WITH netrx_path'\LIB'.
IF LENGTH( netrx_path ) > 0 THEN
CALL SysPutEA this, 'NETRX_PATH', netrx_path
end
objID = 'NRXC'
netrx_name = 'NetRexxKing'
IF wpsObjectExist( '<WP_'objID'>' ) = 0 THEN
DO
setupstring = 'OBJECTID=<WP_'objID'>;EXENAME='this';PARAMETERS=[Type "-run" (without quotes) to run compiled script] %**P\%**F;ASSOCFILTER=*.nrx;ICONFILE='netrx_path'\'netrx_name'.ico;'
IF SysCreateObject( 'WPProgram', 'NetRexx Compiler / Run', '<WP_DEVFLDR>', setupstring, 'U' ) <> 1 THEN
CALL SysCreateObject 'WPProgram', 'NetRexx Compiler / Run', '<WP_DESKTOP>', setupstring, 'U'
CALL rxAddBigIcon netrx_path'\'netrx_name'.png', '<WP_'objID'>'
END
PARSE UPPER VALUE this WITH this'\BIN'.
IF 0 = POS( this'\LIB', TRANSLATE( VALUE( 'PATH',, 'OS2ENVIRONMENT' ) ) ) THEN
CALL VALUE 'PATH', this'\lib;'VALUE( 'PATH',, 'OS2ENVIRONMENT' ), 'OS2ENVIRONMENT'
IF 0 = POS( TRANSLATE( j_path )'\BIN', TRANSLATE( VALUE( 'PATH',, 'OS2ENVIRONMENT' ) ) ) THEN
CALL VALUE 'PATH', '.;'j_path'\bin;'j_path'\lib;'VALUE( 'PATH',, 'OS2ENVIRONMENT' ), 'OS2ENVIRONMENT'
/* Add option -norestart for OS/2s 1.0.2+ java.exe, for better display */
'java -version 2>&1|rxqueue'; parse pull . '1.' subv ' '
PARSE VALUE subv WITH subv'_'.
javaopts = ''
if subv>=6.0 then CALL VALUE 'CLASSPATH', '.;'this'\lib\NetRexxC.jar;'j_path'\lib\tools.jar', 'ENVIRONMENT'
else if subv>=4.1 then NOP
else if subv>=0.2 then javaopts='-norestart'; else if subv <> '' then do; say subv; javaopts='-noasyncgc'; end
/* Add any options from NETREXX_JAVA environment variable */
if subv < 4.2 then
do
nrjava=value('NETREXX_JAVA',,'ENVIRONMENT')
if nrjava\='' then javaopts=javaopts nrjava
end
else
javaopts=value('NETREXX_JAVA',,'ENVIRONMENT')
end
otherwise
/* Add any options from NETREXX_JAVA environment variable */
javaopts=value('NETREXX_JAVA',,'ENVIRONMENT')
end
do queued(); parse pull .; end
old_trace = TRACE( 'O' )z
'java -version'
'java ' javaopts 'org.netrexx.process.NetRexxC' args
CALL TRACE old_trace
/* ----- Run ----- */
if rc<=1 & run then do
if noc then say 'Run option ignored as -nocompile specified'
else do
/* This section of code is still OS/2-specific */
do forever /* find the file parameters */
parse var args file args
if file='' then leave
if left(file,1)='-' then iterate
filename=filespec('n', file); parse var filename fn '.' fe
/* Now determine the exact case of the class, for java commands */
file=fn'.class'
call SysFileTree file, 'foo.', 'FO'
if foo.0<>1 then do
if foo.0=0 then say 'Cannot find file:' file
if foo.0>1 then
say 'File "'file'" is not a unique specification'
exit 1;
end
file = filespec( 'Name', foo.1 ) /* is now correct case */
parse var file fn '.' fe
say 'Running' fn '...'
'java' fn
end
end
end
ELSE
PARSE PULL
exit rc
rxChk: PROCEDURE
DO WHILE QUEUED() > 0; PARSE PULL; END;
org_trace = TRACE( 'O' )
'@'||ARG(1)||ARG(2)||' 2>>&1 | RXQUEUE'
CALL TRACE org_trace
DO WHILE QUEUED() > 0
IF POS( TRANSLATE( ARG(3) ), TRANSLATE( LINEIN( 'QUEUE:' ) ) ) > 0 THEN
IF LENGTH( ARG(4) ) > 0 THEN RETURN ARG(4)
END
RETURN ''
rxFind: PROCEDURE EXPOSE !_msg_!.
PARSE VALUE REVERSE( SysSearchPath( 'PATH', ARG(1) ) ) WITH .'\'fpath
fpath = REVERSE( fpath )
IF ARG() > 1 & LENGTH( fpath ) > 0 THEN
fspec = rxChk( fpath'\'ARG(1), ARG(2), ARG(3), fpath )
ELSE IF STREAM( fpath'\'ARG(1), 'C', 'QUERY EXISTS' ) <> '' THEN
fspec = fpath
ELSE fspec = ''
IF LENGTH( fspec ) > 0 THEN RETURN fspec
CALL LINEOUT 'STDERR', VALUE( 'PROGRAMS',,'ENVIRONMENT' )
CALL SysFileTree VALUE( 'PROGRAMS',,'ENVIRONMENT' )||'\*'||ARG(1), 'file.', 'SFO'
DO i = 1 TO file.0
PARSE VALUE REVERSE( file.i ) WITH .'\'fspec
IF ARG() > 1 THEN
fspec = rxChk( file.i, ARG(2), ARG(3), REVERSE( fspec ) )
ELSE
fspec = REVERSE( fspec )
IF LENGTH( fspec ) > 0 THEN RETURN fspec
END
drives = SysDriveMap( 'C:', 'USED' )
DO j = 1 TO WORDS( drives )
CALL LINEOUT 'STDERR', SUBWORD( drives, j, 1 )
CALL SysFileTree SUBWORD( drives, j, 1 )||'\*'||ARG(1), 'file.', 'SFO'
DO i = 1 TO file.0
PARSE VALUE REVERSE( file.i ) WITH .'\'fspec
IF ARG() > 1 THEN
fspec = rxChk( file.i, ARG(2), ARG(3), REVERSE( fspec ) )
ELSE
fspec = REVERSE( fspec )
IF LENGTH( fspec ) > 0 THEN RETURN fspec
END
END
RETURN ''
rxAddBigIcon: PROCEDURE EXPOSE !_msg_!. java_path
crlf = D2C(13)D2C(10)
bigicons_dir = VALUE( 'BIGICONS',, 'ENVIRONMENT' )
bigicon = FILESPEC( 'N', ARG(1) )
objid = ARG(2)
IF LENGTH( bigicons_dir ) > 0 THEN
DO
IF STREAM( ( bigicons_dir'\'bigicon ), 'C','QUERY EXISTS') = '' THEN
IF SysCopyObject( ARG(1), bigicons_dir ) = 0 THEN
RETURN 1
IF STREAM( bigicons_dir'\bigicons.txt', 'C', 'QUERY EXIST' ) <> '' THEN
DO
f_size = STREAM( bigicons_dir'\bigicons.txt', 'C', 'QUERY SIZE' )
IF f_size > 0 THEN
DO
input = CHARIN( bigicons_dir'\bigicons.txt', 1, f_size )
CALL STREAM bigicons_dir'\bigicons.txt', 'C', 'CLOSE'
PARSE UPPER VALUE input WITH pre'"'(bigicon)'"'post
IF LENGTH( post ) > 0 THEN RETURN 2
PARSE UPPER VALUE input WITH pre'"'(objid)'"'post
IF LENGTH( post ) > 0 THEN RETURN 3
PARSE VALUE input WITH pre'[OBJECTID]'mid(crlf)(crlf)'['post
input = pre'[OBJECTID]'STRIP( STRIP( mid, 'T', D2C(10) ), 'T', D2C(13) )||crlf||LEFT( '"'objid'"', 28 )'"'bigicon'"'crlf||crlf'['post
CALL SysFileDelete bigicons_dir'\bigicons.txt'
CALL CHAROUT bigicons_dir'\bigicons.txt', input
CALL STREAM bigicons_dir'\bigicons.txt', 'C', 'CLOSE'
END
ELSE RETURN 4
END
END
RETURN 0
/* Code borrowed from REXX Tips & Tricks v3.60 */
wpsObjectExist: PROCEDURE /* parameter: '<new_wps_object_id>', return: 1 exist, 0 doesn't exist, 43 error */
PARSE ARG objID
rc = 43 /* init return/error code 43 = routine not found */
SIGNAL ON SYNTAX NAME ObjectExistError
IF SUBSTR( objID, 2, 1 ) <> ":" THEN
IF LEFT( objID, 1 ) <> "<" & RIGHT( objID, 1 ) <> ">" THEN
objID = "<" || objID || ">"
/* create the object and see if it fail */
tempRC = SysCreateObject( "WPFolder", "TestObject", "<WP_NOWHERE>", "OBJECTID=" || objID || ";", "FAIL" )
IF tempRC = 1 THEN
DO
CALL SysDestroyObject objID
rc = 0
END
ELSE
rc = 1
ObjectExistError:
RETURN rc
Script has now been modified to support 4OS2 as well.
Sept 18, 2019