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 )
int ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap );
if( ret >= (int) buffer.size() )
{
buffer.reserve( ret+200 );
buffer.resize( ret+2000 );
ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap );
}
......
......@@ -16,7 +16,10 @@ for C in ${CATEGORIES}; do
for P in ${PARTS}; 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
# also make the part without a rev:
echo "(part $C/$P (value 22)(footprint SM0805))" > $BASEDIR/$C/$P.part
done
done
......@@ -59,16 +59,6 @@ using namespace std;
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
* provides a destructor which is invoked if an exception is thrown.
......@@ -466,65 +456,99 @@ void DIR_LIB_SOURCE::GetRevisions( STRINGS* aResults, const STRING& aPartName )
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 )
throw( IO_ERROR )
{
STRING partName = aPartName; // appended with aRev too if not empty
const char* rev = endsWithRev( partName );
STRING partName = aPartName;
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() )
{
// a supplied rev replaces any in aPartName
if( hasRev )
partName.resize( hasRev - partName.c_str() - 1 );
if( aRev.size() )
{
if( rev ) // a supplied rev replaces any in aPartName
partName.resize( rev - partName.c_str() - 1 );
partName += '/';
partName + aRev;
partName += "/" + aRev;
// find this exact revision
rev = endsWithRev( partName );
}
PN_ITER it = partnames.find( partName );
// partName is the exact part name we need here, or if rev is NULL,
// then look for the highest numbered revision.
if( it == partnames.end() ) // part not found
{
partName += " not found.";
THROW_IO_ERROR( partName );
}
if( rev )
{
PN_ITER it = partnames.find( partName );
readString( aResult, makeFileName( partName ) );
}
if( it == partnames.end() ) // part not found
else
{
partName += " not found.";
THROW_IO_ERROR( partName );
}
// 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.
readString( aResult, makeFileName( partName ) );
STRING search = partName + '/';
// 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.
PN_ITER it = partnames.upper_bound( search );
// verify that this one that is greater than partName is a match and not
// some unrelated name that is larger.
if( it == partnames.end() ||
it->compare( 0, search.size(), search ) != 0 )
{
partName += " is not present without a revision.";
THROW_IO_ERROR( partName );
}
readString( aResult, makeFileName( *it ) );
}
}
else
else // !useVersioning
{
STRING search = partName + '/';
#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
// 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.
PN_ITER it = partnames.upper_bound( search );
// find the part name without any revision
// verify that this one that is greater than partName is a match and not
// some unrelated name that is larger.
if( it == partnames.end() || it->compare( 0, search.size(), search ) != 0 )
PN_ITER it = partnames.find( partName );
if( it == partnames.end() ) // part not found
{
partName.insert( partName.begin(), '\'' );
partName += "' is not present without a revision.";
partName += " not found.";
THROW_IO_ERROR( partName );
}
readString( aResult, makeFileName( *it ) );
readString( aResult, makeFileName( partName ) );
}
}
......
......@@ -107,7 +107,10 @@ protected: ///< derived classes must implement
* 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
* 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 )
throw( IO_ERROR ) = 0;
......
......@@ -355,6 +355,7 @@ void LIB_TABLE::Test()
"(lib_table \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 \" \"))\n"
" (lib (logical old-project) (type schematic)(full_uri /tmp/old-schematic.sch) (options \" \"))\n"
")\n"
,
......@@ -399,7 +400,7 @@ void LIB_TABLE::Test()
}
// find a part
LPID lpid( "meparts:tigers/ears/rev10" );
LPID lpid( "meparts:tigers/ears" );
LookupPart( lpid );
}
......
......@@ -31,7 +31,7 @@
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>------------------
......
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