× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi again,

FWIW, I've attached my own ICONV_H copy book, and I've updated your (Diego's) code to use my copybook. I've also replaced %str() with a based variable (since you're not using null-terminated strings for anything that I can fathom!!) and added a field named OutData that you can view in debug to see that it worked properly.

Code is attached (not sure if it'll make it through the mailing list, but I've CCed Diego directly anyway)

-S


Scott Klement wrote:
Hi Diego,

There are problems with your code -- some are actual bugs that are causing the program to fail, and others are just things I do differently for the sake of readability or maintainability.
/if defined(ICONV_H)
/eof
/endif
/define ICONV_H

/*- +
* Copyright (c) 2006 Scott C. Klement +
* All rights reserved. +
* +
* Redistribution and use in source and binary forms, with or without +
* modification, are permitted provided that the following conditions +
* are met: +
* 1. Redistributions of source code must retain the above copyright +
* notice, this list of conditions and the following disclaimer. +
* 2. Redistributions in binary form must reproduce the above copyright +
* notice, this list of conditions and the following disclaimer in the +
* documentation and/or other materials provided with the distribution. +
* +
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +
* SUCH DAMAGE. +
* +
*/ +

d iconv_t DS qualified
d based(StructureTemplate)
d return_value 10I 0
d cd 10I 0 dim(12)

d QtqCode_T DS qualified
d CCSID 10I 0 inz
d ConvAlt 10I 0 inz
d SubsAlt 10I 0 inz
d ShiftAlt 10I 0 inz
d InpLenOp 10I 0 inz
d ErrorOpt 10I 0 inz
d Reserved 8A inz(*ALLx'00')

d QtqIconvOpen PR extproc('QtqIconvOpen')
d like(iconv_t)
d toCode likeds(QtqCode_t) const
d fromCode likeds(QtqCode_t) const

d iconv PR 10U 0 extproc('iconv')
d cd like(iconv_t) value
d inbuf *
d inbytesleft 10U 0
d outbuf *
d outbytesleft 10U 0

D ICONV_FAIL C CONST(4294967295)

D iconv_close PR 10I 0 extproc('iconv_close')
D cd like(iconv_t) value
h DftActGrp(*NO) BndDir('QC2LE') ActGrp(*NEW)
h*=====================================================================
h* PROGRAMA...:
h* DESCRIPCION:
h* AUTOR......:
h* FECHA......:
h*=====================================================================
/copy iconv_h
d errno Pr 10i 0
d*-----------------------------------------
d* Stand alone fields .
d*-----------------------------------------
d MyData s 32a based(pData)
d pData s * Inz
d pOutData s * Inz
d OutData s 32a based(pOutData)
d err s 10i 0
d hIconv ds Likeds(iconv_t) Inz
d toCde ds likeds(QtqCode_t) inz
d frmCde ds likeds(QtqCode_t) inz
d rc s 10i 0
d inbuf_ptr s *
d inbuf_len s 10u 0
d outbuf_ptr s *
d outbuf_size s 10u 0
d outbuf_left s 10u 0
d output_length s 10i 0
c*=================================================
c*
c* M A I N P R O G R A M
c*
c*=================================================
/free
toCde = *ALLx'00';
frmCde = *ALLx'00';
toCde.CCSID = 819;

hIconv = QtqIconvOpen( toCde : frmCde );
if (hIconv.return_value = -1);
err = errno;
// FIXME: handle error
endif;

pData = %Alloc(%size(MyData));
MyData = 'Diego Acevedo';

inbuf_ptr = pData;
inbuf_len = %size(MyData);

outbuf_size = %size(MyData) * 4;
pOutData = %alloc(outbuf_size);
outbuf_ptr = pOutData;
outbuf_left = outbuf_size;

rc = iconv( hIconv
: inbuf_ptr
: inbuf_len
: outbuf_ptr
: outbuf_left );

if (rc = ICONV_FAIL);
err = errno;
// FIXME: handle error
endif;

if (inbuf_len <> 0);
// FIXME: iconv() could not translate
// the entire string. handle
// error...
endif;

iconv_close(hIconv);

// NOTE: If you want to know the length of
// the output buffer (for example, if
// translating to something like
// UTF-8 where the size of the output
// may vary) you can find out easily:

output_length = outbuf_size - outbuf_left;

dealloc pData;
dealloc pOutData;
*InLR = *On;
Return;
/end-free
c*---------------------------------------------------
c* PROCEDURE: ERRNO
c* PROPOSITO: Retreive error messages.
c*---------------------------------------------------
p errno b Export
d Pi 10i 0
d*------------------------------------
d sys_errno pr * extproc('__errno')
d p_errno s *
d wwreturn s 10i 0 Based(p_errno)
d*---------------------------------------------------
/free
p_errno = sys_errno;
Return wwreturn;
/end-free
p errno e


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.