Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
/* EFUN: filter (array part)
   
   Runs all elements of an array through fun
   and returns an array holding those elements that fun
   returned 1 for.
   */
struct vector *
filter_arr(struct vector *p, struct closure *fun)
{
    struct vector *r;
    char *flags;
    int cnt,res;
    
    if (p->size<1)
	return allocate_array(0);

    res = 0;
    flags = tmpalloc((size_t)p->size + 1); 
    for (cnt = 0; cnt < p->size; cnt++) {
	push_svalue(&p->item[cnt]);
	(void)call_var(1, fun);
	if (sp->type == T_NUMBER && sp->u.number) {
	    flags[cnt] = 1; 
	    res++; 
	} else
	    flags[cnt] = 0;
	pop_stack();
    }
    r = allocate_array(res);
    for (cnt = res = 0; res < r->size && cnt < p->size; cnt++) {
	if (flags[cnt]) 
	    assign_svalue_no_free(&r->item[res++], &p->item[cnt]);
    }
/*    tmpfree(flags); */
    return r;
}
Ejemplo n.º 3
0
static int
php_roxen_low_ub_write(const char *str, uint str_length) {
  int sent_bytes = 0;
  struct pike_string *to_write = NULL;
#ifdef ZTS
  PLS_FETCH();
#endif
#ifdef ROXEN_USE_ZTS
  GET_THIS();
#endif
  if(!MY_FD_OBJ->prog) {
    PG(connection_status) = PHP_CONNECTION_ABORTED;
    zend_bailout();
    return -1;
  }
  to_write = make_shared_binary_string(str, str_length);
  push_string(to_write);
  safe_apply(MY_FD_OBJ, "write", 1);
  if(Pike_sp[-1].type == PIKE_T_INT)
    sent_bytes = Pike_sp[-1].u.integer;
  pop_stack();
  if(sent_bytes != str_length) {
    /* This means the connection is closed. Dead. Gone. *sniff*  */
    php_handle_aborted_connection();
  }
  return sent_bytes;
}
/* virtual */ void CollisionShapeNodeVisitor::visit(CollisionShapeNode* node) {

  pop_stack(node);
  math::mat4 curr_matrix(matrix_stack_.top() * node->get_transform());

  if (shape_index_ >= rigid_body_->shapes().size()) {
    rigid_body_->shapes().push_back(RigidBodyNode::ShapeElement());
    resync_ = true;
  }
  RigidBodyNode::ShapeElement& sh = rigid_body_->shapes().at(shape_index_);
  if (sh.transform != curr_matrix) {
    sh.transform = curr_matrix;
    resync_ = true;
  }
  if (sh.shape_name != node->data.get_shape()) {
    sh.shape =
        CollisionShapeDatabase::instance()->lookup(node->data.get_shape());
    sh.shape_name = node->data.get_shape();
    resync_ = true;
  }
  ++shape_index_;

  // visit children of the collision shape
  if (node->has_children()) {
    push_stack(curr_matrix);

    for (auto child : node->children_)
      child->accept(*this);
  }
}
Ejemplo n.º 5
0
void release_stack(struct node* p_top)
{
	while(is_empty(p_top) == NON_EMPTY)
	{
		pop_stack(p_top);
	}
}
Ejemplo n.º 6
0
static void pextsFatalError(void *ctx, const char *msg, ...)
{
  char    *vmsg;
  va_list  ap;
  
  DBG_FUNC_ENTER();
  if (CB_ABSENT(fatalErrorSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  /* I'm being lazy here :> */
  vmsg = NULL;
  va_start(ap, msg);
  if (vasprintf(&vmsg, msg, ap) < -1)
    push_int(0);
  else {
    push_text(vmsg);
    free(vmsg);
  }
  push_svalue(&THIS->user_data);
  CB_CALL(fatalErrorSAX, 3);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}
Ejemplo n.º 7
0
static void pipe_read_input_callback(INT32 args)
{
  struct input *i;
  struct pike_string *s;

  if (args<2 || sp[1-args].type!=T_STRING)
    Pike_error("Illegal argument to pipe->read_input_callback\n");
   
  i=THIS->firstinput;

  if (!i)
    Pike_error("Pipe read callback without any inputs left.\n");

  s=sp[1-args].u.string;

  if(append_buffer(s))
  {
    /* THIS DOES NOT WORK */
    push_int(0);
    push_int(0);
    push_callback(offset_input_close_callback);
    apply_low(i->u.obj,i->set_nonblocking_offset,3);
    pop_stack();
    THIS->sleeping=1;
  }

  low_start();
  pop_n_elems(args-1);
}
Ejemplo n.º 8
0
Archivo: db.c Proyecto: BPotato/fluffos
void f_db_fetch (void)
{
	db_t *db;
	array_t *ret;

	valid_database("fetch", &the_null_array);

	db = find_db_conn((sp-1)->u.number);
	if (!db) {
		error("Attempt to fetch from an invalid database handle\n");
	}

	if (db->type->fetch) {
		ret = db->type->fetch(&(db->c), sp->u.number);
	} else {
		ret = &the_null_array;
	}

	pop_stack();
	if (!ret) {
		if (db->type->error) {
			char *errormsg;

			errormsg = db->type->error(&(db->c));
			put_malloced_string(errormsg);
		} else {
			sp->u.number = 0;
		}
	} else {
		put_array(ret);
	}
}
Ejemplo n.º 9
0
void do_clear (stack *stack) {
   DEBUGF ('m', "stack=%p\n", stack);
   while (! empty_stack (stack)) {
      bigint *bigint = pop_stack (stack);
      free_bigint (bigint);
   }
}
Ejemplo n.º 10
0
static void pextsElementDecl(void *ctx, const xmlChar *name, int type, xmlElementContentPtr content)
{
  struct mapping  *cmap;
  
  DBG_FUNC_ENTER();
  if (CB_ABSENT(elementDeclSAX)) {
    DBG_FUNC_LEAVE();
    return;
  }

  THIS->ctxt = (xmlParserCtxtPtr)ctx;
  
  push_object(this_object());
  safe_push_text(name);
  push_int(type);
  cmap = tree2mapping(content);
  if (cmap)
    push_mapping(cmap);
  else
    push_int(0);
  push_svalue(&THIS->user_data);
  
  CB_CALL(elementDeclSAX, 5);
  pop_stack();
  
  DBG_FUNC_LEAVE();
}
Ejemplo n.º 11
0
void
f_crypt (void)
{
    const char *res, *p;
    char salt[SALT_LEN + 1];
    const char *choice =
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./";

    if (sp->type == T_STRING && SVALUE_STRLEN(sp) >= 2) {
        p = sp->u.string;
    } else {
        int i;
        
        for (i = 0; i < SALT_LEN; i++)
            salt[i] = choice[random_number(strlen(choice))];

        salt[SALT_LEN] = 0;
        p = salt;
    }
    
    res = string_copy(CRYPT((sp-1)->u.string, p), "f_crypt");
    pop_stack();
    free_string_svalue(sp);
    sp->subtype = STRING_MALLOC;
    sp->u.string = res;
}
Ejemplo n.º 12
0
void f_bson_buf_find(void){
	int size;
	bson b[1];
	bson  sub;
	svalue_t v;
	bson_iterator it;

	size = (sp-1)->u.buf->size;
	bson_init_empty(b);
	bson_init_size( b, size );
	memcpy(b->data, (sp-1)->u.buf->item, size);
	b->finished = 1;

	/* buff不合法 */
	if(bson_size(b) != size){
		pop_n_elems(st_num_arg);
		push_number(0);
		goto free_bson;
	}
	/* 找不到数据 */
	if(!bson_find( &it, b, sp->u.string )){
		pop_n_elems(st_num_arg);
		push_number(0);
		goto free_bson;
	}
	bson_to_v(&it, &v);
	free_buffer((sp-1)->u.buf);
	pop_stack();
	*sp = v;
free_bson:
	bson_destroy( b );
}
Ejemplo n.º 13
0
Archivo: rcs.c Proyecto: johan/pike
static void f_tokenize( INT32 args )
{
    if( !args || Pike_sp[-args].type != PIKE_T_STRING )
        Pike_error("Illegal argument 1 to tokenize\n");
    tokenize( Pike_sp[-args].u.string );
    stack_swap();
    pop_stack();
}
Ejemplo n.º 14
0
// X5:	consulta (pilha de operadores, Y);
//		Se Y != "(": executa GERACÓDIGO, detalhada adiante;. GO TO X5.
//		Se Y =	"(":	desempilha (pilha de operadores, Y);
void jj_expressao_5() {
	if (strcmp(consulta_pilha(pilha_operadores), "(") != 0) {
		jj_gera_codigo();
		jj_expressao_5();
	} else {
		pop_stack(&pilha_operadores);
	}
}
Ejemplo n.º 15
0
int dispose_stack(stack* s, void (*ufree)(void*)) {
	void* data;
	while ((data = pop_stack(s)) != NULL) {
		ufree(data);
	}
	free(s);
	return 1;
}
Ejemplo n.º 16
0
bool script::op_checksig(const message::transaction& parent_tx, 
        uint32_t input_index)
{
    if (stack_.size() < 2)
        return false;
    data_chunk pubkey = pop_stack(), signature = pop_stack();

    script script_code;
    for (operation op: operations_)
    {
        if (op.data == signature || op.code == opcode::codeseparator)
            continue;
        script_code.push_operation(op);
    }

    elliptic_curve_key key;
    key.set_public_key(pubkey);

    uint32_t hash_type = 0;
    hash_type = signature.back();
    signature.pop_back();
    BITCOIN_ASSERT(signature.size() == 70);

    if (hash_type != 1)
    {
        log_error() << "Unimplemented hash_type";
        return false;
    }

    if (input_index >= parent_tx.inputs.size())
    {
        log_fatal() << "script::op_checksig() : input_index " << input_index
                << " is out of range.";
        return false;
    }

    message::transaction tx_tmp = parent_tx;
    // Blank all other inputs' signatures
    for (message::transaction_input& input: tx_tmp.inputs)
        input.input_script = script();
    tx_tmp.inputs[input_index].input_script = script_code;

    hash_digest tx_hash = hash_transaction(tx_tmp, hash_type);
    return key.verify(tx_hash, signature);
}
Ejemplo n.º 17
0
void f_strwidth(){
  int len = SVALUE_STRLEN(sp);
  int width = 0;
  int i;
  for(i=0; i<len; i++)
    width += !(((sp->u.string[i]) & 0xc0) == 0x80);
  pop_stack();
  push_number(width);
}
Ejemplo n.º 18
0
/*
对栈进行模拟插入排序操作
*/
PSTACK sort_stack(PSTACK pS)
{
	PSTACK pS1 = create_stack();

	while(!is_empty(pS))
	{
		int pop_pSData;
		pop_stack(pS,&pop_pSData);
		while(!is_empty(pS1) && pop_pSData<pS1->pTop->data)
		{
			int pop_pS1Data;
			pop_stack(pS1,&pop_pS1Data);
			push_stack(pS,pop_pS1Data);
		}
		push_stack(pS1,pop_pSData);
	}
	return pS1;
}
Ejemplo n.º 19
0
void
f_disassemble_class() {
   array_t *arr;
   if( sp->type != T_CLASS )
     error( "Argument to disassemble_class() not a class.\n" );
   arr = copy_array( sp->u.arr );
   pop_stack();
   push_refed_array(arr);
}
Ejemplo n.º 20
0
/*
用两个栈模拟出队
*/
bool delete_Queue(PSTACK pS1,PSTACK pS2,int *pData)
{
	if(is_empty(pS1) && is_empty(pS2))
		return false;
	if(!is_empty(pS2))
		pop_stack(pS2,pData);
	else if(!is_empty(pS1))
	{
		while(!is_empty(pS1))
		{
			int pS1_popData;
			pop_stack(pS1,&pS1_popData);
			push_stack(pS2,pS1_popData);
		}
		pop_stack(pS2,pData);
	}
	return true;
}
Ejemplo n.º 21
0
void
f_socket_listen (void)
{
    int i, fd, port;
    char addr[ADDR_BUF_SIZE];

    fd = (sp - 1)->u.number;
    get_socket_address(fd, addr, &port, 0);

    if (VALID_SOCKET("listen")) {
	i = socket_listen(fd, sp);
	pop_stack();
        sp->u.number = i;
    } else {
	pop_stack();
        sp->u.number = EESECURITY;
    }
}
Ejemplo n.º 22
0
double
evaluate_expression(ListElmts *outputList)
{
   if(!outputList || outputList->type !=0)
   {
     print_error("Expression mal formée");
     exit(0); 
   }
   ListElmts *current,
             *stack = NULL,
             rslt
   ;
   current = outputList;
   while(current != NULL)
   {
      if(is_operand(current))
      {
         if(push_stack(&stack, current)!= TRUE)
         {
            print_error("Malloc");
            exit(0);
         }
      }
      else
      {

         if(stack->next == NULL)
         {
            print_error("Expression mal formée");
            exit(0);
         }
         rslt = make_operation(stack->next, stack, current);
         pop_stack(&stack);
         pop_stack(&stack);
         if(push_stack(&stack, &rslt)!=TRUE)
         {
            print_error("Malloc");
            exit(0);
         }
      }
      current = current->next;
   }
   return stack->data;
}
Ejemplo n.º 23
0
static void image_ttf_face_names(INT32 args)
{
   int n,i;
   int has[8]={0,0,0,0,0,0,0,0}; /* iso8859=20, unicode=30, any=1 */
   char *hasname[8]={"copyright","family","style","full",
		     "expose","version","postscript","trademark"};
   struct array *a,*b;

   image_ttf_face__names(args);

   if (sp[-1].type!=T_ARRAY)
      Pike_error("Image.TTF.Face->names(): internal error, weird _names()\n");

   a=sp[-1].u.array;

   n=0;
   for (i=0; i<a->size; i++)
   {
      int ihas=1;
      int what;
      b=a->item[i].u.array;

      what=b->item[3].u.integer;
      if (what>=8 || what<0) continue; /* weird */
      switch (b->item[0].u.integer*100+b->item[1].u.integer)
      {
	 case 301: /* M$:  unicode */
	 case 300: /* M$:  unicode (?) */
	    ihas=30;
	    break;
	 case 202: /* ISO: iso-8859-1 */
	    ihas=20;
	    break;
      }
      if (ihas<has[what]) continue; /* worse */

      push_text(hasname[what]);

      if (ihas==30) /* unicode, M$ but weird enough correct byteorder */
      {
	 ptrdiff_t n = b->item[4].u.string->len/2;
	 struct pike_string *ps=begin_wide_shared_string(n,1);
	 p_wchar1 *d=STR1(ps);
	 p_wchar0 *s=STR0(b->item[4].u.string);
	 while (n--) *(d++)=((p_wchar1)s[0]<<8)|(p_wchar1)s[1],s+=2;
	 push_string(end_shared_string(ps));
      }
      else
	 push_svalue(b->item+4);

      n++;
   }
   f_aggregate_mapping(n*2);
   stack_swap();
   pop_stack();
}
Ejemplo n.º 24
0
bool script::op_hash160()
{
    if (stack_.size() < 1)
        return false;
    data_chunk data = pop_stack();
    short_hash hash = generate_ripemd_hash(data);
    data_chunk raw_hash(hash.begin(), hash.end());
    stack_.push_back(raw_hash);
    return true;
}
Ejemplo n.º 25
0
/* Free an input struct and all that it stands for */
static INLINE void free_input(struct input *i)
{
  debug_malloc_touch(i);

  ninputs--;
  switch (i->type)
  {
  case I_OBJ:
  case I_BLOCKING_OBJ:
    if (!i->u.obj) break;
    if (i->u.obj->prog)
    {
#ifdef BLOCKING_CLOSE
      apply_low(i->u.obj,i->set_blocking_offset,0);
      pop_stack();
#endif
      apply(i->u.obj,"close",0);
      pop_stack();
      destruct(i->u.obj);
    }
    free_object(i->u.obj);
    nobjects--;
    i->u.obj=0;
    break;

  case I_STRING:
    free_string(i->u.str);
    nstrings--;
    break;

  case I_MMAP:
#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP)
    munmap(i->u.mmap,i->len);
    mmapped -= i->len;  
#else
    Pike_error("I_MMAP input when MMAP is diabled!");
#endif
    break;

  case I_NONE: break;
  }
  free((char *)i);
}
Ejemplo n.º 26
0
/***************************************************************************//**
 * @author Hayden Waisanen
 *
 * @par Description:
 *    Pops previous file descriptor off stock and restores it to the specified
 *    input or output.
 *
 * @par Class:
 *    Reroute
 *
 * @param[in] int file_no - Redirect STDIN, 0, or STDOUT, 1
 *
 * @returns bool - success or failure
 *
 ******************************************************************************/
bool Reroute::restore(int file_no)
{
   //Pop previous output file descriptor off the stack
   int restore_file_no = pop_stack(file_no);

   close(file_no); // Cloe the current file descriptor
   dup2(restore_file_no, file_no); //Restore descriptor
   close(restore_file_no); //Close useless decriptor
   return true;
}
Ejemplo n.º 27
0
static void pop_strong(graph_search* gs, int v) {
  gs->components_found++;
	printf("%d is in component %d \n", v, gs->components_found);
	gs->scc[v] = gs->components_found;
	
  int* ip = (int*)pop_stack(&(gs->strong));
  int t = (ip != NULL ? *ip : NONE);
  free(ip);	  

	while(!(t == v || empty_stack(gs->strong))) {
		gs->scc[t] = gs->components_found;
		printf("%d is in component %d with %d \n", t, gs->components_found, v);

    ip = (int*)pop_stack(&(gs->strong));
    t = (ip != NULL ? *ip : NONE);

    free(ip);	  
	}
}
Ejemplo n.º 28
0
struct vector *
make_unique(struct vector *arr, struct closure *fun, struct svalue *skipnum)
{
    struct vector *res, *ret;
    struct unique *head, *nxt, *nxt2;
    
    int cnt, ant, cnt2;
    
    if (arr->size < 1)
	return allocate_array(0);

    head = 0; 
    ant = 0; 
    INCREF(arr->ref);
    for(cnt = 0; cnt < arr->size; cnt++) 
    {
	if (arr->item[cnt].type == T_OBJECT)
	{
            push_svalue(&arr->item[cnt]);
            (void)call_var(1, fun);

	    if ((!sp) || (sp->type != skipnum->type) || !equal_svalue(sp, skipnum)) 
	    {
		if (sp) 
		{
		    ant = put_in(&head, sp, &(arr->item[cnt]));
		}
	    }

            pop_stack();
	}
    }
    DECREF(arr->ref);
    ret = allocate_array(ant);
    
    for (cnt = ant - 1; cnt >= 0; cnt--) /* Reverse to compensate put_in */
    {
	ret->item[cnt].type = T_POINTER;
	ret->item[cnt].u.vec = res = allocate_array(head->count);
	nxt2 = head;
	head = head->next;
	cnt2 = 0;
	while (nxt2) 
	{
	    assign_svalue_no_free (&res->item[cnt2++], nxt2->val);
	    free_svalue(&nxt2->mark);
	    nxt = nxt2->same;
/*	    tmpfree((char *) nxt2); */
	    nxt2 = nxt;
	}
	if (!head) 
	    break; /* It shouldn't but, to avoid skydive just in case */
    }
    return ret;
}
Ejemplo n.º 29
0
int main(){

  make_dummy_stack();
  print_stack();

  pop_stack(2);
  print_stack();
  push_stack(1, 23);
  print_stack();
  push_stack(2, 45);
  print_stack();
  pop_stack(1);
  print_stack();
  push_stack(1, 32);
  print_stack();
  pop_stack(2);
  print_stack();

  return 0;
}
Ejemplo n.º 30
0
void __parser(lp_token** input,
              int count)
{
  success=false;
  int top_state=0;
  int input_index=0;
  int accept_state=16;
  int pop_count=0;
  int action=0;

  //initialize the stack at state 0
  pcstack* parse_stack=new_pcstack();
  push_stack(parse_stack,(void*)new_token(0,0));

  while(true)
  {
    top_state=((lp_token*)peek_stack(parse_stack))->lex_id;
    if(input_index==count)action=parse_table[top_state][12];
    else if(input[input_index]->lex_id>=12)return;
    else action=parse_table[top_state][input[input_index]->lex_id];

    if(action==accept_state)//accept
    {
      action=-((lp_token*)peek_stack(parse_stack))->lex_id;
      __prh(&action,parse_stack);
      //printf("accept\n");
      success=true;
      return;
    }
    if(action>0)//shift
    {
      //printf("shift\n");
      push_stack(parse_stack,(void*)new_token(action,input[input_index]->lex_val));
      ++input_index;
    }
    else if(action<0)//reduce
    {
      pop_count=__prh(&action,parse_stack);
      if(pop_count==-1)break;//catch errors here
      while(pop_count>0)
      {
        pop_stack(parse_stack);
        --pop_count;
      }
      push_stack(parse_stack,(void*)new_token(parse_table[((lp_token*)peek_stack(parse_stack))->lex_id][action],0));
      //printf("reduce\n");
    }
    else//error
    {
      //printf("error\n");
      return;
    }
  }
}