From 9c3d5bd96d376ab858e091e9a2d4757c9004c2d8 Mon Sep 17 00:00:00 2001 From: CHARRAS Date: Fri, 2 Nov 2007 17:17:44 +0000 Subject: [PATCH] eschema, pcbnew and cvpcb did not find libraries when they were in the default library path, but in a subdirectory --- change_log.txt | 10 ++ common/gestfich.cpp | 91 ++++++++-------- eeschema/eelibs_read_libraryfiles.cpp | 145 +++++++++++++------------- 3 files changed, 132 insertions(+), 114 deletions(-) diff --git a/change_log.txt b/change_log.txt index a51bd814a3..25157de081 100644 --- a/change_log.txt +++ b/change_log.txt @@ -4,6 +4,16 @@ Started 2007-June-11 Please add newer entries at the top, list the date and your name with email address. +2007-Nov-032 UPDATE Jean-Pierre Charras +================================================================================ ++all: + solved: eeschema, pcbnew and cvpcb did not find libraries when they were + in the default library path, but in a subdirectory + (this is because the default path was not added to the name if the name had + already a path) + + + 2007-Nov-02 UPDATE Geoff Harland ================================================================================ + pcbnew diff --git a/common/gestfich.cpp b/common/gestfich.cpp index bbdd8c003c..9bb5c541c0 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -85,17 +85,18 @@ wxString MakeReducedFileName( const wxString& fullfilename, const wxString& default_ext ) /***************************************************************************/ -/* Calcule le nom "reduit" d'un fichier d'apres les chaines - * fullfilename = nom complet - * default_path = prefixe (chemin) par defaut - * default_ext = extension par defaut +/** Function MakeReducedFileName + * Calculate the "reduced" filename from + * @param fullfilename = full filename + * @param default_path = default path + * @param default_ext = default extension * - * retourne le nom reduit, c'est a dire: - * sans le chemin si le chemin est default_path - * avec ./ si si le chemin est le chemin courant - * sans l'extension si l'extension est default_ext + * @return the "reduced" filename, i.e.: + * without path if it is default_path + * wiht ./ if the path is the current path + * without extension if extension is default_ext * - * Renvoie un chemin en notation unix ('/' en separateur de repertoire) + * the new flename is in unix like notation ('/' as path separator) */ { wxString reduced_filename = fullfilename; @@ -111,18 +112,19 @@ wxString MakeReducedFileName( const wxString& fullfilename, path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); #ifdef __WINDOWS__ + // names are case insensitive under windows path.MakeLower(); Cwd.MakeLower(); ext.MakeLower(); #endif - // Si le fichier est dans chemin par defaut -> suppression du chemin par defaut + // if the path is "default_path" -> remove it wxString root_path = path.Left( Cwd.Length() ); if( root_path == Cwd ) { reduced_filename.Remove( 0, Cwd.Length() ); } - else // Si fichier dans repertoire courant -> chemin = ./ + else // if the path is the current path -> change path to ./ { Cwd = wxGetCwd() + UNIX_STRING_DIR_SEP; #ifdef __WINDOWS__ @@ -130,14 +132,14 @@ wxString MakeReducedFileName( const wxString& fullfilename, #endif Cwd.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); if( path == Cwd ) - { // lib est dans répertoire courant -> Chemin = "./" + { // the path is the current path -> path = "./" reduced_filename.Remove( 0, Cwd.Length() ); wxString tmp = wxT( "./" ) + reduced_filename; reduced_filename = tmp; } } - // Suppression extension standard: + // remove extension if == default_ext: if( !ext.IsEmpty() && reduced_filename.Contains( ext ) ) reduced_filename.Truncate( reduced_filename.Length() - ext.Length() ); @@ -150,15 +152,14 @@ wxString MakeFileName( const wxString& dir, const wxString& shortname, const wxString& ext ) /***************************************************************************/ -/* Calcule le nom complet d'un fichier d'apres les chaines - * dir = prefixe (chemin) (peut etre "") - * shortname = nom avec ou sans chemin ou extension - * ext = extension (peut etre "") - * - * si shortname possede deja un chemin ou une extension, elles - * ne seront pas modifiees - * - * retourne la chaine calculee +/** Function MakeFileName + * Calculate the full file name from dir, shortname and ext + * @param dir = path (can be empty) + * @param shortname = filename with or without path and/or extension + * @param ext = extension (can be empty) + * If shortname has an absolute path, or a path start by ./ , the path will not be modified + * If shortname has an extension, it will not be modified + * @return full filename */ { wxString fullfilename; @@ -166,31 +167,34 @@ wxString MakeFileName( const wxString& dir, if( !dir.IsEmpty() ) { - if( !shortname.Contains( UNIX_STRING_DIR_SEP ) && !shortname.Contains( WIN_STRING_DIR_SEP ) - && !shortname.Contains( wxT( ":" ) ) ) - { /* aucun chemin n'est donne */ - fullfilename = dir; - } + if( !wxIsAbsolutePath( shortname ) ) + { + wxString left = shortname.Left(2); + if( left != wxT("./") ) + { /* no absolute path in shortname */ + fullfilename = dir; + } + } } fullfilename += shortname; fullfilename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); - /* Placement de l'extension s'il n'y en a pas deja une */ + /* Add an extension if shortname has no extension */ if( ext.IsEmpty() ) return fullfilename; - /* Recherche d'une eventuelle extension */ - ii = fullfilename.Length(); /* Pointe la fin du texte */ + /* search for an extension */ + ii = fullfilename.Length(); /* Get the end of name */ for( ; ii >= 0; ii-- ) { if( fullfilename.GetChar( ii ) == '/' ) { - /* Pas d'extension: placement de l'extension standard */ + /* not extension: add ext */ fullfilename += ext; break; } - if( fullfilename.GetChar( ii ) == '.' ) /* extension trouvee */ + if( fullfilename.GetChar( ii ) == '.' ) /* extension exists, do nothing */ break; } @@ -202,7 +206,10 @@ wxString MakeFileName( const wxString& dir, void ChangeFileNameExt( wxString& FullFileName, const wxString& NewExt ) /**************************************************************************/ -/* Change l'extension du "filename FullFileName" en NewExt. +/** Function ChangeFileNameExt + * change the extension of FullFileName to NewExt. + * @param FullFileName = filename to modify + * @param NewExt = new extension for FullFileName */ { wxString FileName; @@ -223,7 +230,9 @@ void ChangeFileNameExt( wxString& FullFileName, const wxString& NewExt ) void AddDelimiterString( wxString& string ) /*******************************************/ -/* ajoute un " en debut et fin de string s'il n'y en a pas deja. +/** Function AddDelimiterString + * Add un " to the start and the end of string (if not already done). + * @param string = string to modify */ { wxString text; @@ -237,9 +246,9 @@ void AddDelimiterString( wxString& string ) } -/*************************************/ -/* Fonction de selection de Repertoires */ -/*************************************/ +/***********************************/ +/* Selection Directory dialog box: */ +/***********************************/ bool EDA_DirectorySelector( const wxString& Title, /* Titre de la fenetre */ wxString& Path, /* Chemin par defaut */ @@ -300,7 +309,7 @@ wxString EDA_FileSelector( const wxString& Title, /* Dialog ti defaultname, Ext, Mask, - flag,/* options d'affichage (wxFD_OPEN, wxFD_SAVE .. */ + flag,/* open mode wxFD_OPEN, wxFD_SAVE .. */ Frame, Pos.x, Pos.y ); @@ -314,9 +323,9 @@ wxString EDA_FileSelector( const wxString& Title, /* Dialog ti /********************************************************/ wxString FindKicadHelpPath() /********************************************************/ -/* Find absolute path for kicad/help (or kicad/help/) */ - -/* Find path kicad/help/xx/ ou kicad/help/: +/** Function FindKicadHelpPath + * Find an absolute path for kicad/help (or kicad/help/) + * Find path kicad/help/xx/ ou kicad/help/: * from BinDir * else from environment variable KICAD * else from one of s_HelpPathList diff --git a/eeschema/eelibs_read_libraryfiles.cpp b/eeschema/eelibs_read_libraryfiles.cpp index 3fca9a762c..ac2b3d38bd 100644 --- a/eeschema/eelibs_read_libraryfiles.cpp +++ b/eeschema/eelibs_read_libraryfiles.cpp @@ -1,6 +1,6 @@ -/***********************************************************/ -/* Module to handle libraries (first part - file and io). */ -/***********************************************************/ +/*****************************************************************/ +/* Functions to handle component library files : read functions */ +/*****************************************************************/ #include "fctsys.h" #include "gr_basic.h" @@ -13,10 +13,7 @@ #include "protos.h" -/* Variables Locales */ - -/* Fonctions locales */ -/* pour librairies de composants */ +/* Local Functions */ static LibEDA_BaseStruct* GetDrawEntry( WinEDA_DrawFrame* frame, FILE* f, char* Line, int* LineNum ); static bool GetLibEntryField( EDA_LibComponentStruct* LibEntry, char* line ); @@ -27,22 +24,18 @@ static bool ReadLibEntryDateAndTime( EDA_LibComponentStruct* Lib static int AddFootprintFilterList( EDA_LibComponentStruct* LibEntryLibEntry, FILE* f, char* Line, int* LineNum ); -/* pour doc librairies */ - -/****************************************************/ -/* Routines de lecture des librairies de composants */ -/****************************************************/ - - -/***************************************************************************** -* 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 ) +/*************************************************************************************/ + +/** Function LoadLibraryName + * 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 + */ { int NumOfParts; FILE* f; @@ -103,8 +96,9 @@ LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame, void LoadLibraries( WinEDA_DrawFrame* frame ) /******************************************/ -/* Delete toutes les librairies chargees et recree toutes les librairies - * donnes dans la liste g_LibName_List +/* Function LoadLibraries + * Clear all alredy loaded librries and load all librairies + * given in g_LibName_List */ { wxString FullLibName, msg; @@ -136,16 +130,17 @@ void LoadLibraries( WinEDA_DrawFrame* frame ) if( LibName.IsEmpty() ) continue; - - FullLibName = MakeFileName( g_RealLibDirBuffer, LibName, g_LibExtBuffer ); - + + FullLibName = MakeFileName( g_RealLibDirBuffer, LibName, g_LibExtBuffer ); + msg = wxT( "Loading " ) + FullLibName; - + frame->PrintMsg( msg ); + if( LoadLibraryName( frame, FullLibName, LibName ) ) msg += wxT( " OK" ); else msg += wxT( " ->Error" ); - + frame->PrintMsg( msg ); } @@ -161,9 +156,9 @@ void LoadLibraries( WinEDA_DrawFrame* frame ) return; LibraryStruct** libs = - (LibraryStruct**) MyZMalloc( sizeof(LibraryStruct *) * (NumOfLibs + 2) ); + (LibraryStruct**) MyZMalloc( sizeof(LibraryStruct*) * (NumOfLibs + 2) ); - int jj = 0; + int jj = 0; for( ii = 0; ii < g_LibName_List.GetCount(); ii++ ) { if( jj >= NumOfLibs ) @@ -198,10 +193,13 @@ void LoadLibraries( WinEDA_DrawFrame* frame ) } -/***************************************************************************** -* Routine to free a library from the current loaded libraries. * -*****************************************************************************/ +/**************************************************************/ void FreeCmpLibrary( wxWindow* frame, const wxString& LibName ) +/**************************************************************/ + +/** Function FreeCmpLibrary + * Routine to remove and free a library from the current loaded libraries. + */ { int NumOfLibs = NumOfLibraries(); LibraryStruct* Lib, * TempLib; @@ -234,7 +232,8 @@ void FreeCmpLibrary( wxWindow* frame, const wxString& LibName ) delete Lib; - /* La librairie supprimee est peut etre celle selectee dans libedit */ + /* The removed librairy can be the current library in libedit. + * If so, clear the current library in libedit */ if( Lib == CurrentLib ) CurrentLib = NULL; } @@ -244,7 +243,8 @@ void FreeCmpLibrary( wxWindow* frame, const wxString& LibName ) const wxChar** GetLibNames() /******************************/ -/* Routine to return pointers to all library names. +/** GetLibNames() + * Routine to return pointers to all library names. * User is responsible to deallocate memory */ { @@ -252,7 +252,7 @@ const wxChar** GetLibNames() const wxChar** Names; LibraryStruct* Lib; - Names = (const wxChar**) MyZMalloc( sizeof(wxChar *) * (NumOfLibs + 1) ); + Names = (const wxChar**) MyZMalloc( sizeof(wxChar*) * (NumOfLibs + 1) ); for( ii = 0, Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext, ii++ ) { Names[ii] = Lib->m_Name.GetData(); @@ -264,10 +264,10 @@ const wxChar** GetLibNames() } -/***************************************************************************** -* Routine to compare two EDA_LibComponentStruct for the PriorQue module. * -* Comparison (insensitive case) is based on Part name. * -*****************************************************************************/ +/** Function LibraryEntryCompare + * Routine to compare two EDA_LibComponentStruct for the PriorQue module. + * Comparison (insensitive case) is based on Part name. + */ int LibraryEntryCompare( EDA_LibComponentStruct* LE1, EDA_LibComponentStruct* LE2 ) { return LE1->m_Name.m_Text.CmpNoCase( LE2->m_Name.m_Text ); @@ -355,7 +355,7 @@ EDA_LibComponentStruct* Read_Component_Definition( WinEDA_DrawFrame* frame, char char* p; char* name; char* prefix = NULL; - + EDA_LibComponentStruct* LibEntry = NULL; bool Res; wxString Msg; @@ -397,11 +397,11 @@ EDA_LibComponentStruct* Read_Component_Definition( WinEDA_DrawFrame* frame, char return NULL; } - else /* Mise a jour des infos de la ligne "DEF" */ + else /* Update infos read from the line "DEF" */ { LibEntry->m_DrawPinNum = (drawnum == 'N') ? FALSE : TRUE; LibEntry->m_DrawPinName = (drawname == 'N') ? FALSE : TRUE; - + /* Copy part name and prefix. */ strupper( name ); if( name[0] != '~' ) @@ -433,11 +433,11 @@ EDA_LibComponentStruct* Read_Component_Definition( WinEDA_DrawFrame* frame, char } } - /* Analyse lignes suivantes */ + /* Read next lines */ while( GetLine( f, Line, LineNum, 1024 ) ) { p = strtok( Line, " \t\n" ); - Res = TRUE; /* Pour test d'erreur (Res = FALSE = erreur) */ + Res = TRUE; /* This is the error flag ( if an error occurs, Res = FALSE) */ if( (Line[0] == 'T') && (Line[1] == 'i') ) { @@ -470,7 +470,7 @@ EDA_LibComponentStruct* Read_Component_Definition( WinEDA_DrawFrame* frame, char frame->PrintMsg( Msg ); } - /* Fin analyse de la ligne ou block: test de l'info lue */ + /* End line or block analysis: test for an error */ if( !Res ) { /* Something went wrong there. */ Msg.Printf( wxT( " Error Line %d, Library not loaded" ), *LineNum ); @@ -533,10 +533,10 @@ static LibEDA_BaseStruct* GetDrawEntry( WinEDA_DrawFrame* frame, FILE* f, char* &Arc->m_Width, chartmp, &startx, &starty, &endx, &endy ); if( nbarg < 8 ) Error = TRUE; - - Arc->m_Unit = Unit; + + Arc->m_Unit = Unit; Arc->m_Convert = Convert; - + if( chartmp[0] == 'F' ) Arc->m_Fill = FILLED_SHAPE; if( chartmp[0] == 'f' ) @@ -545,12 +545,12 @@ static LibEDA_BaseStruct* GetDrawEntry( WinEDA_DrawFrame* frame, FILE* f, char* NORMALIZE_ANGLE( Arc->t1 ); NORMALIZE_ANGLE( Arc->t2 ); - if( nbarg >= 13 ) // Coord reelles des extremites de l'arc lues + if( nbarg >= 13 ) // Actual Coordinates of arc ends are read from file { Arc->m_ArcStart.x = startx; Arc->m_ArcStart.y = starty; Arc->m_ArcEnd.x = endx; Arc->m_ArcEnd.y = endy; } - else + else // Actual Coordinates of arc ends are not read from file (old library), calculate them { Arc->m_ArcStart.x = Arc->m_Rayon; Arc->m_ArcStart.y = 0; Arc->m_ArcEnd.x = Arc->m_Rayon; Arc->m_ArcEnd.y = 0; @@ -636,11 +636,11 @@ static LibEDA_BaseStruct* GetDrawEntry( WinEDA_DrawFrame* frame, FILE* f, char* Pin->m_PinLen = ll; Pin->m_Orient = chartmp1[0] & 255; - Pin->m_Unit = Unit; + Pin->m_Unit = Unit; Pin->m_Convert = Convert; - + strncpy( (char*) &Pin->m_PinNum, PinNum, 4 ); - + Error = (i != 11 && i != 12); Pin->m_PinName = CONV_FROM_UTF8( BufName ); @@ -716,7 +716,6 @@ static LibEDA_BaseStruct* GetDrawEntry( WinEDA_DrawFrame* frame, FILE* f, char* } } } - } break; @@ -868,7 +867,7 @@ static bool GetLibEntryField( EDA_LibComponentStruct* LibEntry, char* line ) if( *line == 0 ) return 0; - line++; + line++; Text = line; /* recherche fin de texte */ @@ -877,23 +876,23 @@ static bool GetLibEntryField( EDA_LibComponentStruct* LibEntry, char* line ) if( *line == 0 ) return 0; - *line = 0; + *line = 0; line++; FieldUserName[0] = 0; - + nbparam = sscanf( line, " %d %d %d %c %c %c %c", &posx, &posy, &size, Char1, Char2, Char3, Char4 ); - orient = TEXT_ORIENT_HORIZ; - + orient = TEXT_ORIENT_HORIZ; + if( Char1[0] == 'V' ) orient = TEXT_ORIENT_VERT; - draw = TRUE; if( Char2[0] == 'I' ) + draw = TRUE; if( Char2[0] == 'I' ) draw = FALSE; - + hjustify = GR_TEXT_HJUSTIFY_CENTER; vjustify = GR_TEXT_VJUSTIFY_CENTER; - + if( nbparam >= 6 ) { if( *Char3 == 'L' ) @@ -921,7 +920,7 @@ static bool GetLibEntryField( EDA_LibComponentStruct* LibEntry, char* line ) default: if( NumOfField >= NUMBER_OF_FIELDS ) break; - + Field = new LibDrawField( NumOfField ); Field->Pnext = LibEntry->Fields; @@ -934,19 +933,19 @@ static bool GetLibEntryField( EDA_LibComponentStruct* LibEntry, char* line ) Field->m_Pos.x = posx; Field->m_Pos.y = posy; Field->m_Orient = orient; - + if( draw == FALSE ) Field->m_Attributs |= TEXT_NO_VISIBLE; - + Field->m_Size.x = Field->m_Size.y = size; Field->m_Text = CONV_FROM_UTF8( Text ); - + if( NumOfField >= FIELD1 ) { ReadDelimitedText( FieldUserName, line, sizeof(FieldUserName) ); Field->m_Name = CONV_FROM_UTF8( FieldUserName ); } - + Field->m_HJustify = hjustify; Field->m_VJustify = vjustify; return TRUE; @@ -987,7 +986,7 @@ static void InsertAlias( PriorQue** PQ, EDA_LibComponentStruct* LibEntry, unsigned ii; if( LibEntry->m_AliasList.GetCount() == 0 ) - return;/* No alias for this component */ + return; /* No alias for this component */ for( ii = 0; ii < LibEntry->m_AliasList.GetCount(); ii++ ) { @@ -1020,7 +1019,7 @@ int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName, const w return 0; if( GetLine( f, Line, &LineNum, sizeof(Line) ) == NULL ) - { + { /* pas de lignes utiles */ fclose( f ); return 0; @@ -1122,20 +1121,20 @@ void EDA_LibComponentStruct::SortDrawItems() int ii, nbitems; if( Entry == NULL ) - return; /* Pas d'alias pour ce composant */ + return; /* Pas d'alias pour ce composant */ /* calcul du nombre d'items */ for( nbitems = 0; Entry != NULL; Entry = Entry->Next() ) nbitems++; BufentryBase = - (LibEDA_BaseStruct**) MyZMalloc( (nbitems + 1) * sizeof(LibEDA_BaseStruct *) ); - + (LibEDA_BaseStruct**) MyZMalloc( (nbitems + 1) * sizeof(LibEDA_BaseStruct*) ); + /* memorisation du chainage : */ for( Entry = m_Drawings, ii = 0; Entry != NULL; Entry = Entry->Next() ) BufentryBase[ii++] = Entry; /* Tri du chainage */ - qsort( BufentryBase, nbitems, sizeof(LibEDA_BaseStruct *), SortItemsFct ); + qsort( BufentryBase, nbitems, sizeof(LibEDA_BaseStruct*), SortItemsFct ); /* Mise a jour du chainage. Remarque: * le dernier element de BufEntryBase (BufEntryBase[nbitems]) est NULL*/