#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

#include <mex.h>
#include <ctl.h>

#include <mexhelper.h>

extern "C"
{
void mexFunction (int nresults, mxArray **arrresults, int nargs,
		const mxArray **arrargs)
{
	if (nargs < 2)
	{
		std::cerr << "Usage: use(typeName, location)";
		return;
	}

	char *type, *loc;
	type = mxArrayToString(arrargs[0]);
	loc = mxArrayToString(arrargs[1]);

	ctl::link lnk(loc);
	if(!lnk)
	{
    	std::cerr <<"Could not create link -> " << "\"" << loc << "\"\n";
		return;
	}

	initEnv();
	ctl::setLink(type, lnk);
}
}
