Beispiel #1
0
  static u3_noun
  _play_core(u3_noun pac,
             u3_noun con)
  {
    if ( (c3__void == pac) ) {
      u3z(con);

      return c3__void;
    } else {
      return u3nt(c3__core, pac, con);
    }
  }
Beispiel #2
0
Datei: term.c Projekt: josl/urbit
/* u3_term_ef_bake(): initial effects for new terminal.
*/
void
u3_term_ef_bake(u3_noun fav)
{
  u3_noun pax = u3nq(u3_blip, c3__term, '1', u3_nul);

  u3v_plan(u3k(pax), u3nc(c3__boot, fav));
  // u3v_plan(u3k(pax), u3nq(c3__flow, c3__seat, c3__dojo, u3_nul));
  u3v_plan(u3k(pax), u3nc(c3__blew, u3_term_get_blew(1)));
  u3v_plan(u3k(pax), u3nc(c3__hail, u3_nul));

  u3z(pax);
}
Beispiel #3
0
  static u3_noun
  _mint_corn(
             u3_noun van,
             u3_noun sut,
             u3_noun gen)
  {
    u3_noun mil = _mint_in(van, sut, c3__noun, gen);
    u3_noun fol = u3k(u3t(mil));

    u3z(mil);
    return fol;
  }
Beispiel #4
0
/* _unix_write_file_hard(): write to a file, overwriting what's there
*/
static c3_w
_unix_write_file_hard(c3_c* pax_c, u3_noun mim)
{
    c3_i  fid_i = open(pax_c, O_WRONLY | O_CREAT | O_TRUNC, 0666);
    c3_w  len_w, rit_w, siz_w, mug_w = 0;
    c3_y* dat_y;

    u3_noun dat = u3t(u3t(mim));

    if ( fid_i < 0 ) {
        uL(fprintf(uH, "error opening %s for writing: %s\r\n",
                   pax_c, strerror(errno)));
        u3z(mim);
        return 0;
    }

    siz_w = u3h(u3t(mim));
    len_w = u3r_met(3, dat);
    dat_y = c3_malloc(siz_w);
    memset(dat_y, 0, siz_w);

    u3r_bytes(0, len_w, dat_y, dat);
    u3z(mim);

    rit_w = write(fid_i, dat_y, siz_w);

    if ( rit_w != siz_w ) {
        uL(fprintf(uH, "error writing %s: %s\r\n",
                   pax_c, strerror(errno)));
        mug_w = 0;
    }
    else {
        mug_w = u3r_mug_bytes(dat_y, len_w);
    }

    close(fid_i);
    free(dat_y);

    return mug_w;
}
Beispiel #5
0
Datei: peg.c Projekt: aulux/urbit
/* functions
*/
  u3_noun
  u3qc_peg(
                   u3_atom a,
                   u3_atom b)
  {
    u3_atom c, d, e, f, g, h;

    c = u3r_met(0, b);
    d = u3qa_dec(c);
    e = u3qc_lsh(0, d, 1);
    f = u3qa_sub(b, e);
    g = u3qc_lsh(0, d, a);
    h = u3qa_add(f, g);

    u3z(c);
    u3z(d);
    u3z(e);
    u3z(f);
    u3z(g);

    return h;
  }
Beispiel #6
0
  static u3_noun
  _mint_cond(
             u3_noun pex,
             u3_noun yom,
             u3_noun woq)
  {
    if ( 1 == u3h(pex) ) {
      if ( 0 == u3t(pex) ) {
        u3z(pex);
        u3z(woq);

        return yom;
      }
      else if ( 1 == u3t(pex) ) {
        u3z(pex);
        u3z(yom);

        return woq;
      }
    }
    return u3nq(6, pex, yom, woq);
  }
Beispiel #7
0
/* _unix_get_mount_point(): retrieve or create mount point
*/
static u3_umon*
_unix_get_mount_point(u3_noun mon)
{
    if ( c3n == u3ud(mon) ) {
        c3_assert(!"mount point must be an atom");
        u3z(mon);
        return NULL;
    }

    c3_c* nam_c = u3r_string(mon);
    u3_umon* mon_u;

    for ( mon_u = u3_Host.unx_u.mon_u;
            mon_u && 0 != strcmp(nam_c, mon_u->nam_c);
            mon_u = mon_u->nex_u )
    {
    }

    if ( !mon_u ) {
        mon_u = malloc(sizeof(u3_umon));
        mon_u->nam_c = nam_c;
        mon_u->dir_u.dir = c3y;
        mon_u->dir_u.dry = c3n;
        mon_u->dir_u.pax_c = strdup(u3_Host.dir_c);
        mon_u->dir_u.par_u = NULL;
        mon_u->dir_u.nex_u = NULL;
        mon_u->dir_u.kid_u = NULL;
        mon_u->nex_u = u3_Host.unx_u.mon_u;
        u3_Host.unx_u.mon_u = mon_u;

    }
    else {
        free(nam_c);
    }

    u3z(mon);

    return mon_u;
}
Beispiel #8
0
/* _sist_staf(): try to load passcode by mug from home directory.
*/
static u3_noun
_sist_staf(c3_l key_l)
{
  c3_c    ful_c[2048];
  c3_c*   hom_c = u3_Host.dir_c;
  u3_noun gum   = u3dc("scot", 'p', key_l);
  c3_c*   gum_c = u3r_string(gum);
  u3_noun txt;

  snprintf(ful_c, 2048, "%s/.urb/code.%s", hom_c, gum_c);
  free(gum_c);
  u3z(gum);
  txt = u3_walk_safe(ful_c);

  if ( 0 == txt ) {
    uL(fprintf(uH, "staf: no passcode %s\n", ful_c));
    return 0;
  }
  else {
    // c3_c* txt_c = u3r_string(txt);
    u3_noun say = u3do("slay", txt);
    u3_noun pas;


    if ( (u3_nul == say) ||
         (u3_blip != u3h(u3t(say))) ||
         ('p' != u3h(u3t(u3t(say)))) )
    {
      uL(fprintf(uH, "staf: %s is corrupt\n", ful_c));
      u3z(say);
      return 0;
    }
    uL(fprintf(uH, "loaded passcode from %s\n", ful_c));
    pas = u3k(u3t(u3t(u3t(say))));

    u3z(say);
    return pas;
  }
}
Beispiel #9
0
  static u3_noun
  _fuse_repo(u3_noun van,
             u3_noun sut,
             u3_noun ref,
             u3_noun bix)
  {
    u3_noun rep = u3qfu_repo(van, sut);
    u3_noun ret = _fuse_in(van, rep, ref, bix);

    if ( c3y == u3r_sing(ret, rep) ) {
      if ( c3__void == rep ) {
        return c3__void;
      } else {
        u3z(rep);
        u3z(ret);
        return u3k(sut);
      }
    } else {
      u3z(rep);
      return ret;
    }
  }
Beispiel #10
0
/* _sist_sing(): replay ovum from the past, time already set.
*/
static void
_sist_sing(u3_noun ovo)
{
  u3_noun gon = u3m_soft(0, u3v_poke, u3k(ovo));

  if ( u3_blip != u3h(gon) ) {
    _sist_suck(ovo, gon);
  }
  else {
    u3_noun vir = u3k(u3h(u3t(gon)));
    u3_noun cor = u3k(u3t(u3t(gon)));
    u3_noun nug;

    u3z(gon);
    nug = u3v_nick(vir, cor);

    if ( u3_blip != u3h(nug) ) {
      _sist_suck(ovo, nug);
    }
    else {
      vir = u3h(u3t(nug));
      cor = u3k(u3t(u3t(nug)));

      while ( u3_nul != vir ) {
        u3_noun fex = u3h(vir);
        u3_noun fav = u3t(fex);

        if ( (c3__init == u3h(fav)) || (c3__inuk == u3h(fav)) ) {
          u3A->own = u3nc(u3k(u3t(fav)), u3A->own);
        }
        vir = u3t(vir);
      }
      u3z(nug);
      u3z(u3A->roc);
      u3A->roc = cor;
    }
    u3z(ovo);
  }
}
Beispiel #11
0
/* _term_it_show_wide(): show wide text, retaining.
*/
static void
_term_it_show_wide(u3_utty* uty_u, c3_w len_w, c3_w* txt_w)
{
  u3_noun wad   = u3i_words(len_w, txt_w);
  u3_noun txt   = u3do("tuft", wad);
  c3_c*   txt_c = u3r_string(txt);

  _term_it_write_str(uty_u, txt_c);
  free(txt_c);
  u3z(txt);

  uty_u->tat_u.mir.cus_w += len_w;
}
Beispiel #12
0
/* logic
*/
  static u3_noun
  _cqfu_conk(u3_noun van,
             u3_noun sut,
             u3_noun got)
  {
    if ( c3y == u3ud(got) ) {
      u3_noun ret = u3qf_face(u3k(got), sut);

      return ret;
    }
    else switch ( u3h(got) ) {
      default: return u3m_bail(c3__fail);

      case 0: {
        return u3k(sut);
      }
      case 1: {
        u3_noun c*k = _cqfu_conk(van, sut, u3t(u3t(got)));
        u3_noun nux = u3k(u3h(u3t(got)));
        u3_noun ret = u3qf_face(nux, c*k);

        u3z(nux);
        u3z(c*k);
        return ret;
      }
      case 2: {
        u3_noun vet = u3r_at(u3qfu_van_vet, van);
        u3_noun hed, tal, deh, lat, ret;

        if ( c3y == vet ) {
          u3_noun cel = u3nt(c3__cell, c3__noun, c3__noun);

          if ( c3n == u3qfu_nest(van, cel, c3y, sut) ) {
            return u3m_bail(c3__fail);
          }
          u3z(cel);
        }
        hed = u3qfu_peek(van, sut, c3__both, 2);
        tal = u3qfu_peek(van, sut, c3__both, 3);
        deh = _cqfu_conk(van, hed, u3h(u3t(got)));
        lat = _cqfu_conk(van, tal, u3t(u3t(got)));

        ret = u3qf_cell(deh, lat);

        u3z(lat);
        u3z(deh);
        u3z(tal);
        u3z(hed);

        return ret;
      }
    }
  }
Beispiel #13
0
/* u3_term_ef_boil(): initial effects for loaded servers.
*/
void
u3_term_ef_boil(void)
{
  {
    u3_noun pax = u3nq(u3_blip, c3__term, '1', u3_nul);

    //  u3v_plan(u3k(pax), u3nc(c3__init, u3k(u3h(u3A->own))));
    u3v_plan(u3k(pax), u3nc(c3__harm, u3_nul));
    u3v_plan(u3k(pax), u3nc(c3__blew, u3_term_get_blew(1)));
    u3v_plan(u3k(pax), u3nc(c3__hail, u3_nul));

    u3z(pax);
  }
}
Beispiel #14
0
/* _unix_free_mount_point(): free mount point
 *
 * this process needs to happen in a very careful order.  in particular,
 * we must recurse before we get to the callback, so that libuv does all
 * the child directories before it does us.
 *
 * tread carefully
*/
static void
_unix_free_mount_point(u3_umon* mon_u)
{
    u3_unod* nod_u;
    for ( nod_u = mon_u->dir_u.kid_u; nod_u; ) {
        u3_unod* nex_u = nod_u->nex_u;
        u3z(_unix_free_node(nod_u));
        nod_u = nex_u;
    }

    free(mon_u->dir_u.pax_c);
    free(mon_u->nam_c);
    free(mon_u);
}
Beispiel #15
0
/* logic
*/
  u3_noun
  _cqfu_busk(u3_noun van,
             u3_noun sut,
             u3_noun cog,
             u3_noun hyp)
  {
    u3_noun sep = u3qfu_seep(van, sut, c3__both, hyp);
    u3_noun bid = u3nt(u3k(cog), u3k(hyp), sep);
    u3_noun ret = u3qf_bull(bid, sut);

    u3z(bid);

    return ret;
  }
Beispiel #16
0
u3_noun 
u3z_save_4(c3_m fun, 
             u3_noun one, 
             u3_noun two, 
             u3_noun tri, 
             u3_noun qua, 
             u3_noun val)
{
  u3_noun key = u3nc(fun, u3nq(u3k(one), u3k(two), u3k(tri), u3k(qua)));

  u3h_put(u3R->cax.har_p, key, u3k(val));
  u3z(key);
  return val;
}
Beispiel #17
0
/* functions
*/
  u3_noun
  u3qc_mas(u3_atom a)
  {
    c3_w b_w;
    u3_atom c, d, e, f;

    b_w = u3r_met(0, a);
    if ( b_w < 2 ) {
      return u3m_bail(c3__exit);
    }
    else {
      c = u3qc_bex((b_w - 1));
      d = u3qc_bex((b_w - 2));
      e = u3qa_sub(a, c);
      f = u3qc_con(e, d);

      u3z(c);
      u3z(d);
      u3z(e);

      return f;
    }
  }
Beispiel #18
0
/* u3_term_ef_ticket(): initial effects for new ticket.
*/
void
u3_term_ef_ticket(c3_c* who_c, c3_c* tic_c)
{
  u3_noun pax = u3nq(u3_blip, c3__term, '1', u3_nul);
  u3_noun who, tic;
  u3_noun whu, tuc; 
  
  whu = u3dc("slaw", 'p', u3i_string(who_c));
  if ( u3_nul == whu ) {
    fprintf(stderr, "ticket: invalid planet '%s'\r\n", who_c);
    exit(1);
  }
  else { who = u3k(u3t(whu)); u3z(whu); }

  tuc = u3dc("slaw", 'p', u3i_string(tic_c));
  if ( u3_nul == tuc ) {
    fprintf(stderr, "ticket: invalid secret '%s'\r\n", tic_c);
    exit(1);
  }
  else { tic = u3k(u3t(tuc)); u3z(tuc); }

  u3v_plan(pax, u3nt(c3__tick, who, tic));
}
Beispiel #19
0
/* u3_term_ef_blit(): send %blit list to specific terminal.
*/
void
u3_term_ef_blit(c3_l     tid_l,
                u3_noun  bls)
{
  u3_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", u3_Host.uty_u));

    u3z(bls); return;
  }

  {
    u3_noun bis = bls;

    while ( c3y == u3du(bis) ) {
      _term_ef_blit(uty_u, u3k(u3h(bis)));
      bis = u3t(bis);
    }
    u3z(bls);
  }
}
Beispiel #20
0
  static u3_noun
  _mint_grow(
             u3_noun van,
             u3_noun sut,
             u3_noun gol,
             u3_atom mel,
             u3_noun ruf,
             u3_noun dab)
  {
    u3_noun dan = _mint_in(van, sut, c3__noun, ruf);
    u3_noun p_dan = u3h(dan);
    u3_noun q_dan = u3t(dan);
    u3_noun toc = _mint_core
      (u3k(p_dan),
              u3nt(c3__gold,
                           u3k(p_dan),
                           u3nc(u3_nul, u3k(dab))));
    u3_noun dez = _mint_bake(van, toc, dab);
    u3_noun zod = u3nc(1, dez);
    u3_noun cot = _mint_core
      (u3k(p_dan),
              u3nt(mel,
                           u3k(p_dan),
                           u3nc(u3k(dez),
                                        u3k(dab))));
    u3_noun ret = u3nc
      (
       _mint_nice(van, gol, cot),
       u3qf_cons(zod, q_dan));

    u3z(zod);
    u3z(toc);
    u3z(dan);

    return ret;
  }
Beispiel #21
0
/* u3n_slam_on(): produce (gat sam).
*/
u3_noun
u3n_slam_on(u3_noun gat, u3_noun sam)
{
  u3_noun cor = u3nc(u3k(u3h(gat)), u3nc(sam, u3k(u3t(u3t(gat)))));

#if 0
  if ( &u3H->rod_u == u3R ) {
    if ( exc_w == 1 ) {
      c3_assert(0);
    } 
    exc_w++;
  }
#endif
  u3z(gat);
  return u3n_kick_on(cor);
}
Beispiel #22
0
/* _sist_cask(): ask for a passcode.
*/
static u3_noun
_sist_cask(c3_c* dir_c, u3_noun nun)
{
  c3_c   paw_c[60];
  u3_noun key;

  uH;
  while ( 1 ) {
    printf("passcode for %s%s? ~", dir_c, (c3y == nun) ? " [none]" : "");

    paw_c[0] = 0;
    c3_fpurge(stdin);
    fgets(paw_c, 59, stdin);

    if ( '\n' == paw_c[0] ) {
      if ( c3y == nun ) {
        key = 0; break;
      }
      else {
        continue;
      }
    }
    else {
      c3_c* say_c = c3_malloc(strlen(paw_c) + 2);
      u3_noun say;

      say_c[0] = '~';
      say_c[1] = 0;
      strncat(say_c, paw_c, strlen(paw_c) - 1);

      say = u3do("slay", u3i_string(say_c));
      if ( (u3_nul == say) ||
           (u3_blip != u3h(u3t(say))) ||
           ('p' != u3h(u3t(u3t(say)))) )
      {
        printf("invalid passcode\n");
        continue;
      }
      key = u3k(u3t(u3t(u3t(say))));

      u3z(say);
      break;
    }
  }
  uL(0);
  return key;
}
Beispiel #23
0
  //  compute lcs
  //
  static void
  _loss(u3_loss* loc_u)
  {
    while ( u3_nul != loc_u->hel ) {
      u3_noun i_hel = u3h(loc_u->hel);
      u3_noun guy   = u3kdb_get(u3k(loc_u->sev), u3k(i_hel));

      if ( u3_none != guy ) {
        u3_noun gay = u3kb_flop(guy);

        _merg(loc_u, 0, gay);
        u3z(gay);
      }

      loc_u->hel = u3t(loc_u->hel);
    }
  }
Beispiel #24
0
  //  apply
  //
  static void
  _lune(u3_loss* loc_u,
        c3_w     inx_w,
        c3_w     goy_w)
  {
    u3_noun kad;

    kad = u3nc(u3i_words(1, &goy_w),
               (inx_w == 0) ? u3_nul
                            : u3k(loc_u->kad[inx_w - 1]));
    if ( loc_u->kct_w == inx_w ) {
      c3_assert(loc_u->kct_w < (1 << 31));
      loc_u->kct_w++;
    } else {
      u3z(loc_u->kad[inx_w]);
    }
    loc_u->kad[inx_w] = kad;
  }
Beispiel #25
0
/* _term_it_path(): path for console file.
*/
static c3_c*
_term_it_path(u3_noun fyl, u3_noun pax)
{
  c3_w len_w;
  c3_c *pas_c;

  //  measure
  //
  len_w = strlen(u3_Host.dir_c);
  {
    u3_noun wiz = pax;

    while ( u3_nul != wiz ) {
      len_w += (1 + u3r_met(3, u3h(wiz)));
      wiz = u3t(wiz);
    }
  }

  //  cut
  //
  pas_c = c3_malloc(len_w + 1);
  strncpy(pas_c, u3_Host.dir_c, len_w);
  pas_c[len_w] = '\0';
  {
    u3_noun wiz   = pax;
    c3_c*   waq_c = (pas_c + strlen(pas_c));

    while ( u3_nul != wiz ) {
      c3_w tis_w = u3r_met(3, u3h(wiz));

      if ( (c3y == fyl) && (u3_nul == u3t(wiz)) ) {
        *waq_c++ = '.';
      } else *waq_c++ = '/';

      u3r_bytes(0, tis_w, (c3_y*)waq_c, u3h(wiz));
      waq_c += tis_w;

      wiz = u3t(wiz);
    }
    *waq_c = 0;
  }
  u3z(pax);
  return pas_c;
}
Beispiel #26
0
/* _unix_create_dir(): create unix directory and watch it
*/
static void
_unix_create_dir(u3_udir* dir_u, u3_udir* par_u, u3_noun nam)
{
    c3_c* nam_c = u3r_string(nam);
    c3_w  nam_w = strlen(nam_c);
    c3_w  pax_w = strlen(par_u->pax_c);
    c3_c* pax_c = c3_malloc(pax_w + 1 + nam_w + 1);

    strncpy(pax_c, par_u->pax_c, pax_w);
    pax_c[pax_w] = '/';
    strncpy(pax_c + pax_w + 1, nam_c, nam_w);
    pax_c[pax_w + 1 + nam_w] = '\0';

    free(nam_c);
    u3z(nam);

    _unix_mkdir(pax_c);
    _unix_watch_dir(dir_u, par_u, pax_c);
}
Beispiel #27
0
  static u3_noun
  _mint_coke(
             u3_noun nug)
  {
    u3_atom axe;

    if ( 0 == u3h(nug) ) {
      axe = u3t(nug);
    } else if ( 10 == u3h(nug) ) {
      u3_noun xin = u3k(u3t(u3t(nug)));

      axe = _mint_coke(xin);
    }
    else {
      return u3m_error("mint-coke");
    }
    u3z(nug);
    return axe;
  }
Beispiel #28
0
/* comp
*/
  u3_noun
  _cqe_comp_fun(u3_noun raq,
                u3_noun vex,
                u3_noun sab)
  {
    u3_noun p_vex, q_vex;

    u3x_cell(vex, &p_vex, &q_vex);
    if ( c3n == u3du(q_vex) ) {
      return u3k(vex);
    } else {
      u3_noun uq_vex = u3t(q_vex);
      u3_noun puq_vex, quq_vex;
      u3_noun yit, yur;
      u3_noun p_yit, q_yit;
      u3_noun ret;

      u3x_cell(uq_vex, &puq_vex, &quq_vex);
      yit = u3x_good(u3n_slam_on(u3k(sab), u3k(quq_vex)));

      u3x_cell(yit, &p_yit, &q_yit);
      yur = _last(p_vex, p_yit);

      if ( c3n == u3du(q_yit) ) {
        ret = u3nc(yur, u3k(q_yit));
      }
      else {
        u3_noun uq_yit = u3t(q_yit);
        u3_noun puq_yit, quq_yit;

        u3x_cell(uq_yit, &puq_yit, &quq_yit);
        ret = u3nq(yur,
                   u3_nul,
                   u3x_good(u3n_slam_on(u3k(raq),
                                        u3nc(u3k(puq_vex),
                                             u3k(puq_yit)))),
                   u3k(quq_yit));
      }
      u3z(yit);
      return ret;
    }
  }
Beispiel #29
0
/* pose
*/
  u3_noun
  u3qe_pose(u3_noun vex,
            u3_noun sab)
  {
    u3_noun p_vex, q_vex;

    u3x_cell(vex, &p_vex, &q_vex);
    if ( c3y == u3du(q_vex) ) {
      return u3k(vex);
    } else {
      u3_noun roq = u3x_good(u3n_kick_on(u3k(sab)));
      u3_noun p_roq, q_roq;
      u3_noun ret;

      u3x_cell(roq, &p_roq, &q_roq);
      ret = u3nc(_last(p_vex, p_roq),
                 u3k(q_roq));

      u3z(roq);
      return ret;
    }
  }
Beispiel #30
0
  static u3_noun
  _heal_as(
           u3_noun van,
           u3_noun sut,
           u3_noun qog,
           u3_atom axe,
           u3_noun ref)
  {
    if ( 1 == axe ) {
      if ( u3_nul == qog ) {
        return u3k(ref);
      } else return _heal_by(van, sut, qog, ref);
    }
    else {
      u3_atom now = u3qc_cap(axe);
      u3_atom lat = u3qc_mas(axe);
      u3_noun ret = _heal_to(van, sut, u3_nul, qog, ref, now, lat);

      u3z(lat);
      return ret;
    }
  }