/* u2_lo_sway(): print trace. */ void u2_lo_sway(c3_l tab_l, u2_noun tax) { u2_noun mok = u2_dc("mook", 2, tax); u2_lo_punt(tab_l, u2k(u2t(mok))); u2z(mok); }
/* u2_lo_punt(): dump tank list. */ void u2_lo_punt(c3_l tab_l, u2_noun tac) { u2_noun blu = u2_term_get_blew(0); c3_l col_l = u2h(blu); u2_noun cat = tac; // We are calling nock here, but hopefully need no protection. // while ( u2_yes == u2_cr_du(cat) ) { u2_noun wol = u2_dc("wash", u2nc(tab_l, col_l), u2k(u2h(cat))); _lo_wall(u2_Arv, wol); cat = u2t(cat); } u2z(tac); u2z(blu); }
/* _cm_jack(): steal the trace as of the current kite. */ static u2_noun _cm_jack(u2_noun old, u2_noun nuw) { u2_noun cur = nuw; if ( nuw == old ) { u2z(old); return u2_nul; } else while ( 1 ) { if ( u2ft(cur) == old ) { u2z(old); u2ft(cur) = u2_nul; return nuw; } else { cur = u2ft(cur); } } }
/* _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); } } if ( !dir_u->par_u->par_u ) { // toplevel for ( fil_u = dir_u->par_u->fil_u; fil_u; fil_u = fil_u->nex_u ) { // uL(fprintf(uH, "top %s\n", fil_u->pax_c)); u2_noun wib = _unix_file_tame(fil_u); if ( u2_none == wib ) continue; u2_noun dur = _unix_dir_name(dir_u); if ( u2_no == u2_sing(dur, u2h(wib)) ) { // wrong desk u2z(wib); u2z(dur); continue; } u2_noun baw = _unix_file_load(fil_u); u2_noun woz = u2nt(u2_nul, u2_do("sham", u2k(baw)), baw); u2z(dur); pam = _unix_dir_ankh_file(pam, u2k(u2t(wib)), baw, woz); u2z(wib); } } 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); pam = _unix_dir_ankh_file(pam, wib, baw, woz); } return u2_do("cosh", u2nt(0, u2_nul, pam)); }
/* bend */ u2_noun // produce j2_mcx(Pt5, bend, fun)(u2_wire wir_r, u2_noun raq, // retain u2_noun vex, // retain u2_noun sab) // retain { u2_noun p_vex, q_vex; u2_bi_cell(wir_r, vex, &p_vex, &q_vex); if ( u2_no == u2_dust(q_vex) ) { return u2_rx(wir_r, vex); } else { u2_noun uq_vex = u2_t(q_vex); u2_noun puq_vex, quq_vex; u2_noun yit, yur; u2_noun p_yit, q_yit; u2_noun ret; u2_bi_cell(wir_r, uq_vex, &puq_vex, &quq_vex); yit = u2_bl_good(wir_r, u2_nk_mong(wir_r, sab, u2_rx(wir_r, quq_vex))); u2_bi_cell(wir_r, yit, &p_yit, &q_yit); yur = _last(wir_r, p_vex, p_yit); if ( u2_no == u2_dust(q_yit) ) { ret = u2_bc(wir_r, yur, u2_rx(wir_r, q_vex)); } else { u2_noun uq_yit = u2_t(q_yit); u2_noun puq_yit, quq_yit; u2_noun vux; u2_bi_cell(wir_r, uq_yit, &puq_yit, &quq_yit); vux = u2_bl_good (wir_r, u2_nk_mong (wir_r, raq, u2_bc(wir_r, u2_rx(wir_r, puq_vex), u2_rx(wir_r, puq_yit)))); if ( u2_nul == vux ) { ret = u2_bc(wir_r, yur, u2_rx(wir_r, q_vex)); } else { ret = u2_bq(wir_r, yur, u2_nul, u2k(u2t(vux)), u2_rx(wir_r, quq_yit)); u2z(vux); } } u2_rz(wir_r, yit); return ret; } }
/* u2_term_ef_bake(): initial effects for new terminal. */ void u2_term_ef_bake(u2_noun fav) { u2_noun pax = u2nq(c3__gold, c3__term, '1', u2_nul); u2_reck_plan(u2A, u2k(pax), u2nc(c3__boot, fav)); u2_reck_plan(u2A, u2k(pax), u2nc(c3__blew, u2_term_get_blew(1))); u2_reck_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul)); u2z(pax); }
// _lo_bench_dec(): benchmark decrement. // static void _lo_bench_dec(c3_w num_w) { c3_w i_w; for ( i_w = 0; i_w < num_w; i_w++ ) { u2_noun soc = u2_do("dec", u2k(u2A->now)); u2z(soc); } }
/* _unix_desk_sync_soba(): sync computed changes. */ static void _unix_desk_sync_soba(u2_udir* dir_u, u2_noun doz) { u2_noun zod = doz; while ( u2_nul != zod ) { _unix_desk_sync_miso(dir_u, u2k(u2h(u2h(zod))), u2k(u2t(u2h(zod)))); zod = u2t(zod); } u2z(doz); }
static u2_noun _walk_ok(u2_reck* rec_u, u2_noun nod) { u2_noun don = u2_cn_mung(u2k(rec_u->toy.arch), u2k(nod)); if ( u2_no == u2_sing(nod, don) ) { c3_assert(0); } u2z(don); return nod; }
// _lo_bench_scot_ud(): benchmark prettyprint. // static void _lo_bench_scot_ud(c3_w num_w) { c3_w i_w; for ( i_w = 0; i_w < num_w; i_w++ ) { u2_noun soc = u2_dc("scot", c3__ud, u2k(u2A->now)); u2z(soc); } }
// _lo_bench_slay_p(): benchmark prettyprint. // static void _lo_bench_slay_p(c3_w num_w) { c3_w i_w; for ( i_w = 0; i_w < num_w; i_w++ ) { u2_noun soc = u2_dc("scot", 'p', u2k(u2A->now)); u2_noun dub = u2_do("slay", soc); u2z(dub); } }
/* u2_cm_bowl(): bail out with preset report. */ u2_noun u2_cm_bowl(u2_noun how) { u2_ray kit_r = u2_wire_kit_r(u2_Wire); u2_tx_sys_bit(u2_Wire, u2_yes); { u2_noun jaq; jmp_buf buf_f; // Reset the old stack trace, pulling off the local top. // jaq = u2_cm_wail(); // Reset the old action trace. { u2z(u2_wrac_at(u2_Wire, duz.don)); u2_wrac_at(u2_Wire, duz.don) = u2_kite_don(kit_r); } // Copy out the jump buffer; free the old kite. { memcpy((void *)buf_f, u2_at_cord(u2_kite_buf_r(kit_r), c3_wiseof(jmp_buf)), sizeof(jmp_buf)); u2_wire_kit_r(u2_Wire) = u2_kite_par_r(kit_r); u2_rl_rfree(u2_Wire, kit_r); } // Longjmp with the how-trace pair. XX: no workee with 64-bit nouns. // { u2z(jaq); _longjmp(buf_f, how); } } return 0; }
/* _term_it_show_wide(): show wide text, retaining. */ static void _term_it_show_wide(u2_utty* uty_u, c3_w len_w, c3_w* txt_w) { u2_noun wad = u2_ci_words(len_w, txt_w); u2_noun txt = u2_do("tuft", wad); c3_c* txt_c = u2_cr_string(txt); _term_it_write_str(uty_u, txt_c); free(txt_c); u2z(txt); uty_u->tat_u.mir.cus_w += len_w; }
/* _unix_desk_sync_into(): sync external changes to desk. */ static void _unix_desk_sync_into(u2_noun who, u2_noun hox, u2_noun syd, u2_udir* dir_u) { u2_noun xun, bur, doz, fav, pax; xun = _unix_dir_arch(dir_u); bur = _unix_desk_peek(u2k(who), hox, syd, u2k(u2A->wen)); if ( u2_no == u2_sing(xun, bur) ) { doz = u2_dc("cyst", xun, bur); pax = u2nq(c3__gold, c3__sync, u2k(u2A->sen), u2_nul); fav = u2nq(c3__into, who, syd, u2nc(u2_yes, doz)); u2_reck_plan(u2A, pax, fav); } else { u2z(xun); u2z(bur); } }
/* _unix_desk_sync_ergo(): sync desk changes to unix. */ static void _unix_desk_sync_ergo(u2_noun who, u2_noun hox, u2_noun syd, u2_noun lok, u2_uhot* hot_u) { u2_udir** dir_u = _unix_pdir(&(hot_u->dir_u), syd); u2_noun xun; #if 0 uL(fprintf(uH, "ergo %s %s %s\n", u2_cr_string(hox), u2_cr_string(syd), u2_cr_string(lok))); #endif if ( !*dir_u ) { *dir_u = malloc(sizeof(u2_udir)); xun = u2nc(u2_no, u2_nul); _unix_dir_forge(*dir_u, &(hot_u->dir_u), u2k(syd)); } else { xun = _unix_dir_arch(*dir_u); } { u2_noun bur = _unix_desk_peek(who, hox, syd, lok); if ( u2_no == u2_sing(xun, bur) ) { u2_noun doz = u2_dc("cyst", bur, xun); _unix_desk_sync_soba(*dir_u, doz); } else { u2z(xun); u2z(bur); } } }
/* _nock_moog(): u2_cn_mink() with fly set. */ static u2_noun _nock_moog(u2_noun bus, u2_noun fol) { u2_noun res; u2_kode pon; pon = 0; { u2_noun hoe; if ( 0 != (hoe = u2_cm_trap()) ) { if ( u2h(hoe) == c3__exit ) { res = u2nc(2, u2k(u2t(hoe))); c3_assert(0); u2z(hoe); } else if ( u2h(hoe) == c3__need ) { res = u2nc(1, u2k(u2t(hoe))); u2z(hoe); } else { u2_noun wac = u2k(u2h(hoe)); u2z(hoe); return u2_cm_bail(wac); } } else { u2_noun pro = _nock_mool(bus, fol, &pon); u2_cm_done(); res = u2nc(pon, pro); } } return res; }
/* u2_term_ef_boil(): initial effects for loaded servers. */ void u2_term_ef_boil(void) { { u2_noun pax = u2nq(u2_blip, c3__term, '1', u2_nul); // u2_proc_plan(u2A, u2k(pax), u2nc(c3__init, u2k(u2h(u2A->own)))); u2_proc_plan(u2A, u2k(pax), u2nc(c3__harm, u2_nul)); u2_proc_plan(u2A, u2k(pax), u2nc(c3__blew, u2_term_get_blew(1))); u2_proc_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul)); u2z(pax); } }
/* 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); } }
/* _unix_file_form(): form a filename path downward. */ static c3_c* _unix_file_form(u2_udir* dir_u, u2_noun pre, u2_noun ext) { c3_c* pre_c = u2_cr_string(pre); c3_c* ext_c = u2_cr_string(ext); c3_w pax_w = strlen(dir_u->pax_c); c3_w pre_w = strlen(pre_c); c3_w ext_w = strlen(ext_c); c3_c* pax_c = c3_malloc(pax_w + 1 + pre_w + 1 + ext_w + 1); strncpy(pax_c, dir_u->pax_c, pax_w); pax_c[pax_w] = '/'; strncpy(pax_c + pax_w + 1, pre_c, pre_w); pax_c[pax_w + 1 + pre_w] = '.'; strncpy(pax_c + pax_w + 1 + pre_w + 1, ext_c, ext_w); pax_c[pax_w + 1 + pre_w + 1 + ext_w] = '\0'; free(pre_c); free(ext_c); u2z(pre); u2z(ext); return pax_c; }
/* _lo_tape(): dump a tape, old style. Don't do this. */ static void _lo_tape(u2_reck* rec_u, FILE* fil_u, u2_noun tep) { u2_noun tap = tep; while ( u2_nul != tap ) { c3_c car_c; if ( u2h(tap) >= 127 ) { car_c = '?'; } else car_c = u2h(tap); putc(car_c, fil_u); tap = u2t(tap); } u2z(tep); }
/* _lo_wall(): dump a wall, old style. Don't do this. */ static void _lo_wall(u2_reck* rec_u, u2_noun wol) { FILE* fil_u = u2_term_io_hija(); u2_noun wal = wol; while ( u2_nul != wal ) { _lo_tape(rec_u, fil_u, u2k(u2h(wal))); putc(13, fil_u); putc(10, fil_u); wal = u2t(wal); } u2_term_io_loja(0); u2z(wol); }
u2_noun u2_cm_bail(c3_l how_l) { u2_ray kit_r = u2_wire_kit_r(u2_Wire); if ( u2_yes == u2_Flag_Abort ) { if ( c3__fail == how_l ) { c3_assert(0); } c3_assert(0); } u2_tx_sys_bit(u2_Wire, u2_yes); // fprintf(stderr, "bail\n"); // if ( _num == 0 ) { c3_assert(0); } else _num--; { u2_noun jaq; jmp_buf buf_f; // Reset the old stack trace, pulling off the local top. // jaq = u2_cm_wail(); // Reset the old action trace. { u2z(u2_wrac_at(u2_Wire, duz.don)); u2_wrac_at(u2_Wire, duz.don) = u2_kite_don(kit_r); } // Copy out the jump buffer; free the old kite. { memcpy((void *)buf_f, u2_at_cord(u2_kite_buf_r(kit_r), c3_wiseof(jmp_buf)), sizeof(jmp_buf)); u2_wire_kit_r(u2_Wire) = u2_kite_par_r(kit_r); u2_rl_rfree(u2_Wire, kit_r); } // Longjmp with the how-trace pair. XX: no workee with 64-bit nouns. // { _longjmp(buf_f, u2nc(how_l, jaq)); } } return 0; }
/* _unix_desk_peek(): peek for ankh. */ static u2_noun _unix_desk_peek(u2_noun hox, u2_noun syd, u2_noun lok) { u2_noun cay; cay = u2_reck_prick (u2A, u2nc(c3_s2('c','z'), u2nq(hox, syd, lok, u2_nul))); if ( u2_nul == cay ) { return u2nt(0, u2_nul, u2_nul); } else { u2_noun ank = u2k(u2t(cay)); u2z(cay); return ank; } }
/* _term_it_path(): path for console file. */ static c3_c* _term_it_path(u2_bean fyl, u2_noun pax) { c3_w len_w; c3_c *pas_c; // measure // len_w = strlen(u2_Host.cpu_c); { u2_noun wiz = pax; while ( u2_nul != wiz ) { len_w += (1 + u2_cr_met(3, u2h(wiz))); wiz = u2t(wiz); } } // cut // pas_c = malloc(len_w + 1); strncpy(pas_c, u2_Host.cpu_c, len_w); pas_c[len_w] = '\0'; { u2_noun wiz = pax; c3_c* waq_c = (pas_c + strlen(pas_c)); while ( u2_nul != wiz ) { c3_w tis_w = u2_cr_met(3, u2h(wiz)); if ( (u2_yes == fyl) && (u2_nul == u2t(wiz)) ) { *waq_c++ = '.'; } else *waq_c++ = '/'; u2_cr_bytes(0, tis_w, (c3_y*)waq_c, u2h(wiz)); waq_c += tis_w; wiz = u2t(wiz); } *waq_c = 0; } u2z(pax); return pas_c; }
/* _unix_dir_forge: instantiate directory tracker (and make directory). */ static void _unix_dir_forge(u2_udir* dir_u, u2_udir* par_u, u2_noun tet) { c3_c* tet_c = u2_cr_string(tet); c3_w pax_w = strlen(par_u->pax_c); c3_w tet_w = strlen(tet_c); c3_c* pax_c = c3_malloc(pax_w + 1 + tet_w + 1); strncpy(pax_c, par_u->pax_c, pax_w + 1); pax_c[pax_w] = '/'; strncpy(pax_c + pax_w + 1, tet_c, tet_w + 1); pax_c[pax_w + tet_w + 1] = '\0'; free(tet_c); u2z(tet); _unix_mkdir(pax_c); _unix_dir_watch(dir_u, par_u, pax_c); }
/* 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); } }
/* u2_walk(): traverse `dir_c` to produce an arch, updating `old`. */ u2_noun u2_walk(u2_reck* rec_u, const c3_c* dir_c, u2_noun old) { // XX - obviously, cheaper to update old data. u2z(old); { struct stat buf_b; if ( 0 != stat(dir_c, &buf_b) ) { uL(fprintf(uH, "can't stat %s\n", dir_c)); // return u2_cm_bail(c3__fail); c3_assert(0); } else { return u2nc(u2_no, _walk_in(rec_u, dir_c, strlen(dir_c))); } } }
/* _http_new_response(): create http response structure. */ static u2_hrep* _http_new_response(c3_l sev_l, c3_l coq_l, c3_l seq_l, u2_noun rep) { u2_noun p_rep, q_rep, r_rep; if ( u2_no == u2_cr_trel(rep, &p_rep, &q_rep, &r_rep) ) { uL(fprintf(uH, "strange response\n")); return 0; } else { u2_hrep* rep_u = c3_malloc(sizeof(u2_hrep)); rep_u->sev_l = sev_l; rep_u->coq_l = coq_l; rep_u->seq_l = seq_l; rep_u->sas_w = p_rep; rep_u->hed_u = _http_list_to_heds(u2k(q_rep)); rep_u->bod_u = (u2_nul == r_rep) ? 0 : _http_octs_to_bod(u2k(u2t(r_rep))); u2z(rep); return rep_u; } }
/* _http_octs_to_bod(): translate octet-stream noun into body. */ static u2_hbod* _http_octs_to_bod(u2_noun oct) { c3_w len_w; if ( !u2_fly_is_cat(u2h(oct)) ) { // 2GB max u2_cm_bail(c3__fail); return 0; } len_w = u2h(oct); { u2_hbod* bod_u = c3_malloc(len_w + sizeof(*bod_u)); bod_u->len_w = len_w; u2_cr_bytes(0, len_w, bod_u->hun_y, u2t(oct)); bod_u->nex_u = 0; u2z(oct); return bod_u; } }
/* _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); }