compiles and links.

This commit is contained in:
C. Guy Yarvin 2014-09-10 17:01:32 -07:00
parent 57278a5a1d
commit a71a657680
32 changed files with 2511 additions and 3524 deletions

View File

@ -261,7 +261,6 @@ V_OFILES=\
v/loop.o \ v/loop.o \
v/raft.o \ v/raft.o \
v/reck.o \ v/reck.o \
v/save.o \
v/sist.o \ v/sist.o \
v/term.o \ v/term.o \
v/time.o \ v/time.o \

2
g/a.c
View File

@ -1,4 +1,4 @@
/* n/a.c /* g/a.c
** **
** This file is in the public domain. ** This file is in the public domain.
*/ */

2
g/h.c
View File

@ -1,4 +1,4 @@
/* n/h.c /* g/h.c
** **
** This file is in the public domain. ** This file is in the public domain.
*/ */

2
g/i.c
View File

@ -1,4 +1,4 @@
/* n/i.c /* g/i.c
** **
** This file is in the public domain. ** This file is in the public domain.
*/ */

2
g/j.c
View File

@ -1,4 +1,4 @@
/* n/j.c /* g/j.c
** **
** This file is in the public domain. ** This file is in the public domain.
*/ */

32
g/m.c
View File

@ -1,7 +1,8 @@
/* c/m.c /* g/m.c
** **
** This file is in the public domain. ** This file is in the public domain.
*/ */
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -9,7 +10,7 @@
/* u3_cm_file(): load file, as atom, or bail. /* u3_cm_file(): load file, as atom, or bail.
*/ */
static u3_noun u3_noun
u3_cm_file(c3_c* pas_c) u3_cm_file(c3_c* pas_c)
{ {
struct stat buf_b; struct stat buf_b;
@ -111,7 +112,7 @@ u3_cm_boot(c3_p adr_p, c3_w len_w)
exit(1); exit(1);
} }
printf("loom: mapped %dMB\n", (len_w >> 18)); printf("loom: mapped %dMB\n", (len_w >> 18));
u3L = map_v; u3_Loom = map_v;
u3H = (u3_cs_home *)_boot_north(map_v, c3_wiseof(u3_cs_home), len_w); u3H = (u3_cs_home *)_boot_north(map_v, c3_wiseof(u3_cs_home), len_w);
u3R = &u3H->rod_u; u3R = &u3H->rod_u;
} }
@ -241,10 +242,14 @@ u3_cm_leap()
u3_road* rod_u; u3_road* rod_u;
if ( u3_yes == u3_co_is_north ) { if ( u3_yes == u3_co_is_north ) {
rod_u = _boot_south(u3R->hat_w, (u3R->cap_w - u3R->hat_w)); rod_u = _boot_south(u3R->hat_w,
c3_wiseof(u3_cs_road),
(u3R->cap_w - u3R->hat_w));
} }
else { else {
rod_u = _boot_north(u3R->cap_w, (u3R->hat_w - u3R->cap_w)); rod_u = _boot_north(u3R->cap_w,
c3_wiseof(u3_cs_road),
(u3R->hat_w - u3R->cap_w));
} }
c3_assert(0 == u3R->kid_u); c3_assert(0 == u3R->kid_u);
@ -294,26 +299,25 @@ u3_cm_flog(c3_w gof_w)
void void
u3_cm_water(c3_w* low_w, c3_w* hig_w) u3_cm_water(c3_w* low_w, c3_w* hig_w)
{ {
c3_assert(u3R == u3H); c3_assert(u3R == &u3H->rod_u);
*low_w = (u3H->hat_w - u3H->rut_w); *low_w = (u3H->rod_u.hat_w - u3H->rod_u.rut_w);
*hig_w = (u3H->mat_w - u3H->cap_w) + c3_wiseof(u3_road); *hig_w = (u3H->rod_u.mat_w - u3H->rod_u.cap_w) + c3_wiseof(u3_cs_home);
} }
/* u2_cm_soft(): system soft wrapper. unifies unix and nock errors. /* u3_cm_soft(): system soft wrapper. unifies unix and nock errors.
** **
** Produces [%$ result] or [%error (list tank)]. ** Produces [%$ result] or [%error (list tank)].
*/ */
u2_noun u3_noun
u2_cm_soft(c3_w sec_w, u2_funk fun_f, u2_noun arg) u3_cm_soft(c3_w sec_w, u3_funk fun_f, u3_noun arg)
{ {
u2_noun why_a; u3_noun why_a;
u3_noun ton;
u3_cm_leap(); u3_cm_leap();
if ( u3_no == (why_a = u3_cm_trap()) ) { if ( u3_no == (why_a = u3_cm_trap()) ) {
u3_noun ton;
if ( 0 != u3R->net.nyd ) { if ( 0 != u3R->net.nyd ) {
c3_assert(0); // XX actually, convert to error c3_assert(0); // XX actually, convert to error
} }

2
g/n.c
View File

@ -1,4 +1,4 @@
/* n/n.c /* g/n.c
** **
** This file is in the public domain. ** This file is in the public domain.
*/ */

2
g/r.c
View File

@ -1,4 +1,4 @@
/* n/r.c /* g/r.c
** **
** This file is in the public domain. ** This file is in the public domain.
*/ */

2
g/t.c
View File

@ -1,4 +1,4 @@
/* n/t.c /* g/t.c
** **
** This file is in the public domain. ** This file is in the public domain.
*/ */

2
g/x.c
View File

@ -1,4 +1,4 @@
/* n/x.c /* g/x.c
** **
** This file is in the public domain. ** This file is in the public domain.
*/ */

2
g/z.c
View File

@ -1,4 +1,4 @@
/* n/z.c /* g/z.c
** **
** This file is in the public domain. ** This file is in the public domain.
*/ */

View File

@ -1,277 +0,0 @@
/* genxxx/watt.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "pit.h"
/* declarations
*/
/* models
*/
extern u2_ho_jet j2_mbj(PtM, tape)[];
/* tier 1
*/
extern u2_ho_jet j2_mbj(Pt1, add)[];
extern u2_ho_jet j2_mbj(Pt1, dec)[];
extern u2_ho_jet j2_mbj(Pt1, div)[];
extern u2_ho_jet j2_mbj(Pt1, gte)[];
extern u2_ho_jet j2_mbj(Pt1, gth)[];
extern u2_ho_jet j2_mbj(Pt1, lte)[];
extern u2_ho_jet j2_mbj(Pt1, lth)[];
extern u2_ho_jet j2_mbj(Pt1, mod)[];
extern u2_ho_jet j2_mbj(Pt1, mul)[];
extern u2_ho_jet j2_mbj(Pt1, sub)[];
/* tier 2
*/
extern u2_ho_jet j2_mbj(Pt2, bind)[];
extern u2_ho_jet j2_mbj(Pt2, clap)[];
extern u2_ho_jet j2_mbj(Pt2, drop)[];
extern u2_ho_jet j2_mbj(Pt2, flop)[];
extern u2_ho_jet j2_mbj(Pt2, lent)[];
extern u2_ho_jet j2_mbj(Pt2, levy)[];
extern u2_ho_jet j2_mbj(Pt2, lien)[];
extern u2_ho_jet j2_mbj(Pt2, need)[];
extern u2_ho_jet j2_mbj(Pt2, reel)[];
extern u2_ho_jet j2_mbj(Pt2, roll)[];
extern u2_ho_jet j2_mbj(Pt2, skim)[];
extern u2_ho_jet j2_mbj(Pt2, skip)[];
extern u2_ho_jet j2_mbj(Pt2, scag)[];
extern u2_ho_jet j2_mbj(Pt2, slag)[];
extern u2_ho_jet j2_mbj(Pt2, snag)[];
extern u2_ho_jet j2_mbj(Pt2, turn)[];
extern u2_ho_jet j2_mbj(Pt2, weld)[];
/* tier 3
*/
extern u2_ho_jet j2_mbj(Pt3, bex)[];
extern u2_ho_jet j2_mbj(Pt3, can)[];
extern u2_ho_jet j2_mbj(Pt3, cap)[];
extern u2_ho_jet j2_mbj(Pt3, cat)[];
extern u2_ho_jet j2_mbj(Pt3, con)[];
extern u2_ho_jet j2_mbj(Pt3, cut)[];
extern u2_ho_jet j2_mbj(Pt3, dis)[];
extern u2_ho_jet j2_mbj(Pt3, dor)[];
extern u2_ho_jet j2_mbj(Pt3, end)[];
extern u2_ho_jet j2_mbj(Pt3, gor)[];
extern u2_ho_jet j2_mbj(Pt3, hor)[];
extern u2_ho_jet j2_mbj(Pt3, lsh)[];
extern u2_ho_jet j2_mbj(Pt3, mas)[];
extern u2_ho_jet j2_mbj(Pt3, met)[];
extern u2_ho_jet j2_mbj(Pt3, mix)[];
extern u2_ho_jet j2_mbj(Pt3, mug)[];
extern u2_ho_jet j2_mbj(Pt3, mum)[];
extern u2_ho_jet j2_mbj(Pt3, mur)[];
extern u2_ho_jet j2_mbj(Pt3, peg)[];
extern u2_ho_jet j2_mbj(Pt3, rap)[];
extern u2_ho_jet j2_mbj(Pt3, rip)[];
extern u2_ho_jet j2_mbj(Pt3, ryp)[];
extern u2_ho_jet j2_mbj(Pt3, rsh)[];
extern u2_ho_jet j2_mbj(Pt3, vor)[];
extern u2_ho_driver j2_mbd(Pt3, po)[];
/* tier 4
*/
extern u2_ho_driver j2_mbd(Pt4, in)[];
extern u2_ho_driver j2_mbd(Pt4, by)[];
/* tier 5
*/
extern u2_ho_jet j2_mbj(Pt5, cue)[];
extern u2_ho_jet j2_mbj(Pt5, mat)[];
extern u2_ho_jet j2_mbj(Pt5, mink)[];
extern u2_ho_jet j2_mbj(Pt5, mule)[];
extern u2_ho_jet j2_mbj(Pt5, jam)[];
extern u2_ho_jet j2_mbj(Pt5, loss)[];
extern u2_ho_jet j2_mbj(Pt5, lore)[];
extern u2_ho_jet j2_mbj(Pt5, pfix)[];
extern u2_ho_jet j2_mbj(Pt5, plug)[];
extern u2_ho_jet j2_mbj(Pt5, pose)[];
extern u2_ho_jet j2_mbj(Pt5, repg)[];
extern u2_ho_jet j2_mbj(Pt5, rexp)[];
extern u2_ho_jet j2_mbj(Pt5, rub)[];
extern u2_ho_jet j2_mbj(Pt5, sfix)[];
extern u2_ho_jet j2_mbj(Pt5, shax)[];
extern u2_ho_jet j2_mbj(Pt5, tape)[];
extern u2_ho_jet j2_mbj(Pt5, trip)[];
extern u2_ho_driver j2_mbd(Pt5, aesc)[];
extern u2_ho_driver j2_mbd(Pt5, bend)[];
extern u2_ho_driver j2_mbd(Pt5, cold)[];
extern u2_ho_driver j2_mbd(Pt5, comp)[];
extern u2_ho_driver j2_mbd(Pt5, cook)[];
extern u2_ho_driver j2_mbd(Pt5, easy)[];
extern u2_ho_driver j2_mbd(Pt5, coco)[];
extern u2_ho_driver j2_mbd(Pt5, coed)[];
extern u2_ho_driver j2_mbd(Pt5, glue)[];
extern u2_ho_driver j2_mbd(Pt5, here)[];
extern u2_ho_driver j2_mbd(Pt5, just)[];
extern u2_ho_driver j2_mbd(Pt5, mask)[];
extern u2_ho_driver j2_mbd(Pt5, og)[];
extern u2_ho_driver j2_mbd(Pt5, rd)[];
extern u2_ho_driver j2_mbd(Pt5, shim)[];
extern u2_ho_driver j2_mbd(Pt5, stag)[];
extern u2_ho_driver j2_mbd(Pt5, stew)[];
extern u2_ho_driver j2_mbd(Pt5, stir)[];
/* tier 6
*/
extern u2_ho_jet j2_mbj(Pt6, bull)[];
extern u2_ho_jet j2_mbj(Pt6, cell)[];
extern u2_ho_jet j2_mbj(Pt6, comb)[];
extern u2_ho_jet j2_mbj(Pt6, cons)[];
extern u2_ho_jet j2_mbj(Pt6, core)[];
extern u2_ho_jet j2_mbj(Pt6, cube)[];
extern u2_ho_jet j2_mbj(Pt6, face)[];
extern u2_ho_jet j2_mbj(Pt6, fitz)[];
extern u2_ho_jet j2_mbj(Pt6, flan)[];
extern u2_ho_jet j2_mbj(Pt6, flip)[];
extern u2_ho_jet j2_mbj(Pt6, flor)[];
extern u2_ho_jet j2_mbj(Pt6, fork)[];
extern u2_ho_jet j2_mbj(Pt6, hike)[];
extern u2_ho_jet j2_mbj(Pt6, look)[];
extern u2_ho_jet j2_mbj(Pt6, open)[];
extern u2_ho_jet j2_mbj(Pt6, rake)[];
extern u2_ho_jet j2_mbj(Pt6, ream)[];
extern u2_ho_jet j2_mbj(Pt6, vest)[];
extern u2_ho_jet j2_mbj(Pt6, ap)[];
extern u2_ho_driver j2_mbd(Pt6, ap)[];
extern u2_ho_jet j2_mbj(Pt6, ut)[];
extern u2_ho_driver j2_mbd(Pt6, ut)[];
/* structures
*/
static u2_ho_driver
_watt_drivers_0[],
_watt_drivers_1[],
_watt_drivers_2[];
u2_ho_driver
j2_da(Pt0) = { j2_sa(Pt0), 0, _watt_drivers_0, 0, u2_none };
static u2_ho_driver
_watt_drivers_0[] = {
{ j2_sb(Pt0, mood), 0, _watt_drivers_1, 0, u2_none },
{ }
};
static u2_ho_driver
_watt_drivers_1[] = {
{ j2_sb(PtM, tape), j2_mbj(PtM, tape), 0, 0, u2_none },
{ j2_sb(PtM, hoon), 0, _watt_drivers_2, 0, u2_none },
{ }
};
static u2_ho_driver
_watt_drivers_2[] = {
{ j2_sb(Pt1, add), j2_mbj(Pt1, add), 0, 0, u2_none },
{ j2_sb(Pt1, dec), j2_mbj(Pt1, dec), 0, 0, u2_none },
{ j2_sb(Pt1, div), j2_mbj(Pt1, div), 0, 0, u2_none },
{ j2_sb(Pt1, gte), j2_mbj(Pt1, gte), 0, 0, u2_none },
{ j2_sb(Pt1, gth), j2_mbj(Pt1, gth), 0, 0, u2_none },
{ j2_sb(Pt1, lte), j2_mbj(Pt1, lte), 0, 0, u2_none },
{ j2_sb(Pt1, lth), j2_mbj(Pt1, lth), 0, 0, u2_none },
{ j2_sb(Pt1, mod), j2_mbj(Pt1, mod), 0, 0, u2_none },
{ j2_sb(Pt1, mul), j2_mbj(Pt1, mul), 0, 0, u2_none },
{ j2_sb(Pt1, sub), j2_mbj(Pt1, sub), 0, 0, u2_none },
{ j2_sb(Pt2, bind), j2_mbj(Pt2, bind), 0, 0, u2_none },
{ j2_sb(Pt2, clap), j2_mbj(Pt2, clap), 0, 0, u2_none },
{ j2_sb(Pt2, drop), j2_mbj(Pt2, drop), 0, 0, u2_none },
{ j2_sb(Pt2, flop), j2_mbj(Pt2, flop), 0, 0, u2_none },
{ j2_sb(Pt2, lent), j2_mbj(Pt2, lent), 0, 0, u2_none },
{ j2_sb(Pt2, levy), j2_mbj(Pt2, levy), 0, 0, u2_none },
{ j2_sb(Pt2, lien), j2_mbj(Pt2, lien), 0, 0, u2_none },
{ j2_sb(Pt2, need), j2_mbj(Pt2, need), 0, 0, u2_none },
{ j2_sb(Pt2, reel), j2_mbj(Pt2, reel), 0, 0, u2_none },
{ j2_sb(Pt2, roll), j2_mbj(Pt2, roll), 0, 0, u2_none },
{ j2_sb(Pt2, skim), j2_mbj(Pt2, skim), 0, 0, u2_none },
{ j2_sb(Pt2, skip), j2_mbj(Pt2, skip), 0, 0, u2_none },
{ j2_sb(Pt2, scag), j2_mbj(Pt2, scag), 0, 0, u2_none },
{ j2_sb(Pt2, slag), j2_mbj(Pt2, slag), 0, 0, u2_none },
{ j2_sb(Pt2, snag), j2_mbj(Pt2, snag), 0, 0, u2_none },
{ j2_sb(Pt2, turn), j2_mbj(Pt2, turn), 0, 0, u2_none },
{ j2_sb(Pt2, weld), j2_mbj(Pt2, weld), 0, 0, u2_none },
{ j2_sb(Pt3, bex), j2_mbj(Pt3, bex), 0, 0, u2_none },
{ j2_sb(Pt3, can), j2_mbj(Pt3, can), 0, 0, u2_none },
{ j2_sb(Pt3, cap), j2_mbj(Pt3, cap), 0, 0, u2_none },
{ j2_sb(Pt3, cat), j2_mbj(Pt3, cat), 0, 0, u2_none },
{ j2_sb(Pt3, con), j2_mbj(Pt3, con), 0, 0, u2_none },
{ j2_sb(Pt3, cut), j2_mbj(Pt3, cut), 0, 0, u2_none },
{ j2_sb(Pt3, dor), j2_mbj(Pt3, dor), 0, 0, u2_none },
{ j2_sb(Pt3, dis), j2_mbj(Pt3, dis), 0, 0, u2_none },
{ j2_sb(Pt3, end), j2_mbj(Pt3, end), 0, 0, u2_none },
{ j2_sb(Pt3, gor), j2_mbj(Pt3, gor), 0, 0, u2_none },
{ j2_sb(Pt3, hor), j2_mbj(Pt3, hor), 0, 0, u2_none },
{ j2_sb(Pt3, lsh), j2_mbj(Pt3, lsh), 0, 0, u2_none },
{ j2_sb(Pt3, mas), j2_mbj(Pt3, mas), 0, 0, u2_none },
{ j2_sb(Pt3, met), j2_mbj(Pt3, met), 0, 0, u2_none },
{ j2_sb(Pt3, mix), j2_mbj(Pt3, mix), 0, 0, u2_none },
{ j2_sb(Pt3, mug), j2_mbj(Pt3, mug), 0, 0, u2_none },
{ j2_sb(Pt3, mum), j2_mbj(Pt3, mum), 0, 0, u2_none },
{ j2_sb(Pt3, mur), j2_mbj(Pt3, mur), 0, 0, u2_none },
{ j2_sb(Pt3, peg), j2_mbj(Pt3, peg), 0, 0, u2_none },
{ j2_sb(Pt3, rap), j2_mbj(Pt3, rap), 0, 0, u2_none },
{ j2_sb(Pt3, rip), j2_mbj(Pt3, rip), 0, 0, u2_none },
{ j2_sb(Pt3, rsh), j2_mbj(Pt3, rsh), 0, 0, u2_none },
{ j2_sb(Pt3, vor), j2_mbj(Pt3, vor), 0, 0, u2_none },
{ j2_sb(Pt3, po), 0, j2_mbd(Pt3, po), 0, u2_none },
{ j2_sb(Pt4, in), 0, j2_mbd(Pt4, in), 0, u2_none },
{ j2_sb(Pt4, by), 0, j2_mbd(Pt4, by), 0, u2_none },
{ j2_sb(Pt5, aesc), 0, j2_mbd(Pt5, aesc), 0, u2_none },
{ j2_sb(Pt5, bend), 0, j2_mbd(Pt5, bend), 0, u2_none },
{ j2_sb(Pt5, coco), 0, j2_mbd(Pt5, coco), 0, u2_none },
{ j2_sb(Pt5, coed), 0, j2_mbd(Pt5, coed), 0, u2_none },
{ j2_sb(Pt5, cold), 0, j2_mbd(Pt5, cold), 0, u2_none },
{ j2_sb(Pt5, comp), 0, j2_mbd(Pt5, comp), 0, u2_none },
{ j2_sb(Pt5, cook), 0, j2_mbd(Pt5, cook), 0, u2_none },
{ j2_sb(Pt5, cue), j2_mbj(Pt5, cue), 0, 0, u2_none },
{ j2_sb(Pt5, easy), 0, j2_mbd(Pt5, easy), 0, u2_none },
{ j2_sb(Pt5, glue), 0, j2_mbd(Pt5, glue), 0, u2_none },
{ j2_sb(Pt5, here), 0, j2_mbd(Pt5, here), 0, u2_none },
{ j2_sb(Pt5, jam), j2_mbj(Pt5, jam), 0, 0, u2_none },
{ j2_sb(Pt5, loss), j2_mbj(Pt5, loss), 0, 0, u2_none },
{ j2_sb(Pt5, lore), j2_mbj(Pt5, lore), 0, 0, u2_none },
{ j2_sb(Pt5, just), 0, j2_mbd(Pt5, just), 0, u2_none },
{ j2_sb(Pt5, mask), 0, j2_mbd(Pt5, mask), 0, u2_none },
{ j2_sb(Pt5, mat), j2_mbj(Pt5, mat), 0, 0, u2_none },
{ j2_sb(Pt5, mink), j2_mbj(Pt5, mink), 0, 0, u2_none },
{ j2_sb(Pt5, mule), j2_mbj(Pt5, mule), 0, 0, u2_none },
{ j2_sb(Pt5, og), 0, j2_mbd(Pt5, og), 0, u2_none },
{ j2_sb(Pt5, pfix), j2_mbj(Pt5, pfix), 0, 0, u2_none },
{ j2_sb(Pt5, plug), j2_mbj(Pt5, plug), 0, 0, u2_none },
{ j2_sb(Pt5, pose), j2_mbj(Pt5, pose), 0, 0, u2_none },
{ j2_sb(Pt5, rd), 0, j2_mbd(Pt5, rd), 0, u2_none },
{ j2_sb(Pt5, repg), j2_mbj(Pt5, repg), 0, 0, u2_none },
{ j2_sb(Pt5, rexp), j2_mbj(Pt5, rexp), 0, 0, u2_none },
{ j2_sb(Pt5, rub), j2_mbj(Pt5, rub), 0, 0, u2_none },
{ j2_sb(Pt5, sfix), j2_mbj(Pt5, sfix), 0, 0, u2_none },
{ j2_sb(Pt5, shax), j2_mbj(Pt5, shax), 0, 0, u2_none },
{ j2_sb(Pt5, shim), 0, j2_mbd(Pt5, shim), 0, u2_none },
{ j2_sb(Pt5, stag), 0, j2_mbd(Pt5, stag), 0, u2_none },
{ j2_sb(Pt5, stew), 0, j2_mbd(Pt5, stew), 0, u2_none },
{ j2_sb(Pt5, stir), 0, j2_mbd(Pt5, stir), 0, u2_none },
{ j2_sb(Pt5, trip), j2_mbj(Pt5, trip), 0, 0, u2_none },
{ j2_sb(Pt6, bull), j2_mbj(Pt6, bull), 0, 0, u2_none },
{ j2_sb(Pt6, cell), j2_mbj(Pt6, cell), 0, 0, u2_none },
{ j2_sb(Pt6, comb), j2_mbj(Pt6, comb), 0, 0, u2_none },
{ j2_sb(Pt6, cons), j2_mbj(Pt6, cons), 0, 0, u2_none },
{ j2_sb(Pt6, core), j2_mbj(Pt6, core), 0, 0, u2_none },
{ j2_sb(Pt6, cube), j2_mbj(Pt6, cube), 0, 0, u2_none },
{ j2_sb(Pt6, face), j2_mbj(Pt6, face), 0, 0, u2_none },
{ j2_sb(Pt6, fitz), j2_mbj(Pt6, fitz), 0, 0, u2_none },
{ j2_sb(Pt6, flan), j2_mbj(Pt6, flan), 0, 0, u2_none },
{ j2_sb(Pt6, flip), j2_mbj(Pt6, flip), 0, 0, u2_none },
{ j2_sb(Pt6, flor), j2_mbj(Pt6, flor), 0, 0, u2_none },
{ j2_sb(Pt6, fork), j2_mbj(Pt6, fork), 0, 0, u2_none },
{ j2_sb(Pt6, hike), j2_mbj(Pt6, hike), 0, 0, u2_none },
{ j2_sb(Pt6, look), j2_mbj(Pt6, look), 0, 0, u2_none },
{ j2_sb(Pt6, ap), j2_mbj(Pt6, ap), j2_mbd(Pt6, ap), 0, u2_none },
{ j2_sb(Pt6, ut), j2_mbj(Pt6, ut), j2_mbd(Pt6, ut), 0, u2_none },
{ }
};

View File

@ -65,6 +65,7 @@
# include "g/r.h" # include "g/r.h"
# include "g/t.h" # include "g/t.h"
# include "g/x.h" # include "g/x.h"
# include "g/v.h"
# include "g/z.h" # include "g/z.h"
/** j: the u2 layer, jets. /** j: the u2 layer, jets.

View File

@ -165,12 +165,12 @@
/* Stat struct /* Stat struct
*/ */
# if defined(U2_OS_linux) # if defined(U2_OS_linux)
# define c3_stat_mtime(dp) (u2_time_t_in_ts((dp)->st_mtime)) # define c3_stat_mtime(dp) (u3_time_t_in_ts((dp)->st_mtime))
# elif defined(U2_OS_osx) # elif defined(U2_OS_osx)
# define c3_stat_mtime(dp) (u2_time_in_ts(&((dp)->st_mtimespec))) # define c3_stat_mtime(dp) (u3_time_in_ts(&((dp)->st_mtimespec)))
# define lseek64 lseek # define lseek64 lseek
# elif defined(U2_OS_bsd) # elif defined(U2_OS_bsd)
# define c3_stat_mtime(dp) (u2_time_in_ts(&((dp)->st_mtim))) # define c3_stat_mtime(dp) (u3_time_in_ts(&((dp)->st_mtim)))
# define lseek64 lseek # define lseek64 lseek
# else # else
# error "port: timeconvert" # error "port: timeconvert"

View File

@ -16,7 +16,7 @@
typedef int8_t c3_ys; // signed byte typedef int8_t c3_ys; // signed byte
typedef uint8_t c3_b; // bit typedef uint8_t c3_b; // bit
// typedef uint8_t c3_t; // boolean typedef uint8_t c3_t; // boolean
typedef uint8_t c3_o; // loobean typedef uint8_t c3_o; // loobean
typedef uint8_t c3_g; // 32-bit log - 0-31 bits typedef uint8_t c3_g; // 32-bit log - 0-31 bits
typedef uint32_t c3_l; // little; 31-bit unsigned integer typedef uint32_t c3_l; // little; 31-bit unsigned integer

View File

@ -7,13 +7,12 @@
/* u3_Loom: base of loom, as a word pointer. /* u3_Loom: base of loom, as a word pointer.
*/ */
c3_global c3_w* u3_Loom; c3_global c3_w* u3_Loom;
# define u3L u3_Loom
/* u3_Home / u3H: root of thread. Always north. /* u3_Home / u3H: root of thread. Always north.
*/ */
c3_global u3_cs_home* u3_Home; c3_global u3_cs_home* u3_Home;
# define u3H u3_Home # define u3H u3_Home
# define u3A (u3_Home->arv_u) # define u3A (&(u3_Home->arv_u))
/* u3_Road / u3R: current road (thread-local). /* u3_Road / u3R: current road (thread-local).
*/ */

View File

@ -555,22 +555,15 @@
u3_bean liv; // if u3_no, shut down u3_bean liv; // if u3_no, shut down
c3_i xit_i; // exit code for shutdown c3_i xit_i; // exit code for shutdown
void* ssl_u; // struct SSL_CTX* void* ssl_u; // struct SSL_CTX*
u3_reck* arv_u; // runtime
} u3_host; // host == computer == process } u3_host; // host == computer == process
# define u3L u3_Host.lup_u // global event loop # define u3L u3_Host.lup_u // global event loop
# define u3R (&(u3_Raft)) # define u3Z (&(u3_Raft))
# define u3S u3_Host.ssl_u # define u3S u3_Host.ssl_u
/* u3_funk: standard system function.
*/
typedef u3_noun (*u3_funk)(u3_reck* rec_u, u3_noun);
/** Global variables. /** Global variables.
**/ **/
c3_global u3_host u3_Host; c3_global u3_host u3_Host;
c3_global u3_wire u3_Wire;
c3_global u3_raft u3_Raft; c3_global u3_raft u3_Raft;
c3_global c3_c* u3_Local; c3_global c3_c* u3_Local;
c3_global c3_c* u3_System; c3_global c3_c* u3_System;
@ -674,12 +667,12 @@
/* u3_sync_reck(): traverse filesystem for changes -> lamb /* u3_sync_reck(): traverse filesystem for changes -> lamb
*/ */
u3_noun u3_noun
u3_sync_reck(u3_reck* rec_u); u3_sync_reck(void);
/* u3_walk(): traverse `dir_c` to produce an arch, updating `old`. /* u3_walk(): traverse `dir_c` to produce an arch, updating `old`.
*/ */
u3_noun u3_noun
u3_walk(u3_reck* rec_u, const c3_c* dir_c, u3_noun old); u3_walk(const c3_c* dir_c, u3_noun old);
/* u3_path(): C unix path in computer for file or directory. /* u3_path(): C unix path in computer for file or directory.
*/ */
@ -722,118 +715,10 @@
void void
u3_ve_tank(c3_l tab_l, u3_noun tac); u3_ve_tank(c3_l tab_l, u3_noun tac);
/** Kernel control.
**/
/* u3_reck_do(): use a kernel function.
*/
# define u3_do(t, a) u3_reck_do(t, a)
# define u3_dc(t, a1, a2) u3_reck_do(t, u3nc(a1, a2))
# define u3_dt(t, a1, a2, a3) u3_reck_do(t, u3nt(a1, a2, a3))
# define u3_dq(t, a1, a2, a3, a4) u3_reck_do(t, u3nq(a1, a2, a3, a4))
u3_noun
u3_reck_do(const c3_c* txt_c, u3_noun arg);
/* u3_reck_line(): apply a reck line (protected).
*/
void
u3_reck_line(u3_reck* rec_u, u3_noun lin);
/* u3_reck_numb(): set the instance number.
*/
void
u3_reck_numb(u3_reck* rec_u);
/* u3_reck_http_request(): hear http request on channel.
*/
void
u3_reck_http_request(u3_reck* rec_u,
u3_bean sec,
u3_noun pox,
u3_noun req);
/* u3_reck_http_respond(): apply http response.
*/
void
u3_reck_http_respond(u3_reck* rec_u, u3_noun pox, u3_noun rep);
/* u3_reck_boot(): boot the reck engine (unprotected).
*/
void
u3_reck_boot(u3_reck* rec_u);
/* u3_reck_launch(): launch the reck engine (unprotected).
*/
u3_bean
u3_reck_launch(u3_reck* rec_u);
/* u3_reck_nick(): transform enveloped packets, [vir cor].
*/
u3_noun
u3_reck_nick(u3_reck* rec_u, u3_noun vir, u3_noun cor);
/* u3_reck_peek(): query the reck namespace (protected).
*/
u3_noun
u3_reck_peek(u3_reck* rec_u, u3_noun hap);
/* u3_reck_keep(): measure timer.
*/
u3_noun
u3_reck_keep(u3_reck* rec_u, u3_noun hap);
/* u3_reck_pike(): poke with floating core.
*/
u3_noun
u3_reck_pike(u3_reck* rec_u, u3_noun ovo, u3_noun cor);
/* u3_reck_poke(): insert and apply an input ovum (protected).
*/
u3_noun
u3_reck_poke(u3_reck* rec_u, u3_noun ovo);
/* u3_reck_prick(): query the reck namespace (unprotected).
*/
u3_noun
u3_reck_prick(u3_reck* rec_u, u3_noun hap);
/* u3_reck_kick(): handle effect. /* u3_reck_kick(): handle effect.
*/ */
void void
u3_reck_kick(u3_reck* rec_u, u3_noun ovo); u3_reck_kick(u3_noun ovo);
/* u3_reck_sync(): poll and apply sync events (protected).
*/
void
u3_reck_sync(u3_reck* rec_u);
/* u3_reck_time(): set the reck time.
*/
void
u3_reck_time(u3_reck* rec_u);
/* u3_reck_wind(): set the reck time artificially.
*/
void
u3_reck_wind(u3_reck* rec_u, u3_noun now);
/* u3_reck_plan(): queue ovum (external).
*/
void
u3_reck_plan(u3_reck* rec_u,
u3_noun pax,
u3_noun fav);
/* u3_reck_plow(): queue ovum list in order (external).
*/
void
u3_reck_plow(u3_reck* rec_u, u3_noun ova);
/* u3_reck_work(): flush ova (unprotected).
*/
void
u3_reck_work(u3_reck* rec_u);
/** Main loop, new style. /** Main loop, new style.
@ -846,7 +731,7 @@
/* u3_lo_lead(): actions on promotion to leader. /* u3_lo_lead(): actions on promotion to leader.
*/ */
void void
u3_lo_lead(u3_reck* rec_u); u3_lo_lead(void);
/* u3_lo_exit(): shut down io across pier. /* u3_lo_exit(): shut down io across pier.
*/ */
@ -862,7 +747,7 @@
/* u3_lo_bail(): clean up all event state. /* u3_lo_bail(): clean up all event state.
*/ */
void void
u3_lo_bail(u3_reck* rec_u); u3_lo_bail(void);
/* u3_lo_tank(): dump single tank. /* u3_lo_tank(): dump single tank.
*/ */
@ -879,13 +764,6 @@
void void
u3_lo_sway(c3_l tab_l, u3_noun tax); u3_lo_sway(c3_l tab_l, u3_noun tax);
/* u3_lo_soft(): standard soft wrapper. Unifies unix and nock errors.
**
** Produces [%$ result] or %error (list tank)].
*/
u3_noun
u3_lo_soft(u3_reck* rec_u, c3_w sec_w, u3_funk fun_f, u3_noun arg);
/* u3_lo_grab(): garbage-collect the world, plus roots; end with u3_none /* u3_lo_grab(): garbage-collect the world, plus roots; end with u3_none
*/ */
void void
@ -1152,7 +1030,8 @@
/* u3_raft_work(): poke, kick, and push pending events. /* u3_raft_work(): poke, kick, and push pending events.
*/ */
void void
u3_raft_work(u3_reck* rec_u); u3_raft_work(void);
/** Disk persistence. /** Disk persistence.
**/ **/
@ -1171,8 +1050,7 @@
** Returns the entry's sequence number. ** Returns the entry's sequence number.
*/ */
c3_d c3_d
u3_sist_pack(u3_reck* rec_u, u3_sist_pack(c3_w tem_w,
c3_w tem_w,
c3_w typ_w, c3_w typ_w,
c3_w* bob_w, c3_w* bob_w,
c3_w len_w); c3_w len_w);

View File

@ -904,13 +904,13 @@
else { else {
u3_noun n_hel, l_hel, r_hel; u3_noun n_hel, l_hel, r_hel;
u3_noun pn_hel, qn_hel; u3_noun pn_hel, qn_hel;
c3_t bit_t; c3_o bit_o;
u3_cx_trel(hel, &n_hel, &l_hel, &r_hel); u3_cx_trel(hel, &n_hel, &l_hel, &r_hel);
u3_cx_cell(n_hel, &pn_hel, &qn_hel); u3_cx_cell(n_hel, &pn_hel, &qn_hel);
if ( (u3_no == u3du(pn_hel)) ) { if ( (u3_no == u3du(pn_hel)) ) {
bit_t = (iq_tub == pn_hel); bit_o = u3_say((iq_tub == pn_hel));
} }
else { else {
u3_noun hpn_hel = u3h(pn_hel); u3_noun hpn_hel = u3h(pn_hel);
@ -920,10 +920,10 @@
u3_ne(u3_co_is_cat(tpn_hel)) ) { u3_ne(u3_co_is_cat(tpn_hel)) ) {
return _fail(tub); return _fail(tub);
} }
else bit_t = (iq_tub >= hpn_hel) && (iq_tub <= tpn_hel); else bit_o = u3_say((iq_tub >= hpn_hel) && (iq_tub <= tpn_hel));
} }
if ( bit_t ) { if ( u3_yes == bit_o ) {
return u3_cx_good return u3_cx_good
(u3_cn_slam_on(u3k(qn_hel), u3k(tub))); (u3_cn_slam_on(u3k(qn_hel), u3k(tub)));
} else { } else {

172
v/ames.c
View File

@ -49,9 +49,9 @@ _ames_free(void* ptr_v)
static c3_w static c3_w
_ames_czar(c3_y imp_y, c3_s* por_s) _ames_czar(c3_y imp_y, c3_s* por_s)
{ {
u2_ames* sam_u = &u2_Host.sam_u; u3_ames* sam_u = &u3_Host.sam_u;
if ( u2_yes == u2_Host.ops_u.loh ) { if ( u3_yes == u3_Host.ops_u.loh ) {
*por_s = 31337 + imp_y; *por_s = 31337 + imp_y;
return 0x7f000001; return 0x7f000001;
} }
@ -62,14 +62,14 @@ _ames_czar(c3_y imp_y, c3_s* por_s)
return 0; return 0;
} }
else if ( 0 == sam_u->imp_w[imp_y] ) { else if ( 0 == sam_u->imp_w[imp_y] ) {
u2_noun nam = u2_dc("scot", 'p', imp_y); u3_noun nam = u3_dc("scot", 'p', imp_y);
c3_c* nam_c = u2_cr_string(nam); c3_c* nam_c = u3_cr_string(nam);
c3_c dns_c[64]; c3_c dns_c[64];
snprintf(dns_c, 64, "%s.urbit.org", nam_c + 1); snprintf(dns_c, 64, "%s.urbit.org", nam_c + 1);
// uL(fprintf(uH, "czar %s, dns %s\n", nam_c, dns_c)); // uL(fprintf(uH, "czar %s, dns %s\n", nam_c, dns_c));
free(nam_c); free(nam_c);
u2z(nam); u3z(nam);
{ {
struct addrinfo* air_u; struct addrinfo* air_u;
@ -95,13 +95,13 @@ _ames_czar(c3_y imp_y, c3_s* por_s)
sam_u->imp_w[imp_y] = ntohl(add_u->sin_addr.s_addr); sam_u->imp_w[imp_y] = ntohl(add_u->sin_addr.s_addr);
#if 1 #if 1
{ {
u2_noun wad = u2_ci_words(1, &sam_u->imp_w[imp_y]); u3_noun wad = u3_ci_words(1, &sam_u->imp_w[imp_y]);
u2_noun nam = u2_dc("scot", c3__if, wad); u3_noun nam = u3_dc("scot", c3__if, wad);
c3_c* nam_c = u2_cr_string(nam); c3_c* nam_c = u3_cr_string(nam);
uL(fprintf(uH, "ames: czar %s: ip %s\n", dns_c, nam_c)); uL(fprintf(uH, "ames: czar %s: ip %s\n", dns_c, nam_c));
free(nam_c); u2z(nam); free(nam_c); u3z(nam);
} }
#endif #endif
break; break;
@ -118,30 +118,30 @@ _ames_czar(c3_y imp_y, c3_s* por_s)
/* _ames_lane_ipv4(): IPv4 address/ from lane. /* _ames_lane_ipv4(): IPv4 address/ from lane.
*/ */
u2_bean u3_bean
_ames_lane_ip(u2_noun lan, c3_s* por_s, c3_w* pip_w) _ames_lane_ip(u3_noun lan, c3_s* por_s, c3_w* pip_w)
{ {
switch ( u2h(lan) ) { switch ( u3h(lan) ) {
case c3__if: { case c3__if: {
*por_s= (c3_s) u2h(u2t(u2t(lan))); *por_s= (c3_s) u3h(u3t(u3t(lan)));
*pip_w = u2_cr_word(0, u2t(u2t(u2t(lan)))); *pip_w = u3_cr_word(0, u3t(u3t(u3t(lan))));
return u2_yes; return u3_yes;
} break; } break;
case c3__is: { case c3__is: {
u2_noun pq_lan = u2h(u2t(u2t(lan))); u3_noun pq_lan = u3h(u3t(u3t(lan)));
if ( u2_nul == pq_lan ) return u2_no; if ( u3_nul == pq_lan ) return u3_no;
else return _ames_lane_ip(u2t(pq_lan), por_s, pip_w); else return _ames_lane_ip(u3t(pq_lan), por_s, pip_w);
} break; } break;
case c3__ix: { case c3__ix: {
*por_s = (c3_s) u2h(u2t(u2t(lan))); *por_s = (c3_s) u3h(u3t(u3t(lan)));
*pip_w = u2_cr_word(0, u2t(u2t(u2t(lan)))); *pip_w = u3_cr_word(0, u3t(u3t(u3t(lan))));
return u2_yes; return u3_yes;
} break; } break;
} }
return u2_no; return u3_no;
} }
/* An unusual lameness in libuv. /* An unusual lameness in libuv.
@ -149,18 +149,18 @@ _ames_lane_ip(u2_noun lan, c3_s* por_s, c3_w* pip_w)
typedef struct { typedef struct {
uv_udp_send_t snd_u; uv_udp_send_t snd_u;
c3_y* buf_y; c3_y* buf_y;
} _u2_udp_send_t; } _u3_udp_send_t;
/* _ames_send_cb(): send callback. /* _ames_send_cb(): send callback.
*/ */
static void static void
_ames_send_cb(uv_udp_send_t* req_u, c3_i sas_i) _ames_send_cb(uv_udp_send_t* req_u, c3_i sas_i)
{ {
_u2_udp_send_t* ruq_u = (void*)req_u; _u3_udp_send_t* ruq_u = (void*)req_u;
#if 0 #if 0
if ( 0 != sas_i ) { if ( 0 != sas_i ) {
uL(fprintf(uH, "ames: send_cb: %s\n", uv_strerror(uv_last_error(u2L)))); uL(fprintf(uH, "ames: send_cb: %s\n", uv_strerror(uv_last_error(u3L))));
} }
#endif #endif
// fprintf(stderr, "ames: tx\r\n"); // fprintf(stderr, "ames: tx\r\n");
@ -169,36 +169,36 @@ _ames_send_cb(uv_udp_send_t* req_u, c3_i sas_i)
} }
void void
u2_ames_ef_bake(void) u3_ames_ef_bake(void)
{ {
u2_noun pax = u2nq(u2_blip, c3__newt, u2k(u2A->sen), u2_nul); u3_noun pax = u3nq(u3_blip, c3__newt, u3k(u3A->sen), u3_nul);
u2_reck_plan(u2A, pax, u2nc(c3__barn, u2_nul)); u3_cv_plan(pax, u3nc(c3__barn, u3_nul));
} }
/* u2_ames_ef_send(): send packet to network (v4). /* u3_ames_ef_send(): send packet to network (v4).
*/ */
void void
u2_ames_ef_send(u2_noun lan, u2_noun pac) u3_ames_ef_send(u3_noun lan, u3_noun pac)
{ {
u2_ames* sam_u = &u2_Host.sam_u; u3_ames* sam_u = &u3_Host.sam_u;
c3_s por_s; c3_s por_s;
c3_w pip_w; c3_w pip_w;
if ( u2_Host.ops_u.fuz_w && ((rand() % 100) < u2_Host.ops_u.fuz_w) ) { if ( u3_Host.ops_u.fuz_w && ((rand() % 100) < u3_Host.ops_u.fuz_w) ) {
u2z(pac); u3z(pac);
return; return;
} }
if ( u2_yes == _ames_lane_ip(lan, &por_s, &pip_w) ) { if ( u3_yes == _ames_lane_ip(lan, &por_s, &pip_w) ) {
c3_w len_w = u2_cr_met(3, pac); c3_w len_w = u3_cr_met(3, pac);
c3_y* buf_y = c3_malloc(len_w); c3_y* buf_y = c3_malloc(len_w);
u2_cr_bytes(0, len_w, buf_y, pac); u3_cr_bytes(0, len_w, buf_y, pac);
if ( 0 == pip_w ) { if ( 0 == pip_w ) {
pip_w = 0x7f000001; pip_w = 0x7f000001;
por_s = u2_Host.sam_u.por_s; por_s = u3_Host.sam_u.por_s;
} }
{ {
struct sockaddr_in add_u; struct sockaddr_in add_u;
@ -211,7 +211,7 @@ u2_ames_ef_send(u2_noun lan, u2_noun pac)
if ( 0 != pip_w ) { if ( 0 != pip_w ) {
uv_buf_t buf_u = uv_buf_init((c3_c*)buf_y, len_w); uv_buf_t buf_u = uv_buf_init((c3_c*)buf_y, len_w);
_u2_udp_send_t* ruq_u = c3_malloc(sizeof(_u2_udp_send_t)); _u3_udp_send_t* ruq_u = c3_malloc(sizeof(_u3_udp_send_t));
ruq_u->buf_y = buf_y; ruq_u->buf_y = buf_y;
@ -232,7 +232,7 @@ u2_ames_ef_send(u2_noun lan, u2_noun pac)
} }
} }
} }
u2z(lan); u2z(pac); u3z(lan); u3z(pac);
} }
/* _ames_time_cb(): timer callback. /* _ames_time_cb(): timer callback.
@ -240,17 +240,16 @@ u2_ames_ef_send(u2_noun lan, u2_noun pac)
static void static void
_ames_time_cb(uv_timer_t* tim_uo) _ames_time_cb(uv_timer_t* tim_uo)
{ {
u2_ames* sam_u = &u2_Host.sam_u; u3_ames* sam_u = &u3_Host.sam_u;
u2_lo_open(); u3_lo_open();
sam_u->law_w = time(0); sam_u->law_w = time(0);
{ {
u2_reck_plan u3_cv_plan
(u2A, (u3nt(u3_blip, c3__ames, u3_nul),
u2nt(u2_blip, c3__ames, u2_nul), u3nc(c3__wake, u3_nul));
u2nc(c3__wake, u2_nul));
} }
u2_lo_shut(u2_no); u3_lo_shut(u3_no);
} }
/* _ames_recv_cb(): receive callback. /* _ames_recv_cb(): receive callback.
@ -268,53 +267,52 @@ _ames_recv_cb(uv_udp_t* wax_u,
_ames_free(buf_u->base); _ames_free(buf_u->base);
} }
else { else {
u2_lo_open(); u3_lo_open();
{ {
struct sockaddr_in* add_u = (struct sockaddr_in *)adr_u; struct sockaddr_in* add_u = (struct sockaddr_in *)adr_u;
u2_noun msg = u2_ci_bytes((c3_w)nrd_i, (c3_y*)buf_u->base); u3_noun msg = u3_ci_bytes((c3_w)nrd_i, (c3_y*)buf_u->base);
c3_s por_s = ntohs(add_u->sin_port); c3_s por_s = ntohs(add_u->sin_port);
c3_w pip_w = ntohl(add_u->sin_addr.s_addr); c3_w pip_w = ntohl(add_u->sin_addr.s_addr);
// fprintf(stderr, "ames: plan\r\n"); // fprintf(stderr, "ames: plan\r\n");
u2_reck_plan u3_cv_plan
(u2A, (u3nt(u3_blip, c3__ames, u3_nul),
u2nt(u2_blip, c3__ames, u2_nul), u3nt(c3__hear,
u2nt(c3__hear, u3nq(c3__if, u3k(u3A->now), por_s, u3_ci_words(1, &pip_w)),
u2nq(c3__if, u2k(u2A->now), por_s, u2_ci_words(1, &pip_w)),
msg)); msg));
} }
_ames_free(buf_u->base); _ames_free(buf_u->base);
u2_lo_shut(u2_yes); u3_lo_shut(u3_yes);
} }
} }
/* u2_ames_io_init(): initialize ames I/O. /* u3_ames_io_init(): initialize ames I/O.
*/ */
void void
u2_ames_io_init() u3_ames_io_init()
{ {
u2_ames* sam_u = &u2_Host.sam_u; u3_ames* sam_u = &u3_Host.sam_u;
c3_s por_s; c3_s por_s;
por_s = u2_Host.ops_u.por_s; por_s = u3_Host.ops_u.por_s;
if ( 0 != u2_Host.ops_u.imp_c ) { if ( 0 != u3_Host.ops_u.imp_c ) {
u2_noun imp = u2_ci_string(u2_Host.ops_u.imp_c); u3_noun imp = u3_ci_string(u3_Host.ops_u.imp_c);
u2_noun num = u2_dc("slaw", 'p', imp); u3_noun num = u3_dc("slaw", 'p', imp);
c3_y num_y; c3_y num_y;
if ( u2_no == u2du(num) ) { if ( u3_no == u3du(num) ) {
uL(fprintf(uH, "malformed emperor: %s\n", u2_Host.ops_u.imp_c)); uL(fprintf(uH, "malformed emperor: %s\n", u3_Host.ops_u.imp_c));
exit(1); exit(1);
} }
num_y = u2_cr_byte(0, u2t(num)); num_y = u3_cr_byte(0, u3t(num));
_ames_czar(num_y, &por_s); _ames_czar(num_y, &por_s);
uL(fprintf(uH, "ames: czar: %s on %d\n", u2_Host.ops_u.imp_c, por_s)); uL(fprintf(uH, "ames: czar: %s on %d\n", u3_Host.ops_u.imp_c, por_s));
u2z(num); u3z(num);
} }
int ret; int ret;
if ( 0 != (ret = uv_udp_init(u2L, &u2_Host.sam_u.wax_u)) ) { if ( 0 != (ret = uv_udp_init(u3L, &u3_Host.sam_u.wax_u)) ) {
uL(fprintf(uH, "ames: init: %s\n", uv_strerror(ret))); uL(fprintf(uH, "ames: init: %s\n", uv_strerror(ret)));
c3_assert(0); c3_assert(0);
} }
@ -347,61 +345,61 @@ u2_ames_io_init()
// Timer too. // Timer too.
{ {
uv_timer_init(u2L, &sam_u->tim_u); uv_timer_init(u3L, &sam_u->tim_u);
} }
} }
/* u2_ames_io_talk(): start receiving ames traffic. /* u3_ames_io_talk(): start receiving ames traffic.
*/ */
void void
u2_ames_io_talk() u3_ames_io_talk()
{ {
u2_ames* sam_u = &u2_Host.sam_u; u3_ames* sam_u = &u3_Host.sam_u;
uL(fprintf(uH, "ames: on localhost, UDP %d.\n", sam_u->por_s)); uL(fprintf(uH, "ames: on localhost, UDP %d.\n", sam_u->por_s));
uv_udp_recv_start(&sam_u->wax_u, _ames_alloc, _ames_recv_cb); uv_udp_recv_start(&sam_u->wax_u, _ames_alloc, _ames_recv_cb);
} }
/* u2_ames_io_exit(): terminate ames I/O. /* u3_ames_io_exit(): terminate ames I/O.
*/ */
void void
u2_ames_io_exit() u3_ames_io_exit()
{ {
u2_ames* sam_u = &u2_Host.sam_u; u3_ames* sam_u = &u3_Host.sam_u;
uv_close((uv_handle_t*)&sam_u->wax_u, 0); uv_close((uv_handle_t*)&sam_u->wax_u, 0);
} }
/* u2_ames_io_poll(): update ames IO state. /* u3_ames_io_poll(): update ames IO state.
*/ */
void void
u2_ames_io_poll() u3_ames_io_poll()
{ {
u2_ames* sam_u = &u2_Host.sam_u; u3_ames* sam_u = &u3_Host.sam_u;
u2_noun wen = u2_reck_keep(u2A, u2nt(u2_blip, c3__ames, u2_nul)); u3_noun wen = u3_cv_keep(u3nt(u3_blip, c3__ames, u3_nul));
if ( (u2_nul != wen) && if ( (u3_nul != wen) &&
(u2_yes == u2du(wen)) && (u3_yes == u3du(wen)) &&
(u2_yes == u2ud(u2t(wen))) ) (u3_yes == u3ud(u3t(wen))) )
{ {
c3_d gap_d = u2_time_gap_ms(u2k(u2A->now), u2k(u2t(wen))); c3_d gap_d = u3_time_gap_ms(u3k(u3A->now), u3k(u3t(wen)));
c3_w lem_w = (time(0) - sam_u->law_w); c3_w lem_w = (time(0) - sam_u->law_w);
c3_w lef_w = (lem_w > 32) ? 0 : (32 - lem_w); c3_w lef_w = (lem_w > 32) ? 0 : (32 - lem_w);
gap_d = c3_min(gap_d, (c3_d)(1000 * lef_w)); gap_d = c3_min(gap_d, (c3_d)(1000 * lef_w));
if ( u2_yes == sam_u->alm ) { if ( u3_yes == sam_u->alm ) {
uv_timer_stop(&sam_u->tim_u); uv_timer_stop(&sam_u->tim_u);
} }
else sam_u->alm = u2_yes; else sam_u->alm = u3_yes;
uv_timer_start(&sam_u->tim_u, _ames_time_cb, gap_d, 0); uv_timer_start(&sam_u->tim_u, _ames_time_cb, gap_d, 0);
} }
else { else {
if ( u2_yes == sam_u->alm ) { if ( u3_yes == sam_u->alm ) {
uv_timer_stop(&sam_u->tim_u); uv_timer_stop(&sam_u->tim_u);
} }
sam_u->alm = u2_no; sam_u->alm = u3_no;
} }
u2z(wen); u3z(wen);
} }

View File

@ -19,24 +19,23 @@
#include <errno.h> #include <errno.h>
#include "all.h" #include "all.h"
#include "f/coal.h"
#include "v/vere.h" #include "v/vere.h"
/* u2_batz_io_init(): initialize batz timer. /* u3_batz_io_init(): initialize batz timer.
*/ */
void void
u2_batz_io_init(void) u3_batz_io_init(void)
{ {
u2_batz* beh_u = &u2_Host.beh_u; u3_batz* beh_u = &u3_Host.beh_u;
uv_timer_init(u2L, &beh_u->tim_u); uv_timer_init(u3L, &beh_u->tim_u);
beh_u->alm = u2_no; beh_u->alm = u3_no;
} }
/* u2_batz_io_exit(): terminate timer. /* u3_batz_io_exit(): terminate timer.
*/ */
void void
u2_batz_io_exit(void) u3_batz_io_exit(void)
{ {
} }
@ -45,49 +44,48 @@ u2_batz_io_exit(void)
static void static void
_batz_time_cb(uv_timer_t* tim_u) _batz_time_cb(uv_timer_t* tim_u)
{ {
u2_batz* beh_u = &u2_Host.beh_u; u3_batz* beh_u = &u3_Host.beh_u;
if(beh_u->run_w < 1024) { if(beh_u->run_w < 1024) {
beh_u->run_w++; beh_u->run_w++;
} }
u2_lo_open(); u3_lo_open();
{ {
u2_reck_plan u3_cv_plan
(u2A, (u3nt(u3_blip, c3__batz, u3_nul),
u2nt(u2_blip, c3__batz, u2_nul), u3nc(c3__wake, u3_nul));
u2nc(c3__wake, u2_nul));
} }
u2_lo_shut(u2_no); u3_lo_shut(u3_no);
} }
/* u2_batz_io_poll(): update batz IO state. /* u3_batz_io_poll(): update batz IO state.
*/ */
void void
u2_batz_io_poll(void) u3_batz_io_poll(void)
{ {
u2_batz* beh_u = &u2_Host.beh_u; u3_batz* beh_u = &u3_Host.beh_u;
u2_noun wen = u2_reck_keep(u2A, u2nt(u2_blip, c3__batz, u2_nul)); u3_noun wen = u3_cv_keep(u3nt(u3_blip, c3__batz, u3_nul));
if ( (u2_nul != wen) && if ( (u3_nul != wen) &&
(u2_yes == u2du(wen)) && (u3_yes == u3du(wen)) &&
(u2_yes == u2ud(u2t(wen))) ) (u3_yes == u3ud(u3t(wen))) )
{ {
c3_d gap_d = u2_time_gap_ms(u2k(u2A->now), u2k(u2t(wen))); c3_d gap_d = u3_time_gap_ms(u3k(u3A->now), u3k(u3t(wen)));
gap_d += beh_u->run_w; gap_d += beh_u->run_w;
if ( u2_yes == beh_u->alm ) { if ( u3_yes == beh_u->alm ) {
uv_timer_stop(&beh_u->tim_u); uv_timer_stop(&beh_u->tim_u);
} }
else beh_u->alm = u2_yes; else beh_u->alm = u3_yes;
uv_timer_start(&beh_u->tim_u, _batz_time_cb, gap_d, 0); uv_timer_start(&beh_u->tim_u, _batz_time_cb, gap_d, 0);
} }
else { else {
if ( u2_yes == beh_u->alm ) { if ( u3_yes == beh_u->alm ) {
uv_timer_stop(&beh_u->tim_u); uv_timer_stop(&beh_u->tim_u);
} }
beh_u->alm = u2_no; beh_u->alm = u3_no;
} }
u2z(wen); u3z(wen);
} }

628
v/cttp.c

File diff suppressed because it is too large Load Diff

379
v/http.c
View File

@ -23,9 +23,9 @@
#include "all.h" #include "all.h"
#include "v/vere.h" #include "v/vere.h"
static void _http_request(u2_hreq* req_u); static void _http_request(u3_hreq* req_u);
static void _http_request_dead(u2_hreq* req_u); static void _http_request_dead(u3_hreq* req_u);
static void _http_conn_dead(u2_hcon *hon_u); static void _http_conn_dead(u3_hcon *hon_u);
/* _http_alloc(): libuv buffer allocator. /* _http_alloc(): libuv buffer allocator.
*/ */
@ -41,10 +41,10 @@ _http_alloc(uv_handle_t* had_u,
/* _http_bod(): create a data buffer. /* _http_bod(): create a data buffer.
*/ */
static u2_hbod* static u3_hbod*
_http_bod(c3_w len_w, const c3_y* hun_y) _http_bod(c3_w len_w, const c3_y* hun_y)
{ {
u2_hbod* bod_u = c3_malloc(len_w + sizeof(*bod_u)); u3_hbod* bod_u = c3_malloc(len_w + sizeof(*bod_u));
bod_u->len_w = len_w; bod_u->len_w = len_w;
memcpy(bod_u->hun_y, hun_y, len_w); memcpy(bod_u->hun_y, hun_y, len_w);
@ -55,13 +55,13 @@ _http_bod(c3_w len_w, const c3_y* hun_y)
/* _http_bud(): create a header buffer. Not null-terminated! /* _http_bud(): create a header buffer. Not null-terminated!
*/ */
static u2_hbod* static u3_hbod*
_http_bud(c3_c* nam_c, c3_c* val_c) _http_bud(c3_c* nam_c, c3_c* val_c)
{ {
c3_w lnm_w = strlen(nam_c); c3_w lnm_w = strlen(nam_c);
c3_w lvl_w = strlen(val_c); c3_w lvl_w = strlen(val_c);
c3_w len_w = lnm_w + 2 + lvl_w + 2; c3_w len_w = lnm_w + 2 + lvl_w + 2;
u2_hbod* bod_u = c3_malloc(len_w + sizeof(*bod_u)); u3_hbod* bod_u = c3_malloc(len_w + sizeof(*bod_u));
strncpy((c3_c *)bod_u->hun_y, nam_c, lnm_w); strncpy((c3_c *)bod_u->hun_y, nam_c, lnm_w);
strncpy((c3_c *)bod_u->hun_y + lnm_w, ": ", 2); strncpy((c3_c *)bod_u->hun_y + lnm_w, ": ", 2);
@ -77,10 +77,10 @@ _http_bud(c3_c* nam_c, c3_c* val_c)
/* _http_heds_free(): free header structure. /* _http_heds_free(): free header structure.
*/ */
static void static void
_http_heds_free(u2_hhed* hed_u) _http_heds_free(u3_hhed* hed_u)
{ {
while ( hed_u ) { while ( hed_u ) {
u2_hhed* nex_u = hed_u->nex_u; u3_hhed* nex_u = hed_u->nex_u;
if ( hed_u->nam_c ) free(hed_u->nam_c); if ( hed_u->nam_c ) free(hed_u->nam_c);
if ( hed_u->val_c ) free(hed_u->val_c); if ( hed_u->val_c ) free(hed_u->val_c);
@ -93,10 +93,10 @@ _http_heds_free(u2_hhed* hed_u)
/* _http_bods_free(): free body structure. /* _http_bods_free(): free body structure.
*/ */
static void static void
_http_bods_free(u2_hbod* bod_u) _http_bods_free(u3_hbod* bod_u)
{ {
while ( bod_u ) { while ( bod_u ) {
u2_hbod* nex_u = bod_u->nex_u; u3_hbod* nex_u = bod_u->nex_u;
free(bod_u); free(bod_u);
bod_u = nex_u; bod_u = nex_u;
@ -106,7 +106,7 @@ _http_bods_free(u2_hbod* bod_u)
/* _http_req_free(): free http request. /* _http_req_free(): free http request.
*/ */
static void static void
_http_req_free(u2_hreq* req_u) _http_req_free(u3_hreq* req_u)
{ {
if ( req_u ) { if ( req_u ) {
if ( req_u->url_c ) { if ( req_u->url_c ) {
@ -126,14 +126,14 @@ _http_req_free(u2_hreq* req_u)
typedef struct { typedef struct {
uv_write_t wri_u; uv_write_t wri_u;
c3_y* buf_y; c3_y* buf_y;
} _u2_write_t; } _u3_write_t;
/* _http_write_cb(): general write callback. /* _http_write_cb(): general write callback.
*/ */
static void static void
_http_write_cb(uv_write_t* wri_u, c3_i sas_i) _http_write_cb(uv_write_t* wri_u, c3_i sas_i)
{ {
_u2_write_t* ruq_u = (void *)wri_u; _u3_write_t* ruq_u = (void *)wri_u;
if ( 0 != sas_i ) { if ( 0 != sas_i ) {
uL(fprintf(uH, "http: write: ERROR\n")); uL(fprintf(uH, "http: write: ERROR\n"));
@ -145,9 +145,9 @@ _http_write_cb(uv_write_t* wri_u, c3_i sas_i)
/* _http_respond_buf(): write back to http. /* _http_respond_buf(): write back to http.
*/ */
static void static void
_http_respond_buf(u2_hreq* req_u, uv_buf_t buf_u) _http_respond_buf(u3_hreq* req_u, uv_buf_t buf_u)
{ {
_u2_write_t* ruq_u; _u3_write_t* ruq_u;
// don't respond to a dead connection // don't respond to a dead connection
if ( uv_is_closing((uv_handle_t*) &(req_u->hon_u->wax_u)) ) { if ( uv_is_closing((uv_handle_t*) &(req_u->hon_u->wax_u)) ) {
@ -155,7 +155,7 @@ _http_respond_buf(u2_hreq* req_u, uv_buf_t buf_u)
return; return;
} }
ruq_u = (_u2_write_t*) c3_malloc(sizeof(_u2_write_t)); ruq_u = (_u3_write_t*) c3_malloc(sizeof(_u3_write_t));
ruq_u->buf_y = (c3_y*)buf_u.base; ruq_u->buf_y = (c3_y*)buf_u.base;
@ -172,8 +172,8 @@ _http_respond_buf(u2_hreq* req_u, uv_buf_t buf_u)
/* _http_respond_body(): attach response body. /* _http_respond_body(): attach response body.
*/ */
static void static void
_http_send_body(u2_hreq *req_u, _http_send_body(u3_hreq *req_u,
u2_hbod *rub_u) u3_hbod *rub_u)
{ {
uv_buf_t buf_u; uv_buf_t buf_u;
@ -191,8 +191,8 @@ _http_send_body(u2_hreq *req_u,
/* _http_respond_body(): attach response body. /* _http_respond_body(): attach response body.
*/ */
static void static void
_http_respond_body(u2_hreq *req_u, _http_respond_body(u3_hreq *req_u,
u2_hbod *rub_u) u3_hbod *rub_u)
{ {
if ( !(req_u->rub_u) ) { if ( !(req_u->rub_u) ) {
req_u->rub_u = req_u->bur_u = rub_u; req_u->rub_u = req_u->bur_u = rub_u;
@ -206,7 +206,7 @@ _http_respond_body(u2_hreq *req_u,
/* _http_respond_str(): attach output string. /* _http_respond_str(): attach output string.
*/ */
static void static void
_http_respond_str(u2_hreq* req_u, _http_respond_str(u3_hreq* req_u,
const c3_c* str_c) const c3_c* str_c)
{ {
_http_respond_body(req_u, _http_bod(strlen(str_c), (const c3_y*)str_c)); _http_respond_body(req_u, _http_bod(strlen(str_c), (const c3_y*)str_c));
@ -215,8 +215,8 @@ _http_respond_str(u2_hreq* req_u,
/* _http_respond_headers(): attach output headers. /* _http_respond_headers(): attach output headers.
*/ */
static void static void
_http_respond_headers(u2_hreq* req_u, _http_respond_headers(u3_hreq* req_u,
u2_hhed* hed_u) u3_hhed* hed_u)
{ {
while ( hed_u ) { while ( hed_u ) {
_http_respond_body(req_u, _http_bud(hed_u->nam_c, hed_u->val_c)); _http_respond_body(req_u, _http_bud(hed_u->nam_c, hed_u->val_c));
@ -227,8 +227,8 @@ _http_respond_headers(u2_hreq* req_u,
/* _http_respond_request(): attach response to request, then free it. /* _http_respond_request(): attach response to request, then free it.
*/ */
static void static void
_http_respond_request(u2_hreq* req_u, _http_respond_request(u3_hreq* req_u,
u2_hrep* rep_u) u3_hrep* rep_u)
{ {
c3_c buf_c[81]; c3_c buf_c[81];
@ -260,8 +260,8 @@ _http_respond_request(u2_hreq* req_u,
} }
free(rep_u); free(rep_u);
c3_assert(u2_no == req_u->end); c3_assert(u3_no == req_u->end);
req_u->end = u2_yes; req_u->end = u3_yes;
} }
/* _http_conn_free_early(): free http connection on failure. /* _http_conn_free_early(): free http connection on failure.
@ -269,7 +269,7 @@ _http_respond_request(u2_hreq* req_u,
static void static void
_http_conn_free_early(uv_handle_t* han_t) _http_conn_free_early(uv_handle_t* han_t)
{ {
u2_hcon* hon_u = (void*) han_t; u3_hcon* hon_u = (void*) han_t;
free(hon_u); free(hon_u);
} }
@ -278,16 +278,16 @@ _http_conn_free_early(uv_handle_t* han_t)
static void static void
_http_conn_free(uv_handle_t* han_t) _http_conn_free(uv_handle_t* han_t)
{ {
u2_hcon* hon_u = (void*) han_t; u3_hcon* hon_u = (void*) han_t;
{ {
struct _u2_http *htp_u = hon_u->htp_u; struct _u3_http *htp_u = hon_u->htp_u;
if ( htp_u->hon_u == hon_u ) { if ( htp_u->hon_u == hon_u ) {
htp_u->hon_u = hon_u->nex_u; htp_u->hon_u = hon_u->nex_u;
} }
else { else {
u2_hcon *pre_u = htp_u->hon_u; u3_hcon *pre_u = htp_u->hon_u;
// XX glories of linear search // XX glories of linear search
// //
@ -301,8 +301,8 @@ _http_conn_free(uv_handle_t* han_t)
} }
while ( 0 != hon_u->req_u ) { while ( 0 != hon_u->req_u ) {
u2_hreq* req_u = hon_u->req_u; u3_hreq* req_u = hon_u->req_u;
u2_hreq* nex_u = req_u->nex_u; u3_hreq* nex_u = req_u->nex_u;
_http_request_dead(req_u); _http_request_dead(req_u);
_http_req_free(req_u); _http_req_free(req_u);
@ -314,7 +314,7 @@ _http_conn_free(uv_handle_t* han_t)
/* _http_conn_dead(): free http connection, close fd. /* _http_conn_dead(): free http connection, close fd.
*/ */
static void static void
_http_conn_dead(u2_hcon *hon_u) _http_conn_dead(u3_hcon *hon_u)
{ {
// uL(fprintf(uH, "connection dead: %d\n", hon_u->coq_l)); // uL(fprintf(uH, "connection dead: %d\n", hon_u->coq_l));
@ -326,14 +326,14 @@ _http_conn_dead(u2_hcon *hon_u)
/* _http_req_dump(): dump complete http request. /* _http_req_dump(): dump complete http request.
*/ */
static void static void
_http_req_dump(u2_hreq* req_u) _http_req_dump(u3_hreq* req_u)
{ {
c3_c* mets[] = { "delete", "get", "head", "post", "put", "other" }; c3_c* mets[] = { "delete", "get", "head", "post", "put", "other" };
printf("%s %s\n", mets[req_u->met_e], printf("%s %s\n", mets[req_u->met_e],
req_u->url_c ? req_u->url_c : "(null)"); req_u->url_c ? req_u->url_c : "(null)");
{ {
u2_hhed* hed_u = req_u->hed_u; u3_hhed* hed_u = req_u->hed_u;
while ( hed_u ) { while ( hed_u ) {
printf("%s: %s\r\n", hed_u->nam_c, hed_u->val_c); printf("%s: %s\r\n", hed_u->nam_c, hed_u->val_c);
@ -341,7 +341,7 @@ _http_req_dump(u2_hreq* req_u)
} }
} }
{ {
u2_hbod* bod_u = req_u->bod_u; u3_hbod* bod_u = req_u->bod_u;
c3_w bod_w = 0; c3_w bod_w = 0;
while ( bod_u ) { while ( bod_u ) {
@ -386,7 +386,7 @@ _http_more(c3_c* str_c, const c3_c* buf_c, size_t siz_i)
static c3_i static c3_i
_http_url(http_parser* par_u, const c3_c* buf_c, size_t siz_i) _http_url(http_parser* par_u, const c3_c* buf_c, size_t siz_i)
{ {
u2_hreq *req_u = par_u->data; u3_hreq *req_u = par_u->data;
req_u->url_c = _http_more(req_u->url_c, buf_c, siz_i); req_u->url_c = _http_more(req_u->url_c, buf_c, siz_i);
return 0; return 0;
@ -397,12 +397,12 @@ _http_url(http_parser* par_u, const c3_c* buf_c, size_t siz_i)
static c3_i static c3_i
_http_header_field(http_parser* par_u, const c3_c* buf_c, size_t siz_i) _http_header_field(http_parser* par_u, const c3_c* buf_c, size_t siz_i)
{ {
u2_hreq *req_u = par_u->data; u3_hreq *req_u = par_u->data;
switch ( req_u->rat_e ) { switch ( req_u->rat_e ) {
case u2_hreq_non: case u3_hreq_non:
case u2_hreq_val: { case u3_hreq_val: {
u2_hhed* hed_u = c3_malloc(sizeof(*hed_u)); u3_hhed* hed_u = c3_malloc(sizeof(*hed_u));
hed_u->nam_c = _http_more(0, buf_c, siz_i); hed_u->nam_c = _http_more(0, buf_c, siz_i);
hed_u->val_c = 0; hed_u->val_c = 0;
@ -411,12 +411,12 @@ _http_header_field(http_parser* par_u, const c3_c* buf_c, size_t siz_i)
break; break;
} }
case u2_hreq_nam: { case u3_hreq_nam: {
req_u->hed_u->nam_c = _http_more(req_u->hed_u->nam_c, buf_c, siz_i); req_u->hed_u->nam_c = _http_more(req_u->hed_u->nam_c, buf_c, siz_i);
break; break;
} }
} }
req_u->rat_e = u2_hreq_nam; req_u->rat_e = u3_hreq_nam;
return 0; return 0;
} }
@ -425,21 +425,21 @@ _http_header_field(http_parser* par_u, const c3_c* buf_c, size_t siz_i)
static c3_i static c3_i
_http_header_value(http_parser* par_u, const c3_c* buf_c, size_t siz_i) _http_header_value(http_parser* par_u, const c3_c* buf_c, size_t siz_i)
{ {
u2_hreq *req_u = par_u->data; u3_hreq *req_u = par_u->data;
switch ( req_u->rat_e ) { switch ( req_u->rat_e ) {
case u2_hreq_non: fprintf(stderr, "http: odd value\r\n"); return 1; case u3_hreq_non: fprintf(stderr, "http: odd value\r\n"); return 1;
case u2_hreq_nam: { case u3_hreq_nam: {
req_u->hed_u->val_c = _http_more(0, buf_c, siz_i); req_u->hed_u->val_c = _http_more(0, buf_c, siz_i);
break; break;
} }
case u2_hreq_val: { case u3_hreq_val: {
req_u->hed_u->val_c = _http_more(req_u->hed_u->val_c, buf_c, siz_i); req_u->hed_u->val_c = _http_more(req_u->hed_u->val_c, buf_c, siz_i);
break; break;
} }
} }
req_u->rat_e = u2_hreq_val; req_u->rat_e = u3_hreq_val;
return 0; return 0;
} }
@ -448,10 +448,10 @@ _http_header_value(http_parser* par_u, const c3_c* buf_c, size_t siz_i)
static c3_i static c3_i
_http_headers_complete(http_parser* par_u) _http_headers_complete(http_parser* par_u)
{ {
u2_hreq *req_u = par_u->data; u3_hreq *req_u = par_u->data;
if ( par_u->method >= u2_hmet_other ) { if ( par_u->method >= u3_hmet_other ) {
req_u->met_e = u2_hmet_other; req_u->met_e = u3_hmet_other;
} else req_u->met_e = par_u->method; } else req_u->met_e = par_u->method;
return 0; return 0;
@ -462,8 +462,8 @@ _http_headers_complete(http_parser* par_u)
static c3_i static c3_i
_http_body(http_parser* par_u, const c3_c* buf_c, size_t siz_i) _http_body(http_parser* par_u, const c3_c* buf_c, size_t siz_i)
{ {
u2_hreq *req_u = par_u->data; u3_hreq *req_u = par_u->data;
u2_hbod* bod_u; u3_hbod* bod_u;
bod_u = _http_bod(siz_i, (const c3_y*)buf_c); bod_u = _http_bod(siz_i, (const c3_y*)buf_c);
@ -483,8 +483,8 @@ _http_body(http_parser* par_u, const c3_c* buf_c, size_t siz_i)
static c3_i static c3_i
_http_message_complete(http_parser* par_u) _http_message_complete(http_parser* par_u)
{ {
u2_hreq* req_u = par_u->data; u3_hreq* req_u = par_u->data;
u2_hcon* hon_u = req_u->hon_u; u3_hcon* hon_u = req_u->hon_u;
c3_assert(req_u == hon_u->ruc_u); c3_assert(req_u == hon_u->ruc_u);
hon_u->ruc_u = 0; hon_u->ruc_u = 0;
@ -522,16 +522,16 @@ static struct http_parser_settings _http_settings = {
/* _http_req_new(): new http request. /* _http_req_new(): new http request.
*/ */
static u2_hreq* static u3_hreq*
_http_req_new(u2_hcon* hon_u) _http_req_new(u3_hcon* hon_u)
{ {
u2_hreq* req_u = c3_malloc(sizeof(*req_u)); u3_hreq* req_u = c3_malloc(sizeof(*req_u));
req_u->hon_u = hon_u; req_u->hon_u = hon_u;
req_u->seq_l = hon_u->seq_l++; req_u->seq_l = hon_u->seq_l++;
req_u->met_e = (u2_hmet)0; req_u->met_e = (u3_hmet)0;
req_u->rat_e = (u2_hrat)0; req_u->rat_e = (u3_hrat)0;
req_u->par_u = c3_malloc(sizeof(struct http_parser)); req_u->par_u = c3_malloc(sizeof(struct http_parser));
http_parser_init(req_u->par_u, HTTP_REQUEST); http_parser_init(req_u->par_u, HTTP_REQUEST);
@ -548,8 +548,8 @@ _http_req_new(u2_hcon* hon_u)
else req_u->ipf_w = ntohl(adr_u.sin_addr.s_addr); else req_u->ipf_w = ntohl(adr_u.sin_addr.s_addr);
} }
req_u->liv = u2_no; req_u->liv = u3_no;
req_u->end = u2_no; req_u->end = u3_no;
req_u->url_c = 0; req_u->url_c = 0;
@ -581,9 +581,9 @@ _http_conn_read_cb(uv_stream_t* tcp_u,
ssize_t siz_w, ssize_t siz_w,
const uv_buf_t * buf_u) const uv_buf_t * buf_u)
{ {
u2_hcon* hon_u = (u2_hcon*)(void*) tcp_u; u3_hcon* hon_u = (u3_hcon*)(void*) tcp_u;
u2_lo_open(); u3_lo_open();
{ {
if ( siz_w == UV_EOF ) { if ( siz_w == UV_EOF ) {
_http_conn_dead(hon_u); _http_conn_dead(hon_u);
@ -609,17 +609,17 @@ _http_conn_read_cb(uv_stream_t* tcp_u,
free(buf_u->base); free(buf_u->base);
} }
} }
u2_lo_shut(u2_yes); u3_lo_shut(u3_yes);
} }
/* _http_conn_new(): create http connection. /* _http_conn_new(): create http connection.
*/ */
static void static void
_http_conn_new(u2_http *htp_u) _http_conn_new(u3_http *htp_u)
{ {
u2_hcon *hon_u = c3_malloc(sizeof(*hon_u)); u3_hcon *hon_u = c3_malloc(sizeof(*hon_u));
uv_tcp_init(u2L, &hon_u->wax_u); uv_tcp_init(u3L, &hon_u->wax_u);
c3_w ret_w; c3_w ret_w;
ret_w = uv_accept((uv_stream_t*)&htp_u->wax_u, ret_w = uv_accept((uv_stream_t*)&htp_u->wax_u,
@ -650,10 +650,10 @@ _http_conn_new(u2_http *htp_u)
/* _http_req_find(): find http request by sequence. /* _http_req_find(): find http request by sequence.
*/ */
static u2_hreq* static u3_hreq*
_http_req_find(u2_hcon* hon_u, c3_w seq_l) _http_req_find(u3_hcon* hon_u, c3_w seq_l)
{ {
u2_hreq* req_u = hon_u->req_u; u3_hreq* req_u = hon_u->req_u;
// XX glories of linear search // XX glories of linear search
// //
@ -668,10 +668,10 @@ _http_req_find(u2_hcon* hon_u, c3_w seq_l)
/* _http_serv_find(): find http connection by sequence. /* _http_serv_find(): find http connection by sequence.
*/ */
static u2_http* static u3_http*
_http_serv_find(c3_l sev_l) _http_serv_find(c3_l sev_l)
{ {
u2_http* htp_u = u2_Host.htp_u; u3_http* htp_u = u3_Host.htp_u;
// XX glories of linear search // XX glories of linear search
// //
@ -686,10 +686,10 @@ _http_serv_find(c3_l sev_l)
/* _http_conn_find(): find http connection by sequence. /* _http_conn_find(): find http connection by sequence.
*/ */
static u2_hcon* static u3_hcon*
_http_conn_find(u2_http *htp_u, c3_w coq_l) _http_conn_find(u3_http *htp_u, c3_w coq_l)
{ {
u2_hcon* hon_u = htp_u->hon_u; u3_hcon* hon_u = htp_u->hon_u;
// XX glories of linear search // XX glories of linear search
// //
@ -704,60 +704,60 @@ _http_conn_find(u2_http *htp_u, c3_w coq_l)
/* _http_heds_to_list(): C headers to list. /* _http_heds_to_list(): C headers to list.
*/ */
static u2_noun static u3_noun
_http_heds_to_list(u2_hhed* hed_u) _http_heds_to_list(u3_hhed* hed_u)
{ {
if ( 0 == hed_u ) { if ( 0 == hed_u ) {
return u2_nul; return u3_nul;
} else { } else {
return u2nc(u2nc(u2_ci_string(hed_u->nam_c), return u3nc(u3nc(u3_ci_string(hed_u->nam_c),
hed_u->val_c ? u2_ci_string(hed_u->val_c) : u2_nul), hed_u->val_c ? u3_ci_string(hed_u->val_c) : u3_nul),
_http_heds_to_list(hed_u->nex_u)); _http_heds_to_list(hed_u->nex_u));
} }
} }
/* _http_list_to_heds(): list to C headers. /* _http_list_to_heds(): list to C headers.
*/ */
static u2_hhed* static u3_hhed*
_http_list_to_heds(u2_noun lix) _http_list_to_heds(u3_noun lix)
{ {
u2_noun yix = lix; u3_noun yix = lix;
u2_hhed* hed_u = 0; u3_hhed* hed_u = 0;
while ( 1 ) { while ( 1 ) {
if ( u2_nul == lix ) { if ( u3_nul == lix ) {
break; break;
} }
else { else {
u2_noun i_lix = u2h(lix); u3_noun i_lix = u3h(lix);
u2_noun pi_lix = u2h(i_lix); u3_noun pi_lix = u3h(i_lix);
u2_noun qi_lix = u2t(i_lix); u3_noun qi_lix = u3t(i_lix);
u2_noun t_lix = u2t(lix); u3_noun t_lix = u3t(lix);
u2_hhed* nex_u = c3_malloc(sizeof(u2_hhed)); u3_hhed* nex_u = c3_malloc(sizeof(u3_hhed));
nex_u->nam_c = u2_cr_string(pi_lix); nex_u->nam_c = u3_cr_string(pi_lix);
nex_u->val_c = u2_cr_string(qi_lix); nex_u->val_c = u3_cr_string(qi_lix);
nex_u->nex_u = hed_u; nex_u->nex_u = hed_u;
hed_u = nex_u; hed_u = nex_u;
lix = t_lix; lix = t_lix;
} }
} }
u2z(yix); u3z(yix);
return hed_u; return hed_u;
} }
/* _http_bods_to_octs: translate body into octet-stream noun. /* _http_bods_to_octs: translate body into octet-stream noun.
*/ */
static u2_noun static u3_noun
_http_bods_to_octs(u2_hbod* bod_u) _http_bods_to_octs(u3_hbod* bod_u)
{ {
c3_w len_w; c3_w len_w;
c3_y* buf_y; c3_y* buf_y;
u2_noun cos; u3_noun cos;
{ {
u2_hbod* bid_u; u3_hbod* bid_u;
len_w = 0; len_w = 0;
for ( bid_u = bod_u; bid_u; bid_u = bid_u->nex_u ) { for ( bid_u = bod_u; bid_u; bid_u = bid_u->nex_u ) {
@ -775,144 +775,141 @@ _http_bods_to_octs(u2_hbod* bod_u)
bod_u = bod_u->nex_u; bod_u = bod_u->nex_u;
} }
} }
cos = u2_ci_bytes(len_w, buf_y); cos = u3_ci_bytes(len_w, buf_y);
free(buf_y); free(buf_y);
return u2nc(len_w, cos); return u3nc(len_w, cos);
} }
/* _http_octs_to_bod(): translate octet-stream noun into body. /* _http_octs_to_bod(): translate octet-stream noun into body.
*/ */
static u2_hbod* static u3_hbod*
_http_octs_to_bod(u2_noun oct) _http_octs_to_bod(u3_noun oct)
{ {
c3_w len_w; c3_w len_w;
if ( !u2_fly_is_cat(u2h(oct)) ) { if ( u3_ne(u3_co_is_cat(u3h(oct))) ) {
// 2GB max // 2GB max
u2_cm_bail(c3__fail); return 0; u3_cm_bail(c3__fail); return 0;
} }
len_w = u2h(oct); len_w = u3h(oct);
{ {
u2_hbod* bod_u = c3_malloc(len_w + sizeof(*bod_u)); u3_hbod* bod_u = c3_malloc(len_w + sizeof(*bod_u));
bod_u->len_w = len_w; bod_u->len_w = len_w;
u2_cr_bytes(0, len_w, bod_u->hun_y, u2t(oct)); u3_cr_bytes(0, len_w, bod_u->hun_y, u3t(oct));
bod_u->nex_u = 0; bod_u->nex_u = 0;
u2z(oct); u3z(oct);
return bod_u; return bod_u;
} }
} }
/* _http_pox_to_noun(): translate srv/con/req to path noun (pox). /* _http_pox_to_noun(): translate srv/con/req to path noun (pox).
*/ */
static u2_noun static u3_noun
_http_pox_to_noun(c3_w sev_l, c3_w coq_l, c3_w seq_l) _http_pox_to_noun(c3_w sev_l, c3_w coq_l, c3_w seq_l)
{ {
return return
u2nt( u3nt(
u2_blip, u3_blip,
c3__http, c3__http,
u2nq(u2_dc("scot", c3_s2('u','v'), sev_l), u3nq(u3_dc("scot", c3_s2('u','v'), sev_l),
u2_dc("scot", c3_s2('u','d'), coq_l), u3_dc("scot", c3_s2('u','d'), coq_l),
u2_dc("scot", c3_s2('u','d'), seq_l), u3_dc("scot", c3_s2('u','d'), seq_l),
u2_nul)); u3_nul));
} }
/* _http_request_to_noun(): translate http request into noun, or u2_none. /* _http_request_to_noun(): translate http request into noun, or u3_none.
*/ */
static u2_noun static u3_noun
_http_request_to_noun(u2_hreq* req_u) _http_request_to_noun(u3_hreq* req_u)
{ {
u2_noun med, url, hed, bod; u3_noun med, url, hed, bod;
switch ( req_u->met_e ) { switch ( req_u->met_e ) {
default: fprintf(stderr, "strange request\r\n"); return u2_none; default: fprintf(stderr, "strange request\r\n"); return u3_none;
case u2_hmet_put: { med = c3__put; break; } case u3_hmet_put: { med = c3__put; break; }
case u2_hmet_get: { med = c3__get; break; } case u3_hmet_get: { med = c3__get; break; }
case u2_hmet_post: { med = c3__post; break; } case u3_hmet_post: { med = c3__post; break; }
} }
url = u2_ci_string(req_u->url_c); url = u3_ci_string(req_u->url_c);
hed = _http_heds_to_list(req_u->hed_u); hed = _http_heds_to_list(req_u->hed_u);
bod = req_u->bod_u ? u2nc(u2_nul, _http_bods_to_octs(req_u->bod_u)) : u2_nul; bod = req_u->bod_u ? u3nc(u3_nul, _http_bods_to_octs(req_u->bod_u)) : u3_nul;
return u2nq(med, url, hed, bod); return u3nq(med, url, hed, bod);
} }
/* _http_new_response(): create http response structure. /* _http_new_response(): create http response structure.
*/ */
static u2_hrep* static u3_hrep*
_http_new_response(c3_l sev_l, c3_l coq_l, c3_l seq_l, u2_noun rep) _http_new_response(c3_l sev_l, c3_l coq_l, c3_l seq_l, u3_noun rep)
{ {
u2_noun p_rep, q_rep, r_rep; u3_noun p_rep, q_rep, r_rep;
if ( u2_no == u2_cr_trel(rep, &p_rep, &q_rep, &r_rep) ) { if ( u3_no == u3_cr_trel(rep, &p_rep, &q_rep, &r_rep) ) {
uL(fprintf(uH, "strange response\n")); uL(fprintf(uH, "strange response\n"));
return 0; return 0;
} }
else { else {
u2_hrep* rep_u = c3_malloc(sizeof(u2_hrep)); u3_hrep* rep_u = c3_malloc(sizeof(u3_hrep));
rep_u->sev_l = sev_l; rep_u->sev_l = sev_l;
rep_u->coq_l = coq_l; rep_u->coq_l = coq_l;
rep_u->seq_l = seq_l; rep_u->seq_l = seq_l;
rep_u->sas_w = p_rep; rep_u->sas_w = p_rep;
rep_u->hed_u = _http_list_to_heds(u2k(q_rep)); rep_u->hed_u = _http_list_to_heds(u3k(q_rep));
rep_u->bod_u = (u2_nul == r_rep) ? 0 : _http_octs_to_bod(u2k(u2t(r_rep))); rep_u->bod_u = (u3_nul == r_rep) ? 0 : _http_octs_to_bod(u3k(u3t(r_rep)));
u2z(rep); return rep_u; u3z(rep); return rep_u;
} }
} }
/* _http_request(): dispatch http request, returning null if async. /* _http_request(): dispatch http request, returning null if async.
*/ */
static void static void
_http_request(u2_hreq* req_u) _http_request(u3_hreq* req_u)
{ {
u2_noun req = _http_request_to_noun(req_u); u3_noun req = _http_request_to_noun(req_u);
if ( u2_none != req ) { if ( u3_none != req ) {
u2_noun pox = _http_pox_to_noun(req_u->hon_u->htp_u->sev_l, u3_noun pox = _http_pox_to_noun(req_u->hon_u->htp_u->sev_l,
req_u->hon_u->coq_l, req_u->hon_u->coq_l,
req_u->seq_l); req_u->seq_l);
u2_reck_plan(u2_Host.arv_u, u3_cv_plan(pox,
pox, u3nq(c3__this,
u2nq(c3__this, req_u->hon_u->htp_u->sec,
req_u->hon_u->htp_u->sec, u3nc(u3_yes, u3_ci_words(1, &req_u->ipf_w)),
u2nc(u2_yes, u2_ci_words(1, &req_u->ipf_w)), req));
req));
} }
} }
/* _http_request_dead(): kill http request. /* _http_request_dead(): kill http request.
*/ */
static void static void
_http_request_dead(u2_hreq* req_u) _http_request_dead(u3_hreq* req_u)
{ {
u2_noun pox = _http_pox_to_noun(req_u->hon_u->htp_u->sev_l, u3_noun pox = _http_pox_to_noun(req_u->hon_u->htp_u->sev_l,
req_u->hon_u->coq_l, req_u->hon_u->coq_l,
req_u->seq_l); req_u->seq_l);
u2_reck_plan(u2_Host.arv_u, u3_cv_plan(pox, u3nc(c3__thud, u3_nul));
pox,
u2nc(c3__thud, u2_nul));
} }
/* _http_flush(): transmit any ready data. /* _http_flush(): transmit any ready data.
*/ */
static void static void
_http_flush(u2_hcon* hon_u) _http_flush(u3_hcon* hon_u)
{ {
while ( hon_u->req_u ) { while ( hon_u->req_u ) {
u2_hreq* req_u = hon_u->req_u; u3_hreq* req_u = hon_u->req_u;
u2_hbod* rub_u = req_u->rub_u; u3_hbod* rub_u = req_u->rub_u;
if ( 0 == rub_u ) { if ( 0 == rub_u ) {
if ( u2_yes == req_u->end ) { if ( u3_yes == req_u->end ) {
hon_u->req_u = req_u->nex_u; hon_u->req_u = req_u->nex_u;
if ( 0 == hon_u->req_u ) { if ( 0 == hon_u->req_u ) {
c3_assert(req_u == hon_u->qer_u); c3_assert(req_u == hon_u->qer_u);
@ -945,11 +942,11 @@ _http_flush(u2_hcon* hon_u)
/* _http_respond(): attach http response. /* _http_respond(): attach http response.
*/ */
static void static void
_http_respond(u2_hrep* rep_u) _http_respond(u3_hrep* rep_u)
{ {
u2_http* htp_u; u3_http* htp_u;
u2_hcon* hon_u; u3_hcon* hon_u;
u2_hreq* req_u; u3_hreq* req_u;
if ( !(htp_u = _http_serv_find(rep_u->sev_l)) ) { if ( !(htp_u = _http_serv_find(rep_u->sev_l)) ) {
uL(fprintf(uH, "http: server not found: %x\r\n", rep_u->sev_l)); uL(fprintf(uH, "http: server not found: %x\r\n", rep_u->sev_l));
@ -980,22 +977,22 @@ _http_respond(u2_hrep* rep_u)
} }
void void
u2_http_ef_bake(void) u3_http_ef_bake(void)
{ {
u2_noun pax = u2nq(u2_blip, c3__http, u2k(u2A->sen), u2_nul); u3_noun pax = u3nq(u3_blip, c3__http, u3k(u3A->sen), u3_nul);
u2_reck_plan(u2A, pax, u2nc(c3__born, u2_nul)); u3_cv_plan(pax, u3nc(c3__born, u3_nul));
} }
/* u2_http_ef_thou(): send %thou effect (incoming response) to http. /* u3_http_ef_thou(): send %thou effect (incoming response) to http.
*/ */
void void
u2_http_ef_thou(c3_l sev_l, u3_http_ef_thou(c3_l sev_l,
c3_l coq_l, c3_l coq_l,
c3_l seq_l, c3_l seq_l,
u2_noun rep) u3_noun rep)
{ {
u2_hrep* rep_u = _http_new_response(sev_l, coq_l, seq_l, rep); u3_hrep* rep_u = _http_new_response(sev_l, coq_l, seq_l, rep);
if ( !rep_u ) { if ( !rep_u ) {
uL(fprintf(uH, "http: response dropped\r\n")); uL(fprintf(uH, "http: response dropped\r\n"));
@ -1008,7 +1005,7 @@ u2_http_ef_thou(c3_l sev_l,
static void static void
_http_listen_cb(uv_stream_t* str_u, c3_i sas_i) _http_listen_cb(uv_stream_t* str_u, c3_i sas_i)
{ {
u2_http* htp_u = (u2_http*)str_u; u3_http* htp_u = (u3_http*)str_u;
if ( 0 != sas_i ) { if ( 0 != sas_i ) {
uL(fprintf(uH, "http: listen_cb: ERROR\n")); uL(fprintf(uH, "http: listen_cb: ERROR\n"));
@ -1021,11 +1018,11 @@ _http_listen_cb(uv_stream_t* str_u, c3_i sas_i)
/* _http_start(): start http server. /* _http_start(): start http server.
*/ */
static void static void
_http_start(u2_http* htp_u) _http_start(u3_http* htp_u)
{ {
struct sockaddr_in add_u; struct sockaddr_in add_u;
uv_tcp_init(u2L, &htp_u->wax_u); uv_tcp_init(u3L, &htp_u->wax_u);
memset(&add_u, 0, sizeof(add_u)); memset(&add_u, 0, sizeof(add_u));
add_u.sin_family = AF_INET; add_u.sin_family = AF_INET;
@ -1057,75 +1054,75 @@ _http_start(u2_http* htp_u)
} }
} }
uL(fprintf(uH, "http: live (%s) on %d\n", uL(fprintf(uH, "http: live (%s) on %d\n",
(u2_yes == htp_u->sec) ? "\"secure\"" : "insecure", (u3_yes == htp_u->sec) ? "\"secure\"" : "insecure",
htp_u->por_w)); htp_u->por_w));
break; break;
} }
} }
/* u2_http_io_init(): initialize http I/O. /* u3_http_io_init(): initialize http I/O.
*/ */
void void
u2_http_io_init() u3_http_io_init()
{ {
// Logically secure port. // Logically secure port.
{ {
u2_http *htp_u = c3_malloc(sizeof(*htp_u)); u3_http *htp_u = c3_malloc(sizeof(*htp_u));
htp_u->sev_l = u2A->sev_l + 1; htp_u->sev_l = u3A->sev_l + 1;
htp_u->coq_l = 1; htp_u->coq_l = 1;
htp_u->por_w = 8443; htp_u->por_w = 8443;
htp_u->sec = u2_yes; htp_u->sec = u3_yes;
htp_u->hon_u = 0; htp_u->hon_u = 0;
htp_u->nex_u = 0; htp_u->nex_u = 0;
htp_u->nex_u = u2_Host.htp_u; htp_u->nex_u = u3_Host.htp_u;
u2_Host.htp_u = htp_u; u3_Host.htp_u = htp_u;
} }
// Insecure port. // Insecure port.
// //
{ {
u2_http *htp_u = c3_malloc(sizeof(*htp_u)); u3_http *htp_u = c3_malloc(sizeof(*htp_u));
htp_u->sev_l = u2A->sev_l; htp_u->sev_l = u3A->sev_l;
htp_u->coq_l = 1; htp_u->coq_l = 1;
htp_u->por_w = 8080; htp_u->por_w = 8080;
htp_u->sec = u2_no; htp_u->sec = u3_no;
htp_u->hon_u = 0; htp_u->hon_u = 0;
htp_u->nex_u = 0; htp_u->nex_u = 0;
htp_u->nex_u = u2_Host.htp_u; htp_u->nex_u = u3_Host.htp_u;
u2_Host.htp_u = htp_u; u3_Host.htp_u = htp_u;
} }
u2_Host.ctp_u.coc_u = 0; u3_Host.ctp_u.coc_u = 0;
} }
/* u2_http_io_talk(): bring up listener. /* u3_http_io_talk(): bring up listener.
*/ */
void void
u2_http_io_talk() u3_http_io_talk()
{ {
u2_http* htp_u; u3_http* htp_u;
for ( htp_u = u2_Host.htp_u; htp_u; htp_u = htp_u->nex_u ) { for ( htp_u = u3_Host.htp_u; htp_u; htp_u = htp_u->nex_u ) {
_http_start(htp_u); _http_start(htp_u);
} }
} }
/* u2_http_io_poll(): poll kernel for http I/O. /* u3_http_io_poll(): poll kernel for http I/O.
*/ */
void void
u2_http_io_poll(void) u3_http_io_poll(void)
{ {
} }
/* u2_http_io_exit(): shut down http. /* u3_http_io_exit(): shut down http.
*/ */
void void
u2_http_io_exit(void) u3_http_io_exit(void)
{ {
} }

468
v/loop.c
View File

@ -24,12 +24,16 @@
#include "all.h" #include "all.h"
#include "v/vere.h" #include "v/vere.h"
#if 0
static jmp_buf Signal_buf; static jmp_buf Signal_buf;
#ifndef SIGSTKSZ #ifndef SIGSTKSZ
# define SIGSTKSZ 16384 # define SIGSTKSZ 16384
#endif #endif
static uint8_t Sigstk[SIGSTKSZ]; static uint8_t Sigstk[SIGSTKSZ];
uint8_t u3_Critical;
typedef enum { typedef enum {
sig_none, sig_none,
sig_overflow, sig_overflow,
@ -38,9 +42,9 @@ typedef enum {
sig_memory, sig_memory,
sig_assert, sig_assert,
sig_timer sig_timer
} u2_kill; } u3_kill;
volatile u2_kill Sigcause; // reasons for exception volatile u3_kill Sigcause; // reasons for exception
static void _lo_cont(void *arg1, void *arg2, void *arg3) static void _lo_cont(void *arg1, void *arg2, void *arg3)
{ {
@ -53,7 +57,7 @@ static void _lo_cont(void *arg1, void *arg2, void *arg3)
static void static void
_lo_signal_handle_over(int emergency, stackoverflow_context_t scp) _lo_signal_handle_over(int emergency, stackoverflow_context_t scp)
{ {
if ( u2_Critical ) { if ( u3_Critical ) {
// Careful not to grow the stack during critical sections. // Careful not to grow the stack during critical sections.
// //
write(2, "stack disaster\n", strlen("stack disaster" + 2)); write(2, "stack disaster\n", strlen("stack disaster" + 2));
@ -75,9 +79,9 @@ _lo_signal_handle_over(int emergency, stackoverflow_context_t scp)
static void static void
_lo_signal_handle_term(int x) _lo_signal_handle_term(int x)
{ {
if ( !u2_Critical ) { if ( !u3_Critical ) {
Sigcause = sig_terminate; Sigcause = sig_terminate;
u2_Host.liv = u2_no; u3_Host.liv = u3_no;
longjmp(Signal_buf, 1); longjmp(Signal_buf, 1);
} }
} }
@ -85,7 +89,7 @@ _lo_signal_handle_term(int x)
static void static void
_lo_signal_handle_intr(int x) _lo_signal_handle_intr(int x)
{ {
if ( !u2_Critical ) { if ( !u3_Critical ) {
Sigcause = sig_interrupt; Sigcause = sig_interrupt;
longjmp(Signal_buf, 1); longjmp(Signal_buf, 1);
} }
@ -94,7 +98,7 @@ _lo_signal_handle_intr(int x)
static void static void
_lo_signal_handle_alrm(int x) _lo_signal_handle_alrm(int x)
{ {
if ( !u2_Critical ) { if ( !u3_Critical ) {
Sigcause = sig_timer; Sigcause = sig_timer;
longjmp(Signal_buf, 1); longjmp(Signal_buf, 1);
} }
@ -118,7 +122,7 @@ _lo_signal_done()
setitimer(ITIMER_VIRTUAL, &itm_u, 0); setitimer(ITIMER_VIRTUAL, &itm_u, 0);
} }
u2_unix_ef_move(); u3_unix_ef_move();
} }
/* _lo_signal_deep(): start deep processing; set timer for sec_w or 0. /* _lo_signal_deep(): start deep processing; set timer for sec_w or 0.
@ -126,7 +130,7 @@ _lo_signal_done()
static void static void
_lo_signal_deep(c3_w sec_w) _lo_signal_deep(c3_w sec_w)
{ {
u2_unix_ef_hold(); u3_unix_ef_hold();
stackoverflow_install_handler(_lo_signal_handle_over, Sigstk, SIGSTKSZ); stackoverflow_install_handler(_lo_signal_handle_over, Sigstk, SIGSTKSZ);
signal(SIGINT, _lo_signal_handle_intr); signal(SIGINT, _lo_signal_handle_intr);
@ -143,17 +147,20 @@ _lo_signal_deep(c3_w sec_w)
} }
signal(SIGVTALRM, _lo_signal_handle_alrm); signal(SIGVTALRM, _lo_signal_handle_alrm);
} }
#endif
/* u2_loop_signal_memory(): end computation for out-of-memory. /* u3_loop_signal_memory(): end computation for out-of-memory.
*/ */
void void
u2_loop_signal_memory() u3_loop_signal_memory()
{ {
fprintf(stderr, "\r\nout of memory\r\n"); fprintf(stderr, "\r\nout of memory\r\n");
c3_assert(0); c3_assert(0);
#if 0
Sigcause = sig_memory; Sigcause = sig_memory;
longjmp(Signal_buf, 1); longjmp(Signal_buf, 1);
#endif
} }
/* _lo_init(): initialize I/O across the process. /* _lo_init(): initialize I/O across the process.
@ -161,13 +168,13 @@ u2_loop_signal_memory()
static void static void
_lo_init() _lo_init()
{ {
u2_unix_io_init(); u3_unix_io_init();
u2_ames_io_init(); u3_ames_io_init();
u2_term_io_init(); u3_term_io_init();
u2_http_io_init(); u3_http_io_init();
u2_cttp_io_init(); u3_cttp_io_init();
u2_save_io_init(); // u3_save_io_init();
u2_batz_io_init(); u3_batz_io_init();
} }
/* _lo_talk(): bring up listeners across the process. /* _lo_talk(): bring up listeners across the process.
@ -175,24 +182,24 @@ _lo_init()
static void static void
_lo_talk() _lo_talk()
{ {
u2_unix_io_talk(); u3_unix_io_talk();
u2_ames_io_talk(); u3_ames_io_talk();
u2_http_io_talk(); u3_http_io_talk();
u2_term_io_talk(); u3_term_io_talk();
} }
/* u2_lo_exit(): terminate I/O across the process. /* u3_lo_exit(): terminate I/O across the process.
*/ */
void void
u2_lo_exit(void) u3_lo_exit(void)
{ {
u2_unix_io_exit(); u3_unix_io_exit();
u2_ames_io_exit(); u3_ames_io_exit();
u2_term_io_exit(); u3_term_io_exit();
u2_http_io_exit(); u3_http_io_exit();
u2_cttp_io_exit(); u3_cttp_io_exit();
u2_save_io_exit(); // u3_save_io_exit();
u2_batz_io_exit(); u3_batz_io_exit();
} }
/* _lo_poll(): reset event flags across the process. /* _lo_poll(): reset event flags across the process.
@ -200,19 +207,19 @@ u2_lo_exit(void)
static void static void
_lo_poll(void) _lo_poll(void)
{ {
u2_ames_io_poll(); u3_ames_io_poll();
u2_http_io_poll(); u3_http_io_poll();
u2_term_io_poll(); u3_term_io_poll();
u2_save_io_poll(); // u3_save_io_poll();
u2_unix_io_poll(); u3_unix_io_poll();
u2_batz_io_poll(); u3_batz_io_poll();
} }
#if 0 #if 0
/* _lo_how(): print how. /* _lo_how(): print how.
*/ */
static const c3_c* static const c3_c*
_lo_how(u2_noun how) _lo_how(u3_noun how)
{ {
switch ( how ) { switch ( how ) {
default: c3_assert(0); break; default: c3_assert(0); break;
@ -228,263 +235,156 @@ _lo_how(u2_noun how)
} }
#endif #endif
/* u2_lo_bail(): clean up all event state. /* u3_lo_bail(): clean up all event state.
*/ */
void void
u2_lo_bail(u2_reck* rec_u) u3_lo_bail(void)
{ {
fflush(stdout); fflush(stdout);
u2_lo_exit(); u3_lo_exit();
exit(1); exit(1);
} }
int c3_cooked() { u2_lo_exit(); return 0; } int c3_cooked() { u3_lo_exit(); return 0; }
/* _lo_tape(): dump a tape, old style. Don't do this. /* _lo_tape(): dump a tape, old style. Don't do this.
*/ */
static void static void
_lo_tape(u2_reck* rec_u, FILE* fil_u, u2_noun tep) _lo_tape(FILE* fil_u, u3_noun tep)
{ {
u2_noun tap = tep; u3_noun tap = tep;
while ( u2_nul != tap ) { while ( u3_nul != tap ) {
c3_c car_c; c3_c car_c;
if ( u2h(tap) >= 127 ) { if ( u3h(tap) >= 127 ) {
car_c = '?'; car_c = '?';
} else car_c = u2h(tap); } else car_c = u3h(tap);
putc(car_c, fil_u); putc(car_c, fil_u);
tap = u2t(tap); tap = u3t(tap);
} }
u2z(tep); u3z(tep);
} }
/* _lo_wall(): dump a wall, old style. Don't do this. /* _lo_wall(): dump a wall, old style. Don't do this.
*/ */
static void static void
_lo_wall(u2_reck* rec_u, u2_noun wol) _lo_wall(u3_noun wol)
{ {
FILE* fil_u = u2_term_io_hija(); FILE* fil_u = u3_term_io_hija();
u2_noun wal = wol; u3_noun wal = wol;
while ( u2_nul != wal ) { while ( u3_nul != wal ) {
_lo_tape(rec_u, fil_u, u2k(u2h(wal))); _lo_tape(fil_u, u3k(u3h(wal)));
putc(13, fil_u); putc(13, fil_u);
putc(10, fil_u); putc(10, fil_u);
wal = u2t(wal); wal = u3t(wal);
} }
u2_term_io_loja(0); u3_term_io_loja(0);
u2z(wol); u3z(wol);
} }
/* u2_lo_tank(): dump single tank. /* u3_lo_tank(): dump single tank.
*/ */
void void
u2_lo_tank(c3_l tab_l, u2_noun tac) u3_lo_tank(c3_l tab_l, u3_noun tac)
{ {
u2_lo_punt(tab_l, u2nc(tac, u2_nul)); u3_lo_punt(tab_l, u3nc(tac, u3_nul));
} }
/* u2_lo_punt(): dump tank list. /* u3_lo_punt(): dump tank list.
*/ */
void void
u2_lo_punt(c3_l tab_l, u2_noun tac) u3_lo_punt(c3_l tab_l, u3_noun tac)
{ {
u2_noun blu = u2_term_get_blew(0); u3_noun blu = u3_term_get_blew(0);
c3_l col_l = u2h(blu); c3_l col_l = u3h(blu);
u2_noun cat = tac; u3_noun cat = tac;
// We are calling nock here, but hopefully need no protection. // We are calling nock here, but hopefully need no protection.
// //
while ( u2_yes == u2_cr_du(cat) ) { while ( u3_yes == u3_cr_du(cat) ) {
u2_noun wol = u2_dc("wash", u2nc(tab_l, col_l), u2k(u2h(cat))); u3_noun wol = u3_dc("wash", u3nc(tab_l, col_l), u3k(u3h(cat)));
_lo_wall(u2_Arv, wol); _lo_wall(wol);
cat = u2t(cat); cat = u3t(cat);
} }
u2z(tac); u3z(tac);
u2z(blu); u3z(blu);
} }
/* u2_lo_sway(): print trace. /* u3_lo_sway(): print trace.
*/ */
void void
u2_lo_sway(c3_l tab_l, u2_noun tax) u3_lo_sway(c3_l tab_l, u3_noun tax)
{ {
u2_noun mok = u2_dc("mook", 2, tax); u3_noun mok = u3_dc("mook", 2, tax);
u2_lo_punt(tab_l, u2k(u2t(mok))); u3_lo_punt(tab_l, u3k(u3t(mok)));
u2z(mok); u3z(mok);
} }
/* u2_lo_soft(): standard soft wrapper. unifies unix and nock errors. /* _lo_time(): set time.
**
** Produces [%$ result] or [%error (list tank)].
*/ */
u2_noun static void
u2_lo_soft(u2_reck* rec_u, c3_w sec_w, u2_funk fun_f, u2_noun arg) _lo_time(void)
{ {
u2_noun hoe, pro, rop; struct timeval tim_tv;
u2_rl_leap(u2_Wire, c3__rock); gettimeofday(&tim_tv, 0);
u3_cv_time(u3_time_in_tv(&tim_tv));
// system level setjmp, for signals
//
c3_assert(u2_nul == u2_wire_tax(u2_Wire));
c3_assert(0 == u2_wire_kit_r(u2_Wire));
// stop signals
//
u2_unix_ef_hold();
_lo_signal_deep(sec_w);
if ( 0 != sigsetjmp(Signal_buf, 1) ) {
u2_noun tax, pre, mok;
// return to blank state
//
_lo_signal_done();
// acquire trace and reset memory
//
tax = u2_wire_tax(u2_Wire);
u2_rl_fall(u2_Wire);
u2z(arg);
tax = u2_rl_take(u2_Wire, tax);
u2_wire_tax(u2_Wire) = u2_nul;
mok = u2_dc("mook", 2, tax);
// other ugly disgusting cleanups
{
u2_wire_kit_r(u2_Wire) = 0;
u2_hevx_be(u2_wire_hev_r(u2_Wire), u2_pryr, god) = 0;
u2_hevx_at(u2_wire_hev_r(u2_Wire), lad) = 0;
}
switch ( Sigcause ) {
default: pre = c3__wyrd; break;
case sig_none: pre = c3__none; break;
case sig_overflow: pre = c3__over; break;
case sig_interrupt: pre = c3__intr; break;
case sig_terminate: pre = c3__term; break;
case sig_memory: pre = c3__full; break;
case sig_assert: pre = c3__lame; break;
case sig_timer: fprintf(stderr, "timer!!\r\n"); pre = c3__slow; break;
}
rop = u2nc(pre, u2k(u2t(mok)));
u2z(mok);
fprintf(stderr, "error computed\r\n");
return rop;
}
if ( 0 != (hoe = u2_cm_trap()) ) {
u2_noun mok;
u2_rl_fall(u2_Wire);
hoe = u2_rl_take(u2_Wire, hoe);
u2_rl_flog(u2_Wire);
mok = u2_dc("mook", 2, u2k(u2t(hoe)));
rop = u2nc(u2k(u2h(hoe)), u2k(u2t(mok)));
u2z(arg);
u2z(hoe);
u2z(mok);
}
else {
u2_noun pro = fun_f(rec_u, arg);
_lo_signal_done();
u2_cm_done();
u2_rl_fall(u2_Wire);
pro = u2_rl_take(u2_Wire, pro);
u2_rl_flog(u2_Wire);
u2z(arg);
rop = u2nc(u2_blip, pro);
}
pro = rop;
return pro;
} }
#if 0 /* u3_lo_open(): begin callback processing.
/* _lo_hard(): standard hard wrapper. Produces result and/or asserts.
*/
static u2_noun
_lo_hard(u2_reck* rec_u, u2_funk fun_f, u2_noun arg)
{
u2_noun pro = u2_lo_soft(rec_u, 0, fun_f, arg);
if ( u2_blip == u2h(pro) ) {
u2_noun poo = u2k(u2t(pro));
u2z(pro); return poo;
}
else {
u2_lo_punt(2, u2k(u2t(pro)));
u2z(pro);
c3_assert(0);
}
}
#endif
/* u2_lo_open(): begin callback processing.
*/ */
void void
u2_lo_open(void) u3_lo_open(void)
{ {
// update time _lo_time();
//
u2_reck_time(u2A);
} }
/* u2_lo_shut(): end callback processing. /* u3_lo_shut(): end callback processing.
*/ */
void void
u2_lo_shut(u2_bean inn) u3_lo_shut(u3_bean inn)
{ {
// u2_lo_grab("lo_shut a", u2_none); // u3_lo_grab("lo_shut a", u3_none);
// process actions // process actions
// //
u2_raft_work(u2A); u3_raft_work();
// u2_lo_grab("lo_shut b", u2_none); // u3_lo_grab("lo_shut b", u3_none);
// update time // update time
// //
u2_reck_time(u2A); _lo_time();
// u2_lo_grab("lo_shut c", u2_none); // u3_lo_grab("lo_shut c", u3_none);
// for input operations, poll fs (XX not permanent) // for input operations, poll fs (XX not permanent)
// XX remove raty_lead guard // XX remove raty_lead guard
// //
if ( u2R->typ_e == u2_raty_lead && u2_yes == inn ) { if ( u3_yes == inn ) {
u2_unix_ef_look(); u3_unix_ef_look();
} }
// u2_lo_grab("lo_shut d", u2_none); // u3_lo_grab("lo_shut d", u3_none);
// clean shutdown // clean shutdown
// //
if ( u2_no == u2_Host.liv ) { if ( u3_no == u3_Host.liv ) {
// direct save and die // direct save and die
// //
u2_cm_purge(); // u3_lo_grab("lo_exit", u3_none);
// u2_lo_grab("lo_exit", u2_none); // u3_loom_save(u3A->ent_d);
u2_loom_save(u2A->ent_d); // u3_loom_exit();
u2_loom_exit(); u3_lo_exit();
u2_lo_exit();
exit(u2_Host.xit_i); exit(u3_Host.xit_i);
} }
else { else {
// poll arvo to generate any event binding changes // poll arvo to generate any event binding changes
@ -502,11 +402,11 @@ _lo_bench_noop(c3_w num_w)
c3_w i_w; c3_w i_w;
for ( i_w = 0; i_w < num_w; i_w++ ) { for ( i_w = 0; i_w < num_w; i_w++ ) {
u2_reck_plan(u2A, u2nq(u2_blip, c3__term, 1, u2_nul), u3_reck_plan(u3A, u3nq(u3_blip, c3__term, 1, u3_nul),
u2nc(c3__noop, u2_nul)); u3nc(c3__noop, u3_nul));
} }
u2_raft_work(u2A); u3_raft_work(u3A);
} }
// _lo_bench_scot_p(): benchmark prettyprint. // _lo_bench_scot_p(): benchmark prettyprint.
@ -517,9 +417,9 @@ _lo_bench_scot_p(c3_w num_w)
c3_w i_w; c3_w i_w;
for ( i_w = 0; i_w < num_w; i_w++ ) { for ( i_w = 0; i_w < num_w; i_w++ ) {
u2_noun soc = u2_dc("scot", 'p', u2k(u2A->now)); u3_noun soc = u3_dc("scot", 'p', u3k(u3A->now));
u2z(soc); u3z(soc);
} }
} }
@ -531,10 +431,10 @@ _lo_bench_slay_p(c3_w num_w)
c3_w i_w; c3_w i_w;
for ( i_w = 0; i_w < num_w; i_w++ ) { for ( i_w = 0; i_w < num_w; i_w++ ) {
u2_noun soc = u2_dc("scot", 'p', u2k(u2A->now)); u3_noun soc = u3_dc("scot", 'p', u3k(u3A->now));
u2_noun dub = u2_do("slay", soc); u3_noun dub = u3_do("slay", soc);
u2z(dub); u3z(dub);
} }
} }
@ -546,9 +446,9 @@ _lo_bench_scot_da(c3_w num_w)
c3_w i_w; c3_w i_w;
for ( i_w = 0; i_w < num_w; i_w++ ) { for ( i_w = 0; i_w < num_w; i_w++ ) {
u2_noun soc = u2_dc("scot", c3__da, u2k(u2A->now)); u3_noun soc = u3_dc("scot", c3__da, u3k(u3A->now));
u2z(soc); u3z(soc);
} }
} }
@ -560,9 +460,9 @@ _lo_bench_dec(c3_w num_w)
c3_w i_w; c3_w i_w;
for ( i_w = 0; i_w < num_w; i_w++ ) { for ( i_w = 0; i_w < num_w; i_w++ ) {
u2_noun soc = u2_do("dec", u2k(u2A->now)); u3_noun soc = u3_do("dec", u3k(u3A->now));
u2z(soc); u3z(soc);
} }
} }
@ -574,9 +474,9 @@ _lo_bench_scot_ud(c3_w num_w)
c3_w i_w; c3_w i_w;
for ( i_w = 0; i_w < num_w; i_w++ ) { for ( i_w = 0; i_w < num_w; i_w++ ) {
u2_noun soc = u2_dc("scot", c3__ud, u2k(u2A->now)); u3_noun soc = u3_dc("scot", c3__ud, u3k(u3A->now));
u2z(soc); u3z(soc);
} }
} }
@ -585,18 +485,18 @@ _lo_bench_scot_ud(c3_w num_w)
static void static void
_lo_bench(const c3_c* lab_c, void (*fun)(c3_w), c3_w num_w) _lo_bench(const c3_c* lab_c, void (*fun)(c3_w), c3_w num_w)
{ {
u2_noun old, new; u3_noun old, new;
uL(fprintf(uH, "bench: %s: start...\n", lab_c)); uL(fprintf(uH, "bench: %s: start...\n", lab_c));
u2_reck_time(u2A); u3_reck_time(u3A);
old = u2k(u2A->now); old = u3k(u3A->now);
fun(num_w); fun(num_w);
u2_reck_time(u2A); u3_reck_time(u3A);
new = u2k(u2A->now); new = u3k(u3A->now);
{ {
c3_w tms_w = (c3_w)u2_time_gap_ms(old, new); c3_w tms_w = (c3_w)u3_time_gap_ms(old, new);
if ( tms_w > (10 * num_w) ) { if ( tms_w > (10 * num_w) ) {
uL(fprintf(uH, "bench: %s*%d: %d ms, %d ms each.\n", uL(fprintf(uH, "bench: %s*%d: %d ms, %d ms each.\n",
@ -610,16 +510,16 @@ _lo_bench(const c3_c* lab_c, void (*fun)(c3_w), c3_w num_w)
} }
#endif #endif
/* u2_lo_show(): generic noun print. /* u3_lo_show(): generic noun print.
*/ */
void void
u2_lo_show(c3_c* cap_c, u2_noun nun) u3_lo_show(c3_c* cap_c, u3_noun nun)
{ {
u2_noun pav = u2_dc("pave", c3__noun, nun); u3_noun pav = u3_dc("pave", c3__noun, nun);
c3_c* txt_c = (c3_c*)u2_cr_tape(pav); c3_c* txt_c = (c3_c*)u3_cr_tape(pav);
fprintf(stderr, "%s: %s\r\n", cap_c, txt_c); fprintf(stderr, "%s: %s\r\n", cap_c, txt_c);
u2z(pav); u3z(pav);
free(txt_c); free(txt_c);
} }
@ -635,53 +535,53 @@ _lo_slow()
#endif #endif
} }
/* u2_lo_loop(): begin main event loop. /* u3_lo_loop(): begin main event loop.
*/ */
void void
u2_lo_loop() u3_lo_loop()
{ {
uv_loop_t* lup_u = uv_default_loop(); uv_loop_t* lup_u = uv_default_loop();
u2_Host.lup_u = lup_u; u3_Host.lup_u = lup_u;
signal(SIGPIPE, SIG_IGN); // pipe, schmipe signal(SIGPIPE, SIG_IGN); // pipe, schmipe
// signal(SIGIO, SIG_IGN); // linux is wont to produce for some reason // signal(SIGIO, SIG_IGN); // linux is wont to produce for some reason
_lo_init(); _lo_init();
u2_raft_init(); u3_raft_init();
if ( u2_no == u2_Host.ops_u.bat ) { if ( u3_no == u3_Host.ops_u.bat ) {
uv_run(u2L, UV_RUN_DEFAULT); uv_run(u3L, UV_RUN_DEFAULT);
} }
} }
/* u2_lo_lead(): actions on promotion to leader. /* u3_lo_lead(): actions on promotion to leader.
*/ */
void void
u2_lo_lead(u2_reck* rec_u) u3_lo_lead(void)
{ {
// Further server configuration. // Further server configuration.
// //
{ {
u2_http_ef_bake(); u3_http_ef_bake();
} }
_lo_talk(); _lo_talk();
{ {
u2_unix_ef_look(); u3_unix_ef_look();
u2_reck_plan(rec_u, u2nt(u2_blip, c3__ames, u2_nul), u3_cv_plan(u3nt(u3_blip, c3__ames, u3_nul),
u2nc(c3__kick, u2k(rec_u->now))); u3nc(c3__kick, u3k(u3A->now)));
} }
_lo_poll(); _lo_poll();
#if 1 #if 0
u2_loom_save(rec_u->ent_d); u3_loom_save(u3A->ent_d);
u2_Host.sav_u.ent_d = rec_u->ent_d; u3_Host.sav_u.ent_d = rec_u->ent_d;
#endif #endif
if ( u2_yes == u2_Host.ops_u.nuu ) { if ( u3_yes == u3_Host.ops_u.nuu ) {
u2_term_ef_boil(1); u3_term_ef_boil(1);
} }
#if 1 #if 1
@ -689,31 +589,32 @@ u2_lo_lead(u2_reck* rec_u)
#endif #endif
} }
#if 0
/* _lo_mark_reck(): mark a reck. /* _lo_mark_reck(): mark a reck.
*/ */
static c3_w static c3_w
_lo_mark_reck(u2_reck* rec_u) _lo_mark_reck(u3_reck* rec_u)
{ {
c3_w siz_w = 0; c3_w siz_w = 0;
c3_w egg_w; c3_w egg_w;
siz_w += u2_cm_mark_noun(rec_u->ken); siz_w += u3_cm_mark_noun(rec_u->ken);
siz_w += u2_cm_mark_noun(rec_u->roc); siz_w += u3_cm_mark_noun(rec_u->roc);
siz_w += u2_cm_mark_noun(rec_u->yot); siz_w += u3_cm_mark_noun(rec_u->yot);
siz_w += u2_cm_mark_noun(rec_u->now); siz_w += u3_cm_mark_noun(rec_u->now);
siz_w += u2_cm_mark_noun(rec_u->wen); siz_w += u3_cm_mark_noun(rec_u->wen);
siz_w += u2_cm_mark_noun(rec_u->sen); siz_w += u3_cm_mark_noun(rec_u->sen);
siz_w += u2_cm_mark_noun(rec_u->own); siz_w += u3_cm_mark_noun(rec_u->own);
siz_w += u2_cm_mark_noun(rec_u->roe); siz_w += u3_cm_mark_noun(rec_u->roe);
siz_w += u2_cm_mark_noun(rec_u->key); siz_w += u3_cm_mark_noun(rec_u->key);
{ {
u2_cart* egg_u; u3_cart* egg_u;
egg_w = 0; egg_w = 0;
for ( egg_u = rec_u->ova.egg_u; egg_u; egg_u = egg_u->nex_u ) { for ( egg_u = rec_u->ova.egg_u; egg_u; egg_u = egg_u->nex_u ) {
egg_w += u2_cm_mark_noun(egg_u->vir); egg_w += u3_cm_mark_noun(egg_u->vir);
} }
siz_w += egg_w; siz_w += egg_w;
} }
@ -731,64 +632,66 @@ _lo_mark()
{ {
c3_w siz_w; c3_w siz_w;
siz_w = u2_cm_mark_internal(); siz_w = u3_cm_mark_internal();
siz_w += _lo_mark_reck(u2_Host.arv_u); siz_w += _lo_mark_reck(u3_Host.arv_u);
return siz_w; return siz_w;
} }
#endif
#if 0
/* _lo_word(): print a word to the passed stream. /* _lo_word(): print a word to the passed stream.
*/ */
static void static void
_lo_word(FILE* fil_u, c3_w wod_w) _lo_word(FILE* fil_u, c3_w wod_w)
{ {
u2_bean top = u2_yes; u3_bean top = u3_yes;
if ( wod_w / (1000 * 1000 * 1000) ) { if ( wod_w / (1000 * 1000 * 1000) ) {
fprintf(fil_u, "%u.", wod_w / (1000 * 1000 * 1000)); fprintf(fil_u, "%u.", wod_w / (1000 * 1000 * 1000));
wod_w %= (1000 * 1000 * 1000); wod_w %= (1000 * 1000 * 1000);
top = u2_no; top = u3_no;
} }
if ( wod_w / (1000 * 1000) ) { if ( wod_w / (1000 * 1000) ) {
fprintf(fil_u, ((top == u2_yes) ? "%u." : "%03u."), fprintf(fil_u, ((top == u3_yes) ? "%u." : "%03u."),
wod_w / (1000 * 1000)); wod_w / (1000 * 1000));
wod_w %= (1000 * 1000); wod_w %= (1000 * 1000);
top = u2_no; top = u3_no;
} }
if ( wod_w / 1000 ) { if ( wod_w / 1000 ) {
fprintf(fil_u, ((top == u2_yes) ? "%u." : "%03u."), wod_w / 1000); fprintf(fil_u, ((top == u3_yes) ? "%u." : "%03u."), wod_w / 1000);
wod_w %= 1000; wod_w %= 1000;
top = u2_no; top = u3_no;
} }
fprintf(fil_u, ((top == u2_yes) ? "%u" : "%03u"), wod_w); fprintf(fil_u, ((top == u3_yes) ? "%u" : "%03u"), wod_w);
} }
/* u2_lo_grab(): garbage-collect the world, plus roots. /* u3_lo_grab(): garbage-collect the world, plus roots.
*/ */
void void
u2_lo_grab(c3_c* cap_c, u2_noun som, ...) u3_lo_grab(c3_c* cap_c, u3_noun som, ...)
{ {
c3_w siz_w, lec_w; c3_w siz_w, lec_w;
siz_w = _lo_mark(); siz_w = _lo_mark();
{ {
va_list vap; va_list vap;
u2_noun tur; u3_noun tur;
va_start(vap, som); va_start(vap, som);
if ( som != u2_none ) { if ( som != u3_none ) {
siz_w += u2_cm_mark_noun(som); siz_w += u3_cm_mark_noun(som);
while ( u2_none != (tur = va_arg(vap, u2_noun)) ) { while ( u3_none != (tur = va_arg(vap, u3_noun)) ) {
siz_w += u2_cm_mark_noun(tur); siz_w += u3_cm_mark_noun(tur);
} }
} }
va_end(vap); va_end(vap);
} }
lec_w = u2_cm_sweep(siz_w); lec_w = u3_cm_sweep(siz_w);
// if ( lec_w || (u2_yes == u2_Flag_Verbose) ) // if ( lec_w || (u3_yes == u3_Flag_Verbose) )
if ( lec_w || !strcmp("init", cap_c) ) { if ( lec_w || !strcmp("init", cap_c) ) {
FILE* fil_u = uH; FILE* fil_u = uH;
fprintf(fil_u, "%s: gc: ", cap_c); fprintf(fil_u, "%s: gc: ", cap_c);
@ -802,11 +705,12 @@ u2_lo_grab(c3_c* cap_c, u2_noun som, ...)
#if 0 #if 0
if ( lec_w ) { if ( lec_w ) {
uL(fprintf(uH, "zero garbage tolerance!\n")); uL(fprintf(uH, "zero garbage tolerance!\n"));
u2_lo_exit(); u3_lo_exit();
c3_assert(0); c3_assert(0);
exit(1); exit(1);
} }
#endif #endif
} }
u2_wire_lan(u2_Wire) = u2_yes; u3_wire_lan(u3_Wire) = u3_yes;
} }
#endif

258
v/main.c
View File

@ -25,24 +25,10 @@
#define C3_GLOBAL #define C3_GLOBAL
#include "all.h" #include "all.h"
#include "v/vere.h" #include "v/vere.h"
#include "v/arvo.h"
/** Legacy fixed jet linkage. Destroy me please.
**/
/* External drivers.
*/
extern u2_ho_driver j2_da(k_164);
/* Built-in battery drivers. Null `cos` terminates.
*/
u2_ho_driver *HostDriverBase[] = {
&j2_k_164_d,
0
};
/* _main_readw(): parse a word from a string. /* _main_readw(): parse a word from a string.
*/ */
static u2_bean static u3_bean
_main_readw(const c3_c* str_c, c3_w max_w, c3_w* out_w) _main_readw(const c3_c* str_c, c3_w max_w, c3_w* out_w)
{ {
c3_c* end_c; c3_c* end_c;
@ -50,117 +36,117 @@ _main_readw(const c3_c* str_c, c3_w max_w, c3_w* out_w)
if ( *str_c != '\0' && *end_c == '\0' && par_w < max_w ) { if ( *str_c != '\0' && *end_c == '\0' && par_w < max_w ) {
*out_w = par_w; *out_w = par_w;
return u2_yes; return u3_yes;
} }
else return u2_no; else return u3_no;
} }
/* _main_getopt(): extract option map from command line. /* _main_getopt(): extract option map from command line.
*/ */
static u2_bean static u3_bean
_main_getopt(c3_i argc, c3_c** argv) _main_getopt(c3_i argc, c3_c** argv)
{ {
c3_i ch_i; c3_i ch_i;
c3_w arg_w; c3_w arg_w;
u2_Host.ops_u.abo = u2_no; u3_Host.ops_u.abo = u3_no;
u2_Host.ops_u.bat = u2_no; u3_Host.ops_u.bat = u3_no;
u2_Host.ops_u.gab = u2_no; u3_Host.ops_u.gab = u3_no;
u2_Host.ops_u.loh = u2_no; u3_Host.ops_u.loh = u3_no;
u2_Host.ops_u.dem = u2_no; u3_Host.ops_u.dem = u3_no;
u2_Host.ops_u.fog = u2_no; u3_Host.ops_u.fog = u3_no;
u2_Host.ops_u.fak = u2_no; u3_Host.ops_u.fak = u3_no;
u2_Host.ops_u.pro = u2_no; u3_Host.ops_u.pro = u3_no;
u2_Host.ops_u.veb = u2_yes; u3_Host.ops_u.veb = u3_yes;
u2_Host.ops_u.nuu = u2_no; u3_Host.ops_u.nuu = u3_no;
u2_Host.ops_u.mem = u2_no; u3_Host.ops_u.mem = u3_no;
u2_Host.ops_u.kno_w = DefaultKernel; u3_Host.ops_u.kno_w = DefaultKernel;
while ( (ch_i = getopt(argc, argv, "I:X:f:k:l:n:p:r:LabcdgqvFM")) != -1 ) { while ( (ch_i = getopt(argc, argv, "I:X:f:k:l:n:p:r:LabcdgqvFM")) != -1 ) {
switch ( ch_i ) { switch ( ch_i ) {
case 'M': { case 'M': {
u2_Host.ops_u.mem = u2_yes; u3_Host.ops_u.mem = u3_yes;
break; break;
} }
case 'I': { case 'I': {
u2_Host.ops_u.imp_c = strdup(optarg); u3_Host.ops_u.imp_c = strdup(optarg);
break; break;
} }
case 'X': { case 'X': {
if ( 0 != strcmp("wtf", optarg) ) { if ( 0 != strcmp("wtf", optarg) ) {
return u2_no; return u3_no;
} else u2_Host.ops_u.fog = u2_yes; } else u3_Host.ops_u.fog = u3_yes;
break; break;
} }
case 'f': { case 'f': {
if ( u2_no == _main_readw(optarg, 100, &u2_Host.ops_u.fuz_w) ) { if ( u3_no == _main_readw(optarg, 100, &u3_Host.ops_u.fuz_w) ) {
return u2_no; return u3_no;
} }
break; break;
} }
case 'k': { case 'k': {
if ( u2_no == _main_readw(optarg, 256, &u2_Host.ops_u.kno_w) ) { if ( u3_no == _main_readw(optarg, 256, &u3_Host.ops_u.kno_w) ) {
return u2_no; return u3_no;
} }
break; break;
} }
case 'l': { case 'l': {
if ( u2_no == _main_readw(optarg, 65536, &arg_w) ) { if ( u3_no == _main_readw(optarg, 65536, &arg_w) ) {
return u2_no; return u3_no;
} else u2_Host.ops_u.rop_s = arg_w; } else u3_Host.ops_u.rop_s = arg_w;
break; break;
} }
case 'n': { case 'n': {
u2_Host.ops_u.nam_c = strdup(optarg); u3_Host.ops_u.nam_c = strdup(optarg);
break; break;
} }
case 'p': { case 'p': {
if ( u2_no == _main_readw(optarg, 65536, &arg_w) ) { if ( u3_no == _main_readw(optarg, 65536, &arg_w) ) {
return u2_no; return u3_no;
} else u2_Host.ops_u.por_s = arg_w; } else u3_Host.ops_u.por_s = arg_w;
break; break;
} }
case 'r': { case 'r': {
u2_Host.ops_u.raf_c = strdup(optarg); u3_Host.ops_u.raf_c = strdup(optarg);
break; break;
} }
case 'L': { u2_Host.ops_u.loh = u2_yes; break; } case 'L': { u3_Host.ops_u.loh = u3_yes; break; }
case 'F': { case 'F': {
u2_Host.ops_u.loh = u2_yes; u3_Host.ops_u.loh = u3_yes;
u2_Host.ops_u.fak = u2_yes; u3_Host.ops_u.fak = u3_yes;
break; break;
} }
case 'a': { u2_Host.ops_u.abo = u2_yes; break; } case 'a': { u3_Host.ops_u.abo = u3_yes; break; }
case 'b': { u2_Host.ops_u.bat = u2_yes; break; } case 'b': { u3_Host.ops_u.bat = u3_yes; break; }
case 'c': { u2_Host.ops_u.nuu = u2_yes; break; } case 'c': { u3_Host.ops_u.nuu = u3_yes; break; }
case 'd': { u2_Host.ops_u.dem = u2_yes; break; } case 'd': { u3_Host.ops_u.dem = u3_yes; break; }
case 'g': { u2_Host.ops_u.gab = u2_yes; break; } case 'g': { u3_Host.ops_u.gab = u3_yes; break; }
case 'q': { u2_Host.ops_u.veb = u2_no; break; } case 'q': { u3_Host.ops_u.veb = u3_no; break; }
case 'v': { u2_Host.ops_u.veb = u2_yes; break; } case 'v': { u3_Host.ops_u.veb = u3_yes; break; }
case '?': default: { case '?': default: {
return u2_no; return u3_no;
} }
} }
} }
if ( u2_Host.ops_u.rop_s == 0 && u2_Host.ops_u.raf_c != 0 ) { if ( u3_Host.ops_u.rop_s == 0 && u3_Host.ops_u.raf_c != 0 ) {
fprintf(stderr, "The -r flag requires -l.\n"); fprintf(stderr, "The -r flag requires -l.\n");
return u2_no; return u3_no;
} }
if ( u2_yes == u2_Host.ops_u.bat ) { if ( u3_yes == u3_Host.ops_u.bat ) {
u2_Host.ops_u.dem = u2_yes; u3_Host.ops_u.dem = u3_yes;
u2_Host.ops_u.nuu = u2_yes; u3_Host.ops_u.nuu = u3_yes;
} }
if ( u2_Host.ops_u.nam_c == 0 ) { if ( u3_Host.ops_u.nam_c == 0 ) {
u2_Host.ops_u.nam_c = getenv("HOSTNAME"); u3_Host.ops_u.nam_c = getenv("HOSTNAME");
if ( u2_Host.ops_u.nam_c == 0 ) { if ( u3_Host.ops_u.nam_c == 0 ) {
c3_w len_w = sysconf(_SC_HOST_NAME_MAX) + 1; c3_w len_w = sysconf(_SC_HOST_NAME_MAX) + 1;
u2_Host.ops_u.nam_c = c3_malloc(len_w); u3_Host.ops_u.nam_c = c3_malloc(len_w);
if ( 0 != gethostname(u2_Host.ops_u.nam_c, len_w) ) { if ( 0 != gethostname(u3_Host.ops_u.nam_c, len_w) ) {
perror("gethostname"); perror("gethostname");
exit(1); exit(1);
} }
@ -168,7 +154,7 @@ _main_getopt(c3_i argc, c3_c** argv)
} }
if ( argc != (optind + 1) ) { if ( argc != (optind + 1) ) {
return u2_no; return u3_no;
} else { } else {
{ {
c3_c* ash_c; c3_c* ash_c;
@ -178,43 +164,46 @@ _main_getopt(c3_i argc, c3_c** argv)
} }
} }
u2_Host.cpu_c = strdup(argv[optind]); u3_Host.cpu_c = strdup(argv[optind]);
return u2_yes; return u3_yes;
} }
} }
/* u2_ve_usage(): print usage and exit. /* u3_ve_usage(): print usage and exit.
*/ */
static void static void
u2_ve_usage(c3_i argc, c3_c** argv) u3_ve_usage(c3_i argc, c3_c** argv)
{ {
fprintf(stderr, "%s: usage: [-v] [-k stage] [-p ames_port] computer\n", fprintf(stderr, "%s: usage: [-v] [-k stage] [-p ames_port] computer\n",
argv[0]); argv[0]);
exit(1); exit(1);
} }
/* u2_ve_panic(): panic and exit. #if 0
/* u3_ve_panic(): panic and exit.
*/ */
static void static void
u2_ve_panic(c3_i argc, c3_c** argv) u3_ve_panic(c3_i argc, c3_c** argv)
{ {
fprintf(stderr, "%s: gross system failure\n", argv[0]); fprintf(stderr, "%s: gross system failure\n", argv[0]);
exit(1); exit(1);
} }
#endif
/* u2_ve_sysopt(): apply option map to system state. /* u3_ve_sysopt(): apply option map to system state.
*/ */
static void static void
u2_ve_sysopt() u3_ve_sysopt()
{ {
u2_Local = strdup(u2_Host.cpu_c); u3_Local = strdup(u3_Host.cpu_c);
u2_System = U2_LIB; u3_System = U2_LIB;
u2_Flag_Abort = u2_Host.ops_u.abo; u3_Flag_Abort = u3_Host.ops_u.abo;
u2_Flag_Garbage = u2_Host.ops_u.gab; u3_Flag_Garbage = u3_Host.ops_u.gab;
u2_Flag_Profile = u2_Host.ops_u.pro; u3_Flag_Profile = u3_Host.ops_u.pro;
u2_Flag_Verbose = u2_Host.ops_u.veb; u3_Flag_Verbose = u3_Host.ops_u.veb;
} }
#if 0
static jmp_buf Signal_buf; static jmp_buf Signal_buf;
#ifndef SIGSTKSZ #ifndef SIGSTKSZ
# define SIGSTKSZ 16384 # define SIGSTKSZ 16384
@ -249,31 +238,30 @@ interrupt_handler(int x)
Sigcause = sig_interrupt; Sigcause = sig_interrupt;
longjmp(Signal_buf, 1); longjmp(Signal_buf, 1);
} }
#endif
c3_i c3_i
main(c3_i argc, main(c3_i argc,
c3_c** argv) c3_c** argv)
{ {
c3_w kno_w;
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
// Parse options. // Parse options.
// //
if ( u2_no == _main_getopt(argc, argv) ) { if ( u3_no == _main_getopt(argc, argv) ) {
u2_ve_usage(argc, argv); u3_ve_usage(argc, argv);
return 1; return 1;
} }
u2_ve_sysopt(); u3_ve_sysopt();
printf("~\n"); printf("~\n");
printf("welcome.\n"); printf("welcome.\n");
printf("vere: urbit home is %s\n", u2_Host.cpu_c); printf("vere: urbit home is %s\n", u3_Host.cpu_c);
printf("vere: hostname is %s\n", u2_Host.ops_u.nam_c); printf("vere: hostname is %s\n", u3_Host.ops_u.nam_c);
if ( u2_yes == u2_Host.ops_u.dem && u2_no == u2_Host.ops_u.bat ) { if ( u3_yes == u3_Host.ops_u.dem && u3_no == u3_Host.ops_u.bat ) {
printf("Starting daemon\n"); printf("Starting daemon\n");
} }
@ -283,75 +271,30 @@ main(c3_i argc,
// Instantiate process globals. // Instantiate process globals.
{ {
u2_wr_check_init(u2_Host.cpu_c); /* Boot memory.
u2_Host.xit_i = 0; */
if ( (u2_no == u2_Host.ops_u.nuu) && u3_cm_boot(U2_OS_LoomBase, (1 << U2_OS_LoomBits));
(u2_yes == u2_loom_load()) )
/* Boot jets.
*/
u3_cj_boot();
/* Boot arvo kernel.
*/
{ {
u2_Host.wir_r = u2_ray_of(0, 0); struct timeval tim_tv;
u2_Wire = u2_Host.wir_r; u3_noun now;
c3_c pas_c[2048];
u2_Host.arv_u = u2_Arv; snprintf(pas_c, 2048, "%s/.urb/urbit.pill", u3_Host.cpu_c);
gettimeofday(&tim_tv, 0);
now = u3_time_in_tv(&tim_tv);
u2_Arv->ova.egg_u = u2_Arv->ova.geg_u = 0; u3_cv_make(pas_c, now);
u2_lo_grab("init", u2_none);
// Horrible ancient stuff.
//
kno_w = u2_Host.arv_u->kno_w;
u2_Host.kno_w = kno_w;
u2_ho_push();
}
else {
u2_loom_boot();
u2_Host.wir_r = u2_wr_init(c3__rock, u2_ray_of(0, 0), u2_ray_of(1, 0));
u2_Wire = u2_Host.wir_r;
u2_Host.arv_u = u2_Arv;
}
}
// If we have not loaded from checkpoint, build kernel.
//
if ( 0 != u2_Host.arv_u->ent_d ) {
u2_reck_time(u2_Host.arv_u);
u2_reck_numb(u2_Host.arv_u);
{
c3_c* dyt_c = u2_cr_string(u2_Host.arv_u->wen);
printf("time: %s\n", dyt_c);
free(dyt_c);
}
}
else {
// Set outside bail trap. Should not be used, but you never know...
//
if ( 0 != u2_cm_trap() ) {
u2_ve_panic(argc, argv);
}
else {
// Set boot and goal stages.
{
if ( (0 == u2_Host.ops_u.kno_w) || (u2_Host.ops_u.kno_w > 255) ) {
kno_w = DefaultKernel;
} else {
kno_w = u2_Host.ops_u.kno_w;
}
}
// Load the system.
//
{
u2_Host.kno_w = u2_Host.ops_u.kno_w;
u2_reck_boot(u2_Host.arv_u);
}
u2_cm_done();
} }
} }
#if 0
// Install signal handlers and set buffers. // Install signal handlers and set buffers.
// //
// Note that we use the sigmask-restoring variant. Essentially, when // Note that we use the sigmask-restoring variant. Essentially, when
@ -373,9 +316,9 @@ main(c3_i argc,
// //
// This is half-assed at present, so we exit. // This is half-assed at present, so we exit.
// //
u2_lo_sway(0, u2k(u2_wire_tax(u2_Wire))); u3_lo_sway(0, u3k(u3_wire_tax(u3_Wire)));
u2_lo_bail(u2_Host.arv_u); u3_lo_bail(u3A);
exit(1); exit(1);
} }
@ -391,9 +334,10 @@ main(c3_i argc,
#endif #endif
} }
u2_lo_grab("main", u2_none); u3_lo_grab("main", u3_none);
#endif
u2_lo_loop(); u3_lo_loop();
return 0; return 0;
} }

631
v/raft.c

File diff suppressed because it is too large Load Diff

745
v/reck.c
View File

@ -18,429 +18,94 @@
#include <term.h> #include <term.h>
#include "all.h" #include "all.h"
#include "f/coal.h"
#include "v/vere.h" #include "v/vere.h"
/* _reck_mung(): formula wrapper with gate and sample.
*/
static u2_noun
_reck_mung_in(u2_reck* rec_u, u2_noun gam)
{
u2_noun pro = u2_cn_mung(u2k(u2h(gam)), u2k(u2t(gam)));
u2z(gam); return pro;
}
static u2_noun
_reck_mung(u2_reck* rec_u, c3_w sec_w, u2_noun gat, u2_noun sam)
{
u2_noun gam = u2nc(gat, sam);
return u2_lo_soft(rec_u, 0, _reck_mung_in, gam);
}
/* u2_reck_pike(): poke with floating core.
*/
u2_noun
u2_reck_pike(u2_reck* rec_u, u2_noun ovo, u2_noun cor)
{
u2_noun fun = u2_cn_nock(cor, u2k(u2_cx_at(42, cor)));
u2_noun sam = u2nc(u2k(rec_u->now), ovo);
return _reck_mung(rec_u, 0, fun, sam);
}
/* u2_reck_nick(): transform enveloped packets, [vir cor].
*/
u2_noun
u2_reck_nick(u2_reck* rec_u, u2_noun vir, u2_noun cor)
{
if ( u2_nul == vir ) {
return u2nt(u2_blip, vir, cor);
}
else {
u2_noun i_vir = u2h(vir);
u2_noun pi_vir, qi_vir;
u2_noun vix;
if ( (u2_yes == u2_cr_cell((i_vir=u2h(vir)), &pi_vir, &qi_vir)) &&
(u2_yes == u2du(qi_vir)) &&
(c3__hear == u2h(qi_vir)) )
{
u2_noun gon;
gon = u2_reck_pike(rec_u, u2k(i_vir), cor);
if ( u2_blip != u2h(gon) ) {
u2z(vir);
return gon;
}
else {
u2_noun viz;
vix = u2k(u2h(u2t(gon)));
cor = u2k(u2t(u2t(gon)));
u2z(gon);
viz = u2_ckb_weld(vix, u2k(u2t(vir)));
u2z(vir);
return u2_reck_nick(rec_u, viz, cor);
}
}
else {
u2_noun nez = u2_reck_nick(rec_u, u2k(u2t(vir)), cor);
if ( u2_blip != u2h(nez) ) {
u2z(vir);
return nez;
} else {
u2_noun viz;
viz = u2nc(u2k(i_vir), u2k(u2h(u2t(nez))));
cor = u2k(u2t(u2t(nez)));
u2z(vir);
u2z(nez);
return u2nt(u2_blip, viz, cor);
}
}
}
}
/* _reck_spat(): spat with toy.
*/
static u2_noun
_reck_spat(u2_reck* rec_u, u2_noun pox)
{
return u2_do("spat", pox);
}
/* _reck_nock_poke(): call poke through hardcoded interface.
*/
static u2_noun
_reck_nock_poke(u2_reck* rec_u, u2_noun ovo)
{
u2_noun fun = u2_cn_nock(u2k(rec_u->roc), u2k(u2_cx_at(42, rec_u->roc)));
u2_noun sam, pro;
sam = u2nc(u2k(rec_u->now), ovo);
#if 0
{
c3_c* ovi_c = u2_cr_string(u2h(u2t(ovo)));
u2_noun tox = _reck_spat(rec_u, u2k(u2h(ovo)));
c3_c* tox_c = u2_cr_string(tox);
uL(fprintf(uH, "poke: %%%s on %s\n", ovi_c, tox_c));
free(tox_c); free(ovi_c); u2z(tox);
}
#endif
#if 0
{
c3_c* ovi_c = u2_cr_string(u2h(u2t(ovo)));
uL(fprintf(uH, "poke: %s\n", ovi_c));
free(ovi_c);
}
#endif
pro = u2_cn_mung(fun, sam);
return pro;
}
/* _reck_nock_peek(): call peek through hardcoded interface.
*/
static u2_noun
_reck_nock_peek(u2_reck* rec_u, u2_noun hap)
{
u2_noun fun = u2_cn_nock(u2k(rec_u->roc), u2k(u2_cx_at(87, rec_u->roc)));
u2_noun sam = u2nc(u2k(rec_u->now), hap);
return u2_cn_mung(fun, sam);
}
/* _reck_nock_keep(): call wait through hardcoded interface.
*/
static u2_noun
_reck_nock_keep(u2_reck* rec_u, u2_noun hap)
{
u2_noun fun = u2_cn_nock(u2k(rec_u->roc), u2k(u2_cx_at(4, rec_u->roc)));
u2_noun sam = u2nc(u2k(rec_u->now), hap);
return u2_cn_mung(fun, sam);
}
/* _reck_nock_wish(): call wish through hardcoded interface.
*/
static u2_noun
_reck_nock_wish(u2_reck* rec_u, u2_noun txt)
{
u2_noun fun = u2_cn_nock(u2k(rec_u->roc), u2k(u2_cx_at(20, rec_u->roc)));
return u2_cn_mung(fun, txt);
}
/* u2_reck_do(): use a kernel function.
*/
u2_noun
u2_reck_do(const c3_c* txt_c, u2_noun arg)
{
return u2_cn_mung(u2_reck_gate(txt_c), arg);
}
/* u2_reck_wish(): noun from expression
*/
u2_noun
u2_reck_wish(u2_reck* rec_u, c3_c* str_c)
{
return _reck_nock_wish(rec_u, u2_ci_string(str_c));
}
/* _reck_scot(): print atom.
*/
static u2_noun
_reck_scot(u2_reck* rec_u, u2_noun dim)
{
return u2_do("scot", dim);
}
/* u2_reck_time(): set the reck time.
*/
void
u2_reck_time(u2_reck* rec_u)
{
struct timeval tim_tv;
gettimeofday(&tim_tv, 0);
u2z(rec_u->now);
rec_u->now = u2_time_in_tv(&tim_tv);
u2z(rec_u->wen);
rec_u->wen = _reck_scot(rec_u, u2nc(c3__da, u2k(rec_u->now)));
}
/* u2_reck_wind(): set the reck time artificially.
*/
void
u2_reck_wind(u2_reck* rec_u, u2_noun now)
{
u2z(rec_u->now);
rec_u->now = now;
u2z(rec_u->wen);
rec_u->wen = _reck_scot(rec_u, u2nc(c3__da, u2k(rec_u->now)));
}
/* u2_reck_numb(): set the instance number.
*/
void
u2_reck_numb(u2_reck* rec_u)
{
struct timeval tp;
gettimeofday(&tp, 0);
rec_u->sev_l = 0x7fffffff &
( ((c3_w) tp.tv_sec) ^
u2_mug(0x7fffffff & ((c3_w) tp.tv_usec)) ^
u2_mug(getpid()));
u2z(rec_u->sen);
rec_u->sen = _reck_scot(rec_u, u2nc(c3__uv, rec_u->sev_l));
}
#if 0
/* _reck_time_bump(): advance the reck time by a small increment.
*/
static void
_reck_time_bump(u2_reck* rec_u)
{
c3_d bum_d = (1ULL << 48ULL);
rec_u->now = u2_cka_add(rec_u->now, u2_ci_chubs(1, &bum_d));
}
#endif
/* u2_reck_peek(): query the reck namespace (protected).
*/
u2_noun
u2_reck_peek(u2_reck* rec_u, u2_noun hap)
{
return _reck_nock_peek(rec_u, hap);
}
/* u2_reck_keep(): measure timer.
*/
u2_noun
u2_reck_keep(u2_reck* rec_u, u2_noun hap)
{
return _reck_nock_keep(rec_u, hap);
}
/* u2_reck_cold(): load full arvo with vanes, from new solid state.
*/
void
u2_reck_cold(u2_reck* rec_u, c3_w kno_w)
{
memset(rec_u, 0, sizeof(*rec_u));
rec_u->kno_w = kno_w;
rec_u->rno_w = 0;
rec_u->ent_d = 1;
rec_u->own = 0;
rec_u->now = 0;
rec_u->wen = 0;
rec_u->sen = 0;
rec_u->roe = 0;
rec_u->key = 0;
rec_u->yot = 0;
{
u2_noun pot, eng;
c3_c ful_c[2048];
if ( u2_yes == u2_Host.ops_u.nuu ) {
snprintf(ful_c, 2048, "%s/urbit.pill", U2_LIB);
} else {
snprintf(ful_c, 2048, "%s/.urb/urbit.pill", u2_Host.cpu_c);
}
printf("loading %s\n", ful_c);
if ( 0 == (pot = u2_walk_load(ful_c)) ) {
perror(ful_c);
exit(1);
}
// Copy into basket to propitiate jet gods.
{
u2_rail bas_r = u2_wire_bas_r(u2_Wire);
u2_noun tup;
tup = u2_cke_cue(pot);
eng = u2_rx(bas_r, tup);
u2z(tup);
}
rec_u->ken = u2h(eng);
rec_u->roc = u2t(eng);
// Execute from kernel to propitiate jet gods.
{
u2_noun fak;
fak = u2_cn_nock(0, rec_u->ken);
u2z(fak);
}
}
// Gates called deep when memory is wrapped.
{
u2z(u2_reck_gate("wash"));
u2z(u2_reck_gate("mook"));
}
u2_reck_time(rec_u);
u2_reck_numb(rec_u);
{
c3_c* dyt_c = u2_cr_string(rec_u->wen);
printf("time: %s\n", dyt_c);
free(dyt_c);
}
}
/* _reck_mole(): parse simple atomic mole. /* _reck_mole(): parse simple atomic mole.
*/ */
static u2_bean static u3_bean
_reck_mole(u2_reck* rec_u, _reck_mole(u3_noun fot,
u2_noun fot, u3_noun san,
u2_noun san,
c3_d* ato_d) c3_d* ato_d)
{ {
u2_noun uco = u2_do("slay", san); u3_noun uco = u3_do("slay", san);
u2_noun p_uco, q_uco, r_uco, s_uco; u3_noun p_uco, q_uco, r_uco, s_uco;
if ( (u2_no == u2_cr_qual(uco, &p_uco, &q_uco, &r_uco, &s_uco)) || if ( (u3_no == u3_cr_qual(uco, &p_uco, &q_uco, &r_uco, &s_uco)) ||
(0 != p_uco) || (0 != p_uco) ||
(0 != q_uco) || (0 != q_uco) ||
(u2_no == u2_sing(fot, r_uco)) ) (u3_no == u3_cr_sing(fot, r_uco)) )
{ {
uL(fprintf(uH, "strange mole %s\n", u2_cr_string(san))); uL(fprintf(uH, "strange mole %s\n", u3_cr_string(san)));
u2z(fot); u2z(uco); return u2_no; u3z(fot); u3z(uco); return u3_no;
} }
else { else {
*ato_d = u2_cr_chub(0, s_uco); *ato_d = u3_cr_chub(0, s_uco);
u2z(fot); u2z(uco); return u2_yes; u3z(fot); u3z(uco); return u3_yes;
} }
} }
/* _reck_lily(): parse little atom. /* _reck_lily(): parse little atom.
*/ */
static u2_bean static u3_bean
_reck_lily(u2_reck* rec_u, u2_noun fot, u2_noun txt, c3_l* tid_l) _reck_lily(u3_noun fot, u3_noun txt, c3_l* tid_l)
{ {
c3_d ato_d; c3_d ato_d;
if ( u2_no == _reck_mole(rec_u, fot, txt, &ato_d) ) { if ( u3_no == _reck_mole(fot, txt, &ato_d) ) {
return u2_no; return u3_no;
} else { } else {
if ( ato_d >= 0x80000000ULL ) { if ( ato_d >= 0x80000000ULL ) {
return u2_no; return u3_no;
} else { } else {
*tid_l = (c3_l) ato_d; *tid_l = (c3_l) ato_d;
return u2_yes; return u3_yes;
} }
} }
} }
/* _reck_kick_term(): apply terminal outputs. /* _reck_kick_term(): apply terminal outputs.
*/ */
static u2_bean static u3_bean
_reck_kick_term(u2_reck* rec_u, u2_noun pox, c3_l tid_l, u2_noun fav) _reck_kick_term(u3_noun pox, c3_l tid_l, u3_noun fav)
{ {
u2_noun p_fav; u3_noun p_fav;
if ( u2_no == u2du(fav) ) { if ( u3_no == u3du(fav) ) {
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
else switch ( u2h(fav) ) { else switch ( u3h(fav) ) {
default: u2z(pox); u2z(fav); return u2_no; default: u3z(pox); u3z(fav); return u3_no;
case c3__bbye: case c3__bbye:
{ {
u2_reck_sync(rec_u); u3z(pox); u3z(fav); return u3_yes;
// u2_reck_plan(rec_u, pox, u2nc(c3__helo, u2_nul));
u2z(pox); u2z(fav); return u2_yes;
} break; } break;
case c3__blit: p_fav = u2t(fav); case c3__blit: p_fav = u3t(fav);
{ {
u2_term_ef_blit(tid_l, u2k(p_fav)); u3_term_ef_blit(tid_l, u3k(p_fav));
u2z(pox); u2z(fav); return u2_yes; u3z(pox); u3z(fav); return u3_yes;
} break; } break;
case c3__logo: case c3__logo:
{ {
u2_Host.liv = u2_no; u3_Host.liv = u3_no;
u2_Host.xit_i = u2t(fav); u3_Host.xit_i = u3t(fav);
u2z(pox); u2z(fav); return u2_yes; u3z(pox); u3z(fav); return u3_yes;
} break; } break;
case c3__init: p_fav = u2t(fav); case c3__init: p_fav = u3t(fav);
{ {
rec_u->own = u2nc(u2k(p_fav), rec_u->own); u3A->own = u3nc(u3k(p_fav), u3A->own);
u2_unix_ef_init(u2k(p_fav)); u3_unix_ef_init(u3k(p_fav));
// uL(fprintf(uH, "kick: init: %d\n", p_fav)); // uL(fprintf(uH, "kick: init: %d\n", p_fav));
u2z(pox); u2z(fav); return u2_yes; u3z(pox); u3z(fav); return u3_yes;
} break; } break;
} }
c3_assert(!"not reached"); return 0; c3_assert(!"not reached"); return 0;
@ -448,380 +113,266 @@ _reck_kick_term(u2_reck* rec_u, u2_noun pox, c3_l tid_l, u2_noun fav)
/* _reck_kick_http(): apply http effects. /* _reck_kick_http(): apply http effects.
*/ */
static u2_bean static u3_bean
_reck_kick_http(u2_reck* rec_u, _reck_kick_http(u3_noun pox,
u2_noun pox,
c3_l sev_l, c3_l sev_l,
c3_l coq_l, c3_l coq_l,
c3_l seq_l, c3_l seq_l,
u2_noun fav) u3_noun fav)
{ {
u2_noun p_fav, q_fav; u3_noun p_fav, q_fav;
if ( u2_no == u2du(fav) ) { if ( u3_no == u3du(fav) ) {
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
else switch ( u2h(fav) ) { else switch ( u3h(fav) ) {
default: u2z(pox); u2z(fav); return u2_no; default: u3z(pox); u3z(fav); return u3_no;
case c3__thus: p_fav = u2h(u2t(fav)); q_fav = u2t(u2t(fav)); case c3__thus: p_fav = u3h(u3t(fav)); q_fav = u3t(u3t(fav));
{ {
u2_cttp_ef_thus(u2_cr_word(0, p_fav), u2k(q_fav)); u3_cttp_ef_thus(u3_cr_word(0, p_fav), u3k(q_fav));
u2z(pox); u2z(fav); u3z(pox); u3z(fav);
return u2_yes; return u3_yes;
} }
case c3__thou: p_fav = u2t(fav); case c3__thou: p_fav = u3t(fav);
{ {
u2_http_ef_thou(sev_l, coq_l, seq_l, u2k(p_fav)); u3_http_ef_thou(sev_l, coq_l, seq_l, u3k(p_fav));
u2z(pox); u2z(fav); u3z(pox); u3z(fav);
return u2_yes; return u3_yes;
} break; } break;
} }
c3_assert(!"not reached"); return u2_no; c3_assert(!"not reached"); return u3_no;
} }
/* _reck_kick_sync(): apply sync outputs. /* _reck_kick_sync(): apply sync outputs.
*/ */
static u2_bean static u3_bean
_reck_kick_sync(u2_reck* rec_u, u2_noun pox, u2_noun fav) _reck_kick_sync(u3_noun pox, u3_noun fav)
{ {
switch ( u2h(fav) ) { switch ( u3h(fav) ) {
default: break; default: break;
case c3__ergo: { case c3__ergo: {
u2_noun who = u2k(u2h(u2t(fav))); u3_noun who = u3k(u3h(u3t(fav)));
u2_noun syd = u2k(u2h(u2t(u2t(fav)))); u3_noun syd = u3k(u3h(u3t(u3t(fav))));
u2_noun rel = u2k(u2t(u2t(u2t(fav)))); u3_noun rel = u3k(u3t(u3t(u3t(fav))));
u2_unix_ef_ergo(who, syd, rel); u3_unix_ef_ergo(who, syd, rel);
u2z(pox); u2z(fav); return u2_yes; u3z(pox); u3z(fav); return u3_yes;
} break; } break;
} }
// XX obviously not right! // XX obviously not right!
// //
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
static u2_bean static u3_bean
_reck_kick_newt(u2_reck* rec_u, u2_noun pox, u2_noun fav) _reck_kick_newt(u3_noun pox, u3_noun fav)
{ {
u2_noun p_fav; switch ( u3h(fav) ) {
switch ( u2h(fav) ) {
default: break; default: break;
case c3__send: { case c3__send: {
u2_noun lan = u2k(u2h(u2t(fav))); u3_noun lan = u3k(u3h(u3t(fav)));
u2_noun pac = u2k(u2t(u2t(fav))); u3_noun pac = u3k(u3t(u3t(fav)));
u2_ames_ef_send(lan, pac); u3_ames_ef_send(lan, pac);
u2z(pox); u2z(fav); return u2_yes; u3z(pox); u3z(fav); return u3_yes;
} break; } break;
} }
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
/* _reck_kick_ames(): apply packet network outputs. /* _reck_kick_ames(): apply packet network outputs.
*/ */
static u2_bean static u3_bean
_reck_kick_ames(u2_reck* rec_u, u2_noun pox, u2_noun fav) _reck_kick_ames(u3_noun pox, u3_noun fav)
{ {
u2_noun p_fav; u3_noun p_fav;
switch ( u2h(fav) ) { switch ( u3h(fav) ) {
default: break; default: break;
case c3__init: p_fav = u2t(fav); case c3__init: p_fav = u3t(fav);
{ {
rec_u->own = u2nc(u2k(p_fav), rec_u->own); u3A->own = u3nc(u3k(p_fav), u3A->own);
u2_unix_ef_init(u2k(p_fav)); u3_unix_ef_init(u3k(p_fav));
// uL(fprintf(uH, "kick: init: %d\n", p_fav)); // uL(fprintf(uH, "kick: init: %d\n", p_fav));
u2z(pox); u2z(fav); return u2_yes; u3z(pox); u3z(fav); return u3_yes;
} break; } break;
} }
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
/* _reck_kick_spec(): apply an effect, by path. /* _reck_kick_spec(): apply an effect, by path.
*/ */
static u2_bean static u3_bean
_reck_kick_spec(u2_reck* rec_u, u2_noun pox, u2_noun fav) _reck_kick_spec(u3_noun pox, u3_noun fav)
{ {
u2_noun i_pox, t_pox; u3_noun i_pox, t_pox;
if ( (u2_no == u2_cr_cell(pox, &i_pox, &t_pox)) || if ( (u3_no == u3_cr_cell(pox, &i_pox, &t_pox)) ||
((i_pox != u2_blip) && ((i_pox != u3_blip) &&
(i_pox != c3__gold) && (i_pox != c3__gold) &&
(i_pox != c3__iron) && (i_pox != c3__iron) &&
(i_pox != c3__lead)) ) (i_pox != c3__lead)) )
{ {
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} else { } else {
u2_noun it_pox, tt_pox; u3_noun it_pox, tt_pox;
if ( (u2_no == u2_cr_cell(t_pox, &it_pox, &tt_pox)) ) { if ( (u3_no == u3_cr_cell(t_pox, &it_pox, &tt_pox)) ) {
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
else switch ( it_pox ) { else switch ( it_pox ) {
default: return u2_no; default: return u3_no;
case c3__http: { case c3__http: {
u2_noun pud = tt_pox; u3_noun pud = tt_pox;
u2_noun p_pud, t_pud, tt_pud, q_pud, r_pud, s_pud; u3_noun p_pud, t_pud, tt_pud, q_pud, r_pud, s_pud;
c3_l sev_l, coq_l, seq_l; c3_l sev_l, coq_l, seq_l;
if ( (u2_no == u2_cr_cell(pud, &p_pud, &t_pud)) || if ( (u3_no == u3_cr_cell(pud, &p_pud, &t_pud)) ||
(u2_no == _reck_lily(rec_u, c3__uv, u2k(p_pud), &sev_l)) ) (u3_no == _reck_lily(c3__uv, u3k(p_pud), &sev_l)) )
{ {
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
if ( u2_nul == t_pud ) { if ( u3_nul == t_pud ) {
coq_l = seq_l = 0; coq_l = seq_l = 0;
} }
else { else {
if ( (u2_no == u2_cr_cell(t_pud, &q_pud, &tt_pud)) || if ( (u3_no == u3_cr_cell(t_pud, &q_pud, &tt_pud)) ||
(u2_no == _reck_lily(rec_u, c3__ud, u2k(q_pud), &coq_l)) ) (u3_no == _reck_lily(c3__ud, u3k(q_pud), &coq_l)) )
{ {
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
if ( u2_nul == tt_pud ) { if ( u3_nul == tt_pud ) {
seq_l = 0; seq_l = 0;
} else { } else {
if ( (u2_no == u2_cr_cell(tt_pud, &r_pud, &s_pud)) || if ( (u3_no == u3_cr_cell(tt_pud, &r_pud, &s_pud)) ||
(u2_nul != s_pud) || (u3_nul != s_pud) ||
(u2_no == _reck_lily(rec_u, c3__ud, u2k(r_pud), &seq_l)) ) (u3_no == _reck_lily(c3__ud, u3k(r_pud), &seq_l)) )
{ {
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
} }
} }
return _reck_kick_http(rec_u, pox, sev_l, coq_l, seq_l, fav); return _reck_kick_http(pox, sev_l, coq_l, seq_l, fav);
} break; } break;
case c3__clay: case c3__clay:
case c3__sync: { case c3__sync: {
return _reck_kick_sync(rec_u, pox, fav); return _reck_kick_sync(pox, fav);
} break; } break;
case c3__newt: { case c3__newt: {
return _reck_kick_newt(rec_u, pox, fav); return _reck_kick_newt(pox, fav);
} break; } break;
case c3__ames: { case c3__ames: {
if ( (u2_nul != tt_pox) ) { if ( (u3_nul != tt_pox) ) {
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
else { else {
return _reck_kick_ames(rec_u, pox, fav); return _reck_kick_ames(pox, fav);
} }
} break; } break;
case c3__term: { case c3__term: {
u2_noun pud = tt_pox; u3_noun pud = tt_pox;
u2_noun p_pud, q_pud; u3_noun p_pud, q_pud;
c3_l tid_l; c3_l tid_l;
if ( (u2_no == u2_cr_cell(pud, &p_pud, &q_pud)) || if ( (u3_no == u3_cr_cell(pud, &p_pud, &q_pud)) ||
(u2_nul != q_pud) || (u3_nul != q_pud) ||
(u2_no == _reck_lily(rec_u, c3__ud, u2k(p_pud), &tid_l)) ) (u3_no == _reck_lily(c3__ud, u3k(p_pud), &tid_l)) )
{ {
uL(fprintf(uH, "term: bad tire\n")); uL(fprintf(uH, "term: bad tire\n"));
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} else { } else {
return _reck_kick_term(rec_u, pox, tid_l, fav); return _reck_kick_term(pox, tid_l, fav);
} }
} break; } break;
} }
} }
c3_assert(!"not reached"); c3_assert(!"not reached");
return u2_no; return u3_no;
} }
/* _reck_kick_norm(): non path-specific effect handling. /* _reck_kick_norm(): non path-specific effect handling.
*/ */
static u2_bean static u3_bean
_reck_kick_norm(u2_reck* rec_u, u2_noun pox, u2_noun fav) _reck_kick_norm(u3_noun pox, u3_noun fav)
{ {
if ( u2_no == u2du(fav) ) { if ( u3_no == u3du(fav) ) {
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
else switch ( u2h(fav) ) { else switch ( u3h(fav) ) {
default: u2z(pox); u2z(fav); return u2_no; default: u3z(pox); u3z(fav); return u3_no;
case c3__vega: case c3__vega:
{ {
// uL(fprintf(uH, "reset\n")); // uL(fprintf(uH, "reset\n"));
u2z(pox); u2z(fav); u3z(pox); u3z(fav);
// u2_ds_wipe(u2_Wire); // doesn't work // u3_ds_wipe(u3_Wire); // doesn't work
return u2_yes; return u3_yes;
} }
case c3__exit: case c3__exit:
{ {
uL(fprintf(uH, "<<<goodbye>>>\n")); uL(fprintf(uH, "<<<goodbye>>>\n"));
u2_lo_bail(rec_u); u3_lo_bail();
u2z(pox); u2z(fav); return u2_yes; u3z(pox); u3z(fav); return u3_yes;
} break; } break;
} }
c3_assert(!"not reached"); return u2_no; c3_assert(!"not reached"); return u3_no;
u2z(pox); u2z(fav); return u2_no; u3z(pox); u3z(fav); return u3_no;
} }
/* u2_reck_kick(): handle effect. /* u3_reck_kick(): handle effect.
*/ */
void void
u2_reck_kick(u2_reck* rec_u, u2_noun ovo) u3_reck_kick(u3_noun ovo)
{ {
if ( (u2_no == _reck_kick_spec(rec_u, u2k(u2h(ovo)), u2k(u2t(ovo)))) && if ( (u3_no == _reck_kick_spec(u3k(u3h(ovo)), u3k(u3t(ovo)))) &&
(u2_no == _reck_kick_norm(rec_u, u2k(u2h(ovo)), u2k(u2t(ovo)))) ) (u3_no == _reck_kick_norm(u3k(u3h(ovo)), u3k(u3t(ovo)))) )
{ {
u2_noun tox = _reck_spat(rec_u, u2k(u2h(ovo))); u3_noun tox = u3_do("spat", u3k(u3h(ovo)));
#if 0 #if 0
if ( (c3__warn != u2h(u2t(ovo))) && if ( (c3__warn != u3h(u3t(ovo))) &&
(c3__text != u2h(u2t(ovo))) && (c3__text != u3h(u3t(ovo))) &&
(c3__note != u2h(u2t(ovo))) ) (c3__note != u3h(u3t(ovo))) )
#endif #endif
#if 1 #if 1
if ( (c3__crud == u2h(u2t(ovo))) ) if ( (c3__crud == u3h(u3t(ovo))) )
#if 0 #if 0
(c3__talk == u2h(u2t(ovo))) || (c3__talk == u3h(u3t(ovo))) ||
(c3__helo == u2h(u2t(ovo))) || (c3__helo == u3h(u3t(ovo))) ||
(c3__init == u2h(u2t(ovo))) ) (c3__init == u3h(u3t(ovo))) )
#endif #endif
{ {
u2_reck_plan(rec_u, u2nt(u2_blip, c3__term, u2_nul), u3_cv_plan(u3nt(u3_blip, c3__term, u3_nul),
u2nc(c3__flog, u2k(u2t(ovo)))); u3nc(c3__flog, u3k(u3t(ovo))));
} }
else { else {
uL(fprintf(uH, "kick: lost %%%s on %s\n", uL(fprintf(uH, "kick: lost %%%s on %s\n",
u2_cr_string(u2h(u2t(ovo))), u3_cr_string(u3h(u3t(ovo))),
u2_cr_string(tox))); u3_cr_string(tox)));
#if 0 #if 0
if ( c3__hear == u2h(u2t(ovo)) ) { if ( c3__hear == u3h(u3t(ovo)) ) {
c3_assert(0); c3_assert(0);
} }
#endif #endif
} }
#endif #endif
u2z(tox); u3z(tox);
} }
u2z(ovo); u3z(ovo);
}
/* u2_reck_poke(): insert and apply an input ovum (protected).
*/
u2_noun
u2_reck_poke(u2_reck* rec_u, u2_noun ovo)
{
return _reck_nock_poke(rec_u, ovo);
}
/* u2_reck_sync(): poll and apply sync events (protected).
*/
void
u2_reck_sync(u2_reck* rec_u)
{
#if 0
u2_reck_plow(rec_u, u2_sync_reck(rec_u));
#endif
}
/* u2_reck_boot(): boot the reck engine (unprotected).
*/
void
u2_reck_boot(u2_reck* rec_u)
{
u2_noun hoe;
memset(rec_u, 0, sizeof *rec_u);
if ( 0 != (hoe = u2_cm_trap()) ) {
u2_cm_purge();
u2_lo_sway(2, u2_ckb_flop(u2k(u2t(hoe))));
u2z(hoe);
exit(1);
}
else {
u2_reck_cold(rec_u, u2_Host.kno_w);
u2_cm_done();
u2_cm_purge();
}
}
/* u2_reck_http_request(): hear http request on channel (unprotected).
*/
void
u2_reck_http_request(u2_reck* rec_u, u2_bean sec, u2_noun pox, u2_noun req)
{
// uL(fprintf(uH, "http: request\n"));
u2_reck_plan(rec_u, pox, u2nq(c3__this, sec, 0, req));
}
/* u2_reck_prick(): query the reck namespace (unprotected).
*/
u2_noun
u2_reck_prick(u2_reck* rec_u, u2_noun hap)
{
u2_noun hoe;
u2_noun que;
if ( 0 != (hoe = u2_cm_trap()) ) {
u2_cm_purge();
u2_lo_sway(2, u2_ckb_flop(u2k(u2t(hoe))));
u2z(hoe);
return u2_nul;
}
else {
que = u2_reck_peek(rec_u, hap);
u2_cm_done();
u2_cm_purge();
}
return que;
}
/* u2_reck_plan(): queue ovum (external).
*/
void
u2_reck_plan(u2_reck* rec_u,
u2_noun pax,
u2_noun fav)
{
if ( u2_raty_lead == u2R->typ_e ) {
u2_noun egg = u2nc(pax, fav);
rec_u->roe = u2nc(u2nc(u2_nul, egg), rec_u->roe);
}
else {
c3_c* hed_c = u2_cr_string(u2h(u2t(pax)));
uL(fprintf(uH, "reck: dropping roe from %s\n", hed_c));
free(hed_c);
u2z(pax); u2z(fav);
}
}
/* u2_reck_plow(): queue multiple ova (external).
*/
void
u2_reck_plow(u2_reck* rec_u, u2_noun ova)
{
u2_noun ovi = ova;
while ( u2_nul != ovi ) {
u2_noun ovo=u2h(ovi);
u2_reck_plan(rec_u, u2k(u2h(ovo)), u2k(u2t(ovo)));
ovi = u2t(ovi);
}
u2z(ova);
} }

View File

@ -26,7 +26,7 @@ _save_sign_cb(uv_signal_t* sil_u, c3_i num_i)
uL(fprintf(uH, "save: signal %d\n", num_i)); uL(fprintf(uH, "save: signal %d\n", num_i));
{ {
switch ( num_i ) { switch ( num_i ) {
case SIGCHLD: u2_save_ef_chld(); break; case SIGCHLD: u3_save_ef_chld(); break;
} }
} }
} }
@ -36,43 +36,43 @@ _save_sign_cb(uv_signal_t* sil_u, c3_i num_i)
static void static void
_save_time_cb(uv_timer_t* tim_u, c3_i sas_i) _save_time_cb(uv_timer_t* tim_u, c3_i sas_i)
{ {
u2_save* sav_u = &u2_Host.sav_u; u3_save* sav_u = &u3_Host.sav_u;
if ( sav_u->pid_w ) { if ( sav_u->pid_w ) {
return; return;
} }
if ( u2A->ent_d > sav_u->ent_d ) { if ( u3A->ent_d > sav_u->ent_d ) {
// uL(fprintf(uH, "autosaving... ent_d %llu\n", u2A->ent_d)); // uL(fprintf(uH, "autosaving... ent_d %llu\n", u3A->ent_d));
u2_cm_purge(); u3_cm_purge();
// u2_lo_grab("save", u2_none); // u3_lo_grab("save", u3_none);
#ifdef FORKPT #ifdef FORKPT
c3_w pid_w; c3_w pid_w;
if ( 0 == (pid_w = fork()) ) { if ( 0 == (pid_w = fork()) ) {
u2_loom_save(u2A->ent_d); u3_loom_save(u3A->ent_d);
exit(0); exit(0);
} }
else { else {
uL(fprintf(uH, "checkpoint: process %d\n", pid_w)); uL(fprintf(uH, "checkpoint: process %d\n", pid_w));
sav_u->ent_d = u2A->ent_d; sav_u->ent_d = u3A->ent_d;
sav_u->pid_w = pid_w; sav_u->pid_w = pid_w;
} }
#else #else
u2_loom_save(u2A->ent_d); u3_loom_save(u3A->ent_d);
sav_u->ent_d = u2A->ent_d; sav_u->ent_d = u3A->ent_d;
#endif #endif
} }
} }
/* u2_save_ef_chld(): report save termination. /* u3_save_ef_chld(): report save termination.
*/ */
void void
u2_save_ef_chld(void) u3_save_ef_chld(void)
{ {
u2_save* sav_u = &u2_Host.sav_u; u3_save* sav_u = &u3_Host.sav_u;
c3_i loc_i; c3_i loc_i;
c3_w pid_w; c3_w pid_w;
@ -89,33 +89,32 @@ u2_save_ef_chld(void)
sav_u->pid_w = 0; sav_u->pid_w = 0;
} }
/* u2_save_io_init(): initialize autosave. /* u3_save_io_init(): initialize autosave.
*/ */
void void
u2_save_io_init(void) u3_save_io_init(void)
{ {
u2_save* sav_u = &u2_Host.sav_u; u3_save* sav_u = &u3_Host.sav_u;
sav_u->ent_d = 0; sav_u->ent_d = 0;
sav_u->pid_w = 0; sav_u->pid_w = 0;
uv_timer_init(u2L, &sav_u->tim_u); uv_timer_init(u3L, &sav_u->tim_u);
uv_timer_start(&sav_u->tim_u, _save_time_cb, 15000, 15000); uv_timer_start(&sav_u->tim_u, _save_time_cb, 15000, 15000);
uv_signal_start(&sav_u->sil_u, _save_sign_cb, SIGCHLD); uv_signal_start(&sav_u->sil_u, _save_sign_cb, SIGCHLD);
} }
/* u2_save_io_exit(): terminate save I/O. /* u3_save_io_exit(): terminate save I/O.
*/ */
void void
u2_save_io_exit(void) u3_save_io_exit(void)
{ {
} }
/* u2_save_io_poll(): poll kernel for save I/O. /* u3_save_io_poll(): poll kernel for save I/O.
*/ */
void void
u2_save_io_poll(void) u3_save_io_poll(void)
{ {
} }

692
v/sist.c

File diff suppressed because it is too large Load Diff

404
v/term.c
View File

@ -29,7 +29,7 @@ static void _term_read_tn_cb(uv_stream_t* tcp_u,
static void _term_read_cb(uv_stream_t* tcp_u, static void _term_read_cb(uv_stream_t* tcp_u,
ssize_t siz_i, ssize_t siz_i,
const uv_buf_t * buf_u); const uv_buf_t * buf_u);
static void _term_suck(u2_utty*, const c3_y*, ssize_t); static void _term_suck(u3_utty*, const c3_y*, ssize_t);
static void _tel_event(telnet_nvt*, telnet_event*); static void _tel_event(telnet_nvt*, telnet_event*);
static void _tel_opt(telnet_nvt*, telnet_byte, telnet_telopt_event*); static void _tel_opt(telnet_nvt*, telnet_byte, telnet_telopt_event*);
@ -55,13 +55,13 @@ _term_alloc(uv_handle_t* had_u,
static void static void
_term_close_cb(uv_handle_t* han_t) _term_close_cb(uv_handle_t* han_t)
{ {
u2_utty* tty_u = (void*) han_t; u3_utty* tty_u = (void*) han_t;
if ( u2_Host.uty_u == tty_u ) { if ( u3_Host.uty_u == tty_u ) {
u2_Host.uty_u = tty_u->nex_u; u3_Host.uty_u = tty_u->nex_u;
} }
else { else {
u2_utty* uty_u; u3_utty* uty_u;
for (uty_u = u2_Host.uty_u; uty_u; uty_u = uty_u->nex_u ) { for (uty_u = u3_Host.uty_u; uty_u; uty_u = uty_u->nex_u ) {
if ( uty_u->nex_u == tty_u ) { if ( uty_u->nex_u == tty_u ) {
uty_u->nex_u = tty_u->nex_u; uty_u->nex_u = tty_u->nex_u;
break; break;
@ -70,10 +70,10 @@ _term_close_cb(uv_handle_t* han_t)
} }
{ {
u2_noun tid = u2_dc("scot", c3__ud, tty_u->tid_l); u3_noun tid = u3_dc("scot", c3__ud, tty_u->tid_l);
u2_noun pax = u2nq(u2_blip, c3__term, tid, u2_nul); u3_noun pax = u3nq(u3_blip, c3__term, tid, u3_nul);
u2_reck_plan(u2A, u2k(pax), u2nc(c3__hook, u2_nul)); u3_cv_plan(u3k(pax), u3nc(c3__hook, u3_nul));
u2z(pax); u3z(pax);
} }
free(tty_u); free(tty_u);
} }
@ -83,22 +83,22 @@ _term_close_cb(uv_handle_t* han_t)
static void static void
_tel_close_cb(uv_handle_t* han_t) _tel_close_cb(uv_handle_t* han_t)
{ {
u2_utel* pty_u = (u2_utel*)(void*)han_t; u3_utel* pty_u = (u3_utel*)(void*)han_t;
telnet_nvt_free(pty_u->tel_u); telnet_nvt_free(pty_u->tel_u);
_term_close_cb(han_t); _term_close_cb(han_t);
} }
/* u2_term_io_init(): initialize terminal. /* u3_term_io_init(): initialize terminal.
*/ */
void void
u2_term_io_init() u3_term_io_init()
{ {
u2_utty* uty_u = calloc(1, sizeof(u2_utty)); u3_utty* uty_u = calloc(1, sizeof(u3_utty));
if ( u2_yes == u2_Host.ops_u.dem ) { if ( u3_yes == u3_Host.ops_u.dem ) {
uty_u->fid_i = 1; uty_u->fid_i = 1;
uv_pipe_init(u2L, &(uty_u->pop_u), 0); uv_pipe_init(u3L, &(uty_u->pop_u), 0);
uv_pipe_open(&(uty_u->pop_u), uty_u->fid_i); uv_pipe_open(&(uty_u->pop_u), uty_u->fid_i);
} }
else { else {
@ -107,7 +107,7 @@ u2_term_io_init()
{ {
uty_u->fid_i = 0; // stdin, yes we write to it... uty_u->fid_i = 0; // stdin, yes we write to it...
uv_pipe_init(u2L, &(uty_u->pop_u), 0); uv_pipe_init(u3L, &(uty_u->pop_u), 0);
uv_pipe_open(&(uty_u->pop_u), uty_u->fid_i); uv_pipe_open(&(uty_u->pop_u), uty_u->fid_i);
uv_read_start((uv_stream_t*)&(uty_u->pop_u), _term_alloc, _term_read_cb); uv_read_start((uv_stream_t*)&(uty_u->pop_u), _term_alloc, _term_read_cb);
} }
@ -217,8 +217,8 @@ u2_term_io_init()
uty_u->tat_u.mir.len_w = 0; uty_u->tat_u.mir.len_w = 0;
uty_u->tat_u.mir.cus_w = 0; uty_u->tat_u.mir.cus_w = 0;
uty_u->tat_u.esc.ape = u2_no; uty_u->tat_u.esc.ape = u3_no;
uty_u->tat_u.esc.bra = u2_no; uty_u->tat_u.esc.bra = u3_no;
uty_u->tat_u.fut.len_w = 0; uty_u->tat_u.fut.len_w = 0;
uty_u->tat_u.fut.wid_w = 0; uty_u->tat_u.fut.wid_w = 0;
@ -230,10 +230,10 @@ u2_term_io_init()
{ {
uty_u->tid_l = 1; uty_u->tid_l = 1;
uty_u->nex_u = 0; uty_u->nex_u = 0;
u2_Host.uty_u = uty_u; u3_Host.uty_u = uty_u;
} }
if ( u2_no == u2_Host.ops_u.dem ) { if ( u3_no == u3_Host.ops_u.dem ) {
// Start raw input. // Start raw input.
// //
{ {
@ -250,9 +250,9 @@ u2_term_io_init()
void void
_term_listen_cb(uv_stream_t *wax_u, int sas_i) _term_listen_cb(uv_stream_t *wax_u, int sas_i)
{ {
u2_utel* pty_u = calloc(1, sizeof(*pty_u)); u3_utel* pty_u = calloc(1, sizeof(*pty_u));
u2_utty* tty_u = &pty_u->uty_t; u3_utty* tty_u = &pty_u->uty_t;
uv_tcp_init(u2L, &tty_u->wax_u); uv_tcp_init(u3L, &tty_u->wax_u);
c3_w ret_w; c3_w ret_w;
if ( 0 != (ret_w = uv_accept(wax_u, (uv_stream_t*)&tty_u->wax_u)) ) { if ( 0 != (ret_w = uv_accept(wax_u, (uv_stream_t*)&tty_u->wax_u)) ) {
uL(fprintf(uH, "term: accept: %s\n", uL(fprintf(uH, "term: accept: %s\n",
@ -287,8 +287,8 @@ _term_listen_cb(uv_stream_t *wax_u, int sas_i)
tty_u->tat_u.mir.len_w = 0; tty_u->tat_u.mir.len_w = 0;
tty_u->tat_u.mir.cus_w = 0; tty_u->tat_u.mir.cus_w = 0;
tty_u->tat_u.esc.ape = u2_no; tty_u->tat_u.esc.ape = u3_no;
tty_u->tat_u.esc.bra = u2_no; tty_u->tat_u.esc.bra = u3_no;
tty_u->tat_u.fut.len_w = 0; tty_u->tat_u.fut.len_w = 0;
tty_u->tat_u.fut.wid_w = 0; tty_u->tat_u.fut.wid_w = 0;
@ -296,17 +296,17 @@ _term_listen_cb(uv_stream_t *wax_u, int sas_i)
tty_u->tat_u.siz.col_l = 80; tty_u->tat_u.siz.col_l = 80;
tty_u->tat_u.siz.row_l = 25; tty_u->tat_u.siz.row_l = 25;
tty_u->tid_l = u2_Host.uty_u->tid_l + 1; tty_u->tid_l = u3_Host.uty_u->tid_l + 1;
tty_u->nex_u = u2_Host.uty_u; tty_u->nex_u = u3_Host.uty_u;
u2_Host.uty_u = tty_u; u3_Host.uty_u = tty_u;
pty_u->tel_u = telnet_nvt_new(tty_u, _tel_event, _tel_opt, NULL); pty_u->tel_u = telnet_nvt_new(tty_u, _tel_event, _tel_opt, NULL);
{ {
u2_noun tid = u2_dc("scot", c3__ud, tty_u->tid_l); u3_noun tid = u3_dc("scot", c3__ud, tty_u->tid_l);
u2_noun pax = u2nq(u2_blip, c3__term, tid, u2_nul); u3_noun pax = u3nq(u3_blip, c3__term, tid, u3_nul);
u2_reck_plan(u2A, u2k(pax), u2nc(c3__blew, u2nc(80, 25))); u3_cv_plan(u3k(pax), u3nc(c3__blew, u3nc(80, 25)));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul)); u3_cv_plan(u3k(pax), u3nc(c3__hail, u3_nul));
u2z(pax); u3z(pax);
} }
telnet_telopt_enable(pty_u->tel_u, _T_ECHO, TELNET_LOCAL); telnet_telopt_enable(pty_u->tel_u, _T_ECHO, TELNET_LOCAL);
@ -316,12 +316,12 @@ _term_listen_cb(uv_stream_t *wax_u, int sas_i)
} }
void void
u2_term_io_talk(void) u3_term_io_talk(void)
{ {
struct sockaddr_in add_u; struct sockaddr_in add_u;
u2_utel* tel_u = &u2_Host.tel_u; u3_utel* tel_u = &u3_Host.tel_u;
uv_tcp_init(u2L, &tel_u->uty_t.wax_u); uv_tcp_init(u3L, &tel_u->uty_t.wax_u);
tel_u->por_s = 10023; tel_u->por_s = 10023;
memset(&add_u, 0, sizeof(add_u)); memset(&add_u, 0, sizeof(add_u));
@ -360,18 +360,18 @@ u2_term_io_talk(void)
} }
} }
/* u2_term_io_exit(): clean up terminal. /* u3_term_io_exit(): clean up terminal.
*/ */
void void
u2_term_io_exit(void) u3_term_io_exit(void)
{ {
if ( u2_yes == u2_Host.ops_u.dem ) { if ( u3_yes == u3_Host.ops_u.dem ) {
uv_close((uv_handle_t*)&u2_Host.uty_u->pop_u, NULL); uv_close((uv_handle_t*)&u3_Host.uty_u->pop_u, NULL);
} }
else { else {
u2_utty* uty_u; u3_utty* uty_u;
for ( uty_u = u2_Host.uty_u; uty_u; uty_u = uty_u->nex_u ) { for ( uty_u = u3_Host.uty_u; uty_u; uty_u = uty_u->nex_u ) {
if ( uty_u->fid_i == -1 ) { continue; } if ( uty_u->fid_i == -1 ) { continue; }
if ( 0 != tcsetattr(uty_u->fid_i, TCSADRAIN, &uty_u->bak_u) ) { if ( 0 != tcsetattr(uty_u->fid_i, TCSADRAIN, &uty_u->bak_u) ) {
c3_assert(!"exit-tcsetattr"); c3_assert(!"exit-tcsetattr");
@ -385,16 +385,16 @@ u2_term_io_exit(void)
} }
void void
u2_term_io_poll(void) u3_term_io_poll(void)
{ {
} }
/* _term_it_buf(): create a data buffer. /* _term_it_buf(): create a data buffer.
*/ */
static u2_ubuf* static u3_ubuf*
_term_it_buf(c3_w len_w, const c3_y* hun_y) _term_it_buf(c3_w len_w, const c3_y* hun_y)
{ {
u2_ubuf* buf_u = c3_malloc(len_w + sizeof(*buf_u)); u3_ubuf* buf_u = c3_malloc(len_w + sizeof(*buf_u));
buf_u->len_w = len_w; buf_u->len_w = len_w;
memcpy(buf_u->hun_y, hun_y, len_w); memcpy(buf_u->hun_y, hun_y, len_w);
@ -408,14 +408,14 @@ _term_it_buf(c3_w len_w, const c3_y* hun_y)
typedef struct { typedef struct {
uv_write_t wri_u; uv_write_t wri_u;
c3_y* buf_y; c3_y* buf_y;
} _u2_write_t; } _u3_write_t;
/* _term_write_cb(): general write callback. /* _term_write_cb(): general write callback.
*/ */
static void static void
_term_write_cb(uv_write_t* wri_u, c3_i sas_i) _term_write_cb(uv_write_t* wri_u, c3_i sas_i)
{ {
_u2_write_t* ruq_u = (void *)wri_u; _u3_write_t* ruq_u = (void *)wri_u;
if ( 0 != sas_i ) { if ( 0 != sas_i ) {
uL(fprintf(uH, "term: write: ERROR\n")); uL(fprintf(uH, "term: write: ERROR\n"));
@ -427,9 +427,9 @@ _term_write_cb(uv_write_t* wri_u, c3_i sas_i)
/* _term_it_write_buf(): write buffer uv style. /* _term_it_write_buf(): write buffer uv style.
*/ */
static void static void
_term_it_write_buf(u2_utty* uty_u, uv_buf_t buf_u) _term_it_write_buf(u3_utty* uty_u, uv_buf_t buf_u)
{ {
_u2_write_t* ruq_u = (_u2_write_t*) c3_malloc(sizeof(_u2_write_t)); _u3_write_t* ruq_u = (_u3_write_t*) c3_malloc(sizeof(_u3_write_t));
ruq_u->buf_y = (c3_y*)buf_u.base; ruq_u->buf_y = (c3_y*)buf_u.base;
@ -446,8 +446,8 @@ _term_it_write_buf(u2_utty* uty_u, uv_buf_t buf_u)
/* _term_it_write_old(): write buffer, transferring pointer. /* _term_it_write_old(): write buffer, transferring pointer.
*/ */
static void static void
_term_it_write_old(u2_utty* uty_u, _term_it_write_old(u3_utty* uty_u,
u2_ubuf* old_u) u3_ubuf* old_u)
{ {
uv_buf_t buf_u; uv_buf_t buf_u;
@ -467,7 +467,7 @@ _term_it_write_old(u2_utty* uty_u,
/* _term_it_write_bytes(): write bytes, retaining pointer. /* _term_it_write_bytes(): write bytes, retaining pointer.
*/ */
static void static void
_term_it_write_bytes(u2_utty* uty_u, _term_it_write_bytes(u3_utty* uty_u,
c3_w len_w, c3_w len_w,
const c3_y* hun_y) const c3_y* hun_y)
{ {
@ -477,7 +477,7 @@ _term_it_write_bytes(u2_utty* uty_u,
/* _term_it_write_txt(): write null-terminated string, retaining pointer. /* _term_it_write_txt(): write null-terminated string, retaining pointer.
*/ */
static void static void
_term_it_write_txt(u2_utty* uty_u, _term_it_write_txt(u3_utty* uty_u,
const c3_y* hun_y) const c3_y* hun_y)
{ {
_term_it_write_bytes(uty_u, strlen((const c3_c*)hun_y), hun_y); _term_it_write_bytes(uty_u, strlen((const c3_c*)hun_y), hun_y);
@ -486,7 +486,7 @@ _term_it_write_txt(u2_utty* uty_u,
/* _term_it_write_str(): write null-terminated string, retaining pointer. /* _term_it_write_str(): write null-terminated string, retaining pointer.
*/ */
static void static void
_term_it_write_str(u2_utty* uty_u, _term_it_write_str(u3_utty* uty_u,
const c3_c* str_c) const c3_c* str_c)
{ {
_term_it_write_txt(uty_u, (const c3_y*) str_c); _term_it_write_txt(uty_u, (const c3_y*) str_c);
@ -495,15 +495,15 @@ _term_it_write_str(u2_utty* uty_u,
/* _term_it_show_wide(): show wide text, retaining. /* _term_it_show_wide(): show wide text, retaining.
*/ */
static void static void
_term_it_show_wide(u2_utty* uty_u, c3_w len_w, c3_w* txt_w) _term_it_show_wide(u3_utty* uty_u, c3_w len_w, c3_w* txt_w)
{ {
u2_noun wad = u2_ci_words(len_w, txt_w); u3_noun wad = u3_ci_words(len_w, txt_w);
u2_noun txt = u2_do("tuft", wad); u3_noun txt = u3_do("tuft", wad);
c3_c* txt_c = u2_cr_string(txt); c3_c* txt_c = u3_cr_string(txt);
_term_it_write_str(uty_u, txt_c); _term_it_write_str(uty_u, txt_c);
free(txt_c); free(txt_c);
u2z(txt); u3z(txt);
uty_u->tat_u.mir.cus_w += len_w; uty_u->tat_u.mir.cus_w += len_w;
} }
@ -511,9 +511,9 @@ _term_it_show_wide(u2_utty* uty_u, c3_w len_w, c3_w* txt_w)
/* _term_it_show_clear(): clear to the beginning of the current line. /* _term_it_show_clear(): clear to the beginning of the current line.
*/ */
static void static void
_term_it_show_clear(u2_utty* uty_u) _term_it_show_clear(u3_utty* uty_u)
{ {
u2_utat* tat_u = &uty_u->tat_u; u3_utat* tat_u = &uty_u->tat_u;
if ( tat_u->siz.col_l ) { if ( tat_u->siz.col_l ) {
c3_w ful_w = tat_u->mir.cus_w / tat_u->siz.col_l; c3_w ful_w = tat_u->mir.cus_w / tat_u->siz.col_l;
@ -539,7 +539,7 @@ _term_it_show_clear(u2_utty* uty_u)
/* _term_it_show_blank(): blank the screen. /* _term_it_show_blank(): blank the screen.
*/ */
static void static void
_term_it_show_blank(u2_utty* uty_u) _term_it_show_blank(u3_utty* uty_u)
{ {
_term_it_write_txt(uty_u, uty_u->ufo_u.out.clear_y); _term_it_write_txt(uty_u, uty_u->ufo_u.out.clear_y);
uty_u->tat_u.mir.cus_w = 0; uty_u->tat_u.mir.cus_w = 0;
@ -548,7 +548,7 @@ _term_it_show_blank(u2_utty* uty_u)
/* _term_it_show_cursor(): set current line, transferring pointer. /* _term_it_show_cursor(): set current line, transferring pointer.
*/ */
static void static void
_term_it_show_cursor(u2_utty* uty_u, c3_w cur_w) _term_it_show_cursor(u3_utty* uty_u, c3_w cur_w)
{ {
if ( cur_w < uty_u->tat_u.mir.cus_w ) { if ( cur_w < uty_u->tat_u.mir.cus_w ) {
c3_w dif_w = (uty_u->tat_u.mir.cus_w - cur_w); c3_w dif_w = (uty_u->tat_u.mir.cus_w - cur_w);
@ -570,7 +570,7 @@ _term_it_show_cursor(u2_utty* uty_u, c3_w cur_w)
/* _term_it_show_line(): set current line /* _term_it_show_line(): set current line
*/ */
static void static void
_term_it_show_line(u2_utty* uty_u, c3_w* lin_w, c3_w len_w) _term_it_show_line(u3_utty* uty_u, c3_w* lin_w, c3_w len_w)
{ {
_term_it_show_wide(uty_u, len_w, lin_w); _term_it_show_wide(uty_u, len_w, lin_w);
@ -586,7 +586,7 @@ _term_it_show_line(u2_utty* uty_u, c3_w* lin_w, c3_w len_w)
/* _term_it_refresh_line(): refresh current line. /* _term_it_refresh_line(): refresh current line.
*/ */
static void static void
_term_it_refresh_line(u2_utty* uty_u) _term_it_refresh_line(u3_utty* uty_u)
{ {
c3_w len_w = uty_u->tat_u.mir.len_w; c3_w len_w = uty_u->tat_u.mir.len_w;
@ -597,9 +597,9 @@ _term_it_refresh_line(u2_utty* uty_u)
/* _term_it_show_more(): new current line. /* _term_it_show_more(): new current line.
*/ */
static void static void
_term_it_show_more(u2_utty* uty_u) _term_it_show_more(u3_utty* uty_u)
{ {
if ( u2_yes == u2_Host.ops_u.dem ) { if ( u3_yes == u3_Host.ops_u.dem ) {
_term_it_write_str(uty_u, "\n"); _term_it_write_str(uty_u, "\n");
} else { } else {
_term_it_write_str(uty_u, "\r\n"); _term_it_write_str(uty_u, "\r\n");
@ -610,73 +610,73 @@ _term_it_show_more(u2_utty* uty_u)
/* _term_it_path(): path for console file. /* _term_it_path(): path for console file.
*/ */
static c3_c* static c3_c*
_term_it_path(u2_bean fyl, u2_noun pax) _term_it_path(u3_bean fyl, u3_noun pax)
{ {
c3_w len_w; c3_w len_w;
c3_c *pas_c; c3_c *pas_c;
// measure // measure
// //
len_w = strlen(u2_Host.cpu_c); len_w = strlen(u3_Host.cpu_c);
{ {
u2_noun wiz = pax; u3_noun wiz = pax;
while ( u2_nul != wiz ) { while ( u3_nul != wiz ) {
len_w += (1 + u2_cr_met(3, u2h(wiz))); len_w += (1 + u3_cr_met(3, u3h(wiz)));
wiz = u2t(wiz); wiz = u3t(wiz);
} }
} }
// cut // cut
// //
pas_c = c3_malloc(len_w + 1); pas_c = c3_malloc(len_w + 1);
strncpy(pas_c, u2_Host.cpu_c, len_w); strncpy(pas_c, u3_Host.cpu_c, len_w);
pas_c[len_w] = '\0'; pas_c[len_w] = '\0';
{ {
u2_noun wiz = pax; u3_noun wiz = pax;
c3_c* waq_c = (pas_c + strlen(pas_c)); c3_c* waq_c = (pas_c + strlen(pas_c));
while ( u2_nul != wiz ) { while ( u3_nul != wiz ) {
c3_w tis_w = u2_cr_met(3, u2h(wiz)); c3_w tis_w = u3_cr_met(3, u3h(wiz));
if ( (u2_yes == fyl) && (u2_nul == u2t(wiz)) ) { if ( (u3_yes == fyl) && (u3_nul == u3t(wiz)) ) {
*waq_c++ = '.'; *waq_c++ = '.';
} else *waq_c++ = '/'; } else *waq_c++ = '/';
u2_cr_bytes(0, tis_w, (c3_y*)waq_c, u2h(wiz)); u3_cr_bytes(0, tis_w, (c3_y*)waq_c, u3h(wiz));
waq_c += tis_w; waq_c += tis_w;
wiz = u2t(wiz); wiz = u3t(wiz);
} }
*waq_c = 0; *waq_c = 0;
} }
u2z(pax); u3z(pax);
return pas_c; return pas_c;
} }
/* _term_it_save(): save file by path. /* _term_it_save(): save file by path.
*/ */
static void static void
_term_it_save(u2_noun pax, u2_noun pad) _term_it_save(u3_noun pax, u3_noun pad)
{ {
c3_c* pax_c; c3_c* pax_c;
pax = u2nt(c3_s4('.','u','r','b'), c3_s3('p','u','t'), pax); pax = u3nt(c3_s4('.','u','r','b'), c3_s3('p','u','t'), pax);
pax_c = _term_it_path(u2_yes, pax); pax_c = _term_it_path(u3_yes, pax);
u2_walk_save(pax_c, 0, pad); u3_walk_save(pax_c, 0, pad);
free(pax_c); free(pax_c);
} }
/* _term_io_belt(): send belt. /* _term_io_belt(): send belt.
*/ */
static void static void
_term_io_belt(u2_utty* uty_u, u2_noun blb) _term_io_belt(u3_utty* uty_u, u3_noun blb)
{ {
u2_noun tid = u2_dc("scot", c3__ud, uty_u->tid_l); u3_noun tid = u3_dc("scot", c3__ud, uty_u->tid_l);
u2_noun pax = u2nq(u2_blip, c3__term, tid, u2_nul); u3_noun pax = u3nq(u3_blip, c3__term, tid, u3_nul);
u2_reck_plan(u2A, pax, u2nc(c3__belt, blb)); u3_cv_plan(pax, u3nc(c3__belt, blb));
} }
/* _tel_event(): telnet sucker /* _tel_event(): telnet sucker
@ -688,21 +688,21 @@ _term_io_belt(u2_utty* uty_u, u2_noun blb)
static void static void
_tel_event(_te_nvt* nvt, _te_evt* evt) _tel_event(_te_nvt* nvt, _te_evt* evt)
{ {
u2_utel* tel_u; u3_utel* tel_u;
c3_assert(0 < telnet_get_userdata(nvt, (void**)&tel_u)); c3_assert(0 < telnet_get_userdata(nvt, (void**)&tel_u));
switch (evt->type) switch (evt->type)
{ {
case TELNET_EV_DATA: case TELNET_EV_DATA:
{ {
_te_dvt* dv = (_te_dvt*)evt; _te_dvt* dv = (_te_dvt*)evt;
_term_suck((u2_utty*)tel_u, dv->data, dv->length); _term_suck((u3_utty*)tel_u, dv->data, dv->length);
break; break;
} }
case TELNET_EV_SEND: case TELNET_EV_SEND:
{ {
_te_svt* sv = (_te_svt*)evt; _te_svt* sv = (_te_svt*)evt;
_term_it_write_bytes((u2_utty*)tel_u, sv->length, sv->data); _term_it_write_bytes((u3_utty*)tel_u, sv->length, sv->data);
break; break;
} }
default: default:
@ -726,10 +726,10 @@ _tel_opt(_te_nvt* nvt, telnet_byte opt, _to_evt* evt)
case TELNET_EV_TELOPT_DATA: case TELNET_EV_TELOPT_DATA:
{ {
_to_dvt* dv = (_to_dvt*)evt; _to_dvt* dv = (_to_dvt*)evt;
u2_utel* tel_u; u3_utel* tel_u;
u2_noun pax; u3_noun pax;
u2_noun blu; u3_noun blu;
u2_noun tid; u3_noun tid;
c3_s col_s; c3_s col_s;
c3_s row_s; c3_s row_s;
@ -745,10 +745,10 @@ _tel_opt(_te_nvt* nvt, telnet_byte opt, _to_evt* evt)
tel_u->uty_t.tat_u.siz.col_l = col_s; tel_u->uty_t.tat_u.siz.col_l = col_s;
tel_u->uty_t.tat_u.siz.row_l = row_s; tel_u->uty_t.tat_u.siz.row_l = row_s;
tid = u2_dc("scot", c3__ud, tel_u->uty_t.tid_l); tid = u3_dc("scot", c3__ud, tel_u->uty_t.tid_l);
pax = u2nq(u2_blip, c3__term, tid, u2_nul); pax = u3nq(u3_blip, c3__term, tid, u3_nul);
blu = u2nc(col_s, row_s); blu = u3nc(col_s, row_s);
u2_reck_plan(u2A, pax, u2nc(c3__blew, blu)); u3_cv_plan(pax, u3nc(c3__blew, blu));
break; break;
} }
} }
@ -756,34 +756,34 @@ _tel_opt(_te_nvt* nvt, telnet_byte opt, _to_evt* evt)
/* _term_io_suck_char(): process a single character. /* _term_io_suck_char(): process a single character.
*/ */
static void static void
_term_io_suck_char(u2_utty* uty_u, c3_y cay_y) _term_io_suck_char(u3_utty* uty_u, c3_y cay_y)
{ {
u2_utat* tat_u = &uty_u->tat_u; u3_utat* tat_u = &uty_u->tat_u;
if ( u2_yes == tat_u->esc.ape ) { if ( u3_yes == tat_u->esc.ape ) {
if ( u2_yes == tat_u->esc.bra ) { if ( u3_yes == tat_u->esc.bra ) {
switch ( cay_y ) { switch ( cay_y ) {
default: { default: {
_term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y); _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
break; break;
} }
case 'A': _term_io_belt(uty_u, u2nc(c3__aro, 'u')); break; case 'A': _term_io_belt(uty_u, u3nc(c3__aro, 'u')); break;
case 'B': _term_io_belt(uty_u, u2nc(c3__aro, 'd')); break; case 'B': _term_io_belt(uty_u, u3nc(c3__aro, 'd')); break;
case 'C': _term_io_belt(uty_u, u2nc(c3__aro, 'r')); break; case 'C': _term_io_belt(uty_u, u3nc(c3__aro, 'r')); break;
case 'D': _term_io_belt(uty_u, u2nc(c3__aro, 'l')); break; case 'D': _term_io_belt(uty_u, u3nc(c3__aro, 'l')); break;
} }
tat_u->esc.ape = tat_u->esc.bra = u2_no; tat_u->esc.ape = tat_u->esc.bra = u3_no;
} }
else { else {
if ( (cay_y >= 'a') && (cay_y <= 'z') ) { if ( (cay_y >= 'a') && (cay_y <= 'z') ) {
tat_u->esc.ape = u2_no; tat_u->esc.ape = u3_no;
_term_io_belt(uty_u, u2nc(c3__met, cay_y)); _term_io_belt(uty_u, u3nc(c3__met, cay_y));
} }
else if ( ('[' == cay_y) || ('O' == cay_y) ) { else if ( ('[' == cay_y) || ('O' == cay_y) ) {
tat_u->esc.bra = u2_yes; tat_u->esc.bra = u3_yes;
} }
else { else {
tat_u->esc.ape = u2_no; tat_u->esc.ape = u3_no;
_term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y); _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
} }
@ -793,36 +793,36 @@ _term_io_suck_char(u2_utty* uty_u, c3_y cay_y)
tat_u->fut.syb_y[tat_u->fut.len_w++] = cay_y; tat_u->fut.syb_y[tat_u->fut.len_w++] = cay_y;
if ( tat_u->fut.len_w == tat_u->fut.wid_w ) { if ( tat_u->fut.len_w == tat_u->fut.wid_w ) {
u2_noun huv = u2_ci_bytes(tat_u->fut.wid_w, tat_u->fut.syb_y); u3_noun huv = u3_ci_bytes(tat_u->fut.wid_w, tat_u->fut.syb_y);
u2_noun wug; u3_noun wug;
// uL(fprintf(uH, "muck-utf8 len %d\n", tat_u->fut.len_w)); // uL(fprintf(uH, "muck-utf8 len %d\n", tat_u->fut.len_w));
// uL(fprintf(uH, "muck-utf8 %x\n", huv)); // uL(fprintf(uH, "muck-utf8 %x\n", huv));
wug = u2_do("turf", huv); wug = u3_do("turf", huv);
// uL(fprintf(uH, "muck-utf32 %x\n", tat_u->fut.len_w)); // uL(fprintf(uH, "muck-utf32 %x\n", tat_u->fut.len_w));
tat_u->fut.len_w = tat_u->fut.wid_w = 0; tat_u->fut.len_w = tat_u->fut.wid_w = 0;
_term_io_belt(uty_u, u2nt(c3__txt, wug, u2_nul)); _term_io_belt(uty_u, u3nt(c3__txt, wug, u3_nul));
} }
} }
else { else {
if ( (cay_y >= 32) && (cay_y < 127) ) { if ( (cay_y >= 32) && (cay_y < 127) ) {
_term_io_belt(uty_u, u2nt(c3__txt, cay_y, u2_nul)); _term_io_belt(uty_u, u3nt(c3__txt, cay_y, u3_nul));
} }
else if ( 0 == cay_y ) { else if ( 0 == cay_y ) {
_term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y); _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
} }
else if ( 8 == cay_y || 127 == cay_y ) { else if ( 8 == cay_y || 127 == cay_y ) {
_term_io_belt(uty_u, u2nc(c3__bac, u2_nul)); _term_io_belt(uty_u, u3nc(c3__bac, u3_nul));
} }
else if ( 13 == cay_y ) { else if ( 13 == cay_y ) {
_term_io_belt(uty_u, u2nc(c3__ret, u2_nul)); _term_io_belt(uty_u, u3nc(c3__ret, u3_nul));
} }
else if ( cay_y <= 26 ) { else if ( cay_y <= 26 ) {
_term_io_belt(uty_u, u2nc(c3__ctl, ('a' + (cay_y - 1)))); _term_io_belt(uty_u, u3nc(c3__ctl, ('a' + (cay_y - 1))));
} }
else if ( 27 == cay_y ) { else if ( 27 == cay_y ) {
tat_u->esc.ape = u2_yes; tat_u->esc.ape = u3_yes;
} }
else if ( cay_y >= 128 ) { else if ( cay_y >= 128 ) {
tat_u->fut.len_w = 1; tat_u->fut.len_w = 1;
@ -844,9 +844,9 @@ _term_read_tn_cb(uv_stream_t* tcp_u,
ssize_t siz_i, ssize_t siz_i,
const uv_buf_t * buf_u) const uv_buf_t * buf_u)
{ {
u2_utel* pty_u = (u2_utel*)(void*) tcp_u; u3_utel* pty_u = (u3_utel*)(void*) tcp_u;
u2_lo_open(); u3_lo_open();
{ {
if ( siz_i == UV_EOF ) { if ( siz_i == UV_EOF ) {
// nothing // nothing
@ -862,7 +862,7 @@ _term_read_tn_cb(uv_stream_t* tcp_u,
err: err:
free(buf_u->base); free(buf_u->base);
} }
u2_lo_shut(u2_yes); u3_lo_shut(u3_yes);
} }
/* _term_suck(): process a chunk of input /* _term_suck(): process a chunk of input
@ -881,9 +881,9 @@ _term_read_tn_cb(uv_stream_t* tcp_u,
*/ */
static inline void static inline void
_term_suck(u2_utty* uty_u, const c3_y* buf, ssize_t siz_i) _term_suck(u3_utty* uty_u, const c3_y* buf, ssize_t siz_i)
{ {
u2_lo_open(); u3_lo_open();
{ {
if ( siz_i == UV_EOF ) { if ( siz_i == UV_EOF ) {
// nothing // nothing
@ -898,7 +898,7 @@ _term_suck(u2_utty* uty_u, const c3_y* buf, ssize_t siz_i)
} }
} }
} }
u2_lo_shut(u2_yes); u3_lo_shut(u3_yes);
} }
/* _term_read_cb(): server read callback. /* _term_read_cb(): server read callback.
@ -908,35 +908,35 @@ _term_read_cb(uv_stream_t* tcp_u,
ssize_t siz_i, ssize_t siz_i,
const uv_buf_t * buf_u) const uv_buf_t * buf_u)
{ {
u2_utty* uty_u = (u2_utty*)(void*)tcp_u; u3_utty* uty_u = (u3_utty*)(void*)tcp_u;
_term_suck(uty_u, (const c3_y*)buf_u->base, siz_i); _term_suck(uty_u, (const c3_y*)buf_u->base, siz_i);
free(buf_u->base); free(buf_u->base);
} }
/* _term_main(): return main or console terminal. /* _term_main(): return main or console terminal.
*/ */
static u2_utty* static u3_utty*
_term_main() _term_main()
{ {
u2_utty* uty_u; u3_utty* uty_u;
for ( uty_u = u2_Host.uty_u; uty_u; uty_u = uty_u->nex_u ) { for ( uty_u = u3_Host.uty_u; uty_u; uty_u = uty_u->nex_u ) {
if ( (uty_u->fid_i != -1) && (uty_u->fid_i <= 2) ) { if ( (uty_u->fid_i != -1) && (uty_u->fid_i <= 2) ) {
return uty_u; return uty_u;
} }
} }
return u2_Host.uty_u; return u3_Host.uty_u;
} }
/* _term_ef_get(): terminal by id. /* _term_ef_get(): terminal by id.
*/ */
static u2_utty* static u3_utty*
_term_ef_get(c3_l tid_l) _term_ef_get(c3_l tid_l)
{ {
if ( 0 != tid_l ) { if ( 0 != tid_l ) {
u2_utty* uty_u; u3_utty* uty_u;
for ( uty_u = u2_Host.uty_u; uty_u; uty_u = uty_u->nex_u ) { for ( uty_u = u3_Host.uty_u; uty_u; uty_u = uty_u->nex_u ) {
if ( tid_l == uty_u->tid_l ) { if ( tid_l == uty_u->tid_l ) {
return uty_u; return uty_u;
} }
@ -945,12 +945,12 @@ _term_ef_get(c3_l tid_l)
return _term_main(); return _term_main();
} }
/* u2_term_get_blew(): return window size [columns rows]. /* u3_term_get_blew(): return window size [columns rows].
*/ */
u2_noun u3_noun
u2_term_get_blew(c3_l tid_l) u3_term_get_blew(c3_l tid_l)
{ {
u2_utty* uty_u = _term_ef_get(tid_l); u3_utty* uty_u = _term_ef_get(tid_l);
c3_l col_l, row_l; c3_l col_l, row_l;
struct winsize siz_u; struct winsize siz_u;
@ -967,101 +967,101 @@ u2_term_get_blew(c3_l tid_l)
uty_u->tat_u.siz.row_l = row_l; uty_u->tat_u.siz.row_l = row_l;
} }
return u2nc(col_l, row_l); return u3nc(col_l, row_l);
} }
/* u2_term_ef_winc(): window change. Just console right now. /* u3_term_ef_winc(): window change. Just console right now.
*/ */
void void
u2_term_ef_winc(void) u3_term_ef_winc(void)
{ {
u2_noun pax = u2nq(u2_blip, c3__term, '1', u2_nul); u3_noun pax = u3nq(u3_blip, c3__term, '1', u3_nul);
u2_reck_plan(u2A, pax, u2nc(c3__blew, u2_term_get_blew(1))); u3_cv_plan(pax, u3nc(c3__blew, u3_term_get_blew(1)));
} }
/* u2_term_ef_ctlc(): send ^C on console. /* u3_term_ef_ctlc(): send ^C on console.
*/ */
void void
u2_term_ef_ctlc(void) u3_term_ef_ctlc(void)
{ {
u2_noun pax = u2nq(u2_blip, c3__term, '1', u2_nul); u3_noun pax = u3nq(u3_blip, c3__term, '1', u3_nul);
u2_reck_plan(u2A, pax, u2nt(c3__belt, c3__ctl, 'c')); u3_cv_plan(pax, u3nt(c3__belt, c3__ctl, 'c'));
} }
/* u2_term_ef_boil(): initial effects for loaded servers. /* u3_term_ef_boil(): initial effects for loaded servers.
*/ */
void void
u2_term_ef_boil(void) u3_term_ef_boil(void)
{ {
{ {
u2_noun pax = u2nq(u2_blip, c3__term, '1', u2_nul); u3_noun pax = u3nq(u3_blip, c3__term, '1', u3_nul);
// u2_reck_plan(u2A, u2k(pax), u2nc(c3__init, u2k(u2h(u2A->own)))); // u3_cv_plan(u3k(pax), u3nc(c3__init, u3k(u3h(u3A->own))));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__harm, u2_nul)); u3_cv_plan(u3k(pax), u3nc(c3__harm, u3_nul));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__blew, u2_term_get_blew(1))); u3_cv_plan(u3k(pax), u3nc(c3__blew, u3_term_get_blew(1)));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul)); u3_cv_plan(u3k(pax), u3nc(c3__hail, u3_nul));
u2z(pax); u3z(pax);
} }
} }
/* u2_term_ef_bake(): initial effects for new terminal. /* u3_term_ef_bake(): initial effects for new terminal.
*/ */
void void
u2_term_ef_bake(u2_noun fav) u3_term_ef_bake(u3_noun fav)
{ {
u2_noun pax = u2nq(u2_blip, c3__term, '1', u2_nul); u3_noun pax = u3nq(u3_blip, c3__term, '1', u3_nul);
u2_reck_plan(u2A, u2k(pax), u2nc(c3__boot, fav)); u3_cv_plan(u3k(pax), u3nc(c3__boot, fav));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__blew, u2_term_get_blew(1))); u3_cv_plan(u3k(pax), u3nc(c3__blew, u3_term_get_blew(1)));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul)); u3_cv_plan(u3k(pax), u3nc(c3__hail, u3_nul));
u2z(pax); u3z(pax);
} }
/* _term_ef_blit(): send blit to terminal. /* _term_ef_blit(): send blit to terminal.
*/ */
static void static void
_term_ef_blit(u2_utty* uty_u, _term_ef_blit(u3_utty* uty_u,
u2_noun blt) u3_noun blt)
{ {
switch ( u2h(blt) ) { switch ( u3h(blt) ) {
default: break; default: break;
case c3__bel: { case c3__bel: {
if ( u2_no == u2_Host.ops_u.dem ) { if ( u3_no == u3_Host.ops_u.dem ) {
_term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y); _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
} }
} break; } break;
case c3__clr: { case c3__clr: {
if ( u2_no == u2_Host.ops_u.dem ) { if ( u3_no == u3_Host.ops_u.dem ) {
_term_it_show_blank(uty_u); _term_it_show_blank(uty_u);
_term_it_refresh_line(uty_u); _term_it_refresh_line(uty_u);
} }
} break; } break;
case c3__hop: { case c3__hop: {
if ( u2_no == u2_Host.ops_u.dem ) { if ( u3_no == u3_Host.ops_u.dem ) {
_term_it_show_cursor(uty_u, u2t(blt)); _term_it_show_cursor(uty_u, u3t(blt));
} }
} break; } break;
case c3__lin: { case c3__lin: {
u2_noun lin = u2t(blt); u3_noun lin = u3t(blt);
c3_w len_w = u2_ckb_lent(u2k(lin)); c3_w len_w = u3_ckb_lent(u3k(lin));
c3_w* lin_w = c3_malloc(4 * len_w); c3_w* lin_w = c3_malloc(4 * len_w);
{ {
c3_w i_w; c3_w i_w;
for ( i_w = 0; u2_nul != lin; i_w++, lin = u2t(lin) ) { for ( i_w = 0; u3_nul != lin; i_w++, lin = u3t(lin) ) {
lin_w[i_w] = u2_cr_word(0, u2h(lin)); lin_w[i_w] = u3_cr_word(0, u3h(lin));
} }
} }
if ( u2_no == u2_Host.ops_u.dem ) { if ( u3_no == u3_Host.ops_u.dem ) {
_term_it_show_clear(uty_u); _term_it_show_clear(uty_u);
_term_it_show_line(uty_u, lin_w, len_w); _term_it_show_line(uty_u, lin_w, len_w);
} else { } else {
@ -1074,57 +1074,57 @@ _term_ef_blit(u2_utty* uty_u,
} break; } break;
case c3__sav: { case c3__sav: {
_term_it_save(u2k(u2h(u2t(blt))), u2k(u2t(u2t(blt)))); _term_it_save(u3k(u3h(u3t(blt))), u3k(u3t(u3t(blt))));
} break; } break;
case c3__sag: { case c3__sag: {
u2_noun pib = u2k(u2t(u2t(blt))); u3_noun pib = u3k(u3t(u3t(blt)));
u2_noun jam; u3_noun jam;
fprintf(stderr, "jamming...\r\n"); fprintf(stderr, "jamming...\r\n");
jam = u2_cke_jam(pib); jam = u3_cke_jam(pib);
fprintf(stderr, "jammed.\r\n"); fprintf(stderr, "jammed.\r\n");
_term_it_save(u2k(u2h(u2t(blt))), jam); _term_it_save(u3k(u3h(u3t(blt))), jam);
} break; } break;
} }
u2z(blt); u3z(blt);
return; return;
} }
/* u2_term_ef_blit(): send %blit list to specific terminal. /* u3_term_ef_blit(): send %blit list to specific terminal.
*/ */
void void
u2_term_ef_blit(c3_l tid_l, u3_term_ef_blit(c3_l tid_l,
u2_noun bls) u3_noun bls)
{ {
u2_utty* uty_u = _term_ef_get(tid_l); u3_utty* uty_u = _term_ef_get(tid_l);
if ( 0 == uty_u ) { if ( 0 == uty_u ) {
// uL(fprintf(uH, "no terminal %d\n", tid_l)); // uL(fprintf(uH, "no terminal %d\n", tid_l));
// uL(fprintf(uH, "uty_u %p\n", u2_Host.uty_u)); // uL(fprintf(uH, "uty_u %p\n", u3_Host.uty_u));
u2z(bls); return; u3z(bls); return;
} }
{ {
u2_noun bis = bls; u3_noun bis = bls;
while ( u2_yes == u2du(bis) ) { while ( u3_yes == u3du(bis) ) {
_term_ef_blit(uty_u, u2k(u2h(bis))); _term_ef_blit(uty_u, u3k(u3h(bis)));
bis = u2t(bis); bis = u3t(bis);
} }
u2z(bls); u3z(bls);
} }
} }
/* u2_term_io_hija(): hijack console for fprintf, returning FILE*. /* u3_term_io_hija(): hijack console for fprintf, returning FILE*.
*/ */
FILE* FILE*
u2_term_io_hija(void) u3_term_io_hija(void)
{ {
u2_utty* uty_u = _term_main(); u3_utty* uty_u = _term_main();
if ( uty_u ) { if ( uty_u ) {
if ( uty_u->fid_i > 2 ) { if ( uty_u->fid_i > 2 ) {
@ -1134,7 +1134,7 @@ u2_term_io_hija(void)
c3_assert(0); c3_assert(0);
} }
else { else {
if ( u2_no == u2_Host.ops_u.dem ) { if ( u3_no == u3_Host.ops_u.dem ) {
if ( 0 != tcsetattr(1, TCSADRAIN, &uty_u->bak_u) ) { if ( 0 != tcsetattr(1, TCSADRAIN, &uty_u->bak_u) ) {
c3_assert(!"hija-tcsetattr"); c3_assert(!"hija-tcsetattr");
} }
@ -1157,12 +1157,12 @@ u2_term_io_hija(void)
else return stdout; else return stdout;
} }
/* u2_term_io_loja(): release console from fprintf. /* u3_term_io_loja(): release console from fprintf.
*/ */
void void
u2_term_io_loja(int x) u3_term_io_loja(int x)
{ {
u2_utty* uty_u = _term_main(); u3_utty* uty_u = _term_main();
if ( uty_u ) { if ( uty_u ) {
if ( uty_u->fid_i > 2 ) { if ( uty_u->fid_i > 2 ) {
@ -1172,7 +1172,7 @@ u2_term_io_loja(int x)
c3_assert(0); c3_assert(0);
} }
else { else {
if ( u2_yes == u2_Host.ops_u.dem ) { if ( u3_yes == u3_Host.ops_u.dem ) {
fflush(stdout); fflush(stdout);
} }
else { else {

View File

@ -18,25 +18,24 @@
#include <term.h> #include <term.h>
#include "all.h" #include "all.h"
#include "f/coal.h"
#include "v/vere.h" #include "v/vere.h"
/* u2_time_sec_in(): urbit seconds from unix time. /* u3_time_sec_in(): urbit seconds from unix time.
** **
** Adjust for future leap secs! ** Adjust for future leap secs!
*/ */
c3_d c3_d
u2_time_sec_in(c3_w unx_w) u3_time_sec_in(c3_w unx_w)
{ {
return 0x8000000cce9e0d80ULL + (c3_d)unx_w; return 0x8000000cce9e0d80ULL + (c3_d)unx_w;
} }
/* u2_time_sec_out(): unix time from urbit seconds. /* u3_time_sec_out(): unix time from urbit seconds.
** **
** Adjust for future leap secs! ** Adjust for future leap secs!
*/ */
c3_w c3_w
u2_time_sec_out(c3_d urs_d) u3_time_sec_out(c3_d urs_d)
{ {
c3_d adj_d = (urs_d - 0x8000000cce9e0d80ULL); c3_d adj_d = (urs_d - 0x8000000cce9e0d80ULL);
@ -47,137 +46,137 @@ u2_time_sec_out(c3_d urs_d)
return (c3_w)adj_d; return (c3_w)adj_d;
} }
/* u2_time_fsc_in(): urbit fracto-seconds from unix microseconds. /* u3_time_fsc_in(): urbit fracto-seconds from unix microseconds.
*/ */
c3_d c3_d
u2_time_fsc_in(c3_w usc_w) u3_time_fsc_in(c3_w usc_w)
{ {
c3_d usc_d = usc_w; c3_d usc_d = usc_w;
return ((usc_d * 65536ULL) / 1000000ULL) << 48ULL; return ((usc_d * 65536ULL) / 1000000ULL) << 48ULL;
} }
/* u2_time_fsc_out: unix microseconds from urbit fracto-seconds. /* u3_time_fsc_out: unix microseconds from urbit fracto-seconds.
*/ */
c3_w c3_w
u2_time_fsc_out(c3_d ufc_d) u3_time_fsc_out(c3_d ufc_d)
{ {
return (c3_w) (((ufc_d >> 48ULL) * 1000000ULL) / 65536ULL); return (c3_w) (((ufc_d >> 48ULL) * 1000000ULL) / 65536ULL);
} }
/* u2_time_msc_out: unix microseconds from urbit fracto-seconds. /* u3_time_msc_out: unix microseconds from urbit fracto-seconds.
*/ */
c3_w c3_w
u2_time_msc_out(c3_d ufc_d) u3_time_msc_out(c3_d ufc_d)
{ {
return (c3_w) (((ufc_d >> 48ULL) * 1000ULL) / 65536ULL); return (c3_w) (((ufc_d >> 48ULL) * 1000ULL) / 65536ULL);
} }
/* u2_time_in_tv(): urbit time from struct timeval. /* u3_time_in_tv(): urbit time from struct timeval.
*/ */
u2_atom u3_atom
u2_time_in_tv(struct timeval* tim_tv) u3_time_in_tv(struct timeval* tim_tv)
{ {
c3_w unx_w = tim_tv->tv_sec; c3_w unx_w = tim_tv->tv_sec;
c3_w usc_w = tim_tv->tv_usec; c3_w usc_w = tim_tv->tv_usec;
c3_d cub_d[2]; c3_d cub_d[2];
cub_d[0] = u2_time_fsc_in(usc_w); cub_d[0] = u3_time_fsc_in(usc_w);
cub_d[1] = u2_time_sec_in(unx_w); cub_d[1] = u3_time_sec_in(unx_w);
return u2_ci_chubs(2, cub_d); return u3_ci_chubs(2, cub_d);
} }
/* u2_time_out_tv(): struct timeval from urbit time. /* u3_time_out_tv(): struct timeval from urbit time.
*/ */
void void
u2_time_out_tv(struct timeval* tim_tv, u2_noun now) u3_time_out_tv(struct timeval* tim_tv, u3_noun now)
{ {
c3_d ufc_d = u2_cr_chub(0, now); c3_d ufc_d = u3_cr_chub(0, now);
c3_d urs_d = u2_cr_chub(1, now); c3_d urs_d = u3_cr_chub(1, now);
tim_tv->tv_sec = u2_time_sec_out(urs_d); tim_tv->tv_sec = u3_time_sec_out(urs_d);
tim_tv->tv_usec = u2_time_fsc_out(ufc_d); tim_tv->tv_usec = u3_time_fsc_out(ufc_d);
u2z(now); u3z(now);
} }
/* u2_time_in_ts(): urbit time from struct timespec. /* u3_time_in_ts(): urbit time from struct timespec.
*/ */
u2_atom u3_atom
u2_time_in_ts(struct timespec* tim_ts) u3_time_in_ts(struct timespec* tim_ts)
{ {
struct timeval tim_tv; struct timeval tim_tv;
tim_tv.tv_sec = tim_ts->tv_sec; tim_tv.tv_sec = tim_ts->tv_sec;
tim_tv.tv_usec = (tim_ts->tv_nsec / 1000); tim_tv.tv_usec = (tim_ts->tv_nsec / 1000);
return u2_time_in_tv(&tim_tv); return u3_time_in_tv(&tim_tv);
} }
#if defined(U2_OS_linux) #if defined(U2_OS_linux)
/* u2_time_t_in_ts(): urbit time from time_t. /* u3_time_t_in_ts(): urbit time from time_t.
*/ */
u2_atom u3_atom
u2_time_t_in_ts(time_t tim) u3_time_t_in_ts(time_t tim)
{ {
struct timeval tim_tv; struct timeval tim_tv;
tim_tv.tv_sec = tim; tim_tv.tv_sec = tim;
tim_tv.tv_usec = 0; tim_tv.tv_usec = 0;
return u2_time_in_tv(&tim_tv); return u3_time_in_tv(&tim_tv);
} }
#endif // defined(U2_OS_linux) #endif // defined(U2_OS_linux)
/* u2_time_out_ts(): struct timespec from urbit time. /* u3_time_out_ts(): struct timespec from urbit time.
*/ */
void void
u2_time_out_ts(struct timespec* tim_ts, u2_noun now) u3_time_out_ts(struct timespec* tim_ts, u3_noun now)
{ {
struct timeval tim_tv; struct timeval tim_tv;
u2_time_out_tv(&tim_tv, now); u3_time_out_tv(&tim_tv, now);
tim_ts->tv_sec = tim_tv.tv_sec; tim_ts->tv_sec = tim_tv.tv_sec;
tim_ts->tv_nsec = (tim_tv.tv_usec * 1000); tim_ts->tv_nsec = (tim_tv.tv_usec * 1000);
} }
/* u2_time_gap_ms(): (wen - now) in ms. /* u3_time_gap_ms(): (wen - now) in ms.
*/ */
c3_d c3_d
u2_time_gap_ms(u2_noun now, u2_noun wen) u3_time_gap_ms(u3_noun now, u3_noun wen)
{ {
if ( u2_no == u2_cka_gth(u2k(wen), u2k(now)) ) { if ( u3_no == u3_cka_gth(u3k(wen), u3k(now)) ) {
u2z(wen); u2z(now); u3z(wen); u3z(now);
return 0ULL; return 0ULL;
} }
else { else {
u2_noun dif = u2_cka_sub(wen, now); u3_noun dif = u3_cka_sub(wen, now);
c3_d fsc_d = u2_cr_chub(0, dif); c3_d fsc_d = u3_cr_chub(0, dif);
c3_d sec_d = u2_cr_chub(1, dif); c3_d sec_d = u3_cr_chub(1, dif);
u2z(dif); u3z(dif);
return (sec_d * 1000ULL) + u2_time_msc_out(fsc_d); return (sec_d * 1000ULL) + u3_time_msc_out(fsc_d);
} }
} }
/* u2_time_gap_double(): (wen - now) in libev resolution. /* u3_time_gap_double(): (wen - now) in libev resolution.
*/ */
double double
u2_time_gap_double(u2_noun now, u2_noun wen) u3_time_gap_double(u3_noun now, u3_noun wen)
{ {
mpz_t now_mp, wen_mp, dif_mp; mpz_t now_mp, wen_mp, dif_mp;
double sec_g = (((double)(1ULL << 32ULL)) * ((double)(1ULL << 32ULL))); double sec_g = (((double)(1ULL << 32ULL)) * ((double)(1ULL << 32ULL)));
double gap_g, dif_g; double gap_g, dif_g;
u2_cr_mp(now_mp, now); u3_cr_mp(now_mp, now);
u2_cr_mp(wen_mp, wen); u3_cr_mp(wen_mp, wen);
mpz_init(dif_mp); mpz_init(dif_mp);
mpz_sub(dif_mp, wen_mp, now_mp); mpz_sub(dif_mp, wen_mp, now_mp);
u2z(now); u3z(now);
u2z(wen); u3z(wen);
dif_g = mpz_get_d(dif_mp) / sec_g; dif_g = mpz_get_d(dif_mp) / sec_g;
gap_g = (dif_g > 0.0) ? dif_g : 0.0; gap_g = (dif_g > 0.0) ? dif_g : 0.0;

841
v/unix.c

File diff suppressed because it is too large Load Diff

133
v/walk.c
View File

@ -19,7 +19,6 @@
#include <errno.h> #include <errno.h>
#include "all.h" #include "all.h"
#include "f/coal.h"
#include "v/vere.h" #include "v/vere.h"
/* |% /* |%
@ -31,23 +30,23 @@
*/ */
#if 0 #if 0
static u2_noun static u3_noun
_walk_ok(u2_reck* rec_u, u2_noun nod) _walk_ok(u3_noun nod)
{ {
u2_noun don = u2_cn_mung(u2k(rec_u->toy.arch), u2k(nod)); u3_noun don = u3_cn_mung(u3k(u2A->toy.arch), u3k(nod));
if ( u2_no == u2_sing(nod, don) ) { if ( u3_no == u3_sing(nod, don) ) {
c3_assert(0); c3_assert(0);
} }
u2z(don); u3z(don);
return nod; return nod;
} }
#endif #endif
/* u2_walk_safe(): load file or 0. /* u3_walk_safe(): load file or 0.
*/ */
u2_noun u3_noun
u2_walk_safe(c3_c* pas_c) u3_walk_safe(c3_c* pas_c)
{ {
struct stat buf_b; struct stat buf_b;
c3_i fid_i = open(pas_c, O_RDONLY, 0644); c3_i fid_i = open(pas_c, O_RDONLY, 0644);
@ -69,17 +68,17 @@ u2_walk_safe(c3_c* pas_c)
return 0; return 0;
} }
else { else {
u2_noun pad = u2_ci_bytes(fln_w, (c3_y *)pad_y); u3_noun pad = u3_ci_bytes(fln_w, (c3_y *)pad_y);
free(pad_y); free(pad_y);
return pad; return pad;
} }
} }
/* u2_walk_load(): load file or bail. /* u3_walk_load(): load file or bail.
*/ */
u2_noun u3_noun
u2_walk_load(c3_c* pas_c) u3_walk_load(c3_c* pas_c)
{ {
struct stat buf_b; struct stat buf_b;
c3_i fid_i = open(pas_c, O_RDONLY, 0644); c3_i fid_i = open(pas_c, O_RDONLY, 0644);
@ -88,7 +87,7 @@ u2_walk_load(c3_c* pas_c)
if ( (fid_i < 0) || (fstat(fid_i, &buf_b) < 0) ) { if ( (fid_i < 0) || (fstat(fid_i, &buf_b) < 0) ) {
uL(fprintf(uH, "%s: %s\n", pas_c, strerror(errno))); uL(fprintf(uH, "%s: %s\n", pas_c, strerror(errno)));
return u2_cm_bail(c3__fail); return u3_cm_bail(c3__fail);
} }
fln_w = buf_b.st_size; fln_w = buf_b.st_size;
pad_y = c3_malloc(buf_b.st_size); pad_y = c3_malloc(buf_b.st_size);
@ -98,20 +97,20 @@ u2_walk_load(c3_c* pas_c)
if ( fln_w != red_w ) { if ( fln_w != red_w ) {
free(pad_y); free(pad_y);
return u2_cm_bail(c3__fail); return u3_cm_bail(c3__fail);
} }
else { else {
u2_noun pad = u2_ci_bytes(fln_w, (c3_y *)pad_y); u3_noun pad = u3_ci_bytes(fln_w, (c3_y *)pad_y);
free(pad_y); free(pad_y);
return pad; return pad;
} }
} }
/* u2_walk_save(): save file or bail. /* u3_walk_save(): save file or bail.
*/ */
void void
u2_walk_save(c3_c* pas_c, u2_noun tim, u2_atom pad) u3_walk_save(c3_c* pas_c, u3_noun tim, u3_atom pad)
{ {
c3_i fid_i = open(pas_c, O_WRONLY | O_CREAT | O_TRUNC, 0666); c3_i fid_i = open(pas_c, O_WRONLY | O_CREAT | O_TRUNC, 0666);
c3_w fln_w, rit_w; c3_w fln_w, rit_w;
@ -119,13 +118,13 @@ u2_walk_save(c3_c* pas_c, u2_noun tim, u2_atom pad)
if ( fid_i < 0 ) { if ( fid_i < 0 ) {
uL(fprintf(uH, "%s: %s\n", pas_c, strerror(errno))); uL(fprintf(uH, "%s: %s\n", pas_c, strerror(errno)));
u2_cm_bail(c3__fail); u3_cm_bail(c3__fail);
} }
fln_w = u2_met(3, pad); fln_w = u3_cr_met(3, pad);
pad_y = c3_malloc(fln_w); pad_y = c3_malloc(fln_w);
u2_cr_bytes(0, fln_w, pad_y, pad); u3_cr_bytes(0, fln_w, pad_y, pad);
u2z(pad); u3z(pad);
rit_w = write(fid_i, pad_y, fln_w); rit_w = write(fid_i, pad_y, fln_w);
close(fid_i); close(fid_i);
@ -133,14 +132,14 @@ u2_walk_save(c3_c* pas_c, u2_noun tim, u2_atom pad)
if ( rit_w != fln_w ) { if ( rit_w != fln_w ) {
uL(fprintf(uH, "%s: %s\n", pas_c, strerror(errno))); uL(fprintf(uH, "%s: %s\n", pas_c, strerror(errno)));
u2_cm_bail(c3__fail); u3_cm_bail(c3__fail);
} }
if ( 0 != tim ) { if ( 0 != tim ) {
struct timeval tim_tv[2]; struct timeval tim_tv[2];
u2_time_out_tv(&tim_tv[0], u2k(tim)); u3_time_out_tv(&tim_tv[0], u3k(tim));
u2_time_out_tv(&tim_tv[1], tim); u3_time_out_tv(&tim_tv[1], tim);
utimes(pas_c, tim_tv); utimes(pas_c, tim_tv);
} }
@ -148,14 +147,14 @@ u2_walk_save(c3_c* pas_c, u2_noun tim, u2_atom pad)
/* _walk_in(): inner loop of _walk(), producing map. /* _walk_in(): inner loop of _walk(), producing map.
*/ */
static u2_noun static u3_noun
_walk_in(u2_reck* rec_u, const c3_c* dir_c, c3_w len_w) _walk_in(const c3_c* dir_c, c3_w len_w)
{ {
DIR* dir_d = opendir(dir_c); DIR* dir_d = opendir(dir_c);
u2_noun map = u2_nul; u3_noun map = u3_nul;
if ( !dir_d ) { if ( !dir_d ) {
return u2_nul; return u3_nul;
} }
else while ( 1 ) { else while ( 1 ) {
struct dirent ent_n; struct dirent ent_n;
@ -189,7 +188,7 @@ _walk_in(u2_reck* rec_u, const c3_c* dir_c, c3_w len_w)
if ( 0 != stat(pat_c, &buf_b) ) { if ( 0 != stat(pat_c, &buf_b) ) {
free(pat_c); free(pat_c);
} else { } else {
u2_noun tim = c3_stat_mtime(&buf_b); u3_noun tim = c3_stat_mtime(&buf_b);
if ( !S_ISDIR(buf_b.st_mode) ) { if ( !S_ISDIR(buf_b.st_mode) ) {
c3_c* dot_c = strrchr(fil_c, '.'); c3_c* dot_c = strrchr(fil_c, '.');
@ -198,32 +197,32 @@ _walk_in(u2_reck* rec_u, const c3_c* dir_c, c3_w len_w)
nam_c[dot_c - fil_c] = 0; nam_c[dot_c - fil_c] = 0;
{ {
u2_noun nam = u2_ci_string(nam_c); u3_noun nam = u3_ci_string(nam_c);
u2_noun ext = u2_ci_string(ext_c); u3_noun ext = u3_ci_string(ext_c);
u2_noun get = u2_ckd_by_get(u2k(map), u2k(nam)); u3_noun get = u3_ckdb_get(u3k(map), u3k(nam));
u2_noun dat = u2_walk_load(pat_c); u3_noun dat = u3_walk_load(pat_c);
u2_noun hax; u3_noun hax;
if ( !strcmp("noun", ext_c) ) { if ( !strcmp("noun", ext_c) ) {
dat = u2_cke_cue(dat); dat = u3_cke_cue(dat);
} }
hax = u2_do("sham", u2k(dat)); hax = u3_do("sham", u3k(dat));
if ( u2_none == get ) { get = u2_nul; } if ( u3_none == get ) { get = u3_nul; }
get = u2_ckd_by_put(get, ext, u2nt(u2_yes, hax, dat)); get = u3_ckdb_put(get, ext, u3nt(u3_yes, hax, dat));
map = u2_ckd_by_put(map, nam, u2nc(u2_no, get)); map = u3_ckdb_put(map, nam, u3nc(u3_no, get));
} }
free(nam_c); free(nam_c);
free(ext_c); free(ext_c);
} }
else { else {
u2_noun dir = _walk_in(rec_u, pat_c, lef_w); u3_noun dir = _walk_in(pat_c, lef_w);
if ( u2_nul != dir ) { if ( u3_nul != dir ) {
map = u2_ckd_by_put map = u3_ckdb_put
(map, u2_ci_string(fil_c), u2nc(u2_no, dir)); (map, u3_ci_string(fil_c), u3nc(u3_no, dir));
} }
else u2z(tim); else u3z(tim);
} }
free(pat_c); free(pat_c);
} }
@ -233,71 +232,71 @@ _walk_in(u2_reck* rec_u, const c3_c* dir_c, c3_w len_w)
return map; return map;
} }
/* u2_walk(): traverse `dir_c` to produce an arch, updating `old`. /* u3_walk(): traverse `dir_c` to produce an arch, updating `old`.
*/ */
u2_noun u3_noun
u2_walk(u2_reck* rec_u, const c3_c* dir_c, u2_noun old) u3_walk(const c3_c* dir_c, u3_noun old)
{ {
// XX - obviously, cheaper to update old data. // XX - obviously, cheaper to update old data.
u2z(old); u3z(old);
{ {
struct stat buf_b; struct stat buf_b;
if ( 0 != stat(dir_c, &buf_b) ) { if ( 0 != stat(dir_c, &buf_b) ) {
uL(fprintf(uH, "can't stat %s\n", dir_c)); uL(fprintf(uH, "can't stat %s\n", dir_c));
// return u2_cm_bail(c3__fail); // return u3_cm_bail(c3__fail);
c3_assert(0); c3_assert(0);
} }
else { else {
return u2nc(u2_no, return u3nc(u3_no,
_walk_in(rec_u, dir_c, strlen(dir_c))); _walk_in(dir_c, strlen(dir_c)));
} }
} }
} }
/* u2_path(): C unix path in computer for file or directory. /* u3_path(): C unix path in computer for file or directory.
*/ */
c3_c* c3_c*
u2_path(u2_bean fyl, u2_noun pax) u3_path(u3_bean fyl, u3_noun pax)
{ {
c3_w len_w; c3_w len_w;
c3_c *pas_c; c3_c *pas_c;
// measure // measure
// //
len_w = strlen(u2_Local); len_w = strlen(u3_Local);
{ {
u2_noun wiz = pax; u3_noun wiz = pax;
while ( u2_nul != wiz ) { while ( u3_nul != wiz ) {
len_w += (1 + u2_cr_met(3, u2h(wiz))); len_w += (1 + u3_cr_met(3, u3h(wiz)));
wiz = u2t(wiz); wiz = u3t(wiz);
} }
} }
// cut // cut
// //
pas_c = c3_malloc(len_w + 1); pas_c = c3_malloc(len_w + 1);
strncpy(pas_c, u2_Local, len_w); strncpy(pas_c, u3_Local, len_w);
pas_c[len_w] = '\0'; pas_c[len_w] = '\0';
{ {
u2_noun wiz = pax; u3_noun wiz = pax;
c3_c* waq_c = (pas_c + strlen(pas_c)); c3_c* waq_c = (pas_c + strlen(pas_c));
while ( u2_nul != wiz ) { while ( u3_nul != wiz ) {
c3_w tis_w = u2_cr_met(3, u2h(wiz)); c3_w tis_w = u3_cr_met(3, u3h(wiz));
if ( (u2_yes == fyl) && (u2_nul == u2t(wiz)) ) { if ( (u3_yes == fyl) && (u3_nul == u3t(wiz)) ) {
*waq_c++ = '.'; *waq_c++ = '.';
} else *waq_c++ = '/'; } else *waq_c++ = '/';
u2_cr_bytes(0, tis_w, (c3_y*)waq_c, u2h(wiz)); u3_cr_bytes(0, tis_w, (c3_y*)waq_c, u3h(wiz));
waq_c += tis_w; waq_c += tis_w;
wiz = u2t(wiz); wiz = u3t(wiz);
} }
*waq_c = 0; *waq_c = 0;
} }
u2z(pax); u3z(pax);
return pas_c; return pas_c;
} }