diff --git a/FL/Fl_Preferences.H b/FL/Fl_Preferences.H
index 5897a736a..228c21bb0 100644
--- a/FL/Fl_Preferences.H
+++ b/FL/Fl_Preferences.H
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Preferences.H,v 1.1.2.10 2002/08/27 03:03:34 easysw Exp $"
+// "$Id: Fl_Preferences.H,v 1.1.2.11 2002/09/05 20:44:35 matthiaswm Exp $"
//
// Preferences definitions for the Fast Light Tool Kit (FLTK).
//
@@ -112,7 +112,7 @@ private:
// node methods
int write( FILE *f );
Node *find( const char *path );
- Node *search( const char *path );
+ Node *search( const char *path, int offset=0 );
Node *addChild( const char *path );
void setParent( Node *parent );
char remove();
@@ -157,5 +157,5 @@ private:
#endif // !Fl_Preferences_H
//
-// End of "$Id: Fl_Preferences.H,v 1.1.2.10 2002/08/27 03:03:34 easysw Exp $".
+// End of "$Id: Fl_Preferences.H,v 1.1.2.11 2002/09/05 20:44:35 matthiaswm Exp $".
//
diff --git a/documentation/Fl_Preferences.html b/documentation/Fl_Preferences.html
index 88dd21ace..b5ce6a4b0 100644
--- a/documentation/Fl_Preferences.html
+++ b/documentation/Fl_Preferences.html
@@ -161,6 +161,9 @@ by groups().
Returns non-zero if a group with this name exists.
+Groupnames are relative to the Preferences node and can contain a path.
+"." describes the current node, "./" describes the topmost node.
+By preceding a groupname with a "./", its path becomes relative to the topmost node.
diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx
index 0eb03d083..afe433762 100644
--- a/src/Fl_Preferences.cxx
+++ b/src/Fl_Preferences.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Preferences.cxx,v 1.1.2.19 2002/08/27 03:03:37 easysw Exp $"
+// "$Id: Fl_Preferences.cxx,v 1.1.2.20 2002/09/05 20:44:36 matthiaswm Exp $"
//
// Preferences methods for the Fast Light Tool Kit (FLTK).
//
@@ -1013,19 +1013,48 @@ Fl_Preferences::Node *Fl_Preferences::Node::find( const char *path )
}
// find a group somewhere in the tree starting here
+// caller must not set 'offset' argument
// - if the node does not exist, 'search' returns NULL
-Fl_Preferences::Node *Fl_Preferences::Node::search( const char *path )
+// - if the pathname is "." (current node) return this node
+// - if the pathname is "./" (root node) return the topmost node
+// - if the pathname starts with "./", start the search at the root node instead
+Fl_Preferences::Node *Fl_Preferences::Node::search( const char *path, int offset )
{
- int len = strlen( path_ );
- if ( strncmp( path, path_, len ) == 0 )
+
+ if ( offset == 0 )
{
- if ( path[ len ] == 0 )
+ if ( path[0] == '.' )
+ {
+ if ( path[1] == 0 )
+ {
+ return this; // user was searching for current node
+ }
+ else if ( path[1] == '/' )
+ {
+ Node *nn = this;
+ while ( nn->parent_ ) nn = nn->parent_;
+ if ( path[2]==0 )
+ { // user is searching for root ( "./" )
+ return nn;
+ }
+ return nn->search( path+2, 2 ); // do a relative search on the root node
+ }
+ }
+ offset = strlen( path_ ) + 1;
+ }
+
+ int len = strlen( path_ );
+ if ( len < offset-1 ) return 0;
+ len -= offset;
+ if ( ( len <= 0 ) || ( strncmp( path, path_+offset, len ) == 0 ) )
+ {
+ if ( len > 0 && path[ len ] == 0 )
return this;
- if ( path[ len ] == '/' )
+ if ( len <= 0 || path[ len ] == '/' )
{
for ( Node *nd = child_; nd; nd = nd->next_ )
{
- Node *nn = nd->find( path );
+ Node *nn = nd->search( path, offset );
if ( nn ) return nn;
}
return 0;
@@ -1084,5 +1113,5 @@ char Fl_Preferences::Node::remove()
//
-// End of "$Id: Fl_Preferences.cxx,v 1.1.2.19 2002/08/27 03:03:37 easysw Exp $".
+// End of "$Id: Fl_Preferences.cxx,v 1.1.2.20 2002/09/05 20:44:36 matthiaswm Exp $".
//
diff --git a/test/preferences.fl b/test/preferences.fl
index 443684c2c..06f6b25c1 100644
--- a/test/preferences.fl
+++ b/test/preferences.fl
@@ -12,6 +12,8 @@ decl {\#include } {}
decl {\#include } {}
+decl {\#include } {}
+
decl {void readPrefs();} {public
}
@@ -294,9 +296,26 @@ Function {writePrefs()} {open return_type void
eat.set( Fl_Preferences::Name( 3 ), "Test3" );
- /** sample code only:
+ /* sample: create a sub-sub-group */
+ Fl_Preferences eatMore( eat, "More" );
+
+ eatMore.set( "more", "stuff" );
+
+ /* all the following searches should return 1 */
+ int sum = 0;
+ sum += app.groupExists( "Breakfast" ); /* find 'eat' relative to 'app' */
+ sum += app.groupExists( "Breakfast/More" ); /* find 'eat.eatMore' relative to 'app' */
+ sum += app.groupExists( "./Breakfast/More" ); /* find 'eat.eatMore' relative to Preferences */
+ sum += eat.groupExists( "More" ); /* find 'eatMore' relative to 'eat' */
+ sum += eat.groupExists( "./Breakfast/More" ); /* find 'eat.eatMore' relative to Preferences */
+ sum += eat.groupExists( "." ); /* find myself ('eat') */
+ sum += eat.groupExists( "./" ); /* find the topmost group ('app') */
+ if ( sum != 7 )
+ fl_message( "Assertion failed:\\nNot all group entries were found!" );
+
+ /* sample code only: */
unsigned int hex = 0x2387efcd;
eat.set( "binFoo", (void*)&hex, sizeof( unsigned int ) );
- eat.set( "binFoo2", (void*)&writePrefs, 1024 );
- **/} {}
+ eat.set( "binFoo2", (void*)&writePrefs, 256 );
+ } {}
}