
/* cift1-c.c -- CIF test 1, 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 out_string (char *str, Channel *out)
{
	unsigned char *ch = (unsigned char *)str;

//fprintf (stderr, "out_string: chucking stuff out..\n");
	while (*ch != '\0') {
		ChanOutChar (out, *ch);
		ch++;
	}
	return;
}

void my_process (Process *me, Channel *kroc_err)
{
	out_string ("Hello, world! (from C)\n", kroc_err);
	return;
}


/* allocates process and returns address to occam world */
void real_cift1_init (int *raddr, Channel *c)
{
	Process *p = ProcAlloc (my_process, 8192, 1, c);

	*raddr = (int)p;
	return;
}

/* frees memory used by a process -- lets hope it's finished :) */
void real_cift1_free (int addr)
{
	Process *p = (Process *)addr;

	ProcAllocClean (p);
	return;
}

void _cift1_init (int *ws) { real_cift1_init ((int *)(ws[0]), (Channel *)(ws[1])); }
void _cift1_free (int *ws) { real_cift1_free ((int)(ws[0])); }

