예제 #1
0
파일: stack.c 프로젝트: fangwen/datas
int suffix_cal(char exp[])
{
    stack temp;
    stack s;
    stack s2;
    init_stack(&temp, 100);
    init_stack(&s, 100);
    init_stack(&s2, 100);
    while(*exp != '\0') {
	push(&temp, *exp);
	exp++;
    }
    while(stack_length(&temp) != 0)
	push(&s, pop(&temp));
    while(stack_length(&s) != 0) {
	push(&s2, pop(&s));
	if(gettop(&s2) == '+' ||gettop(&s2) == '-'||gettop(&s2)=='*'||gettop(&s2) == '/') {
	    char ch3 = pop(&s2);
	    char ch2 = pop(&s2);
	    char ch1 = pop(&s2);
	    int r = calculate(ch1, ch2, ch3);
	    char ch = r + 48;
	    push(&s2, ch);
	}
    }
    return gettop(&s2) - 48;
}
예제 #2
0
float process_data(STACK *pst1)
{	float d;
	STACK integ,deci;
	init_stack(&integ);init_stack(&deci);
	filter(pst1,&integ,&deci);
	return process_integral(&integ)+process_decimal(&deci);

}
예제 #3
0
PCIPHEREXP __INTERNAL_FUNC__ ReverseCipherExpression(PCIPHEREXP pCipherExp) {
	/*
	 * 再压入操作符号与操作节点时
	 * 链中第一个节点不压入栈
	 * 最后一个操作符号不压入栈
	 *
	 * 逆向式中的第一个节点肯定没有操作符号
	 */
	__bool bIsFirst = TRUE;
	LOGIC_OPT *pOpt = NULL;
	PCIPHEREXP pReverseCipherExp = NULL, *pReverseCipherExpPoint = NULL;
	PCIPHEREXP pCurrCipherExp = pCipherExp;
	PSTACK pOptStack = init_stack(0);
	__integer i = 0, iCipherNodeCount = CountCipherNode(pCipherExp);
	PSTACK pCipherExpNodeStack = init_stack(sizeof(CIPHEREXP) * iCipherNodeCount);
	for (i = 0; i < iCipherNodeCount; i++) {
		if (i == 0) {//舍弃第一个节点
			push_stack(pOptStack, &(pCurrCipherExp->Opt), sizeof(LOGIC_OPT));
		} else if (i == iCipherNodeCount-1) {
			push_stack(pCipherExpNodeStack, pCurrCipherExp, sizeof(CIPHEREXP));
		} else {
			push_stack(pOptStack, &(pCurrCipherExp->Opt), sizeof(LOGIC_OPT));
			push_stack(pCipherExpNodeStack, pCurrCipherExp, sizeof(CIPHEREXP));
		}
		pCurrCipherExp = pCurrCipherExp->pNextExp;
	}

	/*
	 * 首先扩充第一个节点(变量)
	 */
	pReverseCipherExpPoint = &pReverseCipherExp;
	do {
		pOpt = (LOGIC_OPT *)pop_stack(pOptStack, sizeof(LOGIC_OPT));
		(*pReverseCipherExpPoint) = CreateCipherExp();

		// 如果是第一个节点
		if (bIsFirst) {
			(*pReverseCipherExpPoint)->bNot = pCipherExp->bNot;//第一个变量是否拥有NOT操作
			(*pReverseCipherExpPoint)->Opt = GenerateReverseLogicOpt(*pOpt);	
			bIsFirst = FALSE;
		} else {
			if (!pOpt)
				(*pReverseCipherExpPoint)->Opt = LOGIC_NONE;
			else
				(*pReverseCipherExpPoint)->Opt = *pOpt;
			pCurrCipherExp = (PCIPHEREXP)pop_stack(pCipherExpNodeStack, sizeof(CIPHEREXP));
			(*pReverseCipherExpPoint)->bKey = pCurrCipherExp->bKey;
			(*pReverseCipherExpPoint)->bNot = pCurrCipherExp->bNot;
			(*pReverseCipherExpPoint)->dwVal = pCurrCipherExp->dwVal;
		}/* end else */
		pReverseCipherExpPoint = &((*pReverseCipherExpPoint)->pNextExp);
	} while (pOpt);
	free_stack(pOptStack);
	free_stack(pCipherExpNodeStack);
	return pReverseCipherExp;
}
예제 #4
0
파일: Main2.c 프로젝트: Orcuslc/Learning
int EvaluateExpression(){

    int n;
    int flag;
    int c;
    char x,theta;
    int a,b;

    char OP[]="+-*/()#";
    SqStack  OPTR;
    SqStack  OPND;

    init_stack(&OPTR);      
    push(&OPTR,'#');
    init_stack(&OPND);
    flag=getNext(&c);

    get_top(OPTR, &x);
    while(c!='#' || x != '#')
    {
        if(flag == 0)
	     {
                  push(&OPND,c);
                  flag = getNext(&c);
             }        else
	{
            get_top(OPTR, &x);
            switch(Precede(x, c))
	    {
                case '<'://栈顶元素优先级低                    
                    push(&OPTR,c);
                    flag = getNext(&c);
                    break;
                case '='://脱括号并接受下一字符 
                    pop(&OPTR,&x);
                    flag = getNext(&c);
                    break;
                case '>':// 退栈并将运算结果入栈                                       
                    pop(&OPTR, &theta);
                    pop(&OPND,&b);
                    pop(&OPND,&a);
                    push(&OPND, Operate(a, theta, b));
                    break;
            }
        }
        get_top(OPTR, &x);
    }
    get_top(OPND, &c);
    return c;
}
예제 #5
0
파일: main.c 프로젝트: ucf-cs/CCSpec
int user_main(int argc, char **argv)
{
    int i;
    int *param;
    unsigned int in_sum = 0, out_sum = 0;

    atomic_init(&x[1], 0);
    atomic_init(&x[2], 0);

    stack = (stack_t*) calloc(1, sizeof(*stack));

    num_threads = procs;
    threads = (thrd_t*) malloc(num_threads * sizeof(thrd_t));
    param = (int*) malloc(num_threads * sizeof(*param));

    init_stack(stack, num_threads);

    for (i = 0; i < num_threads; i++) {
        param[i] = i;
        thrd_create(&threads[i], main_task, &param[i]);
    }
    for (i = 0; i < num_threads; i++)
        thrd_join(threads[i]);

    bool correct = false;
    //correct |= (a == 17 || a == 37 || a == 0);
    //MODEL_ASSERT(correct);

    free(param);
    free(threads);
    free(stack);

    return 0;
}
예제 #6
0
int main()
{
	unsigned int i;
	int tmp;
	Stack s;
	int test_data[SIZE] = {7,8,6,10,5,4,12,3,13,12};
	init_stack(&s);

	for(i = 0; i < SIZE; i++)
	{
		stack_push(&s, test_data[i]);
	}

	printf(">>>>>>start to pop\n");

	while(!stack_is_empty(&s))
	{
		if(get_min(&s, &tmp))
			printf("min is %d\n", tmp);

		stack_pop(&s, &tmp);
		printf("%d\n", tmp);
	}
	return 0;
}
예제 #7
0
int main()
{
	int n;
	stack tmp = { 0, 0 };
	stack *s = &tmp;
	init_stack(s);
	printf("input int:");
	while (scanf("%d", &n) != EOF) {
		if (n < 0) {
			int v = pop_stack(s);
			printf("pop() -> v:%d,num:%d,size:%d\n", v,
			       get_stack_datanum(s), get_stack_size(s));
		} else if (n > 0) {
			push_stack(s, n);
			printf("push() -> num:%d,size:%d\n",
			       get_stack_datanum(s), get_stack_size(s));
		} else {
			break;
		}
		printf("input int:");
	}
	printf("over...\n");
	release_stack(s);	//释放内存
	return 0;
}
예제 #8
0
파일: 24_8.c 프로젝트: yaginuuu/tsukuba
int balance(unsigned char *p){
	unsigned char c;
	init_stack();
	for( ; (c = *p) != '\0'; p++){
		switch(c){
			case '(':
			case '[':
			case '{':
				push(c);
				break;
			case ')':
				if(pop(c) != '(')
					return(0);
				break;
			case '}':
				if(pop(c) != '{')
					return(0);
				break;
			case ']':
				if(pop(c) != '[')
					return(0);
				break;
			default:
				break;	
		}
	}
	if(depth() == NULL)
		return(1);
	else
		return(0);
}
예제 #9
0
파일: SORT.C 프로젝트: gomins/AlgorithmCV
void quick_sort1(void *base, size_t nelem, size_t width, FCMP fcmp)
    {     /* remove recursion & median & small subfile insert*/
    void *v, *u;
    int i, j, t;
    int l, r;
    init_stack();
    v = malloc(width);
    u = malloc(width);
    l = 0;
    r = nelem-1;
    push(r);
    push(l);
    while (!is_stack_empty())
	{
	l = pop();
	r = pop();
	if (r-l+1 > 100)    /* terminal condition */
	    {
	    t = (r+l) >> 1;    /* t is middle */
	    if (fcmp(BASE(l), BASE(t)) > 0)  /* sort left, middle, right */
		{
		memcpy(v, BASE(l), width);
		memcpy(BASE(l), BASE(t), width);
		memcpy(BASE(t), v, width);
		}
	    if (fcmp(BASE(l), BASE(r)) > 0)  /* sort left, middle, right */
		{
		memcpy(v, BASE(l), width);
		memcpy(BASE(l), BASE(r), width);
		memcpy(BASE(r), v, width);
		}
	    if (fcmp(BASE(t), BASE(r)) > 0)  /* sort left, middle, right */
		{
		memcpy(v, BASE(t), width);
		memcpy(BASE(t), BASE(r), width);
		memcpy(BASE(r), v, width);
		}
	    memcpy(v, BASE(t), width);    /* exchange middle with a[r-1] */
	    memcpy(BASE(t), BASE(r-1), width);
	    memcpy(BASE(r-1), v, width);
	    i = l;     /* partition l+1 to r-2 */
	    j = r-1;
	    while (1)      /* partition */
		{
		while (fcmp(BASE(++i), v) < 0);
		while (fcmp(BASE(--j), v) > 0);
		if (i >= j) break;
		memcpy(u, BASE(i), width);
		memcpy(BASE(i), BASE(j), width);
		memcpy(BASE(j), u, width);
		}
	    memcpy(u, BASE(i), width);
	    memcpy(BASE(i), BASE(r-1), width);
	    memcpy(BASE(r-1), u, width);
	    push(r);
	    push(i+1);
	    push(i-1);
	    push(l);
	    }
	else
예제 #10
0
void post_order_iterative(struct Tnode *root)
{
    if (root == NULL)
        return;
    struct stack st;
    init_stack(&st, 1);
    push(&st, root);
    struct Tnode *prev = NULL;
    while (!is_empty(&st)) {
        struct Tnode *cur = (struct Tnode *)top(&st);
        if (!prev || prev->left == cur || prev->right == cur) {
            if (cur->left != NULL)
                push(&st, cur->left);
            else if (cur->right != NULL)
                push(&st, cur->right);
            else {
                printf("%d,", cur->data);
                pop(&st);
            }
        } else if(cur->left == prev) {
            if (cur->right != NULL)
                push(&st, cur->right);
            else {
                printf("%d,", cur->data);
                pop(&st);
            }
        } else if (cur->right == prev) {
            printf("%d,", cur->data);
            pop(&st);
        }
        prev = cur;
    }
    printf("\n");
}
예제 #11
0
int calc_suffix_expr(int *suffix, int len)
{
	int i, tmp, param1, param2, result = 0;
	link_stack sans;

	init_stack(&sans);

	for (i = 0; i < len; i++) {
		switch (suffix[i]) {
		case '+':
		case '-':
		case '*':
		case '/':
			pop(&sans, &param2);
			pop(&sans, &param1);
			tmp = calc_little(param1, param2, suffix[i]);
			push(&sans, tmp);
			break;
		default:
			push(&sans, suffix[i]);
		}
	}
	pop(&sans, &result);
	return result;
}
예제 #12
0
int infix_to_suffix(int *mid, int mid_len, int *suffix)
{
	int i, tmp, counter = 0;
	link_stack sans;

	init_stack(&sans);

	for (i = 0; i < mid_len; i++) {
		switch (mid[i]) {
		case '+':
		case '-':
		case '*':
		case '/':
		case '(':
		case ')':
			process_op_char(mid[i], &sans, suffix, &counter);
			break;
		default:
			suffix[counter++] = mid[i];
			break;
		}
	}

	while (!is_empty(&sans)) {
		pop(&sans, &tmp);
		suffix[counter++] = tmp;
	}

	return counter;
}
예제 #13
0
int main()
{
	stack_sq S;
	int a[] = {3, 8, 5, 17, 9, 30, 15, 22};
	int i;
	init_stack(&S, 5);
	for (i = 0; i < 8; i++)
	{
		push(&S, a[i]);
	}
	printf("%d ", pop(&S));
	printf("%d \n", pop(&S));
	
	push(&S, 68);
	printf("%d ", peek_stack(&S));
	printf("%d \n", pop(&S));
	
	while(!empty_stack(&S))
	{
		printf("%d ", pop(&S));
	}
	printf("\n");
	clear_stack(&S);

    return 0;
}
예제 #14
0
void DFS_directed(node *a[], int V)
    {      /* Get Transitive Closure by Depth First Search */
    int i, j;
    node *t;
    init_stack();
    for (i = 0; i < V; i++)
	{
	for (j = 0; j < V; j++) check[j] = 0;   /* clear */

	push(i);
	check[i] = 1;
	printf("\n %c : ", int2name(i));
	while (!stack_empty())
	    {
	    j = pop();
	    visit(j);
	    for (t = a[j]; t != NULL; t = t->next)
		if (check[t->vertex] == 0)
		    {
		    push(t->vertex);
		    check[t->vertex] = 1;
		    }
	    }
	}
    }
예제 #15
0
void test_stack() {
  stack test;
  init_stack(&test);
  node *temp = NULL;

  temp = top(&test);
  printf("\n[TOP] : %d", (temp != NULL ? temp->start_bar_id : 0));

  temp = pop(&test);
  printf("\n[POP] : %d", (temp != NULL ? temp->start_bar_id : 0));

  temp = push(&test ,10);
  printf("\n[PUSH] : %d", (temp != NULL ? temp->start_bar_id : 0));

  temp = push(&test ,20);
  printf("\n[PUSH] : %d", (temp != NULL ? temp->start_bar_id : 0));

  temp = top(&test);
  printf("\n[TOP] : %d", (temp != NULL ? temp->start_bar_id : 0));

  temp = pop(&test);
  printf("\n[POP] : %d", (temp != NULL ? temp->start_bar_id : 0));

  temp = pop(&test);
  printf("\n[POP] : %d", (temp != NULL ? temp->start_bar_id : 0));

  temp = pop(&test);
  printf("\n[POP] : %d", (temp != NULL ? temp->start_bar_id : 0));
}
예제 #16
0
int
main(void)
{
	stack_t stack;
	int item, i;

	init_stack(&stack);

	for (i = 0; i < 5; ++i)
		push(&stack, i);
	printf("After push, length = %d\n", length(&stack));

	pop(&stack, &item);
	printf("pop top item = %d\n", item);
	printf("After pop, length = %d\n", length(&stack));

	for (i = 0; i < 5; ++i)
		push(&stack, i + 10);
	printf("After push, length = %d\n", length(&stack));

	while ((pop(&stack, &item)) != -1)
		printf("item = %d\n", item);
	printf("After pop, length = %d\n", length(&stack));

	return 0;
}
예제 #17
0
파일: ADJMAT.C 프로젝트: gomins/AlgorithmCV
int count_components(int a[][MAX_VERTEX], int V)
    {
    int count = 0;
    int i, j;
    init_stack();
    for (i = 0; i < V; i++) check[i] = 0;
    for (i = 0; i < V; i++)
	{
	if (check[i] == 0)
	    {
	    printf("\nConnected Component %d : ", ++count);
	    push(i);
	    check[i] = 1;
	    while (!stack_empty())
		{
		i = pop();
		printf("%c ", int2name(i));
		for (j = 0; j < V; j++)
		    if (a[i][j] != 0)
			if (check[j] == 0)
			    {
			    push(j);
			    check[j] = 1;
			    }
		}
	    }
	}
    printf("\nTotally this graph has %d connected components.", count);
    return count;
    }
예제 #18
0
파일: arch.c 프로젝트: jeanbroid/mips
ARCH init_simu(void)
{
	section_t* section_ptr;
	ARCH arch;

	arch = (ARCH) calloc(1, sizeof(*arch));
	if (arch == NULL)
		return NULL;

	/* temporary alloc, mostly useful for tests */

	arch->sections[TEXT].start_addr = 0x400;
	arch->sections[BSS].start_addr = 0xc00;
	arch->sections[DATA].start_addr = 0x1400;

	for (int i = 0; i < 3 ; i++) {
		section_ptr = &(arch->sections[i]);
		section_ptr->size = 1024;
		section_ptr->data = (uchar*) calloc((section_ptr->size)*1024, sizeof(uchar));

		if (section_ptr->data == NULL)
			return NULL;
	}

	/* let's init the stack section */
	init_stack(arch);

	arch->state = NOT_LOADED;
	arch->breakpoints = init_list();

	return arch;
}
예제 #19
0
파일: ADJMAT.C 프로젝트: gomins/AlgorithmCV
void nrDFS_adjmatrix(int a[][MAX_VERTEX], int V)
    {
    int i, j;
    init_stack();
    for (i = 0; i < V; i++) check[i] = 0;
    for (i = 0; i < V; i++)
	{
	if (check[i] == 0)
	    {
	    push(i);
	    check[i] = 1;
	    while (!stack_empty())
		{
		i = pop();
		visit(i);
		for (j = 0; j < V; j++)
		    if (a[i][j] != 0)
			if (check[j] == 0)
			    {
			    push(j);
			    check[j] = 1;
			    }
		}
	    }
	}
    }
예제 #20
0
void topsort(head net[], int V)
    {         /* function for topological sorting */
    int i, j, k;
    node *ptr;

    init_stack();

    set_count_indegree(net, V);

    for (i = 0; i < V; i++)
	if (!net[i].count) /* search start position of topological sort */
	    push(i);
    for (i = 0; i < V; i++)
	{
	 /* if i < V, network has cycle, case of acyclic network
	    loop must be exhausted */
	if (stack_empty())
	    {
	    printf("\nNetwork has a cycle. Sort Terminated ! ");
	    exit(1);
	    }
	else
	    {
	    j = pop();
	    printf("%c, ", int2name(j));
	    for (ptr = net[j].next; ptr; ptr = ptr->next)
		{
		k = ptr->vertex;
		net[k].count--;
		if (!net[k].count)
		    push(k);
		}
	    }
	}
    }
예제 #21
0
void proxy_init_all(void)
{
    pj_status_t status;

    global.port = 5060;
    global.record_route = 0;

    pj_log_set_level(5);

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

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

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

    return;
}
예제 #22
0
파일: maze.c 프로젝트: Kermit95/Playground
int main()
{
	Stack s;
	init_stack(&s);
	int i = 0;
	sElemType start = {
		0,
		{
			1,
			1,
		}
	};
	sElemType curpos = start;
	welcome();
	printf("\n\n");
	print_map();
	printf("\n\nI'm going...........................\n\n");
	i = walk_maze(&curpos, s);
	printf("(@_@)\n\n");
	print_map();
	if(i == 1)
		printf("\n\nDone!\n\n");
	else
		printf("\n\nI'm missing!\n\n");

	return 0;
}
예제 #23
0
void find_max_filling_area(const int *containers, int length, int *start, int *end, int *max_area) {
  stack fill_stack;
  node *temp = NULL;
  init_stack(&fill_stack);
  int i=0;
  
  *max_area = 0;
  if(length > 0){
    temp = push(&fill_stack, containers[0]);
    for(i=1; i<length; ++i) {
      if(containers[temp->start_bar_id] <= containers[i]) {
        /* stack top bar is less than next bar
         * need to stop filling it
         * Number of bars (i - temp->start_bar_id + 1)
         * Max Area (containers[temp->start_bar_id] * #bars)
         * Push it to stack
         */

        int area = (containers[temp->start_bar_id] * (i - temp->start_bar_id + 1));
        if(area > *max_area) {
          *start = temp->start_bar_id;
          *end = i;
          *max_area = (containers[temp->start_bar_id] * (i - temp->start_bar_id + 1));
        }
        temp = pop(&fill_stack);
        temp = push(&fill_stack, i);
      } 
    }
  }
}
예제 #24
0
metalink_stack_t *metalink_stack_new(void) {
  metalink_stack_t *s = malloc(sizeof(metalink_stack_t));
  if (s) {
    init_stack(s);
  }
  return s;
}
예제 #25
0
파일: US3.C 프로젝트: coder03/ldd
main(){
	unsigned char c,x;
	int i;
	FILE *fp;
	init_stack();
	fp = fopen("abc.c","r");
	while( (i=fgetc(fp)) !=EOF ){
		c= (unsigned char) i;
		if ( (c == '{') || (c == '('))
			push(c); // add code to check for stack errors.
		if ( c == ')'){
			x=pop();
			if(x != '('){
				printf(" error in file \n");
				exit(-1);
			}
		}
		if ( c == '}'){
			x=pop();
			if(x != '{'){
				printf(" error in file \n");
				exit(-1);
			}
		}
	}
printf(" no error in file \n") ; // is it ???
	fclose(fp);
}
예제 #26
0
int main(void){

	char c;
	int i=0, j=0, k=0;
	
	PQueue *min = pq_init();	
	char array[MAX_UNIQUE_CHARS];
	char freq[MAX_UNIQUE_CHARS];
	char path[MAX_LENGTH];
	
	gets(array);
	gets(freq);
	gets(path);
	
	int r=0;
	while(array[r]!=NULL){
		Tree *node= tree_init(freq[r]-'0', array[r]);
		pq_enqueue(min, node, freq[r]-'0');
		r+=2;		
	}
	
	while(min->size > 1){
		Tree *left=pq_dequeue(min);
		Tree *right=pq_dequeue(min);
		Tree *node=tree_merge(left, right);	
		pq_enqueue(min, node, node->root->freq);		
	}

	List *l=init_list(9);
	Stack *s=init_stack();
	
	l=recursive_Encoding(min->data[0]->root, s, l);
	
	read_path(min->data[0]->root, path);
}
예제 #27
0
void quick_sort4(int a[], int n)
    {     /* remove recursion & median & small subfile insert*/
    int v, t;
    int i, j;
    int l, r;
    init_stack();
    l = 0;
    r = n-1;
    push(r);
    push(l);
    while (!is_stack_empty())
	{
	l = pop();
	r = pop();
	if (r-l+1 > 200)    /* terminal condition */
	    {
	    t = (r+l) >> 1;    /* t is middle */
	    if (a[l] > a[t])  /* sort left, middle, right */
		{
		v = a[l];
		a[l] = a[t];
		a[t] = v;
		}
	    if (a[l] > a[r])
		{
		v = a[l];
		a[l] = a[r];
		a[r] = v;
		}
	    if (a[t] > a[r])
		{
		v = a[t];
		a[t] = a[r];
		a[r] = v;
		}
	    v = a[t];    /* exchange middle with a[r-1] */
	    a[t] = a[r-1];
	    a[r-1] = v;
	    i = l;     /* partition l+1 to r-2 */
	    j = r-1;
	    while (1)      /* partition */
		{
		while (a[++i] < v);
		while (a[--j] > v);
		if (i >= j) break;
		t = a[i];
		a[i] = a[j];
		a[j] = t;
		}
	    t = a[i];
	    a[i] = a[r-1];
	    a[r-1] = t;
	    push(r);
	    push(i+1);
	    push(i-1);
	    push(l);
	    }
	else
예제 #28
0
task_t *task_create( const char *name,
					 void (*entry)(void *parameter),
					 void *parameter,
					 u16int stackSize,
					 u8int priority,
					 u16int tick){
	
	task_t *task;
	u32int *stackAddr;
	u32int task_id;
	
	task_id = get_task_id();
	if( task_id < 0 ){
		return NULL;
	}
	
	task = (task_t *)kmalloc(sizeof(task_t));
	if(task == NULL)
		return NULL;
		
	stackAddr = (void *)kmalloc(stackSize);
	if( stackAddr == NULL ){
		kfree(task);
		return NULL;
	}
	
	for( int temp=0; temp<NAME_MAXLENTH; temp++ ){
		task->name[temp] = name[temp];
	}
	
	task->task_id = task_id;
	task->entry = (void *)entry;
	task->parameter = parameter;
	task->stack_addr = stackAddr;
	task->stack_size = stackSize;
	task->node.next = NULL;
	task->node.prev = NULL;
	
	task->init_tick = tick;
	task->remaining_tick = tick;
	task->priority = priority;
	task->sp = (void *)( (void *)stackAddr + stackSize -4 );
	
	memset( (u8int *)task->stack_addr, '?', task->stack_size );
	task->sp = (void *)init_stack(task->sp,
								  task->entry,
								  task->parameter);
	task_table[task->task_id] = 1;
	
	task->timer = timer_create(task->name,
							   task_timeout,
							   task,
							   0,
							   SET_ONESHOT);
							   
	return task;
}
예제 #29
0
파일: xml.c 프로젝트: BugIsBitch/AOT
/**********************************************************************
* FUNCTION NAME:
*   save_file
*
* DESCRIPTION:
*   This function save the RAM tree info to the given file
*
* INTERFACE:
*   GLOBAL DATA:
*     None
*
*   INPUT:
*     file_name-- given file name
*     root --root of the tree 
*
*   OUTPUT:
*     None
*
*   INPUT/OUTPUT:
*     None
*
* AUTHOR:
*   Fu Pei
*
* RETURN VALUE:
*
* if save file failed return the error type otherwise return PROCESS_SUCCESS
*
*
* NOTES:
*
*********************************************************************/
int save_file(char *file_name,node_t* root)
{
	int ret = PROCESS_SUCCESS;
	FILE* file;
    stack_t stk;
	node_t *child = NULL;
	node_t* nd = NULL;
	if (file_name)
	{
		file = fopen( file_name, "w" );
	}	
	/*file open failed*/
	if ((NULL == file) ||(NULL == root) )
	{
		ret = FILE_WRITE_ERROR;
	}
	if (ret >= 0)
	{
		/*print head of xml*/
		print_declaration(file,root);
		/*create stack*/
		init_stack(&stk);
		/*push all children of the node to stack*/
		child = root->child;
		while(child)
		{
			/*push data to stack*/
			push(&stk,child);
			child = child->sibl;
		}
		/*is stack empty*/
		while (!stack_empty(&stk))
		{ 
			node_t* nd_child = NULL;
			int nd_chld_index = 0;
			/*get node from the stack*/
			pop(&stk,&nd);
			/*write node to xml file*/
			write_node_begin(file,nd);
			/*last leaf node of the tree with nd as its root*/
			write_node_end(file,nd,&stk);
			/*does nd node have child*/
			nd_child = nd->child;
			/*push all nd_child to stack*/
			while (nd_child)
			{
				push(&stk,nd_child);
				
				nd_child = nd_child->sibl;
			}/*end while*/
		}/*end while*/
		fclose(file);
	}
	
	  return ret;
}
예제 #30
0
void* do_operations(void* thread_index_void_ptr)
{
    int* thread_index_ptr = (int*)thread_index_void_ptr;

    // Get my thread info
    int num_elements_to_spawn = thread_info_array[*thread_index_ptr].num_elements_to_spawn;
    char* operation_array = thread_info_array[*thread_index_ptr].operation_array;

    // Create a stack
    STACK stack;
    init_stack(&stack);

    // Spawn elements
    int i;
    for (i = 0; i < num_elements_to_spawn; ++i)
    {
        // Create an element and push it
        ELEMENT* element = (ELEMENT*)malloc(sizeof(ELEMENT));
        element->value = i;
        push(&stack, element);
    }

    // Do operations
    for (i = 0; i < NUM_OPERATIONS; ++i)
    {
        if (ADD == operation_array[i])
        {
            // Enqueue an element
            ELEMENT* element = pop(&stack);
            if (USE_BLOCKING == mode)
            {
                add_blocking_queue(&blocking_queue, element);
            }
            else
            {
                while (!add_nonblocking_queue(&nonblocking_queue, element));
            }
        }
        else
        {
            // Dequeue an element
            ELEMENT* element = NULL;
            if (USE_BLOCKING == mode)
            {
                element = remove_blocking_queue(&blocking_queue);
            }
            else
            {
                while (!(element = remove_nonblocking_queue(&nonblocking_queue)));
            }
            push(&stack, element);
        }
    }

    return NULL;
}