Re-import the *current* version of Matthias's code, with appropriate

buffer limiting fixes, include "flstring.h" instead of <string.h>,
and replace all use of bool, true, and false, with char, 1, and 0.
(bool is not universally supported by the C++ compilers we currently
use with FLTK 1.x, so 1.x cannot use bool, true, or false without a
lot of configure crap that will make use/distribution a lot more
difficult...)


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2132 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet
2002-04-29 20:56:19 +00:00
parent c8aebffa88
commit 13587f41c2
3 changed files with 1100 additions and 977 deletions
+158 -148
View File
@@ -1,148 +1,158 @@
// //
// "$Id: Fl_Preferences.H,v 1.1.2.1 2002/04/28 16:41:16 easysw Exp $" // "$Id: Fl_Preferences.H,v 1.1.2.2 2002/04/29 20:56:19 easysw Exp $"
// //
// Preferences header file for the Fast Light Tool Kit (FLTK). // Preferences definitions for the Fast Light Tool Kit (FLTK).
// //
// Copyright 2002 by Matthias Melcher. // Copyright 2002 by Matthias Melcher.
// //
// This library is free software; you can redistribute it and/or // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public // modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either // License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version. // version 2 of the License, or (at your option) any later version.
// //
// This library is distributed in the hope that it will be useful, // This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details. // Library General Public License for more details.
// //
// You should have received a copy of the GNU Library General Public // You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA. // USA.
// //
// Please report all bugs and problems to "fltk-bugs@matthiasm.com". // Please report all bugs and problems to "fltk-bugs@fltk.org".
// //
#ifndef Fl_Preferences_H #ifndef Fl_Preferences_H
#define Fl_Preferences_H # define Fl_Preferences_H
# include <stdio.h> # ifdef WIN32
# include <windows.h>
/* missing functions: # endif // WIN32
Fl_Preferences should return functions to create and access User Data directories #include <stdio.h>
Fl_Preferences could offer functions that return the value instead off an error code to write directly into widgets
*/
// missing features:
/** // - get and set binary data
* Preferences are a data tree containing a root, branches and leafs // - Fl_Preferences could offer functions that return the value instead off an error code to write directly into widgets
*/
class Fl_Preferences
{ /**
* Preferences are a data tree containing a root, branches and leafs
public: */
class Fl_Preferences
typedef enum { SYSTEM=0, USER } Root; {
// typedef enum { win32, macos, fltk } Type;
public:
FL_EXPORT Fl_Preferences( enum Root root, const char *vendor, const char *application );
FL_EXPORT Fl_Preferences( Fl_Preferences&, const char *group ); typedef enum { SYSTEM=0, USER } Root;
FL_EXPORT Fl_Preferences( Fl_Preferences*, const char *group ); // typedef enum { win32, macos, fltk } Type;
FL_EXPORT ~Fl_Preferences();
FL_EXPORT Fl_Preferences( enum Root root, const char *vendor, const char *application );
FL_EXPORT int groups(); FL_EXPORT Fl_Preferences( Fl_Preferences&, const char *group );
FL_EXPORT const char *group( int ); FL_EXPORT Fl_Preferences( Fl_Preferences*, const char *group );
FL_EXPORT int groupExists( const char *group ); FL_EXPORT ~Fl_Preferences();
FL_EXPORT int deleteGroup( const char *group );
FL_EXPORT int groups();
FL_EXPORT int entries(); FL_EXPORT const char *group( int );
FL_EXPORT const char *entry( int ); FL_EXPORT char groupExists( const char *group );
FL_EXPORT int entryExists( const char *entry ); FL_EXPORT char deleteGroup( const char *group );
FL_EXPORT int deleteEntry( const char *entry );
FL_EXPORT int entries();
FL_EXPORT int set( const char *entry, int value ); FL_EXPORT const char *entry( int );
FL_EXPORT int set( const char *entry, float value ); FL_EXPORT char entryExists( const char *entry );
FL_EXPORT int set( const char *entry, double value ); FL_EXPORT char deleteEntry( const char *entry );
FL_EXPORT int set( const char *entry, const char *value );
// FL_EXPORT int set( const char *entry, const void *value, int size ); FL_EXPORT char set( const char *entry, char value );
FL_EXPORT char set( const char *entry, int value );
FL_EXPORT int get( const char *entry, int &value, int defaultValue ); FL_EXPORT char set( const char *entry, float value );
FL_EXPORT int get( const char *entry, float &value, float defaultValue ); FL_EXPORT char set( const char *entry, double value );
FL_EXPORT int get( const char *entry, double &value, double defaultValue ); FL_EXPORT char set( const char *entry, const char *value );
FL_EXPORT int get( const char *entry, char *&value, const char *defaultValue ); // FL_EXPORT char set( const char *entry, const void *value, int size );
FL_EXPORT int get( const char *entry, char *value, const char *defaultValue, int maxSize );
// FL_EXPORT int get( const char *entry, void *&value, const char *defaultValue ); FL_EXPORT char get( const char *entry, char &value, char defaultValue );
// FL_EXPORT int get( const char *entry, void *value, const char *defaultValue, int maxSize ); FL_EXPORT char get( const char *entry, int &value, int defaultValue );
FL_EXPORT int size( const char *entry ); FL_EXPORT char get( const char *entry, float &value, float defaultValue );
FL_EXPORT char get( const char *entry, double &value, double defaultValue );
FL_EXPORT int getUserdataPath( char *path ); FL_EXPORT char get( const char *entry, char *&value, const char *defaultValue );
FL_EXPORT char get( const char *entry, char *value, const char *defaultValue, int maxSize );
FL_EXPORT void flush(); // FL_EXPORT char get( const char *entry, void *&value, const char *defaultValue );
// FL_EXPORT char get( const char *entry, void *value, const char *defaultValue, int maxSize );
// FL_EXPORT int export( const char *filename, enum Type fileFormat ); FL_EXPORT int size( const char *entry );
// FL_EXPORT int import( const char *filename );
FL_EXPORT char getUserdataPath( char *path );
// FL_EXPORT const char *namef( const char *, ... );
FL_EXPORT void flush();
private:
// FL_EXPORT char export( const char *filename, enum Type fileFormat );
static char nameBuffer[128]; // FL_EXPORT char import( const char *filename );
struct Entry // FL_EXPORT const char *namef( const char *, ... );
{
char *name, *value; private:
};
static char nameBuffer[128];
class Node
{ struct Entry
Node *child_, *next_, *parent_; {
char *path_; char *name, *value;
int dirty_; };
public:
Node( const char *path ); class Node // a node contains a list to all its entries
~Node(); { // and all means to manage the tree structure
Node *find( const char *path ); Node *child_, *next_, *parent_;
Node *search( const char *path ); char *path_;
int write( FILE *f ); char dirty_;
void setParent( Node *parent ); public:
Node *addChild( const char *path ); Node( const char *path );
void set( const char *name, const char *value ); ~Node();
void set( const char *line ); // node methods
void add( const char *line ); int write( FILE *f );
const char *get( const char *name ); Node *find( const char *path );
int getEntry( const char *name ); Node *search( const char *path );
int deleteEntry( const char *name ); Node *addChild( const char *path );
int remove(); void setParent( Node *parent );
int dirty(); char remove();
int nChildren(); char dirty();
const char *child( int ix ); // entry methods
Entry *entry; int nChildren();
int nEntry, NEntry; const char *child( int ix );
static int lastEntrySet; void set( const char *name, const char *value );
}; void set( const char *line );
friend class Node; void add( const char *line );
const char *get( const char *name );
class RootNode int getEntry( const char *name );
{ char deleteEntry( const char *name );
Fl_Preferences *prefs_; //++ maybe we should hold a reference to the first node // public values
char *filename_; Entry *entry;
char *vendor_, *application_; int nEntry, NEntry;
public: static int lastEntrySet;
RootNode( Fl_Preferences *, enum Root root, const char *vendor, const char *application ); };
~RootNode(); friend class Node;
int read();
int write(); class RootNode // the root node manages file paths and basic reading and writing
int getPath( char *path ); {
}; Fl_Preferences *prefs_;
friend class RootNode; char *filename_;
char *vendor_, *application_;
Node *node; public:
RootNode *rootNode; RootNode( Fl_Preferences *, enum Root root, const char *vendor, const char *application );
}; ~RootNode();
int read();
int write();
#endif char getPath( char *path );
};
// friend class RootNode;
// End of "$Id: Fl_Preferences.H,v 1.1.2.1 2002/04/28 16:41:16 easysw Exp $".
// Node *node;
RootNode *rootNode;
};
#endif // !Fl_Preferences_H
//
// End of "$Id: Fl_Preferences.H,v 1.1.2.2 2002/04/29 20:56:19 easysw Exp $".
//
+939 -827
View File
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -1,5 +1,5 @@
/* /*
* "$Id: flstring.h,v 1.1.2.4 2002/03/28 16:57:41 easysw Exp $" * "$Id: flstring.h,v 1.1.2.5 2002/04/29 20:56:19 easysw Exp $"
* *
* Common string header file for the Fast Light Tool Kit (FLTK). * Common string header file for the Fast Light Tool Kit (FLTK).
* *
@@ -32,6 +32,7 @@
# ifdef HAVE_STRINGS_H # ifdef HAVE_STRINGS_H
# include <strings.h> # include <strings.h>
# endif /* HAVE_STRINGS_H */ # endif /* HAVE_STRINGS_H */
# include <ctype.h>
/* /*
* Apparently Unixware defines "index" to strchr (!) rather than * Apparently Unixware defines "index" to strchr (!) rather than
@@ -71,5 +72,5 @@ extern int fl_vsnprintf(char *, size_t, const char *, va_list ap);
#endif /* !flstring_h */ #endif /* !flstring_h */
/* /*
* End of "$Id: flstring.h,v 1.1.2.4 2002/03/28 16:57:41 easysw Exp $". * End of "$Id: flstring.h,v 1.1.2.5 2002/04/29 20:56:19 easysw Exp $".
*/ */