2013-09-29 00:21:18 +04:00
|
|
|
/* j/3/po.c
|
|
|
|
**
|
|
|
|
** This file is in the public domain.
|
|
|
|
*/
|
|
|
|
#include "all.h"
|
|
|
|
#include "../pit.h"
|
|
|
|
|
|
|
|
// good old linear search
|
|
|
|
//
|
|
|
|
static u2_noun
|
|
|
|
_po_find(u2_noun buf, u2_noun a)
|
|
|
|
{
|
2014-08-20 05:39:48 +04:00
|
|
|
if ( u2_ne(u2_co_is_cat(a)) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
return u2_nul;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
c3_w i_w;
|
|
|
|
c3_w a_w = a;
|
|
|
|
|
|
|
|
for ( i_w = 0; i_w < 256; i_w++ ) {
|
|
|
|
c3_y byt_y[3];
|
|
|
|
c3_w but_w;
|
|
|
|
|
|
|
|
u2_cr_bytes((i_w * 3), 3, byt_y, buf);
|
|
|
|
but_w = (byt_y[0] | (byt_y[1] << 8) | (byt_y[2] << 16));
|
|
|
|
|
|
|
|
if ( but_w == a_w ) {
|
|
|
|
return u2nc(u2_nul, i_w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return u2_nul;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun
|
|
|
|
u2_cwcp_ins(
|
|
|
|
u2_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
u2_noun x, a, buf;
|
|
|
|
|
2014-08-20 05:39:48 +04:00
|
|
|
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam, &a, u2_cv_con_sam, &x, 0)) ||
|
2013-09-29 00:21:18 +04:00
|
|
|
(u2_no == u2du(x)) ||
|
|
|
|
(u2_no == u2ud(buf = u2h(x))) ||
|
|
|
|
(u2_no == u2ud(a)) )
|
|
|
|
{
|
2014-08-20 05:39:48 +04:00
|
|
|
return u2_cm_bail(c3__exit);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
|
|
|
return _po_find(buf, a);
|
|
|
|
}
|
|
|
|
}
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun
|
|
|
|
u2_cwcp_ind(
|
|
|
|
u2_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
u2_noun x, a, buf;
|
|
|
|
|
2014-08-20 05:39:48 +04:00
|
|
|
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam, &a, u2_cv_con_sam, &x, 0)) ||
|
2013-09-29 00:21:18 +04:00
|
|
|
(u2_no == u2du(x)) ||
|
|
|
|
(u2_no == u2ud(buf = u2t(x))) ||
|
|
|
|
(u2_no == u2ud(a)) )
|
|
|
|
{
|
2014-08-20 05:39:48 +04:00
|
|
|
return u2_cm_bail(c3__exit);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
|
|
|
return _po_find(buf, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun
|
|
|
|
u2_cwcp_tos(
|
|
|
|
u2_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
u2_noun x, a, buf;
|
|
|
|
|
2014-08-20 05:39:48 +04:00
|
|
|
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam, &a, u2_cv_con_sam, &x, 0)) ||
|
2013-09-29 00:21:18 +04:00
|
|
|
(u2_no == u2du(x)) ||
|
|
|
|
(u2_no == u2ud(buf = u2h(x))) ||
|
|
|
|
(u2_no == u2ud(a)) ||
|
2014-04-22 05:22:11 +04:00
|
|
|
(a >= 256) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-20 05:39:48 +04:00
|
|
|
return u2_cm_bail(c3__exit);
|
2014-04-22 05:22:11 +04:00
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
else {
|
|
|
|
c3_y byt_y[3];
|
|
|
|
|
|
|
|
u2_cr_bytes((a * 3), 3, byt_y, buf);
|
|
|
|
return (byt_y[0] | (byt_y[1] << 8) | (byt_y[2] << 16));
|
|
|
|
}
|
|
|
|
}
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun
|
|
|
|
u2_cwcp_tod(
|
|
|
|
u2_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
u2_noun x, a, buf;
|
|
|
|
|
2014-08-20 05:39:48 +04:00
|
|
|
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam, &a, u2_cv_con_sam, &x, 0)) ||
|
2013-09-29 00:21:18 +04:00
|
|
|
(u2_no == u2du(x)) ||
|
|
|
|
(u2_no == u2ud(buf = u2t(x))) ||
|
|
|
|
(u2_no == u2ud(a)) ||
|
2014-04-22 05:22:11 +04:00
|
|
|
(a >= 256) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-20 05:39:48 +04:00
|
|
|
return u2_cm_bail(c3__exit);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
|
|
|
c3_y byt_y[3];
|
|
|
|
|
|
|
|
u2_cr_bytes((a * 3), 3, byt_y, buf);
|
|
|
|
return (byt_y[0] | (byt_y[1] << 8) | (byt_y[2] << 16));
|
|
|
|
}
|
|
|
|
}
|