shrub/j/6/look.c

135 lines
3.1 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/look.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
/* internals
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_look_in(
2014-09-06 00:13:24 +04:00
u3_noun cog,
u3_noun dab,
u3_atom axe)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_nul == dab ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun n_dab, l_dab, r_dab;
2014-09-06 00:13:24 +04:00
u3_cr_trel(dab, &n_dab, &l_dab, &r_dab);
2014-11-05 04:18:47 +03:00
if ( c3n == u3du(n_dab) ) {
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__fail);
}
2013-09-29 00:21:18 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun pn_dab = u3h(n_dab);
u3_noun qn_dab = u3t(n_dab);
2014-09-06 00:13:24 +04:00
if ( (u3_nul == l_dab) && (u3_nul == r_dab) ) {
2014-11-05 04:18:47 +03:00
if ( (c3y == u3du(qn_dab)) &&
(c3y == u3_cr_sing(cog, pn_dab)) ) {
2014-09-06 00:13:24 +04:00
return u3nt(u3_nul,
u3k(axe),
u3k(qn_dab));
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
return u3_nul;
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
else if ( (u3_nul == l_dab) ) {
2014-11-05 04:18:47 +03:00
if ( (c3y == u3du(qn_dab)) &&
(c3y == u3_cr_sing(cog, pn_dab)) ) {
2014-09-06 00:13:24 +04:00
return u3nt(u3_nul,
u3_cqc_peg(axe, 2),
u3k(qn_dab));
2013-09-29 00:21:18 +04:00
}
else {
2014-11-05 04:18:47 +03:00
if ( c3y == u3_cqc_gor(cog, pn_dab) ) {
2014-09-06 00:13:24 +04:00
return u3_nul;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun pro;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
axe = u3_cqc_peg(axe, 3);
2014-08-21 01:18:34 +04:00
pro = _look_in(cog, r_dab, axe);
2014-09-06 00:13:24 +04:00
u3z(axe);
2013-09-29 00:21:18 +04:00
return pro;
}
}
}
2014-09-06 00:13:24 +04:00
else if ( (u3_nul == r_dab) ) {
2014-11-05 04:18:47 +03:00
if ( (c3y == u3du(qn_dab)) &&
(c3y == u3_cr_sing(cog, pn_dab)) ) {
2014-09-06 00:13:24 +04:00
return u3nt(u3_nul,
u3_cqc_peg(axe, 2),
u3k(qn_dab));
2013-09-29 00:21:18 +04:00
}
else {
2014-11-05 04:18:47 +03:00
if ( c3y == u3_cqc_gor(cog, pn_dab) ) {
2014-09-06 00:13:24 +04:00
u3_noun pro;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
axe = u3_cqc_peg(axe, 3);
2014-08-21 01:18:34 +04:00
pro = _look_in(cog, l_dab, axe);
2014-09-06 00:13:24 +04:00
u3z(axe);
2013-09-29 00:21:18 +04:00
return pro;
}
else {
2014-09-06 00:13:24 +04:00
return u3_nul;
2013-09-29 00:21:18 +04:00
}
}
}
else {
2014-11-05 04:18:47 +03:00
if ( (c3y == u3du(qn_dab)) &&
(c3y == u3_cr_sing(cog, pn_dab)) ) {
2014-09-06 00:13:24 +04:00
return u3nt(u3_nul,
u3_cqc_peg(axe, 2),
u3k(qn_dab));
2013-09-29 00:21:18 +04:00
}
else {
2014-11-05 04:18:47 +03:00
if ( c3y == u3_cqc_gor(cog, pn_dab) ) {
2014-09-06 00:13:24 +04:00
u3_noun pro;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
axe = u3_cqc_peg(axe, 6);
2014-08-21 01:18:34 +04:00
pro = _look_in(cog, l_dab, axe);
2014-09-06 00:13:24 +04:00
u3z(axe);
2013-09-29 00:21:18 +04:00
return pro;
}
else {
2014-09-06 00:13:24 +04:00
u3_noun pro;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
axe = u3_cqc_peg(axe, 7);
2014-08-21 01:18:34 +04:00
pro = _look_in(cog, r_dab, axe);
2014-09-06 00:13:24 +04:00
u3z(axe);
2013-09-29 00:21:18 +04:00
return pro;
}
}
}
}
}
}
/* functions
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqf_look(
u3_noun cog,
u3_noun dab)
2013-09-29 00:21:18 +04:00
{
2014-08-21 01:18:34 +04:00
return _look_in(cog, dab, 1);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwf_look(
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun cog, dab;
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
if ( c3n == u3_cr_mean(cor, u3_cv_sam_2, &cog, u3_cv_sam_3, &dab, 0) ) {
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3_cqf_look(cog, dab);
2013-09-29 00:21:18 +04:00
}
}