예제 #1
0
파일: unix.c 프로젝트: esaul/urbit
/* _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));
}
예제 #2
0
파일: unix.c 프로젝트: esaul/urbit
/* _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;
}
예제 #3
0
파일: loop.c 프로젝트: gunnarahlberg/urbit
//  _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);
  }
}
예제 #4
0
파일: loop.c 프로젝트: gunnarahlberg/urbit
//  _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);
  }
}
예제 #5
0
파일: term.c 프로젝트: gunnarahlberg/urbit
/* _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;
}
예제 #6
0
파일: unix.c 프로젝트: cgyarvin/urbit
/* _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);
}
예제 #7
0
파일: term.c 프로젝트: gunnarahlberg/urbit
/* _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;
    }
  }
}
예제 #8
0
파일: walk.c 프로젝트: Gruelty/urbit
/* _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;
}
예제 #9
0
파일: unix.c 프로젝트: gphummer/urbit
/* _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));
}