|
Joep,
<snip>
> I'm not sure I see any advantages of a %TOUPPER() built-in since it
> would be nothing more than a wrapper for the function iconv().
And of course every RPG programmer should be comfortable with a
prototype like:
size_t iconv (cd, inbuf, inbytesleft,
outbuf, outbytesleft)
iconv_t cd;
char **inbuf;
size_t *inbytesleft;
char **outbuf;
size_t *outbytesleft;
BIFs are for wimps; real programmers use APIs.
</snip>
I actually found it easiest to write the API wrappers in C and then just
call the whole wrapper from RPG. This example converts my strings to
ASCII to send over a socket connection.... I think most all RPG
programmers could prototype this two pointer function.
/*
int CvtToASCII(PCHAR Input, PINT InLen)
This function converts EBCDIC to ASCII
Input : Input buffer to be converted
InLen : Length of Input Buffer
Returns: -1 for error
*/
int CvtToASCII(PCHAR Input, PINT InLen)
{
CHAR Ascii_Buf[CNV_BUF_LEN];
PCHAR Sav_Buf = NULL;
CHAR from_code[32];
CHAR to_code[32];
iconv_t adc;
INT rc = 0;
INT Ascii_Len = CNV_BUF_LEN;
PCHAR Ebcdic_Buf = Input;
INT Ebcdic_Len = *InLen;
Sav_Buf = (PCHAR) &Ascii_Buf;
memset((PCHAR) &from_code, 0, sizeof(from_code));
memset((PCHAR) &to_code, 0, sizeof(to_code));
strncpy((PCHAR) &from_code, "IBMCCSID000000000000", 20);
strncpy((PCHAR) &to_code, "IBMCCSID00437", 13);
/* Code Conversion Allocation API */
adc = iconv_open((PCHAR) &to_code, (PCHAR) &from_code);
rc = iconv(adc, (const char**) &Ebcdic_Buf, (unsigned int*)
&Ebcdic_Len,
&Sav_Buf, (unsigned int*) &Ascii_Len);
if (rc != -1)
memcpy(Input, &Ascii_Buf, sizeof(char) * (*InLen));
/* Code Conversion Deallocation API */
iconv_close(adc);
return (rc);
}
Andy
PS - Don't tell David I posted C code (ugly code at that) on the RPG
forum :)
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.