static CIRCUITPTR findCircuit(INSTANCE_TPTR it) { STRING circuitname = it->cell_ref; STRING libraryname = it->library_ref; LIBRARYPTR lib; FUNCTIONPTR fun = NIL; CIRCUITPTR cir = NIL; if ((lib = findLibrary(mapL(libraryname),edif_tree)) == NIL) return NIL; for (fun = lib->function; fun != NIL; fun = fun->next) for (cir = fun->circuit; cir != NIL; cir = cir->next) if (cir->name == circuitname) return cir; /* found the circuit */ if (cir == NIL) /* circuit not found: get a new one and add it to the lib */ switch (targetLanguage) { case NelsisLanguage: cir = findNelsisCircuit(circuitname,lib); break; case SeadifLanguage: cir = findSeadifCircuit(circuitname,lib); break; case PseudoSeadifLanguage: cir = makeStubCircuit(circuitname,lib); break; case NoLanguage: default: cir = NIL; } return cir; }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PluginRegistry::PluginEntry PluginRegistry::open(const std::string &file) const { // Load shared library #ifdef WIN32 void *handle = LoadLibrary(file.c_str()); #else void *handle = dlopen(file.c_str(), RTLD_NOW | RTLD_GLOBAL); #endif if ( !handle ) { SEISCOMP_ERROR("Loading plugin %s failed: %s", file.c_str(), sysLastError().c_str()); return PluginEntry(NULL, NULL, file); } if ( findLibrary(handle) ) { return PluginEntry(handle, NULL, file); } #ifndef WIN32 // Reset errors dlerror(); // Load factory Core::Plugin::CreateFunc func; *(void **)(&func) = dlsym(handle, "createSCPlugin"); #else Core::Plugin::CreateFunc func = (Core::Plugin::CreateFunc)GetProcAddress((HMODULE)handle, "createSCPlugin"); #endif if ( !func ) { SEISCOMP_ERROR("Could not load symbol createPlugin: %s", sysLastError().c_str()); #ifndef WIN32 dlclose(handle); #else FreeLibrary((HMODULE)handle); #endif return PluginEntry(NULL, NULL, file); } Core::Plugin *plugin = func(); if ( !plugin ) { SEISCOMP_ERROR("No plugin return from %s", file.c_str()); #ifndef WIN32 dlclose(handle); #else FreeLibrary((HMODULE)handle); #endif return PluginEntry(NULL, NULL, file); } // Do not warn for different patch versions. They must be binary compatible // by definition. if ( (SC_API_VERSION_MAJOR(plugin->description().apiVersion) != SC_API_VERSION_MAJOR(SC_API_VERSION)) || (SC_API_VERSION_MINOR(plugin->description().apiVersion) > SC_API_VERSION_MINOR(SC_API_VERSION)) ) { SEISCOMP_WARNING("API version mismatch (%d.%d != %d.%d) can lead to unpredicted behaviour: %s", SC_API_VERSION_MAJOR(plugin->description().apiVersion), SC_API_VERSION_MINOR(plugin->description().apiVersion), SC_API_VERSION_MAJOR(SC_API_VERSION), SC_API_VERSION_MINOR(SC_API_VERSION), file.c_str()); } return PluginEntry(handle, plugin, file); }
//Add a library using a relative path bool Library::addLibrary(const std::string &libName) { std::string s; if (!findLibrary(libName, s)) { return false; } return addLibraryAbs(s); }
//Get a library using a name ExecutableFile *Library::get(const std::string &name) { std::string s; if (!findLibrary(name, s)) { return NULL; } if (!addLibraryAbs(s)) { return NULL; } ModuleNameToExec::const_iterator it = m_libraries.find(s); if (it == m_libraries.end()) { return NULL; } return (*it).second; }
bool Conf::findSimpleLibrary(const QString &incvar, const QString &libvar, const QString &incname, const QString &libname, QString *incpath, QString *libs) { QString inc, lib; QString s; s = getenv(incvar); if(!s.isEmpty()) { if(!checkHeader(s, incname)) return false; inc = s; } else { if(!findHeader(incname, QStringList(), &s)) return false; inc = s; } s = getenv(libvar); if(!s.isEmpty()) { if(!checkLibrary(s, libname)) return false; lib = s; } else { if(!findLibrary(libname, &s)) return false; lib = s; } QString lib_out; if(!lib.isEmpty()) lib_out += QString("-L") + s; lib_out += QString("-l") + libname; *incpath = inc; *libs = lib_out; return true; }
int main( int argc, _TCHAR* argv[] ) { _TCHAR* errorMsg; _TCHAR* program; _TCHAR* iniFile; _TCHAR* ch; _TCHAR** configArgv = NULL; int configArgc = 0; int exitCode = 0; int ret = 0; void * handle = 0; RunMethod runMethod; SetInitialArgs setArgs; setlocale(LC_ALL, ""); initialArgc = argc; initialArgv = malloc((argc + 1) * sizeof(_TCHAR*)); memcpy(initialArgv, argv, (argc + 1) * sizeof(_TCHAR*)); /* * Strip off any extroneous <CR> from the last argument. If a shell script * on Linux is created in DOS format (lines end with <CR><LF>), the C-shell * does not strip off the <CR> and hence the argument is bogus and may * not be recognized by the launcher or eclipse itself. */ ch = _tcschr( argv[ argc - 1 ], _T_ECLIPSE('\r') ); if (ch != NULL) { *ch = _T_ECLIPSE('\0'); } /* Determine the full pathname of this program. */ program = findProgram(argv); /* Parse configuration file arguments */ iniFile = checkForIni(argc, argv); if (iniFile != NULL) ret = readConfigFile(iniFile, &configArgc, &configArgv); else ret = readIniFile(program, &configArgc, &configArgv); if (ret == 0) { parseArgs (&configArgc, configArgv); } /* Parse command line arguments */ /* Overrides configuration file arguments */ parseArgs( &argc, argv ); /* Special case - user arguments specified in the config file * are appended to the user arguments passed from the command line. */ if (configArgc > 0) { createUserArgs(configArgc, configArgv, &argc, &argv); } /* Initialize official program name */ officialName = name != NULL ? _tcsdup( name ) : getDefaultOfficialName(program); /* Find the directory where the Eclipse program is installed. */ programDir = getProgramDir(program); /* Find the eclipse library */ eclipseLibrary = findLibrary(eclipseLibrary, program); if(eclipseLibrary != NULL) handle = loadLibrary(eclipseLibrary); if(handle == NULL) { errorMsg = malloc( (_tcslen(libraryMsg) + _tcslen(officialName) + 10) * sizeof(_TCHAR) ); _stprintf( errorMsg, libraryMsg, officialName ); if (!suppressErrors) displayMessage( officialName, errorMsg ); else _ftprintf(stderr, _T_ECLIPSE("%s:\n%s\n"), officialName, errorMsg); free( errorMsg ); exit( 1 ); } setArgs = (SetInitialArgs)findSymbol(handle, SET_INITIAL_ARGS); if(setArgs != NULL) setArgs(initialArgc, initialArgv, eclipseLibrary); else { if(!suppressErrors) displayMessage(officialName, entryMsg); else _ftprintf(stderr, _T_ECLIPSE("%s:\n%s\n"), officialName, entryMsg); exit(1); } runMethod = (RunMethod)findSymbol(handle, RUN_METHOD); if(runMethod != NULL) exitCode = runMethod(argc, argv, userVMarg); else { if(!suppressErrors) displayMessage(officialName, entryMsg); else _ftprintf(stderr, _T_ECLIPSE("%s:\n%s\n"), officialName, entryMsg); exit(1); } unloadLibrary(handle); free( eclipseLibrary ); free( programDir ); free( program ); free( officialName ); return exitCode; }
KLibrary* KLibLoader::library( const char *name ) { if (!name) return 0; KLibWrapPrivate* wrap = m_libs[name]; if (wrap) { /* Nothing to do to load the library. */ wrap->ref_count++; return wrap->lib; } /* Test if this library was loaded at some time, but got unloaded meanwhile, whithout being dlclose()'ed. */ QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack); for (; it.current(); ++it) { if (it.current()->name == name) wrap = it.current(); } if (wrap) { d->pending_close.removeRef(wrap); if (!wrap->lib) { /* This lib only was in loaded_stack, but not in m_libs. */ wrap->lib = new KLibrary( name, wrap->filename, wrap->handle ); } wrap->ref_count++; } else { QString libfile = findLibrary( name ); if ( libfile.isEmpty() ) { const QCString libname = makeLibName( name ); #ifndef NDEBUG kdDebug(150) << "library=" << name << ": No file named " << libname << " found in paths." << endl; #endif d->errorMessage = i18n("Library files for \"%1\" not found in paths.").arg(libname); return 0; } lt_dlhandle handle = lt_dlopen( QFile::encodeName(libfile) ); if ( !handle ) { const char* errmsg = lt_dlerror(); if(errmsg) d->errorMessage = QString::fromLocal8Bit(errmsg); else d->errorMessage = QString::null; return 0; } else d->errorMessage = QString::null; KLibrary *lib = new KLibrary( name, libfile, handle ); wrap = new KLibWrapPrivate(lib, handle); d->loaded_stack.prepend(wrap); } m_libs.insert( name, wrap ); connect( wrap->lib, SIGNAL( destroyed() ), this, SLOT( slotLibraryDestroyed() ) ); return wrap->lib; }
KLibrary::KLibrary(const QString &name, int verNum, QObject *parent) : QLibrary(findLibrary(name), verNum, parent), d_ptr(0) { }
void KLibrary::setFileName(const QString &name) { QLibrary::setFileName(findLibrary(name)); }
void EventLogChannel::setUpRegistry() const { std::string key = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\"; key.append(_logFile); key.append("\\"); key.append(_name); HKEY hKey; DWORD disp; #if defined(POCO_WIN32_UTF8) std::wstring ukey; UnicodeConverter::toUTF16(key, ukey); DWORD rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ukey.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp); #else DWORD rc = RegCreateKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp); #endif if (rc != ERROR_SUCCESS) return; if (disp == REG_CREATED_NEW_KEY) { #if defined(POCO_WIN32_UTF8) std::wstring path; #if defined(POCO_DLL) #if defined(_DEBUG) path = findLibrary(L"PocoFoundationd.dll"); #else path = findLibrary(L"PocoFoundation.dll"); #endif #endif if (path.empty()) path = findLibrary(L"PocoMsg.dll"); #else std::string path; #if defined(POCO_DLL) #if defined(_DEBUG) path = findLibrary("PocoFoundationd.dll"); #else path = findLibrary("PocoFoundation.dll"); #endif #endif if (path.empty()) path = findLibrary("PocoMsg.dll"); #endif if (!path.empty()) { DWORD count = 8; DWORD types = 7; #if defined(POCO_WIN32_UTF8) RegSetValueExW(hKey, L"CategoryMessageFile", 0, REG_SZ, (const BYTE*) path.c_str(), static_cast<DWORD>(sizeof(wchar_t)*(path.size() + 1))); RegSetValueExW(hKey, L"EventMessageFile", 0, REG_SZ, (const BYTE*) path.c_str(), static_cast<DWORD>(sizeof(wchar_t)*(path.size() + 1))); RegSetValueExW(hKey, L"CategoryCount", 0, REG_DWORD, (const BYTE*) &count, static_cast<DWORD>(sizeof(count))); RegSetValueExW(hKey, L"TypesSupported", 0, REG_DWORD, (const BYTE*) &types, static_cast<DWORD>(sizeof(types))); #else RegSetValueEx(hKey, "CategoryMessageFile", 0, REG_SZ, (const BYTE*) path.c_str(), static_cast<DWORD>(path.size() + 1)); RegSetValueEx(hKey, "EventMessageFile", 0, REG_SZ, (const BYTE*) path.c_str(), static_cast<DWORD>(path.size() + 1)); RegSetValueEx(hKey, "CategoryCount", 0, REG_DWORD, (const BYTE*) &count, static_cast<DWORD>(sizeof(count))); RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (const BYTE*) &types, static_cast<DWORD>(sizeof(types))); #endif } } RegCloseKey(hKey); }
void QKDEIntegration::initLibrary() { if( !inited ) { enable = false; inited = true; QString libpath = findLibrary(); if( libpath.isEmpty()) return; QLibrary lib( libpath ); lib.setAutoUnload( false ); qtkde_initializeIntegration = ( bool (*)( ) ) lib.resolve("initializeIntegration"); if( qtkde_initializeIntegration == NULL ) return; qtkde_getOpenFileNames = ( QStringList (*)( const QString& filter, QString* workingDirectory, long parent, const QCString& name, const QString& caption, QString* selectedFilter, bool multiple ) ) lib.resolve("getOpenFileNames"); if( qtkde_getOpenFileNames == NULL ) return; qtkde_getSaveFileName = ( QString (*)( const QString& initialSelection, const QString& filter, QString* workingDirectory, long parent, const QCString& name, const QString& caption, QString* selectedFilter ) ) lib.resolve("getSaveFileName"); if( qtkde_getSaveFileName == NULL ) return; qtkde_getExistingDirectory = ( QString (*)( const QString& initialDirectory, long parent, const QCString& name, const QString& caption ) ) lib.resolve("getExistingDirectory"); if( qtkde_getExistingDirectory == NULL ) return; qtkde_getColor = ( QColor (*)( const QColor& color, long parent, const QCString& name ) ) lib.resolve("getColor"); if( qtkde_getColor == NULL ) return; qtkde_getFont = ( QFont (*)( bool* ok, const QFont& def, long parent, const QCString& name ) ) lib.resolve("getFont"); if( qtkde_getFont == NULL ) return; qtkde_messageBox1 = ( int (*)( int type, long parent, const QString& caption, const QString& text, int button0, int button1, int button2 ) ) lib.resolve("messageBox1"); if( qtkde_messageBox1 == NULL ) return; qtkde_messageBox2 = ( int (*)( int type, long parent, const QString& caption, const QString& text, const QString& button0Text, const QString& button1Text, const QString& button2Text, int defaultButton, int escapeButton ) ) lib.resolve("messageBox2"); if( qtkde_messageBox2 == NULL ) return; enable = qtkde_initializeIntegration(); } }