#include "parser.h" #include #ifdef DARWIN #include "stdlib.h" #endif #ifdef NOSTRING void memset(char *s, int c, int n) { char *se = s + n; while(s < se) *s++ = c; } #else #include #endif int dh_memcmp(char *a,char *b,int n) { int c = 0; while( c < n ) { if( *a != *b ) return c+1; a++; b++; c++; } return 0; } struct nodec *new_nodecp( struct nodec *newparent ) { static int pos = 0; int size = sizeof( struct nodec ); struct nodec *self = (struct nodec *) malloc( size ); memset( (char *) self, 0, size ); self->parent = newparent; self->pos = ++pos; return self; } struct nodec *new_nodec() { int size = sizeof( struct nodec ); struct nodec *self = (struct nodec *) malloc( size ); memset( (char *) self, 0, size ); return self; } void del_nodec( struct nodec *node ) { struct nodec *curnode; struct attc *curatt; struct nodec *next; struct attc *nexta; curnode = node->firstchild; while( curnode ) { next = curnode->next; del_nodec( curnode ); if( !next ) break; curnode = next; } curatt = node->firstatt; while( curatt ) { nexta = curatt->next; free( curatt ); curatt = nexta; } free( node ); } struct attc* new_attc( struct nodec *newparent ) { int size = sizeof( struct attc ); struct attc *self = (struct attc *) malloc( size ); memset( (char *) self, 0, size ); self->parent = newparent; return self; } //#define DEBUG struct nodec* parserc_parse( struct parserc *self, char *xmlin ) { char *tagname, *attname, *attval, *val; struct nodec *root = new_nodec(); int tagname_len = 0; int attname_len = 0; int attval_len = 0; struct nodec *curnode = root; struct nodec *temp; struct attc *curatt = NULL; char *cpos = &xmlin[0]; int pos = 0; int res = 0; int dent; register int let; #ifdef DEBUG printf("Entry to C Parser\n"); #endif val_1: #ifdef DEBUG printf("val_1: %c\n", *cpos); #endif let = *cpos; switch( let ) { case 0: goto done; case '<': goto val_x; } if( !curnode->numvals ) { curnode->value = cpos; curnode->vallen = 1; } curnode->numvals++; cpos++; val_x: #ifdef DEBUG printf("val_x: %c\n", *cpos); #endif let = *cpos; switch( let ) { case 0: goto done; case '<': switch( *(cpos+1) ) { case '!': if( *(cpos+2) == '[' ) { // type = 1; goto cdata; } else { cpos++; cpos++; goto val_x;//actually goto error... } } else if( *(cpos+2) == '-' && //