* contrib/hbnf/acctyear.prg
* contrib/hbnf/byteneg.prg
* contrib/hbnf/isshare.prg
* contrib/hbnf/sinkey.prg
* contrib/hbnf/kspeed.c
* contrib/hbnf/prtscr.c
* contrib/hbnf/descendn.c
* contrib/hbnf/peek.c
* contrib/hbnf/scancode.prg
* contrib/hbnf/vidmode.prg
* contrib/hbnf/nwsem.prg
* contrib/hbnf/acctadj.prg
* contrib/hbnf/week.prg
* contrib/hbnf/vidcur.prg
* contrib/hbnf/iamidle.c
* contrib/hbnf/miltime.prg
* contrib/hbnf/prtesc.prg
* contrib/hbnf/acctmnth.prg
* contrib/hbnf/proper.c
* contrib/hbnf/savearr.prg
* contrib/hbnf/madd.prg
* contrib/hbnf/rand1.prg
* contrib/hbnf/dispmsg.prg
* contrib/hbnf/fttext.c
* contrib/hbnf/mouse1.prg
* contrib/hbnf/settime.prg
* contrib/hbnf/page.prg
* contrib/hbnf/restsets.prg
* contrib/hbnf/byt2bit.prg
* contrib/hbnf/setkeys.c
* contrib/hbnf/month.prg
* contrib/hbnf/byt2hex.prg
* contrib/hbnf/findith.prg
* contrib/hbnf/at2.prg
* contrib/hbnf/acctweek.prg
* contrib/hbnf/dispc.c
* contrib/hbnf/gcd.prg
* contrib/hbnf/pegs.prg
* contrib/hbnf/min2dhm.prg
* contrib/hbnf/acctqtr.prg
* contrib/hbnf/numlock.c
* contrib/hbnf/dosver.prg
* contrib/hbnf/nooccur.prg
* contrib/hbnf/dayofyr.prg
* contrib/hbnf/metaph.prg
* contrib/hbnf/ontick.c
* contrib/hbnf/menu1.prg
* contrib/hbnf/byteand.prg
* contrib/hbnf/sqzn.prg
* contrib/hbnf/bytexor.prg
* contrib/hbnf/ftidle.c
* contrib/hbnf/workdays.prg
* contrib/hbnf/byteor.prg
* contrib/hbnf/asum.prg
* contrib/hbnf/shift.c
* contrib/hbnf/sleep.prg
* contrib/hbnf/wda.prg
* contrib/hbnf/woy.prg
* contrib/hbnf/aavg.prg
* contrib/hbnf/any2any.prg
* contrib/hbnf/origin.c
* contrib/hbnf/mouse.c
* contrib/hbnf/chdir.c
* contrib/hbnf/adessort.prg
* contrib/hbnf/setdate.prg
* contrib/hbnf/netpv.prg
* contrib/hbnf/amedian.prg
* contrib/hbnf/blink.prg
* contrib/hbnf/stod.c
* contrib/hbnf/vertmenu.prg
* contrib/hbnf/linked.prg
* contrib/hbnf/qtr.prg
* contrib/hbnf/aredit.prg
* contrib/hbnf/n2color.c
* contrib/hbnf/alt.c
* contrib/hbnf/xbox.prg
* contrib/hbnf/ftround.prg
* contrib/hbnf/hex2dec.prg
* contrib/hbnf/getver.c
* contrib/hbnf/nwuid.prg
* contrib/hbnf/dectobin.prg
* contrib/hbnf/aemaxlen.prg
* contrib/hbnf/bitset.prg
* contrib/hbnf/nwlstat.prg
* contrib/hbnf/invclr.prg
* contrib/hbnf/ctrl.c
* contrib/hbnf/popadder.prg
* contrib/hbnf/lastday.prg
* contrib/hbnf/tempfile.prg
* contrib/hbnf/diskfunc.prg
* contrib/hbnf/scregion.prg
* contrib/hbnf/d2e.prg
* contrib/hbnf/mouse2.prg
* contrib/hbnf/ftisprn.c
* contrib/hbnf/pickday.prg
* contrib/hbnf/firstday.prg
* contrib/hbnf/daytobow.prg
* contrib/hbnf/anomatch.prg
* contrib/hbnf/menutonf.prg
* contrib/hbnf/ftattr.c
* contrib/hbnf/pvid.prg
* contrib/hbnf/isbiton.prg
* contrib/hbnf/color2n.c
* contrib/hbnf/isbit.prg
* contrib/hbnf/datecnfg.prg
* contrib/hbnf/cntryset.prg
* contrib/hbnf/putkey.c
* contrib/hbnf/getenvrn.c
* contrib/hbnf/easter.prg
* contrib/hbnf/bytenot.prg
* contrib/hbnf/ntow.prg
* contrib/hbnf/aeminlen.prg
* contrib/hbnf/poke.c
* contrib/hbnf/floptst.prg
* contrib/hbnf/pchr.prg
* contrib/hbnf/savesets.prg
* contrib/hbnf/tbwhile.prg
* contrib/hbnf/mkdir.c
* contrib/hbnf/year.prg
* contrib/hbnf/caplock.c
* contrib/hbnf/rmdir.c
* contrib/hbnf/calendar.prg
* contrib/hbnf/e2d.prg
* contrib/hbnf/elapsed.prg
* contrib/hbnf/sysmem.prg
* contrib/hbnf/bitclr.prg
* contrib/hbnf/eltime.prg
* contrib/hbnf/aading.prg
* contrib/hbnf/dfile.prg
* contrib/hbnf/elapmil.prg
* contrib/hbnf/setlastk.c
* contrib/hbnf/pending.prg
* contrib/hbnf/clrsel.prg
- Stripped NFDOC/HBDOC from source code.
188 lines
4.7 KiB
C
188 lines
4.7 KiB
C
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* File......: getenvrn.c
|
|
* Author....: Rick Whitt
|
|
* CIS ID....: 70672,605
|
|
*
|
|
* This is an original work by Rick Whitt and is placed in the
|
|
* public domain.
|
|
*
|
|
* Modification history:
|
|
* ---------------------
|
|
* Rev 1.2a 09 Sep 1996 JO
|
|
* Added underscore prefix to environ() calls for MSC 8.0
|
|
* Note: 5.2e version will work if linked with MSC OldNames.lib
|
|
*
|
|
* Rev 1.2 01 Jan 1996 03:01:00 TED
|
|
* Added prototypes to kill compiler warning.
|
|
*
|
|
* Rev 1.1 15 Aug 1991 23:08:42 GLENN
|
|
* Forest Belt proofread/edited/cleaned up doc
|
|
*
|
|
* Rev 1.0 17 Jul 1991 22:08:12 GLENN
|
|
* Initial revision.
|
|
*
|
|
*/
|
|
|
|
#include "hbapi.h"
|
|
|
|
#if defined( HB_OS_UNIX )
|
|
# include <unistd.h>
|
|
# if defined( HB_OS_DARWIN )
|
|
# include <crt_externs.h>
|
|
# define environ (*_NSGetEnviron())
|
|
# elif !defined( __WATCOMC__ )
|
|
extern char **environ;
|
|
# endif
|
|
#elif defined( HB_OS_DOS )
|
|
# define environ _environ
|
|
extern char **_environ;
|
|
#elif defined( HB_OS_WIN )
|
|
# include <windows.h>
|
|
#endif
|
|
|
|
#define NORETURN 0
|
|
#define CHARTYPE 1
|
|
#define ARRAYTYPE 2
|
|
#define CRLF "\x0D\x0A"
|
|
|
|
HB_FUNC( FT_GETE )
|
|
{
|
|
#if defined( HB_OS_DOS ) || defined( HB_OS_UNIX )
|
|
{
|
|
char *buffer = NULL;
|
|
int x;
|
|
int buffsize = 0;
|
|
int rettype = NORETURN;
|
|
|
|
if( HB_ISCHAR( 1 ) )
|
|
rettype = CHARTYPE;
|
|
if( HB_ISARRAY( 1 ) )
|
|
rettype = ARRAYTYPE;
|
|
|
|
/* scan strings first and add up total size */
|
|
if( rettype == CHARTYPE )
|
|
{
|
|
for( x = 0; environ[x]; x++ )
|
|
{
|
|
/* add length of this string plus 2 for the crlf */
|
|
buffsize += ( strlen( environ[x] ) + 2 );
|
|
}
|
|
/* add 1 more byte for final nul character */
|
|
buffsize++;
|
|
/* now allocate that much memory and make sure 1st byte is a nul */
|
|
buffer = ( char * ) hb_xgrab( buffsize + 1 );
|
|
buffer[0] = '\0';
|
|
}
|
|
|
|
for( x = 0; environ[x]; x++ )
|
|
{
|
|
if( !environ[x] )
|
|
/* null string, we're done */
|
|
break;
|
|
|
|
if( rettype == CHARTYPE )
|
|
{
|
|
/* tack string onto end of buffer */
|
|
hb_strncat( buffer, environ[x], buffsize );
|
|
/* add crlf at end of each string */
|
|
hb_strncat( buffer, CRLF, buffsize );
|
|
}
|
|
else if( rettype == ARRAYTYPE )
|
|
/* store string to next array element */
|
|
hb_storvc( environ[x], 1, x + 1 );
|
|
}
|
|
|
|
if( rettype == CHARTYPE )
|
|
{
|
|
/* return buffer to app and free memory */
|
|
hb_storc( buffer, 1 );
|
|
hb_xfree( buffer );
|
|
}
|
|
|
|
/* return number of strings found */
|
|
hb_retni( x );
|
|
}
|
|
#elif defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE )
|
|
{
|
|
char *buffer = NULL;
|
|
LPTCH lpEnviron = GetEnvironmentStrings();
|
|
char *sCurEnv;
|
|
int x;
|
|
HB_ISIZ buffsize = 0;
|
|
int rettype = NORETURN;
|
|
|
|
char * szEnviron = HB_TCHAR_CONVFROM( lpEnviron );
|
|
|
|
if( HB_ISCHAR( 1 ) )
|
|
rettype = CHARTYPE;
|
|
if( HB_ISARRAY( 1 ) )
|
|
rettype = ARRAYTYPE;
|
|
|
|
if( rettype == CHARTYPE )
|
|
/* scan strings first and add up total size */
|
|
{
|
|
for( sCurEnv = szEnviron; *sCurEnv; sCurEnv++ )
|
|
{
|
|
if( !*sCurEnv )
|
|
/* null string, we're done */
|
|
break;
|
|
|
|
/* add length of this string plus 2 for the crlf */
|
|
buffsize += ( strlen( ( char * ) sCurEnv ) + 2 );
|
|
|
|
while( *sCurEnv )
|
|
sCurEnv++;
|
|
}
|
|
/* add 1 more byte for final nul character */
|
|
buffsize++;
|
|
|
|
/* now allocate that much memory and make sure 1st byte is a nul */
|
|
buffer = ( char * ) hb_xgrab( buffsize + 1 );
|
|
buffer[0] = '\0';
|
|
}
|
|
x = 0;
|
|
for( sCurEnv = szEnviron; *sCurEnv; sCurEnv++ )
|
|
{
|
|
if( !*sCurEnv )
|
|
/* null string, we're done */
|
|
break;
|
|
|
|
if( rettype == CHARTYPE )
|
|
{
|
|
/* tack string onto end of buffer */
|
|
hb_strncat( buffer, ( char * ) sCurEnv, buffsize );
|
|
/* add crlf at end of each string */
|
|
hb_strncat( buffer, CRLF, buffsize );
|
|
}
|
|
|
|
if( rettype == ARRAYTYPE )
|
|
/* store string to next array element */
|
|
hb_storvc( ( char * ) sCurEnv, 1, x + 1 );
|
|
x++;
|
|
while( *sCurEnv )
|
|
sCurEnv++;
|
|
}
|
|
|
|
if( rettype == CHARTYPE )
|
|
{
|
|
/* return buffer to app and free memory */
|
|
hb_storc( buffer, 1 );
|
|
hb_xfree( buffer );
|
|
}
|
|
|
|
/* return number of strings found */
|
|
hb_retni( x );
|
|
|
|
HB_TCHAR_FREE( szEnviron );
|
|
FreeEnvironmentStrings( ( LPTSTR ) lpEnviron );
|
|
}
|
|
#else
|
|
hb_storc( NULL, 1 );
|
|
hb_retni( 0 );
|
|
#endif
|
|
}
|