pdatabase-cvs Mailing List for pdb (Page 3)
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-01-09 02:25:41
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31824/src Modified Files: Makefile Makefile.am Makefile.in binarytree.c list.c pdb.c pdb_parse.c pdb_types.c str.c Log Message: Completed hash type support -- loadable from function calls and disk. Index: pdb_types.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_types.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pdb_types.c 26 Oct 2004 20:02:24 -0000 1.4 +++ pdb_types.c 9 Jan 2005 01:28:05 -0000 1.5 @@ -20,11 +20,13 @@ */ #include <stdio.h> +#include <stdlib.h> #include <math.h> #include <string.h> #include <malloc.h> #include "list.h" #include "binarytree.h" +#include "hash.h" #include "str.h" #include "pdb.h" #include "pdb_parse.h" @@ -72,6 +74,20 @@ pdb_write_list_node_cb }, { + /* Hash table */ + HASH_NODE_TYPE, + "[", + "]", + pdb_create_hash_node_cb, + pdb_load_hash_node_cb, + pdb_set_hash_node_cb, /* hash setting "creates" the hash */ + pdb_add_hash_node_child_cb, + pdb_free_hash_node_cb, + pdb_query_hash_node_cb, + pdb_del_child_hash_node_cb, + pdb_write_hash_node_cb + }, + { /* String */ STRING_NODE_TYPE, NULL, /* standard load type (fallback) */ @@ -150,12 +166,7 @@ * Return type info struct by the given bitmask id. */ struct pdb_node_types_t* pdb_get_type_info(int type) { - /* - * Floating point arithmetic is not _exact_, - * so round to a whole number. - * It will give you some BS like 2.9999...9 rather than 3. - */ - return(&(pdb_types[round_i(log(type) / log(2))])); + return (&pdb_types[type - 1]); } @@ -198,8 +209,10 @@ * It will also add the newly created child to the parent structure. */ void* pdb_standard_create_node(char* id, struct pdb_node_t* parent, int type) { - struct pdb_node_t* nptr = - (struct pdb_node_t*)malloc(sizeof(struct pdb_node_t)); + struct pdb_node_t* nptr; + struct pdb_node_types_t* tiptr; + + nptr = (struct pdb_node_t*)malloc(sizeof(struct pdb_node_t)); if (!nptr) { ERROR("Unable to allocate memory for node structure."); return NULL; @@ -220,7 +233,7 @@ * Add child to parent structure. */ if (parent) { - struct pdb_node_types_t* tiptr = pdb_get_type_info(parent->type); + 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", @@ -250,13 +263,10 @@ */ int pdb_standard_load_node(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, int* line) { - - printf("loading %s\n", ttype(pptr->type)); + int type = pptr->type; - struct pdb_node_types_t* ctiptr = NULL; void* cptr = NULL; - char* tok = pdb_get_token(fptr, &type, line); while (tok) { @@ -269,8 +279,6 @@ } tok_arr = pdb_token_parse(tok); - printf("loading (%i)[%s] of type %s into [%s] of type %s\n", - type, tok_arr[0], ttype(type), pptr->id, ttype(pptr->type)); /* * Create the child node and add to parent. @@ -317,14 +325,16 @@ */ int pdb_free_node_cb(void* dptr) { struct pdb_node_t* nptr = dptr; + struct pdb_node_types_t* tiptr; int ret = 0; + if (nptr->custom_free_cb) { /* * Use the custom free callback rather than the default. */ ret = nptr->custom_free_cb(nptr); } else { - struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); + tiptr = pdb_get_type_info(nptr->type); ret = tiptr->free_cb(nptr); } if (nptr->id) @@ -342,6 +352,8 @@ * (e.g. pdb_del rather than pdb_unload). */ int pdb_free_node(struct pdb_node_t* nptr) { + struct pdb_node_types_t* tiptr; + /* * Remove from parent. */ @@ -357,7 +369,7 @@ */ ret = nptr->custom_free_cb(nptr); } else { - struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); + tiptr = pdb_get_type_info(nptr->type); ret = tiptr->free_cb(nptr); } @@ -377,10 +389,12 @@ * Delete a node from its parent, but don't free the node. */ void pdb_del_node_from_parent(struct pdb_node_t* nptr) { + struct pdb_node_types_t* tiptr; + if (!nptr->parent) return; - struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->parent->type); + tiptr = pdb_get_type_info(nptr->parent->type); if (!tiptr->del_child_cb) { fprintf(stderr, "%s:%s():%i: Error: Cannot remove '%s' from parent; \ @@ -404,7 +418,12 @@ int pdb_standard_write_node(struct pdb* dbptr, FILE* fptr, struct pdb_node_t* nptr, int tabs) { - struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); + struct pdb_node_types_t* tiptr; + int i = 0; + int ret; + + tiptr = pdb_get_type_info(nptr->type); + if (!tiptr->write_cb) { char* trace = pdb_trace(nptr); fprintf(stderr, "%s:%s():%i: Warning: Unable to write node \"%s\" to \ @@ -417,7 +436,6 @@ /* * Write tabs -- if any (if tabs != -1 [root]). */ - int i = 0; if (tabs != -1) for (; i < tabs; i++) fputc('\t', fptr); @@ -439,7 +457,7 @@ /* * Write node to disk. */ - int ret = tiptr->write_cb(dbptr, fptr, nptr, tabs + 1); + ret = tiptr->write_cb(dbptr, fptr, nptr, tabs + 1); /* * Write tabs and tree closing token (if tabs != -1 [root]). @@ -456,11 +474,11 @@ } -/************************************************************* - ****************** ****************** - ****************** Binary Tree Node Type ****************** - ****************** ****************** - *************************************************************/ +/****************** + ****************** + ****************** Binary Tree Node Type + ****************** + ******************/ /* @@ -469,12 +487,14 @@ void* pdb_create_tree_node_cb(char* id, struct pdb_node_t* parent, char** tok_arr) { - struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, - TREE_NODE_TYPE); + struct pdb_node_t* nptr; + struct binaryTree* tptr; + + nptr = pdb_standard_create_node(id, parent, TREE_NODE_TYPE); if (!nptr) return NULL; - struct binaryTree* tptr = tree_create(); + tptr = tree_create(); if (!tptr) { ERROR("Unable to allocate memory for node data structure [tree]."); free(nptr); @@ -543,13 +563,17 @@ int pdb_write_tree_node_cb(struct pdb* dbptr, FILE* fptr, struct pdb_node_t* nptr, int tabs) { + struct binaryTree* tptr; + struct linkList* lptr; + struct linkNode* lnptr; + /* * Create a list from the tree so we can iterate through it. */ - struct binaryTree* tptr = nptr->data; - struct linkList* lptr = list_create(); + tptr = nptr->data; + lptr = list_create(); tree_to_list(tptr, lptr); - struct linkNode* lnptr = lptr->root; + lnptr = lptr->root; /* * Shuffle tree (if set). @@ -598,11 +622,11 @@ } -/************************************************************* - ****************** ****************** - ****************** List Node Type ****************** - ****************** ****************** - *************************************************************/ +/****************** + ****************** + ****************** List Node Type + ****************** + ******************/ /* @@ -611,12 +635,14 @@ void* pdb_create_list_node_cb(char* id, struct pdb_node_t* parent, char** tok_arr) { - struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, - LIST_NODE_TYPE); + struct pdb_node_t* nptr; + struct linkList* lptr; + + nptr = pdb_standard_create_node(id, parent, LIST_NODE_TYPE); if (!nptr) return NULL; - struct linkList* lptr = list_create(); + lptr = list_create(); if (!lptr) { ERROR("Unable to allocate memory for node data structure [list]."); free(nptr); @@ -700,9 +726,6 @@ int pdb_write_list_node_cb(struct pdb* dbptr, FILE* fptr, struct pdb_node_t* nptr, int tabs) { - /* - * Create a list from the tree so we can iterate through it. - */ struct linkList* lptr = nptr->data; struct linkNode* lnptr = lptr->root; @@ -740,11 +763,180 @@ } -/************************************************************* - ****************** ****************** - ****************** String Node Type ****************** - ****************** ****************** - *************************************************************/ +/****************** + ****************** + ****************** Hash Node Type + ****************** + ******************/ + + +/* + * Callback for creating a new hash node. + */ +void* pdb_create_hash_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr) { + + struct pdb_node_t* nptr; + + nptr = pdb_standard_create_node(id, parent, HASH_NODE_TYPE); + if (!nptr) + return NULL; + + /* + * Due to the nature of the hash table, at this point it + * can only be created from disk. + * This is because we need the size, and the only viable + * method of obtaining it is from the file itself. + * For now, we leave the data NULL -- it will be created + * on load :( + */ + nptr->data = NULL; + + return nptr; +} + + +/* + * Callback for loading a hash node. + */ +int pdb_load_hash_node_cb(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, + int* line) { + + int type; + char* tok; + + /* + * The hash table must first be created. + * Get the size of the table from the file, + * it should be next. + */ + type = pptr->type; + tok = pdb_get_token(fptr, &type, line); + printf("[%s]\n", tok); + + if ((type != STRING_NODE_TYPE) || (!tok) || (tok ? !*tok : 0)) { + char* e = va(NULL, + "Unable to load hash from file -- no size (line %i).\n", *line); + ERROR(e); + free(e); + return 0; + } + + type = atoi(tok); + pptr->data = (void*)hash_create(type); + + free(tok); + + return pdb_standard_load_node(fptr, pptr, tok_arr, line); +} + + +/* + * Setting a hash should only be done in pdb_set(). + * This will create the real hash table, where as + * pdb_create_hash_node_cb() only setup the node in the db. + * + * The void* data is an int* of the hash size. + */ +void pdb_set_hash_node_cb(struct pdb_node_t* nptr, void* data) { + int* dptr = (int*)data; + + nptr->data = (void*)hash_create(*dptr); +} + + +/* + * Add a child to the parent structure. + */ +int pdb_add_hash_node_child_cb(struct pdb_node_t* parent, char* id, + struct pdb_node_t* child) { + + struct hash* hptr = parent->data; + return hash_add(hptr, id, child); +} + + +/* + * Free a hash node. + */ +int pdb_free_hash_node_cb(struct pdb_node_t* nptr) { + struct hash* hptr = nptr->data; + hash_free(hptr, (void*)&pdb_free_node_cb); + return 1; +} + + +/* + * Query a child node from the given hash. + */ +struct pdb_node_t* pdb_query_hash_node_cb(struct pdb_node_t* nptr, char* id) { + struct hash* hptr = nptr->data; + return ((struct pdb_node_t*)hash_get(hptr, id)); +} + + +/* + * Delete a child from the parent hash, but do not free child. + */ +void pdb_del_child_hash_node_cb(struct pdb_node_t* pptr, + struct pdb_node_t* nptr) { + + struct hash* hptr = pptr->data; + hash_remove(hptr, nptr->id); +} + + +/* + * Write a link list node to disk. + */ +int pdb_write_hash_node_cb(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs) { + + struct hash* hptr = nptr->data; + struct hash_node_t* hnptr = NULL; + int i = 0; + struct linkList* lptr = NULL; + struct linkNode* lnptr = NULL; + char* ic = NULL; + + /* + * Write the table size to disk. + */ + for (; i < tabs; i++) + fputc('\t', fptr); + ic = itoa(hptr->size); + fputs(ic, fptr); + free(ic); + fputc(PDB_TOKEN_TERM, fptr); + fputc('\n', fptr); + + /* + * Write all children to disk. + */ + lptr = NULL; + lnptr = NULL; + for (i = 0; i < hptr->size; i++) { + lptr = hptr->tbl[i]; + if (!lptr) + continue; + lnptr = lptr->root; + while (lnptr) { + hnptr = lnptr->data; + if (!pdb_standard_write_node(dbptr, fptr, hnptr->data, tabs)) + return 0; + lnptr = lnptr->next; + } + } + + return 1; +} + + +/****************** + ****************** + ****************** String Node Type + ****************** + ******************/ /* @@ -754,8 +946,9 @@ void* pdb_create_string_node_cb(char* id, struct pdb_node_t* parent, char** tok_arr) { - struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, - STRING_NODE_TYPE); + struct pdb_node_t* nptr; + + nptr = pdb_standard_create_node(id, parent, STRING_NODE_TYPE); if (!nptr) return NULL; @@ -828,11 +1021,11 @@ } -/************************************************************* - ****************** ****************** - ****************** Integer Node Type ****************** - ****************** ****************** - *************************************************************/ +/****************** + ****************** + ****************** Integer Node Type + ****************** + ******************/ /* @@ -842,8 +1035,9 @@ void* pdb_create_int_node_cb(char* id, struct pdb_node_t* parent, char** tok_arr) { - struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, - INT_NODE_TYPE); + struct pdb_node_t* nptr; + + nptr = pdb_standard_create_node(id, parent, INT_NODE_TYPE); if (!nptr) return NULL; @@ -874,11 +1068,11 @@ } -/************************************************************* - ****************** ****************** - ****************** Abstract Node Type ****************** - ****************** ****************** - *************************************************************/ +/****************** + ****************** + ****************** Abstract Node Type + ****************** + ******************/ /* @@ -888,8 +1082,9 @@ void* pdb_create_abstract_node_cb(char* id, struct pdb_node_t* parent, char** tok_arr) { - struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, - ABSTRACT_NODE_TYPE); + struct pdb_node_t* nptr; + + nptr = pdb_standard_create_node(id, parent, ABSTRACT_NODE_TYPE); if (!nptr) return NULL; @@ -919,11 +1114,11 @@ } -/************************************************************* - ****************** ****************** - ****************** Link Node Type ****************** - ****************** ****************** - *************************************************************/ +/****************** + ****************** + ****************** Link Node Type + ****************** + ******************/ /* @@ -936,8 +1131,9 @@ void* pdb_create_link_node_cb(char* id, struct pdb_node_t* parent, char** tok_arr) { - struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, - LINK_NODE_TYPE); + struct pdb_node_t* nptr; + + nptr = pdb_standard_create_node(id, parent, LINK_NODE_TYPE); if (!nptr) return NULL; Index: Makefile.am =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.am 18 Oct 2004 00:20:50 -0000 1.1.1.1 +++ Makefile.am 9 Jan 2005 01:28:05 -0000 1.2 @@ -24,7 +24,8 @@ pdb_types.c\ binarytree.c\ list.c\ - str.c + str.c\ + hash.c pdb_LDFLAGS = Index: str.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/str.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- str.c 18 Oct 2004 00:20:49 -0000 1.1.1.1 +++ str.c 9 Jan 2005 01:28:05 -0000 1.2 @@ -33,204 +33,17 @@ #include <ctype.h> #include <string.h> #include <stdlib.h> -#include <sys/time.h> -#include <pthread.h> +//#ifdef POSIX + #include <sys/time.h> + #include <pthread.h> +//#else +// #include <winsock.h> +// #include <time.h> +//#endif #include "str.h" /* - * Easier (and faster) method of converting - * an integer to a string. - */ -static char* s_dec[1001] = { - "0", - "1", "2", "3", "4", "5", "6", "7", "8", "9", - "10", "11", "12", "13", "14", "15", "16", "17", "18", - "19", "20", "21", "22", "23", "24", "25", "26", "27", - "28", "29", "30", "31", "32", "33", "34", "35", "36", - "37", "38", "39", "40", "41", "42", "43", "44", "45", - "46", "47", "48", "49", "50", "51", "52", "53", "54", - "55", "56", "57", "58", "59", "60", "61", "62", "63", - "64", "65", "66", "67", "68", "69", "70", "71", "72", - "73", "74", "75", "76", "77", "78", "79", "80", "81", - "82", "83", "84", "85", "86", "87", "88", "89", "90", - "91", "92", "93", "94", "95", "96", "97", "98", "99", - "100", "101", "102", "103", "104", "105", "106", "107", "108", - "109", "110", "111", "112", "113", "114", "115", "116", "117", - "118", "119", "120", "121", "122", "123", "124", "125", "126", - "127", "128", "129", "130", "131", "132", "133", "134", "135", - "136", "137", "138", "139", "140", "141", "142", "143", "144", - "145", "146", "147", "148", "149", "150", "151", "152", "153", - "154", "155", "156", "157", "158", "159", "160", "161", "162", - "163", "164", "165", "166", "167", "168", "169", "170", "171", - "172", "173", "174", "175", "176", "177", "178", "179", "180", - "181", "182", "183", "184", "185", "186", "187", "188", "189", - "190", "191", "192", "193", "194", "195", "196", "197", "198", - "199", "200", "201", "202", "203", "204", "205", "206", "207", - "208", "209", "210", "211", "212", "213", "214", "215", "216", - "217", "218", "219", "220", "221", "222", "223", "224", "225", - "226", "227", "228", "229", "230", "231", "232", "233", "234", - "235", "236", "237", "238", "239", "240", "241", "242", "243", - "244", "245", "246", "247", "248", "249", "250", "251", "252", - "253", "254", "255", "256", "257", "258", "259", "260", "261", - "262", "263", "264", "265", "266", "267", "268", "269", "270", - "271", "272", "273", "274", "275", "276", "277", "278", "279", - "280", "281", "282", "283", "284", "285", "286", "287", "288", - "289", "290", "291", "292", "293", "294", "295", "296", "297", - "298", "299", "300", "301", "302", "303", "304", "305", "306", - "307", "308", "309", "310", "311", "312", "313", "314", "315", - "316", "317", "318", "319", "320", "321", "322", "323", "324", - "325", "326", "327", "328", "329", "330", "331", "332", "333", - "334", "335", "336", "337", "338", "339", "340", "341", "342", - "343", "344", "345", "346", "347", "348", "349", "350", "351", - "352", "353", "354", "355", "356", "357", "358", "359", "360", - "361", "362", "363", "364", "365", "366", "367", "368", "369", - "370", "371", "372", "373", "374", "375", "376", "377", "378", - "379", "380", "381", "382", "383", "384", "385", "386", "387", - "388", "389", "390", "391", "392", "393", "394", "395", "396", - "397", "398", "399", "400", "401", "402", "403", "404", "405", - "406", "407", "408", "409", "410", "411", "412", "413", "414", - "415", "416", "417", "418", "419", "420", "421", "422", "423", - "424", "425", "426", "427", "428", "429", "430", "431", "432", - "433", "434", "435", "436", "437", "438", "439", "440", "441", - "442", "443", "444", "445", "446", "447", "448", "449", "450", - "451", "452", "453", "454", "455", "456", "457", "458", "459", - "460", "461", "462", "463", "464", "465", "466", "467", "468", - "469", "470", "471", "472", "473", "474", "475", "476", "477", - "478", "479", "480", "481", "482", "483", "484", "485", "486", - "487", "488", "489", "490", "491", "492", "493", "494", "495", - "496", "497", "498", "499", "500", "501", "502", "503", "504", - "505", "506", "507", "508", "509", "510", "511", "512", "513", - "514", "515", "516", "517", "518", "519", "520", "521", "522", - "523", "524", "525", "526", "527", "528", "529", "530", "531", - "532", "533", "534", "535", "536", "537", "538", "539", "540", - "541", "542", "543", "544", "545", "546", "547", "548", "549", - "550", "551", "552", "553", "554", "555", "556", "557", "558", - "559", "560", "561", "562", "563", "564", "565", "566", "567", - "568", "569", "570", "571", "572", "573", "574", "575", "576", - "577", "578", "579", "580", "581", "582", "583", "584", "585", - "586", "587", "588", "589", "590", "591", "592", "593", "594", - "595", "596", "597", "598", "599", "600", "601", "602", "603", - "604", "605", "606", "607", "608", "609", "610", "611", "612", - "613", "614", "615", "616", "617", "618", "619", "620", "621", - "622", "623", "624", "625", "626", "627", "628", "629", "630", - "631", "632", "633", "634", "635", "636", "637", "638", "639", - "640", "641", "642", "643", "644", "645", "646", "647", "648", - "649", "650", "651", "652", "653", "654", "655", "656", "657", - "658", "659", "660", "661", "662", "663", "664", "665", "666", - "667", "668", "669", "670", "671", "672", "673", "674", "675", - "676", "677", "678", "679", "680", "681", "682", "683", "684", - "685", "686", "687", "688", "689", "690", "691", "692", "693", - "694", "695", "696", "697", "698", "699", "700", "701", "702", - "703", "704", "705", "706", "707", "708", "709", "710", "711", - "712", "713", "714", "715", "716", "717", "718", "719", "720", - "721", "722", "723", "724", "725", "726", "727", "728", "729", - "730", "731", "732", "733", "734", "735", "736", "737", "738", - "739", "740", "741", "742", "743", "744", "745", "746", "747", - "748", "749", "750", "751", "752", "753", "754", "755", "756", - "757", "758", "759", "760", "761", "762", "763", "764", "765", - "766", "767", "768", "769", "770", "771", "772", "773", "774", - "775", "776", "777", "778", "779", "780", "781", "782", "783", - "784", "785", "786", "787", "788", "789", "790", "791", "792", - "793", "794", "795", "796", "797", "798", "799", "800", "801", - "802", "803", "804", "805", "806", "807", "808", "809", "810", - "811", "812", "813", "814", "815", "816", "817", "818", "819", - "820", "821", "822", "823", "824", "825", "826", "827", "828", - "829", "830", "831", "832", "833", "834", "835", "836", "837", - "838", "839", "840", "841", "842", "843", "844", "845", "846", - "847", "848", "849", "850", "851", "852", "853", "854", "855", - "856", "857", "858", "859", "860", "861", "862", "863", "864", - "865", "866", "867", "868", "869", "870", "871", "872", "873", - "874", "875", "876", "877", "878", "879", "880", "881", "882", - "883", "884", "885", "886", "887", "888", "889", "890", "891", - "892", "893", "894", "895", "896", "897", "898", "899", "900", - "901", "902", "903", "904", "905", "906", "907", "908", "909", - "910", "911", "912", "913", "914", "915", "916", "917", "918", - "919", "920", "921", "922", "923", "924", "925", "926", "927", - "928", "929", "930", "931", "932", "933", "934", "935", "936", - "937", "938", "939", "940", "941", "942", "943", "944", "945", - "946", "947", "948", "949", "950", "951", "952", "953", "954", - "955", "956", "957", "958", "959", "960", "961", "962", "963", - "964", "965", "966", "967", "968", "969", "970", "971", "972", - "973", "974", "975", "976", "977", "978", "979", "980", "981", - "982", "983", "984", "985", "986", "987", "988", "989", "990", - "991", "992", "993", "994", "995", "996", "997", "998", "999", - "1000" -}; - - -/* - * Random numbers ranging from 0 - 10000000, - * because you never know when you will need one. - * - * A more time consuming method but better randomization - * would be to use rnd_i(). - */ -static int i_rnd[1001] = { - 3850971, 3041462, 1908384, 2286661, 9336546, - 4764411, 7019659, 3418351, 6337531, 3218359, - 4875727, 9335898, 3968657, 558772, 4847232, - 4182844, 4461563, 8386521, 5206347, 9386190, - 6416873, 6310874, 4303343, 8320923, 910853, - 8218139, 560295, 3331406, 4715867, 6233639, - 4080795, 8566839, 1791453, 5989179, 3369852, - 1127999, 3269942, 389511, 7062702, 9607473, - 6124223, 1938429, 1459723, 92880, 5013553, - 6306955, 6792076, 9475116, 4693477, 4514775, - 1377658, 3626702, 825649, 5681001, 1947625, - 1736502, 6415493, 5024273, 7584261, 1131360, - 3774264, 1665056, 2214551, 5565717, 170587, - 5584403, 6693716, 3440529, 8490267, 6272770, - 5564354, 4614490, 8211199, 7024078, 7223722, - 5741104, 5847385, 6532150, 7732573, 3057214, - 1046925, 9110231, 6683917, 1872574, 7307585, - 1147894, 6125429, 6239430, 6172167, 6226042, - 7370790, 9946431, 7891098, 2101694, 8028500, - 578037, 7686097, 7238568, 4018566, 8692716, - 3511338, 2099272, 5823558, 4238889, 1639702, - 3047280, 9979994, 7487088, 9579430, 228919, - 544302, 626355, 9339150, 9744571, 5015282, - 9163087, 892466, 3657063, 7918869, 9580985, - 9883105, 7806012, 2043769, 290555, 9907706, - 72269, 868592, 7593803, 7310838, 7403510, - 8802872, 822176, 9502782, 4626430, 7577418, - 1142485, 7673711, 7557412, 8629573, 9769493, - 7786331, 1690227, 2912201, 9641833, 1434799, - 443835, 1321273, 4843617, 4100898, 9240142, - 6940954, 3984003, 7046154, 8984723, 6790910, - 9470212, 1573345, 7659502, 9580368, 8884183, - 5063012, 8383240, 2222711, 7082146, 3009670, - 9800129, 8224631, 3199733, 9873893, 9370556, - 5485579, 176576, 3577136, 8397780, 2334762, - 7528287, 1357967, 6172387, 4888256, 5458865, - 5412529, 1829210, 1959220, 4975036, 813934, - 8750130, 6961600, 2387279, 8925984, 6541968, - 3787814, 6505348, 4925208, 8526877, 3587494, - 451231, 843359, 4328478, 6167316, 717252, - 6215386, 4169247, 3410181, 9792522, 2567027, - 5744943, 9837161, 3924994, 4433682, 4725417, - 1900211, 2362563, 6554628, 3859431, 7337599, - 7368562, 5125913, 6815552, 2272193, 6568249, - 3357520, 6060007, 3073597, 8282729, 4586884, - 9177444, 1250312, 5430243, 6022274, 9933980, - 8663848, 2237660, 4103228, 2074029, 4546535, - 9186607, 335324, 4383696, 5627954, 4769006, - 9109114, 7528165, 7131569, 5663742, 3903949, - 6985521, 5548656, 1546214, 3801073, 7820849, - 8114464, 9674945, 6397208, 3704413, 474026, - 3500444, 5398209, 1724338, 1447040, 1420483, - 1658319, 110888, 3658144, 8277899, 4701269, - 8204679, 7464506, 7552945, 2588375, 3092460, - 4838303, 4213841, 3136978, 4486224, 2393935, - 7040927, 1471745, 7942591, 1103493, 7789170, - 8279792, 1734309, 7464116, 7193352, 5438723, - 7938142, 693797, 836932, 2178833, 2140837, - 2257416, 6353504, 4768077, 8431912, 4631403, - 1985698, 6636591, 2095909, 9538643, 8233036 -}; - - -/* * Parse a token into an array. * The resulting array contains * character pointers to specific @@ -259,11 +72,16 @@ * when it is no longer needed. */ char** token_parse(char* token, char delim, char* dump) { + int size = 2; + char* ctoken = token; + char** tok_arr = NULL; + char* cpy = NULL; + int index = 0; + char* last = NULL; + /* * Determine the number of elements. */ - int size = 2; - char* ctoken = token; while (*ctoken) { if (*ctoken == delim) ++size; @@ -279,20 +97,20 @@ /* * Allocate memory for the array. */ - char** tok_arr = (char**)malloc(sizeof(char*) * size + sizeof(char*)); + tok_arr = (char**)malloc(sizeof(char*) * size + sizeof(char*)); /* * Copy token to first index of array. */ - char* cpy = (char*)malloc(sizeof(char) * strlen(token) + sizeof(char)); + cpy = (char*)malloc(sizeof(char) * strlen(token) + sizeof(char)); strcpy(cpy, token); token = cpy; /* * Parse the token. */ - int index = 0; - char* last = token; + index = 0; + last = token; while (*token) { if (*token == delim) { tok_arr[index] = last; @@ -321,6 +139,7 @@ */ void token_rm_index(char** tok_arr, int index) { int i = 0; + for (; i < index; i++) if (!tok_arr[i]) return; @@ -340,11 +159,13 @@ */ char* token_concat(char** tok_arr, int index) { int i = 0; + char* ret = NULL; + for (; i < index; i++) if (!tok_arr[i]) return NULL; - char* ret = (char*)malloc(sizeof(char)); + ret = (char*)malloc(sizeof(char)); *ret = '\0'; while (tok_arr[i]) { @@ -368,6 +189,7 @@ */ char* token_data(char** tok_arr) { int i = 0; + while (tok_arr[i]) ++i; return tok_arr[i + 1]; @@ -380,6 +202,7 @@ */ void token_free(char** tok_arr) { int i = 0; + while (tok_arr[i]) ++i; free(tok_arr[i + 1]); @@ -392,6 +215,7 @@ */ int str_find(char* str, char tok) { int i = 0; + while (*str) { if (*str == tok) return i; @@ -414,6 +238,7 @@ char* str_rem(char* str, char rem) { char* ret = str; char* sstr = NULL; + while (*str) { if (*str == rem) { sstr = str; @@ -521,6 +346,7 @@ * Method derived from SRVX IRC Services: * http://www.srvx.org */ + int multi_wild = 0; /* * Match str against mask @@ -528,7 +354,7 @@ * ? denotes single-character wildcard */ while (*mask) { - int multi_wild = 0; + multi_wild = 0; switch (*mask) { case '*': case '?': @@ -619,6 +445,7 @@ */ char* add_lf(char* str) { char* ostr = str; + while (*str) ++str; --str; @@ -647,11 +474,13 @@ * "fbasd". */ char* str_apply(char* str, char* apply) { + char tswitch = ' '; + char* estr = NULL; + str = (char*)realloc(str, sizeof(char) * (strlen(str) + strlen(apply)) + sizeof(char)); - char* estr = (str + (strlen(str) * sizeof(char))); - char tswitch = ' '; + estr = (str + (strlen(str) * sizeof(char))); while (*apply) { switch (*apply) { @@ -686,16 +515,6 @@ /* - * Convert int to str [0-1000]. - */ -char* dec(int i) { - if ((i < 0) || (i > 1000)) - return 0; - return s_dec[i]; -} - - -/* * Make sure the last character of * the string is a null terminater. */ @@ -710,11 +529,11 @@ * for testing purposes. */ char* rnd_str(int min, int max) { + int i = 0, r = 0; int s = ((rnd_i(time(NULL)) % (max - min)) + min); char* buf = (char*)malloc(sizeof(char) * s + sizeof(char)); --s; - int i = 0, r = 0; for (; i < s; i++) { r = 0; while (r == '\n' || r == '\r' || r == 0 || r == '\\') { @@ -735,10 +554,21 @@ * number table. */ int rnd_i(int seed) { + int s; struct timeval tv; - gettimeofday(&tv, NULL); + #ifdef WIN32 + long y; + #endif - int s = (tv.tv_usec * tv.tv_sec * seed + 1); + #ifdef WIN32 + y = GetTickCount(); + tv.tv_usec = ((y % 1000) * 1000); + tv.tv_sec = (y / 1000); + #elif defined(POSIX) + gettimeofday(&tv, NULL); + #endif + + s = (tv.tv_usec * tv.tv_sec * seed + 1); if (s < 0) s *= -1; return (s); @@ -793,6 +623,7 @@ */ void arr_append(void** arr, void* data) { int i = 0; + while (arr[i]) ++i; arr[i] = data; @@ -814,8 +645,9 @@ * Free an array. */ void arr_free(void** arr, int size, int free_data) { + int i = 0; + if (free_data) { - int i = 0; for (; i < size; i++) { if (arr[i]) free(arr[i]); @@ -832,6 +664,7 @@ int require_params(char* str, int need) { int ws = 1; int i = 0; + while (*str) { if (*str == ' ') ws = 1; @@ -869,3 +702,46 @@ return 1; return 0; } + + +/* + * Convert an integer to a char*. + */ +char* itoa(int i) { + char* str = (char*)malloc(sizeof(char) * 1024); + char* ostr = str; + int neg = 0; + int m, p; + char t; + + memset(str, 0, (sizeof(char) * 1024)); + + if (!i) { + *str = '0'; + return str; + } else if (i < 0) { + neg = 1; + i *= -1; + } + + while (i) { + *str = int_to_char(i % 10); + ++str; + i /= 10; + } + + if (neg) + *str = '-'; + + i = strlen(ostr); + m = (i / 2); /* save cycles, precalculate it */ + p = 0; + while (p < m) { + t = ostr[i - p - 1]; + ostr[i - p - 1] = ostr[p]; + ostr[p] = t; + ++p; + } + + return ostr; +} Index: list.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/list.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- list.c 18 Oct 2004 00:20:50 -0000 1.1.1.1 +++ list.c 9 Jan 2005 01:28:05 -0000 1.2 @@ -19,14 +19,10 @@ * */ -#include "../config.h" - #include <stdio.h> #include <malloc.h> #include <time.h> -#ifdef HAVE_STDLIB_H - #include <stdlib.h> -#endif +#include <stdlib.h> #include "list.h" /* @@ -35,6 +31,7 @@ */ struct linkList* list_create() { struct linkList* lptr = NULL; + lptr = (struct linkList*)malloc(sizeof(struct linkList)); if (lptr != NULL) { lptr->root = NULL; @@ -64,11 +61,14 @@ int list_free(struct linkList* lptr, int free_data, list_func_ptr free_callback) { + struct linkNode* tptr; + struct linkNode* nptr; + if (lptr == NULL) return 0; - struct linkNode* tptr = lptr->root; - struct linkNode* nptr = NULL; + tptr = lptr->root; + nptr = NULL; while (tptr) { nptr = tptr->next; @@ -192,6 +192,7 @@ */ void* list_create_node(void* dptr) { struct linkNode* nptr = NULL; + nptr = (struct linkNode*)malloc(sizeof(struct linkNode)); if (nptr == NULL) /* Out of Memory */ @@ -212,11 +213,13 @@ * Return a Pointer to the Data */ void* list_add_node_front(struct linkList* lptr, void* dptr) { + struct linkNode* nptr; + if (lptr == NULL) return NULL; /* Create the Node */ - struct linkNode* nptr = list_create_node(dptr); + nptr = list_create_node(dptr); /* Link the Node into The List */ if (lptr->root == NULL) { @@ -239,11 +242,13 @@ * Return a Pointer to the Data */ void* list_add_node_end(struct linkList* lptr, void* dptr) { + struct linkNode* nptr; + if (lptr == NULL) return NULL; /* Create the Node */ - struct linkNode* nptr = list_create_node(dptr); + nptr = list_create_node(dptr); /* Link the Node into The List */ if (lptr->root == NULL) { @@ -275,13 +280,15 @@ void* list_add_node_middle(struct linkList* lptr, struct linkNode* lnptr, void* dptr, int position) { + struct linkNode* nptr; + if (lnptr == NULL) return NULL; if ((position != ADD_BEFORE) && (position != ADD_AFTER)) return NULL; /* Create the Node */ - struct linkNode* nptr = list_create_node(dptr); + nptr = list_create_node(dptr); /* Link the Node into The List */ if (lptr->root == NULL) { @@ -329,17 +336,20 @@ */ void list_shuffle(struct linkList* lptr) { struct linkNode* lnptr = lptr->root; - int nodes = 1; + int nodes = 1, node = 0; + struct linkNode** node_arr; + int a = 0, b = 0; + void* dptr = NULL; + while (lnptr) { ++nodes; lnptr = lnptr->next; } - - struct linkNode** node_arr = - (struct linkNode**)malloc(sizeof(struct linkNode*) * nodes); + + node_arr = (struct linkNode**)malloc(sizeof(struct linkNode*) * nodes); lnptr = lptr->root; - int node = 0; + node = 0; for (; node < (nodes - 1); node++) { node_arr[node] = lnptr; lnptr = lnptr->next; @@ -347,8 +357,6 @@ node_arr[node] = NULL; node = ((nodes - 1) * .65 ); - int a = 0, b = 0; - void* dptr = NULL; srand(time(NULL) * node); for (; node > 0; node--) { a = (rand() % (nodes - 1)); Index: Makefile.in =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/Makefile.in,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.in 18 Oct 2004 00:20:50 -0000 1.1.1.1 +++ Makefile.in 9 Jan 2005 01:28:05 -0000 1.2 @@ -121,7 +121,8 @@ pdb_types.c\ binarytree.c\ list.c\ - str.c + str.c\ + hash.c pdb_LDFLAGS = @@ -138,7 +139,7 @@ am_pdb_OBJECTS = pdb.$(OBJEXT) pdb_file.$(OBJEXT) pdb_parse.$(OBJEXT) \ pdb_types.$(OBJEXT) binarytree.$(OBJEXT) list.$(OBJEXT) \ - str.$(OBJEXT) + str.$(OBJEXT) hash.$(OBJEXT) pdb_OBJECTS = $(am_pdb_OBJECTS) pdb_DEPENDENCIES = @@ -148,10 +149,10 @@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ depcomp = $(SHELL) $(top_srcdir)/depcomp -@AMDEP_TRUE@DEP_FILES = $(DEPDIR)/binarytree.Po $(DEPDIR)/list.Po \ -@AMDEP_TRUE@ $(DEPDIR)/pdb.Po $(DEPDIR)/pdb_file.Po \ -@AMDEP_TRUE@ $(DEPDIR)/pdb_parse.Po $(DEPDIR)/pdb_types.Po \ -@AMDEP_TRUE@ $(DEPDIR)/str.Po +@AMDEP_TRUE@DEP_FILES = $(DEPDIR)/binarytree.Po $(DEPDIR)/hash.Po \ +@AMDEP_TRUE@ $(DEPDIR)/list.Po $(DEPDIR)/pdb.Po \ +@AMDEP_TRUE@ $(DEPDIR)/pdb_file.Po $(DEPDIR)/pdb_parse.Po \ +@AMDEP_TRUE@ $(DEPDIR)/pdb_types.Po $(DEPDIR)/str.Po COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \ @@ -218,6 +219,7 @@ -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/binarytree.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/hash.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/list.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/pdb.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/pdb_file.Po@am__quote@ Index: Makefile =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/Makefile,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile 18 Oct 2004 00:20:48 -0000 1.1.1.1 +++ Makefile 9 Jan 2005 01:28:05 -0000 1.2 @@ -121,7 +121,8 @@ pdb_types.c\ binarytree.c\ list.c\ - str.c + str.c\ + hash.c pdb_LDFLAGS = @@ -138,7 +139,7 @@ am_pdb_OBJECTS = pdb.$(OBJEXT) pdb_file.$(OBJEXT) pdb_parse.$(OBJEXT) \ pdb_types.$(OBJEXT) binarytree.$(OBJEXT) list.$(OBJEXT) \ - str.$(OBJEXT) + str.$(OBJEXT) hash.$(OBJEXT) pdb_OBJECTS = $(am_pdb_OBJECTS) pdb_DEPENDENCIES = @@ -148,10 +149,10 @@ LDFLAGS = LIBS = depcomp = $(SHELL) $(top_srcdir)/depcomp -DEP_FILES = $(DEPDIR)/binarytree.Po $(DEPDIR)/list.Po \ - $(DEPDIR)/pdb.Po $(DEPDIR)/pdb_file.Po \ - $(DEPDIR)/pdb_parse.Po $(DEPDIR)/pdb_types.Po \ - $(DEPDIR)/str.Po +DEP_FILES = $(DEPDIR)/binarytree.Po $(DEPDIR)/hash.Po \ + $(DEPDIR)/list.Po $(DEPDIR)/pdb.Po \ + $(DEPDIR)/pdb_file.Po $(DEPDIR)/pdb_parse.Po \ + $(DEPDIR)/pdb_types.Po $(DEPDIR)/str.Po COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \ @@ -218,6 +219,7 @@ -rm -f *.tab.c include $(DEPDIR)/binarytree.Po +include $(DEPDIR)/hash.Po include $(DEPDIR)/list.Po include $(DEPDIR)/pdb.Po include $(DEPDIR)/pdb_file.Po Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pdb.c 26 Oct 2004 20:02:21 -0000 1.4 +++ pdb.c 9 Jan 2005 01:28:05 -0000 1.5 @@ -32,37 +32,56 @@ #include "pdb_types.h" #include "list.h" +#include "hash.h" #include "binarytree.h" 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"); - /*int i = 123; - printf("set: %i\n", pdb_set(dbptr, "", "asdf", &i, INT_NODE_TYPE));*/ + char* a = pdb_query(dbptr, "foo/a"); + printf("[%s]\n", a); - printf("\n--WRITE--\n\n"); - int w = pdb_write(dbptr, "/home/para/foo.tmp"); - printf("write returned: %i\n", w); + printf("\n--DEBUG 2--\n\n"); + + int size = 100; + printf("create: %i\n", + pdb_set(dbptr, "/", "asdf", &size, HASH_NODE_TYPE)); + struct pdb_node_t* nptr = pdb_query_node(dbptr, "asdf"); + printf("node [%x]\n", nptr); + struct hash* h = nptr->data; + printf("hash [%x]\n", h); + printf("size: %i\n", h->size); + + a = strdup("foobar"); + pdb_set(dbptr, "asdf", "foo", a, STRING_NODE_TYPE); + free(a); + + pdb_write(dbptr, "/home/para/test.db2"); + printf("\n--UNLOAD--\n\n"); pdb_unload(dbptr); - return 0; -} + return 0;} /* * Load a file and return a database pointer. */ struct pdb* pdb_load(char* file) { - struct pdb* dbptr = (struct pdb*)malloc(sizeof(struct pdb)); + struct pdb* dbptr; + struct pdb_node_types_t* rntptr; + int line = 1; + FILE* fptr; + + dbptr = (struct pdb*)malloc(sizeof(struct pdb)); if (!dbptr) return NULL; - FILE* fptr = pdb_open_file(file); + fptr = pdb_open_file(file); if (!fptr) return NULL; @@ -73,7 +92,7 @@ dbptr->settings = PDB_DEFAULT_SETTINGS; dbptr->file = (char*)malloc(sizeof(char) * (strlen(file) + 1)); strcpy(dbptr->file, file); - struct pdb_node_types_t* rntptr = pdb_get_type_info(ROOT_NODE_TYPE); + rntptr = pdb_get_type_info(ROOT_NODE_TYPE); if (!rntptr) { ERROR("Root node type is invalid."); free(dbptr->file); @@ -86,7 +105,6 @@ /* * Load database. */ - int line = 1; pdb_standard_load_node(fptr, dbptr->data, NULL, &line); pdb_close_file(fptr); @@ -138,11 +156,14 @@ int pdb_create_link(struct pdb* dbptr, char* path, char* key, struct pdb_node_t* tnptr) { - struct pdb_node_t* nptr = pdb_query_node(dbptr, path); + struct pdb_node_t* nptr; + struct pdb_node_types_t* tiptr; + + nptr = pdb_query_node(dbptr, path); if (!nptr) return 0; - struct pdb_node_types_t* tiptr = pdb_get_type_info(LINK_NODE_TYPE); + tiptr = pdb_get_type_info(LINK_NODE_TYPE); return (tiptr->create_cb(key, nptr, (char**)tnptr) ? 1 : 0); } @@ -151,16 +172,19 @@ * Return a given node from the database. */ struct pdb_node_t* pdb_query_node(struct pdb* dbptr, char* path) { + char** tok_arr; + struct pdb_node_t* nptr; + struct pdb_node_types_t* tiptr; + int i = 0; if (!strcmp(path, "") || !strcmp(path, "/")) return dbptr->data; - char** tok_arr = token_parse(path, PDB_PATH_DELIM, NULL); + tok_arr = token_parse(path, PDB_PATH_DELIM, NULL); - struct pdb_node_t* nptr = dbptr->data; - struct pdb_node_types_t* tiptr = NULL; + nptr = dbptr->data; + tiptr = NULL; - int i = 0; while (tok_arr[i]) { tiptr = pdb_get_type_info(nptr->type); nptr = tiptr->query_cb(nptr, tok_arr[i]); @@ -188,16 +212,21 @@ * Set a node's data. If it does not exist, create it. */ int pdb_set(struct pdb* dbptr, char* path, char* key, void* data, int type) { - struct pdb_node_types_t* tiptr = pdb_get_type_info(type); + struct pdb_node_types_t* tiptr; + struct pdb_node_t* pptr; + struct pdb_node_types_t* ptiptr; + struct pdb_node_t* nptr; + + tiptr = pdb_get_type_info(type); if (!tiptr) return 0; - struct pdb_node_t* pptr = pdb_query_node(dbptr, path); + pptr = pdb_query_node(dbptr, path); if (!pptr) return 0; - struct pdb_node_types_t* ptiptr = pdb_get_type_info(pptr->type); - struct pdb_node_t* nptr = ptiptr->query_cb(pptr, key); + ptiptr = pdb_get_type_info(pptr->type); + nptr = ptiptr->query_cb(pptr, key); if (!nptr) { /* @@ -212,8 +241,8 @@ } if (!tiptr->set_cb) { - fprintf(stderr, "%s:%s():%i: Error: 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); return 0; } @@ -227,11 +256,14 @@ * Delete a node, recursively deleting all child nodes. */ int pdb_del(struct pdb* dbptr, char* path) { - struct pdb_node_t* nptr = pdb_query_node(dbptr, path); + struct pdb_node_t* nptr; + struct pdb_node_types_t* tiptr; + + nptr = pdb_query_node(dbptr, path); if (!nptr) return 0; - struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); + tiptr = pdb_get_type_info(nptr->type); if (!tiptr->free_cb) { fprintf(stderr, "%s:%s():%i: Error: Unable to free node %s; type %i \ @@ -249,20 +281,28 @@ * The resulting string is allocated and must be freed. */ char* pdb_trace(struct pdb_node_t* nptr) { - struct linkList* lptr = list_create(); + struct linkList* lptr; + struct linkNode* lnptr; + char* sbuf; + char* buf; + int buf_size; + int used; + char* str; + + lptr = list_create(); while (nptr) { list_add_node_front(lptr, nptr->id); nptr = nptr->parent; } - struct linkNode* lnptr = lptr->root; - char* sbuf = (char*)malloc(BLOCK_SIZE); - char* buf = sbuf; - int buf_size = BLOCK_SIZE; - int used = 1; + lnptr = lptr->root; + sbuf = (char*)malloc(BLOCK_SIZE); + buf = sbuf; + buf_size = BLOCK_SIZE; + used = 1; memset(sbuf, 0, BLOCK_SIZE); - char* str = NULL; + str = NULL; while (lnptr) { str = lnptr->data; @@ -298,21 +338,25 @@ * Write a loaded database structure to disk. */ int pdb_write(struct pdb* dbptr, char* file) { + FILE* fptr; + struct pdb_node_t* nptr; + int ret; + if (!dbptr) return 0; if (!dbptr->data) return 0; - FILE* fptr = fopen(file, "w"); + fptr = fopen(file, "w"); if (!fptr) { fprintf(stderr, "%s:%s():%i: Error: Unable to open file \"%s\" for \ writing.\n", __FILE__, __FUNCTION__, __LINE__, file); return 0; } - struct pdb_node_t* nptr = dbptr->data; + nptr = dbptr->data; - int ret = pdb_standard_write_node(dbptr, fptr, nptr, -1); + ret = pdb_standard_write_node(dbptr, fptr, nptr, -1); fclose(fptr); return ret; } Index: pdb_parse.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_parse.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pdb_parse.c 26 Oct 2004 03:41:08 -0000 1.3 +++ pdb_parse.c 9 Jan 2005 01:28:05 -0000 1.4 @@ -59,19 +59,19 @@ * If EOF or critical error, return NULL. */ char* pdb_get_token(FILE* fptr, int* type, int* line) { - //printf("pdb_get_token(%x, %s, %i)\n", fptr, ttype(*type), *line); int buf_size = BLOCK_SIZE; int used = 1; - char* sbuf = (char*)malloc(sizeof(char) * buf_size); - memset(sbuf, 0, sizeof(char) * buf_size); - char* buf = sbuf; - + char* sbuf; + char* buf; int ws_end = 0; - char byte; int quotes = 0; /* total amount of quotes went through */ struct pdb_node_types_t* tptr = NULL; + sbuf = (char*)malloc(sizeof(char) * buf_size); + memset(sbuf, 0, sizeof(char) * buf_size); + buf = sbuf; + while (!feof(fptr)) { byte = fgetc(fptr); @@ -298,11 +298,14 @@ * remove elements with only whitespaces. */ char** pdb_token_parse(char* str) { - char** tok_arr = token_parse(str, '\"', NULL); - + char** tok_arr; int i = 0; + int s = 0; + + tok_arr = token_parse(str, '\"', NULL); + while (tok_arr[i]) { - int s = 0; + s = 0; while (tok_arr[i][s]) { if (!is_whitespace(tok_arr[i][s])) { s = -1; Index: binarytree.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/binarytree.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- binarytree.c 18 Oct 2004 00:20:48 -0000 1.1.1.1 +++ binarytree.c 9 Jan 2005 01:28:05 -0000 1.2 @@ -19,7 +19,6 @@ * */ - /* * IMPORTANT: * Data added should be allocated prior to adding @@ -28,8 +27,6 @@ * * All keys are character arrays. */ - -#include "../config.h" #include <stdlib.h> #include <stdio.h> @@ -45,11 +42,12 @@ struct binaryTree* tree_create() { struct binaryTree* tptr = (struct binaryTree*) malloc(sizeof(struct binaryTree)); + if (tptr == NULL) { /* Out of Memory */ #ifdef TREE_DEBUG - printf("binarytree.c: tree_create(): Failed creating tree; \ -out of memory.\n"); + printf("binarytree.c: tree_create(): Failed creating tree; " + "out of memory.\n"); #endif return NULL; } @@ -135,11 +133,14 @@ * NO _DATA_ ALLOCATION WILL BE DONE */ int tree_add_node(struct binaryTree* tptr, char* key, void* data) { + struct treeNode* pptr; + struct treeNode* nptr; + if (tptr == NULL) return 0; - struct treeNode* pptr = tptr->root; - struct treeNode* nptr = NULL; + pptr = tptr->root; + nptr = NULL; /* locate parent node */ while (pptr != NULL) { @@ -161,9 +162,9 @@ if (tptr->root == NULL) { /* out of memory */ #ifdef TREE_DEBUG - printf("binarytree.c: tree_add_node(): \ - Failed allocating root node; \ - out of memory.\n"); + printf("binarytree.c: tree_add_node(): " + "Failed allocating root node; " + "out of memory.\n"); #endif return 0; } @@ -189,9 +190,9 @@ if (pptr->right == NULL) { /* out of memory */ #ifdef TREE_DEBUG - printf("binarytree.c: tree_create(): \ - Failed allocating right child; \ - out of memory.\n"); + printf("binarytree.c: tree_create(): " + "Failed allocating right child; " + "out of memory.\n"); #endif return 0; } @@ -207,9 +208,9 @@ if (nptr->key == NULL) { /* out of memory */ #ifdef TREE_DEBUG - printf("binarytree.c: tree_create(): \ - Failed allocating node key; \ - out of memory.\n"); + printf("binarytree.c: tree_create(): " + "Failed allocating node key; " + "out of memory.\n"); #endif exit(1); } @@ -224,10 +225,12 @@ * and return the data at that node. */ void* tree_get_node(struct binaryTree* tptr, char* key) { + struct treeNode* nptr; + if (tptr == NULL) return 0; - struct treeNode* nptr = tptr->root; + nptr = tptr->root; /* locate parent node */ while (nptr != NULL) { @@ -250,10 +253,14 @@ * nodes data. */ void* tree_delink_node(struct binaryTree* tptr, char* key) { + struct treeNode* nptr; + struct treeNode* rptr; + void* dptr; + if (tptr == NULL) return 0; - struct treeNode* nptr = tptr->root; + nptr = tptr->root; /* locate node */ while (nptr != NULL) { @@ -268,7 +275,7 @@ /* node not found */ return NULL; - void* dptr = nptr->data; + dptr = nptr->data; /* delink node */ if (nptr->left == NULL) { @@ -316,14 +323,14 @@ } else tptr->root = nptr->right; /* follow right childs left children to NULL */ - struct treeNode* rptr = nptr->right; + rptr = nptr->right; while (rptr->left != NULL) rptr = rptr->left; /* put left child here */ rptr->left = nptr->left; } else { /* follow right childs left children to NULL */ - struct treeNode* rptr = nptr->right->left; + rptr = nptr->right->left; while (rptr->left != NULL) rptr = rptr->left; if (nptr->parent != NULL) { |
From: Michael L. <par...@us...> - 2005-01-09 02:03:50
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6791/src Modified Files: binarytree.c pdb.c Log Message: Can set binary tree key compare callback. Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pdb.c 9 Jan 2005 01:28:05 -0000 1.5 +++ pdb.c 9 Jan 2005 02:03:24 -0000 1.6 @@ -36,36 +36,40 @@ #include "binarytree.h" int main(int argc, char** argv) { - printf(PDB_COMPILE_INFO); + 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("\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"); char* a = pdb_query(dbptr, "foo/a"); printf("[%s]\n", a); - printf("\n--DEBUG 2--\n\n"); - - int size = 100; - printf("create: %i\n", - pdb_set(dbptr, "/", "asdf", &size, HASH_NODE_TYPE)); - - struct pdb_node_t* nptr = pdb_query_node(dbptr, "asdf"); - printf("node [%x]\n", nptr); - struct hash* h = nptr->data; - printf("hash [%x]\n", h); - printf("size: %i\n", h->size); - - a = strdup("foobar"); - pdb_set(dbptr, "asdf", "foo", a, STRING_NODE_TYPE); - free(a); - - pdb_write(dbptr, "/home/para/test.db2"); + //pdb_write(dbptr, "/home/para/test.db2"); printf("\n--UNLOAD--\n\n"); - pdb_unload(dbptr); - return 0;} + pdb_unload(dbptr);*/ + return 0; +} /* Index: binarytree.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/binarytree.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- binarytree.c 9 Jan 2005 01:28:05 -0000 1.2 +++ binarytree.c 9 Jan 2005 02:03:24 -0000 1.3 @@ -32,6 +32,7 @@ #include <stdio.h> #include <string.h> #include <malloc.h> +#include <ctype.h> #include "list.h" #include "binarytree.h" @@ -52,6 +53,8 @@ return NULL; } tptr->root = NULL; + tptr->flags = TREE_FLAG_DEFAULT; + tptr->_tree_str_cmp = (void*)&strcmp; return tptr; } @@ -144,11 +147,11 @@ /* locate parent node */ while (pptr != NULL) { - if (strcmp(key, pptr->key) < 0) { + if (tptr->_tree_str_cmp(key, pptr->key) < 0) { if (pptr->left == NULL) break; pptr = pptr->left; - } else if (strcmp(key, pptr->key) > 0) { + } else if (tptr->_tree_str_cmp(key, pptr->key) > 0) { if (pptr->right == NULL) break; pptr = pptr->right; @@ -170,7 +173,7 @@ } tptr->root->parent = NULL; nptr = tptr->root; - } else if (strcmp(key, pptr->key) < 0) { + } else if (tptr->_tree_str_cmp(key, pptr->key) < 0) { /* left child */ pptr->left = (struct treeNode*)malloc(sizeof(struct treeNode)); if (pptr->left == NULL) { @@ -234,9 +237,9 @@ /* locate parent node */ while (nptr != NULL) { - if (strcmp(key, nptr->key) < 0) { + if (tptr->_tree_str_cmp(key, nptr->key) < 0) { nptr = nptr->left; - } else if (strcmp(key, nptr->key) > 0) { + } else if (tptr->_tree_str_cmp(key, nptr->key) > 0) { nptr = nptr->right; } else return nptr->data; @@ -264,9 +267,9 @@ /* locate node */ while (nptr != NULL) { - if (strcmp(key, nptr->key) < 0) { + if (tptr->_tree_str_cmp(key, nptr->key) < 0) { nptr = nptr->left; - } else if (strcmp(key, nptr->key) > 0) { + } else if (tptr->_tree_str_cmp(key, nptr->key) > 0) { nptr = nptr->right; } else break; @@ -416,3 +419,72 @@ list_add_node_end(lptr, nptr->data); } + + +/* + * Enable tree setting(s). + * settings are OR'ed togther. + */ +void tree_enable(struct binaryTree* tptr, int flags) { + tptr->flags |= flags; + + tree_set_strcmp(tptr, NULL); +} + + +/* + * Disable tree setting(s). + * settings are OR'ed togther. + */ +void tree_disable(struct binaryTree* tptr, int flags) { + tptr->flags &= ~flags; + + tree_set_strcmp(tptr, NULL); +} + + +/* + * Set what string compare function to use. + * If _str_cmp is NULL, set dependent on tree flags. + */ +void tree_set_strcmp(struct binaryTree* tptr, tree_str_cmp_cb _strcmp) { + if (_strcmp) { + tptr->_tree_str_cmp = _strcmp; + return; + } + + /* + * Set dependent on tree flags. + */ + if ((tptr->flags & TREE_FLAG_NO_CASE) == TREE_FLAG_NO_CASE) + tptr->_tree_str_cmp = (void*)&_tree_lower_strcmp; + else + tptr->_tree_str_cmp = (void*)&strcmp; +} + +/* + * Case insensitive string compare. + */ +int _tree_lower_strcmp(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; + + if (tolower(*s1) > tolower(*s2)) + return 1; + else if (tolower(*s1) < tolower(*s2)) + return -1; + + ++s1; + ++s2; + } + + return (*s2 ? -1 : 0); +} |
From: Michael L. <par...@us...> - 2005-01-09 02:03:49
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6791/include Modified Files: binarytree.h Log Message: Can set binary tree key compare callback. Index: binarytree.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/binarytree.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- binarytree.h 18 Oct 2004 00:20:50 -0000 1.1.1.1 +++ binarytree.h 9 Jan 2005 02:03:24 -0000 1.2 @@ -31,9 +31,18 @@ #endif typedef void (*tree_func_ptr)(void* dptr); - -/* Individual Node - Within The Tree */ +typedef int (*tree_str_cmp_cb)(char* s1, char* s2); + +/* + * Tree flags. + */ +#define TREE_FLAG_DEFAULT 0 +#define TREE_FLAG_NO_CASE 1 + +/* + * Individual Node + * Within The Tree + */ struct treeNode { struct treeNode* right; struct treeNode* left; @@ -42,9 +51,13 @@ void* data; }; -/* Tree Structure */ +/* + * Tree Structure + */ struct binaryTree { struct treeNode* root; + int flags; + tree_str_cmp_cb _tree_str_cmp; }; struct binaryTree* tree_create(); @@ -64,6 +77,12 @@ void tree_to_list(struct binaryTree* tptr, struct linkList* lptr); void tree_node_to_list(struct treeNode* nptr, struct linkList* lptr); +void tree_enable(struct binaryTree* tptr, int flags); +void tree_disable(struct binaryTree* tptr, int flags); + +void tree_set_strcmp(struct binaryTree* tptr, tree_str_cmp_cb _strcmp); +int _tree_lower_strcmp(char* s1, char* s2); + #ifdef __cplusplus } #endif |
From: Michael L. <par...@us...> - 2005-01-09 02:03:32
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6791 Modified Files: pdb.pws Log Message: Can set binary tree key compare callback. Index: pdb.pws =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.pws,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pdb.pws 9 Jan 2005 01:28:04 -0000 1.5 +++ pdb.pws 9 Jan 2005 02:03:23 -0000 1.6 @@ -1,8 +1,8 @@ [filenumbers] -0=711 -1=72 -2=63 +0=83 +1=443 +2=84 3=153 4=906 5=60 @@ -29,12 +29,9 @@ clean before build=false [filelist] -0=/home/para/Projects/pdb/src/str.c -1=/home/para/Projects/pdb/src/pdb_parse.c -2=/home/para/Projects/pdb/src/hash.c -3=/home/para/Projects/pdb/include/pdb_types.h -4=/home/para/Projects/pdb/src/pdb_types.c -5=/home/para/Projects/pdb/src/pdb.c +0=/home/para/Projects/pdb/include/binarytree.h +1=/home/para/Projects/pdb/src/binarytree.c +2=/home/para/Projects/pdb/src/pdb.c [Project Tree] 0=0 |
From: Michael L. <par...@us...> - 2005-01-09 01:28:14
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31824/include Modified Files: Makefile Makefile.am Makefile.in pdb_types.h str.h Log Message: Completed hash type support -- loadable from function calls and disk. Index: Makefile.in =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/Makefile.in,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.in 18 Oct 2004 00:20:51 -0000 1.1.1.1 +++ Makefile.in 9 Jan 2005 01:28:05 -0000 1.2 @@ -107,7 +107,8 @@ pdb_types.h\ binarytree.h\ list.h\ - str.h + str.h\ + hash.h EXTRA_DIST = $(pdb_include_DATA) Index: Makefile.am =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.am 18 Oct 2004 00:20:51 -0000 1.1.1.1 +++ Makefile.am 9 Jan 2005 01:28:05 -0000 1.2 @@ -13,6 +13,7 @@ pdb_types.h\ binarytree.h\ list.h\ - str.h + str.h\ + hash.h EXTRA_DIST = $(pdb_include_DATA) Index: Makefile =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/Makefile,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile 18 Oct 2004 00:20:51 -0000 1.1.1.1 +++ Makefile 9 Jan 2005 01:28:05 -0000 1.2 @@ -107,7 +107,8 @@ pdb_types.h\ binarytree.h\ list.h\ - str.h + str.h\ + hash.h EXTRA_DIST = $(pdb_include_DATA) Index: pdb_types.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb_types.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pdb_types.h 26 Oct 2004 20:02:19 -0000 1.4 +++ pdb_types.h 9 Jan 2005 01:28:05 -0000 1.5 @@ -25,16 +25,20 @@ /* * PDB types. */ -#define NO_NODE_TYPE 0 -#define TREE_NODE_TYPE 1 -#define LIST_NODE_TYPE 2 -#define STRING_NODE_TYPE 4 -#define INT_NODE_TYPE 8 -#define ABSTRACT_NODE_TYPE 16 -#define LINK_NODE_TYPE 32 +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 +}; /* - * Next bitmask after the highest one above. + * This needs to be the bit which is higher + * than any bit used in the above enumeration. */ #define BLOCK_CLOSE 64 @@ -140,6 +144,23 @@ struct pdb_node_t* nptr, int tabs); /* + * Hash table + */ +void* pdb_create_hash_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr); +int pdb_load_hash_node_cb(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, + int* line); +void pdb_set_hash_node_cb(struct pdb_node_t* nptr, void* data); +int pdb_add_hash_node_child_cb(struct pdb_node_t* parent, char* id, + struct pdb_node_t* child); +int pdb_free_hash_node_cb(struct pdb_node_t* nptr); +struct pdb_node_t* pdb_query_hash_node_cb(struct pdb_node_t* nptr, char* id); +void pdb_del_child_hash_node_cb(struct pdb_node_t* pptr, + struct pdb_node_t* nptr); +int pdb_write_hash_node_cb(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs); + +/* * String */ void* pdb_create_string_node_cb(char* id, struct pdb_node_t* parent, Index: str.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/str.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- str.h 18 Oct 2004 00:20:51 -0000 1.1.1.1 +++ str.h 9 Jan 2005 01:28:05 -0000 1.2 @@ -23,6 +23,8 @@ #ifndef _STR_H #define _STR_H +#define int_to_char(x) ((char)(x + 48)) + #ifdef __cplusplus extern "C" { @@ -51,7 +53,6 @@ char* str_apply(char* str, char* apply); -char* dec(int i); void chk_str(char* str); char* rnd_str(int min, int max); int rnd_i(int seed); @@ -68,6 +69,8 @@ int str_starts_with(char* str, char* tok); +char* itoa(int i); + #ifdef __cplusplus } #endif |
From: Michael L. <par...@us...> - 2005-01-09 01:28:14
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31824 Modified Files: config.log pdb.prj pdb.pws Log Message: Completed hash type support -- loadable from function calls and disk. Index: config.log =================================================================== RCS file: /cvsroot/pdatabase/pdb/config.log,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- config.log 26 Oct 2004 03:41:07 -0000 1.3 +++ config.log 9 Jan 2005 01:28:04 -0000 1.4 @@ -988,3 +988,39 @@ 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 = include/Makefile + CONFIG_HEADERS = + CONFIG_LINKS = + CONFIG_COMMANDS = + $ ./config.status + +on turtle + +config.status:718: creating include/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 turtle + +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.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pdb.pws 26 Oct 2004 20:02:08 -0000 1.4 +++ pdb.pws 9 Jan 2005 01:28:04 -0000 1.5 @@ -1,11 +1,11 @@ [filenumbers] -0=39 -1=569 -2=25 -3=26 -4=95 -5=41 +0=711 +1=72 +2=63 +3=153 +4=906 +5=60 6=133 [filemarkers] @@ -29,11 +29,11 @@ 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_parse.h -3=/home/para/Projects/pdb/src/pdb_parse.c -4=/home/para/Projects/pdb/include/pdb.h +0=/home/para/Projects/pdb/src/str.c +1=/home/para/Projects/pdb/src/pdb_parse.c +2=/home/para/Projects/pdb/src/hash.c +3=/home/para/Projects/pdb/include/pdb_types.h +4=/home/para/Projects/pdb/src/pdb_types.c 5=/home/para/Projects/pdb/src/pdb.c [Project Tree] Index: pdb.prj =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.prj,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- pdb.prj 18 Oct 2004 00:20:48 -0000 1.1.1.1 +++ pdb.prj 9 Jan 2005 01:28:04 -0000 1.2 @@ -73,7 +73,8 @@ pdb_types.h\ binarytree.h\ list.h\ - str.h + str.h\ + hash.h module.source.name=src module.source.type= @@ -84,7 +85,8 @@ pdb_types.c\ binarytree.c\ list.c\ - str.c + str.c\ + hash.c module.pixmap.name=pixmaps module.pixmap.type= |
From: Michael L. <par...@us...> - 2004-10-26 20:03:27
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19148/include Modified Files: pdb.h pdb_types.h Log Message: Writing to disk, free callback overrides. Index: pdb.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pdb.h 26 Oct 2004 03:41:08 -0000 1.3 +++ pdb.h 26 Oct 2004 20:02:19 -0000 1.4 @@ -53,12 +53,32 @@ * pdb setting value bitmasks. */ #define PDB_CASE_INSENSITIVE 1 +#define PDB_WRITE_SHUFFLE 2 +#define PDB_WRITE_NODE_FIRST 4 /* * Default pdb settings. */ -#define PDB_DEFAULT_SETTINGS 0 +#define PDB_DEFAULT_SETTINGS (PDB_WRITE_SHUFFLE | PDB_WRITE_NODE_FIRST) + + +/* + * 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. + */ +#define PDB_WRITE_NODE_FIRST_ID "finop" + + +/* + * 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)(struct pdb_node_t* nptr); /* @@ -69,6 +89,7 @@ char* id; void* data; struct pdb_node_t* parent; + custom_free_cb_t custom_free_cb; }; @@ -106,6 +127,10 @@ char* pdb_trace(struct pdb_node_t* nptr); +int pdb_write(struct pdb* dbptr, char* file); + +void pdb_set_free_method(struct pdb_node_t* nptr, void* free_cb); + #ifdef __cplusplus } #endif Index: pdb_types.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb_types.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pdb_types.h 26 Oct 2004 03:41:08 -0000 1.3 +++ pdb_types.h 26 Oct 2004 20:02:19 -0000 1.4 @@ -29,12 +29,14 @@ #define TREE_NODE_TYPE 1 #define LIST_NODE_TYPE 2 #define STRING_NODE_TYPE 4 -#define LINK_NODE_TYPE 8 +#define INT_NODE_TYPE 8 +#define ABSTRACT_NODE_TYPE 16 +#define LINK_NODE_TYPE 32 /* * Next bitmask after the highest one above. */ -#define BLOCK_CLOSE 16 +#define BLOCK_CLOSE 64 /* * The type of token that pdb should consider @@ -62,7 +64,9 @@ typedef struct pdb_node_t* (*query_cb_t)(struct pdb_node_t* nptr, char* id); typedef void (*del_child_cb_t)(struct pdb_node_t* pptr, struct pdb_node_t* nptr); - +typedef int (*write_cb_t)(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs); + /* * Information for a single node type. @@ -78,6 +82,7 @@ free_cb_t free_cb; query_cb_t query_cb; del_child_cb_t del_child_cb; + write_cb_t write_cb; }; @@ -99,6 +104,8 @@ int pdb_standard_load_node(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, int* line); int pdb_free_node(struct pdb_node_t* nptr); +int pdb_standard_write_node(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs); /* * Binary tree @@ -113,6 +120,8 @@ struct pdb_node_t* pdb_query_tree_node_cb(struct pdb_node_t* nptr, char* id); void pdb_del_child_tree_node_cb(struct pdb_node_t* pptr, struct pdb_node_t* nptr); +int pdb_write_tree_node_cb(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs); /* * Link list @@ -127,6 +136,8 @@ struct pdb_node_t* pdb_query_list_node_cb(struct pdb_node_t* nptr, char* id); void pdb_del_child_list_node_cb(struct pdb_node_t* pptr, struct pdb_node_t* nptr); +int pdb_write_list_node_cb(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs); /* * String @@ -135,6 +146,24 @@ char** tok_arr); void pdb_set_string_node_cb(struct pdb_node_t* nptr, void* data); int pdb_free_string_node_cb(struct pdb_node_t* nptr); +int pdb_write_string_node_cb(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs); + +/* + * Integer + */ +void* pdb_create_int_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr); +void pdb_set_int_node_cb(struct pdb_node_t* nptr, void* data); +int pdb_free_int_node_cb(struct pdb_node_t* nptr); + +/* + * Abstract + */ +void* pdb_create_abstract_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr); +void pdb_set_abstract_node_cb(struct pdb_node_t* nptr, void* data); +int pdb_free_abstract_node_cb(struct pdb_node_t* nptr); /* * Link |
From: Michael L. <par...@us...> - 2004-10-26 20:03:26
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19148/src Modified Files: pdb.c pdb_types.c Log Message: Writing to disk, free callback overrides. Index: pdb_types.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_types.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pdb_types.c 26 Oct 2004 03:41:08 -0000 1.3 +++ pdb_types.c 26 Oct 2004 20:02:24 -0000 1.4 @@ -54,7 +54,8 @@ pdb_add_tree_node_child_cb, pdb_free_tree_node_cb, pdb_query_tree_node_cb, - pdb_del_child_tree_node_cb + pdb_del_child_tree_node_cb, + pdb_write_tree_node_cb }, { /* Link List */ @@ -67,7 +68,8 @@ pdb_add_list_node_child_cb, pdb_free_list_node_cb, pdb_query_list_node_cb, - pdb_del_child_list_node_cb + pdb_del_child_list_node_cb, + pdb_write_list_node_cb }, { /* String */ @@ -80,7 +82,36 @@ NULL, /* no child nodes supported */ pdb_free_string_node_cb, NULL, - NULL /* string has no child */ + NULL, /* string has no child */ + pdb_write_string_node_cb + }, + { + /* Integer type */ + INT_NODE_TYPE, + NULL, /* no loading from disk */ + NULL, /* no loading from disk */ + pdb_create_int_node_cb, + NULL, + pdb_set_int_node_cb, + NULL, /* integers have no children */ + pdb_free_int_node_cb, + NULL, + NULL, + NULL /* not written to disk */ + }, + { + /* Abstract type */ + ABSTRACT_NODE_TYPE, + NULL, /* no loading from disk */ + NULL, /* no loading from disk */ + pdb_create_abstract_node_cb, + NULL, + pdb_set_abstract_node_cb, + NULL, /* abstracts have no children */ + pdb_free_abstract_node_cb, + NULL, + NULL, + NULL /* not written to disk */ }, { /* @@ -89,21 +120,22 @@ * the last type in the array. */ LINK_NODE_TYPE, - NULL, - NULL, + NULL, /* no loading from disk */ + NULL, /* no loading from disk */ pdb_create_link_node_cb, - NULL, /* links cannot be "set" */ - NULL, NULL, + NULL, /* links cannot be "set" */ + NULL, /* links have no real children */ pdb_free_link_node_cb, pdb_query_link_node_cb, - NULL /* children are ignored on free */ + NULL, /* children are ignored on free */ + NULL /* links not written to disk */ }, { /* Terminating Entry */ NO_NODE_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL + NULL, NULL, NULL } }; @@ -176,6 +208,7 @@ nptr->data = NULL; nptr->parent = parent; nptr->type = type; + nptr->custom_free_cb = NULL; if (id) { nptr->id = (char*)malloc(sizeof(char) * (strlen(id) + 1)); @@ -284,8 +317,16 @@ */ int pdb_free_node_cb(void* dptr) { struct pdb_node_t* nptr = dptr; - struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); - int ret = tiptr->free_cb(nptr); + int ret = 0; + if (nptr->custom_free_cb) { + /* + * Use the custom free callback rather than the default. + */ + ret = nptr->custom_free_cb(nptr); + } else { + struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); + ret = tiptr->free_cb(nptr); + } if (nptr->id) free(nptr->id); free(nptr); @@ -309,8 +350,17 @@ /* * Free data container. */ - struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); - int ret = tiptr->free_cb(nptr); + int ret = 0; + if (nptr->custom_free_cb) { + /* + * Use the custom free callback rather than the default. + */ + ret = nptr->custom_free_cb(nptr); + } else { + struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); + ret = tiptr->free_cb(nptr); + } + /* * Free node. @@ -343,6 +393,69 @@ } +/* + * Write a given node to disk. + * + * Types without an open_token will have their write callbacks called + * without a need line prepended. + * Types without a close_token will not have the close_token and new line + * appended. + */ +int pdb_standard_write_node(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs) { + + struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); + 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", + __FILE__, __FUNCTION__, __LINE__, trace, nptr->type); + free(trace); + return 1; + } + + /* + * Write tabs -- if any (if tabs != -1 [root]). + */ + int i = 0; + if (tabs != -1) + for (; i < tabs; i++) + fputc('\t', fptr); + + /* + * Write key in double quotes followed by a tree opening token. + */ + if (tabs != -1) { + fputc('\"', fptr); + if (nptr->id) + fputs(nptr->id, fptr); + fputs("\" ", fptr); + if (tiptr->open_token) { + fputs(tiptr->open_token, fptr); + fputc('\n', fptr); + } + } + + /* + * Write node to disk. + */ + int ret = tiptr->write_cb(dbptr, fptr, nptr, tabs + 1); + + /* + * Write tabs and tree closing token (if tabs != -1 [root]). + */ + if ((tabs != -1) && (tiptr->close_token)) { + i = 0; + for (; i < tabs; i++) + fputc('\t', fptr); + fputs(tiptr->close_token, fptr); + fputc('\n', fptr); + } + + return ret; +} + + /************************************************************* ****************** ****************** ****************** Binary Tree Node Type ****************** @@ -424,6 +537,67 @@ } +/* + * Write a binary tree node to disk. + */ +int pdb_write_tree_node_cb(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs) { + + /* + * Create a list from the tree so we can iterate through it. + */ + struct binaryTree* tptr = nptr->data; + struct linkList* lptr = list_create(); + tree_to_list(tptr, lptr); + struct linkNode* lnptr = lptr->root; + + /* + * Shuffle tree (if set). + */ + if (pdb_is_set(dbptr, PDB_WRITE_SHUFFLE)) + list_shuffle(lptr); + + /* + * Set PDB_WRITE_NODE_FIRST_ID as the first in the list + * if PDB_WRITE_NODE_FIRST is set. + * Only if root node. + */ + if (!tabs) { + if (pdb_is_set(dbptr, PDB_WRITE_NODE_FIRST)) { + while (lnptr) { + nptr = lnptr->data; + if (!strcmp(nptr->id, PDB_WRITE_NODE_FIRST_ID)) { + list_free_node(lptr, lnptr, 0, NULL); + list_add_node_front(lptr, nptr); + break; + } + lnptr = lnptr->next; + } + } + } + + /* + * Write all children to disk. + */ + lnptr = lptr->root; + while (lnptr) { + nptr = lnptr->data; + if (!pdb_standard_write_node(dbptr, fptr, nptr, tabs)) { + list_free(lptr, 0, NULL); + return 0; + } + lnptr = lnptr->next; + } + + /* + * Free temp list (but not data). + */ + list_free(lptr, 0, NULL); + + return 1; +} + + /************************************************************* ****************** ****************** ****************** List Node Type ****************** @@ -520,6 +694,52 @@ } +/* + * Write a link list node to disk. + */ +int pdb_write_list_node_cb(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs) { + + /* + * Create a list from the tree so we can iterate through it. + */ + struct linkList* lptr = nptr->data; + struct linkNode* lnptr = lptr->root; + + /* + * Set PDB_WRITE_NODE_FIRST_ID as the first in the list + * if PDB_WRITE_NODE_FIRST is set. + * Only if root node. + */ + if (!tabs) { + if (pdb_is_set(dbptr, PDB_WRITE_NODE_FIRST)) { + while (lnptr) { + nptr = lnptr->data; + if (!strcmp(nptr->id, PDB_WRITE_NODE_FIRST_ID)) { + list_delink_node(lptr, lnptr); + list_add_node_front(lptr, nptr); + break; + } + lnptr = lnptr->next; + } + } + } + + /* + * Write all children to disk. + */ + lnptr = lptr->root; + while (lnptr) { + nptr = lnptr->data; + if (!pdb_standard_write_node(dbptr, fptr, nptr, tabs)) + return 0; + lnptr = lnptr->next; + } + + return 1; +} + + /************************************************************* ****************** ****************** ****************** String Node Type ****************** @@ -539,11 +759,14 @@ if (!nptr) return NULL; + nptr->data = NULL; + if (tok_arr) { - nptr->data = (char*)malloc(sizeof(char) * (strlen(tok_arr[1]) + 1)); - strcpy((char*)nptr->data, tok_arr[1]); - } else - nptr->data = NULL; + if (tok_arr[1]) { + nptr->data = (char*)malloc(sizeof(char) * (strlen(tok_arr[1]) + 1)); + strcpy((char*)nptr->data, tok_arr[1]); + } + } return nptr; } @@ -569,7 +792,7 @@ /* - * Free a tree node. + * Free a string node. */ int pdb_free_string_node_cb(struct pdb_node_t* nptr) { free(nptr->data); @@ -577,6 +800,125 @@ } +/* + * Write a string node to disk. + */ +int pdb_write_string_node_cb(struct pdb* dbptr, FILE* fptr, + struct pdb_node_t* nptr, int tabs) { + + /* + * Write data in double quotes followed by a token terminator and new line. + * If there no data, write token terminator and a new line. + */ + tabs = 0; /* reuse as flag */ + if (nptr->data) { + if (*(char*)(nptr->data)) { + fputc('\"', fptr); + fputs((const char*)nptr->data, fptr); + fputc('\"', fptr); + tabs = 1; + } + } + if (!tabs) + fseek(fptr, -1, SEEK_CUR); /* replace space with token terminator */ + fputc(PDB_TOKEN_TERM, fptr); + fputc('\n', fptr); + + return 1; +} + + +/************************************************************* + ****************** ****************** + ****************** Integer Node Type ****************** + ****************** ****************** + *************************************************************/ + + +/* + * Callback for creating a new integer node. + * If tok_arr is not NULL, tok_arr is just an int* casted to a char**. + */ +void* pdb_create_int_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr) { + + struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, + INT_NODE_TYPE); + if (!nptr) + return NULL; + + nptr->data = (void*)malloc(sizeof(int)); + if (tok_arr) + *(int*)(nptr->data) = *(int*)tok_arr; + else + *(int*)(nptr->data) = 0; + + return nptr; +} + + +/* + * (Re)set the data at an integer node. + */ +void pdb_set_int_node_cb(struct pdb_node_t* nptr, void* data) { + *(int*)(nptr->data) = *(int*)data; +} + + +/* + * Free an integer node. + */ +int pdb_free_int_node_cb(struct pdb_node_t* nptr) { + free(nptr->data); + return 1; +} + + +/************************************************************* + ****************** ****************** + ****************** Abstract Node Type ****************** + ****************** ****************** + *************************************************************/ + + +/* + * Callback for creating a new abstract node. + * If tok_arr is not NULL, tok_arr is just a void* casted to a char**. + */ +void* pdb_create_abstract_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr) { + + struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, + ABSTRACT_NODE_TYPE); + if (!nptr) + return NULL; + + nptr->data = (void*)tok_arr; + + return nptr; +} + + +/* + * (Re)set the data at an abstract node. + */ +void pdb_set_abstract_node_cb(struct pdb_node_t* nptr, void* data) { + nptr->data = data; +} + + +/* + * Free an abstract node. + */ +int pdb_free_abstract_node_cb(struct pdb_node_t* nptr) { + /* + * TODO -- how do we free this? + */ + //free(nptr->data); + return 1; +} + + /************************************************************* ****************** ****************** ****************** Link Node Type ****************** Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pdb.c 26 Oct 2004 03:41:08 -0000 1.3 +++ pdb.c 26 Oct 2004 20:02:21 -0000 1.4 @@ -41,15 +41,12 @@ printf("\n--DEBUG--\n\n"); - struct pdb_node_t* nptr = pdb_query_node(dbptr, "finop/foo/foo2"); - if (nptr) { - printf("[%s] [%s]\n", nptr->id, (char*)nptr->data); + /*int i = 123; + printf("set: %i\n", pdb_set(dbptr, "", "asdf", &i, INT_NODE_TYPE));*/ - char* loc = pdb_trace(nptr); - printf("trace [%s]\n", loc); - free(loc); - } else - printf("returned NULL\n"); + printf("\n--WRITE--\n\n"); + int w = pdb_write(dbptr, "/home/para/foo.tmp"); + printf("write returned: %i\n", w); printf("\n--UNLOAD--\n\n"); pdb_unload(dbptr); @@ -165,7 +162,6 @@ int i = 0; while (tok_arr[i]) { - printf("[%s]\n", nptr->id); tiptr = pdb_get_type_info(nptr->type); nptr = tiptr->query_cb(nptr, tok_arr[i]); if (!nptr) @@ -296,3 +292,37 @@ list_free(lptr, 0, NULL); return sbuf; } + + +/* + * Write a loaded database structure to disk. + */ +int pdb_write(struct pdb* dbptr, char* file) { + if (!dbptr) + return 0; + if (!dbptr->data) + return 0; + + FILE* fptr = fopen(file, "w"); + if (!fptr) { + fprintf(stderr, "%s:%s():%i: Error: Unable to open file \"%s\" for \ +writing.\n", __FILE__, __FUNCTION__, __LINE__, file); + return 0; + } + + struct pdb_node_t* nptr = dbptr->data; + + int ret = pdb_standard_write_node(dbptr, fptr, nptr, -1); + fclose(fptr); + return ret; +} + + +/* + * Set a custom free callback for the given node. + * 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) { + nptr->custom_free_cb = (custom_free_cb_t)free_cb; +} |
From: Michael L. <par...@us...> - 2004-10-26 20:03:08
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19148 Modified Files: pdb.pws Log Message: Writing to disk, free callback overrides. Index: pdb.pws =================================================================== RCS file: /cvsroot/pdatabase/pdb/pdb.pws,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pdb.pws 26 Oct 2004 03:41:07 -0000 1.3 +++ pdb.pws 26 Oct 2004 20:02:08 -0000 1.4 @@ -1,11 +1,11 @@ [filenumbers] -0=128 -1=240 +0=39 +1=569 2=25 -3=2 -4=107 -5=168 +3=26 +4=95 +5=41 6=133 [filemarkers] |
From: Michael L. <par...@us...> - 2004-10-26 03:41:17
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18523/src Modified Files: pdb.c pdb_parse.c pdb_types.c Log Message: Comment handling, delete node, location backtrace, list added, str fixed. Index: pdb_types.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_types.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pdb_types.c 24 Oct 2004 21:56:14 -0000 1.2 +++ pdb_types.c 26 Oct 2004 03:41:08 -0000 1.3 @@ -50,22 +50,24 @@ "}", pdb_create_tree_node_cb, pdb_load_tree_node_cb, - NULL, /* trees cannot be "set" */ + NULL, /* trees cannot be "set" */ pdb_add_tree_node_child_cb, pdb_free_tree_node_cb, - pdb_query_tree_node_cb + pdb_query_tree_node_cb, + pdb_del_child_tree_node_cb }, { /* Link List */ LIST_NODE_TYPE, "(", ")", - NULL, - NULL, - NULL, /* lists cannot be "set" */ - NULL, - NULL, - NULL + pdb_create_list_node_cb, + pdb_load_list_node_cb, + NULL, /* lists cannot be "set" */ + pdb_add_list_node_child_cb, + pdb_free_list_node_cb, + pdb_query_list_node_cb, + pdb_del_child_list_node_cb }, { /* String */ @@ -77,7 +79,8 @@ pdb_set_string_node_cb, NULL, /* no child nodes supported */ pdb_free_string_node_cb, - NULL + NULL, + NULL /* string has no child */ }, { /* @@ -89,22 +92,25 @@ NULL, NULL, pdb_create_link_node_cb, - NULL, /* links cannot be "set" */ + NULL, /* links cannot be "set" */ NULL, NULL, pdb_free_link_node_cb, - pdb_query_link_node_cb + pdb_query_link_node_cb, + NULL /* children are ignored on free */ }, { /* Terminating Entry */ NO_NODE_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL + NULL, NULL, NULL, NULL, + NULL, NULL } }; static void* pdb_standard_create_node(char* id, struct pdb_node_t* parent, int type); +static void pdb_del_node_from_parent(struct pdb_node_t* nptr); static int pdb_free_node_cb(void* dptr); @@ -280,11 +286,63 @@ struct pdb_node_t* nptr = dptr; struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); int ret = tiptr->free_cb(nptr); + if (nptr->id) + free(nptr->id); + free(nptr); + return ret; +} + + +/* + * Free a node and remove it from the parent. + * + * Use this function and NOT pdb_node_types_t->free_cb() + * if you are deleting a single node from the structure + * (e.g. pdb_del rather than pdb_unload). + */ +int pdb_free_node(struct pdb_node_t* nptr) { + /* + * Remove from parent. + */ + pdb_del_node_from_parent(nptr); + + /* + * Free data container. + */ + struct pdb_node_types_t* tiptr = pdb_get_type_info(nptr->type); + int ret = tiptr->free_cb(nptr); + + /* + * Free node. + */ + if (nptr->id) + free(nptr->id); free(nptr); + return ret; } +/* + * Delete a node from its parent, but don't free the node. + */ +void pdb_del_node_from_parent(struct pdb_node_t* nptr) { + if (!nptr->parent) + return; + + struct pdb_node_types_t* 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", + __FILE__, __FUNCTION__, __LINE__, nptr->id, nptr->parent->type); + return; + } + + tiptr->del_child_cb(nptr->parent, nptr); +} + + /************************************************************* ****************** ****************** ****************** Binary Tree Node Type ****************** @@ -341,7 +399,6 @@ */ int pdb_free_tree_node_cb(struct pdb_node_t* nptr) { struct binaryTree* tptr = nptr->data; - free(nptr->id); tree_free(tptr, 1, (void*)&pdb_free_node_cb); return 1; } @@ -356,6 +413,113 @@ } +/* + * Delete a child from the parent tree, but do not free child. + */ +void pdb_del_child_tree_node_cb(struct pdb_node_t* pptr, + struct pdb_node_t* nptr) { + + struct binaryTree* tptr = pptr->data; + tree_delink_node(tptr, nptr->id); +} + + +/************************************************************* + ****************** ****************** + ****************** List Node Type ****************** + ****************** ****************** + *************************************************************/ + + +/* + * Callback for creating a new list node. + */ +void* pdb_create_list_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr) { + + struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, + LIST_NODE_TYPE); + if (!nptr) + return NULL; + + struct linkList* lptr = list_create(); + if (!lptr) { + ERROR("Unable to allocate memory for node data structure [list]."); + free(nptr); + return NULL; + } + nptr->data = (void*)lptr; + + return nptr; +} + + +/* + * Callback for loading a list node. + */ +int pdb_load_list_node_cb(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, + int* line) { + + return pdb_standard_load_node(fptr, pptr, tok_arr, line); +} + + +/* + * Add a child to the parent structure. + */ +int pdb_add_list_node_child_cb(struct pdb_node_t* parent, char* id, + struct pdb_node_t* child) { + + struct linkList* lptr = parent->data; + return (list_add_node_end(lptr, (void*)child) ? 1 : 0); +} + + +/* + * Free a list node. + */ +int pdb_free_list_node_cb(struct pdb_node_t* nptr) { + struct linkList* lptr = nptr->data; + list_free(lptr, 1, (void*)&pdb_free_node_cb); + return 1; +} + + +/* + * Query a child node from the given list. + */ +struct pdb_node_t* pdb_query_list_node_cb(struct pdb_node_t* nptr, char* id) { + struct linkList* lptr = nptr->data; + struct linkNode* lnptr = lptr->root; + + while (lnptr) { + nptr = lnptr->data; + if (!strcmp(nptr->id, id)) + return nptr; + lnptr = lnptr->next; + } + return NULL; +} + + +/* + * Delete a child from the parent list, but do not free child. + */ +void pdb_del_child_list_node_cb(struct pdb_node_t* pptr, + struct pdb_node_t* nptr) { + + struct linkList* lptr = pptr->data; + struct linkNode* lnptr = lptr->root; + + while (lnptr) { + if (lnptr->data == nptr) { + list_delink_node(lptr, lnptr); + return; + } + } +} + + /************************************************************* ****************** ****************** ****************** String Node Type ****************** @@ -365,6 +529,7 @@ /* * Callback for creating a new string node. + * If tok_arr is not NULL, tok_arr is just a char* casted to a char**. */ void* pdb_create_string_node_cb(char* id, struct pdb_node_t* parent, char** tok_arr) { @@ -374,8 +539,11 @@ if (!nptr) return NULL; - nptr->data = (char*)malloc(sizeof(char) * (strlen(tok_arr[1]) + 1)); - strcpy((char*)nptr->data, tok_arr[1]); + if (tok_arr) { + nptr->data = (char*)malloc(sizeof(char) * (strlen(tok_arr[1]) + 1)); + strcpy((char*)nptr->data, tok_arr[1]); + } else + nptr->data = NULL; return nptr; } @@ -404,7 +572,6 @@ * Free a tree node. */ int pdb_free_string_node_cb(struct pdb_node_t* nptr) { - free(nptr->id); free(nptr->data); return 1; } @@ -442,7 +609,6 @@ * Free a link node. */ int pdb_free_link_node_cb(struct pdb_node_t* nptr) { - free(nptr->id); return 1; } Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pdb.c 24 Oct 2004 21:56:14 -0000 1.2 +++ pdb.c 26 Oct 2004 03:41:08 -0000 1.3 @@ -30,28 +30,28 @@ #include "pdb_file.h" #include "pdb_parse.h" #include "pdb_types.h" +#include "list.h" #include "binarytree.h" int main(int argc, char** argv) { + printf(PDB_COMPILE_INFO); + printf("\n--LOAD--\n\n"); struct pdb* dbptr = pdb_load("/home/para/test.db"); printf("\n--DEBUG--\n\n"); - /*struct binaryTree* tptr = pdb_query(dbptr, ""); - if (!tptr) - printf("returned NULL\n"); - else - tree_debug(tptr->root);*/ + struct pdb_node_t* nptr = pdb_query_node(dbptr, "finop/foo/foo2"); + if (nptr) { + printf("[%s] [%s]\n", nptr->id, (char*)nptr->data); - char* a = pdb_query(dbptr, "finop/foo/foo2"); - printf("[%s]\n", a); + char* loc = pdb_trace(nptr); + printf("trace [%s]\n", loc); + free(loc); + } else + printf("returned NULL\n"); - pdb_set(dbptr, "finop/foo", "foo2", "123", STRING_NODE_TYPE); - - a = pdb_query(dbptr, "finop/foo/foo2"); - printf("[%s]\n", a); - + printf("\n--UNLOAD--\n\n"); pdb_unload(dbptr); return 0; } @@ -101,11 +101,8 @@ * Unload a database. */ int pdb_unload(struct pdb* dbptr) { - struct pdb_node_types_t* tiptr = pdb_get_type_info(ROOT_NODE_TYPE); + int ret = pdb_free_node(dbptr->data); free(dbptr->file); - - int ret = tiptr->free_cb(dbptr->data); - free(dbptr->data); free(dbptr); return ret; } @@ -168,8 +165,11 @@ int i = 0; while (tok_arr[i]) { + printf("[%s]\n", nptr->id); tiptr = pdb_get_type_info(nptr->type); nptr = tiptr->query_cb(nptr, tok_arr[i]); + if (!nptr) + break; ++i; } @@ -225,3 +225,74 @@ tiptr->set_cb(nptr, data); return 1; } + + +/* + * Delete a node, recursively deleting all child nodes. + */ +int pdb_del(struct pdb* dbptr, char* path) { + struct pdb_node_t* nptr = pdb_query_node(dbptr, path); + if (!nptr) + return 0; + + struct pdb_node_types_t* 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); + return 0; + } + + return pdb_free_node(nptr); +} + + +/* + * Create a backtrace of the given nodes location relative to the root. + * The resulting string is allocated and must be freed. + */ +char* pdb_trace(struct pdb_node_t* nptr) { + struct linkList* lptr = list_create(); + + while (nptr) { + list_add_node_front(lptr, nptr->id); + nptr = nptr->parent; + } + + struct linkNode* lnptr = lptr->root; + char* sbuf = (char*)malloc(BLOCK_SIZE); + char* buf = sbuf; + int buf_size = BLOCK_SIZE; + int used = 1; + memset(sbuf, 0, BLOCK_SIZE); + char* str = NULL; + + while (lnptr) { + str = lnptr->data; + if (!str) { + lnptr = lnptr->next; + continue; + } + if (*str) { + *buf = '/'; + ++buf; + } + while (*str) { + *buf = *str; + ++buf; + ++str; + ++used; + if (used >= buf_size) { + buf_size *= 2; + sbuf = (char*)realloc(sbuf, BLOCK_SIZE); + buf = (sbuf + (sizeof(char) * (used - 1))); + memset(buf, 0, (sizeof(char) * (buf_size - used))); + } + } + lnptr = lnptr->next; + } + + list_free(lptr, 0, NULL); + return sbuf; +} Index: pdb_parse.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_parse.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pdb_parse.c 24 Oct 2004 21:56:14 -0000 1.2 +++ pdb_parse.c 26 Oct 2004 03:41:08 -0000 1.3 @@ -86,6 +86,15 @@ continue; ws_end = 1; } + + /* + * If comment (and enabled), skip token. + */ + #ifdef PDB_ENABLE_COMMENTS + if (!(quotes % 2) &&(pdb_parse_comment(fptr, line, byte))) + continue; + #endif /* PDB_ENABLE_COMMENTS */ + if (byte == '\"') ++quotes; @@ -309,3 +318,49 @@ } return tok_arr; } + + +/* + * If the byte is a comment, skip comment. + * Return 1 if it is a command, 0 if not. + */ +#ifdef PDB_ENABLE_COMMENTS +int pdb_parse_comment(FILE* fptr, int* line, char byte) { + if (byte == '#') { + /* + * Feed to EOL. + */ + while (!feof(fptr)) { + byte = fgetc(fptr); + if (byte == '\n') { + (*line)++; + return 1; + } + } + } else if (byte == PDB_COMMENT_BLOCK_S[0]) { + if (strlen(PDB_COMMENT_BLOCK_S) == 2) { + FPEEK(&byte, fptr); + if (byte != PDB_COMMENT_BLOCK_S[1]) + return 0; + } + /* + * Feed to PDB_COMMENT_BLOCK_E. + */ + while (!feof(fptr)) { + byte = fgetc(fptr); + if (byte == '\n') + (*line)++; + else if (byte == PDB_COMMENT_BLOCK_E[0]) { + if (strlen(PDB_COMMENT_BLOCK_E) == 2) { + FPEEK(&byte, fptr); + if (byte != PDB_COMMENT_BLOCK_E[1]) + continue; + } + fgetc(fptr); + return 1; + } + } + } + return 0; +} +#endif /* PDB_ENABLE_COMMENTS */ |
From: Michael L. <par...@us...> - 2004-10-26 03:41:16
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18523/include Modified Files: pdb.h pdb_parse.h pdb_types.h Log Message: Comment handling, delete node, location backtrace, list added, str fixed. Index: pdb.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pdb.h 24 Oct 2004 21:56:13 -0000 1.2 +++ pdb.h 26 Oct 2004 03:41:08 -0000 1.3 @@ -22,16 +22,31 @@ #ifndef _PDB_H #define _PDB_H +/* + * Handy macros. + */ #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__, \ __FUNCTION__, __LINE__, msg); +#define PDB_COMPILE_INFO "pdb: Compiled on: " __DATE__ " at " __TIME__ + + /* * pdb constants. */ #define PDB_TOKEN_TERM ';' #define PDB_PATH_DELIM '/' +#define PDB_COMMENT_CHAR '#' +#define PDB_COMMENT_BLOCK_S "/*" /* can only be 2 chars */ +#define PDB_COMMENT_BLOCK_E "*/" /* can only be 2 chars */ + + +/* + * Comment to disable comment handling. + */ +#define PDB_ENABLE_COMMENTS /* @@ -87,6 +102,9 @@ void* pdb_query(struct pdb* dbptr, char* path); int 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); #ifdef __cplusplus } Index: pdb_types.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb_types.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pdb_types.h 24 Oct 2004 21:56:14 -0000 1.2 +++ pdb_types.h 26 Oct 2004 03:41:08 -0000 1.3 @@ -60,6 +60,8 @@ struct pdb_node_t* child); typedef int (*free_cb_t)(struct pdb_node_t* nptr); typedef struct pdb_node_t* (*query_cb_t)(struct pdb_node_t* nptr, char* id); +typedef void (*del_child_cb_t)(struct pdb_node_t* pptr, + struct pdb_node_t* nptr); /* @@ -75,6 +77,7 @@ add_node_cb_t add_child_cb; free_cb_t free_cb; query_cb_t query_cb; + del_child_cb_t del_child_cb; }; @@ -95,6 +98,7 @@ int pdb_standard_load_node(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, int* line); +int pdb_free_node(struct pdb_node_t* nptr); /* * Binary tree @@ -107,6 +111,22 @@ struct pdb_node_t* child); int pdb_free_tree_node_cb(struct pdb_node_t* nptr); struct pdb_node_t* pdb_query_tree_node_cb(struct pdb_node_t* nptr, char* id); +void pdb_del_child_tree_node_cb(struct pdb_node_t* pptr, + struct pdb_node_t* nptr); + +/* + * Link list + */ +void* pdb_create_list_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr); +int pdb_load_list_node_cb(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, + int* line); +int pdb_add_list_node_child_cb(struct pdb_node_t* parent, char* id, + struct pdb_node_t* child); +int pdb_free_list_node_cb(struct pdb_node_t* nptr); +struct pdb_node_t* pdb_query_list_node_cb(struct pdb_node_t* nptr, char* id); +void pdb_del_child_list_node_cb(struct pdb_node_t* pptr, + struct pdb_node_t* nptr); /* * String Index: pdb_parse.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb_parse.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- pdb_parse.h 18 Oct 2004 00:20:51 -0000 1.1.1.1 +++ pdb_parse.h 26 Oct 2004 03:41:08 -0000 1.2 @@ -39,6 +39,10 @@ int tok_starts_with(char* str, char* tok); char** pdb_token_parse(char* str); +#ifdef PDB_ENABLE_COMMENTS +int pdb_parse_comment(FILE* fptr, int* line, char byte); +#endif /* PDB_ENABLE_COMMENTS */ + #ifdef __cplusplus } #endif |
From: Michael L. <par...@us...> - 2004-10-26 03:41:16
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18523 Modified Files: config.log pdb.pws Log Message: Comment handling, delete node, location backtrace, list added, str fixed. Index: config.log =================================================================== RCS file: /cvsroot/pdatabase/pdb/config.log,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- config.log 24 Oct 2004 21:56:13 -0000 1.2 +++ config.log 26 Oct 2004 03:41:07 -0000 1.3 @@ -952,3 +952,39 @@ config.status:822: creating config.h config.status:942: config.h is unchanged 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 = include/Makefile + CONFIG_HEADERS = + CONFIG_LINKS = + CONFIG_COMMANDS = + $ ./config.status + +on turtle + +config.status:718: creating include/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 turtle + +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.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pdb.pws 24 Oct 2004 21:56:13 -0000 1.2 +++ pdb.pws 26 Oct 2004 03:41:07 -0000 1.3 @@ -1,11 +1,11 @@ [filenumbers] -0=116 -1=215 -2=33 -3=187 -4=87 -5=29 +0=128 +1=240 +2=25 +3=2 +4=107 +5=168 6=133 [filemarkers] @@ -28,9 +28,6 @@ [Project State] clean before build=false -[breakpoints] -0=1,,0,543319135,0,,pdb_types.c,287,250,0,pdb_load_tree_node_cb,,1098571361, - [filelist] 0=/home/para/Projects/pdb/include/pdb_types.h 1=/home/para/Projects/pdb/src/pdb_types.c |
From: Michael L. <par...@us...> - 2004-10-24 21:56:24
|
Update of /cvsroot/pdatabase/pdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30963/src Modified Files: pdb.c pdb_parse.c pdb_types.c Log Message: Added string type, query, set, and some other stuff. Index: pdb.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- pdb.c 18 Oct 2004 00:20:49 -0000 1.1.1.1 +++ pdb.c 24 Oct 2004 21:56:14 -0000 1.2 @@ -35,17 +35,22 @@ int main(int argc, char** argv) { struct pdb* dbptr = pdb_load("/home/para/test.db"); - - struct pdb_node_t* nptr = dbptr->data; - printf("root id [%s]\n", nptr->id); - struct binaryTree* tptr = nptr->data; - printf("debug:\n"); - //tree_debug(tptr->root); - nptr = tree_get_node(tptr, "finop"); - printf("{%s}\n", nptr->id); - tptr = nptr->data; - tree_debug(tptr->root); + printf("\n--DEBUG--\n\n"); + + /*struct binaryTree* tptr = pdb_query(dbptr, ""); + if (!tptr) + printf("returned NULL\n"); + else + tree_debug(tptr->root);*/ + + char* a = pdb_query(dbptr, "finop/foo/foo2"); + printf("[%s]\n", a); + + pdb_set(dbptr, "finop/foo", "foo2", "123", STRING_NODE_TYPE); + + a = pdb_query(dbptr, "finop/foo/foo2"); + printf("[%s]\n", a); pdb_unload(dbptr); return 0; @@ -68,6 +73,7 @@ * Initialize pdb structure. */ dbptr->altered = 0; + dbptr->settings = PDB_DEFAULT_SETTINGS; dbptr->file = (char*)malloc(sizeof(char) * (strlen(file) + 1)); strcpy(dbptr->file, file); struct pdb_node_types_t* rntptr = pdb_get_type_info(ROOT_NODE_TYPE); @@ -78,7 +84,7 @@ pdb_close_file(fptr); return NULL; } - dbptr->data = (*rntptr->create_cb)("root_replace_me_with_NULL", NULL); + dbptr->data = (*rntptr->create_cb)(NULL, NULL, NULL); /* * Load database. @@ -103,3 +109,119 @@ free(dbptr); return ret; } + + +/* + * Enable pdb setting(s). + * settings are OR'ed togther. + */ +void pdb_enable(struct pdb* dbptr, int settings) { + dbptr->settings |= settings; +} + + +/* + * Disable pdb setting(s). + * settings are OR'ed togther. + */ +void pdb_disable(struct pdb* dbptr, int settings) { + dbptr->settings &= ~settings; +} + + +/* + * Return 1 if the given setting is set. + */ +int pdb_is_set(struct pdb* dbptr, int setting) { + return ((dbptr->settings & setting) == setting); +} + + +/* + * Create a node link from path/key to tnptr. + * Node links will be ignored when written to disk. + */ +int pdb_create_link(struct pdb* dbptr, char* path, char* key, + struct pdb_node_t* tnptr) { + + struct pdb_node_t* nptr = pdb_query_node(dbptr, path); + if (!nptr) + return 0; + + struct pdb_node_types_t* tiptr = pdb_get_type_info(LINK_NODE_TYPE); + return (tiptr->create_cb(key, nptr, (char**)tnptr) ? 1 : 0); +} + + +/* + * Return a given node from the database. + */ +struct pdb_node_t* pdb_query_node(struct pdb* dbptr, char* path) { + + if (!strcmp(path, "") || !strcmp(path, "/")) + return dbptr->data; + + char** tok_arr = token_parse(path, PDB_PATH_DELIM, NULL); + + struct pdb_node_t* nptr = dbptr->data; + struct pdb_node_types_t* tiptr = NULL; + + int i = 0; + while (tok_arr[i]) { + tiptr = pdb_get_type_info(nptr->type); + nptr = tiptr->query_cb(nptr, tok_arr[i]); + ++i; + } + + token_free(tok_arr); + + return nptr; +} + + +/* + * 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); + return (nptr ? nptr->data : NULL); +} + + +/* + * Set a node's data. If it does not exist, create it. + */ +int pdb_set(struct pdb* dbptr, char* path, char* key, void* data, int type) { + struct pdb_node_types_t* tiptr = pdb_get_type_info(type); + if (!tiptr) + return 0; + + struct pdb_node_t* pptr = pdb_query_node(dbptr, path); + if (!pptr) + return 0; + + struct pdb_node_types_t* ptiptr = pdb_get_type_info(pptr->type); + struct pdb_node_t* nptr = ptiptr->query_cb(pptr, key); + + if (!nptr) { + /* + * Node does not exists -- create. + */ + 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); + return 0; + } + } + + if (!tiptr->set_cb) { + fprintf(stderr, "%s:%s():%i: Error: 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; + } + + tiptr->set_cb(nptr, data); + return 1; +} Index: pdb_parse.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_parse.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- pdb_parse.c 18 Oct 2004 00:20:50 -0000 1.1.1.1 +++ pdb_parse.c 24 Oct 2004 21:56:14 -0000 1.2 @@ -184,7 +184,7 @@ * Return 1 if token has ended. */ int is_end_of_token(char byte) { - return ((byte == TOKEN_TERM) || (byte == '\n')); + return ((byte == PDB_TOKEN_TERM) || (byte == '\n')); } Index: pdb_types.c =================================================================== RCS file: /cvsroot/pdatabase/pdb/src/pdb_types.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- pdb_types.c 18 Oct 2004 00:20:49 -0000 1.1.1.1 +++ pdb_types.c 24 Oct 2004 21:56:14 -0000 1.2 @@ -50,9 +50,10 @@ "}", pdb_create_tree_node_cb, pdb_load_tree_node_cb, + NULL, /* trees cannot be "set" */ pdb_add_tree_node_child_cb, pdb_free_tree_node_cb, - NULL + pdb_query_tree_node_cb }, { /* Link List */ @@ -61,6 +62,7 @@ ")", NULL, NULL, + NULL, /* lists cannot be "set" */ NULL, NULL, NULL @@ -68,13 +70,30 @@ { /* String */ STRING_NODE_TYPE, + NULL, /* standard load type (fallback) */ + NULL, /* standard load type (fallback) */ + pdb_create_string_node_cb, + NULL, /* load done by creation */ + pdb_set_string_node_cb, + NULL, /* no child nodes supported */ + pdb_free_string_node_cb, + NULL + }, + { + /* + * Link Node + * For efficiency, this should remain + * the last type in the array. + */ + LINK_NODE_TYPE, NULL, NULL, + pdb_create_link_node_cb, + NULL, /* links cannot be "set" */ NULL, NULL, - NULL, - NULL, - NULL + pdb_free_link_node_cb, + pdb_query_link_node_cb }, { /* Terminating Entry */ @@ -93,7 +112,12 @@ * Return type info struct by the given bitmask id. */ struct pdb_node_types_t* pdb_get_type_info(int type) { - return(&(pdb_types[(int)(log(type) / log(2))])); + /* + * Floating point arithmetic is not _exact_, + * so round to a whole number. + * It will give you some BS like 2.9999...9 rather than 3. + */ + return(&(pdb_types[round_i(log(type) / log(2))])); } @@ -157,14 +181,23 @@ * Add child to parent structure. */ if (parent) { - struct pdb_node_types_t* tiptr = pdb_get_type_info(type); - 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", - __FILE__, __FUNCTION__, __LINE__, tiptr->bitmask, type); + struct pdb_node_types_t* 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", + __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", + __FILE__, __FUNCTION__, __LINE__, tiptr->bitmask, type); + free(nptr->id); + free(nptr); + return NULL; + } } } @@ -188,19 +221,18 @@ char* tok = pdb_get_token(fptr, &type, line); while (tok) { - tok_arr = pdb_token_parse(tok); - printf("loading [%s] of type %s into [%s] of type %s\n", - tok_arr[0], ttype(type), pptr->id, ttype(pptr->type)); - /* * Is the block over? */ - if (type & BLOCK_CLOSE) { - token_free(tok_arr); + if ((type & BLOCK_CLOSE) == BLOCK_CLOSE) { free(tok); return 1; } + tok_arr = pdb_token_parse(tok); + printf("loading (%i)[%s] of type %s into [%s] of type %s\n", + type, tok_arr[0], ttype(type), pptr->id, ttype(pptr->type)); + /* * Create the child node and add to parent. */ @@ -211,18 +243,20 @@ free(tok); return 0; } - cptr = ctiptr->create_cb(tok_arr[0], pptr); + cptr = ctiptr->create_cb(tok_arr[0], pptr, tok_arr); /* - * Load the child node. + * Load the child node (if supported). */ - 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", - __FILE__, __FUNCTION__, __LINE__, *line); - token_free(tok_arr); - free(tok); - return 0; + 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", + __FILE__, __FUNCTION__, __LINE__, *line); + token_free(tok_arr); + free(tok); + return 0; + } } /* @@ -261,7 +295,9 @@ /* * Callback for creating a new tree node. */ -void* pdb_create_tree_node_cb(char* id, struct pdb_node_t* parent) { +void* pdb_create_tree_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr) { + struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, TREE_NODE_TYPE); if (!nptr) @@ -280,7 +316,7 @@ /* - * Callbaco for loading a tree node. + * Callback for loading a tree node. */ int pdb_load_tree_node_cb(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, int* line) { @@ -309,3 +345,112 @@ tree_free(tptr, 1, (void*)&pdb_free_node_cb); return 1; } + + +/* + * Query a child node from the given binary tree. + */ +struct pdb_node_t* pdb_query_tree_node_cb(struct pdb_node_t* nptr, char* id) { + struct binaryTree* tptr = nptr->data; + return (struct pdb_node_t*)tree_get_node(tptr, id); +} + + +/************************************************************* + ****************** ****************** + ****************** String Node Type ****************** + ****************** ****************** + *************************************************************/ + + +/* + * Callback for creating a new string node. + */ +void* pdb_create_string_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr) { + + struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, + STRING_NODE_TYPE); + if (!nptr) + return NULL; + + nptr->data = (char*)malloc(sizeof(char) * (strlen(tok_arr[1]) + 1)); + strcpy((char*)nptr->data, tok_arr[1]); + + return nptr; +} + + +/* + * (Re)set the data at a string node. + */ +void pdb_set_string_node_cb(struct pdb_node_t* nptr, void* data) { + char* dptr = (char*)data; + + if (nptr->data) + nptr->data = (char*)realloc(nptr->data, sizeof(char) * + (strlen(dptr) + 1)); + else + nptr->data = (char*)malloc(sizeof(char) * (strlen(dptr) + 1)); + + if (!nptr->data) { + ERROR("Unable to allocate memory for string data."); + } else + strcpy(nptr->data, dptr); +} + + +/* + * Free a tree node. + */ +int pdb_free_string_node_cb(struct pdb_node_t* nptr) { + free(nptr->id); + free(nptr->data); + return 1; +} + + +/************************************************************* + ****************** ****************** + ****************** Link Node Type ****************** + ****************** ****************** + *************************************************************/ + + +/* + * Callback for creating a new link node. + * + * This is a little different than normal creation + * callbacks -- the tok_arr is a pointer target + * node to be linked. + */ +void* pdb_create_link_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr) { + + struct pdb_node_t* nptr = pdb_standard_create_node(id, parent, + LINK_NODE_TYPE); + if (!nptr) + return NULL; + + nptr->data = tok_arr; + + return nptr; +} + + +/* + * Free a link node. + */ +int pdb_free_link_node_cb(struct pdb_node_t* nptr) { + free(nptr->id); + return 1; +} + + +/* + * Follow the link node. + */ +struct pdb_node_t* pdb_query_link_node_cb(struct pdb_node_t* nptr, char* id) { + nptr = nptr->data; + return (nptr ? nptr->data : NULL); +} |
From: Michael L. <par...@us...> - 2004-10-24 21:56:23
|
Update of /cvsroot/pdatabase/pdb/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30963/include Modified Files: pdb.h pdb_types.h Log Message: Added string type, query, set, and some other stuff. Index: pdb.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- pdb.h 18 Oct 2004 00:20:51 -0000 1.1.1.1 +++ pdb.h 24 Oct 2004 21:56:13 -0000 1.2 @@ -28,9 +28,22 @@ __FUNCTION__, __LINE__, msg); /* - * PDB constants. + * pdb constants. */ -#define TOKEN_TERM ';' +#define PDB_TOKEN_TERM ';' +#define PDB_PATH_DELIM '/' + + +/* + * pdb setting value bitmasks. + */ +#define PDB_CASE_INSENSITIVE 1 + + +/* + * Default pdb settings. + */ +#define PDB_DEFAULT_SETTINGS 0 /* @@ -49,34 +62,9 @@ */ struct pdb { struct pdb_node_t* data; - int altered; char* file; -}; - - -/* - * Node callback types. - */ -typedef void* (*create_cb_t)(char* id, struct pdb_node_t* parent); -typedef int (*load_cb_t)(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, - int* line); -typedef int (*add_node_cb_t)(struct pdb_node_t* parent, char* id, - struct pdb_node_t* child); -typedef int (*free_cb_t)(struct pdb_node_t* nptr); - - -/* - * Information for a single node type. - */ -struct pdb_node_types_t { - int bitmask; - char* open_token; - char* close_token; - create_cb_t create_cb; - load_cb_t load_cb; - add_node_cb_t add_child_cb; - free_cb_t free_cb; - void* query_cb; //TODO + int altered; + int settings; }; @@ -86,8 +74,19 @@ #endif struct pdb* pdb_load(char* file); +int pdb_unload(struct pdb* dbptr); -struct pdb_node_types_t* pdb_get_type_info(int type); +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); + +int pdb_set(struct pdb* dbptr, char* path, char* key, void* data, int type); #ifdef __cplusplus } Index: pdb_types.h =================================================================== RCS file: /cvsroot/pdatabase/pdb/include/pdb_types.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- pdb_types.h 18 Oct 2004 00:20:51 -0000 1.1.1.1 +++ pdb_types.h 24 Oct 2004 21:56:14 -0000 1.2 @@ -29,12 +29,12 @@ #define TREE_NODE_TYPE 1 #define LIST_NODE_TYPE 2 #define STRING_NODE_TYPE 4 +#define LINK_NODE_TYPE 8 /* - * This bitmask should continue - * from the above types. + * Next bitmask after the highest one above. */ -#define BLOCK_CLOSE 8 +#define BLOCK_CLOSE 16 /* * The type of token that pdb should consider @@ -47,8 +47,42 @@ */ #define ROOT_NODE_TYPE TREE_NODE_TYPE - - + +/* + * Node callback types. + */ +typedef void* (*create_cb_t)(char* id, struct pdb_node_t* parent, + char** tok_arr); +typedef int (*load_cb_t)(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, + int* line); +typedef void (*set_cb_t)(struct pdb_node_t* nptr, void* data); +typedef int (*add_node_cb_t)(struct pdb_node_t* parent, char* id, + struct pdb_node_t* child); +typedef int (*free_cb_t)(struct pdb_node_t* nptr); +typedef struct pdb_node_t* (*query_cb_t)(struct pdb_node_t* nptr, char* id); + + +/* + * Information for a single node type. + */ +struct pdb_node_types_t { + int bitmask; + char* open_token; + char* close_token; + create_cb_t create_cb; + load_cb_t load_cb; + set_cb_t set_cb; + add_node_cb_t add_child_cb; + free_cb_t free_cb; + query_cb_t query_cb; +}; + + +/* + * Handy macros. + */ +#define round_i(x) ((int)(x + .5)) + #ifdef __cplusplus extern "C" @@ -62,13 +96,33 @@ int pdb_standard_load_node(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, int* line); -void* pdb_create_tree_node_cb(char* id, struct pdb_node_t* parent); +/* + * Binary tree + */ +void* pdb_create_tree_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr); int pdb_load_tree_node_cb(FILE* fptr, struct pdb_node_t* pptr, char** tok_arr, int* line); int pdb_add_tree_node_child_cb(struct pdb_node_t* parent, char* id, struct pdb_node_t* child); int pdb_free_tree_node_cb(struct pdb_node_t* nptr); +struct pdb_node_t* pdb_query_tree_node_cb(struct pdb_node_t* nptr, char* id); + +/* + * String + */ +void* pdb_create_string_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr); +void pdb_set_string_node_cb(struct pdb_node_t* nptr, void* data); +int pdb_free_string_node_cb(struct pdb_node_t* nptr); +/* + * Link + */ +void* pdb_create_link_node_cb(char* id, struct pdb_node_t* parent, + char** tok_arr); +int pdb_free_link_node_cb(struct pdb_node_t* nptr); +struct pdb_node_t* pdb_query_link_node_cb(struct pdb_node_t* nptr, char* id); #ifdef __cplusplus } |
From: Michael L. <par...@us...> - 2004-10-24 21:56:23
|
Update of /cvsroot/pdatabase/pdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30963 Modified Files: Makefile Makefile.in config.log pdb.pws Log Message: Added string type, query, set, and some other stuff. Index: Makefile.in =================================================================== RCS file: /cvsroot/pdatabase/pdb/Makefile.in,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.in 18 Oct 2004 00:20:48 -0000 1.1.1.1 +++ Makefile.in 24 Oct 2004 21:56:13 -0000 1.2 @@ -128,7 +128,7 @@ DIST_COMMON = README ./stamp-h.in AUTHORS COPYING ChangeLog INSTALL \ Makefile.am Makefile.in NEWS TODO acconfig.h acinclude.m4 \ aclocal.m4 config.guess config.h.in config.sub configure \ - configure.in depcomp install-sh ltmain.sh missing mkinstalldirs + configure.in install-sh ltmain.sh missing mkinstalldirs DIST_SUBDIRS = $(SUBDIRS) all: config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive Index: config.log =================================================================== RCS file: /cvsroot/pdatabase/pdb/config.log,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- config.log 18 Oct 2004 00:20:46 -0000 1.1.1.1 +++ config.log 24 Oct 2004 21:56:13 -0000 1.2 @@ -775,7 +775,7 @@ lt_cv_cc_64bit_output=no lt_cv_deplibs_check_method=pass_all lt_cv_file_magic_cmd='$MAGIC_CMD' -lt_cv_file_magic_test_file='/lib/libc.so.6 /lib/libc-2.3.3.so' +lt_cv_file_magic_test_file='/lib/libc.so.6 /lib/libc-2.3.4.so' lt_cv_ld_reload_flag=-r lt_cv_objdir=.libs lt_cv_path_LD=/usr/i686-pc-linux-gnu/bin/ld @@ -952,219 +952,3 @@ config.status:822: creating config.h config.status:942: config.h is unchanged 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 = include/Makefile - CONFIG_HEADERS = - CONFIG_LINKS = - CONFIG_COMMANDS = - $ ./config.status - -on turtle - -config.status:718: creating include/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 turtle - -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 turtle - -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 = include/Makefile - CONFIG_HEADERS = - CONFIG_LINKS = - CONFIG_COMMANDS = - $ ./config.status - -on turtle - -config.status:718: creating include/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 turtle - -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 = include/Makefile - CONFIG_HEADERS = - CONFIG_LINKS = - CONFIG_COMMANDS = - $ ./config.status - -on turtle - -config.status:718: creating include/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 turtle - -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 = include/Makefile - CONFIG_HEADERS = - CONFIG_LINKS = - CONFIG_COMMANDS = - $ ./config.status - -on turtle - -config.status:718: creating include/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 turtle - -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 = include/Makefile - CONFIG_HEADERS = - CONFIG_LINKS = - CONFIG_COMMANDS = - $ ./config.status - -on turtle - -config.status:718: creating include/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 turtle - -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 turtle - -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.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- pdb.pws 18 Oct 2004 00:20:48 -0000 1.1.1.1 +++ pdb.pws 24 Oct 2004 21:56:13 -0000 1.2 @@ -1,11 +1,11 @@ [filenumbers] -0=62 -1=219 +0=116 +1=215 2=33 3=187 -4=62 -5=28 +4=87 +5=29 6=133 [filemarkers] @@ -28,6 +28,9 @@ [Project State] clean before build=false +[breakpoints] +0=1,,0,543319135,0,,pdb_types.c,287,250,0,pdb_load_tree_node_cb,,1098571361, + [filelist] 0=/home/para/Projects/pdb/include/pdb_types.h 1=/home/para/Projects/pdb/src/pdb_types.c Index: Makefile =================================================================== RCS file: /cvsroot/pdatabase/pdb/Makefile,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile 18 Oct 2004 00:19:59 -0000 1.1.1.1 +++ Makefile 24 Oct 2004 21:56:13 -0000 1.2 @@ -128,7 +128,7 @@ DIST_COMMON = README ./stamp-h.in AUTHORS COPYING ChangeLog INSTALL \ Makefile.am Makefile.in NEWS TODO acconfig.h acinclude.m4 \ aclocal.m4 config.guess config.h.in config.sub configure \ - configure.in depcomp install-sh ltmain.sh missing mkinstalldirs + configure.in install-sh ltmain.sh missing mkinstalldirs DIST_SUBDIRS = $(SUBDIRS) all: config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive |