Well met,
I was going through the GnuCOBOL FAQ, looking to clear up any stale links, and the first one I bumped into was an entry from 2009, pointed to a now stale link on opencobol.org. ooRexx integration. Thinking I’d spend a few minutes to refresh the link, was not to go according to plan. The code that embedded ooRexx version 3.5 was no longer functional with ooRexx release 4. Release 4 added 64 bit support, and the early code did not account for this, so it was borked on 64bit hardware. That change ended up being relatively trivial, but interest was piqued and then a round of enhancements began.
GnuCOBOL now supports full extending and embedding of Open Object Rexx. COBOL programs can invoke Rexx scripting with one line of code, thanks to user defined functions, and Rexx can call into compiled COBOL thanks to RegisterFunction and RegisterCommand features of ooRexx.
The FAQ entry has expanded, code to allow
move function rexx(mode, script, host, args, buffer)
to rexx-status
has been published, along with samples that demonstrate RexxRegisterFunctionExe, RexxRegisterFunctionDLL, RexxRegisterComandExe, and RexxRegisterCommandDLL. Exe and DLL forms differ in that Exe is for internal entry points (code local to the application registering the entry) and DLL is for linking to external shared libraries, independent of the local application space. These work both for Windows, and POSIX (GNU/Linux) systems, as well as supporting both 32bit and 64bit hardware.
GnuCOBOL can now easily call internal and external Rexx scripts (with a call to RexxStart, or using the provided function rexx() interface), and Rexx scripts can invoke GnuCOBOL subprograms, as well as sending commands to a “gnucobol” host environment.
The synergy creates a powerful pairing. As part of the unit testing provided with the user function repository, a small Rexx interactive shell is also provided (4 lines of GnuCOBOL) to allow for exploring Rexx instructions, trying external scripts, and testing Rexx command handlers backed by GnuCOBOL subprograms, and binary invocation of GnuCOBOL code as Rexx functions.
Code listings, sample runs and technical documentation can be found at http://opencobol.add1tocobol.com/gnucobol/#can-gnucobol-interface-with-rexx and the current source archive is attached to a post at http://sourceforge.net/p/open-cobol/discussion/contrib/thread/203c5fbd/#2427
(We have plans to move the project space off of SourceForge and will start up a self-hosted Apache Allura installation, likely within the next month). We’ll strive to ensure that no links go stale, and there are appropriate explicit and implicit redirects put in place.
prompt$ LD_LIBRARY_PATH=. rlwrap cobcrun gnucobol-rexx shell For testing in the shell: call cobol arg1,arg2; say result address gnucobol; with command; return rc call cobout 1,2,3; return result ** address extcob; command; return rc ** ** If libtest-cobrexx.so is in search path any Rexx instructions, default address is gnucobol q to quit GnuCOBOL ooRexx test shell: 2015-10-26/20:10:50.00-0400 ooRexx: parse pull name; say "Hello, " || name; return name Flunky Hello, Flunky Status : +00000, +0000000000, +0000000000 Length : 6 Result :Flunky:
ooRexx: parse version v; return v
Status : +00000, +0000000000, +0000000000 Length : 38 Result :REXX-ooRexx_4.1.0(MT) 6.03 17 Aug 2014:
ooRexx: parse verion . level .; return l; 1 *-* parse verion . level .; REX0025E: Error 25: Invalid subkeyword found REX0296E: Error 25.12: PARSE must be followed by one of the keywords ARG, LINEIN, PULL, SOURCE, VALUE, VAR, or VERSION; found "VERION" Status : -00025, -0000000025, +0000000000 Length : 32768 Result ::
ooRexx: parse version . level .; return level Status : +00000, +0000000000, +0000000000 Length : 4 Result :6.03: ooRexx: return 21 * 2 Status : +00042, +0000000000, +0000000000 Length : 2 Result :42: ooRexx: address 'sh'; 'make clean' rm *.c *.i *.c.h *.c.l* gnucobol-rexx.so callrexx oorexxcall Status : +00000, +0000000000, +0000000000 Length : 0 Result :: ooRexx: address 'sh'; 'ls -l' total 7676 -rw-rw-r--. 1 btiffin btiffin 13341 Oct 22 16:01 callrexx.cob -rw-rw-r--. 1 btiffin btiffin 5128 Oct 22 05:32 callrexx.tar.gz -rwxr-xr-x. 1 btiffin btiffin 3775 Oct 21 22:03 example.rex -rwxrwxr-x. 1 btiffin btiffin 19588 Oct 22 21:05 expand-words -rw-rw-r--. 1 btiffin btiffin 4384 Oct 22 21:05 expand-words.cob -rwxrwxr-x. 1 btiffin btiffin 362 Oct 23 03:43 gnucobol.rex -rw-rw-r--. 1 btiffin btiffin 27559 Oct 24 00:26 gnucobol-rexx.cob -rw-rw-r--. 1 btiffin btiffin 780 Oct 24 00:03 gnucobol-rexx.cpy -rw-rw-r--. 1 btiffin btiffin 1388 Oct 23 19:13 gnucobol-rexx.org -rw-rw-r--. 1 btiffin btiffin 12443 Oct 24 00:26 gnucobol-rexx.tar.gz -rw-rw-r--. 1 btiffin btiffin 597 Oct 24 00:22 Makefile -rwxr-xr-x. 1 btiffin btiffin 5280 Oct 22 16:20 month.rex -rwxrwxr-x. 1 btiffin btiffin 123 Oct 21 22:35 mycmd.rex -rwxrwxr-x. 1 btiffin btiffin 107 Oct 21 02:14 MYCMD.REX -rw-rw-r--. 1 btiffin btiffin 6824 Oct 21 18:09 oorexxcall.cob -rw-rw-r--. 1 btiffin btiffin 6805 Oct 21 01:46 oorexx.txt -rw-------. 1 btiffin btiffin 7687367 Oct 23 23:59 rexxref-1.pdf drwxrwxr-x. 2 btiffin btiffin 4096 Oct 21 16:37 sample -rwxr-xr-x. 1 btiffin btiffin 3952 Oct 22 16:05 startrx2.rex -rwxr-xr-x. 1 btiffin btiffin 4099 Oct 22 16:00 startrx3.rex -rwxrwxr-x. 1 btiffin btiffin 38 Oct 21 01:07 version.rex Status : +00000, +0000000000, +0000000000 Length : 0 Result ::
ooRexx: call cobol 1,abc,3,4; return result Status : +00000, +0000000000, +0000000000 Length: 48 Result :Hello from GnuCOBOL, Rexx. 04 arguments received: ooRexx: call cobout 1,abc,3,4,5; return result Status : +00000, +0000000000, +0000000000 Length: 45 Result :05 arguments received. Second argument :ABC: ooRexx: address gnucobol; command string; return rc Status : +00000, +0000000000, +0000000000 Length: 49 Result :By your command. GnuCOBOL received 014 characters: ooRexx: address extcobol; command string; return rc 1 *-* command string; >>> "COMMAND STRING" +++ "RC(30)" Status : +00030, +0000000000, +0000000000 Length: 2 Result :30: ooRexx: address extcob; command string; return rc Status : +00000, +0000000000, +0000000000 Length: 67 Result :External command received 014 characters, first part:COMMAND STRING: ooRexx: q prompt$
Open Object Rexx and GnuCOBOL, a fine pair, and working well together.
Cheers, and have good, everyone
Brian