urbit/j/f/fitz.c

71 lines
1.4 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/fitz.c
**
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2013-09-29 00:21:18 +04:00
/* functions
*/
2014-11-06 06:10:22 +03:00
static u3_noun
2014-08-21 01:18:34 +04:00
_fitz_fiz(
2014-09-06 00:13:24 +04:00
u3_noun yaz,
u3_noun wix)
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
c3_w yaz_w = u3r_met(3, yaz);
c3_w wix_w = u3r_met(3, wix);
2013-09-29 00:21:18 +04:00
c3_y yaz_y, wix_y;
2014-11-06 03:20:01 +03:00
yaz_y = (0 == yaz_w) ? 0 : u3r_byte((yaz_w - 1), yaz);
2013-09-29 00:21:18 +04:00
if ( (yaz_y < 'A') || (yaz_y > 'Z') ) yaz_y = 0;
2014-11-06 03:20:01 +03:00
wix_y = (0 == wix_w) ? 0 : u3r_byte((wix_w - 1), wix);
2013-09-29 00:21:18 +04:00
if ( (wix_y < 'A') || (wix_y > 'Z') ) wix_y = 0;
if ( yaz_y && wix_y ) {
if ( !wix_y || (wix_y > yaz_y) ) {
2014-11-05 04:18:47 +03:00
return c3n;
2013-09-29 00:21:18 +04:00
}
}
2014-11-05 04:18:47 +03:00
return c3y;
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
u3qf_fitz(
2014-09-06 00:13:24 +04:00
u3_noun yaz,
u3_noun wix)
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
c3_w i_w, met_w = c3_min(u3r_met(3, yaz), u3r_met(3, wix));
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
if ( c3n == _fitz_fiz(yaz, wix) ) {
return c3n;
2013-09-29 00:21:18 +04:00
}
for ( i_w = 0; i_w < met_w; i_w++ ) {
2014-11-06 03:20:01 +03:00
c3_y yaz_y = u3r_byte(i_w, yaz);
c3_y wix_y = u3r_byte(i_w, wix);
2013-09-29 00:21:18 +04:00
if ( (yaz_y >= 'A') && (yaz_y <= 'Z') ) yaz_y = 0;
if ( (wix_y >= 'A') && (wix_y <= 'Z') ) wix_y = 0;
if ( yaz_y && wix_y && (yaz_y != wix_y) ) {
2014-11-05 04:18:47 +03:00
return c3n;
2013-09-29 00:21:18 +04:00
}
}
2014-11-05 04:18:47 +03:00
return c3y;
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
u3wf_fitz(
2014-09-06 00:13:24 +04:00
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun yaz, wix;
2013-09-29 00:21:18 +04:00
2014-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam_2, &yaz, u3x_sam_3, &wix, 0)) ||
2014-11-05 04:18:47 +03:00
(c3n == u3ud(yaz)) ||
(c3n == u3ud(wix)) )
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-11-06 22:13:57 +03:00
return u3qf_fitz(yaz, wix);
2013-09-29 00:21:18 +04:00
}
}