$include (..\lib\compStch.ext) /* *============================================================================ * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE * * Permission to use for any purpose, modify, copy, and make enhancements * and derivative works of the software is granted if attribution is given to * R.M. Gillmore, dba the ACME Software Deli, as the author * * While the ACME Software Deli does not work for money, there is nonetheless * a significant amount of work involved. The ACME Software Deli maintains the * rights to all code written, though it may be used and distributed as long as * the following conditions are maintained. * * 1. The copyright statement at the top of each code block is maintained in * your distribution. * 2. You do not identify yourself as the ACME Software Deli * 3. Any changes made to the software are sent to the ACME Software Deli *============================================================================ */ getEnvironmentModule: do; $if not noID declare IDString (*) byte data ( '@(#)getenv.p86 $Author: rmgillmore $ $Date:: 2025-05-04 19:35:39#$:', 0 ); $endif $include (..\lib\comnDefs.ext) $set ( getEnvSource ) $include (..\lib\string.ext) $include (..\lib\ptrMath.ext) $include (..\lib\sysCalls.ext) $if LOGGING $include (..\lib\logger.ext) $endif getenv: procedure ( variableNamePtr ) pointer reentrant public; declare variableNamePtr pointer, variableNameString based variableNamePtr (*) char, variableValuePtr pointer, variableValueString based variableValuePtr (*) char; declare pspAddress pointer, pspStruct based pspAddress pspStructure, envStrPtr pointer, envStr based envStrPtr (*) char, varString ( 2048 ) char; declare stringLength word, compareIndex integer, varNameStringLength word, equalPtr pointer; pspAddress = getPsp; envStrPtr = build$ptr( pspStruct.environmentBlock, 0 ); variableValuePtr = NULL; do while ( NULL = variableValuePtr ) and ( NUL <> envStr( 0 ) ); /* * copy the string from the environment to the local space */ call strcpy( @varString( 0 ), envStrPtr ); /* * find the equal sign in this string */ variableValuePtr = strchr( @varString( 0 ), '=' ); if ( NULL <> variableValuePtr ) then do; /* * split the string into two pieces by replacing the equal * sign with a NUL */ variableValueString( 0 ) = NUL; variableValuePtr = incPtr( variableValuePtr, size( envStr( 0 ) ), 1 ); varNameStringLength = strlen( @varString( 0 ) ); $if LOGGING call addToLog( DEBUG, __FILE__, __LINE__, @( '''%s'' is ''%s''', 0 ), @varString, @variableValueString ); $endif /* * compare the name passed in to the local environment string */ compareIndex = stricmp( variableNamePtr, @varString( 0 ) ); $if LOGGING call addToLog( DEBUG, __FILE__, __LINE__, @( 'stricmp( ''%s'', ''%s'' ) returned %d', 0 ), variableNamePtr, @varString( 0 ), compareIndex ); $endif if ( 0 = compareIndex ) then do; /* * we have a match, so return the address of the value */ variableValuePtr = @envStr( varNameStringLength + 1 ); end; else do; /* * go to the next environment variable */ stringLength = strlen( envStrPtr ); envStrPtr = @envStr( stringLength + 1 ); variableValuePtr = NULL; end; end; else do; /* * go to the next environment variable */ stringLength = strlen( envStrPtr ); envStrPtr = @envStr( stringLength + 1 ); end; end; $if LOGGING call addToLog( DEBUG, __FILE__, __LINE__, @( 'returning ''%s''', 0 ), variableValuePtr ); $endif return ( variableValuePtr ); end getenv; end getEnvironmentModule;