pdatabase-cvs Mailing List for pdb (Page 2)
Brought to you by:
paralizer
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(9) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(17) |
Feb
(30) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(5) |
Oct
(2) |
Nov
|
Dec
|
From: Michael L. <par...@us...> - 2005-02-10 02:51:16
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29944/include Modified Files: Makefile pdb.h Log Message: Fixed crash on load if file is nonexistant. Index: pdb.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pdb.h 8 Feb 2005 15:10:18 -0000 1.9 +++ pdb.h 10 Feb 2005 02:51:06 -0000 1.10 @@ -69,7 +69,7 @@ * thread safe features for pdb. */ #define PDB_USING_THREADS -//#define PDB_THREAD_DEBUG +#define PDB_THREAD_DEBUG #ifdef PDB_USING_THREADS #include <pthread.h> Index: Makefile =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/Makefile,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile 9 Jan 2005 01:28:05 -0000 1.2 +++ Makefile 10 Feb 2005 02:51:06 -0000 1.3 @@ -56,7 +56,7 @@ PRE_UNINSTALL = : POST_UNINSTALL = : host_alias = -host_triplet = i686-pc-linux-gnu +host_triplet = x86_64-unknown-linux-gnu AMTAR = ${SHELL} /home/para/Projects/pdb/missing --run tar AR = ar AS = @AS@ @@ -71,7 +71,7 @@ ECHO = echo EGREP = grep -E EXEEXT = -F77 = +F77 = g77 GCJ = @GCJ@ GCJFLAGS = @GCJFLAGS@ INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s |
From: Michael L. <par...@us...> - 2005-02-10 02:51:15
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29944/src Modified Files: Makefile pdb.c Log Message: Fixed crash on load if file is nonexistant. Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- pdb.c 8 Feb 2005 15:10:18 -0000 1.12 +++ pdb.c 10 Feb 2005 02:51:06 -0000 1.13 @@ -37,7 +37,7 @@ printf(PDB_COMPILE_INFO); printf("\n--LOAD--\n\n"); - struct pdb* dbptr = pdb_load("/home/para/test.db"); + struct pdb* dbptr = pdb_load("/home/para/para.db"); printf("\n--DEBUG--\n\n"); @@ -48,7 +48,8 @@ pdb_write(dbptr, "/home/para/test.db2"); printf("\n--UNLOAD--\n\n"); - pdb_unload(dbptr); + if (dbptr) + pdb_unload(dbptr); return 0; }*/ @@ -117,6 +118,9 @@ * Unload a database. */ int pdb_unload(struct pdb* dbptr) { + if (!dbptr) + return 0; + PDB_MUTEX_LOCK(dbptr); int ret = pdb_free_node(dbptr->data); @@ -136,6 +140,9 @@ * settings are OR'ed togther. */ void pdb_enable(struct pdb* dbptr, int settings) { + if (!dbptr) + return; + PDB_MUTEX_LOCK(dbptr); dbptr->settings |= settings; @@ -149,6 +156,9 @@ * settings are OR'ed togther. */ void pdb_disable(struct pdb* dbptr, int settings) { + if (!dbptr) + return; + PDB_MUTEX_LOCK(dbptr); dbptr->settings &= ~settings; @@ -161,6 +171,9 @@ * Return 1 if the given setting is set. */ int pdb_is_set(struct pdb* dbptr, int setting) { + if (!dbptr) + return 0; + return ((dbptr->settings & setting) == setting); } @@ -176,6 +189,9 @@ struct pdb_node_types_t* tiptr; int ret; + if (!dbptr) + return 0; + nptr = pdb_query_node(dbptr, path); if (!nptr) @@ -200,6 +216,9 @@ struct pdb_node_types_t* tiptr; int i = 0; + if (!dbptr) + return 0; + PDB_MUTEX_LOCK(dbptr); if (!strcmp(path, "") || !strcmp(path, "/")) { @@ -231,7 +250,12 @@ * Return a given node's data pointer from the database. */ void* pdb_query(struct pdb* dbptr, char* path) { - struct pdb_node_t* nptr = pdb_query_node(dbptr, path); + struct pdb_node_t* nptr; + + if (!dbptr) + return NULL; + + nptr = pdb_query_node(dbptr, path); return (nptr ? nptr->data : NULL); } @@ -260,6 +284,9 @@ struct pdb_node_types_t* ptiptr; struct pdb_node_t* nptr; + if (!dbptr) + return NULL; + PDB_MUTEX_LOCK(dbptr); tiptr = pdb_get_type_info(type); @@ -316,6 +343,9 @@ struct pdb_node_t* nptr; struct pdb_node_types_t* tiptr; + if (!dbptr) + return 0; + nptr = pdb_query_node(dbptr, path); if (!nptr) return 0; @@ -404,6 +434,9 @@ * Set the disk write interval. */ void pdb_set_write_interval(struct pdb* dbptr, int seconds) { + if (!dbptr) + return; + PDB_MUTEX_LOCK(dbptr); dbptr->write_interval = seconds; PDB_MUTEX_UNLOCK(dbptr); @@ -413,6 +446,9 @@ * Return 1 if the pdb is scheduled for a disk write. */ int pdb_need_write(struct pdb* dbptr) { + if (!dbptr) + return 0; + return (time(NULL) >= (dbptr->last_write + dbptr->write_interval)); } @@ -425,6 +461,9 @@ struct pdb_node_t* nptr; int ret; + if (!dbptr) + return 0; + PDB_MUTEX_LOCK(dbptr); if (!dbptr) { @@ -468,6 +507,9 @@ void pdb_set_free_method(struct pdb* dbptr, struct pdb_node_t* nptr, void* free_cb) { + if (!dbptr) + return; + PDB_MUTEX_LOCK(dbptr); nptr->custom_free_cb = (custom_free_cb_t)free_cb; PDB_MUTEX_UNLOCK(dbptr); @@ -479,9 +521,14 @@ */ int pdb_count_children(struct pdb* dbptr, char* path) { struct pdb_node_types_t* tiptr; - struct pdb_node_t* nptr = pdb_query_node(dbptr, path); + struct pdb_node_t* nptr; int ret; + if (!dbptr) + return 0; + + nptr = pdb_query_node(dbptr, path); + if (!nptr) return 0; Index: Makefile =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/Makefile,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile 8 Feb 2005 15:10:18 -0000 1.3 +++ Makefile 10 Feb 2005 02:51:06 -0000 1.4 @@ -56,7 +56,7 @@ PRE_UNINSTALL = : POST_UNINSTALL = : host_alias = -host_triplet = i686-pc-linux-gnu +host_triplet = x86_64-unknown-linux-gnu AMTAR = ${SHELL} /home/para/Projects/pdb/missing --run tar AR = ar AS = @AS@ @@ -71,7 +71,7 @@ ECHO = echo EGREP = grep -E EXEEXT = -F77 = +F77 = g77 GCJ = @GCJ@ GCJFLAGS = @GCJFLAGS@ INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s |
From: Michael L. <par...@us...> - 2005-02-08 21:17:56
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1962/src Modified Files: binarytree.c Log Message: Compiles on 64 bit linux with no warnings. Index: binarytree.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/binarytree.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- binarytree.c 8 Feb 2005 15:10:18 -0000 1.6 +++ binarytree.c 8 Feb 2005 21:17:03 -0000 1.7 @@ -387,8 +387,8 @@ if (nptr == NULL) return; - /*printf("[tree debug] address:%x\tkey: _%s_\n", - (unsigned long*)nptr, nptr->key);*/ + printf("[tree debug] address:%lx\tkey: _%s_\n", + (unsigned long)nptr, nptr->key); //printf("%s right\n", nptr->key); tree_debug(nptr->right); |
From: Michael L. <par...@us...> - 2005-02-08 21:17:49
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1962 Modified Files: pdb.pws Log Message: Compiles on 64 bit linux with no warnings. Index: pdb.pws =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.pws,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- pdb.pws 8 Feb 2005 18:08:28 -0000 1.12 +++ pdb.pws 8 Feb 2005 21:16:59 -0000 1.13 @@ -1,9 +1,9 @@ [filenumbers] -0=63 -1=1265 -2=442 -3=45 +0=400 +1=42 +2=1265 +3=442 4=24 5=149 6=101 @@ -31,9 +31,10 @@ clean before build=false [filelist] -0=/home/para/Projects/pdb/include/binarytree.h -1=/home/para/Projects/pdb/src/pdb_types.c -2=/home/para/Projects/pdb/src/pdb.c +0=/home/para/Projects/pdb/src/binarytree.c +1=/home/para/Projects/pdb/include/binarytree.h +2=/home/para/Projects/pdb/src/pdb_types.c +3=/home/para/Projects/pdb/src/pdb.c [Project Tree] 0=0 |
From: Michael L. <par...@us...> - 2005-02-08 21:17:46
|
Update of /cvsroot/pdatabase/pdb/api_src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1962/api_src Modified Files: pdb.h Log Message: Compiles on 64 bit linux with no warnings. Index: pdb.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/api_src/pdb.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pdb.h 8 Feb 2005 18:08:29 -0000 1.2 +++ pdb.h 8 Feb 2005 21:17:02 -0000 1.3 @@ -29,10 +29,11 @@ #define __PDB_H /* - * Windows or POSIZ? + * Windows or POSIX? */ -//#define WIN32 -#define POSIX +#ifndef WIN32 + #define POSIX +#endif /* * Enable verbose loading/unloading messages. @@ -41,6 +42,13 @@ /* + * Using threads? Define this ONLY if you defined it + * within pdb, otherwise the structures will be different. + */ +//#define PDB_USING_THREADS + + +/* * This callback can be used to override standard free * callbacks for nodes. It is especially useful for non-standard * types like ABSTRACT_NODE_TYPE, where the actual data type may @@ -77,9 +85,31 @@ #endif }; +/* + * PDB types. + */ +enum { + NO_NODE_TYPE, + TREE_NODE_TYPE, + LIST_NODE_TYPE, + HASH_NODE_TYPE, + STRING_NODE_TYPE, + INT_NODE_TYPE, + ABSTRACT_NODE_TYPE, + LINK_NODE_TYPE +}; + +/* + * pdb setting value bitmasks. + */ +#define PDB_CASE_INSENSITIVE 1 +#define PDB_WRITE_SHUFFLE 2 +#define PDB_WRITE_NODE_FIRST 4 +#define PDB_THREAD_SAFE 8 + #ifdef WIN32 - #define dlsym((struct HINSTANCE__*)obj, func) \ - GetProcAddress((struct HINSTANCE__*)hDLL, func.c_str()) + #define dlsym(obj, func) \ + GetProcAddress((HMODULE)obj, func) #endif struct _pdb_funcs_t { @@ -112,6 +142,22 @@ struct pdb_node_t* nptr, void* free_cb); int (*_pdb_count_children_fptr)(struct pdb* dbptr, char* path); + + int (*_pdb_free_node_fptr)(struct pdb_node_t* nptr); + + /* + * Extra wrappers for pdb_set_node() + */ + struct pdb_node_t* (*_pdb_create_tree_fptr)(struct pdb* dbptr, char* path, + char* key); + struct pdb_node_t* (*_pdb_create_list_fptr)(struct pdb* dbptr, char* path, + char* key); + struct pdb_node_t* (*_pdb_create_hash_fptr)(struct pdb* dbptr, char* path, + char* key, int size); + struct pdb_node_t* (*_pdb_create_abstract_fptr)(struct pdb* dbptr, + char* path, char* key, void* data, void* free_cb); + struct pdb_node_t* (*_pdb_set_int_fptr)(struct pdb* dbptr, char* path, + char* key, int data); }; @@ -120,7 +166,6 @@ * BEGIN - INTERNAL DATA STRUCTURES * **********************************************/ - /* * HASH TABLE */ @@ -190,7 +235,6 @@ tree_str_cmp_cb _tree_str_cmp; }; - /********************************************** * * END - INTERNAL DATA STRUCTURES @@ -238,7 +282,21 @@ void* free_cb); int pdb_count_children(struct pdb* dbptr, char* path); - + +int pdb_free_node(struct pdb_node_t* nptr); + +/* + * Extra wrappers for pdb_set_node() + */ +struct pdb_node_t* pdb_create_tree(struct pdb* dbptr, char* path, char* key); +struct pdb_node_t* pdb_create_list(struct pdb* dbptr, char* path, char* key); +struct pdb_node_t* pdb_create_hash(struct pdb* dbptr, char* path, char* key, + int size); +struct pdb_node_t* pdb_create_abstract(struct pdb* dbptr, char* path, + char* key, void* data, void* free_cb); +struct pdb_node_t* pdb_set_int(struct pdb* dbptr, char* path, char* key, + int data); + #ifdef __cplusplus } #endif |
From: Michael L. <par...@us...> - 2005-02-08 18:08:56
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24568 Modified Files: pdb.pws Log Message: Updated api_src/pdb.h with data structs Index: pdb.pws =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.pws,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- pdb.pws 8 Feb 2005 15:10:17 -0000 1.11 +++ pdb.pws 8 Feb 2005 18:08:28 -0000 1.12 @@ -1,8 +1,8 @@ [filenumbers] -0=1265 -1=442 -2=1 +0=63 +1=1265 +2=442 3=45 4=24 5=149 @@ -31,8 +31,9 @@ clean before build=false [filelist] -0=/home/para/Projects/pdb/src/pdb_types.c -1=/home/para/Projects/pdb/src/pdb.c +0=/home/para/Projects/pdb/include/binarytree.h +1=/home/para/Projects/pdb/src/pdb_types.c +2=/home/para/Projects/pdb/src/pdb.c [Project Tree] 0=0 |
From: Michael L. <par...@us...> - 2005-02-08 18:08:55
|
Update of /cvsroot/pdatabase/pdb/api_src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24568/api_src Modified Files: pdb.h Log Message: Updated api_src/pdb.h with data structs Index: pdb.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/api_src/pdb.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- pdb.h 8 Feb 2005 15:10:18 -0000 1.1 +++ pdb.h 8 Feb 2005 18:08:29 -0000 1.2 @@ -114,6 +114,89 @@ int (*_pdb_count_children_fptr)(struct pdb* dbptr, char* path); }; + +/********************************************** + * + * BEGIN - INTERNAL DATA STRUCTURES + * + **********************************************/ + +/* + * HASH TABLE + */ +/* + * A hash node. + */ +struct hash_node_t { + char* id; + void* data; +}; +/* + * The root hash type. + */ +struct hash { + int size; + struct linkList** tbl; +}; +/* + * Callback which can be passed to free_hash(). + */ +typedef void (*hash_func_ptr)(void* dptr); + +/* + * LINKED LIST + */ +enum list_add_seq { + ADD_BEFORE, + ADD_AFTER +}; +typedef void (*list_func_ptr)(void* dptr); + +/* Individual Node + Within The List */ +struct linkNode { + struct linkNode* prev; + struct linkNode* next; + void* data; +}; +/* List Structure */ +struct linkList { + struct linkNode* root; + struct linkNode* last; +}; + +/* + * BINARY TREE + */ +typedef void (*tree_func_ptr)(void* dptr); +typedef int (*tree_str_cmp_cb)(char* s1, char* s2); +/* + * Individual Node + * Within The Tree + */ +struct treeNode { + struct treeNode* right; + struct treeNode* left; + struct treeNode* parent; + char* key; + void* data; +}; +/* + * Tree Structure + */ +struct binaryTree { + struct treeNode* root; + int flags; + tree_str_cmp_cb _tree_str_cmp; +}; + + +/********************************************** + * + * END - INTERNAL DATA STRUCTURES + * + **********************************************/ + #ifdef __cplusplus extern "C" { |
From: Michael L. <par...@us...> - 2005-02-08 15:10:58
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18589/include Modified Files: pdb.h Added Files: hash.h Log Message: Added api_src/ Index: pdb.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- pdb.h 25 Jan 2005 02:29:41 -0000 1.8 +++ pdb.h 8 Feb 2005 15:10:18 -0000 1.9 @@ -22,8 +22,6 @@ #ifndef _PDB_H #define _PDB_H -#include <pthread.h> - /* * Handy macros. */ @@ -73,6 +71,9 @@ #define PDB_USING_THREADS //#define PDB_THREAD_DEBUG +#ifdef PDB_USING_THREADS + #include <pthread.h> +#endif /* * Macros to lock or unlock a mutex if @@ -161,7 +162,9 @@ long last_write; int write_interval; /* in seconds */ int settings; - pthread_mutex_t* mutex; + #ifdef PDB_USING_THREADS + pthread_mutex_t* mutex; + #endif }; --- NEW FILE: hash.h --- /* * This file is part of pdb. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Header: /cvsroot/pdatabase/pdb/include/hash.h,v 1.1 2005/02/08 15:10:18 paralizer Exp $ * */ #ifndef _HASH_H #define _HASH_H /* * A hash node. */ struct hash_node_t { char* id; void* data; }; /* * The root hash type. */ struct hash { int size; struct linkList** tbl; }; /* * Callback which can be passed to free_hash(). */ typedef void (*hash_func_ptr)(void* dptr); #ifdef __cplusplus extern "C" { #endif struct hash* hash_create(int size); void hash_free(struct hash* hptr, hash_func_ptr free_callback); int hash_add(struct hash* hptr, char* key, void* dptr); void* hash_get(struct hash* hptr, char* key); struct hash_node_t* hash_get_node(struct hash* hptr, char* key); int hash_del(struct hash* hptr, char* key, hash_func_ptr free_callback); int hash_remove(struct hash* hptr, char* key); int hash_count_children(struct hash* hptr); #ifdef __cplusplus } #endif #endif /* _HASH_H */ |
From: Michael L. <par...@us...> - 2005-02-08 15:10:57
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18589 Modified Files: config.log pdb.prj pdb.pws Log Message: Added api_src/ Index: config.log =================================================================== RCS file: /cvsroot/pdatabase/pdb/config.log,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- config.log 9 Jan 2005 01:28:04 -0000 1.4 +++ config.log 8 Feb 2005 15:10:16 -0000 1.5 @@ -1024,3 +1024,93 @@ config.status:718: creating src/Makefile config.status:1106: executing default-1 commands + +## ---------------------- ## +## Running config.status. ## +## ---------------------- ## + +This file was extended by config.status, which was +generated by GNU Autoconf 2.59. Invocation command line was + + CONFIG_FILES = src/Makefile + CONFIG_HEADERS = + CONFIG_LINKS = + CONFIG_COMMANDS = + $ ./config.status + +on locutus + +config.status:718: creating src/Makefile +config.status:1106: executing default-1 commands + +## ---------------------- ## +## Running config.status. ## +## ---------------------- ## + +This file was extended by config.status, which was +generated by GNU Autoconf 2.59. Invocation command line was + + CONFIG_FILES = src/Makefile + CONFIG_HEADERS = + CONFIG_LINKS = + CONFIG_COMMANDS = + $ ./config.status + +on locutus + +config.status:718: creating src/Makefile +config.status:1106: executing default-1 commands + +## ---------------------- ## +## Running config.status. ## +## ---------------------- ## + +This file was extended by config.status, which was +generated by GNU Autoconf 2.59. Invocation command line was + + CONFIG_FILES = src/Makefile + CONFIG_HEADERS = + CONFIG_LINKS = + CONFIG_COMMANDS = + $ ./config.status + +on locutus + +config.status:718: creating src/Makefile +config.status:1106: executing default-1 commands + +## ---------------------- ## +## Running config.status. ## +## ---------------------- ## + +This file was extended by config.status, which was +generated by GNU Autoconf 2.59. Invocation command line was + + CONFIG_FILES = src/Makefile + CONFIG_HEADERS = + CONFIG_LINKS = + CONFIG_COMMANDS = + $ ./config.status + +on locutus + +config.status:718: creating src/Makefile +config.status:1106: executing default-1 commands + +## ---------------------- ## +## Running config.status. ## +## ---------------------- ## + +This file was extended by config.status, which was +generated by GNU Autoconf 2.59. Invocation command line was + + CONFIG_FILES = src/Makefile + CONFIG_HEADERS = + CONFIG_LINKS = + CONFIG_COMMANDS = + $ ./config.status + +on locutus + +config.status:718: creating src/Makefile +config.status:1106: executing default-1 commands Index: pdb.pws =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.pws,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- pdb.pws 6 Feb 2005 01:27:34 -0000 1.10 +++ pdb.pws 8 Feb 2005 15:10:17 -0000 1.11 @@ -1,7 +1,7 @@ [filenumbers] -0=110 -1=983 +0=1265 +1=442 2=1 3=45 4=24 @@ -31,10 +31,8 @@ clean before build=false [filelist] -0=/home/para/Projects/pdb/include/pdb_types.h -1=/home/para/Projects/pdb/src/pdb_types.c -2=/home/para/Projects/pdb/include/pdb.h -3=/home/para/Projects/pdb/src/pdb.c +0=/home/para/Projects/pdb/src/pdb_types.c +1=/home/para/Projects/pdb/src/pdb.c [Project Tree] 0=0 Index: pdb.prj =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.prj,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pdb.prj 9 Jan 2005 01:28:04 -0000 1.2 +++ pdb.prj 8 Feb 2005 15:10:17 -0000 1.3 @@ -118,8 +118,8 @@ compiler.options.warning.buttons=0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 compiler.options.optimize.buttons=1 0 0 0 compiler.options.other.buttons=1 1 -compiler.options.other.c.flags= -compiler.options.other.l.flags= +compiler.options.other.c.flags=-fPIC +compiler.options.other.l.flags=-shared compiler.options.other.l.libs= project.src.paths= |
From: Michael L. <par...@us...> - 2005-02-08 15:10:49
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18589/src Modified Files: Makefile Makefile.am Makefile.in binarytree.c pdb.c pdb_parse.c pdb_types.c Added Files: hash.c Log Message: Added api_src/ Index: Makefile.am =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.am 9 Jan 2005 01:28:05 -0000 1.2 +++ Makefile.am 8 Feb 2005 15:10:18 -0000 1.3 @@ -8,10 +8,12 @@ -I../include/ AM_CFLAGS =\ + -fPIC\ -Wall\ -g -pg AM_CXXFLAGS =\ + -fPIC\ -Wall\ -g -pg @@ -27,7 +29,8 @@ str.c\ hash.c -pdb_LDFLAGS = +pdb_LDFLAGS = \ + -shared pdb_LDADD = \ -lm Index: pdb_types.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_types.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pdb_types.c 6 Feb 2005 01:27:34 -0000 1.9 +++ pdb_types.c 8 Feb 2005 15:10:18 -0000 1.10 @@ -306,16 +306,16 @@ if (parent) { tiptr = pdb_get_type_info(parent->type); if (!tiptr->add_child_cb) { - fprintf(stderr, "%s:%s():%i: Error: Unable to add child node to \ -parent (type %i); not supported by parent.\n", + fprintf(stderr, "%s:%s():%i: Error: Unable to add child node to " + "parent (type %i); not supported by parent.\n", __FILE__, __FUNCTION__, __LINE__, parent->type); free(nptr->id); free(nptr); return NULL; } else { if (!tiptr->add_child_cb(parent, id, nptr)) { - fprintf(stderr, "%s:%s():%i: Error: Unable to add child node \ -of type %i to parent node of type %i.\n", + fprintf(stderr, "%s:%s():%i: Error: Unable to add child node " + "of type %i to parent node of type %i.\n", __FILE__, __FUNCTION__, __LINE__, tiptr->bitmask, type); free(nptr->id); free(nptr); @@ -341,7 +341,6 @@ char* tok = pdb_get_token(fptr, &type, line); while (tok) { - printf("token [%s]\n", tok); /* * Is the block over? */ @@ -357,8 +356,9 @@ */ ctiptr = pdb_get_type_info(type); if (!ctiptr) { - fprintf(stderr, "%s:%s():%i: Error: Unknown child type %i on line \ -%i; halting database load.\n", __FILE__, __FUNCTION__, __LINE__, type, *line); + fprintf(stderr, "%s:%s():%i: Error: Unknown child type %i on line " + "%i; halting database load.\n", __FILE__, __FUNCTION__, + __LINE__, type, *line); free(tok); return 0; } @@ -369,8 +369,8 @@ */ if (ctiptr->load_cb) { if (!ctiptr->load_cb(fptr, cptr, tok_arr, line)) { - fprintf(stderr, "%s:%s():%i: Error: An error occured while \ -loading the database; halting database load on line %i.\n", + fprintf(stderr, "%s:%s():%i: Error: An error occured while " + "loading the database; halting database load on line %i.\n", __FILE__, __FUNCTION__, __LINE__, *line); token_free(tok_arr); free(tok); @@ -469,8 +469,8 @@ tiptr = pdb_get_type_info(nptr->parent->type); if (!tiptr->del_child_cb) { - fprintf(stderr, "%s:%s():%i: Error: Cannot remove '%s' from parent; \ -type %i does not support operation.\n", + fprintf(stderr, "%s:%s():%i: Error: Cannot remove '%s' from parent; " + "type %i does not support operation.\n", __FILE__, __FUNCTION__, __LINE__, nptr->id, nptr->parent->type); return; } @@ -498,8 +498,8 @@ if (!tiptr->write_cb) { char* trace = pdb_trace(nptr); - fprintf(stderr, "%s:%s():%i: Warning: Unable to write node \"%s\" to \ -disk; operation node supported by node type %i.\n", + fprintf(stderr, "%s:%s():%i: Warning: Unable to write node \"%s\" to " + "disk; operation node supported by node type %i.\n", __FILE__, __FUNCTION__, __LINE__, trace, nptr->type); free(trace); return 1; @@ -1270,8 +1270,8 @@ * Free an abstract node. */ int pdb_free_abstract_node_cb(struct pdb_node_t* nptr) { - fprintf(stderr, "Warning: %s:%s():%i: Abstract node cannot be freed " \ - "-- no custom free method defined! [%s]\n", \ + fprintf(stderr, "Warning: %s:%s():%i: Abstract node cannot be freed " + "-- no custom free method defined! [%s]\n", __FILE__, __FUNCTION__, __LINE__, pdb_trace(nptr)); Index: Makefile.in =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/Makefile.in,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.in 9 Jan 2005 01:28:05 -0000 1.2 +++ Makefile.in 8 Feb 2005 15:10:18 -0000 1.3 @@ -103,11 +103,13 @@ AM_CFLAGS = \ + -fPIC\ -Wall\ -g -pg AM_CXXFLAGS = \ + -fPIC\ -Wall\ -g -pg @@ -125,7 +127,9 @@ hash.c -pdb_LDFLAGS = +pdb_LDFLAGS = \ + -shared + pdb_LDADD = \ -lm Index: Makefile =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/Makefile,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile 9 Jan 2005 01:28:05 -0000 1.2 +++ Makefile 8 Feb 2005 15:10:18 -0000 1.3 @@ -103,11 +103,13 @@ AM_CFLAGS = \ + -fPIC\ -Wall\ -g -pg AM_CXXFLAGS = \ + -fPIC\ -Wall\ -g -pg @@ -125,7 +127,9 @@ hash.c -pdb_LDFLAGS = +pdb_LDFLAGS = \ + -shared + pdb_LDADD = \ -lm Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- pdb.c 6 Feb 2005 01:27:34 -0000 1.11 +++ pdb.c 8 Feb 2005 15:10:18 -0000 1.12 @@ -33,7 +33,7 @@ #include "pdb_types.h" #include "list.h" -int main(int argc, char** argv) { +/*int main(int argc, char** argv) { printf(PDB_COMPILE_INFO); printf("\n--LOAD--\n\n"); @@ -50,7 +50,7 @@ printf("\n--UNLOAD--\n\n"); pdb_unload(dbptr); return 0; -} +}*/ /* @@ -285,8 +285,8 @@ */ nptr = tiptr->create_cb(key, pptr, NULL); if (!nptr) { - fprintf(stderr, "%s:%s():%i: Error: Unable to create \"%s/%s\" in \ -database.\n", __FILE__, __FUNCTION__, __LINE__, path, key); + fprintf(stderr, "%s:%s():%i: Error: Unable to create \"%s/%s\" in " + "database.\n", __FILE__, __FUNCTION__, __LINE__, path, key); PDB_MUTEX_UNLOCK(dbptr); return NULL; } @@ -298,8 +298,8 @@ dbptr->altered = 1; if (!tiptr->set_cb) { - /*fprintf(stderr, "%s:%s():%i: Warning: Unable to set data at \"%s/%s\" \ -in database; type %i does not support it.\n", + /*fprintf(stderr, "%s:%s():%i: Warning: Unable to set data at \"%s/%s\" " + "in database; type %i does not support it.\n", __FILE__, __FUNCTION__, __LINE__, path, key, tiptr->bitmask);*/ } else tiptr->set_cb(nptr, data); @@ -325,8 +325,8 @@ tiptr = pdb_get_type_info(nptr->type); if (!tiptr->free_cb) { - fprintf(stderr, "%s:%s():%i: Error: Unable to free node %s; type %i \ -does not support deletion.\n", + fprintf(stderr, "%s:%s():%i: Error: Unable to free node %s; type %i " + "does not support deletion.\n", __FILE__, __FUNCTION__, __LINE__, nptr->id, nptr->type); PDB_MUTEX_UNLOCK(dbptr); return 0; @@ -438,8 +438,8 @@ fptr = fopen(file, "w"); if (!fptr) { - fprintf(stderr, "%s:%s():%i: Error: Unable to open file \"%s\" for \ -writing.\n", __FILE__, __FUNCTION__, __LINE__, file); + fprintf(stderr, "%s:%s():%i: Error: Unable to open file \"%s\" for " + "writing.\n", __FILE__, __FUNCTION__, __LINE__, file); PDB_MUTEX_UNLOCK(dbptr); return 0; } Index: pdb_parse.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_parse.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pdb_parse.c 9 Jan 2005 03:35:39 -0000 1.5 +++ pdb_parse.c 8 Feb 2005 15:10:18 -0000 1.6 @@ -109,9 +109,9 @@ tptr = is_closing_tok(fptr, byte); if (tptr) { if (*type != tptr->bitmask) { - fprintf(stderr, "pdb_parse.c: pdb_get_token(): Invalid \ -closing block token on line %i. Closing type %i for type %i.\n", - *line, tptr->bitmask, *type); + fprintf(stderr, "pdb_parse.c: pdb_get_token(): Invalid " + "closing block token on line %i. Closing type %i for " + "type %i.\n", *line, tptr->bitmask, *type); free(sbuf); return NULL; } Index: binarytree.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/binarytree.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- binarytree.c 25 Jan 2005 02:29:42 -0000 1.5 +++ binarytree.c 8 Feb 2005 15:10:18 -0000 1.6 @@ -387,8 +387,8 @@ if (nptr == NULL) return; - printf("[tree debug] address:%x\tkey: _%s_\n", - (unsigned int)nptr, nptr->key); + /*printf("[tree debug] address:%x\tkey: _%s_\n", + (unsigned long*)nptr, nptr->key);*/ //printf("%s right\n", nptr->key); tree_debug(nptr->right); --- NEW FILE: hash.c --- /* * This file is part of pdb. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Header: /cvsroot/pdatabase/pdb/src/hash.c,v 1.1 2005/02/08 15:10:18 paralizer Exp $ * */ /* * String hash table. * * The hash table uses a link list chainer to resolve collisions. * When the table is created, the lists are not. * A list is created when an item needs to go into an empty * cell weather the list is needed or not. * If an entry is deleted, and that was the last entry in the list * for that cell, the list is not deleted. The list will be deallocated * when the hash table has been explicitly freed. * The idea is to create only what is needed, but keep efficiency up. */ #include <stdio.h> #include <malloc.h> #include <string.h> #include "list.h" #include "hash.h" static int hash_key(char* str, int size); /* * Create a hash table of the given size. */ struct hash* hash_create(int size) { int i = 0; struct hash* hptr = (struct hash*)malloc(sizeof(struct hash)); if (!hptr) return 0; if (!size) { /* * Cannot create hash of size 0 -- default to 1. */ fprintf(stderr, "%s: WARNING: Hash of size 0 not allowed, using " "1 bucket.\n", __FILE__); size = 1; } hptr->size = size; hptr->tbl = (struct linkList**)malloc(sizeof(struct linkList*) * size); for (i = 0; i < size; i++) hptr->tbl[i] = NULL; return hptr; } /* * Free a hash table. * If NULLis passed for free_callback, the data will * be deallocated with free(); otherwise free_callback * will be invoked with the void* data as the only parameter. */ void hash_free(struct hash* hptr, hash_func_ptr free_callback) { struct linkNode* lnptr; struct hash_node_t* nptr; int i = 0; for (; i < hptr->size; i++) { if (hptr->tbl[i]) { /* * Free nodes in list. * This must be used rather than list_free() * because there is an extra data structure * specific to the hash table which must be freed. */ lnptr = hptr->tbl[i]->root; nptr = NULL; while (lnptr) { nptr = lnptr->data; if (nptr) { free(nptr->id); if (free_callback) free_callback(nptr->data); else free(nptr->data); free(nptr); } lnptr = lnptr->next; } /* * Free list. */ list_free(hptr->tbl[i], 0, NULL); } } free(hptr->tbl); free(hptr); } /* * STATIC * Generate a (hopefully) distributed integer between * 0 and size based on the passed str. */ int hash_key(char* str, int size) { unsigned int ret = 1; while (*str) ret = ((ret >> 1) + (ret * *str++)); return (ret % size); } /* * Add dptr to the hash table using key as the id. */ int hash_add(struct hash* hptr, char* key, void* dptr) { struct hash_node_t* nptr; int i = hash_key(key, hptr->size); /* * Does a list exist at this node yet? * If not create one. */ if (!hptr->tbl[i]) hptr->tbl[i] = list_create(); /* * Create the entry node. */ nptr = (struct hash_node_t*)malloc(sizeof(struct hash_node_t)); nptr->id = (char*)malloc(sizeof(char) * (strlen(key) + 1)); strcpy(nptr->id, key); nptr->data = dptr; /* * Add node to list. */ list_add_node_end(hptr->tbl[i], (void*)nptr); return 1; } /* * Query an entry -- return the data pointer. */ void* hash_get(struct hash* hptr, char* key) { struct hash_node_t* nptr = hash_get_node(hptr, key); return (nptr ? nptr->data : NULL); } /* * Query an entry -- return the entry node. */ struct hash_node_t* hash_get_node(struct hash* hptr, char* key) { struct linkNode* lnptr; struct hash_node_t* nptr; int i = hash_key(key, hptr->size); if (!hptr->tbl[i]) return NULL; lnptr = hptr->tbl[i]->root; nptr = NULL; while (lnptr) { nptr = lnptr->data; if (!strcmp(nptr->id, key)) return nptr; lnptr = lnptr->next; } return NULL; } /* * Delete an entry. */ int hash_del(struct hash* hptr, char* key, hash_func_ptr free_callback) { struct linkNode* lnptr; struct hash_node_t* nptr; int i = hash_key(key, hptr->size); if (!hptr->tbl[i]) return 0; /* * Find the node in the list. */ lnptr = hptr->tbl[i]->root; nptr = NULL; while (lnptr) { nptr = lnptr->data; if (!strcmp(nptr->id, key)) break; lnptr = lnptr->next; nptr = NULL; } if (!nptr) return 0; /* * Remove the node from the list. */ list_free_node(hptr->tbl[i], lnptr, 0, NULL); /* * Free the node. */ free(nptr->id); if (free_callback) free_callback(nptr->data); else free(nptr->data); free(nptr); return 1; } /* * Remove an entry, but do not free the data. */ int hash_remove(struct hash* hptr, char* key) { struct linkNode* lnptr; struct hash_node_t* nptr; int i = hash_key(key, hptr->size); if (!hptr->tbl[i]) return 0; /* * Find the node in the list. */ lnptr = hptr->tbl[i]->root; nptr = NULL; while (lnptr) { nptr = lnptr->data; if (!strcmp(nptr->id, key)) break; lnptr = lnptr->next; nptr = NULL; } if (!nptr) return 0; /* * Remove the node from the list. */ list_free_node(hptr->tbl[i], lnptr, 0, NULL); /* * Free the node, but not the data. */ free(nptr->id); free(nptr); return 1; } /* * Return the number of children a hash table has. */ int hash_count_children(struct hash* hptr) { int i = 0; int b = 0; struct linkList* lptr; struct linkNode* lnptr; for (; b < hptr->size; b++) { if (hptr->tbl[b]) { lptr = hptr->tbl[b]; lnptr = lptr->root; while (lnptr) { ++i; lnptr = lnptr->next; } } } return i; } |
From: Michael L. <par...@us...> - 2005-02-08 15:10:31
|
Update of /cvsroot/pdatabase/pdb/api_src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18589/api_src Added Files: README pdb.c pdb.h Log Message: Added api_src/ --- NEW FILE: README --- http://www.sourceforge.net/projects/pdatabase If you wish to use pdb as a shared library, you can compile these files into your project. They include functions to easily load and unload pdb, as well as wrappers for the entire documented API. --- NEW FILE: pdb.h --- /* * This file is part of PDB. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Header: /cvsroot/pdatabase/pdb/api_src/pdb.h,v 1.1 2005/02/08 15:10:18 paralizer Exp $ * * * * This header is used in conjunction with pdb * compiled as a shared library. * You can download pdb at http://pdatabase.sourceforge.net/ * */ #ifndef __PDB_H #define __PDB_H /* * Windows or POSIZ? */ //#define WIN32 #define POSIX /* * Enable verbose loading/unloading messages. */ #define _PDB_VERBOSE /* * This callback can be used to override standard free * callbacks for nodes. It is especially useful for non-standard * types like ABSTRACT_NODE_TYPE, where the actual data type may * differ from node to node. */ struct pdb_node_t; typedef int (*custom_free_cb_t)(void* nptr); /* * Single database node. */ struct pdb_node_t { int type; char* id; void* data; struct pdb_node_t* parent; custom_free_cb_t custom_free_cb; }; /* * Database root node. */ struct pdb { struct pdb_node_t* data; char* file; int altered; long last_write; int write_interval; /* in seconds */ int settings; #ifdef PDB_USING_THREADS pthread_mutex_t* mutex; #endif }; #ifdef WIN32 #define dlsym((struct HINSTANCE__*)obj, func) \ GetProcAddress((struct HINSTANCE__*)hDLL, func.c_str()) #endif struct _pdb_funcs_t { struct pdb* (*_pdb_load_fptr)(char* file); int (*_pdb_unload_fptr)(struct pdb* dbptr); void (*_pdb_enable_fptr)(struct pdb* dbptr, int settings); void (*_pdb_disable_fptr)(struct pdb* dbptr, int settings); int (*_pdb_is_set_fptr)(struct pdb* dbptr, int setting); int (*_pdb_create_link_fptr)(struct pdb* dbptr, char* path, char* key, struct pdb_node_t* tnptr); struct pdb_node_t* (*_pdb_query_node_fptr)(struct pdb* dbptr, char* path); void* (*_pdb_query_fptr)(struct pdb* dbptr, char* path); struct pdb_node_t* (*_pdb_set_fptr)(struct pdb* dbptr, char* path, char* key, void* data); struct pdb_node_t* (*_pdb_set_node_fptr)(struct pdb* dbptr, char* path, char* key, void* data, int type); int (*_pdb_del_fptr)(struct pdb* dbptr, char* path); char* (*_pdb_trace_fptr)(struct pdb_node_t* nptr); void (*_pdb_set_write_interval_fptr)(struct pdb* dbptr, int seconds); int (*_pdb_need_write_fptr)(struct pdb* dbptr); int (*_pdb_write_fptr)(struct pdb* dbptr, char* file); void (*_pdb_set_free_method_fptr)(struct pdb* dbptr, struct pdb_node_t* nptr, void* free_cb); int (*_pdb_count_children_fptr)(struct pdb* dbptr, char* path); }; #ifdef __cplusplus extern "C" { #endif int load_pdb_lib(char* file); int unload_pdb_lib(); void recache_pdb_lib(); /* * Function wrappers from library. */ struct pdb* pdb_load(char* file); int pdb_unload(struct pdb* dbptr); void pdb_enable(struct pdb* dbptr, int settings); void pdb_disable(struct pdb* dbptr, int settings); int pdb_is_set(struct pdb* dbptr, int setting); int pdb_create_link(struct pdb* dbptr, char* path, char* key, struct pdb_node_t* tnptr); struct pdb_node_t* pdb_query_node(struct pdb* dbptr, char* path); void* pdb_query(struct pdb* dbptr, char* path); struct pdb_node_t* pdb_set(struct pdb* dbptr, char* path, char* key, void* data); struct pdb_node_t* pdb_set_node(struct pdb* dbptr, char* path, char* key, void* data, int type); int pdb_del(struct pdb* dbptr, char* path); char* pdb_trace(struct pdb_node_t* nptr); void pdb_set_write_interval(struct pdb* dbptr, int seconds); int pdb_need_write(struct pdb* dbptr); int pdb_write(struct pdb* dbptr, char* file); void pdb_set_free_method(struct pdb* dbptr, struct pdb_node_t* nptr, void* free_cb); int pdb_count_children(struct pdb* dbptr, char* path); #ifdef __cplusplus } #endif #endif /* __PDB_H */ --- NEW FILE: pdb.c --- /* * This file is part of PDB. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Header: /cvsroot/pdatabase/pdb/api_src/pdb.c,v 1.1 2005/02/08 15:10:18 paralizer Exp $ * * * * This header is used in conjunction with pdb * compiled as a shared library. * You can download pdb at http://pdatabase.sourceforge.net/ * */ #define __PDB_C #include <stdio.h> #include "pdb.h" #ifdef POSIX #include <dlfcn.h> #elif defined(WIN32) #include <windows.h> #endif static void* _pdb_obj; static struct _pdb_funcs_t _pdb_funcs = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; /* * Load the pdb shared object. */ int load_pdb_lib(char* file) { #ifdef _PDB_VERBOSE printf("INFO: pdb.c: Loading pdb library \"%s\"... ", file); #endif #ifdef POSIX _pdb_obj = dlopen(file, RTLD_NOW); #elif defined(WIN32) _pdb_obj = LoadLibrary(file); #endif #ifdef _PDB_VERBOSE printf("%s\n", (_pdb_obj ? "success" : "failed")); #endif recache_pdb_lib(); return (_pdb_obj ? 1 : 0); } /* * Unload the pdb shared object. */ int unload_pdb_lib() { int r; #ifdef _PDB_VERBOSE printf("INFO: pdb.c: Unloading pdb library... "); #endif #ifdef POSIX r = dlclose(_pdb_obj); #elif defined(WIN32) r = FreeLibrary((struct HINSTANCE__*)_pdb_obj); #endif #ifdef _PDB_VERBOSE printf("%s\n", (r ? "failed" : "success")); #endif return (r ? 0 : 1); } /* * (Re)cache the pdb shared object function pointers. */ void recache_pdb_lib() { #ifdef _PDB_VERBOSE printf("INFO: pdb.c: Caching pdb function pointers...\n"); #endif _pdb_funcs._pdb_load_fptr = dlsym(_pdb_obj, "pdb_load"); _pdb_funcs._pdb_unload_fptr = dlsym(_pdb_obj, "pdb_unload"); _pdb_funcs._pdb_load_fptr = dlsym(_pdb_obj, "pdb_load"); _pdb_funcs._pdb_unload_fptr = dlsym(_pdb_obj, "pdb_unload"); _pdb_funcs._pdb_enable_fptr = dlsym(_pdb_obj, "pdb_enable"); _pdb_funcs._pdb_disable_fptr = dlsym(_pdb_obj, "pdb_disable"); _pdb_funcs._pdb_is_set_fptr = dlsym(_pdb_obj, "pdb_is_set"); _pdb_funcs._pdb_create_link_fptr = dlsym(_pdb_obj, "pdb_create_link"); _pdb_funcs._pdb_query_node_fptr = dlsym(_pdb_obj, "pdb_query_node"); _pdb_funcs._pdb_query_fptr = dlsym(_pdb_obj, "pdb_query"); _pdb_funcs._pdb_set_fptr = dlsym(_pdb_obj, "pdb_set"); _pdb_funcs._pdb_set_node_fptr = dlsym(_pdb_obj, "pdb_set_node"); _pdb_funcs._pdb_del_fptr = dlsym(_pdb_obj, "pdb_del"); _pdb_funcs._pdb_trace_fptr = dlsym(_pdb_obj, "pdb_trace"); _pdb_funcs._pdb_set_write_interval_fptr = dlsym(_pdb_obj, "pdb_set_write_interval"); _pdb_funcs._pdb_need_write_fptr = dlsym(_pdb_obj, "pdb_need_write"); _pdb_funcs._pdb_write_fptr = dlsym(_pdb_obj, "pdb_write"); _pdb_funcs._pdb_set_free_method_fptr = dlsym(_pdb_obj, "pdb_set_free_method"); _pdb_funcs._pdb_count_children_fptr = dlsym(_pdb_obj, "pdb_count_children"); #ifdef _PDB_VERBOSE printf("INFO: pdb.c: Cached pdb_load(): %s\n", (_pdb_funcs._pdb_load_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_unload(): %s\n", (_pdb_funcs._pdb_unload_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_enable(): %s\n", (_pdb_funcs._pdb_enable_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_disable(): %s\n", (_pdb_funcs._pdb_disable_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_is_set(): %s\n", (_pdb_funcs._pdb_is_set_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_create_link(): %s\n", (_pdb_funcs._pdb_create_link_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_query_node(): %s\n", (_pdb_funcs._pdb_query_node_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_query(): %s\n", (_pdb_funcs._pdb_query_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_set(): %s\n", (_pdb_funcs._pdb_set_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_set_node(): %s\n", (_pdb_funcs._pdb_set_node_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_del(): %s\n", (_pdb_funcs._pdb_del_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_trace(): %s\n", (_pdb_funcs._pdb_trace_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_set_write_interval(): %s\n", (_pdb_funcs._pdb_set_write_interval_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_need_write(): %s\n", (_pdb_funcs._pdb_need_write_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_write(): %s\n", (_pdb_funcs._pdb_write_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_set_free_method(): %s\n", (_pdb_funcs._pdb_set_free_method_fptr ? "success" : "failed")); printf("INFO: pdb.c: Cached pdb_count_children(): %s\n", (_pdb_funcs._pdb_count_children_fptr ? "success" : "failed")); #endif } /* * Function wrappers from library. */ struct pdb* pdb_load(char* file) { return _pdb_funcs._pdb_load_fptr(file); } int pdb_unload(struct pdb* dbptr) { return _pdb_funcs._pdb_unload_fptr(dbptr); } void pdb_enable(struct pdb* dbptr, int settings) { _pdb_funcs._pdb_enable_fptr(dbptr, settings); } void pdb_disable(struct pdb* dbptr, int settings) { _pdb_funcs._pdb_disable_fptr(dbptr, settings); } int pdb_is_set(struct pdb* dbptr, int setting) { return _pdb_funcs._pdb_is_set_fptr(dbptr, setting); } int pdb_create_link(struct pdb* dbptr, char* path, char* key, struct pdb_node_t* tnptr) { return _pdb_funcs._pdb_create_link_fptr(dbptr, path, key, tnptr); } struct pdb_node_t* pdb_query_node(struct pdb* dbptr, char* path) { return _pdb_funcs._pdb_query_fptr(dbptr, path); } void* pdb_query(struct pdb* dbptr, char* path) { return _pdb_funcs._pdb_query_fptr(dbptr, path); } struct pdb_node_t* pdb_set(struct pdb* dbptr, char* path, char* key, void* data) { return _pdb_funcs._pdb_set_fptr(dbptr, path, key, data); } struct pdb_node_t* pdb_set_node(struct pdb* dbptr, char* path, char* key, void* data, int type) { return _pdb_funcs._pdb_set_node_fptr(dbptr, path, key, data, type); } int pdb_del(struct pdb* dbptr, char* path) { return _pdb_funcs._pdb_del_fptr(dbptr, path); } char* pdb_trace(struct pdb_node_t* nptr) { return _pdb_funcs._pdb_trace_fptr(nptr); } void pdb_set_write_interval(struct pdb* dbptr, int seconds) { _pdb_funcs._pdb_set_write_interval_fptr(dbptr, seconds); } int pdb_need_write(struct pdb* dbptr) { return _pdb_funcs._pdb_need_write_fptr(dbptr); } int pdb_write(struct pdb* dbptr, char* file) { return _pdb_funcs._pdb_write_fptr(dbptr, file); } void pdb_set_free_method(struct pdb* dbptr, struct pdb_node_t* nptr, void* free_cb) { _pdb_funcs._pdb_set_free_method_fptr(dbptr, nptr, free_cb); } int pdb_count_children(struct pdb* dbptr, char* path) { return _pdb_funcs._pdb_count_children_fptr(dbptr, path); } |
From: Michael L. <par...@us...> - 2005-02-08 15:08:24
|
Update of /cvsroot/pdatabase/pdb/api_src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18140/api_src Log Message: Directory /cvsroot/pdatabase/pdb/api_src added to the repository |
From: Michael L. <par...@us...> - 2005-02-06 01:27:44
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20822/src Modified Files: pdb.c pdb_types.c Log Message: Fixed hash load problem Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- pdb.c 25 Jan 2005 02:29:42 -0000 1.10 +++ pdb.c 6 Feb 2005 01:27:34 -0000 1.11 @@ -41,15 +41,10 @@ printf("\n--DEBUG--\n\n"); - pdb_enable(dbptr, PDB_THREAD_SAFE); - PDB_MUTEX_LOCK(dbptr); - int* a = pdb_query(dbptr, "a/b"); printf("%x\n", a); printf("[%i]\n", *a); - //pdb_set_int(dbptr, "a", "c", 12); - pdb_write(dbptr, "/home/para/test.db2"); printf("\n--UNLOAD--\n\n"); Index: pdb_types.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_types.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- pdb_types.c 25 Jan 2005 02:29:42 -0000 1.8 +++ pdb_types.c 6 Feb 2005 01:27:34 -0000 1.9 @@ -341,6 +341,7 @@ char* tok = pdb_get_token(fptr, &type, line); while (tok) { + printf("token [%s]\n", tok); /* * Is the block over? */ @@ -901,19 +902,31 @@ int pdb_load_hash_node_cb(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, int* line) { - int type; - char* tok; + char b; + int i; + struct pdb_node_types_t* tiptr = pdb_get_type_info(HASH_NODE_TYPE); /* - * The hash table must first be created. - * Get the size of the table from the file, - * it should be next. + * Move to the next non-white character. */ - type = pptr->type; - tok = pdb_get_token(fptr, &type, line); - printf("[%s]\n", tok); - - if ((type != STRING_NODE_TYPE) || (!tok) || (tok ? !*tok : 0)) { + while (!feof(fptr)) { + FPEEK(&b, fptr); + if (!is_whitespace(b)) + break; + if (b == '\n') + *line++; + fgetc(fptr); + } + /* + * Skip over the opening token. + */ + for (i = 0; i < strlen(tiptr->open_token); ++i) + fgetc(fptr); + + /* + * Get the size of the hash table. + */ + if (!fscanf(fptr, "%i;", &i)) { char* e = va(NULL, "Unable to load hash from file -- no size (line %i).\n", *line); ERROR(e); @@ -921,11 +934,8 @@ return 0; } - type = atoi(tok); - pptr->data = (void*)hash_create(type); + pptr->data = (void*)hash_create(i); - free(tok); - return pdb_standard_load_node(fptr, pptr, tok_arr, line); } |
From: Michael L. <par...@us...> - 2005-02-06 01:27:44
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20822 Modified Files: pdb.pws Log Message: Fixed hash load problem Index: pdb.pws =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.pws,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pdb.pws 25 Jan 2005 02:29:40 -0000 1.9 +++ pdb.pws 6 Feb 2005 01:27:34 -0000 1.10 @@ -1,9 +1,9 @@ [filenumbers] -0=92 -1=719 -2=59 -3=36 +0=110 +1=983 +2=1 +3=45 4=24 5=149 6=101 @@ -32,13 +32,9 @@ [filelist] 0=/home/para/Projects/pdb/include/pdb_types.h -1=/home/para/Projects/pdb/src/str.c -2=/home/para/Projects/pdb/src/hash.c -3=/home/para/Projects/pdb/src/pdb_parse.c -4=/home/para/Projects/pdb/include/pdb_parse.h -5=/home/para/Projects/pdb/src/pdb_types.c -6=/home/para/Projects/pdb/include/pdb.h -7=/home/para/Projects/pdb/src/pdb.c +1=/home/para/Projects/pdb/src/pdb_types.c +2=/home/para/Projects/pdb/include/pdb.h +3=/home/para/Projects/pdb/src/pdb.c [Project Tree] 0=0 |
From: Michael L. <par...@us...> - 2005-01-25 02:30:29
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10772/src Modified Files: binarytree.c list.c pdb.c pdb_types.c str.c Log Message: Added integer read/write support to/from disk. Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pdb.c 17 Jan 2005 05:44:58 -0000 1.9 +++ pdb.c 25 Jan 2005 02:29:42 -0000 1.10 @@ -37,17 +37,20 @@ printf(PDB_COMPILE_INFO); printf("\n--LOAD--\n\n"); - struct pdb* dbptr = pdb_load("/home/para/para.db"); + struct pdb* dbptr = pdb_load("/home/para/test.db"); printf("\n--DEBUG--\n\n"); pdb_enable(dbptr, PDB_THREAD_SAFE); PDB_MUTEX_LOCK(dbptr); - char* a = pdb_query(dbptr, "servers/gamesurge/server"); - printf("[%s]\n", a); + int* a = pdb_query(dbptr, "a/b"); + printf("%x\n", a); + printf("[%i]\n", *a); - //pdb_write(dbptr, "/home/para/test.db2"); + //pdb_set_int(dbptr, "a", "c", 12); + + pdb_write(dbptr, "/home/para/test.db2"); printf("\n--UNLOAD--\n\n"); pdb_unload(dbptr); Index: pdb_types.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_types.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pdb_types.c 16 Jan 2005 00:46:22 -0000 1.7 +++ pdb_types.c 25 Jan 2005 02:29:42 -0000 1.8 @@ -66,7 +66,8 @@ pdb_query_tree_node_cb, pdb_del_child_tree_node_cb, pdb_write_tree_node_cb, - pdb_count_children_tree_cb + pdb_count_children_tree_cb, + 1 /* write to disk in block format */ }, { /* Link List */ @@ -81,7 +82,8 @@ pdb_query_list_node_cb, pdb_del_child_list_node_cb, pdb_write_list_node_cb, - pdb_count_children_list_cb + pdb_count_children_list_cb, + 1 /* write to disk in block format */ }, { /* Hash table */ @@ -96,7 +98,8 @@ pdb_query_hash_node_cb, pdb_del_child_hash_node_cb, pdb_write_hash_node_cb, - pdb_count_children_hash_cb + pdb_count_children_hash_cb, + 1 /* write to disk in block format */ }, { /* String */ @@ -111,22 +114,24 @@ NULL, NULL, /* string has no child */ pdb_write_string_node_cb, - NULL /* strings do not have children */ + NULL, /* strings do not have children */ + 0 /* write to disk in line format */ }, { /* Integer type */ INT_NODE_TYPE, - NULL, /* no loading from disk */ - NULL, /* no loading from disk */ + "'", + "'", pdb_create_int_node_cb, - NULL, + pdb_load_int_node_cb, pdb_set_int_node_cb, NULL, /* integers have no children */ pdb_free_int_node_cb, NULL, NULL, - NULL, /* not written to disk */ - NULL /* integers do not have children */ + pdb_write_int_node_cb, + NULL, /* integers do not have children */ + 0 /* write to disk in line format */ }, { /* Abstract type */ @@ -141,7 +146,8 @@ NULL, NULL, NULL, /* not written to disk */ - NULL /* abstracts do not have children */ + NULL, /* abstracts do not have children */ + 0 /* not written to disk */ }, { /* @@ -160,13 +166,14 @@ pdb_query_link_node_cb, NULL, /* children are ignored on free */ NULL, /* links not written to disk */ - NULL /* links do not have children */ + NULL, /* links do not have children */ + 0 /* links not written to disk */ }, { /* Terminating Entry */ NO_NODE_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, 0 } }; @@ -505,14 +512,14 @@ fputc('\t', fptr); /* - * Write key in double quotes followed by a tree opening token. + * Write key in double quotes followed by an opening token. */ if (tabs != -1) { fputc('\"', fptr); if (nptr->id) fputs(nptr->id, fptr); fputs("\" ", fptr); - if (tiptr->open_token) { + if ((tiptr->write_as_block) && (tiptr->open_token)) { fputs(tiptr->open_token, fptr); fputc('\n', fptr); } @@ -526,7 +533,7 @@ /* * Write tabs and tree closing token (if tabs != -1 [root]). */ - if ((tabs != -1) && (tiptr->close_token)) { + if ((tabs != -1) && (tiptr->close_token) && (tiptr->write_as_block)) { i = 0; for (; i < tabs; i++) fputc('\t', fptr); @@ -1146,16 +1153,39 @@ return NULL; nptr->data = (void*)malloc(sizeof(int)); + if (tok_arr) *(int*)(nptr->data) = *(int*)tok_arr; else *(int*)(nptr->data) = 0; - + return nptr; } /* + * Callback for loading an integer node. + */ +int pdb_load_int_node_cb(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, + int* line) { + + struct pdb_node_types_t* tiptr; + int* i = (int*)pptr->data; + + tiptr = pdb_get_type_info(INT_NODE_TYPE); + + /* + * Read the integer from the file and set it. + */ + fscanf(fptr, tiptr->open_token, NULL); + fscanf(fptr, "%i", i); + fscanf(fptr, tiptr->close_token, NULL); + + return 1; +} + + +/* * (Re)set the data at an integer node. */ void pdb_set_int_node_cb(struct pdb_node_t* nptr, void* data) { @@ -1172,6 +1202,26 @@ } +/* + * Write an integer node to disk. + */ +int pdb_write_int_node_cb(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs) { + + struct pdb_node_types_t* tiptr; + + tiptr = pdb_get_type_info(INT_NODE_TYPE); + + fprintf(fptr, "%s%i%s%c\n", + tiptr->open_token, + *(int*)nptr->data, + tiptr->close_token, + PDB_TOKEN_TERM); + + return 1; +} + + /****************** ****************** ****************** Abstract Node Type |
From: Michael L. <par...@us...> - 2005-01-25 02:30:29
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10772/include Modified Files: binarytree.h list.h pdb.h pdb_types.h str.h Log Message: Added integer read/write support to/from disk. Index: pdb_types.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb_types.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pdb_types.h 16 Jan 2005 00:46:21 -0000 1.6 +++ pdb_types.h 25 Jan 2005 02:29:41 -0000 1.7 @@ -89,7 +89,7 @@ del_child_cb_t del_child_cb; write_cb_t write_cb; count_children_cb_t count_children_cb; - + int write_as_block; /* use multiplue lines while writing to disk? */ }; @@ -190,8 +190,12 @@ */ void* pdb_create_int_node_cb(char* id, struct pdb_node_t* parent, char** tok_arr); +int pdb_load_int_node_cb(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, + int* line); void pdb_set_int_node_cb(struct pdb_node_t* nptr, void* data); int pdb_free_int_node_cb(struct pdb_node_t* nptr); +int pdb_write_int_node_cb(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs); /* * Abstract |
From: Michael L. <par...@us...> - 2005-01-25 02:30:00
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10772 Modified Files: pdb.pws Log Message: Added integer read/write support to/from disk. Index: pdb.pws =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.pws,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- pdb.pws 16 Jan 2005 00:46:21 -0000 1.8 +++ pdb.pws 25 Jan 2005 02:29:40 -0000 1.9 @@ -1,12 +1,13 @@ [filenumbers] -0=59 -1=36 -2=24 -3=25 -4=101 -5=38 -6=133 +0=92 +1=719 +2=59 +3=36 +4=24 +5=149 +6=101 +7=48 [filemarkers] 0= @@ -16,6 +17,7 @@ 4= 5= 6= +7= [File View] filter.file.unmatch=*.so *.o *.a *.la @@ -29,12 +31,14 @@ clean before build=false [filelist] -0=/home/para/Projects/pdb/src/hash.c -1=/home/para/Projects/pdb/src/pdb_parse.c -2=/home/para/Projects/pdb/include/pdb_parse.h -3=/home/para/Projects/pdb/src/pdb_types.c -4=/home/para/Projects/pdb/include/pdb.h -5=/home/para/Projects/pdb/src/pdb.c +0=/home/para/Projects/pdb/include/pdb_types.h +1=/home/para/Projects/pdb/src/str.c +2=/home/para/Projects/pdb/src/hash.c +3=/home/para/Projects/pdb/src/pdb_parse.c +4=/home/para/Projects/pdb/include/pdb_parse.h +5=/home/para/Projects/pdb/src/pdb_types.c +6=/home/para/Projects/pdb/include/pdb.h +7=/home/para/Projects/pdb/src/pdb.c [Project Tree] 0=0 |
From: Michael L. <par...@us...> - 2005-01-17 05:45:13
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv819/src Modified Files: pdb.c Log Message: Fixed macro names which did not have PDB_ prepended. Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- pdb.c 16 Jan 2005 00:46:22 -0000 1.8 +++ pdb.c 17 Jan 2005 05:44:58 -0000 1.9 @@ -82,7 +82,7 @@ dbptr->last_write = time(NULL); dbptr->write_interval = PDB_DEFAULT_WRITE_INTERVAL; dbptr->settings = PDB_DEFAULT_SETTINGS; - #ifdef USING_THREADS + #ifdef PDB_USING_THREADS dbptr->mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(dbptr->mutex, NULL); #endif @@ -123,7 +123,7 @@ int ret = pdb_free_node(dbptr->data); - #ifdef USING_THREADS + #ifdef PDB_USING_THREADS pthread_mutex_destroy(dbptr->mutex); #endif |
From: Michael L. <par...@us...> - 2005-01-17 05:45:09
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv819/include Modified Files: pdb.h Log Message: Fixed macro names which did not have PDB_ prepended. Index: pdb.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pdb.h 16 Jan 2005 00:46:21 -0000 1.6 +++ pdb.h 17 Jan 2005 05:44:58 -0000 1.7 @@ -70,8 +70,8 @@ * Comment this if you do not wish to enable * thread safe features for pdb. */ -#define USING_THREADS -#define THREAD_DEBUG +#define PDB_USING_THREADS +//#define PDB_THREAD_DEBUG /* @@ -79,8 +79,8 @@ * PDB_THREAD_SAFE is enabled for the given * database. */ -#ifdef USING_THREADS - #ifdef THREAD_DEBUG +#ifdef PDB_USING_THREADS + #ifdef PDB_THREAD_DEBUG #define __PDB_THREAD_DEBUG_OUTPUT(op) \ { \ printf("%s:%s():%i MUTEX %s\n", __FILE__, \ |
From: Michael L. <par...@us...> - 2005-01-16 00:46:34
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1982/src Modified Files: binarytree.c list.c pdb.c pdb_types.c str.c Log Message: Now handles shared memory management via local mutex. Index: binarytree.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/binarytree.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- binarytree.c 9 Jan 2005 02:03:24 -0000 1.3 +++ binarytree.c 16 Jan 2005 00:46:21 -0000 1.4 @@ -36,6 +36,7 @@ #include "list.h" #include "binarytree.h" +static void tree_branch_count_children(struct treeNode* nptr, int* i); /* * Create a binary tree. @@ -488,3 +489,31 @@ return (*s2 ? -1 : 0); } + + +/* + * Return the number of children a binary tree has. + */ +int tree_count_children(struct binaryTree* tptr) { + int i = 0; + tree_branch_count_children(tptr->root, &i); + return i; +} + + +/* + * Count children on a given branch. + */ +void tree_branch_count_children(struct treeNode* nptr, int* i) { + /* + * Count children on left branch. + */ + tree_branch_count_children(nptr->left, i); + + /* + * Count children on right branch. + */ + tree_branch_count_children(nptr->right, i); + + (*i)++; +} Index: str.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/str.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- str.c 9 Jan 2005 01:28:05 -0000 1.2 +++ str.c 16 Jan 2005 00:46:22 -0000 1.3 @@ -215,6 +215,9 @@ */ int str_find(char* str, char tok) { int i = 0; + + if (!str) + return -1; while (*str) { if (*str == tok) @@ -578,11 +581,15 @@ /* * Case insensitive string compare. * Return: + * -1 s1 < s2 * 0 s1 = s2 * 1 s1 > s2 - * 2 s1 < s2 */ int cstrcmp(char* s1, char* s2) { + if (!s1 && s2) return -1; + else if (s1 && !s2) return 1; + else if (!s1 && !s2) return 0; + while (*s1) { if (!*s2) return 1; @@ -662,19 +669,20 @@ * are in 'str'. */ int require_params(char* str, int need) { - int ws = 1; int i = 0; - + int ws = 0; + while (*str) { if (*str == ' ') - ws = 1; - else if (ws) { - ++i; + ++ws; + else { + if (ws) + ++i; ws = 0; } - ++str; } + return (i >= need); } Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pdb.c 9 Jan 2005 03:35:39 -0000 1.7 +++ pdb.c 16 Jan 2005 00:46:22 -0000 1.8 @@ -35,12 +35,16 @@ int main(int argc, char** argv) { printf(PDB_COMPILE_INFO); + printf("\n--LOAD--\n\n"); - struct pdb* dbptr = pdb_load("/home/para/test.db"); + struct pdb* dbptr = pdb_load("/home/para/para.db"); printf("\n--DEBUG--\n\n"); + + pdb_enable(dbptr, PDB_THREAD_SAFE); + PDB_MUTEX_LOCK(dbptr); - char* a = pdb_query(dbptr, "foo"); + char* a = pdb_query(dbptr, "servers/gamesurge/server"); printf("[%s]\n", a); //pdb_write(dbptr, "/home/para/test.db2"); @@ -53,20 +57,23 @@ /* * Load a file and return a database pointer. + * If file is NULL, create an empty database. */ struct pdb* pdb_load(char* file) { struct pdb* dbptr; struct pdb_node_types_t* rntptr; int line = 1; - FILE* fptr; + FILE* fptr = NULL; dbptr = (struct pdb*)malloc(sizeof(struct pdb)); if (!dbptr) return NULL; - fptr = pdb_open_file(file); - if (!fptr) - return NULL; + if (file) { + fptr = pdb_open_file(file); + if (!fptr) + return NULL; + } /* * Initialize pdb structure. @@ -75,8 +82,17 @@ dbptr->last_write = time(NULL); dbptr->write_interval = PDB_DEFAULT_WRITE_INTERVAL; dbptr->settings = PDB_DEFAULT_SETTINGS; - dbptr->file = (char*)malloc(sizeof(char) * (strlen(file) + 1)); - strcpy(dbptr->file, file); + #ifdef USING_THREADS + dbptr->mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); + pthread_mutex_init(dbptr->mutex, NULL); + #endif + + if (file) { + dbptr->file = (char*)malloc(sizeof(char) * (strlen(file) + 1)); + strcpy(dbptr->file, file); + } else + dbptr->file = NULL; + rntptr = pdb_get_type_info(ROOT_NODE_TYPE); if (!rntptr) { ERROR("Root node type is invalid."); @@ -88,11 +104,13 @@ dbptr->data = (*rntptr->create_cb)(NULL, NULL, NULL); /* - * Load database. + * Load database (if file was specified). */ - pdb_standard_load_node(fptr, dbptr->data, NULL, &line); + if (file) { + pdb_standard_load_node(fptr, dbptr->data, NULL, &line); + pdb_close_file(fptr); + } - pdb_close_file(fptr); return dbptr; } @@ -101,7 +119,14 @@ * Unload a database. */ int pdb_unload(struct pdb* dbptr) { + PDB_MUTEX_LOCK(dbptr); + int ret = pdb_free_node(dbptr->data); + + #ifdef USING_THREADS + pthread_mutex_destroy(dbptr->mutex); + #endif + free(dbptr->file); free(dbptr); return ret; @@ -113,7 +138,11 @@ * settings are OR'ed togther. */ void pdb_enable(struct pdb* dbptr, int settings) { + PDB_MUTEX_LOCK(dbptr); + dbptr->settings |= settings; + + PDB_MUTEX_UNLOCK(dbptr); } @@ -122,7 +151,11 @@ * settings are OR'ed togther. */ void pdb_disable(struct pdb* dbptr, int settings) { + PDB_MUTEX_LOCK(dbptr); + dbptr->settings &= ~settings; + + PDB_MUTEX_UNLOCK(dbptr); } @@ -143,13 +176,20 @@ struct pdb_node_t* nptr; struct pdb_node_types_t* tiptr; + int ret; nptr = pdb_query_node(dbptr, path); + if (!nptr) return 0; tiptr = pdb_get_type_info(LINK_NODE_TYPE); - return (tiptr->create_cb(key, nptr, (char**)tnptr) ? 1 : 0); + + PDB_MUTEX_LOCK(dbptr); + ret = (tiptr->create_cb(key, nptr, (char**)tnptr) ? 1 : 0); + + PDB_MUTEX_UNLOCK(dbptr); + return ret; } @@ -162,8 +202,12 @@ struct pdb_node_types_t* tiptr; int i = 0; - if (!strcmp(path, "") || !strcmp(path, "/")) + PDB_MUTEX_LOCK(dbptr); + + if (!strcmp(path, "") || !strcmp(path, "/")) { + PDB_MUTEX_UNLOCK(dbptr); return dbptr->data; + } tok_arr = token_parse(path, PDB_PATH_DELIM, NULL); @@ -180,6 +224,7 @@ token_free(tok_arr); + PDB_MUTEX_UNLOCK(dbptr); return nptr; } @@ -196,8 +241,20 @@ /* * Set a node's data. If it does not exist, create it. * Return a pointer to the node. + * + * This is for string node types. */ struct pdb_node_t* pdb_set(struct pdb* dbptr, char* path, char* key, + void* data) { + + return (pdb_set_node(dbptr, path, key, data, STRING_NODE_TYPE)); +} + +/* + * Set a node's data. If it does not exist, create it. + * Return a pointer to the node. + */ +struct pdb_node_t* pdb_set_node(struct pdb* dbptr, char* path, char* key, void* data, int type) { struct pdb_node_types_t* tiptr; @@ -205,13 +262,21 @@ struct pdb_node_types_t* ptiptr; struct pdb_node_t* nptr; + PDB_MUTEX_LOCK(dbptr); + tiptr = pdb_get_type_info(type); - if (!tiptr) + if (!tiptr) { + PDB_MUTEX_UNLOCK(dbptr); return NULL; + } + PDB_MUTEX_UNLOCK(dbptr); pptr = pdb_query_node(dbptr, path); + if (!pptr) return NULL; + + PDB_MUTEX_LOCK(dbptr); ptiptr = pdb_get_type_info(pptr->type); nptr = ptiptr->query_cb(pptr, key); @@ -224,6 +289,7 @@ if (!nptr) { fprintf(stderr, "%s:%s():%i: Error: Unable to create \"%s/%s\" in \ database.\n", __FILE__, __FUNCTION__, __LINE__, path, key); + PDB_MUTEX_UNLOCK(dbptr); return NULL; } } @@ -234,14 +300,13 @@ dbptr->altered = 1; if (!tiptr->set_cb) { - fprintf(stderr, "%s:%s():%i: Warning: Unable to set data at \"%s/%s\" \ + /*fprintf(stderr, "%s:%s():%i: Warning: Unable to set data at \"%s/%s\" \ in database; type %i does not support it.\n", - __FILE__, __FUNCTION__, __LINE__, path, key, tiptr->bitmask); - return NULL; - } - - tiptr->set_cb(nptr, data); + __FILE__, __FUNCTION__, __LINE__, path, key, tiptr->bitmask);*/ + } else + tiptr->set_cb(nptr, data); + PDB_MUTEX_UNLOCK(dbptr); return nptr; } @@ -252,17 +317,20 @@ int pdb_del(struct pdb* dbptr, char* path) { struct pdb_node_t* nptr; struct pdb_node_types_t* tiptr; - + nptr = pdb_query_node(dbptr, path); if (!nptr) return 0; + PDB_MUTEX_LOCK(dbptr); + tiptr = pdb_get_type_info(nptr->type); if (!tiptr->free_cb) { fprintf(stderr, "%s:%s():%i: Error: Unable to free node %s; type %i \ does not support deletion.\n", __FILE__, __FUNCTION__, __LINE__, nptr->id, nptr->type); + PDB_MUTEX_UNLOCK(dbptr); return 0; } @@ -271,6 +339,7 @@ */ dbptr->altered = 1; + PDB_MUTEX_UNLOCK(dbptr); return pdb_free_node(nptr); } @@ -337,7 +406,9 @@ * Set the disk write interval. */ void pdb_set_write_interval(struct pdb* dbptr, int seconds) { + PDB_MUTEX_LOCK(dbptr); dbptr->write_interval = seconds; + PDB_MUTEX_UNLOCK(dbptr); } /* @@ -356,15 +427,22 @@ struct pdb_node_t* nptr; int ret; - if (!dbptr) + PDB_MUTEX_LOCK(dbptr); + + if (!dbptr) { + PDB_MUTEX_UNLOCK(dbptr); return 0; - if (!dbptr->data) + } + if (!dbptr->data) { + PDB_MUTEX_UNLOCK(dbptr); return 0; + } fptr = fopen(file, "w"); if (!fptr) { fprintf(stderr, "%s:%s():%i: Error: Unable to open file \"%s\" for \ writing.\n", __FILE__, __FUNCTION__, __LINE__, file); + PDB_MUTEX_UNLOCK(dbptr); return 0; } @@ -379,6 +457,7 @@ dbptr->altered = 0; dbptr->last_write = time(NULL); + PDB_MUTEX_UNLOCK(dbptr); return ret; } @@ -388,6 +467,46 @@ * If set, this will be used rather than the types default * free method. */ -void pdb_set_free_method(struct pdb_node_t* nptr, void* free_cb) { +void pdb_set_free_method(struct pdb* dbptr, struct pdb_node_t* nptr, + void* free_cb) { + + PDB_MUTEX_LOCK(dbptr); nptr->custom_free_cb = (custom_free_cb_t)free_cb; + PDB_MUTEX_UNLOCK(dbptr); +} + + +/* + * Return the number of children a container has. + */ +int pdb_count_children(struct pdb* dbptr, char* path) { + struct pdb_node_types_t* tiptr; + struct pdb_node_t* nptr = pdb_query_node(dbptr, path); + int ret; + + if (!nptr) + return 0; + + PDB_MUTEX_LOCK(dbptr); + + tiptr = pdb_get_type_info(nptr->type); + if (!tiptr) { + /* + * Play it safe -- container not empty. + */ + PDB_MUTEX_UNLOCK(dbptr); + return 0; + } + if (!tiptr->count_children_cb) { + /* + * Again, playing it safe. + */ + PDB_MUTEX_UNLOCK(dbptr); + return 0; + } + + ret = tiptr->count_children_cb(nptr); + + PDB_MUTEX_UNLOCK(dbptr); + return ret; } Index: pdb_types.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_types.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pdb_types.c 9 Jan 2005 03:35:39 -0000 1.6 +++ pdb_types.c 16 Jan 2005 00:46:22 -0000 1.7 @@ -18,6 +18,14 @@ * $Header$ * */ + +/* + * NOTE + * + * Be aware if PDB_THREAD_SAFE is enabled for the given database, + * most functions in pdb.c are mutex protected -- watch out for + * multipule locks. + */ #include <stdio.h> #include <stdlib.h> @@ -57,7 +65,8 @@ pdb_free_tree_node_cb, pdb_query_tree_node_cb, pdb_del_child_tree_node_cb, - pdb_write_tree_node_cb + pdb_write_tree_node_cb, + pdb_count_children_tree_cb }, { /* Link List */ @@ -71,7 +80,8 @@ pdb_free_list_node_cb, pdb_query_list_node_cb, pdb_del_child_list_node_cb, - pdb_write_list_node_cb + pdb_write_list_node_cb, + pdb_count_children_list_cb }, { /* Hash table */ @@ -85,7 +95,8 @@ pdb_free_hash_node_cb, pdb_query_hash_node_cb, pdb_del_child_hash_node_cb, - pdb_write_hash_node_cb + pdb_write_hash_node_cb, + pdb_count_children_hash_cb }, { /* String */ @@ -99,7 +110,8 @@ pdb_free_string_node_cb, NULL, NULL, /* string has no child */ - pdb_write_string_node_cb + pdb_write_string_node_cb, + NULL /* strings do not have children */ }, { /* Integer type */ @@ -113,7 +125,8 @@ pdb_free_int_node_cb, NULL, NULL, - NULL /* not written to disk */ + NULL, /* not written to disk */ + NULL /* integers do not have children */ }, { /* Abstract type */ @@ -127,7 +140,8 @@ pdb_free_abstract_node_cb, NULL, NULL, - NULL /* not written to disk */ + NULL, /* not written to disk */ + NULL /* abstracts do not have children */ }, { /* @@ -145,13 +159,14 @@ pdb_free_link_node_cb, pdb_query_link_node_cb, NULL, /* children are ignored on free */ - NULL /* links not written to disk */ + NULL, /* links not written to disk */ + NULL /* links do not have children */ }, { /* Terminating Entry */ NO_NODE_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL + NULL, NULL, NULL, NULL } }; @@ -164,23 +179,43 @@ /****************** ****************** - ****************** Container creation wrappers. + ****************** Container creation and set wrappers. ****************** ******************/ struct pdb_node_t* pdb_create_tree(struct pdb* dbptr, char* path, char* key) { - return pdb_set(dbptr, path, key, NULL, TREE_NODE_TYPE); + return pdb_set_node(dbptr, path, key, NULL, TREE_NODE_TYPE); } struct pdb_node_t* pdb_create_list(struct pdb* dbptr, char* path, char* key) { - return pdb_set(dbptr, path, key, NULL, LIST_NODE_TYPE); + return pdb_set_node(dbptr, path, key, NULL, LIST_NODE_TYPE); } struct pdb_node_t* pdb_create_hash(struct pdb* dbptr, char* path, char* key, int size) { - return pdb_set(dbptr, path, key, &size, HASH_NODE_TYPE); + return pdb_set_node(dbptr, path, key, &size, HASH_NODE_TYPE); +} + +struct pdb_node_t* pdb_create_abstract(struct pdb* dbptr, char* path, + char* key, void* data, void* free_cb) { + + struct pdb_node_t* nptr = NULL; + nptr = pdb_set_node(dbptr, path, key, data, ABSTRACT_NODE_TYPE); + + if (!nptr) + return NULL; + + pdb_set_free_method(dbptr, nptr, free_cb); + + return nptr; +} + +struct pdb_node_t* pdb_set_int(struct pdb* dbptr, char* path, + char* key, int data) { + + return pdb_set_node(dbptr, path, key, &data, INT_NODE_TYPE); } @@ -651,6 +686,14 @@ } +/* + * Return the number of children a binary tree has. + */ +int pdb_count_children_tree_cb(struct pdb_node_t* nptr) { + return tree_count_children(nptr->data); +} + + /****************** ****************** ****************** List Node Type @@ -792,6 +835,26 @@ } +/* + * Return the number of children a list has. + */ +int pdb_count_children_list_cb(struct pdb_node_t* nptr) { + struct linkList* lptr; + struct linkNode* lnptr; + int i = 0; + + lptr = nptr->data; + lnptr = lptr->root; + + while (lnptr) { + ++i; + lnptr = lnptr->next; + } + + return i; +} + + /****************** ****************** ****************** Hash Node Type @@ -961,6 +1024,14 @@ } +/* + * Return the number of children a hash has. + */ +int pdb_count_children_hash_cb(struct pdb_node_t* nptr) { + return hash_count_children(nptr->data); +} + + /****************** ****************** ****************** String Node Type |
From: Michael L. <par...@us...> - 2005-01-16 00:46:33
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1982/include Modified Files: binarytree.h list.h pdb.h pdb_parse.h pdb_types.h str.h Log Message: Now handles shared memory management via local mutex. Index: pdb.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pdb.h 9 Jan 2005 03:35:38 -0000 1.5 +++ pdb.h 16 Jan 2005 00:46:21 -0000 1.6 @@ -22,6 +22,8 @@ #ifndef _PDB_H #define _PDB_H +#include <pthread.h> + /* * Handy macros. */ @@ -55,6 +57,7 @@ #define PDB_CASE_INSENSITIVE 1 #define PDB_WRITE_SHUFFLE 2 #define PDB_WRITE_NODE_FIRST 4 +#define PDB_THREAD_SAFE 8 /* @@ -64,6 +67,55 @@ /* + * Comment this if you do not wish to enable + * thread safe features for pdb. + */ +#define USING_THREADS +#define THREAD_DEBUG + + +/* + * Macros to lock or unlock a mutex if + * PDB_THREAD_SAFE is enabled for the given + * database. + */ +#ifdef USING_THREADS + #ifdef THREAD_DEBUG + #define __PDB_THREAD_DEBUG_OUTPUT(op) \ + { \ + printf("%s:%s():%i MUTEX %s\n", __FILE__, \ + __FUNCTION__, __LINE__, op); \ + } + #else + #define __PDB_THREAD_DEBUG_OUTPUT(op) {} + #endif + + #define __PDB_LOCK(mutex) \ + { pthread_mutex_lock(mutex); } + #define __PDB_UNLOCK(mutex) \ + { pthread_mutex_unlock(mutex); } +#else + #define __PDB_LOCK(mutex) {} + #define __PDB_UNLOCK(mutex) {} + #define __PDB_THREAD_DEBUG_OUTPUT(op) {} +#endif +#define PDB_MUTEX_LOCK(dbptr) \ + { \ + if ((dbptr->settings & PDB_THREAD_SAFE) == PDB_THREAD_SAFE) { \ + __PDB_THREAD_DEBUG_OUTPUT("LOCK"); \ + __PDB_LOCK(dbptr->mutex); \ + } \ + } +#define PDB_MUTEX_UNLOCK(dbptr) \ + { \ + if ((dbptr->settings & PDB_THREAD_SAFE) == PDB_THREAD_SAFE) { \ + __PDB_THREAD_DEBUG_OUTPUT("UNLOCK"); \ + __PDB_UNLOCK(dbptr->mutex); \ + } \ + } + + +/* * If PDB_WRITE_NODE_FIRST is enabled, write the following * node to disk first (if existant in the root). * This is only for the root node. @@ -84,7 +136,7 @@ * differ from node to node. */ struct pdb_node_t; -typedef int (*custom_free_cb_t)(struct pdb_node_t* nptr); +typedef int (*custom_free_cb_t)(void* nptr); /* @@ -109,6 +161,7 @@ long last_write; int write_interval; /* in seconds */ int settings; + pthread_mutex_t* mutex; }; @@ -131,6 +184,8 @@ void* pdb_query(struct pdb* dbptr, char* path); struct pdb_node_t* pdb_set(struct pdb* dbptr, char* path, char* key, + void* data); +struct pdb_node_t* pdb_set_node(struct pdb* dbptr, char* path, char* key, void* data, int type); int pdb_del(struct pdb* dbptr, char* path); @@ -140,10 +195,20 @@ int pdb_need_write(struct pdb* dbptr); int pdb_write(struct pdb* dbptr, char* file); -void pdb_set_free_method(struct pdb_node_t* nptr, void* free_cb); +void pdb_set_free_method(struct pdb* dbptr, struct pdb_node_t* nptr, + void* free_cb); + +int pdb_count_children(struct pdb* dbptr, char* path); #ifdef __cplusplus } #endif +/* + * For ease of inclusion -- include other pdb headers. + */ +#include "pdb_file.h" +#include "pdb_types.h" +#include "pdb_parse.h" + #endif /* _PDB_H */ Index: pdb_types.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb_types.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pdb_types.h 9 Jan 2005 01:28:05 -0000 1.5 +++ pdb_types.h 16 Jan 2005 00:46:21 -0000 1.6 @@ -70,6 +70,7 @@ struct pdb_node_t* nptr); typedef int (*write_cb_t)(struct pdb* dbptr, FILE* fptr, struct pdb_node_t* nptr, int tabs); +typedef int (*count_children_cb_t)(struct pdb_node_t* nptr); /* @@ -87,6 +88,8 @@ query_cb_t query_cb; del_child_cb_t del_child_cb; write_cb_t write_cb; + count_children_cb_t count_children_cb; + }; @@ -101,6 +104,15 @@ { #endif +struct pdb_node_t* pdb_create_tree(struct pdb* dbptr, char* path, char* key); +struct pdb_node_t* pdb_create_list(struct pdb* dbptr, char* path, char* key); +struct pdb_node_t* pdb_create_hash(struct pdb* dbptr, char* path, char* key, + int size); +struct pdb_node_t* pdb_create_abstract(struct pdb* dbptr, char* path, + char* key, void* data, void* free_cb); +struct pdb_node_t* pdb_set_int(struct pdb* dbptr, char* path, + char* key, int data); + struct pdb_node_types_t* pdb_get_type_info(int type); struct pdb_node_types_t* pdb_get_type_info_otok(char* tok); struct pdb_node_types_t* pdb_get_type_info_ctok(char* tok); @@ -126,6 +138,7 @@ struct pdb_node_t* nptr); int pdb_write_tree_node_cb(struct pdb* dbptr, FILE* fptr, struct pdb_node_t* nptr, int tabs); +int pdb_count_children_tree_cb(struct pdb_node_t* nptr); /* * Link list @@ -142,6 +155,7 @@ struct pdb_node_t* nptr); int pdb_write_list_node_cb(struct pdb* dbptr, FILE* fptr, struct pdb_node_t* nptr, int tabs); +int pdb_count_children_list_cb(struct pdb_node_t* nptr); /* * Hash table @@ -159,6 +173,7 @@ struct pdb_node_t* nptr); int pdb_write_hash_node_cb(struct pdb* dbptr, FILE* fptr, struct pdb_node_t* nptr, int tabs); +int pdb_count_children_hash_cb(struct pdb_node_t* nptr); /* * String Index: pdb_parse.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb_parse.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pdb_parse.h 9 Jan 2005 03:35:38 -0000 1.3 +++ pdb_parse.h 16 Jan 2005 00:46:21 -0000 1.4 @@ -35,11 +35,6 @@ { #endif -struct pdb_node_t* pdb_create_tree(struct pdb* dbptr, char* path, char* key); -struct pdb_node_t* pdb_create_list(struct pdb* dbptr, char* path, char* key); -struct pdb_node_t* pdb_create_hash(struct pdb* dbptr, char* path, char* key, - int size); - char* pdb_get_token(FILE* fptr, int* type, int* line); int tok_starts_with(char* str, char* tok); char** pdb_token_parse(char* str); Index: binarytree.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/binarytree.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- binarytree.h 9 Jan 2005 02:03:24 -0000 1.2 +++ binarytree.h 16 Jan 2005 00:46:21 -0000 1.3 @@ -83,6 +83,8 @@ void tree_set_strcmp(struct binaryTree* tptr, tree_str_cmp_cb _strcmp); int _tree_lower_strcmp(char* s1, char* s2); +int tree_count_children(struct binaryTree* tptr); + #ifdef __cplusplus } #endif |
From: Michael L. <par...@us...> - 2005-01-16 00:46:31
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1982 Modified Files: pdb.pws Log Message: Now handles shared memory management via local mutex. Index: pdb.pws =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.pws,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pdb.pws 9 Jan 2005 03:35:38 -0000 1.7 +++ pdb.pws 16 Jan 2005 00:46:21 -0000 1.8 @@ -3,9 +3,9 @@ 0=59 1=36 2=24 -3=183 -4=95 -5=55 +3=25 +4=101 +5=38 6=133 [filemarkers] |
From: Michael L. <par...@us...> - 2005-01-09 03:35:49
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24852/src Modified Files: pdb.c pdb_parse.c pdb_types.c Log Message: Scheduled writing complete, fixed various minor bugs. Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pdb.c 9 Jan 2005 02:03:24 -0000 1.6 +++ pdb.c 9 Jan 2005 03:35:39 -0000 1.7 @@ -24,6 +24,7 @@ #include <stdio.h> #include <malloc.h> #include <string.h> +#include <time.h> #include "str.h" #include "pdb.h" @@ -32,42 +33,20 @@ #include "pdb_types.h" #include "list.h" -#include "hash.h" -#include "binarytree.h" - int main(int argc, char** argv) { - struct binaryTree* tptr = tree_create(); - char* a1 = strdup("a1"); - char* A1 = strdup("A1"); - char* b2 = strdup("b2"); - char* B2 = strdup("B2"); - - tree_add_node(tptr, "a1", a1); - tree_add_node(tptr, "A1", A1); - tree_add_node(tptr, "b2", b2); - tree_add_node(tptr, "B2", B2); - - tree_debug(tptr->root); - - tree_enable(tptr, TREE_FLAG_NO_CASE); - char* d = tree_get_node(tptr, "A1"); - printf("[%s]\n", d); - - tree_free(tptr, 1, NULL); - - /*printf(PDB_COMPILE_INFO); + printf(PDB_COMPILE_INFO); printf("\n--LOAD--\n\n"); struct pdb* dbptr = pdb_load("/home/para/test.db"); printf("\n--DEBUG--\n\n"); - char* a = pdb_query(dbptr, "foo/a"); + char* a = pdb_query(dbptr, "foo"); printf("[%s]\n", a); //pdb_write(dbptr, "/home/para/test.db2"); printf("\n--UNLOAD--\n\n"); - pdb_unload(dbptr);*/ + pdb_unload(dbptr); return 0; } @@ -93,6 +72,8 @@ * Initialize pdb structure. */ dbptr->altered = 0; + dbptr->last_write = time(NULL); + dbptr->write_interval = PDB_DEFAULT_WRITE_INTERVAL; dbptr->settings = PDB_DEFAULT_SETTINGS; dbptr->file = (char*)malloc(sizeof(char) * (strlen(file) + 1)); strcpy(dbptr->file, file); @@ -214,8 +195,11 @@ /* * Set a node's data. If it does not exist, create it. + * Return a pointer to the node. */ -int pdb_set(struct pdb* dbptr, char* path, char* key, void* data, int type) { +struct pdb_node_t* pdb_set(struct pdb* dbptr, char* path, char* key, + void* data, int type) { + struct pdb_node_types_t* tiptr; struct pdb_node_t* pptr; struct pdb_node_types_t* ptiptr; @@ -223,11 +207,11 @@ tiptr = pdb_get_type_info(type); if (!tiptr) - return 0; + return NULL; pptr = pdb_query_node(dbptr, path); if (!pptr) - return 0; + return NULL; ptiptr = pdb_get_type_info(pptr->type); nptr = ptiptr->query_cb(pptr, key); @@ -240,19 +224,25 @@ if (!nptr) { fprintf(stderr, "%s:%s():%i: Error: Unable to create \"%s/%s\" in \ database.\n", __FILE__, __FUNCTION__, __LINE__, path, key); - return 0; + return NULL; } } + /* + * Schedule a disk write. + */ + dbptr->altered = 1; + if (!tiptr->set_cb) { fprintf(stderr, "%s:%s():%i: Warning: Unable to set data at \"%s/%s\" \ in database; type %i does not support it.\n", __FILE__, __FUNCTION__, __LINE__, path, key, tiptr->bitmask); - return 0; + return NULL; } tiptr->set_cb(nptr, data); - return 1; + + return nptr; } @@ -276,6 +266,11 @@ return 0; } + /* + * Schedule a disk write. + */ + dbptr->altered = 1; + return pdb_free_node(nptr); } @@ -339,6 +334,21 @@ /* + * Set the disk write interval. + */ +void pdb_set_write_interval(struct pdb* dbptr, int seconds) { + dbptr->write_interval = seconds; +} + +/* + * Return 1 if the pdb is scheduled for a disk write. + */ +int pdb_need_write(struct pdb* dbptr) { + return (time(NULL) >= (dbptr->last_write + dbptr->write_interval)); +} + + +/* * Write a loaded database structure to disk. */ int pdb_write(struct pdb* dbptr, char* file) { @@ -362,6 +372,13 @@ ret = pdb_standard_write_node(dbptr, fptr, nptr, -1); fclose(fptr); + + /* + * Reset our writing schedule. + */ + dbptr->altered = 0; + dbptr->last_write = time(NULL); + return ret; } Index: pdb_parse.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_parse.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pdb_parse.c 9 Jan 2005 01:28:05 -0000 1.4 +++ pdb_parse.c 9 Jan 2005 03:35:39 -0000 1.5 @@ -34,22 +34,6 @@ static char* remove_chasing_whitespaces(char* str); /* - * TEMP FUNCTION - */ -char* ttype(int num) { - if (num == NO_NODE_TYPE) - return "none"; - else if (num == TREE_NODE_TYPE) - return "tree"; - else if (num == LIST_NODE_TYPE) - return "list"; - else if (num == STRING_NODE_TYPE) - return "string"; - return NULL; -} - - -/* * Return the next token from the loaded file. * A token will be the entire string, excluding any * padding whitespaces. It will also not include Index: pdb_types.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_types.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pdb_types.c 9 Jan 2005 01:28:05 -0000 1.5 +++ pdb_types.c 9 Jan 2005 03:35:39 -0000 1.6 @@ -162,6 +162,35 @@ static int pdb_free_node_cb(void* dptr); +/****************** + ****************** + ****************** Container creation wrappers. + ****************** + ******************/ + + +struct pdb_node_t* pdb_create_tree(struct pdb* dbptr, char* path, char* key) { + return pdb_set(dbptr, path, key, NULL, TREE_NODE_TYPE); +} + +struct pdb_node_t* pdb_create_list(struct pdb* dbptr, char* path, char* key) { + return pdb_set(dbptr, path, key, NULL, LIST_NODE_TYPE); +} + +struct pdb_node_t* pdb_create_hash(struct pdb* dbptr, char* path, char* key, + int size) { + + return pdb_set(dbptr, path, key, &size, HASH_NODE_TYPE); +} + + +/****************** + ****************** + ****************** Helper functions. + ****************** + ******************/ + + /* * Return type info struct by the given bitmask id. */ @@ -332,7 +361,7 @@ /* * Use the custom free callback rather than the default. */ - ret = nptr->custom_free_cb(nptr); + ret = nptr->custom_free_cb(nptr->data); } else { tiptr = pdb_get_type_info(nptr->type); ret = tiptr->free_cb(nptr); @@ -974,8 +1003,12 @@ if (nptr->data) nptr->data = (char*)realloc(nptr->data, sizeof(char) * (strlen(dptr) + 1)); - else + else { + if (!dptr) + dptr = ""; + nptr->data = (char*)malloc(sizeof(char) * (strlen(dptr) + 1)); + } if (!nptr->data) { ERROR("Unable to allocate memory for string data."); @@ -1106,10 +1139,11 @@ * Free an abstract node. */ int pdb_free_abstract_node_cb(struct pdb_node_t* nptr) { - /* - * TODO -- how do we free this? - */ - //free(nptr->data); + fprintf(stderr, "Warning: %s:%s():%i: Abstract node cannot be freed " \ + "-- no custom free method defined! [%s]\n", \ + __FILE__, __FUNCTION__, __LINE__, + pdb_trace(nptr)); + return 1; } |
From: Michael L. <par...@us...> - 2005-01-09 03:35:47
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24852/include Modified Files: pdb.h pdb_parse.h Log Message: Scheduled writing complete, fixed various minor bugs. Index: pdb.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pdb.h 26 Oct 2004 20:02:19 -0000 1.4 +++ pdb.h 9 Jan 2005 03:35:38 -0000 1.5 @@ -27,7 +27,7 @@ */ #define ERROR(msg) fprintf(stderr, "Error: %s:%s():%i: %s\n", __FILE__, \ __FUNCTION__, __LINE__, msg); -#define WARNING(msg) fprintf(stderr, "Error: %s:%s():%i: %s\n", __FILE__, \ +#define WARNING(msg) fprintf(stderr, "Warning: %s:%s():%i: %s\n", __FILE__, \ __FUNCTION__, __LINE__, msg); #define PDB_COMPILE_INFO "pdb: Compiled on: " __DATE__ " at " __TIME__ @@ -72,6 +72,12 @@ /* + * pdb's default disk write interval in seconds. + */ +#define PDB_DEFAULT_WRITE_INTERVAL 120 + + +/* * This callback can be used to override standard free * callbacks for nodes. It is especially useful for non-standard * types like ABSTRACT_NODE_TYPE, where the actual data type may @@ -100,6 +106,8 @@ struct pdb_node_t* data; char* file; int altered; + long last_write; + int write_interval; /* in seconds */ int settings; }; @@ -122,11 +130,14 @@ struct pdb_node_t* pdb_query_node(struct pdb* dbptr, char* path); void* pdb_query(struct pdb* dbptr, char* path); -int pdb_set(struct pdb* dbptr, char* path, char* key, void* data, int type); +struct pdb_node_t* pdb_set(struct pdb* dbptr, char* path, char* key, + void* data, int type); int pdb_del(struct pdb* dbptr, char* path); char* pdb_trace(struct pdb_node_t* nptr); +void pdb_set_write_interval(struct pdb* dbptr, int seconds); +int pdb_need_write(struct pdb* dbptr); int pdb_write(struct pdb* dbptr, char* file); void pdb_set_free_method(struct pdb_node_t* nptr, void* free_cb); Index: pdb_parse.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb_parse.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pdb_parse.h 26 Oct 2004 03:41:08 -0000 1.2 +++ pdb_parse.h 9 Jan 2005 03:35:38 -0000 1.3 @@ -34,6 +34,11 @@ extern "C" { #endif + +struct pdb_node_t* pdb_create_tree(struct pdb* dbptr, char* path, char* key); +struct pdb_node_t* pdb_create_list(struct pdb* dbptr, char* path, char* key); +struct pdb_node_t* pdb_create_hash(struct pdb* dbptr, char* path, char* key, + int size); char* pdb_get_token(FILE* fptr, int* type, int* line); int tok_starts_with(char* str, char* tok); |
From: Michael L. <par...@us...> - 2005-01-09 03:35:47
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24852 Modified Files: pdb.pws Log Message: Scheduled writing complete, fixed various minor bugs. Index: pdb.pws =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.pws,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pdb.pws 9 Jan 2005 02:03:23 -0000 1.6 +++ pdb.pws 9 Jan 2005 03:35:38 -0000 1.7 @@ -1,11 +1,11 @@ [filenumbers] -0=83 -1=443 -2=84 -3=153 -4=906 -5=60 +0=59 +1=36 +2=24 +3=183 +4=95 +5=55 6=133 [filemarkers] @@ -29,9 +29,12 @@ clean before build=false [filelist] -0=/home/para/Projects/pdb/include/binarytree.h -1=/home/para/Projects/pdb/src/binarytree.c -2=/home/para/Projects/pdb/src/pdb.c +0=/home/para/Projects/pdb/src/hash.c +1=/home/para/Projects/pdb/src/pdb_parse.c +2=/home/para/Projects/pdb/include/pdb_parse.h +3=/home/para/Projects/pdb/src/pdb_types.c +4=/home/para/Projects/pdb/include/pdb.h +5=/home/para/Projects/pdb/src/pdb.c [Project Tree] 0=0 |