Merge pull request #3523 from urbit/jb/restage-leer

vere: adds leer-jet in support of new +to-wain:format
This commit is contained in:
Joe Bryan 2020-10-14 12:56:17 -07:00 committed by GitHub
commit 6eb3890670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 135 additions and 69 deletions

View File

@ -98,6 +98,7 @@
u3_noun u3qe_jam(u3_atom);
u3_noun u3qe_mat(u3_atom);
u3_noun u3qe_rub(u3_atom, u3_atom);
u3_noun u3qe_leer(u3_atom);
u3_noun u3qe_lore(u3_atom);
u3_noun u3qe_loss(u3_noun, u3_noun);
u3_noun u3qe_lune(u3_atom);

View File

@ -108,6 +108,7 @@
u3_noun u3we_jam(u3_noun);
u3_noun u3we_mat(u3_noun);
u3_noun u3we_rub(u3_noun);
u3_noun u3we_leer(u3_noun);
u3_noun u3we_lore(u3_noun);
u3_noun u3we_loss(u3_noun);
u3_noun u3we_lune(u3_noun);

128
pkg/urbit/jets/e/leer.c Normal file
View File

@ -0,0 +1,128 @@
/* j/5/leer.c
**
*/
#include "all.h"
static u3_atom
_leer_cut(c3_w pos_w, c3_w len_w, u3_atom src)
{
if ( 0 == len_w ) {
return 0;
}
else {
u3i_slab sab_u;
u3i_slab_bare(&sab_u, 3, len_w);
sab_u.buf_w[sab_u.len_w - 1] = 0;
u3r_bytes(pos_w, len_w, sab_u.buf_y, src);
return u3i_slab_mint_bytes(&sab_u);
}
}
// Leaving the lore jet in place for backwards compatibility.
// TODO: remove u3[qw]e_lore (also from jet tree)
u3_noun
u3qe_lore(u3_atom lub)
{
c3_w len_w = u3r_met(3, lub);
c3_w pos_w = 0;
u3_noun tez = u3_nul;
while ( 1 ) {
c3_w meg_w = 0;
c3_y end_y;
c3_y byt_y;
while ( 1 ) {
if ( pos_w >= len_w ) {
byt_y = 0;
end_y = c3y;
break;
}
byt_y = u3r_byte(pos_w + meg_w, lub);
if ( (10 == byt_y) || (0 == byt_y) ) {
end_y = __(byt_y == 0);
break;
} else meg_w++;
}
if ((byt_y == 0) && ((pos_w + meg_w + 1) < len_w)) {
return u3m_bail(c3__exit);
}
if ( !_(end_y) && pos_w >= len_w ) {
return u3kb_flop(tez);
}
else {
tez = u3nc(_leer_cut(pos_w, meg_w, lub), tez);
if ( _(end_y) ) {
return u3kb_flop(tez);
}
pos_w += (meg_w + 1);
}
}
}
u3_noun
u3we_lore(u3_noun cor)
{
u3_noun lub;
if ( (u3_none == (lub = u3r_at(u3x_sam, cor))) ||
(c3n == u3ud(lub)) )
{
return u3m_bail(c3__fail);
} else {
return u3qe_lore(lub);
}
}
u3_noun
u3qe_leer(u3_atom txt)
{
u3_noun pro;
u3_noun* lit = &pro;
{
c3_w pos_w, i_w = 0, len_w = u3r_met(3, txt);
u3_noun* hed;
u3_noun* tel;
while ( i_w < len_w ) {
// scan till end or newline
//
for ( pos_w = i_w; i_w < len_w; ++i_w ) {
if ( 10 == u3r_byte(i_w, txt) ) {
break;
}
}
// append to list
//
*lit = u3i_defcons(&hed, &tel);
*hed = _leer_cut(pos_w, i_w - pos_w, txt);
lit = tel;
i_w++;
}
}
*lit = u3_nul;
return pro;
}
u3_noun
u3we_leer(u3_noun cor)
{
u3_noun txt = u3x_at(u3x_sam, cor);
if ( c3n == u3ud(txt) ) {
return u3m_bail(c3__fail);
}
return u3qe_leer(txt);
}

View File

@ -1,69 +0,0 @@
/* j/5/lore.c
**
*/
#include "all.h"
u3_noun
u3qe_lore(u3_atom lub)
{
c3_w len_w = u3r_met(3, lub);
c3_w pos_w = 0;
u3_noun tez = u3_nul;
while ( 1 ) {
c3_w meg_w = 0;
c3_y end_y;
c3_y byt_y;
while ( 1 ) {
if ( pos_w >= len_w ) {
byt_y = 0;
end_y = c3y;
break;
}
byt_y = u3r_byte(pos_w + meg_w, lub);
if ( (10 == byt_y) || (0 == byt_y) ) {
end_y = __(byt_y == 0);
break;
} else meg_w++;
}
if ((byt_y == 0) && ((pos_w + meg_w + 1) < len_w)) {
return u3m_bail(c3__exit);
}
{
c3_y* byts_y = 0;
if ( 0 != meg_w ) {
byts_y = alloca(meg_w);
u3r_bytes(pos_w, meg_w, byts_y, lub);
}
if ( _(end_y) ) {
return u3kb_flop(u3nc(u3i_bytes(meg_w, byts_y), tez));
}
if ( pos_w >= len_w ) {
return u3kb_flop(tez);
}
tez = u3nc(u3i_bytes(meg_w, byts_y), tez);
pos_w += (meg_w + 1);
}
}
}
u3_noun
u3we_lore(u3_noun cor)
{
u3_noun lub;
if ( (u3_none == (lub = u3r_at(u3x_sam, cor))) ||
(c3n == u3ud(lub)) )
{
return u3m_bail(c3__fail);
} else {
return u3qe_lore(lub);
}
}

View File

@ -230,6 +230,10 @@ static c3_c* _141_hex_aes_ha[] = {
0
};
static u3j_harm _141_hex_leer_a[] = {{".2", u3we_leer}, {}};
static c3_c* _141_hex_leer_ha[] = {
0
};
static u3j_harm _141_hex_lore_a[] = {{".2", u3we_lore}, {}};
static c3_c* _141_hex_lore_ha[] = {
"19b13cfea49fd14aafbb20b8b888ba454f809c3f50a7cfeebd43f87336fe052d",
@ -413,6 +417,7 @@ static c3_c* _141_hex_ripe_ha[] = {
static u3j_core _141_hex_d[] =
{ { "lore", 63, _141_hex_lore_a, 0, _141_hex_lore_ha },
{ "leer", 63, _141_hex_leer_a, 0, _141_hex_leer_ha },
{ "loss", 63, _141_hex_loss_a, 0, _141_hex_loss_ha },
{ "lune", 127, _141_hex_lune_a, 0, _141_hex_lune_ha },