From 9f9e7fd5c1e6c690c38b052c9c7230dbbe59405a Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Sun, 9 Jan 2011 07:35:13 -0600 Subject: [PATCH] Enhance DIR_LIB_SOURCE:ReadPart() and GetRevisions() to work in the un versioned mode. --- common/richio.cpp | 2 +- new/make-dir-lib-source-test-data.sh | 5 +- new/sch_dir_lib_source.cpp | 118 ++++++++++++++++----------- new/sch_lib.h | 5 +- new/sch_lib_table.cpp | 3 +- new/sch_part.cpp | 2 +- 6 files changed, 83 insertions(+), 52 deletions(-) diff --git a/common/richio.cpp b/common/richio.cpp index 6a0f6b693e..82fca41dbe 100644 --- a/common/richio.cpp +++ b/common/richio.cpp @@ -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 ); } diff --git a/new/make-dir-lib-source-test-data.sh b/new/make-dir-lib-source-test-data.sh index 1e6ab0face..704d44840b 100755 --- a/new/make-dir-lib-source-test-data.sh +++ b/new/make-dir-lib-source-test-data.sh @@ -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 + diff --git a/new/sch_dir_lib_source.cpp b/new/sch_dir_lib_source.cpp index 3153eaf62f..51e48f0257 100644 --- a/new/sch_dir_lib_source.cpp +++ b/new/sch_dir_lib_source.cpp @@ -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,36 +456,90 @@ 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 ); + + partName += '/'; + partName + aRev; + + // find this exact 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 ) ); + } + + 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 + '/'; + + // 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 ) ); + } } - if( aRev.size() ) + else // !useVersioning { - if( rev ) // a supplied rev replaces any in aPartName - partName.resize( rev - partName.c_str() - 1 ); +#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 - partName += "/" + aRev; + // find the part name without any revision - rev = endsWithRev( partName ); - } - - // 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 ); if( it == partnames.end() ) // part not found @@ -506,26 +550,6 @@ void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const S readString( aResult, makeFileName( partName ) ); } - else - { - 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.insert( partName.begin(), '\'' ); - partName += "' is not present without a revision."; - THROW_IO_ERROR( partName ); - } - - readString( aResult, makeFileName( *it ) ); - } } diff --git a/new/sch_lib.h b/new/sch_lib.h index 88a57cee48..9dd8df3692 100644 --- a/new/sch_lib.h +++ b/new/sch_lib.h @@ -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; diff --git a/new/sch_lib_table.cpp b/new/sch_lib_table.cpp index 435ded6aa4..bc4ebe2ff8 100644 --- a/new/sch_lib_table.cpp +++ b/new/sch_lib_table.cpp @@ -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 ); } diff --git a/new/sch_part.cpp b/new/sch_part.cpp index 18aae13989..ab05858994 100644 --- a/new/sch_part.cpp +++ b/new/sch_part.cpp @@ -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 //-----------------------