shrub/j/6/hike.c

146 lines
3.1 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/hike.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
/* internal tools
*/
/* _lily_hike_belt_root(): convert (pac) to a list of root tools.
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_lily_hike_belt_root(
2014-09-06 00:13:24 +04:00
u3_noun pac)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( (u3_nul == pac) ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_atom axis = u3h(u3h(pac));
u3_noun tool = u3t(u3h(pac));
u3_noun list_tool = _lily_hike_belt_root(u3t(pac));
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3_cr_sing(1, axis) ) {
return u3nc(u3k(tool),
2013-09-29 00:21:18 +04:00
list_tool);
}
else return list_tool;
}
}
/* _lily_hike_belt_l(): factor (pac) left.
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_lily_hike_belt_l(
2014-09-06 00:13:24 +04:00
u3_noun pac)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( (u3_nul == pac) ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_atom axis = u3h(u3h(pac));
u3_noun tool = u3t(u3h(pac));
u3_noun belt_l = _lily_hike_belt_l(u3t(pac));
2013-09-29 00:21:18 +04:00
{
2014-08-21 01:18:34 +04:00
if ( (1 != axis) &&
2014-09-06 00:13:24 +04:00
(u3_yes == u3_cr_sing(2, u3_cqc_cap(axis))) )
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_atom axis_tap = u3_cqc_mas(axis);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
return u3nc(
u3nc(
u3k(axis_tap),
u3k(tool)),
2013-09-29 00:21:18 +04:00
belt_l);
}
else return belt_l;
}
}
}
/* _lily_hike_belt_r(): factor (pac) right.
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_lily_hike_belt_r(
2014-09-06 00:13:24 +04:00
u3_noun pac)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( (u3_nul == pac) ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_atom axis = u3h(u3h(pac));
u3_noun tool = u3t(u3h(pac));
u3_noun belt_r = _lily_hike_belt_r(u3t(pac));
2013-09-29 00:21:18 +04:00
{
2014-08-21 01:18:34 +04:00
if ( (1 != axis) &&
2014-09-06 00:13:24 +04:00
(u3_yes == u3_cr_sing(3, u3_cqc_cap(axis))) )
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_atom axis_tap = u3_cqc_mas(axis);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
return u3nc(
u3nc(u3k(axis_tap),
u3k(tool)),
2013-09-29 00:21:18 +04:00
belt_r);
}
else return belt_r;
}
}
}
/* functions
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqf_hike(
u3_noun axe,
u3_noun pac)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( (u3_nul == pac) ) {
return u3nc(0, u3k(axe));
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun zet = _lily_hike_belt_root(pac);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_nul != zet ) {
u3_noun fol = u3k(u3h(zet));
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(zet);
2013-09-29 00:21:18 +04:00
return fol;
}
else {
2014-09-06 00:13:24 +04:00
u3_noun tum = _lily_hike_belt_l(pac);
u3_noun gam = _lily_hike_belt_r(pac);
u3_noun hax = u3_cqc_peg(axe, 2);
u3_noun moz = u3_cqc_peg(axe, 3);
u3_noun zip = u3_cqf_hike(hax, tum);
u3_noun dof = u3_cqf_hike(moz, gam);
u3_noun fol = u3_cqf_cons(zip, dof);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(tum);
u3z(gam);
u3z(hax);
u3z(moz);
u3z(zip);
u3z(dof);
2013-09-29 00:21:18 +04:00
return fol;
}
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwf_hike(
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun axe, pac;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( (u3_no == u3_cr_mean(cor, u3_cv_sam_2, &axe, u3_cv_sam_3, &pac, 0)) ||
(u3_no == u3ud(axe)) )
2013-09-29 00:21:18 +04:00
{
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_hike(axe, pac);
2013-09-29 00:21:18 +04:00
}
}