PluginRegistry()
    {
        char* env = getenv( "EQ_PLUGIN_PATH" );
        std::string envString( env ? env : "" );

        if( envString.empty( ))
        {
            char cwd[MAXPATHLEN];
            directories.push_back( getcwd( cwd, MAXPATHLEN ));

#ifdef _WIN32
            if( GetModuleFileName( 0, cwd, MAXPATHLEN ) > 0 )
                directories.push_back( lunchbox::getDirname( cwd ));
#else
#  ifdef Darwin
            env = getenv( "DYLD_LIBRARY_PATH" );
#  else
            env = getenv( "LD_LIBRARY_PATH" );
#  endif
        if( env )
            envString = env;
#  endif
        }

#ifdef _WIN32
        const char separator = ';';
#else
        const char separator = ':';
#endif

        while( !envString.empty( ))
        {
            size_t nextPos = envString.find( separator );
            if ( nextPos == std::string::npos )
                nextPos = envString.size();

            std::string path = envString.substr( 0, nextPos );
            if ( nextPos == envString.size( ))
                envString = "";
            else
                envString = envString.substr( nextPos + 1, envString.size() );

            if( !path.empty( ))
                directories.push_back( path );
        }
    }
// ProcessEnvironment
//------------------------------------------------------------------------------
void FunctionSettings::ProcessEnvironment( const Array< AString > & envStrings ) const
{
    // the environment string is used in windows as a double-null terminated string
    // so convert our array to a single buffer

    // work out space required
    uint32_t size = 0;
    for ( uint32_t i=0; i<envStrings.GetSize(); ++i )
    {
        size += envStrings[ i ].GetLength() + 1; // string len inc null
    }

    // allocate space
    AutoPtr< char > envString( (char *)ALLOC( size + 1 ) ); // +1 for extra double-null

    // while iterating, extract the LIB environment variable (if there is one)
    AStackString<> libEnvVar;

    // copy strings end to end
    char * dst = envString.Get();
    for ( uint32_t i=0; i<envStrings.GetSize(); ++i )
    {
        if ( envStrings[ i ].BeginsWith( "LIB=" ) )
        {
            libEnvVar.Assign( envStrings[ i ].Get() + 4, envStrings[ i ].GetEnd() );
        }

        const uint32_t thisStringLen = envStrings[ i ].GetLength();
        AString::Copy( envStrings[ i ].Get(), dst, thisStringLen );
        dst += ( thisStringLen + 1 );
    }

    // final double-null
    *dst = '\000';

    FBuild::Get().SetEnvironmentString( envString.Get(), size, libEnvVar );
}