Esempio n. 1
0
int
ud_init (struct udoc *ud)
{
  bin_zero (ud, sizeof (*ud));
  if (!ud_oht_init (&ud->ud_parts, sizeof (struct ud_part))) goto FAIL;
  if (!ud_oht_init (&ud->ud_link_exts, sizeof (struct ud_ref))) goto FAIL;
  if (!ud_oht_init (&ud->ud_refs, sizeof (struct ud_ref))) goto FAIL;
  if (!ud_oht_init (&ud->ud_ref_names, sizeof (struct ud_ref))) goto FAIL;
  if (!ud_oht_init (&ud->ud_footnotes, sizeof (struct ud_ref))) goto FAIL;
  if (!ud_oht_init (&ud->ud_styles, sizeof (struct ud_ref))) goto FAIL;
  if (!dstack_init (&ud->ud_errors, 16, sizeof (struct ud_err))) goto FAIL;
  if (!token_init (&ud->ud_tok)) goto FAIL;

  ud->ud_dirfd_pwd = open_ro (".");
  if (ud->ud_dirfd_pwd == -1) goto FAIL;
  ud->ud_dirfd_src = -1;
  ud->ud_dirfd_out = -1;
  ud->ud_main_doc = ud;
  ud->ud_cur_doc = ud;

  if (!ht_init (&ud->ud_loopchecks)) goto FAIL;
  if (!ht_init (&ud->ud_documents)) goto FAIL;

  taia_now (&ud->ud_time_start);

  return 1;
  FAIL:
  ud_free (ud);
  return 0;
}
Esempio n. 2
0
void dstack_test()
{
	dstack dst;
	dstack_init(&dst, N);
	size_t i;
	for(i = 0; i < N/2; i++)
		dstack_push(&dst, (int)i, DSTACK_L);
	for(i = 0; i < N/2; i++)
		dstack_push(&dst, (int)i, DSTACK_H);
	for(i = 0; i < N/2; i++)
		printf("%d\n", dstack_pop(&dst, DSTACK_L));
	printf("\n");
	for(i = 0; i < N/2; i++)
		printf("%d\n", dstack_pop(&dst, DSTACK_H));
	dstack_free(&dst);
}
Esempio n. 3
0
int main(void)
{
  struct object obj;
  struct object *obp;
  const void *vp;
  unsigned long num;
  unsigned long cmp;

  test_assert(dstack_init(&st, STACK_SIZE, sizeof(struct object)));

  /* check size is zero */
  test_assert(dstack_size(&st) == 0);
  test_assert(dstack_SIZE(&st) == 0);

  /* check pop on empty is no-op */
  test_assert(dstack_pop(&st, (void **) &obp) == 0);

  /* check push works */
  for (num = 0; num < STACK_SIZE; ++num) {
    obj.num = num;
    test_assert(dstack_push(&st, &obj));
  }

  /* check size is correct */
  test_assert(dstack_bytes(&st) == STACK_SIZE * sizeof(struct object));
  test_assert(dstack_BYTES(&st) == STACK_SIZE * sizeof(struct object));

  test_assert(dstack_size(&st) == STACK_SIZE);
  test_assert(dstack_SIZE(&st) == STACK_SIZE);

  /* check pop and peek work */
  for (num = 0; num < STACK_SIZE; ++num) {
    dstack_peek(&st, (void **) &obp);
    test_assert(obp);

    cmp = obp->num;
    test_assert(cmp == STACK_SIZE - 1 - num);

    dstack_pop(&st, (void **) &obp);
    test_assert(obp);

    cmp = obp->num;
    test_assert(cmp == STACK_SIZE - 1 - num);
  }

  return 0;
}