/* _unix_desk_sync_miso(): sync out change. */ static void _unix_desk_sync_miso(u2_udir* dir_u, u2_noun pax, u2_noun mis) { if ( (u2_no == u2du(pax)) || u2_no == u2du(u2t(pax)) ) { c3_assert(0); u2z(pax); u2z(mis); } else { u2_noun i_pax = u2h(pax); u2_noun t_pax = u2t(pax); u2_noun it_pax = u2h(t_pax); u2_noun tt_pax = u2t(t_pax); if ( u2_nul == tt_pax ) { _unix_desk_sync_tofu(dir_u, u2k(i_pax), u2k(it_pax), mis); } else { u2_udir** dis_u = _unix_pdir(dir_u, u2k(i_pax)); if ( !*dis_u ) { *dis_u = malloc(sizeof(u2_udir)); _unix_dir_forge(*dis_u, dir_u, u2k(i_pax)); } _unix_desk_sync_miso(*dis_u, u2k(t_pax), mis); } } u2z(pax); }
/* _nock_pray_mool(): load from namespace, in virtual mode. */ static u2_noun _nock_pray_mool(u2_noun gof, u2_kode *pon) // transfer { u2_noun lad = u2_hevn_at(lad); c3_assert(u2_yes == u2du(lad)); c3_assert(0 == *pon); { u2_noun i_lad = u2fh(lad); u2_noun t_lad = u2ft(lad); u2_noun pro; u2_noun hoe; u2_hevn_at(lad) = t_lad; if ( 0 != (hoe = u2_cm_trap()) ) { u2_cm_done(); return u2_cm_bail(u2k(u2h(hoe))); } else { if ( u2_nul == t_lad ) { pro = u2_cn_mung(u2k(i_lad), u2k(gof)); } else { pro = _nock_molg(u2k(i_lad), u2k(gof), pon); } u2_cm_done(); c3_assert(t_lad == u2_hevn_at(lad)); u2_hevn_at(lad) = lad; if ( 0 != *pon ) { u2z(gof); return pro; } else { if ( u2_no == u2du(pro) ) { *pon = 1; u2z(pro); return u2nc(gof, u2_nul); } else { u2_noun res = u2k(u2t(pro)); u2z(gof); u2z(pro); return res; } } } } }
/* u2_unix_io_poll(): update unix IO state. */ void u2_unix_io_poll(void) { u2_unix* unx_u = &u2_Host.unx_u; u2_noun wen = u2_reck_keep(u2A, u2nt(c3__gold, c3__clay, u2_nul)); if ( (u2_nul != wen) && (u2_yes == u2du(wen)) && (u2_yes == u2ud(u2t(wen))) ) { c3_d gap_d = u2_time_gap_ms(u2k(u2A->now), u2k(u2t(wen))); if ( u2_yes == unx_u->alm ) { uv_timer_stop(&unx_u->tim_u); } else unx_u->alm = u2_yes; uv_timer_start(&unx_u->tim_u, _unix_time_cb, gap_d, 0); } else { if ( u2_yes == unx_u->alm ) { uv_timer_stop(&unx_u->tim_u); } unx_u->alm = u2_no; } u2z(wen); }
/* u2_unix_io_poll(): update unix IO state. */ void u2_unix_io_poll(void) { u2_unix* unx_u = &u2_Host.unx_u; u2_noun wen = u2_reck_keep(u2A, u2nt(u2_blip, c3__clay, u2_nul)); if ( (u2_nul != wen) && (u2_yes == u2du(wen)) && (u2_yes == u2ud(u2t(wen))) ) { c3_d gap_d = u2_time_gap_ms(u2k(u2A->now), u2k(u2t(wen))); if ( u2_yes == unx_u->alm ) { uv_timer_stop(&unx_u->tim_u); } else unx_u->alm = u2_yes; if ( gap_d < 1000 ) { gap_d = 1000; } // band-aid on an unknown clay timer bug uv_timer_start(&unx_u->tim_u, _unix_time_cb, gap_d, 0); } else { if ( u2_yes == unx_u->alm ) { uv_timer_stop(&unx_u->tim_u); } unx_u->alm = u2_no; } u2z(wen); }
/* u2_batz_io_poll(): update batz IO state. */ void u2_batz_io_poll(void) { u2_batz* beh_u = &u2_Host.beh_u; u2_noun wen = u2_reck_keep(u2A, u2nt(c3__gold, c3__batz, u2_nul)); if ( (u2_nul != wen) && (u2_yes == u2du(wen)) && (u2_yes == u2ud(u2t(wen))) ) { c3_d gap_d = u2_time_gap_ms(u2k(u2A->now), u2k(u2t(wen))); if ( u2_yes == beh_u->alm ) { uv_timer_stop(&beh_u->tim_u); } else beh_u->alm = u2_yes; uv_timer_start(&beh_u->tim_u, _batz_time_cb, gap_d, 0); } else { if ( u2_yes == beh_u->alm ) { uv_timer_stop(&beh_u->tim_u); } beh_u->alm = u2_no; } u2z(wen); }
/* u2_cr_tape(): `a`, a list of bytes, as malloced C string. */ c3_y* u2_cr_tape(u2_noun a) { u2_noun b; c3_w i_w; c3_y *a_y; for ( i_w = 0, b=a; u2_yes == u2du(b); i_w++, b=u2t(b) ) ; a_y = c3_malloc(i_w + 1); for ( i_w = 0, b=a; u2_yes == u2du(b); i_w++, b=u2t(b) ) { a_y[i_w] = u2h(b); } a_y[i_w] = 0; return a_y; }
/* _unix_dir_ankh_file(): process a file for ankh. */ static u2_noun _unix_dir_ankh_file(u2_noun pam, u2_noun wib, u2_noun baw, u2_noun woz) { u2_weak ole; if ( u2_no == u2du(wib) ) { ole = u2_ckd_by_get(u2k(pam), u2k(wib)); if ( u2_none == ole ) { ole = u2_do("cosh", u2nt(0, woz, u2_nul)); } else { u2_noun elo; elo = u2_do("cosh", u2nt(0, woz, u2k(u2t(u2t(ole))))); u2z(ole); ole = elo; } pam = u2_ckd_by_put(pam, wib, ole); } else { u2_noun fid = u2h(wib); u2_noun har = u2t(wib); ole = u2_ckd_by_get(u2k(pam), u2k(fid)); if ( u2_none == ole ) { ole = u2nt (0, u2_nul, u2_ckd_by_put(u2_nul, u2k(har), u2_do("cosh", u2nt(0, woz, u2_nul)))); ole = u2_do("cosh", ole); } else { u2_noun roo = u2t(u2t(ole)); u2_weak tup = u2_ckd_by_get(u2k(roo), u2k(har)); u2_noun oor, elo; if ( u2_none == tup ) { tup = u2_do("cosh", u2nt(0, woz, u2_nul)); } else { u2_noun upt; upt = u2_do("cosh", u2nt(0, woz, u2k(u2t(u2t(tup))))); u2z(tup); tup = upt; } oor = u2_ckd_by_put(u2k(roo), u2k(har), tup); elo = u2_do("cosh", u2nt(0, u2k(u2h(u2t(ole))), oor)); u2z(ole); ole = elo; } pam = u2_ckd_by_put(pam, u2k(fid), ole); u2z(wib); } return pam; }
/* nock_molg(): function call (mung) with kode. Arguments transferred. */ static u2_noun _nock_molg(u2_noun gat, u2_noun sam, u2_kode* pon) { if ( (u2_no == u2du(gat)) || (u2_no == u2du(u2t(gat))) ) { *pon = 2; return u2_cm_wail(); } else { u2_noun cor, fol; cor = u2nc(u2k(u2h(gat)), u2nc(sam, u2k(u2t(u2t(gat))))); fol = u2k(u2h(gat)); u2z(gat); // XX try to chip with u2_ds_find? but a rare case... return _nock_mool(cor, fol, pon); } }
/* _cm_depth() */ static c3_w _cm_depth(u2_noun old, u2_noun nuw) { c3_w dep_w = 0; while ( nuw != old ) { c3_assert(u2_yes == u2du(nuw)); nuw = u2t(nuw); dep_w++; } return dep_w; }
/* _unix_desk_sync_tako(): sync out change. */ static void _unix_desk_sync_tako(u2_udir* dir_u, u2_noun pax, u2_noun mis) { if ( (u2_no == u2du(pax)) ) { c3_assert(!"tack"); } else if ( u2_no == u2du(u2t(pax)) ) { // at toplevel u2_noun i_pax = u2h(pax); u2_noun t_pax = u2t(pax); c3_c* par_u = strrchr(dir_u->pax_c, '/') + 1; u2_noun pem = u2_ci_string(par_u); c3_assert( u2_nul == t_pax ); // XX ugly, wrong _unix_desk_sync_tofu(dir_u->par_u, pem, u2k(i_pax), mis); } else { u2_noun i_pax = u2h(pax); u2_noun t_pax = u2t(pax); u2_noun it_pax = u2h(t_pax); u2_noun tt_pax = u2t(t_pax); if ( u2_nul == tt_pax ) { _unix_desk_sync_tofu(dir_u, u2k(i_pax), u2k(it_pax), mis); } else { u2_udir** dis_u = _unix_pdir(dir_u, u2k(i_pax)); if ( !*dis_u ) { *dis_u = c3_malloc(sizeof(u2_udir)); _unix_dir_forge(*dis_u, dir_u, u2k(i_pax)); } _unix_desk_sync_tako(*dis_u, u2k(t_pax), mis); } } u2z(pax); }
/* _unix_dir_arch(): resolve directory to old style arch. */ static u2_noun _unix_dir_arch(u2_udir* dir_u) { u2_udir* dis_u; u2_ufil* fil_u; u2_noun pam = u2_nul; for ( dis_u = dir_u->dis_u; dis_u; dis_u = dis_u->nex_u ) { u2_noun pre = _unix_dir_name(dis_u); u2_noun arc = _unix_dir_arch(dis_u); // uL(fprintf(uH, "dir %s\n", u2_cr_string(pre))); pam = u2_ckd_by_put(pam, pre, arc); } for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) { u2_noun wib = _unix_file_name(fil_u); u2_noun baw = _unix_file_load(fil_u); u2_noun has = u2_do("sham", u2k(baw)); u2_noun fil = u2nt(u2_yes, has, baw); if ( u2_no == u2du(wib) ) { // uL(fprintf(uH, "file %s\n", u2_cr_string(wib))); pam = u2_ckd_by_put(pam, wib, fil); } else { u2_weak ole = u2_ckd_by_get(u2k(pam), u2k(u2h(wib))); u2_noun arc, rac; // uL(fprintf(uH, "file %s.%s\n", u2_cr_string(u2h(wib)), // u2_cr_string(u2t(wib)))); if ( u2_none == ole ) { arc = u2nc(u2_no, u2_nul); } else if ( u2_yes == u2h(ole) ) { u2z(ole); arc = u2nc(u2_no, u2_nul); } else arc = ole; rac = u2nc(u2_no, u2_ckd_by_put(u2k(u2t(arc)), u2k(u2t(wib)), fil)); pam = u2_ckd_by_put(pam, u2k(u2h(wib)), rac); u2z(wib); u2z(arc); } } return u2nc(u2_no, pam); }
/* u2_term_ef_blit(): send %blit list to specific terminal. */ void u2_term_ef_blit(c3_l tid_l, u2_noun bls) { u2_utty* uty_u = _term_ef_get(tid_l); if ( 0 == uty_u ) { // uL(fprintf(uH, "no terminal %d\n", tid_l)); // uL(fprintf(uH, "uty_u %p\n", u2_Host.uty_u)); u2z(bls); return; } { u2_noun bis = bls; while ( u2_yes == u2du(bis) ) { _term_ef_blit(uty_u, u2k(u2h(bis))); bis = u2t(bis); } u2z(bls); } }
/* nock_mool(): fast internal mink interface. Arguments transferred. */ u2_noun _nock_mool(u2_noun bus, u2_noun fol, u2_kode* pon) { u2_noun hib, gal; c3_assert(u2_yes == *pon); while ( 1 ) { u2_tx_did_hop(u2_Wire, 1); if ( u2_no == u2du(fol) ) { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } else { hib = u2fh(fol); gal = u2ft(fol); } if ( u2_yes == u2du(hib) ) { u2_noun poz, riv; u2_kode h_pon = 0, t_pon = 0; poz = _nock_mool(u2k(bus), u2k(hib), &h_pon); if ( 2 == h_pon ) { *pon = 2; u2z(bus); u2z(fol); return poz; } riv = _nock_mool(bus, u2k(gal), &t_pon); u2z(fol); if ( 2 == t_pon ) { *pon = 2; u2z(poz); return riv; } if ( (1 == h_pon) || (1 == t_pon) ) { u2_noun lal; *pon = 1; if ( 0 == h_pon ) { u2z(poz); lal = riv; } else if ( 0 == t_pon ) { u2z(riv); lal = poz; } else { lal = u2_ckb_weld(poz, riv); } return lal; } return u2_cn_cell(poz, riv); } else switch ( hib ) { default: *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); case 0: { if ( u2_no == u2_cr_ud(gal) ) { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } else { u2_weak pro = u2_cr_at(gal, bus); if ( u2_none == pro ) { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } else { pro = u2k(pro); u2z(bus); u2z(fol); return pro; } } } case 1: { u2_noun pro = u2k(gal); u2z(bus); u2z(fol); return pro; } c3_assert(!"not reached"); case 2: { if ( (u2_no == u2du(gal)) || (u2_no == u2du(u2fh(gal))) ) { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } else { u2_noun neb; neb = _nock_mool(bus, u2k(gal), pon); u2z(fol); if ( 0 != *pon ) { return neb; } bus = u2k(u2fh(neb)); fol = u2k(u2ft(neb)); u2z(neb); continue; } } c3_assert(!"not reached"); case 3: { u2_noun gof, pro; gof = _nock_mool(bus, u2k(gal), pon); u2z(fol); if ( 0 != *pon ) { return gof; } pro = u2du(gof); u2z(gof); return pro; } c3_assert(!"not reached"); case 4: { u2_noun gof, pro; gof = _nock_mool(bus, u2k(gal), pon); u2z(fol); if ( 0 != *pon ) { return gof; } if ( u2_none == (pro = u2_rl_vint(u2_Wire, gof)) ) { *pon = 2; u2z(gof); return u2_cm_wail(); } u2z(gof); return pro; } c3_assert(!"not reached"); case 5: { u2_noun gof, pro; gof = _nock_mool(bus, u2k(gal), pon); u2z(fol); if ( 0 != *pon ) { return gof; } if ( u2_no == u2du(gof) ) { *pon = 2; u2z(gof); return u2_cm_wail(); } pro = u2_cr_sing(u2h(gof), u2t(gof)); u2z(gof); return pro; } c3_assert(!"not reached"); case 6: { u2_noun b_gal, cd_gal, c_gal, d_gal; if ( u2_no == u2_cr_cell(gal, &b_gal, &cd_gal) ) { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } else { u2_noun tys, nex; tys = _nock_mool(u2k(bus), u2k(b_gal), pon); if ( 0 != *pon ) { u2z(bus); u2z(fol); return tys; } if ( u2_no == u2_cr_cell(cd_gal, &c_gal, &d_gal) ) { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } if ( 0 == tys ) { nex = u2k(c_gal); } else if ( 1 == tys ) { nex = u2k(d_gal); } else { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } u2z(fol); fol = nex; continue; } } c3_assert(!"not reached"); case 7: { u2_noun b_gal, c_gal; if ( u2_no == u2_cr_cell(gal, &b_gal, &c_gal) ) { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } else { u2_noun bod, nex; bod = _nock_mool(bus, u2k(b_gal), pon); if ( 0 != *pon ) { u2z(fol); return bod; } nex = u2k(c_gal); u2z(fol); bus = bod; fol = nex; continue; } } c3_assert(!"not reached"); case 8: { u2_noun b_gal, c_gal; // c3_assert(!"got 8 (mink)!"); if ( u2_no == u2_cr_cell(gal, &b_gal, &c_gal) ) { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } else { u2_noun wib, bod, nex; wib = _nock_mool(u2k(bus), u2k(b_gal), pon); if ( 0 != *pon ) { u2z(bus); u2z(fol); return wib; } bod = u2nc(wib, bus); nex = u2k(c_gal); u2z(fol); bus = bod; fol = nex; continue; } } c3_assert(!"not reached"); case 9: { u2_noun b_gal, c_gal; if ( (u2_no == u2_cr_cell(gal, &b_gal, &c_gal)) || (u2_no == u2ud(b_gal)) ) { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } else { u2_noun seb; u2_weak xip; seb = _nock_mool(bus, u2k(c_gal), pon); u2z(fol); if ( 0 != *pon ) { return seb; } u2_tx_sys_bit(u2_Wire, u2_yes); xip = u2_ds_find(u2_Wire, seb); u2_tx_sys_bit(u2_Wire, u2_no); if ( u2_none != xip ) { u2_noun pro; u2_tx_sys_bit(u2_Wire, u2_yes); pro = u2_ho_kicq(u2_Wire, xip, seb, b_gal, pon); u2_tx_sys_bit(u2_Wire, u2_no); u2z(seb); if ( u2_none == pro ) { *pon = 2; return u2_cm_wail(); } else return pro; } else { u2_noun nex = u2_cr_at(b_gal, seb); if ( u2_none == nex ) { *pon = 2; u2z(seb); return u2_cm_wail(); } bus = seb; fol = u2k(nex); continue; } } } c3_assert(!"not reached"); case 10: { u2_noun p_gal, q_gal; if ( u2_no == u2_cr_cell(gal, &p_gal, &q_gal) ) { *pon = 2; u2z(bus); u2z(fol); return u2_cm_wail(); } else { u2_noun zep, hod, nex; if ( u2_yes == u2du(p_gal) ) { u2_noun b_gal = u2fh(p_gal); u2_noun c_gal = u2ft(p_gal); u2_noun d_gal = q_gal; hod = _nock_mool(u2k(bus), u2_ct(c_gal), pon); if ( 0 != *pon ) { u2z(fol); return hod; } zep = u2k(b_gal); nex = u2k(d_gal); u2z(fol); } else { u2_noun b_gal = p_gal; u2_noun c_gal = q_gal; zep = u2k(b_gal); hod = u2_nul; nex = u2k(c_gal); u2z(fol); } return _nock_hint(zep, hod, bus, nex, pon); } } case 11: { u2_noun gof; gof = _nock_mool(bus, u2k(gal), pon); u2z(fol); if ( 0 != *pon ) { return gof; } return _nock_pray_mool(gof, pon); } c3_assert(!"not reached"); } } }
/* _nock_cool(): nock, transferring arguments. */ static u2_noun _nock_cool(u2_noun bus, u2_noun fol) { u2_noun hib, gal; while ( 1 ) { u2_tx_did_hop(u2_Wire, 1); if ( u2_no == u2du(fol) ) { return u2_cm_bail(c3__exit); } else { hib = u2fh(fol); gal = u2ft(fol); } if ( u2_yes == u2du(hib) ) { u2_noun poz, riv; poz = _nock_cool(u2k(bus), u2k(hib)); riv = _nock_cool(bus, u2k(gal)); u2z(fol); return u2_cn_cell(poz, riv); } else switch ( hib ) { default: return u2_cm_bail(c3__exit); case 0: { if ( u2_no == u2_cr_ud(gal) ) { return u2_cm_bail(c3__exit); } else { u2_noun pro = u2k(u2at(gal, bus)); u2z(bus); u2z(fol); return pro; } } case 1: { u2_noun pro = u2k(gal); u2z(bus); u2z(fol); return pro; } c3_assert(!"not reached"); case 2: { if ( u2_no == u2du(gal) ) { return u2_cm_bail(c3__exit); } else { u2_noun nex = _nock_cool(u2k(bus), u2k(u2ft(gal))); u2_noun seb = _nock_cool(bus, u2k(u2fh(gal))); u2z(fol); bus = seb; fol = nex; continue; } } c3_assert(!"not reached"); case 3: { u2_noun gof, pro; gof = _nock_cool(bus, u2k(gal)); pro = u2du(gof); u2z(gof); u2z(fol); return pro; } c3_assert(!"not reached"); case 4: { u2_noun gof, pro; gof = _nock_cool(bus, u2k(gal)); if ( (u2_none == (pro = u2_rl_vint(u2_Wire, gof))) ) { return u2_cm_bail(c3__exit); } u2z(gof); u2z(fol); return pro; } c3_assert(!"not reached"); case 5: { if ( u2_no == u2du(gal) ) { return u2_cm_bail(c3__exit); } else { u2_noun wim = _nock_cool(bus, u2k(gal)); u2_noun pro; if ( u2_no == u2du(wim) ) { return u2_cm_bail(c3__exit); } else pro = u2_cr_sing(u2h(wim), u2t(wim)); u2z(wim); u2z(fol); return pro; } } c3_assert(!"not reached"); case 6: { u2_noun b_gal, c_gal, d_gal; u2_cx_trel(gal, &b_gal, &c_gal, &d_gal); { u2_noun tys = _nock_cool(u2k(bus), u2k(b_gal)); u2_noun nex; if ( 0 == tys ) { nex = u2k(c_gal); } else if ( 1 == tys ) { nex = u2k(d_gal); } else return u2_cm_bail(c3__exit); u2z(fol); fol = nex; continue; } } c3_assert(!"not reached"); case 7: { u2_noun b_gal, c_gal; u2_cx_cell(gal, &b_gal, &c_gal); { u2_noun bod = _nock_cool(bus, u2k(b_gal)); u2_noun nex = u2k(c_gal); u2z(fol); bus = bod; fol = nex; continue; } } c3_assert(!"not reached"); case 8: { u2_noun b_gal, c_gal; // c3_assert(!"got 8 (nock)!"); u2_cx_cell(gal, &b_gal, &c_gal); { u2_noun bod = u2nc(_nock_cool(u2k(bus), u2k(b_gal)), bus); u2_noun nex = u2k(c_gal); u2z(fol); bus = bod; fol = nex; continue; } } c3_assert(!"not reached"); case 9: { u2_noun b_gal, c_gal; u2_cx_cell(gal, &b_gal, &c_gal); if ( u2_no == u2ud(b_gal) ) { return u2_cm_bail(c3__exit); } else { u2_noun seb = _nock_cool(bus, u2k(c_gal)); u2_weak xip; u2_tx_sys_bit(u2_Wire, u2_yes); xip = u2_ds_find(u2_Wire, seb); if ( u2_none != xip ) { u2_noun pro = u2_ho_kick(u2_Wire, xip, seb, b_gal); u2_tx_sys_bit(u2_Wire, u2_no); if ( u2_none == pro ) { return u2_cm_bail(c3__exit); } else { u2z(seb); u2z(fol); return pro; } } else { u2_tx_sys_bit(u2_Wire, u2_no); { u2_noun nex = u2_ct(u2at(b_gal, seb)); u2z(fol); bus = seb; fol = nex; continue; } } } } c3_assert(!"not reached"); case 10: { u2_noun p_gal, q_gal; u2_cx_cell(gal, &p_gal, &q_gal); { u2_noun zep, hod, nex, pro; if ( u2_yes == u2du(p_gal) ) { u2_noun b_gal = u2fh(p_gal); u2_noun c_gal = u2ft(p_gal); u2_noun d_gal = q_gal; zep = u2k(b_gal); hod = _nock_cool(u2k(bus), u2_ct(c_gal)); nex = u2_ct(d_gal); } else { u2_noun b_gal = p_gal; u2_noun c_gal = q_gal; zep = u2k(b_gal); hod = u2_nul; nex = u2_ct(c_gal); } u2_cz(fol); pro = _nock_hint(zep, hod, bus, nex, 0); return pro; } } case 11: { u2_noun gof, pro; gof = _nock_cool(bus, u2k(gal)); pro = _nock_pray_cool(gof); u2z(fol); return pro; } c3_assert(!"not reached"); } } }
/* _unix_desk_sync_tofu(): sync out file install. */ static void _unix_desk_sync_tofu(u2_udir* dir_u, u2_noun pre, u2_noun ext, u2_noun mis) { c3_c* pox_c = _unix_file_form(dir_u, u2k(pre), u2_no, u2k(ext)); c3_c* pux_c = _unix_file_form(dir_u, u2k(pre), u2_yes, u2k(ext)); u2_ufil** fil_u; // uL(fprintf(uH, "tofu pox_c %s op %s\n", pox_c, u2_cr_string(u2h(mis)))); #ifdef SYNCLOG c3_w slot = u2_Host.unx_u.lot_w++ % 1024; free(u2_Host.unx_u.sylo[slot].pax_c); u2_Host.unx_u.sylo[slot].pax_c = 0; #endif fil_u = &(dir_u->fil_u); while ( 1 ) { // XX crude! if ( !*fil_u || !strcmp((*fil_u)->pax_c, pox_c) || !strcmp((*fil_u)->pax_c, pux_c) ) { break; } else fil_u = &((*fil_u)->nex_u); } if ( *fil_u && (c3__del == u2h(mis)) ) { u2_ufil* ded_u = *fil_u; #ifdef SYNCLOG u2_Host.unx_u.sylo[slot].unx = u2_no; u2_Host.unx_u.sylo[slot].wer_m = c3_s4('t','o','f','u'); u2_Host.unx_u.sylo[slot].wot_m = c3__del; u2_Host.unx_u.sylo[slot].pax_c = strdup(ded_u->pax_c); #endif *fil_u = ded_u->nex_u; _unix_unlink(ded_u->pax_c); _unix_file_free(ded_u); free(pox_c); free(pux_c); } else { u2_noun god, oat; c3_c* pax_c; if ( *fil_u ) { u2_noun old = _unix_file_load(*fil_u); c3_assert(c3__mut == u2h(mis)); god = _unix_desk_sync_udon(u2k(u2t(mis)), old); _unix_unlink((*fil_u)->pax_c); free((*fil_u)->pax_c); } else { c3_assert(c3__ins == u2h(mis)); god = u2k(u2t(mis)); } if ( u2_yes == u2du(god) ) { oat = u2_cke_jam(god); pax_c = pux_c; free(pox_c); } else { oat = god; pax_c = pox_c; free(pux_c); } #ifdef SYNCLOG u2_Host.unx_u.sylo[slot].unx = u2_no; u2_Host.unx_u.sylo[slot].wer_m = c3_s4('t','o','f','u'); u2_Host.unx_u.sylo[slot].wot_m = u2h(mis); u2_Host.unx_u.sylo[slot].pax_c = strdup(pax_c); #endif _unix_save(pax_c, oat); if ( *fil_u ) { (*fil_u)->dot_c = (pax_c + ((*fil_u)->dot_c - (*fil_u)->pax_c)); (*fil_u)->pax_c = pax_c; mpz_clear((*fil_u)->mod_mp); u2_cr_mp((*fil_u)->mod_mp, u2A->now); } else { mpz_t mod_mp; u2_cr_mp(mod_mp, u2A->now); *fil_u = c3_malloc(sizeof(u2_ufil)); _unix_file_watch(*fil_u, dir_u, pax_c, mod_mp); mpz_clear(mod_mp); } } u2z(pre); u2z(ext); u2z(mis); }
/* _unix_dir_ankh(): resolve directory to new style ankh. */ static u2_noun _unix_dir_ankh(u2_udir* dir_u) { u2_udir* dis_u; u2_ufil* fil_u; u2_noun pam = u2_nul; for ( dis_u = dir_u->dis_u; dis_u; dis_u = dis_u->nex_u ) { u2_noun pre = _unix_dir_name(dis_u); u2_noun ank = _unix_dir_ankh(dis_u); // uL(fprintf(uH, "dir %s\n", u2_cr_string(pre))); if ( 0 != u2h(ank) ) { pam = u2_ckd_by_put(pam, pre, ank); } } for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) { u2_noun wib = _unix_file_name(fil_u); u2_noun baw = _unix_file_load(fil_u); u2_noun woz = u2nt(u2_nul, u2_do("sham", u2k(baw)), baw); u2_weak ole; if ( u2_no == u2du(wib) ) { ole = u2_ckd_by_get(u2k(pam), u2k(wib)); if ( u2_none == ole ) { ole = u2_do("cosh", u2nt(0, woz, u2_nul)); } else { u2_noun elo; elo = u2_do("cosh", u2nt(0, woz, u2k(u2t(u2t(ole))))); u2z(ole); ole = elo; } pam = u2_ckd_by_put(pam, wib, ole); } else { u2_noun fid = u2h(wib); u2_noun har = u2t(wib); ole = u2_ckd_by_get(u2k(pam), u2k(fid)); if ( u2_none == ole ) { ole = u2nt (0, u2_nul, u2_ckd_by_put(u2_nul, u2k(har), u2_do("cosh", u2nt(0, woz, u2_nul)))); ole = u2_do("cosh", ole); } else { u2_noun roo = u2t(u2t(ole)); u2_weak tup = u2_ckd_by_get(u2k(roo), u2k(har)); u2_noun oor, elo; if ( u2_none == tup ) { tup = u2_do("cosh", u2nt(0, woz, u2_nul)); } else { u2_noun upt; upt = u2_do("cosh", u2nt(0, woz, u2k(u2t(u2t(tup))))); u2z(tup); tup = upt; } oor = u2_ckd_by_put(u2k(roo), u2k(har), tup); elo = u2_do("cosh", u2nt(0, u2k(u2h(u2t(ole))), oor)); u2z(ole); ole = elo; } pam = u2_ckd_by_put(pam, u2k(fid), ole); u2z(wib); } } return u2_do("cosh", u2nt(0, u2_nul, pam)); }
/* _unix_desk_sync_tofu(): sync out file install. */ static void _unix_desk_sync_tofu(u2_udir* dir_u, u2_noun pre, u2_noun ext, u2_noun mis) { c3_c* pox_c = _unix_file_form(dir_u, u2k(pre), u2_no, u2k(ext)); c3_c* pux_c = _unix_file_form(dir_u, u2k(pre), u2_yes, u2k(ext)); u2_ufil** fil_u; // uL(fprintf(uH, "tofu pox_c %s op %s\n", pox_c, u2_cr_string(u2h(mis)))); fil_u = &(dir_u->fil_u); while ( 1 ) { // XX crude! if ( !*fil_u || !strcmp((*fil_u)->pax_c, pox_c) || !strcmp((*fil_u)->pax_c, pux_c) ) { break; } else fil_u = &((*fil_u)->nex_u); } if ( *fil_u && (c3__del == u2h(mis)) ) { u2_ufil* ded_u = *fil_u; *fil_u = ded_u->nex_u; _unix_unlink(ded_u->pax_c); _unix_file_free(ded_u); free(ded_u); free(pox_c); free(pux_c); } else { u2_noun god, oat; c3_c* pax_c; if ( *fil_u ) { u2_noun old = _unix_file_load(*fil_u); c3_assert(c3__mut == u2h(mis)); god = _unix_desk_sync_udon(u2k(u2t(mis)), old); _unix_unlink((*fil_u)->pax_c); free((*fil_u)->pax_c); } else { c3_assert(c3__ins == u2h(mis)); god = u2k(u2t(mis)); } if ( u2_yes == u2du(god) ) { oat = u2_cke_jam(god); pax_c = pux_c; free(pox_c); } else { oat = god; pax_c = pox_c; free(pux_c); } if ( *fil_u ) { (*fil_u)->dot_c = (pax_c + ((*fil_u)->dot_c - (*fil_u)->pax_c)); (*fil_u)->pax_c = pax_c; mpz_clear((*fil_u)->mod_mp); u2_cr_mp((*fil_u)->mod_mp, u2A->now); } else { mpz_t mod_mp; u2_cr_mp(mod_mp, u2A->now); *fil_u = malloc(sizeof(u2_ufil)); _unix_file_watch(*fil_u, dir_u, pax_c, mod_mp); mpz_clear(mod_mp); } _unix_save((*fil_u)->pax_c, oat); } u2z(pre); u2z(ext); u2z(mis); }