示例#1
0
文件: bttrace.cpp 项目: CapelliC/IL
//-----------------
// set tracer mode
//
BtFImpl(tracemode, t, p)
{
	Term cp = p->copy(t.getarg(0)), a;

	static ArgALIter::aDesc keys[4] = {
		{ "ext",	f_INT },
		{ "file",	f_ATOM },
		{ "on",		f_NOTERM },
		{ "off",	f_NOTERM }
	};
	ArgALIter it(cp, keys, sizeof(keys) / sizeof(keys[0]));
	unsigned ixk;

	for ( ; ; ) {
		switch (it.nextarg(&ixk, &a)) {

		case ArgALIter::KeyValue:
			if (ixk == 0) {
				Int i = Int(a);
				if (i > 0)
					p->tracer()->etrace_on();
				else
					p->tracer()->etrace_off();
			}
			if (ixk == 1) {
				ofstream *f = new ofstream(a);
				if (f->good()) //is_open())
					p->tracer()->setoutput(f);
				else {
					delete f;
					goto err;
				}
			}
			break;

		case ArgALIter::Key:
			if (ixk == 2)
				p->tracer()->trace_on();
			if (ixk == 3)
				p->tracer()->trace_off();
			break;

		case ArgALIter::EndArgs:
			cp.Destroy();
			return 1;

		default:
			goto err;
		}
	}

err:
	p->BtErr(BTERR_INVALID_ARG_TYPE);
	cp.Destroy();

	return 0;
}
示例#2
0
文件: iafx.cpp 项目: CapelliC/IL
/////////////////////////////////////////////////////////////////
// attempt a parse and call
//	if query succeed, copy vars values to v[] (up to nv elements)
//	you must guarantee that nv >= 'num of vars in src'
//
IIFTYPE(int) IAFX_QueryString(const char *src, EngHandle h, Term **var_val, kstr_list *var_ids)
{
	int rc = -1;	// if some error occurs
	IntlogExec *ile = GetEngines()->HtoD(h);

	if (ile != 0)
	{
		// prepare input source stream
		IntlogParser* parser = GetEngines()->get_parser();
        istringstream srcstream(src);

		// save status
		parser->SetSource(&srcstream, "QueryString", var_ids);

		// submit source line: if parse ok, query
		if (parser->getinput() == IntlogParser::NewClause)
		{
			Term tparsed = parser->parsed;

			int nv = var_ids->numel();
			if (nv > 0)
				*var_val = new Term[nv];

			rc = runquery(ile, tparsed, var_ids, *var_val, var_ids->numel());

			tparsed.Destroy();
		}
	}

	// some error occurred
	return rc;
}
示例#3
0
文件: bttrace.cpp 项目: CapelliC/IL
//-------------------------
// scan argument specifier and
//
static int setspy(IntlogExec *p, Term t, int on)
{
	Term cp = p->copy(t), a, r;
	ArgALIter it(cp, 0, 0);

	for ( ; ; ) {
		kstring funct;
		int arity = -1;

		switch (it.nextarg(0, &a)) {

		case ArgALIter::Pair:
			if (!(r = a.getarg(1)).type(f_INT))
				goto err;

			arity = Int(r);
			a = a.getarg(0);

			// fall through!

		case ArgALIter::Single:
			if (!a.type(f_ATOM))
				goto err;
			funct = a.kstr();
			break;

		default:
			goto err;

		case ArgALIter::EndArgs:
			cp.Destroy();
			return 1;
		}

		p->tracer()->spy(funct, on, arity);
	}

err:
	p->BtErr(BTERR_INVALID_ARG_TYPE);
	cp.Destroy();
	return 0;
}