コード例 #1
0
ファイル: db.c プロジェクト: 10xEngineer/My-Wallet-iPhone
bool update_index(char *path, idx *idx, uint8_t *kek, kdfp *kdfp, uint8_t *id, entry *entry) {
    size_t size    = index_size(idx);
    uint8_t *flags = scan_attrs(entry, &size);

    size += 1024 - (size % 1024);

    void    *addr = mmfile(path, &size);
    box     *kbox = BOX_PTR(addr, KDFP_LEN);
    box     *data = BOX_PTR(kbox, BOX_LEN(KEY_LEN));
    uint8_t *key  = BOX_DATA(kbox);

    if (!addr || !flags) return false;

    uint32_t *count = (uint32_t *) BOX_DATA(data);
    uint8_t *cursor = BOX_DATA(data) + sizeof(uint32_t);

    *count = idx->count;
    for (uint32_t i = 0; i < idx->count; i++) {
        term *term = &idx->terms[i];
        bool append = false;

        for (uint32_t j = 0; !append && j < entry->count; j++) {
            string *val = &entry->attrs[j].val;
            if (flags[j] == SKIP) continue;
            if (val->len == term->len && !memcmp(val->str, term->str, val->len)) {
                flags[j] = SKIP;
                append   = true;
                break;
            }
        }

        if (!append && term->count == 1 && !memcmp(term->ids, id, ID_LEN)) {
            (*count)--;
            continue;
        }

        cursor = write_term(cursor, term, id, append);
    }

    for (uint32_t i = 0; i < entry->count; i++) {
        string *val = &entry->attrs[i].val;
        if (flags[i] == WRITE) {
            term term  = { .len = val->len, .str = val->str };
            cursor = write_term(cursor, &term, id, true);
            (*count)++;
        }
    }

    *count = htonl(*count);
    free(flags);

    write_kdfp(addr, kdfp);
    memcpy(key, idx->key, KEY_LEN);
    encrypt_box(key, data, INDEX_LEN(size));
    encrypt_box(kek, kbox, KEY_LEN);

    return mmsync(path, addr, size);
}
コード例 #2
0
ファイル: lct.c プロジェクト: jbailhache/log
type type_term (term x)
{
type t;
#ifdef TRACE
	sput ("Type of ", err);
	write_term (x, err);
	sput ("...\n", err);
#endif
	t = type_term_1 (x);
#ifdef TRACE
	sput ("type of ", err);
	write_term (x, err);
	sput ("is ", err);
	write_type (t, err);
	sput (".\n", err);
#endif
	return t;
}
コード例 #3
0
ファイル: generate_cpp.cpp プロジェクト: RickMoynihan/circa
void write_block_contents(SourceWriter* writer, Block* block)
{
    for (int i=0; i < block->length(); i++) {
        Term* term = block->get(i);
        if (is_input_placeholder(term) || is_output_placeholder(term))
            continue;
        write_term(writer, term);
    }
}
コード例 #4
0
ファイル: lct.c プロジェクト: jbailhache/log
term ap (term fnc, term arg)
{
type tf, ta;
	tf = type_term (fnc);
	if (tf->k != TYPE_FNC)
		sput ("ap: invalid function\n", err);
	ta = type_term (arg);
	if (!equal_type (ta, tf->fnc.arg))
	{
		sput ("ap: bad type\n\tfunction ", err);
		write_term (fnc, err);
		sput (" has type ", err);
		write_type (tf, err);
		sput ("\n\targument ", err);
		write_term (arg, err);
		sput (" has type ", err);
		write_type (ta, err);
		sput ("\n", err);
	}
	return ap1 (fnc, arg);
}
コード例 #5
0
ファイル: lct.c プロジェクト: jbailhache/log
term lambda (term v, term x)
{
term r;
#ifdef TRACE
	sput ("Lambda ", err);
	write_term (v, err);
	sput (" . ", err);
	write_term (x, err);
	sput ("...\n", err);
#endif
	r = lambda_1 (v, x);
#ifdef TRACE
	sput ("lambda ", err);
	write_term (v, err);
	sput (" . ", err);
	write_term (x, err);
	sput (" = ", err);
	write_term (r, err);
	sput (".\n", err);
#endif
	return r;
}
コード例 #6
0
ファイル: sys_write.c プロジェクト: kperelygin/MortalKernel
int		sys_write(const int fd, void *buff, int bufflen)
{
  t_open_file	*f;
  t_task	*p = gl_current_task;
  int		cc;

  if (fd + 1 > p->opened_files)
    return (-1);
  if (fd < 0)
    return (-2);
  if (!p->files[fd]->file)
    return (write_term(buff, bufflen));
  f = p->files[fd];
  if (!(f->flags & O_RDWR))
    return (-3);
  cc = write_file(f->file, f->offset, buff, bufflen);
  return (cc);
}
コード例 #7
0
ファイル: lct.c プロジェクト: jbailhache/log
main ()
{
term x, n;
type t;
term plus_omega, omega_2, plus_omega_2, plus_omega_n, omega_n, omega_omega,
	plus_omega_omega;
term f, p;

	param_out.fd = stdout;
	param_err.fd = stderr;
	init ();
	/* Exemple : construction de l'ordinal omega * 2 */
	x = ap (LIM, ap (ap (S(ORD,ORD,ORD),
		ap (ap (S(ORD,fnc(ORD,ORD),fnc(ORD,ORD)),rep(ORD)),
			ap(K(fnc(ORD,ORD),ORD),SUC))),
		ap(K(ORD,ORD),ap(LIM,I(ORD)))));
	sput ("x = ", out);
	write_term (x, out);
	t = type_term (x);
	sput ("\nt = ", out);
	write_type (t, out);
	sput ("\n", out);

	n = var ("n", ORD);
	/*
	x = ap (LIM, lambda (n,
		ap (ap (ap (rep(ORD), n), SUC), ap (LIM, I(ORD)))
			));
		*/
	x = ap (ap (ap (rep(ORD), n), SUC), ap (LIM, I(ORD)));
	/*   x = ap (rep(ORD), n); */

	sput ("x = ", out);
	write_term (x, out);
	t = type_term (x);
	sput ("\nt = ", out);
	write_type (t, out);
	sput ("\n", out);

	x = lambda (n, x);
	sput ("x = ", out);
	write_term (x, out);
	t = type_term (x);
	sput ("\nt = ", out);
	write_type (t, out);
	sput ("\n", out);

	x = ap (LIM, x);
	sput ("x = ", out);
	write_term (x, out);
	t = type_term (x);
	sput ("\nt = ", out);
	write_type (t, out);
	sput ("\n", out);

	x = var ("x", ORD);
	plus_omega = lambda (x, lim (lambda (n,
		rpt (ORD, n, SUC, x)
			)));
	omega_2 = lim (lambda (n, rpt (ORD, n, plus_omega, ZERO)));
	t = type_term (omega_2);
	sput ("Type of omega_2 = ", out);
	write_type (t, out);
	sput ("\n", out);

	plus_omega_2 = lambda (x, lim (lambda (n,
		rpt (ORD, n, plus_omega, x))));
	t = type_term (plus_omega_2);
	sput ("Type of plus_omega_2 is ", out);
	write_type (t, out);

	f = var ("f", fnc(ORD,ORD));
	p = var ("p", ORD);

	plus_omega_n = lambda (n, rpt (fnc(ORD,ORD), n, lambda (f,
		lambda (x, lim (lambda (p, rpt (ORD, p, f, x)))) ),
		SUC));
	/*
	next_power = lambda (f,
		lambda (x, lim (lambda (p, rpt (ORD, p, f, x)))));
	plus_omega_n = lambda (n, rpt (fnc(ORD,ORD), n,
	*/
	t = type_term (plus_omega_n);
	sput ("\nType of plus_omega_n is ", out);
	write_type (t, out);

	omega_n = lambda (n, ap (ap (plus_omega_n, n), ZERO));
	t = type_term (omega_n);
	sput ("\nType of omega_n is ", out);
	write_type (t, out);

	omega_omega = lim (omega_n);
	t = type_term (omega_omega);
	sput ("\nType of omega_omega is ", out);
	write_type (t, out);

	plus_omega_omega = lambda (x, lim (lambda (n,
					    ap (ap (plus_omega_n, n), x) )));
	t = type_term (plus_omega_omega);
	sput ("\nType of plus_omega_omega is ", out);
	write_type (t, out);

	sput ("\n", out);

}
コード例 #8
0
ファイル: lct.c プロジェクト: jbailhache/log
write_term (term x, struct put_fnct *put)
{
	switch (x->k)
	{
		case TERM_I:
			sput (" I [", put);
			write_type (x->I.a, put);
			sput ("] ", put);
			break;
		case TERM_K:
			sput (" K [", put);
			write_type (x->K.a, put);
			sput (", ", put);
			write_type (x->K.b, put);
			sput ("] ", put);
			break;
		case TERM_S:
			sput (" S [", put);
			write_type (x->S.a, put);
			sput (", ", put);
			write_type (x->S.b, put);
			sput (", ", put);
			write_type (x->S.c, put);
			sput ("] ", put);
			break;
		case TERM_Y:
			sput (" Y [", put);
			write_type (x->Y.a, put);
			sput ("] ", put);
			break;
		case TERM_ZERO:
			sput (" 0 ", put);
			break;
		case TERM_SUC:
			sput (" suc ", put);
			break;
		case TERM_LIM:
			sput (" lim ", put);
			break;
		case TERM_REP:
			sput (" rep [", put);
			write_type (x->rep.a, put);
			sput ("] ", put);
			break;
		case TERM_AP:
			sput ("-", put);
			write_term (x->ap.fnc, put);
			write_term (x->ap.arg, put);
			break;
		case TERM_VAR:
			sput (" <", put);
			sput (x->var.name, put);
			sput (":", put);
			write_type (x->var.typ, put);
			sput ("> ", put);
			break;
		case TERM_UNDEF:
			sput (" U ", put);
			break;
		default:
			sput ("?", put);

	}
}
コード例 #9
0
ファイル: bpx.c プロジェクト: edechter/PRISM
void bpx_write(TERM t) {
	XDEREF(t);
	write_term(t);
}
コード例 #10
0
static int trans_command_rec(SP_term_ref t1, SP_stream *stream, struct event_stream_data *p)
{
#define buffer no_access_to_buffer_here
  spio_t_error_code code = SPIO_E_ERROR;
  SP_term_ref t2 = SP_new_term_ref();
  SP_atom name;
  SP_pred_ref pred;
  int i;
  char const *s;
  char c1, c2;

  switch (SP_term_type(t1))
    {
    case SP_TYPE_ATOM:
      if (SP_get_atom(t1, &name)
          && name == local.atm_nil)
        {
          goto success;
        }
      s = SP_string_from_atom(name);
      goto atomic;

    case SP_TYPE_INTEGER:
    case SP_TYPE_FLOAT:
      SP_get_number_codes(t1, &s);
  atomic:
      {
        code = SP_put_encoded_string(stream, s, SPIO_OPTION_NONE);
        if (SPIO_FAILED(code))
          {
            goto failure;
          }
        else
          {
            goto success;
          }
      }
      
    case SP_TYPE_COMPOUND:
      SP_get_functor(t1, &name, &i);
      if (name==local.atm_period && i==2)
	for (;;)
	  {
	    SP_get_list(t1, t2, t1);
	    if (!trans_command_rec(t2, stream, p))
	      goto failure;
	    if (SP_is_list(t1))
	      {
                PUT_BUFFER_CHAR(p, stream, ' ');
		continue;
	      }
	    else
	      if (SP_is_atom(t1) && SP_get_atom(t1, &name) && name==local.atm_nil)
		goto success;
	      else
		goto list_error;
	  }
/* Ignore compiler warnings here! */
      else if (((name==local.atm_dq && (c1='"', c2='"', 1)) ||
		(name==local.atm_sqb && (c1='[', c2=']', 1)) ||
		(name==local.atm_br && (c1='{', c2='}', 1)) ||
		(name==local.atm_min && (c1='-', c2=' ', 1))) &&
	       i==1)
	{
          PUT_BUFFER_CHAR(p, stream, c1);
	  SP_get_arg(1, t1, t2);
	  if (!trans_command_rec(t2, stream, p))
	    goto failure;
          PUT_BUFFER_CHAR(p, stream, c2);
	  /* p->buffer[p->index] = '\0'; */
	  goto success;
	}
      else if (name==local.atm_dot && i==1) {
	SP_get_arg(1, t1, t1);

	if (SP_is_atom(t1))	/* the root path, "." */
          PUT_BUFFER_CHAR(p, stream, '.');
	else while (SP_is_list(t1)) { /* .first.second.third ... */
	  SP_get_list(t1, t2, t1);
          PUT_BUFFER_CHAR(p, stream, '.');
	  if (!trans_command_rec(t2, stream, p))
	    goto failure;
	}
	/* p->buffer[p->index] = '\0'; */
	goto success;
      }
      else if (i == 1
               && (    (name==local.atm_write           && ( pred = local.write_pred, 1))
                    || (name==local.atm_writeq          && ( pred = local.writeq_pred, 1))
                    || (name==local.atm_write_canonical && ( pred = local.write_canonical_pred, 1)) ) )
	{
	  SP_get_arg(1, t1, t1);
          if (write_term(pred, t1, stream))
            goto success;
          else
            goto failure;
        }
      else if (name==local.atm_format && i==2)
	{
	  SP_get_arg(2, t1, t2);
	  SP_get_arg(1, t1, t1);
          if (do_format(t1, t2, stream))
            {
              goto success;
            }
          else
            {
              goto failure;
            }
	}
      else if ((name == local.atm_chars || name==local.atm_codes) && i==1)
	{
	  SP_get_arg(1, t1, t1);
	  if (!SP_get_list_codes(t1, &s)) /* [PM] May 2000 used to ignore errors */
            {
              goto list_error;  /* Misleading error message */
            }
	  goto atomic;
	}
      else if (name==local.atm_list && i==1)
        {
	  SP_get_arg(1, t1, t1);
          if (trans_command_list(t1, stream, p))
            goto success;
          else
            goto failure;
        }
      else
        {
          SAVE_ERROR(DOMAIN_ERROR, "tcl_command_spec", t1, 2);
        }
	    
    case SP_TYPE_VARIABLE:
  instantiation_error:
      SAVE_ERROR(INSTANTIATION_ERROR, "", t1, 2);
    }
  SP_ASSERT(0);                 /* not reached */

 success:
  SP_ASSERT(p->index < p->size);
  /* p->buffer[p->index] = '\0'; */
  return 1;

list_error:
  if (SP_is_variable(t1))
    goto instantiation_error;
  else
    SAVE_ERROR(DOMAIN_ERROR+DOMAIN_LIST, "", t1, 2);
failure:
error:
  return 0;

#undef buffer
}
コード例 #11
0
static int writeq_term(SP_term_ref t1, SP_stream *stream, struct event_stream_data *p)
{
  (void) p;
  return write_term(local.writeq_pred, t1, stream);
}