Example #1
0
bool clLibrary::Load( const LString& LibName )
{
#if defined( OS_WINDOWS )
	FLibHandle = ::LoadLibrary( LibName.c_str() );

	if ( !FLibHandle )
	{
		LString DLL = FindLibrary( LibName );

		FLibHandle = ::LoadLibrary( DLL.c_str() );
	}

#else
	const char* ErrStr;

	FLibHandle = dlopen( LibName.c_str(), RTLD_LAZY );

	if ( ( ErrStr = dlerror() ) != NULL )
	{
		FLibHandle = NULL;
	}

#endif

	CHECK_RET( !FLibHandle, false, "Unable to load library " + LibName );

	return true;
}
Example #2
0
void
Project::AddLibrary(const char *path)
{
	if (!path)
		return;
	
	DPath libpath(path);
	if (!BEntry(libpath.GetFullPath()).Exists())
	{
		libpath = FindLibrary(libpath.GetFileName());
		if (libpath.IsEmpty())
		{
			if (gBuildMode)
			{
				printf("%s seems to be missing\n", path);
			}
			else
			{
				BString err;
				err << path << " seems to be missing. Do you want to remove it from the project?";
				int32 result = ShowAlert(err.String(),"Remove","Keep");
				if (result == 0)
					return;
			}
		}
	}
	
	if (!HasLibrary(libpath.GetFullPath()))
	{
		STRACE(1,("%s: Added library %s\n",GetName(),libpath.GetFullPath()));
		fLibraryList.AddItem(gFileFactory.CreateSourceFileItem(libpath.GetFullPath()));
	}
}
Example #3
0
void WinEDA_ViewlibFrame::SelectAndViewLibraryPart(int option)
/**************************************************************/
/* Routine to select and view library Part  (NEW, NEXT or PREVIOUS) */
{
LibraryStruct * Lib;

	if(g_CurrentViewLibraryName.IsEmpty() ) SelectCurrentLibrary();
	if(g_CurrentViewLibraryName.IsEmpty() ) return;

	Lib = FindLibrary(g_CurrentViewLibraryName.GetData());
	if ( Lib == NULL ) return;

	if ( (g_CurrentViewComponentName.IsEmpty()) || ( option == NEW_PART ) )
		{
		ViewOneLibraryContent(Lib, NEW_PART);
		return;
		}

	EDA_LibComponentStruct * LibEntry = FindLibPart(g_CurrentViewComponentName.GetData(),
								 g_CurrentViewLibraryName.GetData(), FIND_ALIAS);

	if ( LibEntry == NULL ) return;

	if (option == NEXT_PART )
		ViewOneLibraryContent(Lib, NEXT_PART);

	if (option == PREVIOUS_PART )
		ViewOneLibraryContent(Lib, PREVIOUS_PART);

}
Example #4
0
void EnvironmentImportLibrary(FObject env, FObject nam)
{
    FAssert(EnvironmentP(env));
    FAssert(AsEnvironment(env)->Interactive == TrueObject);

    FObject lib = FindLibrary(nam);
    FAssert(LibraryP(lib));

    FObject elst = AsLibrary(lib)->Exports;

    while (PairP(elst))
    {
        FAssert(PairP(First(elst)));
        FAssert(SymbolP(First(First(elst))));
        FAssert(GlobalP(Rest(First(elst))));

#ifdef FOMENT_DEBUG
        int_t ret =
#endif // FOMENT_DEBUG
        EnvironmentImportGlobal(env,
                ImportGlobal(env, First(First(elst)), Rest(First(elst))));
        FAssert(ret == 0);

        elst = Rest(elst);
    }

    FAssert(elst == EmptyListObject);
}
Example #5
0
XN_C_API XnStatus xnOSLoadLibrary(const XnChar* cpFileName, XN_LIB_HANDLE* pLibHandle)
{
	// Validate the input/output pointers (to make sure none of them is NULL)
	XN_VALIDATE_INPUT_PTR(cpFileName);
	XN_VALIDATE_OUTPUT_PTR(pLibHandle);

	XnChar strLibPath[XN_FILE_MAX_PATH];
#if XN_PLATFORM == XN_PLATFORM_ANDROID_ARM
	XnStatus nRetVal = FindLibrary(cpFileName, strLibPath, sizeof(strLibPath));
	if (nRetVal != XN_STATUS_OK)
	{
		return nRetVal;
	}
#else
	strncpy(strLibPath, cpFileName, sizeof(strLibPath));
#endif

	// Load the requested shared library via the OS
	*pLibHandle = dlopen(strLibPath, RTLD_NOW);
	
	// Make sure it succeeded (return value is not NULL). If not return an error....
	if (*pLibHandle == NULL)
	{
		xnLogWarning(XN_MASK_OS, "Failed loading lib: %s\n", dlerror());
		return XN_STATUS_OS_CANT_LOAD_LIB;
	}

	// All is good...
	return (XN_STATUS_OK);
}
Example #6
0
FObject FindOrLoadLibrary(FObject nam)
{
    FObject lib = FindLibrary(nam);

    if (LibraryP(lib))
        return(lib);

    return(LoadLibrary(nam));
}
Example #7
0
static FObject LoadLibrary(FObject nam)
{
    FDontWait dw;
    FObject lp = R.LibraryPath;

    while (PairP(lp))
    {
        FAssert(StringP(First(lp)));

        FObject le = R.LibraryExtensions;

        while (PairP(le))
        {
            FAssert(StringP(First(le)));

            FObject libfn = LibraryNameFlat(First(lp), nam, First(le));
            FObject port = OpenInputFile(libfn);

            if (TextualPortP(port) == 0)
            {
                libfn = LibraryNameDeep(First(lp), nam, First(le));
                port = OpenInputFile(libfn);
            }

            if (TextualPortP(port))
            {
                WantIdentifiersPort(port, 1);

                for (;;)
                {
                    FObject obj = Read(port);

                    if (obj == EndOfFileObject)
                        break;

                    if (PairP(obj) == 0 || EqualToSymbol(First(obj), R.DefineLibrarySymbol) == 0)
                        RaiseExceptionC(R.Syntax, "define-library", "expected a library",
                                List(libfn, obj));

                    CompileLibrary(obj);
                }
            }

            FObject lib = FindLibrary(nam);
            if (LibraryP(lib))
                return(lib);

            le = Rest(le);
        }

        lp = Rest(lp);
    }

    FAssert(lp == EmptyListObject);

    return(NoValueObject);
}
/* Called to find the library. This _has_ to be called before anything else is done. */
static void setup_lib(void)
{
  if ( (advg_page = FindLibrary(ADVG_SIG)) == -1)
    {
      /* Cannot find the library! */
      fe_print_xy(0, 0, 0, "Could not find libadvg ("ADVG_SIG")\n");
      fe_sleep(100);
      fe_finalize();
    }
}
Example #9
0
void WinEDA_ViewlibFrame::DisplayLibInfos(void)
/**********************************************/
/* Affiche en Ligne d'info la librairie en cours de visualisation */
{
wxString msg;
LibraryStruct * Lib;

	Lib = FindLibrary(g_CurrentViewLibraryName.GetData());
	msg = _("Browse library: ");
	if ( Lib ) msg += g_CurrentViewLibraryName;
	else msg += _("None");
	SetTitle(msg);
}
Example #10
0
/*****************************************************************************
* Routine to load the given library name. FullLibName should hold full path  *
* of file name to open, while LibName should hold only its name.			 *
* IF library already exists, it is NOT reloaded.							 *
* return: new lib or NULL													 *
*****************************************************************************/
LibraryStruct * LoadLibraryName(WinEDA_DrawFrame * frame,
				const wxString & FullLibName, const wxString & LibName)
{
int NumOfParts;
FILE *f;
LibraryStruct *NewLib;
PriorQue *Entries;
wxString FullFileName;

	if ( (NewLib = FindLibrary(LibName)) != NULL)
	{
		if ( NewLib->m_FullFileName == FullLibName )
			return NewLib;
		FreeCmpLibrary(frame, LibName);
	}

	NewLib = NULL;

	f = wxFopen(FullLibName, wxT("rt") );
	if (f == NULL)
	{
		wxString msg;
		msg.Printf( _("Library <%s> not found"), FullLibName.GetData());
		DisplayError(frame, msg);
		return NULL;
	}
		
	NewLib = new LibraryStruct(LIBRARY_TYPE_EESCHEMA, LibName, FullLibName);
	Entries = LoadLibraryAux(frame, NewLib, f, &NumOfParts);
	if ( Entries != NULL)
	{
		NewLib->m_Entries = Entries;
		NewLib->m_NumOfParts = NumOfParts;
		
		if ( g_LibraryList == NULL ) g_LibraryList = NewLib;
		else
		{
			LibraryStruct *tmplib = g_LibraryList;
			while ( tmplib->m_Pnext ) tmplib = tmplib->m_Pnext;
			tmplib->m_Pnext = NewLib;
		}

		FullFileName = FullLibName;
		ChangeFileNameExt(FullFileName, DOC_EXT);
		LoadDocLib(frame, FullFileName, NewLib->m_Name);
	}
	else delete NewLib;
		
	fclose(f);
	return NewLib;
}
Example #11
0
void WinEDA_ConfigFrame::AddOrInsertLibrary(wxCommandEvent& event)
/****************************************************************/
/* Insert or add a library to the existing library list:
	New library is put in list before (insert) or after (add)
	the selection
*/
{
    int ii;
    wxString FullLibName,ShortLibName, Mask;

    ii = m_ListLibr->GetSelection();
    if ( ii < 0 ) ii = 0;
    ChangeSetup();
    if( event.GetId() == ADD_LIB)
    {
        if( g_LibName_List.GetCount() != 0 ) ii ++;	/* Add after selection */
    }

    Mask = wxT("*") + g_LibExtBuffer;
    FullLibName = EDA_FileSelector( _("Library files:"),
                                    g_RealLibDirBuffer,		/* Chemin par defaut */
                                    wxEmptyString,					/* nom fichier par defaut */
                                    g_LibExtBuffer,		/* extension par defaut */
                                    Mask,				/* Masque d'affichage */
                                    this,
                                    wxOPEN,
                                    TRUE
                                  );

    if ( FullLibName.IsEmpty() ) return;

    ShortLibName = MakeReducedFileName(FullLibName,g_RealLibDirBuffer,g_LibExtBuffer);

    //Add or insert new library name
    if (FindLibrary(ShortLibName) == NULL)
    {
        m_LibListChanged = TRUE;
        g_LibName_List.Insert(ShortLibName, ii);
        m_ListLibr->Clear();
        m_ListLibr->InsertItems(g_LibName_List, 0);
    }

    else DisplayError(this, _("Library already in use"));

}
Example #12
0
void LoadLibraries(WinEDA_DrawFrame * frame)
/******************************************/
/* Delete toutes les librairies chargees et recree toutes les librairies
donnes dans la liste g_LibName_List
*/
{
wxString FullLibName, msg;
wxString LibName;
unsigned ii, iimax = g_LibName_List.GetCount();

	frame->PrintMsg( _("Start loading schematic libs"));

	// Free the unwanted libraries (i.e. not in list) but keep the .cache lib
LibraryStruct *nextlib, *lib = g_LibraryList;
	for (; lib != NULL; lib = nextlib )
	{
		nextlib = lib->m_Pnext;
		if ( lib->m_IsLibCache )  continue;

		wxString libname = lib->m_Name;

		// is this library in "wanted list" g_LibName_List ?
		int test = g_LibName_List.Index(libname);
		if ( test == wxNOT_FOUND ) FreeCmpLibrary(frame, libname);
	}

	// Load missing libraries (if any)
	for ( ii = 0 ; ii < iimax; ii++)
	{
		LibName = g_LibName_List[ii];

		if( LibName.IsEmpty() ) continue;
		FullLibName = MakeFileName(g_RealLibDirBuffer, LibName, g_LibExtBuffer);
		msg = wxT("Loading ") + FullLibName;
		if ( LoadLibraryName(frame, FullLibName, LibName) )
			msg += wxT(" OK");
		else
			msg += wxT(" ->Error");
		frame->PrintMsg( msg );
	}
	
	// reorder the linked list to match the order filename list:
	int NumOfLibs;
	for (NumOfLibs = 0, lib = g_LibraryList; lib != NULL; lib = lib->m_Pnext)
	{
		lib->m_Flags = 0;
		NumOfLibs++;
	}
	if ( NumOfLibs == 0 ) return;
		
	LibraryStruct ** libs =
		(LibraryStruct **) MyZMalloc(sizeof(LibraryStruct *) * (NumOfLibs + 2));

	int jj = 0;
	for (ii = 0; ii < g_LibName_List.GetCount(); ii++)
	{
		if ( jj >= NumOfLibs ) break;
		lib = FindLibrary(g_LibName_List[ii]);
		if ( lib )
		{
			lib->m_Flags = 1;
			libs[jj++] = lib;
		}
	}
	/* Put lib cache at end of list */
	for (lib = g_LibraryList; lib != NULL; lib = lib->m_Pnext)
	{
		if ( lib->m_Flags == 0 ) libs[jj++] = lib;
	}
	libs[jj] = NULL;

	/* Change the linked list pointers */
	for (ii = 0; libs[ii] != NULL; ii++)
		libs[ii]->m_Pnext = libs[ii+1];

	g_LibraryList = libs[0];
	
	MyFree(libs);

	for (lib = g_LibraryList; lib != NULL; lib = lib->m_Pnext)
		lib->m_Flags = 0;
}
Example #13
0
void WinEDA_FindFrame::LocatePartInLibs(wxCommandEvent& event)
/*************************************************************/
/* Recherche exhaustive d'un composant en librairies, meme non chargees
*/
{
wxString Text, FindList;
const wxChar ** ListNames;
LibraryStruct *Lib = NULL;
EDA_LibComponentStruct * LibEntry;
bool FoundInLib = FALSE;	// True si reference trouvee ailleurs qu'en cache
	
	Text = m_NewTextCtrl->GetData();
	if ( Text.IsEmpty() )
	{
		Close(); return;
	}
	s_OldStringFound = Text;

	int ii, nbitems, NumOfLibs = NumOfLibraries();
	if (NumOfLibs == 0)
		{
		DisplayError(this, _("No libraries are loaded"));
		Close(); return;
		}

	ListNames = GetLibNames();
		
	nbitems = 0;
	for (ii = 0; ii < NumOfLibs; ii++ )	/* Recherche de la librairie */
	{
	bool IsLibCache;
		Lib = FindLibrary(ListNames[ii]);
		if ( Lib == NULL ) break;
		if ( Lib->m_Name.Contains( wxT(".cache")) ) IsLibCache = TRUE;
		else IsLibCache = FALSE;
		LibEntry = (EDA_LibComponentStruct *) PQFirst(&Lib->m_Entries, FALSE);
		while( LibEntry )
		{
			if( WildCompareString(Text, LibEntry->m_Name.m_Text, FALSE) )
			{
				nbitems ++;
				if ( ! IsLibCache ) FoundInLib = TRUE;
				if ( ! FindList.IsEmpty() ) FindList += wxT("\n");
				FindList << _("Found ")
						+ LibEntry->m_Name.m_Text
						+ _(" in lib ") + Lib->m_Name;
			}
		LibEntry = (EDA_LibComponentStruct *) PQNext(Lib->m_Entries, LibEntry, NULL);
		}
	}

	free (ListNames);
	
	if ( ! FoundInLib )
	{
		if ( nbitems ) FindList = wxT("\n") + Text + _(" found only in cache");
		else FindList = Text + _(" not found");
		FindList += _("\nExplore All Libraries?");
		if ( IsOK(this, FindList) )
		{
			FindList.Empty();
			ExploreAllLibraries(Text, FindList);
			if ( FindList.IsEmpty() ) DisplayInfo(this, _("Nothing found") );
			else DisplayInfo(this, FindList);
		}
	}
	else DisplayInfo(this, FindList);
	
	Close();
}