/* struct.c */ #include #include #include "struct.h" void init_exp( struct exp* p ) { p->s = INIT; p->depth = 0; } int set_vexp( struct exp* p, char* s ) { if ( p->s == L_NODE ) return 2; p->v.s = malloc( sizeof ( char ) * ( strlen( s ) + 1 ) ); if ( p->v.s == NULL ) return 1; strcpy( p->v.s, s ); p->s = B_NODE; return 0; } int add_node_exp( struct exp* p, struct exp* a ) { if ( p->s == B_NODE ) return 2; p->v.n[p->depth++] = a; p->s = L_NODE; return 0; } /* ERROR PROBLEM IS HEAR */ void destroy_exp( struct exp* p ) /* warning: this recursively destroys the *ENTIRE* tree */ { if ( p->s == B_NODE ) /* we free the string if base */ free( p->v.s ); for ( ; p->depth > 0; p->depth-- ) destroy_exp( p->v.n[p->depth] ); /* we recursively destroy ALL nodes of the list */ free( p ); /* we destroy the node itself */ }