× 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.



And why aren't we using the 'QtmhGetEnv' API to Get the environment?
I realize it takes a bit of research to get it working, but I'm just
wondering.

Bob Cozzi
cozzi@rpgiv.com
Visit the on-line  Midrange  Developer  forum at: http://www.rpgiv.com


> -----Original Message-----
> From: rpg400-l-admin@midrange.com [mailto:rpg400-l-admin@midrange.com]
On
> Behalf Of Simon Coulter
> Sent: Thursday, January 24, 2002 3:39 PM
> To: Geert Van Landeghem
> Cc: RPG400-L@midrange.com
> Subject: RE: CLASSPATH Api's?
>
>
> Hello Geert,
>
> You should ask these questions on the list so everyone benefits from
the
> answer.  ALthough this is no no longer a Java question and should be
> directed to the RPG400-L list.
>
> C has no idea about fixed-length strings.  Most C functions either
require
> you to pass the length of the data as a separate parameter or they
expect
> null-terminated strings.  Any C function that has a char * string
> definition and no length integer will need a null added to the end of
the
> character data.
>
> You can do that in two ways:  If you define the RPG prototype as a
pointer
> with OPTIONS(*STRING) as you have done then RPG puts a null on the end
BUT
> it doesn't trim the data.  You can define the RPG prototype as
accepting a
> *VARSIZE variable and put the terminating null on yourself.  Neither
> approach is ideal but if you use the keyword VALUE or CONST you don't
need
> to stuff about with the based pointer -- let the compiler do the hard
> work.  You can also use an expression so you could wrap %trim around
the
> variable e.g., eval envptr = getenv(%trim(envvar))
>
> RPG has no idea about null-terminated strings so when you tell it to
> display VALUE it shows all 250 bytes.  Even though you use %TRIM that
will
> only trim blanks and there could be all sorts of crap after the
> terminating null.  However there is a %STR BIF that will extract a
> null-terminated string.
>
> getenv gives you a pointer to a null-terminated string.  You must
> determine the length of that string.  The easiest way to do that is to
use
> the %STR BIF.  You could also call the C function strlen() which
returns
> the length of the string not counting the null.  Then you can simply
> %SUBST the data.
>
> Also, although getenv is exported from the C-runtime it no longer
appears
> to be used.  The C headers eventually map getenv to Qp0zGetEnvNoCCSID
> which is what I use.  The corresponding putenv function is not
exported at
> all and it maps to Qp0zPutEnvNoCCSID.  I couldn't get your prototype
to
> work when passing a literal so I changed it.
>
> I have attached two versions of the code: one using %STR and the other
> using strlen(); take your pick.
>
> Here is a fixed version of your code that uses %STR:
>
> H DFTACTGRP(*NO) BNDDIR('QC2LE') ACTGRP(*NEW)
>
> DGetEnvVar        PR              *   Extproc('Qp0zGetEnvNoCCSID')
> D   Envp                          *   Value options(*string)
>
> D  Valuep         S               *
> D  Value          S            250A   Based(Valuep)
> D  Msg1           S             50A
> D  Msg2           S             50A
>
> C                   Eval      Valuep=GetEnvVar('CLASSPATH')
>
> C                   If        Valuep = *NULL
> C                   Movel(p)  'NULL'        Msg1
> C                   Else
> C                   EVAL      msg1 = %str(valuep: %size(value))
> C                   Eval      Msg2 =%char(%len(%trim(msg1)))
> C     Msg2          dsply
> C                   Endif
>
> C     Msg1          dsply
> C                   Eval      *inlr=*on
>
> Here is a fixed version of your code that uses strlen():
>
> H DFTACTGRP(*NO) BNDDIR('QC2LE') ACTGRP(*NEW)
>
> DGetEnvVar        PR              *   Extproc('Qp0zGetEnvNoCCSID')
> D   Envp                          *   Value options(*string)
> DPutEnvVar        PR            10I 0 Extproc('Qp0zPutEnvNoCCSID')
> D   Envp                          *   Value options(*string)
> D strlen          PR            10I 0 EXTPROC('__strlen')
> D   string                        *   VALUE OPTIONS(*STRING)
>
> D  Valuep         S               *
> D  Value          S            250A   Based(Valuep)
> D  Msg1           S             50A
> D  Msg2           S             50A
>
> C                   Eval      Valuep=GetEnvVar('CLASSPATH')
>
> C                   If        Valuep = *NULL
> C                   Movel(p)  'NULL'        Msg1
> C                   Else
> C                   Eval      Msg2 =%char(strlen(valuep))
> C     Msg2          dsply
> C                   EVAL      msg1 = %SUBST(value:1:strlen(valuep))
> C                   Endif
>
> Regards,
> Simon Coulter.
>
> --------------------------------------------------------------------
>    FlyByNight Software         AS/400 Technical Specialists
>    http://www.flybynight.com.au/
>
>    Phone: +61 3 9419 0175   Mobile: +61 0411 091 400        /"\
>    Fax:   +61 3 9419 0175   mailto: shc@flybynight.com.au   \ /
>                                                              X
>                  ASCII Ribbon campaign against HTML E-Mail  / \
> --------------------------------------------------------------------
>
> _______________________________________________
> This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
list
> To post a message email: RPG400-L@midrange.com
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l
> or email: RPG400-L-request@midrange.com
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/rpg400-l.




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.