2013-09-29 00:21:18 +04:00
|
|
|
/* j/6/crop.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
|
|
|
static u3_noun
|
|
|
|
_crop_dext(u3_noun, u3_noun, u3_noun, u3_noun);
|
|
|
|
static u3_noun
|
|
|
|
_crop_sint(u3_noun, u3_noun, u3_noun, u3_noun);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2014-08-21 01:18:34 +04:00
|
|
|
_crop_repo(
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun ref,
|
|
|
|
u3_noun bix)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun rep = u3_cqfu_repo(van, sut);
|
|
|
|
u3_noun ret = _crop_dext(van, rep, ref, bix);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3y == u3_cr_sing(ret, rep) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
if ( c3__void == rep ) {
|
|
|
|
return c3__void;
|
|
|
|
} else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(rep);
|
|
|
|
u3z(ret);
|
|
|
|
return u3k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(rep);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2014-08-21 01:18:34 +04:00
|
|
|
_crop_dext(
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun ref,
|
|
|
|
u3_noun bix)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun p_sut, q_sut, p_ref, q_ref;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3n == u3du(ref) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
switch ( ref ) {
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__void: return u3k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
case c3__noun: return c3__void;
|
2014-09-06 00:13:24 +04:00
|
|
|
default: return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3y == u3_cr_sing(sut, ref) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
return c3__void;
|
|
|
|
}
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3n == u3du(sut) ) switch ( sut ) {
|
2014-09-06 00:13:24 +04:00
|
|
|
default: return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
case c3__noun: return _crop_repo(van, sut, ref, bix);
|
2013-09-29 00:21:18 +04:00
|
|
|
case c3__void: return c3__void;
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
else switch ( u3h(sut) ) {
|
|
|
|
default: return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
case c3__atom:
|
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( c3__atom == u3h(ref) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
return c3__void;
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
else if ( c3__cell == u3h(ref) ) {
|
|
|
|
return u3k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
else return _crop_sint(van, sut, ref, bix);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__bull: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
|
2013-12-26 21:12:07 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun foz = _crop_dext(van, q_sut, ref, bix);
|
|
|
|
u3_noun ret = u3_cqf_bull(p_sut, foz);
|
2013-12-26 21:12:07 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(foz);
|
2013-12-26 21:12:07 +04:00
|
|
|
return ret;
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__cell: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( c3__atom == u3h(ref) ) {
|
|
|
|
return u3k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
else if ( c3__cell == u3h(ref) ) {
|
|
|
|
u3_cx_cell(u3t(ref), &p_ref, &q_ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3y == u3_cqfu_nest
|
|
|
|
(van, p_ref, c3n, p_sut) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun foz = _crop_dext(van, q_sut, q_ref, bix);
|
|
|
|
u3_noun ret = u3_cqf_cell(p_sut, foz);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(foz);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
else return u3k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
else return _crop_sint(van, sut, ref, bix);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-04-22 05:22:11 +04:00
|
|
|
case c3__core:
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (c3__atom == u3h(ref)) || (c3__cell == u3h(ref)) ) {
|
|
|
|
return u3k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
else return _crop_sint(van, sut, ref, bix);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__cube: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (c3__cube == u3h(ref)) &&
|
2014-11-05 04:18:47 +03:00
|
|
|
(c3y == u3_cr_sing(p_sut, u3h(u3t(ref)))) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
return c3__void;
|
2014-04-22 05:22:11 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
else if ( (c3__atom == u3h(ref)) || (c3__cell == u3h(ref)) ) {
|
|
|
|
u3_noun foz = _crop_dext(van, q_sut, ref, bix);
|
|
|
|
u3_noun ret;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3y == u3_cqfu_firm(van, foz, p_sut) ) {
|
2014-09-06 00:13:24 +04:00
|
|
|
ret = u3_cqf_cube(p_sut, foz);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else ret = c3__void;
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(foz);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
else return _crop_sint(van, sut, ref, bix);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__face: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun foz = _crop_dext(van, q_sut, ref, bix);
|
|
|
|
u3_noun ret = u3_cqf_face(p_sut, foz);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(foz);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__fork: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun dis = _crop_dext(van, p_sut, ref, bix);
|
|
|
|
u3_noun dat = _crop_dext(van, q_sut, ref, bix);
|
|
|
|
u3_noun ret = u3_cqf_fork(dis, dat);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(dis);
|
|
|
|
u3z(dat);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__hold: p_sut = u3t(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun hud = u3nc(u3k(sut), u3k(ref));
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3y == u3_cqdi_has(bix, hud) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
# if 0
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun dun = u3_cqfu_dunq(van, "type", sut);
|
|
|
|
u3_noun niz = u3_cqfu_dunq(van, "over", ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_ct_push(u3nc(c3__mean, dun));
|
|
|
|
u3_ct_push(u3nc(c3__mean, niz));
|
2013-09-29 00:21:18 +04:00
|
|
|
# endif
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3_cm_error("crop-loop");
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun bux = u3_cqdi_put(bix, hud);
|
|
|
|
u3_noun ret = _crop_repo(van, sut, ref, bux);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(hud);
|
|
|
|
u3z(bux);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2014-08-21 01:18:34 +04:00
|
|
|
_crop_sint(
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun ref,
|
|
|
|
u3_noun bix)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun p_ref, q_ref;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
switch ( u3h(ref) ) {
|
|
|
|
default: return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__bull: u3_cx_cell(u3t(ref), &p_ref, &q_ref);
|
2013-12-26 21:12:07 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
return _crop_dext(van, sut, q_ref, bix);
|
2013-12-26 21:12:07 +04:00
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
case c3__core:
|
2013-12-26 21:12:07 +04:00
|
|
|
case c3__cube: {
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__face: u3_cx_cell(u3t(ref), &p_ref, &q_ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
return _crop_dext(van, sut, q_ref, bix);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__fork: u3_cx_cell(u3t(ref), &p_ref, &q_ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun hin = _crop_dext(van, sut, p_ref, bix);
|
|
|
|
u3_noun ret = _crop_dext(van, hin, q_ref, bix);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(hin);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
case c3__hold: p_ref = u3t(ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun rep = u3_cqfu_repo(van, ref);
|
|
|
|
u3_noun ret = _crop_dext(van, sut, rep, bix);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(rep);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
2014-09-03 09:46:55 +04:00
|
|
|
_cqfu_crop(
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun ref)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
return _crop_dext(van, sut, ref, u3_nul);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* boilerplate
|
|
|
|
*/
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
|
|
|
u3_cwfu_crop(
|
|
|
|
u3_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun sut, ref, van;
|
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, &ref, u3_cv_con, &van, 0)) ||
|
2014-11-06 02:36:30 +03:00
|
|
|
(u3_none == (sut = u3_cr_at(u3_cv_sam, van))) )
|
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-03 09:46:55 +04:00
|
|
|
return _cqfu_crop(van, sut, ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
|
|
|
u3_cqfu_crop(u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun ref)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-28 23:40:40 +04:00
|
|
|
c3_m fun_m = c3__crop;
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun pro = u3_cz_find_2(fun_m, sut, ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-06 02:36:30 +03:00
|
|
|
if ( u3_none != pro ) {
|
2014-08-28 23:40:40 +04:00
|
|
|
return pro;
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-03 09:46:55 +04:00
|
|
|
pro = _cqfu_crop(van, sut, ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3_cz_save_2(fun_m, sut, ref, pro);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|