/* u2_term_ef_boil(): initial effects for loaded servers. */ void u2_term_ef_boil(c3_l old_l, c3_l ono_l) { if ( ono_l ) { u2_noun oan = u2_dc("scot", c3__uv, old_l); u2_noun tid_l; for ( tid_l = 1; tid_l <= ono_l; tid_l++ ) { u2_noun tin = u2_dc("scot", c3__ud, tid_l); u2_noun pax = u2nc(c3__gold, u2nq(c3__term, u2k(oan), tin, u2_nul)); u2_noun hud = u2nc(c3__wipe, u2_nul); u2_reck_plan(u2A, pax, hud); } u2z(oan); } { u2_noun pax = u2nc(c3__gold, u2nq(c3__term, u2k(u2A->sen), '1', u2_nul)); u2_reck_plan(u2A, u2k(pax), u2nc(c3__init, u2k(u2h(u2A->own)))); u2_reck_plan(u2A, u2k(pax), u2nc(c3__blew, u2_term_get_blew(u2A, 1))); u2_reck_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul)); u2z(pax); } }
/* _http_pox_to_noun(): translate srv/con/req to path noun (pox). */ static u2_noun _http_pox_to_noun(c3_w sev_l, c3_w coq_l, c3_w seq_l) { return u2nt( c3__iron, c3__http, u2nq(u2_dc("scot", c3_s2('u','v'), sev_l), u2_dc("scot", c3_s2('u','d'), coq_l), u2_dc("scot", c3_s2('u','d'), seq_l), u2_nul)); }
/* u2_unix_ef_ergo(): update filesystem, outbound. */ void u2_unix_ef_ergo(u2_noun who, u2_noun syd, u2_noun rel) { u2_noun hox = u2_dc("scot", 'p', u2k(who)); u2_noun lok = u2_dc("scot", c3__ud, rel); u2_uhot* hot_u; hot_u = _unix_home(u2k(who)); if ( 0 != hot_u ) { _unix_desk_sync_ergo(who, hox, syd, lok, hot_u); } }
/* _unix_ship_update(): update top level ship. */ static void _unix_ship_update(u2_uhot* hot_u) { u2_udir* dir_u = &(hot_u->dir_u); DIR* rid_u = _unix_opendir(dir_u->pax_c); if ( u2_yes == _unix_dir_update(dir_u, rid_u) ) { u2_udir* dis_u; u2_noun who, hox; { mpz_t who_mp; mpz_init_set(who_mp, hot_u->who_mp); who = u2_ci_mp(who_mp); hox = u2_dc("scot", 'p', u2k(who)); } for ( dis_u = dir_u->dis_u; dis_u; dis_u = dis_u->nex_u ) { u2_noun syd = _unix_dir_name(dis_u); // uL(fprintf(uH, "sync %s %s\n", u2_cr_string(hox), u2_cr_string(syd))); _unix_desk_sync_into(u2k(who), u2k(hox), syd, dis_u); } u2z(hox); u2z(who); } }
/* _unix_hot_gain(): gain ship. */ static void _unix_hot_gain(u2_noun who, u2_bean mek) { u2_noun hox = u2_dc("scot", 'p', who); c3_c* hox_c = u2_cr_string(hox); c3_c* pax_c = _unix_down(u2_Host.ops_u.hom_c, hox_c + 1); DIR* rid_u = opendir(pax_c); if ( !rid_u ) { if ( u2_yes == mek ) { _unix_mkdir(pax_c); } else return; } else closedir(rid_u); // uL(fprintf(uH, "GAIN %s\n", pax_c)); free(hox_c); u2z(hox); u2_unix_acquire(pax_c); { u2_uhot* hot_u = malloc(sizeof(u2_uhot)); _unix_dir_watch(&hot_u->dir_u, 0, pax_c); u2_cr_mp(hot_u->who_mp, who); hot_u->nex_u = u2_Host.unx_u.hot_u; u2_Host.unx_u.hot_u = hot_u; } }
/* _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_ankh(dir_u); bur = _unix_desk_peek(hox, u2k(syd), u2k(u2A->wen)); if ( (u2_no == u2_sing(u2h(xun), u2h(bur)))) //&& // (u2_no == _unix_ankh_sing(xun, bur)) ) { doz = u2_dc("cost", xun, bur); pax = u2nq(u2_blip, 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(who); u2z(syd); u2z(xun); u2z(bur); } }
/* _term_close_cb(): free terminal. */ static void _term_close_cb(uv_handle_t* han_t) { u2_utty* tty_u = (void*) han_t; if ( u2_Host.uty_u == tty_u ) { u2_Host.uty_u = tty_u->nex_u; } else { u2_utty* uty_u; for (uty_u = u2_Host.uty_u; uty_u; uty_u = uty_u->nex_u ) { if ( uty_u->nex_u == tty_u ) { uty_u->nex_u = tty_u->nex_u; break; } } } { u2_noun tid = u2_dc("scot", c3__ud, tty_u->tid_l); u2_noun pax = u2nq(u2_blip, c3__term, tid, u2_nul); u2_proc_plan(u2A, u2k(pax), u2nc(c3__hook, u2_nul)); u2z(pax); } free(tty_u); }
/* _term_io_belt(): send belt. */ static void _term_io_belt(u2_utty* uty_u, u2_noun blb) { u2_noun tid = u2_dc("scot", c3__ud, uty_u->tid_l); u2_noun pax = u2nq(c3__gold, c3__term, tid, u2_nul); u2_reck_plan(u2A, pax, u2nc(c3__belt, blb)); }
/* 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); }
// _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_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); }
/* _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); } } }
/* _tel_opt(): telnet event sucker */ static void _tel_opt(_te_nvt* nvt, telnet_byte opt, _to_evt* evt) { switch (evt->type) { default: break; case TELNET_EV_TELOPT_DATA: { _to_dvt* dv = (_to_dvt*)evt; u2_utel* tel_u; u2_noun pax; u2_noun blu; u2_noun tid; c3_s col_s; c3_s row_s; if ( opt != _T_NAWS ) { return; } c3_assert(0 < telnet_get_userdata(nvt, (void**)&tel_u)); col_s = dv->data[1] | (dv->data[0] << 8); row_s = dv->data[3] | (dv->data[2] << 8); tel_u->uty_t.tat_u.siz.col_l = col_s; tel_u->uty_t.tat_u.siz.row_l = row_s; tid = u2_dc("scot", c3__ud, tel_u->uty_t.tid_l); pax = u2nq(u2_blip, c3__term, tid, u2_nul); blu = u2nc(col_s, row_s); u2_proc_plan(u2A, pax, u2nc(c3__blew, blu)); break; } } }
/* _unix_desk_sync_udon(): apply udon to existing value. */ static u2_noun _unix_desk_sync_udon(u2_noun don, u2_noun old) { return u2_dc("lump", don, old); }
/* u2_lo_soft(): standard soft wrapper. unifies unix and nock errors. ** ** Produces [%$ result] or [%error (list tank)]. */ u2_noun u2_lo_soft(u2_reck* rec_u, c3_w sec_w, u2_funk fun_f, u2_noun arg) { u2_noun hoe, pro, rop; u2_rl_leap(u2_Wire, c3__rock); // 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; }
void _term_listen_cb(uv_stream_t *wax_u, int sas_i) { u2_utel* pty_u = calloc(1, sizeof(*pty_u)); u2_utty* tty_u = &pty_u->uty_t; uv_tcp_init(u2L, &tty_u->wax_u); c3_w ret_w; if ( 0 != (ret_w = uv_accept(wax_u, (uv_stream_t*)&tty_u->wax_u)) ) { uL(fprintf(uH, "term: accept: %s\n", uv_strerror(ret_w))); uv_close((uv_handle_t*)&tty_u->wax_u, NULL); free(tty_u); } else { uv_read_start((uv_stream_t*)&tty_u->wax_u, _term_alloc, _term_read_tn_cb); tty_u->ufo_u.out.clear_y = (const c3_y*)"\033[H\033[J"; tty_u->ufo_u.out.el_y = (const c3_y*)"\033[K"; tty_u->ufo_u.out.ed_y = (const c3_y*)"\033[J"; tty_u->ufo_u.out.bel_y = (const c3_y*)"\007"; tty_u->ufo_u.out.cub1_y = (const c3_y*)"\010"; tty_u->ufo_u.out.cud1_y = (const c3_y*)"\033[B"; tty_u->ufo_u.out.cuu1_y = (const c3_y*)"\033[A"; tty_u->ufo_u.out.cuf1_y = (const c3_y*)"\033[C"; tty_u->ufo_u.inn.kcuu1_y = (const c3_y*)"\033[A"; tty_u->ufo_u.inn.kcud1_y = (const c3_y*)"\033[B"; tty_u->ufo_u.inn.kcuf1_y = (const c3_y*)"\033[C"; tty_u->ufo_u.inn.kcub1_y = (const c3_y*)"\033[D"; tty_u->ufo_u.inn.max_w = strlen("\033[D"); tty_u->fid_i = -1; tty_u->tat_u.mir.lin_w = 0; tty_u->tat_u.mir.len_w = 0; tty_u->tat_u.mir.cus_w = 0; tty_u->tat_u.esc.ape = u2_no; tty_u->tat_u.esc.bra = u2_no; tty_u->tat_u.fut.len_w = 0; tty_u->tat_u.fut.wid_w = 0; tty_u->tat_u.siz.col_l = 80; tty_u->tat_u.siz.row_l = 25; tty_u->tid_l = u2_Host.uty_u->tid_l + 1; tty_u->nex_u = u2_Host.uty_u; u2_Host.uty_u = tty_u; 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); u2_noun pax = u2nq(u2_blip, c3__term, tid, u2_nul); u2_proc_plan(u2A, u2k(pax), u2nc(c3__blew, u2nc(80, 25))); u2_proc_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul)); u2z(pax); } telnet_telopt_enable(pty_u->tel_u, _T_ECHO, TELNET_LOCAL); telnet_telopt_enable(pty_u->tel_u, _T_CTIM, TELNET_LOCAL); telnet_telopt_enable(pty_u->tel_u, _T_NAWS, TELNET_REMOTE); } }