

/* cift2-c.c -- CIF test 2, C part */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "cifccsp.h"

void first_process (Process *me, Channel *out)
{
	int i;

	for (i = 0;; i++) {
		ChanOutInt (out, i);
		ProcAfter (50000);
	}
}

void t_first_process (Process *me, Channel *out) {
	first_process (me, out);
}

void second_process (Process *me, Channel *in, Channel *out)
{
	for (;;) {
		int i;

		ChanInInt (in, &i);
		i = i * 2;
		ChanOutInt (out, i);
	}
}

void t_second_process (Process *me, Channel *in, Channel *out)
{
	second_process (me, in, out);
}

void third_process (Process *me, Channel *in, Channel *byteout)
{
	char txtbuf[64];

	for (;;) {
		int i;

		ChanInInt (in, &i);
		EXTERNAL_CALLN (sprintf, txtbuf, "0x%8.8x\n", (unsigned int)i);

		for (i = 0; txtbuf[i] != '\0'; i++) {
			ChanOutChar (byteout, txtbuf[i]);
		}
	}
}

void t_third_process (Process *me, Channel *in, Channel *byteout)
{
	third_process (me, in, byteout);
}

void real_cift2_0_init (int *raddr, Channel *out)
{
	Process *p = ProcAlloc (t_first_process, 1024, 1, out);

	*raddr = (int)p;
	return;
}

void real_cift2_1_init (int *raddr, Channel *in, Channel *out)
{
	Process *p = ProcAlloc (t_second_process, 1024, 2, in, out);

	*raddr = (int)p;
	return;
}

void real_cift2_2_init (int *raddr, Channel *in, Channel *byteout)
{
	Process *p = ProcAlloc (t_third_process, 2048, 2, in, byteout);

	*raddr = (int)p;
	return;
}

void _cift2_0_init (int *ws) { real_cift2_0_init ((int *)(ws[0]), (Channel *)(ws[1])); }
void _cift2_1_init (int *ws) { real_cift2_1_init ((int *)(ws[0]), (Channel *)(ws[1]), (Channel *)(ws[2])); }
void _cift2_2_init (int *ws) { real_cift2_2_init ((int *)(ws[0]), (Channel *)(ws[1]), (Channel *)(ws[2])); }

