urbit/j/f/ut_fink.c

80 lines
1.7 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/fink.c
**
** This file is in the public domain.
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2013-09-29 00:21:18 +04:00
/* logic
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-09-03 09:46:55 +04:00
_cqfu_fink(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun dep,
u3_noun way,
u3_noun cog)
2013-09-29 00:21:18 +04:00
{
2014-11-06 22:13:57 +03:00
u3_noun dun = u3qfu_dunq(van, "type", sut);
2014-09-06 00:13:24 +04:00
u3_noun nuc = (u3_blip == cog)
2014-11-06 22:13:57 +03:00
? u3qfu_shew
2014-08-21 01:18:34 +04:00
(van,
2014-09-06 00:13:24 +04:00
u3nc
2014-11-06 03:20:01 +03:00
(u3nc('c', u3i_string("find-limb")),
2013-09-29 00:21:18 +04:00
'$'))
2014-11-06 22:13:57 +03:00
: u3qfu_shep
2014-09-06 00:13:24 +04:00
(van, "find-limb", 'a', u3k(cog));
u3_noun pro;
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
u3t_push(u3nc(c3__mean, dun));
u3t_push(u3nc(c3__mean, nuc));
2013-09-29 00:21:18 +04:00
{
2014-11-06 22:13:57 +03:00
u3_noun hoq = u3qfu_find(van, sut, dep, way, cog);
2014-09-06 00:13:24 +04:00
u3_noun fin = u3t(hoq);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_nul == fin ) {
2014-11-06 03:20:01 +03:00
u3m_p("cog", cog);
return u3m_error("find-none");
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
pro = u3k(u3t(fin));
u3z(hoq);
2013-09-29 00:21:18 +04:00
}
}
2014-11-06 03:20:01 +03:00
u3t_drop();
u3t_drop();
2013-09-29 00:21:18 +04:00
return pro;
}
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3wfu_fink(u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun sut, dep, way, cog, van;
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_mean(cor, u3v_sam_2, &dep,
u3v_sam_6, &way,
u3v_sam_7, &cog,
u3v_con, &van,
2013-09-29 00:21:18 +04:00
0)) ||
2014-11-06 03:20:01 +03:00
(u3_none == (sut = u3r_at(u3v_sam, van))) )
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-03 09:46:55 +04:00
return _cqfu_fink(van, sut, dep, way, cog);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3qfu_fink(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun dep,
u3_noun way,
u3_noun cog)
2013-09-29 00:21:18 +04:00
{
2014-09-03 09:46:55 +04:00
return _cqfu_fink(van, sut, dep, way, cog);
2013-09-29 00:21:18 +04:00
}