Esempio n. 1
0
File: nock.c Progetto: sillsm/urbit
/* _nock_pray_cool(): load from namespace, in kernel mode.
*/
static u2_noun
_nock_pray_cool(u2_noun gof)                                      //  transfer
{
    //  This should just exit - but for various reasons, all historical,
    //  we could be actually minking here.  Therefore we have to respect
    //  the mink if it exists.
    //
    u2_noun lad = u2_hevn_at(lad);

    if ( u2_nul == lad ) {
        return u2_cm_bowl(u2nc(c3__need, u2nc(gof, u2_nul)));
    }
    else {
        u2_kode pon = 0;
        u2_noun mog = _nock_pray_mool(gof, &pon);

        if ( 0 == pon ) {
            return mog;
        }
        else if ( 1 == pon ) {
            return u2_cm_bowl(u2nc(c3__need, mog));
        }
        else if ( 2 == pon ) {
            return u2_cm_bowl(u2nc(c3__exit, mog));
        }
        else {
            c3_assert(0);
            return 0;
        }
    }
}
Esempio n. 2
0
  static u2_noun                                                  //  produce
  _og_list(u2_wire wir_r,
           u2_noun a,                                             //  retain
           u2_noun b,                                             //  retain
           u2_noun c)                                             //  retain
  {
    u2_noun l = u2_nul;

    if ( !u2_fly_is_cat(b) ) {
      return u2_bl_bail(wir_r, c3__fail);
    }
    while ( 0 != b ) {
      u2_noun x = j2_mbc(Pt3, mix)(wir_r, a, c);
      u2_noun y = j2_mbc(Pt3, mix)(wir_r, b, x);
      u2_noun d = j2_mbc(Pt5, shas)(wir_r, c3_s4('o','g','-','b'), y);
      u2_noun m;

      u2z(x); u2z(y);

      if ( b < 256 ) {
        u2_noun e = j2_mbc(Pt3, end)(wir_r, 0, b, d);
        
        u2z(d);
        m = u2nc(b, e);
        b = 0;
      } else {
        m = u2nc(256, d);
        c = d;

        b -= 256;
      }
      l = u2nc(m, l);
    }
    return u2_ckb_flop(l);
  }
Esempio n. 3
0
/* u2_term_ef_boil(): initial effects for loaded servers.
*/
void
u2_term_ef_boil(c3_l ono_l)
{
  if ( ono_l ) {
    u2_noun tid_l;

    for ( tid_l = 2; tid_l <= ono_l; tid_l++ ) {
      u2_noun tin = u2_dc("scot", c3__ud, tid_l);
      u2_noun pax = u2nq(c3__gold, c3__term, tin, u2_nul);
      u2_noun hud = u2nc(c3__wipe, u2_nul);

      u2_reck_plan(u2A, pax, hud);
    }
  }

  {
    u2_noun pax = u2nq(c3__gold, c3__term, '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(1)));
    u2_reck_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul));

    u2z(pax);
  }
}
Esempio n. 4
0
File: nock.c Progetto: sillsm/urbit
/* u2_cn_moch(): blind mink with empty fly.
*/
u2_noun
u2_cn_moch(u2_noun bus,
           u2_noun fol)
{
    u2_noun fly = u2nc(u2nc(0, 0), u2nc(1, 0));

    return u2_cn_mink(bus, fol, fly);
}
Esempio n. 5
0
/* 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);
}
Esempio n. 6
0
/* _http_heds_to_list(): C headers to list.
*/
static u2_noun
_http_heds_to_list(u2_hhed* hed_u)
{
  if ( 0 == hed_u ) {
    return u2_nul;
  } else {
    return u2nc(u2nc(u2_ci_string(hed_u->nam_c),
                     hed_u->val_c ? u2_ci_string(hed_u->val_c) : u2_nul),
                _http_heds_to_list(hed_u->nex_u));
  }
}
/* 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);
  }
}
Esempio n. 8
0
/* _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_ci_tape(): from a C string, to a list of bytes.
*/
u2_atom
u2_ci_tape(const c3_c* txt_c)
{
  if ( !*txt_c ) {
    return u2_nul;
  } else return u2nc(*txt_c, u2_ci_tape(txt_c + 1));
}
/* u2_cf_list(): list all the files in directory `pas`.  List of cask.
*/
u2_noun
u2_cf_list(u2_noun pas)
{
  c3_c* pas_c = u2_cr_string(pas);

  u2z(pas);
  {
    u2_noun lis = u2_nul;
    DIR *dir_d = opendir(pas_c);

    if ( !dir_d ) {
      free(pas_c);
      return u2_nul;
    }
    else {
      while ( 1 ) {
        struct dirent ent_n;
        struct dirent *out_n;

        if ( readdir_r(dir_d, &ent_n, &out_n) != 0 ) {
          perror(pas_c);
          return u2_cm_bail(c3__fail);
        }
        else if ( !out_n ) {
          break;
        }
        else lis = u2nc(u2_ci_string(out_n->d_name), lis);
      }

      free(pas_c);
      return lis;
    }
  }
}
Esempio n. 11
0
/* _http_bods_to_octs: translate body into octet-stream noun.
*/
static u2_noun
_http_bods_to_octs(u2_hbod* bod_u)
{
  c3_w    len_w;
  c3_y*   buf_y;
  u2_noun cos;

  {
    u2_hbod* bid_u;

    len_w = 0;
    for ( bid_u = bod_u; bid_u; bid_u = bid_u->nex_u ) {
      len_w += bid_u->len_w;
    }
  }
  buf_y = c3_malloc(len_w);

  {
    c3_y* ptr_y = buf_y;

    while ( bod_u ) {
      memcpy(ptr_y, bod_u->hun_y, bod_u->len_w);
      ptr_y += bod_u->len_w;
      bod_u = bod_u->nex_u;
    }
  }
  cos = u2_ci_bytes(len_w, buf_y);
  free(buf_y);
  return u2nc(len_w, cos);
}
Esempio n. 12
0
void
u2_http_ef_bake(void)
{
  u2_noun pax = u2nq(c3__gold, c3__http, u2k(u2A->sen), u2_nul);

  u2_reck_plan(u2A, pax, u2nc(c3__born, u2_nul));
}
Esempio n. 13
0
/* u2_term_get_blew(): return window size [columns rows].
*/
u2_noun
u2_term_get_blew(c3_l tid_l)
{
  u2_utty*       uty_u = _term_ef_get(tid_l);
  c3_l           col_l, row_l;

#if 1
  struct winsize siz_u;
  if ( uty_u && (0 == ioctl(uty_u->fid_i, TIOCGWINSZ, &siz_u)) ) {
    col_l = siz_u.ws_col;
    row_l = siz_u.ws_row;
  } else {
    col_l = 80;
    row_l = 24;
  }
#else
  {
    c3_i col_i, row_i;

    uv_tty_get_winsize(&uty_u->wax_u, &col_i, &row_i);
    col_l = col_i;
    row_l = row_i;
  }
#endif
  if ( uty_u ) {
    uty_u->tat_u.siz.col_l = col_l;
    uty_u->tat_u.siz.row_l = row_l;
  }

  return u2nc(col_l, row_l);
}
Esempio n. 14
0
File: unix.c Progetto: esaul/urbit
/* _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);
  }
}
Esempio n. 15
0
/* u2_term_ef_winc(): window change.  Just console right now.
*/
void
u2_term_ef_winc(void)
{
  u2_noun pax = u2nq(c3__gold, c3__term, '1', u2_nul);

  u2_reck_plan(u2A, pax, u2nc(c3__blew, u2_term_get_blew(1)));
}
/* u2_term_ef_winc(): window change.  Just console right now.
*/
void
u2_term_ef_winc(void)
{
  u2_noun pax = u2nq(u2_blip, c3__term, '1', u2_nul);

  u2_proc_plan(u2A, pax, u2nc(c3__blew, u2_term_get_blew(1)));
}
Esempio n. 17
0
File: nock.c Progetto: sillsm/urbit
/* u2_cn_mink(): logical virtual nock.
*/
u2_noun
u2_cn_mink(u2_noun bus,
           u2_noun fol,
           u2_noun fly)
{
    u2_noun res;
    u2_bean bit;

    bit = u2_tx_sys_bit(u2_Wire, u2_no);
    c3_assert(bit == u2_yes);
    bit = u2_tx_glu_bit(u2_Wire, u2_yes);

    {
        u2_noun lad;

        lad = u2_hevn_at(lad);
        u2_hevn_at(lad) = u2nc(fly, u2k(lad));
        {
            res = _nock_moog(bus, fol);
        }
        // c3_assert(lad == u2ft(u2_hevn_at(lad)));

        u2z(u2_hevn_at(lad));
        u2_hevn_at(lad) = lad;
    }

    u2_tx_sys_bit(u2_Wire, u2_yes);
    u2_tx_glu_bit(u2_Wire, bit);

    return res;
}
/* _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);
}
Esempio n. 19
0
/* 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(c3__gold, c3__sync, u2k(u2A->sen), u2_nul),
                    u2nq(c3__into, who, u2_blip, u2nc(u2_yes, u2_nul)));
}
Esempio n. 20
0
/* _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));
}
Esempio n. 21
0
File: nock.c Progetto: ngvrnd/urbit
/* 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);
  }
}
Esempio n. 22
0
/* _unix_desk_peek(): peek for arch.
*/
static u2_noun
_unix_desk_peek(u2_noun who, 
                u2_noun hox, 
                u2_noun syd, 
                u2_noun lok)
{
  u2_noun cay;

  cay = u2_reck_prick
    (u2A, who, u2nc(c3_s2('c','z'), u2nq(hox, syd, lok, u2_nul)));

  if ( u2_nul == cay ) {
    return u2nc(u2_no, u2_nul);
  } else {
    u2_noun arc = u2k(u2t(cay));

    u2z(cay); return arc;
  }
}
Esempio n. 23
0
/* _http_request_dead(): kill http request.
*/
static void
_http_request_dead(u2_hreq* req_u)
{
  u2_noun pox = _http_pox_to_noun(req_u->hon_u->htp_u->sev_l,
                                  req_u->hon_u->coq_l,
                                  req_u->seq_l);

  u2_reck_plan(u2_Host.arv_u,
               pox,
               u2nc(c3__thud, u2_nul));
}
Esempio n. 24
0
/* _term_it_save(): save file by path.
*/
static void
_term_it_save(u2_noun pax, u2_noun pad)
{
  c3_c* pax_c;

  pax = u2nc(c3_s3('p','u','t'), pax);
  pax_c = _term_it_path(u2_yes, pax);

  u2_walk_save(pax_c, 0, pad);
  free(pax_c);
}
Esempio n. 25
0
//  _lo_bench_noop(): benchmark no-op events.
//
static void
_lo_bench_noop(c3_w num_w)
{
  c3_w i_w;

  for ( i_w = 0; i_w < num_w; i_w++ ) {
    u2_reck_plan(u2A, u2nq(c3__gold, c3__term, 1, u2_nul),
                      u2nc(c3__noop, u2_nul));
  }

  u2_raft_work(u2A);
}
Esempio n. 26
0
/* _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);
}
Esempio n. 27
0
File: nock.c Progetto: sillsm/urbit
/* _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;
                }
            }
        }
    }
}
Esempio n. 28
0
File: nock.c Progetto: sillsm/urbit
/* _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;
}
Esempio n. 29
0
File: unix.c Progetto: esaul/urbit
/* _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);
  }
}
/* _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;
    }
  }
}