Using Regular Expressions (regex) in a BSFN

BOster

BOster

Legendary Poster
Anyone ever use regular expressions in a BSFN?

I found the header file uregex.h (and the libs/dll) in ..system\includev\unicode but it doesn't appear to be referenced by jde.h and ..system\includev\unicode doesn't appear to be listed as a header file directory by busbuild and it it doesn't include the libs file when linking. I can work around both of those (dynamic linking, etc.). I am just wondering if JDE has somehow exposed this (or different) regex library some other way.
 
Hey Brian,
Never used any of that stuff in that folder. However, you should be able to avoid the hassle of dynamic linking by using something like the following:

[FONT=Consolas, Courier, monospace]#pragma comment( lib, "icui18n" )

[/FONT][FONT=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]You may have to qualify the library name with a path if the libv32 folder is not part of the library path in BUSBUILD (probably similar to what you needed to do when you #included uregex.h).[/FONT]
 
Jeremy, Good suggestion. Following works (at least on local web dev) - quickly tested by compiling some code that declared a variable and called uregex_close. Compiled and linked.

Code:
#include "../includev/unicode/uregex.h"
#ifdef _MSC_VER
	#pragma comment(lib, "icui18n")
#endif

No relative path needed for the library for some reason, but I needed it for the #include to the header file.

Only downside might be if we move to Linux (which is a possibility). There doesn't appear to be an equivalent for GCC. But I guess we have more control over compiler and linker options on the Enterprise Server so we could specify this in the ES jde.ini???
 
I'm not exactly sure where busbuild gets its INCLUDE and LIB paths from when functions are built.

It may be worth a test to see if the jde.ini (JDE_CG section) is the ticket. It makes sense just by eyeballing it as the libv32 folder is present:

INCLUDES=$(COMP)\VC\include;$(SYSTEM)\include;$(SYSTEM)\cg;$(APP)\include;$(SYSTEM)\includev
LIBS=$(COMP)\VC\lib;$(SYSTEM)\lib32;$(APP)\lib32;$(SYSTEM)\libv32


You could add a $(SYSTEM)\includev\unicode to yours and see if the build works without the relative path qualifier on your #include.
 
Old thread but this project is finally moving into testing and I have now encountered another problem.

The code in the previous posts works fine locally (compiles, links, executes). However, when doing a FULL build on the Enterprise server the build ends in error. It appears there is an error during the link process.

Mon Apr 18 19:08:45 - Executing: 'link @link_cmd >> CCUST.log'.
Mon Apr 18 19:08:46 - builddll.c:2373 BUILDDLL0082 ERROR: Exiting DoTheLink with failure

When we do an update package we don't get error but I did notice that ccust.dll is NOT in the bin32 directory in the package folder. We are not deploying at this point, just trying to troubleshoot the build process.

The library I am trying to link to is ..\system\lib32v\icui18n.lib

This is what is on the enterprise server in the jde.ini:

[JDE_CG]
LIBS=...;$(SYSTEM)\LIB32;$(SYSTEM)\LIBV32;$(APP)\LIB32
...

[BSFN BUILD]
...
LinkLibraries=jdekrnl.lib jdel.lib jdenet.lib jdeipc.lib owver.lib jdeunicode.lib v_verify.lib xerceswrapper.lib xmlpublisher.lib

[SVR]
...
LibVPath=libv32


Do I simply add the icui18n.lib library to the list in LinkLibraries in the jde.ini on the ES server? Any ideas?
 
Last edited:
Brian,

The libv32 folder exists only in the system folder. The lib32 folder in the package only has the libraries for the business functions (i..e no system libraries). Review the .sts and .txt files for errors. Hopefully, it will tell you which function was "unlinkable".
 
Thanks for the info on the libv32 folder. I saw the lib32 folder and incorrectly assumed it was some sort of copy from the system directory (guess I should actually look at the contents before posting). Edit my post to take that stuff out.
 
Hi Brian,

resurrecting this old thread to see if you ever managed to get this working?


To extend a bit on the information shared in this thread so far:
  1. The linker does receive the instruction to use "/DEFAULTLIB:icui18n" from the #pragma, but either cannot find or open the file icui18n.lib, as indicated by the following error message:
    LINK : fatal error LNK1104: cannot open file 'icui18n.lib'
    (The linker log can be found in the "BuildArea", under <PackageName>\obj\CCUSTOM ).
  2. Both the include path to the header file (uregex.h) and the library path to the library file (icui18n.lib) are part of the default configuration in JDE.ini.
 
How I got it working

Building on this thread's inputs I managed to build a BSFN to use RegEx within JDE - thanks for Jeremy and Brian for setting the foundation!

I wanted to briefly share what I did to provide a starting point for others seeking such functionality.

Following are the core parts of the BSFN written as a proof of concept:

Header
Code:
#include "unicode/uregex.h"


#ifdef _MSC_VER
#pragma comment(lib, "../libv32/icui18n.lib")
#endif

Source
This code can be used to extract a particular grouped match. Calling with nGroupNumber=0 will return the entire match, nGroupNumber=1 will return the first group, and so forth.
Code:
    /************************************************************************ 
    *  Variable declarations 
    ************************************************************************/ 
    URegularExpression*     uRegEx  = (URegularExpression*) NULL;
    UParseError             pe      = { 0 };
    UErrorCode              status  = 0;
    UChar                   matching_string[31] = { 0 };
 
   /************************************************************************ 
    * Main Processing 
    ************************************************************************/ 
   if ((!IsStringNull(lpDS->szSearchText) || !IsStringNull(lpDS->szRegEx))
       && !IsStringBlank(lpDS->szRegEx))
   {
       /* compile regex */
       uRegEx = uregex_open((const UChar*)lpDS->szRegEx,
           -1,
           0,
           &pe,
           &status);


       /* load text */
       uregex_setText(uRegEx,
           (const UChar*)lpDS->szSearchText,
           -1,
           &status);


       /* find match */
       if (uregex_find(uRegEx, -1, &status))
       {
           /* extract matching group */
           uregex_group(uRegEx,
               lpDS->nGroupNumber,
               matching_string,
               30,
               &status);


           jdeStrncpy(lpDS->szResult, (JCHAR*)matching_string, DIM(lpDS->szResult) - 1);
       }
       else
       {
           jdeStrcpy(lpDS->szResult, _J("NO MATCH"));
       }
   }
   


   /************************************************************************ 
    * Function Clean Up 
    ************************************************************************/ 
   if (uRegEx != (URegularExpression*)NULL)
   {
       uregex_close(uRegEx);
   }


NOTES:
  • UChar corresponds to JCHAR - they (currently) both map to wchar_t
  • It appears that the linker doesn't get the path to "$(SYSTEM)\LIBV32", as defined in JDE.INI. Maybe it can't resolve the variable $(SYSTEM) or the paths are not set in the environment used by the linker. The workaround works because the path to the lib32 is explicitly passed to the linker and libv32 is located in the same folder.
  • This approach only works for Windows environments, as the "#pragma comment(lib, xxx)" is specific to the Visual Studio toolchain. For other environments you will likely have to change the JDE.INI to tell the linker about the library "icui18n" (e.g. via LinkLibraries ) and where to find it.
  • uregex.h is a C Wrapper to a C++ library. The functions are documented within the header file. For more information on the library/regex: http://userguide.icu-project.org/strings/regexp

Hope this helps!
 
Back
Top