/* * DATA STRUCTURES * ==== ========== * * FOR THE * === === * * DATA DECLARATION BUILDER * ==== =========== ======= * * This module provides the internal structures needed * for the data declaration builder. It is itself the * sort of output generated by the program (although a * bit optimized!) */ #include <dcw.h> #include "struct.h" declnlist build_declnlist( name, s, next ) char *name; shapelist s; declnlist next; { declnlist new = NEW( struct declnlist_str ); COPYOF( new->name, name ); new->shapes = s; new->next = next; return new; } void print_declnlist( d ) declnlist d; { for( ; d!=NULL; d=d->next ) { Puts( d->name ); Puts( " = " ); print_shapelist( d->shapes ); putchar( '\n' ); } } shapelist build_shapelist( id, p, pl, next ) char *id; paramlist p; printlist pl; shapelist next; { shapelist new = NEW( struct shapelist_str ); COPYOF( new->name, id ); new->params = p; new->pl = pl; new->next = next; return new; } void print_shape( s ) shapelist s; { Puts( s->name ); if( s->params ) { Puts( "( " ); print_paramlist( s->params ); Puts( " )" ); } putchar( ' ' ); print_printlist( s->pl ); } void print_shapelist( s ) shapelist s; { if( s != NULL ) { print_shape( s ); for( s=s->next; s!=NULL; s=s->next ) { Puts( "or " ); print_shape(s); } } } paramlist build_paramlist( type, id, next ) char *type, *id; paramlist next; { paramlist new = NEW( struct paramlist_str ); COPYOF( new->type, type ); COPYOF( new->name, id ); new->next = next; return new; } void print_paramlist( p ) paramlist p; { if( p != NULL ) { printf( "%s %s", p->type, p->name ); for( p=p->next; p!=NULL; p=p->next ) { printf( ", %s %s", p->type, p->name ); } } } printitem build_printitem_str( s ) char *s; { printitem new = NEW( struct printitem_str ); new->tag = printitem_is_str; new->str = s; return new; } printitem build_printitem_num( n ) int n; { printitem new = NEW( struct printitem_str ); new->tag = printitem_is_num; new->num = n; return new; } void print_printitem( i ) printitem i; { switch( i->tag ) { case printitem_is_num: printf( "%d ", i->num ); break; case printitem_is_str: printf( "\"%s\" ", i->str ); break; default: ABORT( ("datadec: print_printitem called with printitem tag = %d\n", i->tag ) ); } } printlist build_printlist( h, t ) printitem h; printlist t; { printlist new = NEW( struct printlist_str ); new->item = h; new->next = t; return new; } void print_printlist( p ) printlist p; { for( ; p!=NULL; p=p->next ) { print_printitem( p->item ); } }