Commit 9f9e7fd5 authored by Dick Hollenbeck's avatar Dick Hollenbeck

Enhance DIR_LIB_SOURCE:ReadPart() and GetRevisions() to work in the un versioned mode.

parent b752cfde
...@@ -230,7 +230,7 @@ int OUTPUTFORMATTER::vprint( const char* fmt, va_list ap ) throw( IO_ERROR ) ...@@ -230,7 +230,7 @@ int OUTPUTFORMATTER::vprint( const char* fmt, va_list ap ) throw( IO_ERROR )
int ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap ); int ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap );
if( ret >= (int) buffer.size() ) if( ret >= (int) buffer.size() )
{ {
buffer.reserve( ret+200 ); buffer.resize( ret+2000 );
ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap ); ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap );
} }
......
...@@ -16,7 +16,10 @@ for C in ${CATEGORIES}; do ...@@ -16,7 +16,10 @@ for C in ${CATEGORIES}; do
for P in ${PARTS}; do for P in ${PARTS}; do
for R in ${REVS}; do for R in ${REVS}; do
(part $C/$P/$R extends $P/$R (value 22)(footprint SM0805)) > $BASEDIR/$C/$P.part.$R echo "(part $C/$P (value 22)(footprint SM0805))" > $BASEDIR/$C/$P.part.$R
done done
# also make the part without a rev:
echo "(part $C/$P (value 22)(footprint SM0805))" > $BASEDIR/$C/$P.part
done done
done done
...@@ -59,16 +59,6 @@ using namespace std; ...@@ -59,16 +59,6 @@ using namespace std;
using namespace SCH; using namespace SCH;
/* __func__ is C99 prescribed, but just in case:
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=338
#if defined(__GNUG__) // The GNU C++ compiler defines this
#define FUNC_NAME(x) // nothing, GNU C++ defines __func__ just fine.
#else
#define FUNC_NAME(x) static const char __func__[] = #x;
#endif
*/
/** /**
* Class DIR_WRAP * Class DIR_WRAP
* provides a destructor which is invoked if an exception is thrown. * provides a destructor which is invoked if an exception is thrown.
...@@ -466,36 +456,37 @@ void DIR_LIB_SOURCE::GetRevisions( STRINGS* aResults, const STRING& aPartName ) ...@@ -466,36 +456,37 @@ void DIR_LIB_SOURCE::GetRevisions( STRINGS* aResults, const STRING& aPartName )
aResults->push_back( it->substr( rev - it->c_str() ) ); aResults->push_back( it->substr( rev - it->c_str() ) );
} }
} }
else
{
// In non-version mode, there were no revisions read in, only part
// files without a revision. But clients higher up expect to see
// at least one revision in order for the API to work, so we return
// a revision ""
aResults->push_back( "" );
}
} }
void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const STRING& aRev ) void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const STRING& aRev )
throw( IO_ERROR ) throw( IO_ERROR )
{ {
STRING partName = aPartName; // appended with aRev too if not empty STRING partName = aPartName;
const char* rev = endsWithRev( partName ); const char* hasRev = endsWithRev( partName );
if( !useVersioning && (aRev.size() || rev) ) if( useVersioning )
{ {
STRING msg = "this type 'dir' LIB_SOURCE not using 'useVersioning' option, cannot ask for a revision";
THROW_IO_ERROR( msg );
}
if( aRev.size() ) if( aRev.size() )
{ {
if( rev ) // a supplied rev replaces any in aPartName // a supplied rev replaces any in aPartName
partName.resize( rev - partName.c_str() - 1 ); if( hasRev )
partName.resize( hasRev - partName.c_str() - 1 );
partName += "/" + aRev; partName += '/';
partName + aRev;
rev = endsWithRev( partName ); // find this exact revision
}
// partName is the exact part name we need here, or if rev is NULL,
// then look for the highest numbered revision.
if( rev )
{
PN_ITER it = partnames.find( partName ); PN_ITER it = partnames.find( partName );
if( it == partnames.end() ) // part not found if( it == partnames.end() ) // part not found
...@@ -506,8 +497,13 @@ void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const S ...@@ -506,8 +497,13 @@ void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const S
readString( aResult, makeFileName( partName ) ); readString( aResult, makeFileName( partName ) );
} }
else else
{ {
// There's no rev on partName string. Find the most recent rev, i.e. highest,
// which will be first because of the BY_REV compare method, which treats
// higher numbered revs as first.
STRING search = partName + '/'; STRING search = partName + '/';
// There's no rev on partName string. Find the most recent rev, i.e. highest, // There's no rev on partName string. Find the most recent rev, i.e. highest,
...@@ -517,15 +513,43 @@ void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const S ...@@ -517,15 +513,43 @@ void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const S
// verify that this one that is greater than partName is a match and not // verify that this one that is greater than partName is a match and not
// some unrelated name that is larger. // some unrelated name that is larger.
if( it == partnames.end() || it->compare( 0, search.size(), search ) != 0 ) if( it == partnames.end() ||
it->compare( 0, search.size(), search ) != 0 )
{ {
partName.insert( partName.begin(), '\'' ); partName += " is not present without a revision.";
partName += "' is not present without a revision.";
THROW_IO_ERROR( partName ); THROW_IO_ERROR( partName );
} }
readString( aResult, makeFileName( *it ) ); readString( aResult, makeFileName( *it ) );
} }
}
else // !useVersioning
{
#if 1
if( hasRev || aRev.size() )
{
STRING msg = "this type 'dir' LIB_SOURCE not using 'useVersioning' option, cannot ask for a revision";
THROW_IO_ERROR( msg );
}
#else
// no revisions allowed, strip it
if( hasRev )
partName.resize( hasRev - partName.c_str() - 1 );
#endif
// find the part name without any revision
PN_ITER it = partnames.find( partName );
if( it == partnames.end() ) // part not found
{
partName += " not found.";
THROW_IO_ERROR( partName );
}
readString( aResult, makeFileName( partName ) );
}
} }
......
...@@ -107,7 +107,10 @@ protected: ///< derived classes must implement ...@@ -107,7 +107,10 @@ protected: ///< derived classes must implement
* fetches all revisions for @a aPartName into @a aResults. Revisions are strings * fetches all revisions for @a aPartName into @a aResults. Revisions are strings
* like "rev12", "rev279", and are library source agnostic. These do not have to be * like "rev12", "rev279", and are library source agnostic. These do not have to be
* in a contiguous order, but the first 3 characters must be "rev" and subsequent * in a contiguous order, but the first 3 characters must be "rev" and subsequent
* characters must consist of at least one decimal digit. * characters must consist of at least one decimal digit. If the LIB_SOURCE
* does not support revisions, it is allowed to return a single "" string as
* the only result. This means aPartName is present in the libsource, only once
* without a revision. This is a special case.
*/ */
virtual void GetRevisions( STRINGS* aResults, const STRING& aPartName ) virtual void GetRevisions( STRINGS* aResults, const STRING& aPartName )
throw( IO_ERROR ) = 0; throw( IO_ERROR ) = 0;
......
...@@ -355,6 +355,7 @@ void LIB_TABLE::Test() ...@@ -355,6 +355,7 @@ void LIB_TABLE::Test()
"(lib_table \n" "(lib_table \n"
" (lib (logical www) (type http) (full_uri http://kicad.org/libs) (options \" \"))\n" " (lib (logical www) (type http) (full_uri http://kicad.org/libs) (options \" \"))\n"
" (lib (logical meparts) (type dir) (full_uri /tmp/eeschema-lib) (options useVersioning))\n" " (lib (logical meparts) (type dir) (full_uri /tmp/eeschema-lib) (options useVersioning))\n"
// " (lib (logical meparts) (type dir) (full_uri /tmp/eeschema-lib) (options \" \"))\n"
" (lib (logical old-project) (type schematic)(full_uri /tmp/old-schematic.sch) (options \" \"))\n" " (lib (logical old-project) (type schematic)(full_uri /tmp/old-schematic.sch) (options \" \"))\n"
")\n" ")\n"
, ,
...@@ -399,7 +400,7 @@ void LIB_TABLE::Test() ...@@ -399,7 +400,7 @@ void LIB_TABLE::Test()
} }
// find a part // find a part
LPID lpid( "meparts:tigers/ears/rev10" ); LPID lpid( "meparts:tigers/ears" );
LookupPart( lpid ); LookupPart( lpid );
} }
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
using namespace SCH; using namespace SCH;
#define MAX_INHERITANCE_NESTING 10 // no problem going larger #define MAX_INHERITANCE_NESTING 6 // no problem going larger
//-----<temporary home for PART sub objects, move after stable>------------------ //-----<temporary home for PART sub objects, move after stable>------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment