[Xmltools-development] xmltools/src mcd.h nmap.c xmltool.c
Status: Beta
Brought to you by:
nik_89
|
From: nik_89 <ni...@us...> - 2004-12-24 22:12:53
|
Update of /cvsroot/xmltools/xmltools/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30651 Modified Files: mcd.h nmap.c xmltool.c Log Message: nmap.c xmltool.c : Major bug fixes on those 2, it actually works very well for me. We will do some tests and release it if theres no more bugs. Index: nmap.c =================================================================== RCS file: /cvsroot/xmltools/xmltools/src/nmap.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** nmap.c 1 Nov 2004 17:56:24 -0000 1.5 --- nmap.c 24 Dec 2004 22:12:42 -0000 1.6 *************** *** 19,22 **** --- 19,24 ---- * node at a time (a set of nodes to be * duplicated with different content). + * + * TODO : convert all(almost) the integers returning to pointers and arguments * */ *************** *** 55,59 **** } if (!n_map) ! rootnam = rootname; return 0; } --- 57,67 ---- } if (!n_map) ! { ! if (!rootnam) ! rootnam = calloc(1, strlen(rootname)); ! else ! rootnam = realloc(rootnam, strlen(rootname)); ! memcpy(rootnam, rootname, strlen(rootname)); ! } return 0; } *************** *** 118,121 **** --- 126,131 ---- if (!rootnam) Nmap_AddRoot("_xml_root_"); + else + rootnam = realloc(rootnam, 0); } else *************** *** 237,261 **** int Nmap_Del(char *parent_name, char *child_name) { /* errors : 1 is that n_map doesnt exist, 2 if the parent doesnt exist, 3 if the child node doesnt exist (if the child node doesnt exist and theres no more nodes, it will delete it) */ if (!n_map) return N_MAP_UNEXIST; ! int o_checknode = check_node_struct(parent_name, child_name); if ( o_checknode == PARENT_UNEXIST) return o_checknode; ! int pnum = give_parent_number(parent_name); if (pnum == PARENT_UNEXIST) return pnum; ! if (o_checknode == 1 && n_map[pnum].total_child > 0) { ! int cnum = give_child_number(parent_name, child_name); if (cnum == CHILD_UNEXIST) return cnum; ! unsigned int loo = cnum; while (loo < n_map[pnum].total_child) { printf("nmap_del : loo %d\n", loo); unsigned int slen = strlen(n_map[pnum].child_nodes[loo + 1]) + 1; ! /* for the content */ unsigned int c_slen = strlen(n_map[pnum].child_content[loo + 1]) + 1; --- 247,276 ---- int Nmap_Del(char *parent_name, char *child_name) { /* errors : 1 is that n_map doesnt exist, 2 if the parent doesnt exist, 3 if the child node doesnt exist (if the child node doesnt exist and theres no more nodes, it will delete it) */ + unsigned int todel = 0, loo = 0, totalc = 0; + int o_checknode = 0, pnum = 0, cnum = 0; + if (!n_map) return N_MAP_UNEXIST; ! o_checknode = check_node_struct(parent_name, child_name); if ( o_checknode == PARENT_UNEXIST) return o_checknode; ! pnum = give_parent_number(parent_name); if (pnum == PARENT_UNEXIST) return pnum; ! if (o_checknode == 1 && n_map[pnum].total_child > 0) { ! cnum = give_child_number(parent_name, child_name); if (cnum == CHILD_UNEXIST) return cnum; ! loo = cnum; ! #if old_del_method while (loo < n_map[pnum].total_child) { printf("nmap_del : loo %d\n", loo); unsigned int slen = strlen(n_map[pnum].child_nodes[loo + 1]) + 1; ! /* will have to assign the last ! * entry to the current pointer(pointer to delete) */ /* for the content */ unsigned int c_slen = strlen(n_map[pnum].child_content[loo + 1]) + 1; *************** *** 266,269 **** --- 281,287 ---- n_map[pnum].child_content[loo] = (char*)realloc(n_map->child_content[loo], c_slen); + /* this is stupid and newb... we only need to set the pointer heh + * the worse would be to have to set the pointers of all after the + * one to delete. */ memcpy(n_map[pnum].child_nodes[loo], n_map[pnum].child_nodes[loo + 1], slen); memcpy(n_map[pnum].child_content[loo], n_map[pnum].child_content[loo + 1], c_slen); *************** *** 297,307 **** loo++; } loo = 0; ! while (loo < n_map->total_child - 1) { printf("nmap_del : list %s\n", n_map->child_nodes[loo]); loo++; } ! n_map->total_child--; } --- 315,373 ---- loo++; } + #else + /* ok this is very simple yet it does the same and even better than the above + * coding. (using pointers) */ + while (1 != 2) + { + todel = give_child_number(parent_name, child_name); + if (n_map->total_child == 1) + { /* we just delete the entry without doing anything else */ + printf("Nmap_del : only one left to del \n"); + free(n_map->child_nodes[todel]); + free(n_map->child_content[todel]); + free(n_map->child_nodes); + free(n_map->child_content); + n_map->total_child--; + } + else if (n_map->total_child == todel) + { /* we just delete the entry and realloc the node and content pointers */ + printf("Nmap_del : deleting the last one of the list\n"); + free(n_map->child_nodes[todel]); + free(n_map->child_content[todel]); + n_map->total_child--; + /* realloc the node and content ptp */ + n_map->child_nodes = (char**)realloc(n_map->child_nodes, sizeof(char*) * (n_map->total_child)); + n_map->child_content = (char**)realloc(n_map->child_content, sizeof(char*) * (n_map->total_child)); + + } + else + { + printf("Nmap_del : normal deleting part\n"); + /* free the data of the current node and content */ + free(n_map->child_nodes[todel]); + free(n_map->child_content[todel]); + /* pass the end content and node to the freed pointers */ + n_map->child_nodes[todel] = NULL; + n_map->child_content[todel] = NULL; + n_map->child_nodes[todel] = n_map->child_nodes[n_map->total_child - 1]; + n_map->child_content[todel] = n_map->child_content[n_map->total_child - 1]; + /* substract the nodes and content total */ + n_map->total_child--; + /* realloc the node and content ptp */ + n_map->child_nodes = (char**)realloc(n_map->child_nodes, sizeof(char*) * (n_map->total_child)); + n_map->child_content = (char**)realloc(n_map->child_content, sizeof(char*) * (n_map->total_child)); + } + break; + } + #endif loo = 0; ! ! while (loo < n_map->total_child) { printf("nmap_del : list %s\n", n_map->child_nodes[loo]); loo++; } ! /* n_map->total_child--; */ ! } *************** *** 315,318 **** --- 381,386 ---- free(n_map->root_name); free(n_map->parent_name); + n_map->root_name = NULL; + n_map->parent_name = NULL; /* now done above free(n_map->child_nodes); *************** *** 321,325 **** /* n_map = realloc(n_map, 0); */ free(n_map); ! #if multi_parents if (nodes_total > 0) --- 389,393 ---- /* n_map = realloc(n_map, 0); */ free(n_map); ! n_map = NULL; #if multi_parents if (nodes_total > 0) Index: xmltool.c =================================================================== RCS file: /cvsroot/xmltools/xmltools/src/xmltool.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** xmltool.c 1 Nov 2004 17:56:24 -0000 1.4 --- xmltool.c 24 Dec 2004 22:12:42 -0000 1.5 *************** *** 12,20 **** General Public License for more details. */ ! /* xmltool.c ! * * the basic xml functions for the project xmltools are here */ /* extern */ #include <libxml/tree.h> --- 12,23 ---- General Public License for more details. */ ! /*! ! * xmltool.c * the basic xml functions for the project xmltools are here */ + #define error_handle(error) xmlt_errno = error; return error + #define error_handle2(error) xmlt_errno = error; return NULL + /* extern */ #include <libxml/tree.h> *************** *** 44,52 **** static xmlBufferPtr createdtdheader(xmlDocPtr doc, xmlChar **buf1); ! static void freedtdheader(xmlBufferPtr buf, xmlChar *buf1); static xmlNodePtr *findNode(xmlDocPtr *doc, char *parent_name, char *child_name, char *content); ! #define usexmlbuffer 1 /* Externally accessable functions */ --- 47,55 ---- static xmlBufferPtr createdtdheader(xmlDocPtr doc, xmlChar **buf1); ! static void freedtdheader(xmlBufferPtr buf, xmlChar **buf1); static xmlNodePtr *findNode(xmlDocPtr *doc, char *parent_name, char *child_name, char *content); ! #define usexmlbuffer 0 /* Externally accessable functions */ *************** *** 301,314 **** xmlChar *buf1 = NULL; ! xmlBufferPtr buf = createdtdheader(doc, (char**)&buf1); dtd = xmlCreateIntSubset(doc, buf1, NULL, NULL); ! freedtdheader(buf, buf1); doc->intSubset = dtd; ! /* xmlNewChild((xmlNodePtr)dtd->children, NULL, "some stuff", NULL); */ xmlSaveFormatFile(filename, doc, 1); xmlFreeDoc(doc); } else --- 304,325 ---- xmlChar *buf1 = NULL; ! xmlBufferPtr buf = createdtdheader(doc, &buf1); ! if (!buf1) ! printf("madd debug buf1 is empty, thats why it crashes\n"); dtd = xmlCreateIntSubset(doc, buf1, NULL, NULL); ! printf("madd debug1\n"); ! /* showMemStats(); */ ! freedtdheader(buf, &buf1); ! /*showMemStats(); */ ! printf("madd debug2\n"); doc->intSubset = dtd; ! printf("madd debug3\n"); /* xmlNewChild((xmlNodePtr)dtd->children, NULL, "some stuff", NULL); */ xmlSaveFormatFile(filename, doc, 1); + printf("madd debug4\n"); xmlFreeDoc(doc); + printf("madd debug5\n"); } else *************** *** 360,366 **** if (open(filename, 0644) == -1) /* check to see if the file exist */ { ! xmlt_errno = FILE_UNEXIST; ! return NULL; } if (!n_map) { --- 371,377 ---- if (open(filename, 0644) == -1) /* check to see if the file exist */ { ! error_handle2(FILE_UNEXIST); } + if (!n_map) { *************** *** 368,372 **** return NULL; } ! doc = xmlParseFile(filename); xmlValidCtxtPtr ctxt = xmlNewValidCtxt(); --- 379,383 ---- return NULL; } ! doc = xmlParseFile(filename); xmlValidCtxtPtr ctxt = xmlNewValidCtxt(); *************** *** 425,436 **** static xmlBufferPtr createdtdheader(xmlDocPtr doc, xmlChar **buf1) { - - #if usexmlbuffer xmlChar *elem = "<!ELEMENT "; ! xmlChar *pcdata = "(#PCDATA)"; ! ! NODE_MAP *n_map = Nmap_GetData(); xmlBufferPtr buf; buf = xmlBufferCreateSize(strlen(doc->children->name) + 3); --- 436,446 ---- static xmlBufferPtr createdtdheader(xmlDocPtr doc, xmlChar **buf1) { xmlChar *elem = "<!ELEMENT "; ! xmlChar *pcdata = " (#PCDATA)"; NODE_MAP *n_map = Nmap_GetData(); + #if usexmlbuffer + + xmlBufferPtr buf; buf = xmlBufferCreateSize(strlen(doc->children->name) + 3); *************** *** 482,494 **** return buf; #else #endif } ! static void freedtdheader(xmlBufferPtr buf, xmlChar *buf1) { #if usexmlbuffer xmlBufferFree(buf); #else ! buf1 = realloc(buf1, 0); #endif } --- 492,527 ---- return buf; #else + unsigned int a = 0; + char *tmp1 = calloc(1, 512); + printf("will now use the 2nd way of doing the dtd header\n"); + sprintf(tmp1, "%s [\n%s%s ANY>", doc->children->name, elem, doc->children->name); + printf("here1\n"); + sprintf(tmp1, "%s%s%s (", tmp1, elem, n_map->parent_name); + printf("here2\n"); + while (a < n_map->total_child - 1) + { + sprintf(tmp1, "%s%s, ", tmp1, n_map->child_nodes[a]); + a++; + } + sprintf(tmp1, "%s%s)>", tmp1, n_map->child_nodes[a]); + a= 0; + while (a < n_map->total_child) + { + sprintf(tmp1, "%s%s%s%s >", tmp1, elem, n_map->child_nodes[a], pcdata); + a++; + } + sprintf(tmp1, "%s]", tmp1); + printf("createdtdheader temp1 %s\n", tmp1); + *buf1 = tmp1; + return NULL; #endif } ! static void freedtdheader(xmlBufferPtr buf, xmlChar **buf1) { #if usexmlbuffer xmlBufferFree(buf); #else ! /* *buf1 = realloc(buf1, 0); */ #endif } Index: mcd.h =================================================================== RCS file: /cvsroot/xmltools/xmltools/src/mcd.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mcd.h 1 Nov 2004 17:55:41 -0000 1.1 --- mcd.h 24 Dec 2004 22:12:42 -0000 1.2 *************** *** 34,39 **** #ifndef MCD_QUIET #ifndef WIN32 ! #warning - Building with memory checking. ! #warning expect lower performance. - #endif #endif --- 34,39 ---- #ifndef MCD_QUIET #ifndef WIN32 ! /*#warning - Building with memory checking. ! #warning expect lower performance. -*/ #endif #endif |