/* u2_term_ef_ctlc(): send ^C on console. */ void u2_term_ef_ctlc(void) { u2_noun pax = u2nq(c3__gold, c3__term, '1', u2_nul); u2_reck_plan(u2A, pax, u2nt(c3__belt, c3__ctl, 'c')); }
/* 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_term_ef_ctlc(): send ^C on console. */ void u2_term_ef_ctlc(void) { u2_noun pax = u2nq(u2_blip, c3__term, '1', u2_nul); u2_proc_plan(u2A, pax, u2nt(c3__belt, c3__ctl, 'c')); }
/* 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_unix_ef_init(): update filesystem for new acquisition. */ void u2_unix_ef_init(u2_noun who) { _unix_hot_gain(u2k(who), u2_yes); u2_reck_plan(u2A, u2nq(u2_blip, c3__sync, u2k(u2A->sen), u2_nul), u2nq(c3__into, who, u2_blip, u2nt(u2_yes, u2nc(0, 0), u2_nul))); }
/* _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)); }
/* _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; }
/* _term_it_save(): save file by path. */ static void _term_it_save(u2_noun pax, u2_noun pad) { c3_c* pax_c; pax = u2nt(c3_s4('.','u','r','b'), c3_s3('p','u','t'), pax); pax_c = _term_it_path(u2_yes, pax); u2_walk_save(pax_c, 0, pad); free(pax_c); }
/* _unix_time_cb(): timer callback. */ static void _unix_time_cb(uv_timer_t* tim_u, c3_i sas_i) { u2_lo_open(); { u2_reck_plan (u2A, u2nt(c3__gold, c3__clay, u2_nul), u2nc(c3__wake, u2_nul)); } u2_lo_shut(u2_no); }
/* _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)); }
/* _unix_time_cb(): timer callback. */ static void _unix_time_cb(uv_timer_t* tim_u) { if ( u2_nul == u2A->roe ) { u2_lo_open(); { u2_reck_plan (u2A, u2nt(u2_blip, c3__clay, u2_nul), u2nc(c3__wake, u2_nul)); } u2_lo_shut(u2_no); } }
/* _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); }
/* logic */ u2_bean // transfer j2_mcx(Pt6, ut, conk)(u2_wire wir_r, u2_noun van, // retain u2_noun sut, // retain u2_noun got) // retain { if ( u2_yes == u2ud(got) ) { return j2_mby(Pt6, face)(wir_r, got, sut); } else switch ( u2h(got) ) { default: return u2_cm_bail(c3__fail); case 0: { return u2k(sut); } case 1: { return j2_mby(Pt6, face) (wir_r, u2h(u2t(got)), j2_mcx(Pt6, ut, conk)(wir_r, van, sut, u2t(u2t(got)))); } case 2: { u2_bean vet = u2_frag(j2_ut_van_vet, van); u2_noun hed, tal, ret; if ( u2_yes == vet ) { u2_noun cel = u2nt(c3__cell, c3__noun, c3__noun); if ( u2_no == j2_mcy(Pt6, ut, nest)(wir_r, van, cel, u2_yes, sut) ) { return u2_bl_bail(wir_r, c3__fail); } u2z(cel); } hed = j2_mcy(Pt6, ut, peek)(wir_r, van, sut, c3__both, 2); tal = j2_mcy(Pt6, ut, peek)(wir_r, van, sut, c3__both, 3); ret = j2_mby(Pt6, cell) (wir_r, j2_mcx(Pt6, ut, conk)(wir_r, van, hed, u2h(u2t(got))), j2_mcx(Pt6, ut, conk)(wir_r, van, tal, u2t(u2t(got)))); u2z(hed); u2z(tal); return ret; } } }
/* _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; } }
/* _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(xun, bur) ) { doz = u2_dc("cost", xun, bur); pax = u2nq(c3__gold, c3__sync, u2k(u2A->sen), u2_nul); fav = u2nq(c3__into, who, syd, u2nt(u2_yes, u2_nul, doz)); u2_reck_plan(u2A, pax, fav); } else { u2z(who); u2z(syd); u2z(xun); u2z(bur); } }
/* _unix_desk_sync_ergo(): sync desk changes to unix. */ static void _unix_desk_sync_ergo(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 = c3_malloc(sizeof(u2_udir)); xun = u2nt(0, u2_nul, u2_nul); _unix_dir_forge(*dir_u, &(hot_u->dir_u), u2k(syd)); } else { xun = _unix_dir_ankh(*dir_u); } { u2_noun bur = _unix_desk_peek(hox, syd, lok); if ( u2_no == u2_sing(xun, bur) ) { u2_noun doz = u2_dc("cost", bur, xun); _unix_desk_sync_soba(*dir_u, doz); } else { u2z(xun); u2z(bur); } } }
/* _term_io_suck_char(): process a single character. */ static void _term_io_suck_char(u2_utty* uty_u, c3_y cay_y) { u2_utat* tat_u = &uty_u->tat_u; // uL(fprintf(uH, "suck-char %x\n", cay_y)); if ( u2_yes == tat_u->esc.ape ) { if ( u2_yes == tat_u->esc.bra ) { switch ( cay_y ) { default: { _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y); break; } case 'A': _term_io_belt(uty_u, u2nc(c3__aro, 'u')); break; case 'B': _term_io_belt(uty_u, u2nc(c3__aro, 'd')); break; case 'C': _term_io_belt(uty_u, u2nc(c3__aro, 'r')); break; case 'D': _term_io_belt(uty_u, u2nc(c3__aro, 'l')); break; } tat_u->esc.ape = tat_u->esc.bra = u2_no; } else { if ( (cay_y >= 'a') && (cay_y <= 'z') ) { tat_u->esc.ape = u2_no; _term_io_belt(uty_u, u2nc(c3__met, cay_y)); } else if ( ('[' == cay_y) || ('O' == cay_y) ) { tat_u->esc.bra = u2_yes; } else { tat_u->esc.ape = u2_no; _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y); } } } else if ( 0 != tat_u->fut.wid_w ) { tat_u->fut.syb_y[tat_u->fut.len_w++] = cay_y; 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); u2_noun wug; // uL(fprintf(uH, "muck-utf8 len %d\n", tat_u->fut.len_w)); // uL(fprintf(uH, "muck-utf8 %x\n", huv)); wug = u2_do("turf", huv); // uL(fprintf(uH, "muck-utf32 %x\n", tat_u->fut.len_w)); tat_u->fut.len_w = tat_u->fut.wid_w = 0; _term_io_belt(uty_u, u2nt(c3__txt, wug, u2_nul)); } } else { if ( (cay_y >= 32) && (cay_y < 127) ) { _term_io_belt(uty_u, u2nt(c3__txt, cay_y, u2_nul)); } else if ( 0 == cay_y ) { _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y); } else if ( 8 == cay_y || 127 == cay_y ) { _term_io_belt(uty_u, u2nc(c3__bac, u2_nul)); } else if ( 13 == cay_y ) { _term_io_belt(uty_u, u2nc(c3__ret, u2_nul)); } else if ( cay_y <= 26 ) { _term_io_belt(uty_u, u2nc(c3__ctl, ('a' + (cay_y - 1)))); } else if ( 27 == cay_y ) { tat_u->esc.ape = u2_yes; } else if ( cay_y >= 128 ) { tat_u->fut.len_w = 1; tat_u->fut.syb_y[0] = cay_y; if ( cay_y <= 224 ) { tat_u->fut.wid_w = 2; } else if ( cay_y <= 240 ) { tat_u->fut.wid_w = 3; } else tat_u->fut.wid_w = 4; } } }
/* _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)); }
/* _walk_in(): inner loop of _walk(), producing map. */ static u2_noun _walk_in(u2_reck* rec_u, const c3_c* dir_c, c3_w len_w) { DIR* dir_d = opendir(dir_c); u2_noun map = u2_nul; if ( !dir_d ) { return u2_nul; } else while ( 1 ) { struct dirent ent_n; struct dirent* out_n; if ( readdir_r(dir_d, &ent_n, &out_n) != 0 ) { uL(fprintf(uH, "%s: %s\n", dir_c, strerror(errno))); break; } else if ( !out_n ) { break; } else if ( !strcmp(out_n->d_name, ".") || !strcmp(out_n->d_name, "..") || ('~' == out_n->d_name[0]) || ('.' == out_n->d_name[0]) ) // XX restricts some spans { continue; } else { c3_c* fil_c = out_n->d_name; c3_w lef_w = len_w + 1 + strlen(fil_c); c3_c* pat_c = malloc(lef_w + 1); struct stat buf_b; strcpy(pat_c, dir_c); pat_c[len_w] = '/'; strcpy(pat_c + len_w + 1, fil_c); if ( 0 != stat(pat_c, &buf_b) ) { free(pat_c); } else { u2_noun tim = c3_stat_mtime(&buf_b); if ( !S_ISDIR(buf_b.st_mode) ) { c3_c* dot_c = strrchr(fil_c, '.'); c3_c* nam_c = strdup(fil_c); c3_c* ext_c = strdup(dot_c + 1); nam_c[dot_c - fil_c] = 0; { u2_noun nam = u2_ci_string(nam_c); u2_noun ext = u2_ci_string(ext_c); u2_noun get = u2_ckd_by_get(u2k(map), u2k(nam)); u2_noun dat = u2_walk_load(pat_c); u2_noun hax; if ( !strcmp("noun", ext_c) ) { dat = u2_cke_cue(dat); } hax = u2_do("sham", u2k(dat)); if ( u2_none == get ) { get = u2_nul; } get = u2_ckd_by_put(get, ext, u2nt(u2_yes, hax, dat)); map = u2_ckd_by_put(map, nam, u2nc(u2_no, get)); } free(nam_c); free(ext_c); } else { u2_noun dir = _walk_in(rec_u, pat_c, lef_w); if ( u2_nul != dir ) { map = u2_ckd_by_put (map, u2_ci_string(fil_c), u2nc(u2_no, dir)); } else u2z(tim); } free(pat_c); } } } closedir(dir_d); return map; }