示例#1
0
/** assumes given postfix expression is valid */
int evaluatePostfixExpression( char *expr ){
	//create the stack
	stackNode2Ptr stack = malloc(sizeN);
	
	int x, y;
	int i = 0;
	char c = expr[i];
	//read entire expression
	while (c != '\0' && i < 80){
		
		//check what if c is digit or operator
		if (isdigit(c)){
			// c is a number, so push2 it onto stack
			x = c - '0';
			push2(&stack, x);
		} else {
			/* c must be an operator,
			 * so have to pop2 two elements from the stack and 
			 * apply the operation */
			 x = pop2(&stack);
			 y = pop2(&stack);
			 push2(&stack, calculate2(x, y, c));
		}
		c = expr[++i];
	}
	return pop2(&stack);
} 
示例#2
0
static Boolean compNodeSetNodeSet(binaryExpr *be, expr* left, expr* right, VTDNav *vn, opType op){
	exception e;
	int i,i1,k,s1,stackSize;
	Try {
		if (be->fib1 == NULL)
			be->fib1 = createFastIntBuffer2(BUF_SZ_EXP);

	          push2(vn);
	          stackSize = vn->contextBuf2->size;
	          while ((i = be->left->evalNodeSet(be->left,vn)) != -1) {
	              i1 = getStringVal(vn,i);
	              if (i1 != -1)
	              appendInt(be->fib1,i1);
	          }
			  be->left->reset(be->left,vn);
	          vn->contextBuf2->size = stackSize;
	          pop2(vn);
	          push2(vn);
	          stackSize = vn->contextBuf2->size;
	          while ((i = be->right->evalNodeSet(be->right,vn)) != -1) {
	              i1 = getStringVal(vn,i);
	              if (i1 != -1){
	                  s1 = be->fib1->size;
	                  for (k = 0; k < s1; k++) {
		                  Boolean b = compareVV(be,intAt(be->fib1,k),vn,i1,op);
		                  if (b){
		                      clearFastIntBuffer(be->fib1);
		                      vn->contextBuf2->size = stackSize;
		        	          pop2(vn);
		        	          be->right->reset(be->right,vn);
		                      return TRUE;
		                  }
		              }
	              }
	          }
	          vn->contextBuf2->size = stackSize;
	          pop2(vn);
	          be->right->reset(be->right,vn);
	          clearFastIntBuffer(be->fib1);
	          return FALSE;

	} Catch (e) {
		if (e.et == out_of_mem){
			Throw e;
		}
		if(be->fib1!=NULL)
			clearFastIntBuffer(be->fib1);

		e.et = other_exception;
		e.msg = "undefined run time behavior in computerEQNE";
		Throw e;
	}
	return FALSE;
}
示例#3
0
int	evalNodeSet_pe (pathExpr *pe,VTDNav *vn){
	int a;
	while (TRUE) {
		switch (pe->evalState) {
		case 0: /*this state is teh initial state;*/
			a = pe->fe->evalNodeSet(pe->fe,vn);
			if (a == -1){
				pe->evalState =4;
			}
			else
				pe->evalState = 1;
			break;
		case 1: /* fe returns valid value, then iterate the locationPath*/
			push2(vn);
			a = evalNodeSet_lpe(pe->lpe, vn);
			if (a == -1) {
				reset_lpe(pe->lpe, vn);
				pe->evalState = 3;
			} else {
				pe->evalState = 2;
				if (isUnique_pe(pe,a))
					return a;
			}
			break;
		case 2:
			a = evalNodeSet_lpe(pe->lpe, vn);
			if (a == -1) {
				reset_lpe(pe->lpe, vn);
				pe->evalState = 3;
			} else{
				if (isUnique_pe(pe, a))
					return a;
				//return a;
			}
			break;
		case 3:
			pop2(vn);
			a = pe->fe->evalNodeSet(pe->fe,vn);
			if (a == -1)
				pe->evalState = 4;
			else{
			    push2(vn);
				pe->evalState = 2;
			}
			break;
		case 4:
			return -1;
		default:
			throwException2(other_exception,
				"Invalid state evaluating PathExpr");
		}
	}
}
void convert(char infix[size],char postfix[size])
{
    int i,j=0;
    char ch,op;
    struct stack s;
    s.top=-1;
    for(i=0; infix[i]!='\0'; i++)
    {
     //   display(&s);
        ch=infix[i];
        if(isopnd(ch)==1)
        {
            postfix[j]=ch;
            j++;
        }
        else if(ch=='(')
        {
            push2(&s,ch);
        }
        else if(ch==')')
        {
            char k=pop2(&s);
            while(k!='(')
            {
                postfix[j]=k;
                j++;
                k=pop2(&s);
            }
            //pop(&s);
        }
        else
        {
            while(!isempty(s))
            {
                //result=prcd(ch,s.arr[s.top]);
                if(prcd(s.arr[s.top],ch)||ch=='(')
                    break;
                op=pop2(&s);
                postfix[j]=op;
                j++;
            }
            push2(&s,ch);
        }
    }
    while(!isempty(s))
    {
        op=pop2(&s);
        postfix[j]=op;
        j++;
    }
    postfix[j]='\0';
}
int main(){
	struct doublestack dstack;
	dstack.topFirstStack =-1;
	dstack.topSecondStack =100;
	push1(&dstack,10);
	push1(&dstack,20);
	push2(&dstack,30);
	push2(&dstack,50);
	int x = pop1(&dstack);
	printf("Pop item from stack one %d \n",x);
		int y = pop2(&dstack);
		printf("Pop item from stack two %d \n",y);
}
示例#6
0
/* Driver program to test twStacks class */
int main()
{
  struct TwoStack * twoStacks = createStacks(5);
  push1(twoStacks, 5);
  push2(twoStacks, 10);
  push2(twoStacks, 15);
  push1(twoStacks, 11);
  push2(twoStacks, 7);
  printf("Popped element from stack1 is %d", pop1(twoStacks));
  push2(twoStacks, 40);
  printf("\nPopped element from stack2 is %d", pop2(twoStacks));
  return 0;
}
示例#7
0
int main()
{
	size = 5;
	top1= -1;
	top2 = 5;
	push1(5);
	push2(10);
	push1(45);
	push1(12);
	push2(41);
	printf("Element Popped from stack 1 is: %d\n",pop1());				
	printf("Element Popped from stack 2 is: %d\n",pop2());
	return 0;
}
示例#8
0
文件: main.cpp 项目: CCJY/coliru
int main(int argc, char** argv) 
{
    node* head=NULL;         //initializing head to NULL
    push(head,2);           //creating link list
    push(head,4);           //this requires &head
    push(head,8);           //link list is 8,4,2
    //selectSort(head);        //this does not require &head
    //reverse(head);          //this requires &head
    print(head);
    std::cout << "============" << std::endl;
    push2(&head, 10);
    push2(&head, 42);
    print(head);
    return 0;
}
示例#9
0
int main(void)
{
	char buf[1024] = "";
	char *p = NULL;
	fgets(buf,sizeof(buf),stdin);
	p = strtok(buf," \n");
	push2(atoi(p));
	while((p = strtok(NULL, " \n")) != NULL)
	{
		char op;
		int b, a;
		switch(*p)
		{
			case '+':
			case '-':
					//if(!is_empty())
					{
						while (top1 != 0) {
							op = pop1();
							//if(*op == ' ')
							//	break;
						b = pop2(); 
						a = pop2(); 
							if(op == '+')
						push2(a + b);
						else 
						push2(a - b);
						};
					}
						push1(*p);
						break;
	 		case '*':
			case '/':
						push1(*p);
						break;
			default: push2(atoi(p));
		}
	}
 switch(pop1()){
	 case '+': printf("%d\n",pop2() + pop2());break;
	 case '-': printf("%d\n",pop2() - pop2());break;
	 case '*': printf("%d\n",pop2() * pop2());break;
	 case '/': printf("%d\n",pop2() / pop2());break;
 }
	//printf("%d\n",pop2());
	destory();
	return 0;
}
示例#10
0
UCSChar* evalString_pe  (pathExpr *pe,VTDNav *vn){
	exception e;
	int size = vn->contextBuf2->size ,a = -1;
	push2(vn);
	Try {
		a = evalNodeSet_pe(pe,vn);
		if (a != -1) {
			if (getTokenType(vn,a) == TOKEN_ATTR_NAME) {
				a++;
			}
			if (getTokenType(vn,a) == TOKEN_STARTING_TAG) {
				a = getText(vn);
			}
		}
	} Catch (e) {
	}
	vn->contextBuf2->size = size;
	reset_pe(pe,vn);
	pop2(vn);
	Try {
		if (a != -1)
			return toString(vn,a);
	} Catch (e) {
		if (e.et ==out_of_mem){
			Throw e;
		}
	}
	return createEmptyString();

}
示例#11
0
文件: que_w_stk.c 项目: n0x3u5/Code
int pop1()
{
	if(top==-1)
		printf("Queue is empty.");
	else
		push2(stk1[top--]);
}
示例#12
0
static Boolean compNumericalNodeSet(binaryExpr *be, expr* left, expr* right, VTDNav *vn, opType op){
	exception e;
	int i,i1,stackSize;
	double d;
	Try {
		   d = be->left->evalNumber(be->left,vn);
            push2(vn);
			stackSize = vn->contextBuf2->size;
            while ((i = be->right->evalNodeSet(be->right,vn)) != -1) {
                i1 = getStringVal(vn,i);
                if (i1!=-1 && compareVNumber1(be,i1,vn,d,op)){
                    be->right->reset(be->right,vn);
                    vn->contextBuf2->size = stackSize;
                    pop2(vn);
                    return TRUE;
                }
            }
            vn->contextBuf2->size = stackSize;
            pop2(vn);
            be->right->reset(be->right,vn);
            return FALSE;
	} Catch (e) {
		e.et = other_exception;
		e.msg = "Undefined behavior in evalBoolean_be";
		Throw e;
	}
	return FALSE;
}
示例#13
0
Lisp_Object make_complex(Lisp_Object r, Lisp_Object i)
{
    Lisp_Object v, nil = C_nil;
/*
 * Here r and i are expected to be either both rational (which in this
 * context includes the case of integer values) or both of the same
 * floating point type.  It is assumed that this has already been
 * arranged by here.
 */
    if (i == fixnum_of_int(0)) return r;
    stackcheck2(0, r, i);
    push2(r, i);
    v = getvector(TAG_NUMBERS, TYPE_COMPLEX_NUM, sizeof(Complex_Number));
/*
 * The vector r has uninitialized contents here - dodgy.  If the call
 * to getvector succeeded then I fill it in, otherwise I will not
 * refer to it again, and I think that unreferenced vectors containing junk
 * are OK.
 */
    pop2(i, r);
    errexit();
    real_part(v) = r;
    imag_part(v) = i;
    return v;
}
示例#14
0
int main() {
    boost::thread pop_sync1(&popper_sync);
    boost::thread pop_sync2(&popper_sync);
    boost::thread pop_sync3(&popper_sync);

    boost::thread push1(&pusher);
    boost::thread push2(&pusher);
    boost::thread push3(&pusher);

    // Waiting for all the tasks to push
    push1.join();
    push2.join();
    push3.join();
    g_queue.flush(); 

    // Waiting for all the tasks to pop
    pop_sync1.join();
    pop_sync2.join();
    pop_sync3.join();


    // Asserting that no tasks remained,
    // and falling though without blocking
    assert(!g_queue.try_pop_task());

    g_queue.push_task(&do_nothing);
    // Asserting that there is a task,
    // and falling though without blocking
    assert(g_queue.try_pop_task());

}
示例#15
0
static Boolean compNodeSetString(binaryExpr *be, expr* left, expr* right, VTDNav *vn, opType op){
	exception e;
	int i,i1 = 0,stackSize;
	UCSChar *s=NULL;
	Boolean b;
	Try {
		    s = be->right->evalString(be->right,vn);
            push2(vn);
            stackSize = vn->contextBuf2->size;
            while ((i = be->left->evalNodeSet(be->left,vn)) != -1) {
                i1 = getStringVal(vn,i);
                if (i1 != -1){
						b = compareVString2(be,i1,vn,s,op);
						if (b==TRUE){
						be->left->reset(be->left,vn);
						vn->contextBuf2->size = stackSize;
						pop2(vn);
						free(s);
						return b;
					}
                }
            }
            vn->contextBuf2->size = stackSize;
            pop2(vn);
            be->left->reset(be->left,vn);
            b = compEmptyNodeSet(op, s);
			free(s);
			return b;
	} Catch ( e) {
		e.et = other_exception;
		e.msg = "undefined run time behavior in computerEQNE";
		Throw e;
	}
	return FALSE;
}
示例#16
0
double	evalNumber_pe (pathExpr *pe,VTDNav *vn){

	double d = 0.0;
	exception e;
	int a = -1;
	int size;
	push2(vn);
	size = vn->contextBuf2->size;
	Try {
		a =evalNodeSet_pe(pe,vn);
		if (a!=-1){
			if (getTokenType(vn,a)== TOKEN_ATTR_NAME){
				a ++;
			}else if (getTokenType(vn,a)== TOKEN_STARTING_TAG) {
				a = getText(vn);
			}
		}
	} Catch (e){
	}
	vn->contextBuf2->size = size;
	reset_pe(pe,vn);
	pop2(vn);
	Try{
		if (a!=-1) return parseDouble(vn,a);
	}Catch (e){
	}
	return 0/d;
}
示例#17
0
文件: algo.c 项目: Hyllore/push_swap
t_lst	*algo(t_lst *lst_a, t_lst *lst_b, t_lst *tmp, int c)
{
	lst_a = tmp;
	while (ft_check(lst_a, lst_b, tmp) == 0)
	{
		if (ft_check(lst_a = swap(lst_a, tmp, lst_b), lst_b, tmp) == 1)
			return (lst_a);
		c = add(lst_a, tmp, c);
		lst_a = add2(lst_a, lst_b, tmp, c);
		if (lst_a->content == c && ft_check(tmp, lst_b, tmp) == 0)
		{
			lst_a = tmp;
			lst_b = push(lst_b, lst_a, tmp, "pb ");
			lst_a = push2(lst_a, lst_b, tmp);
		}
		if (lst_a == NULL)
			while (lst_b != NULL)
			{
				if (lst_b->next == NULL)
					lst_a = push(lst_a, lst_b, tmp, "pa\n");
				else
					lst_a = push(lst_a, lst_b, tmp, "pa ");
				lst_a = tmp;
				lst_b = push3(lst_b, lst_a, tmp);
			}
	}
	return (lst_a);
}
示例#18
0
文件: expression.cpp 项目: WLBF/OJ
int result(char fir[],int plus) //算出结果 
{
    char c,ch;
    int x,y,i = 0;
    count1 = 0;
    count2 = 0;
    push2('#');
    while( fir[i]!='#' || optr[count2-1]!='#')
    {
        c = fir[i];
        if( isdigit(c) )
        {
            push1(c-'0');
            i++;
            continue;
        }
        if( isalpha(c) )
        {
            push1(c-'a'+plus);
            i++;
            continue;
        }
        if(c == '+' || c== '-'||c=='*' || c=='('||c==')'||c=='#')
        {
            switch( record(optr[count2-1],c) )
            {
                
                case -1: push2(c); i++; break;
                case 0 : pop2(); i++; break;
                case 1 : ch = pop2();
                         y = pop1();
                         x = pop1(); 
                         push1(computer(x,y,ch));
                         break;
            }
        }
        else
            i++;
    }
return opnd[count1-1];
}
示例#19
0
Lisp_Object Llcm(Lisp_Object nil, Lisp_Object a, Lisp_Object b)
{
    Lisp_Object g;
    push2(b, a);
    g = gcd(a, b);
    errexitn(2);
    pop(a);
    a = quot2(a, g);
    pop(b);
    errexit();
    a = times2(a, b);
    errexit();
    return onevalue(a);
}
示例#20
0
static Lisp_Object pluscc(Lisp_Object a, Lisp_Object b)
/*
 * Add complex values.
 */
{
    Lisp_Object c, nil;
    push2(a, b);
    c = plus2(imag_part(a), imag_part(b));
    pop2(b, a);
    errexit();
    a = plus2(real_part(a), real_part(b));
    errexit();
    return make_complex(a, c);
}
示例#21
0
void dequeue()
{
    int i;
 
    for (i = 0;i <= count;i++)
    {
        push2(pop1());
    }
    pop2();
    count--;
    for (i = 0;i <= count;i++)
    {
        push1(pop2());
    }
}
示例#22
0
void
mainloop(void) {
  unsigned char a, f, b, c, d, e, h, l;
  unsigned char r, a1, f1, b1, c1, d1, e1, h1, l1, i, iff1, iff2, im;
  unsigned short pc;
  unsigned short ix, iy, sp;
  unsigned int radjust;
  unsigned char ixoriy, new_ixoriy;
  unsigned char intsample;
  unsigned char op;

  a=f=b=c=d=e=h=l=a1=f1=b1=c1=d1=e1=h1=l1=i=r=iff1=iff2=im=0;
  ixoriy=new_ixoriy=0;
  ix=iy=sp=pc=0;
  tstates=radjust=0;

  while(1) {
    ixoriy=new_ixoriy;
    new_ixoriy=0;
    intsample=1;
    op=fetch(pc);
    pc++;
    radjust++;

    switch(op) {
      #include "z80ops.c"
    }

    syncIntWithEmuSpeed();

    if(vRefreshInt == 1 && intsample && iff1) {
      do_interrupt();
      push2(pc);
      pc=0x38;
      vRefreshInt=0;
    }

    if (reset_flag) {
      /* actually a kludge to let us do a reset */
      a=f=b=c=d=e=h=l=a1=f1=b1=c1=d1=e1=h1=l1=i=r=iff1=iff2=im=0;
      ixoriy=new_ixoriy=0;
      ix=iy=sp=pc=0;
      tstates=radjust=0;
      reset_flag = 0;
    }

  }
}
示例#23
0
void
mainloop(void) {
  unsigned char a, f, b, c, d, e, h, l;
  unsigned char r, a1, f1, b1, c1, d1, e1, h1, l1, i, iff1, iff2, im;
  unsigned short pc;
  unsigned short ix, iy, sp;
  extern unsigned long tstates,tsmax;
  unsigned int radjust;
  unsigned char ixoriy, new_ixoriy;
  unsigned char intsample;
  unsigned char op;
  
  a=f=b=c=d=e=h=l=a1=f1=b1=c1=d1=e1=h1=l1=i=r=iff1=iff2=im=0;
  ixoriy=new_ixoriy=0;
  ix=iy=sp=pc=0;
  tstates=radjust=0;
  while(1) {
    ixoriy=new_ixoriy;
    new_ixoriy=0;
    intsample=1;
    op=fetch(pc);
    pc++;
    radjust++;

    switch(op) {
      #include "z80ops.c"
    }

    if(tstates>tsmax)
      fix_tstates();

    if(interrupted == 1 && intsample && iff1) {
      do_interrupt();
      push2(pc);
      pc=0x38;
      interrupted=0;
    }

    if (reset_ace) {
      /* actually a kludge to let us do a reset */
      a=f=b=c=d=e=h=l=a1=f1=b1=c1=d1=e1=h1=l1=i=r=iff1=iff2=im=0;
      ixoriy=new_ixoriy=0;
      ix=iy=sp=pc=0;
      tstates=radjust=0;
      reset_ace = 0;
    }
  }
}
示例#24
0
Lisp_Object make_ratio(Lisp_Object p, Lisp_Object q)
/*
 * By the time this is called (p/q) must be in its lowest terms, q>0
 */
{
    Lisp_Object v, nil = C_nil;
    if (q == fixnum_of_int(1)) return p;
    stackcheck2(0, p, q);
    push2(p, q);
    v = getvector(TAG_NUMBERS, TYPE_RATNUM, sizeof(Rational_Number));
    pop2(q, p);
    errexit();
    numerator(v) = p;
    denominator(v) = q;
    return v;
}
示例#25
0
Boolean evalBoolean_pe (pathExpr *pe,VTDNav *vn){
	exception e;
	Boolean b = FALSE;
	int size;
	push2(vn);
	/* record teh stack size*/
	size = vn->contextBuf2->size;
    Try{
		b = (evalNodeSet_pe(pe,vn) != -1);
	}Catch (e){
	}
	/*rewind stack*/
	vn->contextBuf2->size = size;
	reset_pe(pe,vn);
	pop2(vn);
	return b;
}
示例#26
0
文件: stackListtest.c 项目: n-sm/qrs
int main()
{
  printf("pop(): %c\n", pop()); // 

  printf("vacia? %d\n", VACIA); //si, vacia
  printf("push('a');\n"); 
  push2('a');
  printf("vacia? %d\n", VACIA); //no, tiene 'a'
  printf("pop(): %c\n", pop()); // saco 'a'
  printf("vacia? %d  (TIENE Q DAR VACIA!!)\n", VACIA); //si, vacia


  /*
  printf("push('b');\n");
  push2('b');
  printf("vacia? %d\n", VACIA);
  printf("pop(): %c\n", pop());
  printf("vacia? %d\n", VACIA);

  printf("sd");

  nodo* t = NULL;
  if (t == NULL) printf("t es NULL\n");
  nodo n1 = { 'a', t };
  if (n1.next == NULL) printf("n1.next es NULL\n");
  t = &n1;
  if (t->next == NULL) printf("t->next es NULL\n");
  t = t->next;  
  if (t == NULL) printf("t es NULL\n");

  
  /*
  printf("pop(): %c\n", pop());
  printf("pop(): %c\n", pop());
  int i;
  for (i=0; i < 25; i++) {
    printf("push('a');\n");
    push('a');
  }
  for (i=0; i < 25; i++)
      printf("pop(): %c\n", pop());
  */             
}
示例#27
0
int main()
{
  int choice, num, exit = 0;
  while(exit != 1){
    printf("1. Input to stack-1\n"
	   "2. Input to stack-2\n"
	   "3. POP from stack-1\n"
	   "4. POO from stack-2\n"
	   "5. Print Stacks\n"
	   "6. Exit\n");
    scanf("%d", &choice);
    switch(choice){
    case 1:
      printf("Input a number to add to the stack\n");
      scanf("%d", &num);
      push1(num);
      break;
    case 2:
      printf("Input a number to add to the stack\n");
      scanf("%d", &num);
      push2(num);
      break;
    case 3:
      pop1();
      break;
    case 4:
      pop2();
      break;
    case 5:
      print();
      break;
    case 6:
      exit = 1;
      break;
    default:
      printf("Not a valid choice, Try Again!!\n");
      break;
    }
  }
}
示例#28
0
void convert(char infix[50],char prefix[50])
{
    char temp[50],out[50];
    int i,j;
    struct stack *st=(struct stack*)malloc(sizeof(struct stack));
    (*st).tos=-1;
    //reverse the infix expression
    for(i=strlen(infix)-1,j=0;i>=0;i--,j++)
    {
        temp[j]=infix[i];
    }
    temp[j]='\0';

    printf("\nThe temp expression is: %s\n",temp);
    for(i=0,j=0;temp[i]!='\0';i++)
    {
        /*if temp[i] is an operand write it to out[j]
        if it is an operator(op) and stack is empty, push it onto stack and if stack is not empty , pop from stack
        and compare the popped element and operator(op) precedence .if the precedence of popped operator is
        greater than that of the operator(op) write popped opearator into out[j] otherwise push operator(op)
        onto the stack. repeat the process
        */
        if(isopnd(temp[i]))
        {
            out[j]=temp[i];
            j++;
        }
        else if(temp[i]==')')
        {
            push2(st,temp[i]);
        }
        else if(temp[i]=='(')
        {
            char k=pop2(st);
            while(k!=')')
            {
                out[j]=k;
                j++;
                k=pop2(st);
            }
            pop2(st);
        }
        else
        {
            char op1;
            int flag=0;
            while(1)
            {
            op1=temp[i];
            if(isempty((st)))
            {
                push2(st,op1);
                flag=1;
                break;
            }
            else
            {
                char op2=pop2(st);

                if(prcd(op1,op2)||op2=='(')   //prcd op1>op2
                {
                    push2(st,op2);

                    break;
                }
                else
                {
                    out[j]=op2;
                    j++;
                }
            }
            }

        if(flag==0)
            push2(st,op1);
        }

    }
    while(!isempty(st))
    {
        printf("in");
        out[j]=pop2(st);
        j++;
    }
    out[j]='\0';
    //printf("\nThe output expression is: %s\n",out);
    //reverse the output string
    for(i=strlen(out)-1,j=0;i>=0;i--,j++)
    {
        prefix[j]=out[i];
    }
    prefix[j]='\0';
    return;


}
示例#29
0
/* ----------------------------------------------------------------------------
   function:            search_()          author:              Andrew Cave
   creation date:       09-Oct-1987        last modification:   ##-###-####
   arguments:           none.
   description:

   See PostScript reference manual page 211.

---------------------------------------------------------------------------- */
Bool search_(ps_context_t *pscontext)
{
  int32  postsize , matchsize , presize ;
  OBJECT *o1 , *o2 ;
  uint8  *str ;

  uint8  tags1 , tags2 ;
  uint8  *seek ;
  int32  stringsize ;
  OBJECT newobject = OBJECT_NOTVM_NOTHING ;

  UNUSED_PARAM(ps_context_t *, pscontext) ;

  if ( theStackSize( operandstack ) < 1 )
    return error_handler( STACKUNDERFLOW ) ;

/*  Check types. */
  o1 = stackindex( 1 , & operandstack ) ;
  o2 = theTop( operandstack ) ;
  tags1 = theTags(*o1) ;
  tags2 = theTags(*o2) ;
  if ( oType(*o1) != OSTRING || oType(*o2) != OSTRING )
    return error_handler( TYPECHECK ) ;

/*  Check access requirements. */
  if ( (!oCanRead(*o1) && !object_access_override(o1)) ||
       (!oCanRead(*o2) && !object_access_override(o2)) )
    return error_handler( INVALIDACCESS ) ;

/*  Extract the location of seek & string, and their lengths. */
  seek = oString(*o2) ;
  str = oString(*o1) ;
  matchsize = theLen(*o2) ;
  stringsize = theLen(*o1) ;

/*  Remove the trivial cases. */
  if ( stringsize == 0 ) {
    Copy(o2, &fnewobj) ;
    return TRUE ;
  }
  if ( matchsize == 0 ) {
    theTags( newobject ) = tags1 ;
    theLen( newobject )  = 0 ;
    oString( newobject ) = NULL ;
    SETGLOBJECTTO(newobject, oGlobalValue(*o1));

    if ( ! push2(&newobject, &tnewobj, &operandstack) )
      return FALSE ;

    theTags(*o2) = tags1 ;
    SETGLOBJECTTO(*o2, oGlobalValue(*o1));
    return TRUE ;
  }
  postsize = stringsize - matchsize ;
  presize = 0 ;
/*
  Compare sub-strings of string (of length match_size) with seek,
  until no sub-string left that is that long, or have found match.
*/
  while ( postsize >= 0 ) {

/*  If matched up sub-string, then setup post, match & pre. */
    if ( ! HqMemCmp( & str[ presize ] , matchsize , seek , matchsize )) {
      theTags( newobject ) = tags1 ;
      theLen( newobject )  = ( uint16 )presize ;
      oString( newobject ) = ( presize != 0 ? str : NULL ) ;
      SETGLOBJECTTO(newobject, oGlobalValue(*o1));

      if ( ! push2(&newobject, &tnewobj, &operandstack) )
        return FALSE ;

      theTags(*o2) = tags1 ;
      theLen(*o2) = ( uint16 )matchsize ;
      oString(*o2) = str + presize ;
      SETGLOBJECTTO(*o2, oGlobalValue(*o1));

      theLen(*o1) = ( uint16 )postsize ;
      oString(*o1) = ( postsize != 0 ? str + presize + matchsize : NULL ) ;
      return TRUE ;
    }
/* Otherwise look at next sub-string. */
    ++presize ;
    --postsize ;
  }
/*  No match occurred, so push the boolean false. */
  Copy(o2, &fnewobj) ;
  return TRUE ;
}
示例#30
0
Calculator::Calculator(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Calculator)
{
    ui->setupUi(this);

    pastNumber = 0;
    currentNumber = ui->lcd->value();
    state = '\0';
    point = false;
    in = false;
    count = 0;

    connect(ui->button0, SIGNAL(clicked()),
            this, SLOT(push0()));
    connect(ui->button1, SIGNAL(clicked()),
            this, SLOT(push1()));
    connect(ui->button2, SIGNAL(clicked()),
            this, SLOT(push2()));
    connect(ui->button3, SIGNAL(clicked()),
            this, SLOT(push3()));
    connect(ui->button4, SIGNAL(clicked()),
            this, SLOT(push4()));
    connect(ui->button5, SIGNAL(clicked()),
            this, SLOT(push5()));
    connect(ui->button6, SIGNAL(clicked()),
            this, SLOT(push6()));
    connect(ui->button7, SIGNAL(clicked()),
            this, SLOT(push7()));
    connect(ui->button8, SIGNAL(clicked()),
            this, SLOT(push8()));
    connect(ui->button9, SIGNAL(clicked()),
            this, SLOT(push9()));
    connect(ui->buttonDot, SIGNAL(clicked()),
            this, SLOT(pushpoint()));
    connect(ui->buttonCE, SIGNAL(clicked()),
            this, SLOT(ce()));
    connect(ui->buttonC, SIGNAL(clicked()),
            this, SLOT(c()));
    connect(ui->buttonPlus, SIGNAL(clicked()),
            this, SLOT(pushPlus()));
    connect(ui->buttonSub, SIGNAL(clicked()),
            this, SLOT(pushSub()));
    connect(ui->buttonTimes, SIGNAL(clicked()),
            this, SLOT(pushTimes()));
    connect(ui->buttonDiv, SIGNAL(clicked()),
            this, SLOT(pushDiv()));
    connect(ui->buttonEqual, SIGNAL(clicked()),
            this, SLOT(pushEqual()));

    QFont font = ui->button0->font();
    font.setPointSize(40);
    ui->button0->setFont(font);
    ui->button1->setFont(font);
    ui->button2->setFont(font);
    ui->button3->setFont(font);
    ui->button4->setFont(font);
    ui->button5->setFont(font);
    ui->button6->setFont(font);
    ui->button7->setFont(font);
    ui->button8->setFont(font);
    ui->button9->setFont(font);
    ui->buttonC->setFont(font);
    ui->buttonCE->setFont(font);
    ui->buttonEqual->setFont(font);
    ui->buttonDiv->setFont(font);
    ui->buttonTimes->setFont(font);
    ui->buttonPlus->setFont(font);
    ui->buttonSub->setFont(font);
    ui->buttonDot->setFont(font);
}