Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

regex in C oder RPG

55 views
Skip to first unread message

Franz...@yahoo.de

unread,
Jan 11, 2006, 6:33:29 AM1/11/06
to
Hello,

I tried to use the C-function regex in RPG. For this, there is a
sourcefile in C in the "C / C++ Programmersguide" and a RPG-program at
"http://www.think400.dk/adhoc_3.htm".
With both programs, I get the message "Failed to match".
First I think, its a problem of the character set. But i can't find
out.

any ideas

kind regards
Franz

Lou

unread,
Jan 11, 2006, 11:25:28 AM1/11/06
to
I am not thrilled about the way the sample code passes the regex_t data
structure. They define the parameter it is passed in as passing by
value, but use the %addr of the data strucure during the actual call. I
would define a pointer to be passed by value and insert/extract the
contents of the data structure into the pointer.

I am not saying this is a problem or the cause of your problem. I have
just had poor luck passing parameters by value using the %addr
function.

Does the person who posted this code say if it is tested and acutally
works? Can you run the sample as is?

Franz...@yahoo.de

unread,
Jan 12, 2006, 2:43:57 AM1/12/06
to

Lou schrieb:

> I am not thrilled about the way the sample code passes the regex_t data
> structure. They define the parameter it is passed in as passing by
> value, but use the %addr of the data strucure during the actual call. I
> would define a pointer to be passed by value and insert/extract the
> contents of the data structure into the pointer.
>
> I am not saying this is a problem or the cause of your problem. I have
> just had poor luck passing parameters by value using the %addr
> function.
>

I debug the rpg-program an see the data in regex_t is changed after the
first procedure regcomp is finished. So I think, the pointing ist
correct

> Does the person who posted this code say if it is tested and acutally
> works?

I have no contact to the person

>Can you run the sample as is?

I compiled without any erros. I run the sample with the string/pattern
of the example and other string/pattern-combinations. Everytime I got
the message: regexec() failed

Franz

Lou

unread,
Jan 12, 2006, 1:49:54 PM1/12/06
to
The only approach I can suggest is trace and dump until you see where
the code is going wrong.

The RPG definitions look propper for calling 'c'. I have written lots
of code that does similar types of calls. I have found that you have to
take a lot of dumps to find the problems. Many times I solve the
problem by changing the function prototypes to pass parameters by value
or not (not meaning pass by reference). I would like to tell you I have
discovered the formula for when you pass by reference and when you pass
by value, but I have not. I have found that memory dumps will show when
a parameter is not being passed correctly.

I wonder why the code is using the align keyword on the data
structures. I have not had good luck using align.

I wonder if ASCII/EDCDIC conversions are needed. I don't know what the
code you are calling is, and what code set it expects.

Thomas Raddatz

unread,
Jan 12, 2006, 5:14:05 PM1/12/06
to Lou
Lou,

The "align" keyword is needed, whenever C structures are not declared as "_Packed". You can think of
the RPG "align" as to be the opposite of the C "_Packed" keyword.

That is why the "align" keyword has to be specified for regex_t:

typedef struct { /* regcomp() data saved for regexec() */
size_t re_nsub; /* # of subexpressions in RE pattern */
void *re_comp; /* compiled RE; freed by regfree() */
int re_cflags; /* saved cflags for regexec() */
size_t re_erroff; /* RE pattern error offset */
size_t re_len; /* # wchar_t chars in compiled pattern */
_LC_colval_t re_ucoll[2]; /* min/max uniq collating values */
void *re_lsub[__REG_SUBEXP_MAX+1]; /* start subexp */
void *re_esub[__REG_SUBEXP_MAX+1]; /* end subexp */
unsigned char re_map[256]; /* maps valid pattern characters*/
mbstate_t re_shift; /* Saved shift state */
short re_dbcs; /* May start with DBCS character */
} regex_t;

Here is a sample of a "_Packed" structure that needs no "align" keyword in RPG:

typedef _Packed struct {
char reserved1[16];
volatile void *const *const in_buf;
volatile void *const *const out_buf;
char reserved2[48];
_RIOFB_T riofb;
char reserved3[32];
const unsigned int buf_length;
char reserved4[28];
volatile char *const in_null_map;
volatile char *const out_null_map;
volatile char *const null_key_map;
char reserved5[48];
const int min_length;
short null_map_len;
short null_key_map_len;
char reserved6[8];
} _RFILE;

typedef char _SYSindara[99];


Thomas Raddatz.


Lou schrieb:

Tools400

unread,
Jan 13, 2006, 4:05:15 AM1/13/06
to
Franz,

I successfully compiled and ran the REGEX program for V5R3, V5R2 and
V5R1. Perhaps we should exchange the source code and look for a typo on
your side.

I also searched the IBM APARs for "regexec" and "regcomp". There are
only two APARs that matches the search criteria. Unfortunately they do
not seem to be related with the problem:

http://www-912.ibm.com/n_dir/nas4apar.nsf/c79815e083182fec862564c00079d117/26c9feb302231e4786256d73003caae3?OpenDocument&Highlight=2,regexec

http://www-912.ibm.com/n_dir/nas4apar.nsf/c79815e083182fec862564c00079d117/8d0407f3e26fda9786256dd7004232f9?OpenDocument&Highlight=2,regexec


Thomas Raddatz.


Franz...@yahoo.de schrieb:

Barbara Morris

unread,
Jan 13, 2006, 6:42:38 PM1/13/06
to

I think you're right that it's a character set problem.

I put that source into a CCSID(37) file and it ran as expected. I
copied it into a CCSID(273) file and changed my job to 273, and compiled
it again, and it got the "Failed to match" error when it ran.

When I corrected the CCSID(273) source so that the backslash and
square-bracket characters \[] were correct, and recompiled, the program
ran fine.

Leif Guldbrand

unread,
Jan 13, 2006, 8:31:41 PM1/13/06
to
Thanks Barbara,

I'll add the problem and your comments into the link @ Think400.dk

Best regards,
Leif

Franz...@yahoo.de

unread,
Jan 16, 2006, 12:08:52 PM1/16/06
to
Hello Barbara,

how do you correct the backslash and square-bracket characters ?

Franz

Barbara Morris

unread,
Jan 16, 2006, 4:47:42 PM1/16/06
to
Franz...@yahoo.de wrote:
>
> Hello Barbara,
>
> how do you correct the backslash and square-bracket characters ?
>

I had my job CCSID in the same CCSID as the source file, and then I just
typed over those characters in SEU to make them look like the backslash
and square brackets. (When I first opened the file, those characters
looked like other strange characters.)

Or you could just change the code to get the string and pattern values
as parameters. Then write another program, to call that program,
passing in the pattern and string. I assume that your usual source
files have a German CCSID, and that when you code that pattern in your
German source file, those characters will be interpreted correctly.)

0 new messages