Exemplo n.º 1
0
static void test_stack_peek(void) {
  Stack *stack = create_stack();
  push(stack, 5);

  assert (5 == peek(stack) && "peek at stack should show 5");
  destroy_stack(stack);
}
Exemplo n.º 2
0
void
destroy_cat_list (cat_list **cl)
{
  int rc;

  if (*cl == NULL)
    {
      return;
    }

  if ((rc = close_all_prepared_statements (*cl)))
    {
      l->APP_ERR (rc, "Cannot close all prepared statements to destroy cat_list");
    }
  if (sqlite3_close ((*cl)->db))
    {
      SQLITE3_ERR ((*cl)->db, "Cannot close category list DB");
    }
  destroy_stack (&(*cl)->parents_id_and_next_offset);
  if ((*cl)->cur_cat.name != NULL)
    {
      free ((void *) (*cl)->cur_cat.name);
    }

  free ((void *) *cl);
  *cl = NULL;
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: heptat/C
int main() {
  Stack *stack = create_stack();
  push(stack, 20);
  printf("stack head value = %d\n", stack->head->value);
  print_stack(stack);

  push(stack, 21);
  printf("stack head value = %d\n", stack->head->value);
  print_stack(stack);

  // Node *node = (Node *) malloc(sizeof(Node));
  Node *node = NULL;
  pop(stack, &node);
  printf("popped value = %d\n", node->value);
  printf("stack head value = %d\n", stack->head->value);
  print_stack(stack);

  push(stack, 22);
  printf("stack head value = %d\n", stack->head->value);
  print_stack(stack);

  free(node);
  destroy_stack(stack);

  return 0;
}
Exemplo n.º 4
0
static void test_push_onto_empty_stack_size_is_one(void) {
  Stack *stack = create_stack();
  push(stack, 5);

  assert (1 == size(stack) && "stack size after push should be 1");
  destroy_stack(stack);
}
Exemplo n.º 5
0
static void test_non_empty_stack_is_empty_returns_false(void) {
  Stack *stack = create_stack();
  push(stack, 5);

  assert (FALSE == is_empty(stack) && "stack is_empty should return FALSE");
  destroy_stack(stack);
}
Exemplo n.º 6
0
int main(int argc, char *argv[]) {


    init_ncurses();
    refresh();

    for (int i=0; i<NPILAS; i++)
      win[i] = create_newwin(H, W, 1, 1 + i * W);

    for (int i=0; i<NPILAS; i++)
	p[i] = create_stack(N);

    /* Inicializar */
    for (int i=N-1; i>=0; i--)
	push(i+1, p[0]);

    traslada(N, 0, 2);
   
    for (int i=0; i<NPILAS; i++)
	destroy_stack(p[i]);

    for (int i=0; i<NPILAS; i++)
	destroy_win(win[i]);
    end_ncurses();

    return EXIT_SUCCESS;
}
Exemplo n.º 7
0
void release_tokenizer(tokenizer_t* t)
{
	free(t->source);
	free(t->token_value);
	destroy_stack(t->index_stack);
	memset(t, 0, sizeof(tokenizer_t));
}
Exemplo n.º 8
0
static void test_push_onto_empty_stack_creates_node_with_value(void) {
  Stack *stack = create_stack();
  push(stack, 5);

  assert (5 == stack->head->value && "stack->head->value should be 5");
  destroy_stack(stack);
}
Exemplo n.º 9
0
static void test_empty_stack_peek(void) {
  Stack *stack = create_stack();

  // Note: You can't tell if a stack is empty by simply peeking, you also have
  // to call "is_empty"
  assert (0 == peek(stack) && "peek at empty stack should show 0");
  destroy_stack(stack);
}
Exemplo n.º 10
0
static void test_push_onto_non_empty_stack_size_is_correct(void) {
  Stack *stack = create_stack();
  push(stack, 5);
  push(stack, 4);

  assert (2 == size(stack) && "stack size after pushes should be 2");
  destroy_stack(stack);
}
Exemplo n.º 11
0
void disable_exceptions(void) {
    if (current_frame != NULL) {
        free(current_frame);
        current_frame = NULL;
    }
    destroy_stack(exception_stack, free);
    exception_stack = NULL;
}
Exemplo n.º 12
0
static void test_pop_from_empty_stack_size_is_zero(void) {
  Stack *stack = create_stack();
  Node *node = NULL;
  pop(stack, &node);

  assert (0 == size(stack) && "stack size should be 0");
  free(node);
  destroy_stack(stack);
}
Exemplo n.º 13
0
static void test_pop_from_empty_stack_node_is_null(void) {
  Stack *stack = create_stack();
  Node *node = NULL;
  pop(stack, &node);

  assert (NULL == node && "popped node should be NULL");
  free(node);
  destroy_stack(stack);
}
Exemplo n.º 14
0
static void test_pop_from_stack_with_one_node_value_is_correct(void) {
  Stack *stack = create_stack();
  push(stack, 5);
  Node *node = NULL;
  pop(stack, &node);

  assert (5 == node->value && "popped value should be 5");
  free(node);
  destroy_stack(stack);
}
Exemplo n.º 15
0
void finish_task_switch(void)
{
	task_t* old;
	const uint32_t core_id = CORE_ID;

	spinlock_irqsave_lock(&readyqueues[core_id].lock);

	if ((old = readyqueues[core_id].old_task) != NULL) {
		readyqueues[core_id].old_task = NULL;

		if (old->status == TASK_FINISHED) {
			/* cleanup task */
			if (old->stack) {
				//LOG_INFO("Release stack at 0x%zx\n", old->stack);
				destroy_stack(old->stack, DEFAULT_STACK_SIZE);
				old->stack = NULL;
			}

			if (!old->parent && old->heap) {
				kfree(old->heap);
				old->heap = NULL;
			}

			if (old->ist_addr) {
				destroy_stack(old->ist_addr, KERNEL_STACK_SIZE);
				old->ist_addr = NULL;
			}

			old->last_stack_pointer = NULL;

			if (readyqueues[core_id].fpu_owner == old->id)
				readyqueues[core_id].fpu_owner = 0;

			/* signalizes that this task could be reused */
			old->status = TASK_INVALID;
		} else {
			// re-enqueue old task
			readyqueues_push_back(core_id, old);
		}
	}

	spinlock_irqsave_unlock(&readyqueues[core_id].lock);
}
Exemplo n.º 16
0
static void test_pop_from_stack_with_one_node_size_is_correct(void) {
  Stack *stack = create_stack();
  push(stack, 5);
  Node *node = NULL;
  pop(stack, &node);

  assert (0 == size(stack) && "stack size after pop should be 0");
  free(node);
  destroy_stack(stack);
}
Exemplo n.º 17
0
static void test_stack_peek_after_pop(void) {
  Stack *stack = create_stack();
  push(stack, 4);
  push(stack, 5);
  Node *node;
  pop(stack, &node);

  assert (4 == peek(stack) && "peek at stack should show 4");
  free(node);
  destroy_stack(stack);
}
Exemplo n.º 18
0
static void test_pop_from_non_empty_stack_value_is_correct(void) {
  Stack *stack = create_stack();
  push(stack, 5);
  push(stack, 4);
  Node *node = NULL;
  pop(stack, &node);

  assert (4 == node->value && "popped value should be 4");
  free(node);
  destroy_stack(stack);
}
Exemplo n.º 19
0
int main(void)
{
	char ch;
	init_stack(5);
	while ((ch = getchar()) != '\n')
		push(ch);
	while (!is_empty())
		putchar(pop());
	putchar('\n');
	destroy_stack();
	return 0;
}
Exemplo n.º 20
0
static void free_ressources(void){

  if(src_file != (FILE *) 0){

    if( fclose(src_file) == EOF ){
      src_file = (FILE *) 0;
      bailout("free_ressources Cannot close file stream");
    }
    src_file = (FILE *) 0;
  }

  if( stack != (Stack *) 0 ){ destroy_stack(); }
}
Exemplo n.º 21
0
static void test_sort_stack_with_two_nodes_in_order(void) {
  Stack *stack = create_stack();
  push(stack, 1);
  push(stack, 2);

  sort(stack);

  Node *ptr = stack->next;
  assert (1 == ptr->value && "first stack value should be 1");
  ptr = ptr->next;
  assert (2 == ptr->value && "second stack value should be 2");
  destroy_stack(stack);
  ptr = NULL;
}
Exemplo n.º 22
0
int main(int argc, char *argv[]){

////////Lista
	struct List *list;
	int i;
	
	list = init_list();

	for(i=1; i<=10; i++){
		add(list,i);
	}

	print_list(list);

	destroy_list(list);

////////Cola
	struct COLA *Cola;
	int j;
	
	Cola = init_cola();

	for(j=1; j<=10; j++){
		add(Cola,j);
	}

	print_cola(Cola);

	destroy_cola(Cola);
	
	

////////Pila

	struct Stack *stack;
	int k;
	
	stack = init_stack();

	for(k=1; k<=10; k++){
		add(stack,k);
	}

	print_stack(stack);

	destroy_stack(stack);

	return 1;
}
Exemplo n.º 23
0
/**
 * Returns a null terminated character array to be used as symbol lookup table.
 * include/exclude should be a list of characters in the form of a sorted
 * string in ascending order.
 */
char *
generate_charset(charset_opt_t opt, const char *exclude, const char *include)
{
    struct stack    stack;
    char            *symtab;
    size_t          symtab_size;

    init_stack(&stack);

    // start at end so characters can be popped in order    
    for (int i = '~'; i >= '!'; --i) {
        int     allowed     = 0;
        int     disallowed  = 0;

        // allow according to options/include list
        if ((opt & LOWER && islower(i)) ||
            (opt & UPPER && isupper(i)) ||
            (opt & DIGIT && isdigit(i)) ||
            (opt & PUNCT && ispunct(i)) ||
            (include && bsearch(&i, include, strlen(include),
                                sizeof(char), cmpchar))) 
        {
            allowed = 1;
        }

        // disallow if found in exclude list
        if (exclude && 
            bsearch(&i, exclude, strlen(exclude),
                    sizeof(char), cmpchar))
        {
            disallowed = 1;
        }

        // push allowed characters onto stack
        if (allowed && !disallowed)
            if (!push(&stack, i)) return NULL;
    }

    /* Populate symbol table */
    symtab_size = stack.depth;
    symtab = malloc((symtab_size + 1) * sizeof(char));
    for (int i = 0, c; pop(&stack, &c); ++i)
        symtab[i] = (char) c;
    symtab[symtab_size] = '\0'; 
    
    destroy_stack(&stack);

    return symtab;
}
Exemplo n.º 24
0
void kd_nn_search_all(Kdtree *kd_tree, float r) {
  int i, n;
  int *neighbors;
  Stack s;

  init_stack(&s, kd_tree->size);

  for(i = 0; i < kd_tree->size; i++) {
    //kd_tree->nodes[i].neighbors = (int*)malloc(N_SIZE * sizeof(int));
    n = kd_nn_search(kd_tree, &(kd_tree->nodes[i]), r, &neighbors, &s);
    kd_tree->nodes[i].neighbors = neighbors;
    kd_tree->nodes[i].neighbors_size = n;
  }

  destroy_stack(&s);
}
Exemplo n.º 25
0
void sort(stack_t *s) {
    if (s == NULL || s->is_empty(s))
        return;
    
    int buf;
    stack_t *r = make_stack();
    
    while (!s->is_empty(s)) {
        buf = s->pop(s);
        while (!r->is_empty(r) && r->peak(r) > buf)
            s->push(s, r->pop(r));
        r->push(r, buf);
    }
    
    memcpy(s, r, sizeof(stack_t));
    destroy_stack(r);
}
Exemplo n.º 26
0
int main(int argc, char *argv[])
{
    __stack *s = init_stack();
    int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    int i;

    for(i=0; i<9; i++)
    {
        push(s, array+i);
    }

    printf("stack size is %zu\n", get_stack_size(s));
    while(!is_stack_empty(s))
    {
        int *p = (int *)pop(s);
        printf("%d\n", *p);
    }
    destroy_stack(s);
    return 0;
}
Exemplo n.º 27
0
int main(){

    STACK *s = create_stack();
    int i;
    
    printf("PUSH TIME\n");
    for(i = 0; i < 10; i++){
        print_stack(s);
        push(s, i);
    }

    printf("POP TIME\n");
    while( !empty(s) ){
        print_stack(s);
        pop(s);
    }

    print_stack(s);

    destroy_stack(&s);
    print_stack(s);
    return 0;
}
Exemplo n.º 28
0
void
rust_task::free_stack(stk_seg *stk) {
    LOGPTR(sched_loop, "freeing stk segment", (uintptr_t)stk);
    total_stack_sz -= user_stack_size(stk);
    destroy_stack(&local_region, stk);
}
Exemplo n.º 29
0
/*
 * main()
 */
int main(int argc, char *argv[])
{
    pj_status_t status;

    global.port = 5060;
    pj_log_set_level(4);

    status = init_options(argc, argv);
    if (status != PJ_SUCCESS)
	return 1;

    status = init_stack();
    if (status != PJ_SUCCESS) {
	app_perror("Error initializing stack", status);
	return 1;
    }

    status = init_proxy();
    if (status != PJ_SUCCESS) {
	app_perror("Error initializing proxy", status);
	return 1;
    }

    status = init_stateless_proxy();
    if (status != PJ_SUCCESS) {
	app_perror("Error initializing stateless proxy", status);
	return 1;
    }

#if PJ_HAS_THREADS
    status = pj_thread_create(global.pool, "sproxy", &worker_thread, 
			      NULL, 0, 0, &global.thread);
    if (status != PJ_SUCCESS) {
	app_perror("Error creating thread", status);
	return 1;
    }

    while (!global.quit_flag) {
	char line[10];

	puts("\n"
	     "Menu:\n"
	     "  q    quit\n"
	     "  d    dump status\n"
	     "  dd   dump detailed status\n"
	     "");

	if (fgets(line, sizeof(line), stdin) == NULL) {
	    puts("EOF while reading stdin, will quit now..");
	    global.quit_flag = PJ_TRUE;
	    break;
	}

	if (line[0] == 'q') {
	    global.quit_flag = PJ_TRUE;
	} else if (line[0] == 'd') {
	    pj_bool_t detail = (line[1] == 'd');
	    pjsip_endpt_dump(global.endpt, detail);
#if STATEFUL
	    pjsip_tsx_layer_dump(detail);
#endif
	}
    }

    pj_thread_join(global.thread);

#else
    puts("\nPress Ctrl-C to quit\n");
    for (;;) {
	pj_time_val delay = {0, 0};
	pjsip_endpt_handle_events(global.endpt, &delay);
    }
#endif

    destroy_stack();

    return 0;
}
Exemplo n.º 30
0
/* main()
 *
 * If called with argument, treat argument as SIP URL to be called.
 * Otherwise wait for incoming calls.
 */
int main(int argc, char *argv[])
{
    if (init_stack())
	goto on_error;

    /* If URL is specified, then make call immediately. */
    if (argc > 1) {
	pj_sockaddr hostaddr;
	char hostip[PJ_INET6_ADDRSTRLEN+2];
	char temp[80];
	call_t *call;
	pj_str_t dst_uri = pj_str(argv[1]);
	pj_str_t local_uri;
	pjsip_dialog *dlg;
	pj_status_t status;
	pjsip_tx_data *tdata;

	if (pj_gethostip(AF, &hostaddr) != PJ_SUCCESS) {
	    PJ_LOG(1,(THIS_FILE, "Unable to retrieve local host IP"));
	    goto on_error;
	}
	pj_sockaddr_print(&hostaddr, hostip, sizeof(hostip), 2);

	pj_ansi_sprintf(temp, "<sip:sipecho@%s:%d>",
			hostip, SIP_PORT);
	local_uri = pj_str(temp);

	call = &app.call[0];

	status = pjsip_dlg_create_uac( pjsip_ua_instance(),
				       &local_uri,  /* local URI */
				       &local_uri,  /* local Contact */
				       &dst_uri,    /* remote URI */
				       &dst_uri,    /* remote target */
				       &dlg);	    /* dialog */
	if (status != PJ_SUCCESS) {
	    app_perror(THIS_FILE, "Unable to create UAC dialog", status);
	    return 1;
	}

	status = pjsip_inv_create_uac( dlg, NULL, 0, &call->inv);
	if (status != PJ_SUCCESS) goto on_error;

	call->inv->mod_data[mod_sipecho.id] = call;

	status = pjsip_inv_invite(call->inv, &tdata);
	if (status != PJ_SUCCESS) goto on_error;

	status = pjsip_inv_send_msg(call->inv, tdata);
	if (status != PJ_SUCCESS) goto on_error;

	puts("Press ENTER to quit...");
    } else {
	puts("Ready for incoming calls. Press ENTER to quit...");
    }

    for (;;) {
	char s[10];

	printf("\nMenu:\n"
	       "  h    Hangup all calls\n"
	       "  l    %s message logging\n"
	       "  q    Quit\n",
	       (app.enable_msg_logging? "Disable" : "Enable"));

	if (fgets(s, sizeof(s), stdin) == NULL)
	    continue;

	if (s[0]=='q')
	    break;
	switch (s[0]) {
	case 'l':
	    app.enable_msg_logging = !app.enable_msg_logging;
	    break;
	case 'h':
	    hangup_all();
	    break;
	}
    }

    destroy_stack();

    puts("Bye bye..");
    return 0;

on_error:
    puts("An error has occurred. run a debugger..");
    return 1;
}