#include <stdio.h>
#include MUT_H
#include MLO_H
#include MLU_H
#include MPH_H
#include MPU_H
#include SCR_H
#include "mbkgen.h"
#include "util.h"

void ROUTE_CHANNEL(va_alist)
va_dcl
{
ptype_list *pt = NULL;
va_list args;
channel_list *ch;
char *s;
int i;

	if (WORK_PHFIG == NULL) {
		(void)fflush(stdout);
		(void)fputs("*** genlib error ***\n", stderr);
		(void)fputs("Illegal ROUTE_CHANNEL : missing DEF_PHFIG\n", stderr);
		EXIT(1);
	}
	va_start(arg);
	figname = namealloc(va_arg(arg, char *));
	while (1) {
		
		if (!(s = namealloc(checkname(va_arg(arg, char *)))))
			break;
		if (!(i = ((va_arg(arg, int) + 1) * 2) / 2)) {
			fflush(stdout);
			(void)fputs("*** genlib error ***\n", stderr);
			(void)fputs("Illegal ROUTE_CHANNEL : 0 width supply\n", stderr);
			EXIT(1);
		}
		pt = addptype(pt, i, s);
	}

	lf = getlofig(argv[1], 'A');
	ch = checkandbuild(WORK_PHFIG, lf, pt);
	routechannel(WORK_PHFIG, ch);
	destroysegments(getphfig(ch->NAME, 'A'), null);
	verticalmerge(getphfig(ch->NAME, 'A'));
	makeblock(pf, ch);
}
