Skip to content
Snippets Groups Projects
struct.c 2.99 KiB
Newer Older
dcw's avatar
dcw committed
/*
 *                   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!)
dcw's avatar
dcw committed
 */


#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( " = " );
dcw's avatar
dcw committed
                print_shapelist( d->shapes );
                putchar( '\n' );
dcw's avatar
dcw committed
        }
}


shapelist build_shapelist( id, p, pl, next ) char *id; paramlist p; printlist pl; shapelist next;
dcw's avatar
dcw committed
{
        shapelist new = NEW( struct shapelist_str );

        COPYOF( new->name, id );
dcw's avatar
dcw committed
        new->params = p;
dcw's avatar
dcw committed
        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 );
}


dcw's avatar
dcw committed
void print_shapelist( s ) shapelist s;
{
        if( s != NULL ) {
		print_shape( s );
dcw's avatar
dcw committed
                for( s=s->next; s!=NULL; s=s->next ) {
                        Puts( "or " );
			print_shape(s);
dcw's avatar
dcw committed
                }
        }
}


paramlist build_paramlist( type, id, next ) char *type, *id; paramlist next;
dcw's avatar
dcw committed
{
        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;
dcw's avatar
dcw committed
{
        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 );
                }
dcw's avatar
dcw committed
        }
}


printitem build_printitem_str( s ) char *s;
dcw's avatar
dcw committed
{
	printitem new = NEW( struct printitem_str );
dcw's avatar
dcw committed

	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 );
	}
dcw's avatar
dcw committed
}