--- plplot-5.13.0/src/plctrl.c.orig +++ plplot-5.13.0/src/plctrl.c @@ -56,6 +56,10 @@ #include #endif +#ifdef _WIN32 +#include +#endif + // Random number generator (Mersenne Twister) #include "mt19937ar.h" @@ -68,6 +72,10 @@ // work even in the single precision floating point case. #define FUZZ_EPSILON 1.e-4 +#ifdef _WIN32 +static HMODULE handle_dll; +#endif + // Static functions // Used by any external init code to suggest a path @@ -124,6 +132,41 @@ #endif #endif + +#ifdef _WIN32 +BOOL WINAPI +DllMain (HINSTANCE hinstDLL, + DWORD fdwReason, + LPVOID lpvReserved) +{ + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + handle_dll = (HMODULE) hinstDLL; + break; + } + + return TRUE; +} + +char * plGetWinInstallDir() +{ + char *path; + char *p; + + path = (char*) malloc(MAX_PATH); + + GetModuleFileName(handle_dll, path, MAX_PATH); + + p = strrchr (path, '\\'); + *p = '\0'; + p = strrchr (path, '\\'); + *p = '\0'; + + return path; +} +#endif + //-------------------------------------------------------------------------- // Routines that deal with colors & color maps. @@ -2189,6 +2232,14 @@ return fs; #endif +#ifdef _WIN32 + dn = plGetWinInstallDir(); + plGetName( dn, "bin", fn, &fs ); + free(dn); + if ( !plFindName( fs ) ) + return fs; +#endif + // Crapped out free_mem( fs ); @@ -2323,6 +2374,15 @@ if ( file != NULL ) goto done; #endif // macintosh + +#ifdef _WIN32 + dn = plGetWinInstallDir(); + plGetName( dn, "share\\plplot" PLPLOT_VERSION, fn, &fs ); + free(dn); + if ( ( file = pdf_fopen( fs, "rb" ) ) != NULL ) + goto done; + fprintf( stderr, "WININSTALLDIR =\"%s\" ; file=\"%s\"\n", dn, fs ); // what IS set? +#endif if ( plplotLibDir != NULL ) {