コード例 #1
0
slist slist_insert(slist lista, int ind, int dato)
{
  int lon = slist_length(lista);
  int i;
  slist nodoAux = slist_create();
  slist nodoNuevo = slist_create();
  slist listaAux = lista;

  if( ind == 0)
  {
    lista = slist_preppend(lista, dato);
    return lista;
  }

  if( ind == lon)
  {
    lista = slist_append(lista, dato);
    return lista;
  }

  if( ind > 0 && ind < lon)
  {
    nodoNuevo = slist_append(nodoNuevo, dato);
    for(i = 0; i < ind - 1; lista = slist_next(lista), i++)
      ;
    nodoAux = slist_next(lista);
    slist_next(lista) = nodoNuevo;
    slist_next(nodoNuevo) = nodoAux;
  }
  return listaAux;
}
コード例 #2
0
ファイル: llcurl.cpp プロジェクト: AGoodPerson/Ascent
void LLCurl::Easy::prepRequest(const std::string& url,
							   const std::vector<std::string>& headers,
							   ResponderPtr responder, bool post)
{
	resetState();
	
	if (post) setoptString(CURLOPT_ENCODING, "");

//	setopt(CURLOPT_VERBOSE, 1); // usefull for debugging
	setopt(CURLOPT_NOSIGNAL, 1);

	if (LLSocks::getInstance()->isHttpProxyEnabled())
	{
		std::string address = LLSocks::getInstance()->getHTTPProxy().getIPString();
		U16 port = LLSocks::getInstance()->getHTTPProxy().getPort();
		setoptString(CURLOPT_PROXY, address.c_str());
		setopt(CURLOPT_PROXYPORT, port);
		if (LLSocks::getInstance()->getHttpProxyType() == LLPROXY_SOCKS)
		{
			setopt(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
		}
		else
		{
			setopt(CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
		}
	}

	mOutput.reset(new LLBufferArray);
	setopt(CURLOPT_WRITEFUNCTION, (void*)&curlWriteCallback);
	setopt(CURLOPT_WRITEDATA, (void*)this);

	setopt(CURLOPT_READFUNCTION, (void*)&curlReadCallback);
	setopt(CURLOPT_READDATA, (void*)this);
	
	setopt(CURLOPT_HEADERFUNCTION, (void*)&curlHeaderCallback);
	setopt(CURLOPT_HEADERDATA, (void*)this);

	setErrorBuffer();
	setCA();

	setopt(CURLOPT_SSL_VERIFYPEER, true);
	setopt(CURLOPT_TIMEOUT, CURL_REQUEST_TIMEOUT);

	setoptString(CURLOPT_URL, url);

	mResponder = responder;

	if (!post)
	{
		slist_append("Connection: keep-alive");
		slist_append("Keep-alive: 300");
		// Accept and other headers
		for (std::vector<std::string>::const_iterator iter = headers.begin();
			 iter != headers.end(); ++iter)
		{
			slist_append((*iter).c_str());
		}
	}
}
コード例 #3
0
ファイル: llcurl.cpp プロジェクト: HizWylder/GIS
void LLCurl::Easy::prepRequest(const std::string& url,
							   const std::vector<std::string>& headers,
							   ResponderPtr responder, S32 time_out, bool post)
{
	resetState();
	
	if (post) setoptString(CURLOPT_ENCODING, "");

	//setopt(CURLOPT_VERBOSE, 1); // useful for debugging
	setopt(CURLOPT_NOSIGNAL, 1);

	// Set the CURL options for either Socks or HTTP proxy
	LLProxy::getInstance()->applyProxySettings(this);

	mOutput.reset(new LLBufferArray);
	mOutput->setThreaded(true);
	setopt(CURLOPT_WRITEFUNCTION, (void*)&curlWriteCallback);
	setopt(CURLOPT_WRITEDATA, (void*)this);

	setopt(CURLOPT_READFUNCTION, (void*)&curlReadCallback);
	setopt(CURLOPT_READDATA, (void*)this);
	
	setopt(CURLOPT_HEADERFUNCTION, (void*)&curlHeaderCallback);
	setopt(CURLOPT_HEADERDATA, (void*)this);

	// Allow up to five redirects
	if (responder && responder->followRedir())
	{
		setopt(CURLOPT_FOLLOWLOCATION, 1);
		setopt(CURLOPT_MAXREDIRS, MAX_REDIRECTS);
	}

	setErrorBuffer();
	setCA();

	setopt(CURLOPT_SSL_VERIFYPEER, true);
	
	//don't verify host name so urls with scrubbed host names will work (improves DNS performance)
	setopt(CURLOPT_SSL_VERIFYHOST, 0);
	setopt(CURLOPT_TIMEOUT, llmax(time_out, CURL_REQUEST_TIMEOUT));

	setoptString(CURLOPT_URL, url);

	mResponder = responder;

	if (!post)
	{
		slist_append("Connection: keep-alive");
		slist_append("Keep-alive: 300");
		// Accept and other headers
		for (std::vector<std::string>::const_iterator iter = headers.begin();
			 iter != headers.end(); ++iter)
		{
			slist_append((*iter).c_str());
		}
	}
}
コード例 #4
0
slist slist_concat(slist l1, slist l2)
{
  slist listaNueva = slist_create();

  for( ; l1 != slist_empty(); l1 = slist_next(l1))
    listaNueva = slist_append(listaNueva, slist_data(l1));
  for( ; l2 != slist_empty(); l2 = slist_next(l2))
    listaNueva = slist_append(listaNueva, slist_data(l2));

  return listaNueva;
}
コード例 #5
0
ファイル: aho-corasick.c プロジェクト: caidongyun/ahocorasick
int
aho_corasick_maketree(aho_corasick_t *in)
{
	slist_t queue;
	aho_corasick_state_t *state,*s,*r;
	aho_corasick_t *g = in;
	int i;

	slist_init(&queue);

	// Set all FAIL transition of 0 state to point to itself
	for(i = 0; i < AHO_CORASICK_CHARACTERS ;i++)
	{
		if ( aho_corasick_goto_get(g->zerostate,i) == FAIL )
			aho_corasick_goto_set(g->zerostate, i, g->zerostate);
		// Construct fail()
		else
		{
			if ( slist_append(&queue,aho_corasick_goto_get(g->zerostate,i)) < 0 )
				goto fail;
			aho_corasick_fail(aho_corasick_goto_get(g->zerostate,i)) = g->zerostate;
		}
	}

	// Set fail() for depth > 0
	while( (r = slist_pop_first(&queue)) != NULL )
	{
		for(i = 0; i < AHO_CORASICK_CHARACTERS ;i++)
		{
			if ( (s = aho_corasick_goto_get(r,i)) == FAIL )
				continue;
			if ( slist_append(&queue,s) < 0 )
				goto fail;
			state = aho_corasick_fail(r);
			while( aho_corasick_goto_get(state,i) == FAIL )
				state = aho_corasick_fail(state);
			aho_corasick_fail(s) = aho_corasick_goto_get(state,i);
			debug(printf("Setting f(%u) == %u\n",s->id,
				     aho_corasick_goto_get(state,i)->id));
			// Join outputs missing
		}
	}

	slist_destroy(&queue,SLIST_LEAVE_DATA);
	return 0;

fail:
	slist_destroy(&queue,SLIST_LEAVE_DATA);
	return -1;
}
コード例 #6
0
/**
 * Invalidate possibly cached page.
 *
 * This is used when we know a new and fresh copy of the page is held on
 * the disk.  Further access to the page will require reloading the
 * page from disk.
 */
void
lru_invalidate(DBM *db, long bno)
{
	struct lru_cache *cache = db->cache;
	void *value;

	if (
		g_hash_table_lookup_extended(cache->pagnum,
			ulong_to_pointer(bno), NULL, &value)
	) {
		long idx = pointer_to_int(value);

		g_assert(idx >= 0 && idx < cache->pages);
		g_assert(cache->numpag[idx] == bno);

		/*
		 * One should never be invalidating a dirty page, unless something
		 * went wrong during a split and we're trying to undo things.
		 * Since the operation will cause a data loss, warn.
		 */

		if (cache->dirty[idx]) {
			g_warning("sdbm: \"%s\": %s() invalidating dirty page #%ld",
				db->name, stacktrace_caller_name(1), bno);
		}

		hash_list_remove(cache->used, value);
		g_hash_table_remove(cache->pagnum, ulong_to_pointer(bno));
		cache->numpag[idx] = -1;
		cache->dirty[idx] = FALSE;
		slist_append(cache->available, value);	/* Make index available */
	}
}
コード例 #7
0
ファイル: pmsg.c プロジェクト: qgewfg/gtk-gnutella
/**
 * Appends `n_bytes' to the pmsg_t buffer. If the last pmsg_t is writable
 * it is filled with as much data as space is still available. Otherwise
 * or if this space is not sufficient another pmsg_t is created and
 * appendded to the list.
 */
void
pmsg_slist_append(slist_t *slist, const void *data, size_t n_bytes)
{
	pmsg_t *mb;

	g_assert(slist);

	if (0 == n_bytes)
		return;
	g_assert(NULL != data);

	mb = slist_tail(slist);
	if (mb && pmsg_is_writable(mb)) {
		size_t n;

		n = pmsg_write(mb, data, n_bytes);
		data = (const char *) data + n;
		n_bytes -= n;
	}
	if (n_bytes > 0) {
		mb = pmsg_new(PMSG_P_DATA, NULL, MAX(n_bytes, PMSG_SLIST_GROW_MIN));
		pmsg_write(mb, data, n_bytes);
		slist_append(slist, mb);
	}
}
コード例 #8
0
ファイル: slist.cpp プロジェクト: jmgunn87/lp3
slist* slist_range(slist* list,
                   int from,
                   int to)
{
  slist* ret=0;
  slist_elem* it=0;

  if(!list)
    return ret;
  if(from>list->_size||
     to>list->_size||to<from)
    return ret;

  it=slist_elem_at(list,from);
  if(!it)
    return ret;

  to-=from;
  ret=new_slist();
  while(it&&to)
  {
    slist_append(ret,it->_data);
    it=it->_next;
    --to;
  }
  return ret;
}
コード例 #9
0
ファイル: event.c プロジェクト: inscriptionweb/pikrellcam
void
at_command_add(char *at_line)
	{
	AtCommand	*at;
	char		 frequency[32], at_time[64], cmd[200];
	int			 n;

	frequency[0] = '\0';
	n = sscanf(at_line, "%31s %63s \"%199[^\n\"]", frequency, at_time, cmd);
	if (frequency[0] == '#' || frequency[0] == '\n' || frequency[0] == '\0')
		return;
	if (n != 3)
		{
		log_printf_no_timestamp("Bad at command: %s\n", at_line);
		return;
		}
	at = (AtCommand *) calloc(1, sizeof(AtCommand));
	at->frequency = strdup(frequency);
	at->at_time = strdup(at_time);
	at->command = strdup(cmd);
	at_command_list = slist_append(at_command_list, at);

	log_printf_no_timestamp("at_command_add [%s] at: %s  command: [%s]\n",
				at->frequency, at->at_time, at->command);
	}
コード例 #10
0
ファイル: parser.cpp プロジェクト: jmgunn87/clrgen
slist* parse_bnf(char* input)
{
  if(!input)return 0;

  slist* items=new_slist();
  slist* lexed_in=lex_bnf(input);
  lp_token** lex_arr=(lp_token**)calloc(lexed_in->_size,sizeof(lp_token*));
  int last_item=0;
  int i=0;
  slist_elem* sle=lexed_in->_head;

  for(;i<lexed_in->_size&&sle;++i,sle=sle->_next)
  {
    lex_arr[i]=(lp_token*)sle->_data;
    if(lex_arr[i]->lex_id==SEMI_COLON)
    {
      __parser(&lex_arr[last_item],(i-last_item)+1);
      last_item=i+1;
      if(success)
        slist_append(items,(void*)item);
      else return 0;
    }
  }
  free(lex_arr);
  slist_destroy(lexed_in);
  return items;
}
コード例 #11
0
ファイル: cmp_groupcounter.c プロジェクト: balazskreith/ntrt
void* _groupcounter_start()
{
  CMP_DEF_THIS(cmp_groupcounter_t, _cmp_groupcounter);
  pcap_listener_t *pcap_listener;
  groupcounters_holder_t* holder;
  groupcounter_prototype_t *prototype;
  groupcounter_t* groupcounter;
  slist_t* it;
  int32_t index;

  dmap_rdlock_table_pcapls();
  dmap_rdlock_table_groupcounter_protos();
  for(index = 0; dmap_itr_table_pcapls(&index, &pcap_listener) == BOOL_TRUE; ++index){
    it     = pcap_listener->groupcounter_prototypes;
    holder = &this->holders[index];
    for(; it; it = it->next){
      prototype = it->data;
      groupcounter = make_groupcounter(prototype);
      holder->groupcounters = slist_append(holder->groupcounters, groupcounter);
      groupcounter->interface.init(groupcounter, pcap_listener);
    }
  }
  dmap_rdunlock_table_groupcounter_protos();
  dmap_rdunlock_table_pcapls();

  return NULL;
}
コード例 #12
0
ファイル: test-slist.c プロジェクト: vdt/libcore
void test_slist_append_to_empty(void)
{
    unsigned long *val = NULL;

    assert_true(test_slist == NULL);

    test_slist = slist_create();

    assert_true(test_slist != NULL);
    assert_true(slist_is_empty(test_slist));

    val = make_ulong_ptr(9999);
    assert_true(val != NULL);

    assert_true(slist_append(test_slist, val) == 0);

    /* Verify */
    val = NULL;
    val = slist_index(test_slist, 0);
    assert_true(val != NULL);
    assert_ulong_equal(9999, *val);
    assert_true(slist_size(test_slist) == 1);

    slist_free_all(test_slist, NULL);
    test_slist = NULL;
}
コード例 #13
0
ファイル: test-list.c プロジェクト: laurofigueroa/EDyA1
SList * clonar(SList *l) {
	SList *ret = NULL;

	for(; l != NULL; l = slist_next(l))
		ret = slist_append(ret, slist_data(l));

	return ret;
}
コード例 #14
0
/*
 * Function obex_object_receive_body()
 *
 *    Handle receiving of body
 *
 */
static int obex_object_receive_body(obex_object_t *object, buf_t *msg, uint8_t hi,
				uint8_t *source, unsigned int len)
{
	struct obex_header_element *element;

	DEBUG(4, "This is a body-header. Len=%d\n", len);

	if (len > msg->data_size) {
		DEBUG(1, "Header %d to big. HSize=%d Buffer=%d\n",
				hi, len, msg->data_size);
		return -1;
	}

	if (!object->rx_body) {
		int alloclen = OBEX_OBJECT_ALLOCATIONTRESHOLD + len;

		if (object->hinted_body_len)
			alloclen = object->hinted_body_len;

		DEBUG(4, "Allocating new body-buffer. Len=%d\n", alloclen);
		if (!(object->rx_body = buf_new(alloclen)))
			return -1;
	}

	/* Reallocate body buffer if needed */
	if (object->rx_body->data_avail + object->rx_body->tail_avail < (int) len) {
		int t;
		DEBUG(4, "Buffer too small. Go realloc\n");
		t = buf_total_size(object->rx_body);
		buf_resize(object->rx_body, t + OBEX_OBJECT_ALLOCATIONTRESHOLD + len);
		if (buf_total_size(object->rx_body) != t + OBEX_OBJECT_ALLOCATIONTRESHOLD + len) {
			DEBUG(1, "Can't realloc rx_body\n");
			return -1;
			/* FIXME: Handle this in a nice way... */
		}
	}

	buf_insert_end(object->rx_body, source, len);

	if (hi == OBEX_HDR_BODY_END) {
		DEBUG(4, "Body receive done\n");
		if ( (element = malloc(sizeof(struct obex_header_element)) ) ) {
			memset(element, 0, sizeof(struct obex_header_element));
			element->length = object->rx_body->data_size;
			element->hi = OBEX_HDR_BODY;
			element->buf = object->rx_body;

			/* Add element to rx-list */
			object->rx_headerq = slist_append(object->rx_headerq, element);
		} else
			buf_free(object->rx_body);

		object->rx_body = NULL;
	} else
		DEBUG(4, "Normal body fragment...\n");

	return 1;
}
コード例 #15
0
ファイル: slist.c プロジェクト: qgewfg/gtk-gnutella
/**
 * Move entry to the tail of the slist.
 */
bool
slist_moveto_tail(slist_t *slist, void *key)
{
	if (slist_remove(slist, key)) {
		slist_append(slist, key);
		return TRUE;
	}
	return FALSE;
}
コード例 #16
0
void LLCurl::Easy::prepRequest(const std::string& url,
                               const std::vector<std::string>& headers,
                               ResponderPtr responder, bool post)
{
    resetState();

    if (post) setoptString(CURLOPT_ENCODING, "");

//	setopt(CURLOPT_VERBOSE, 1); // usefull for debugging
    setopt(CURLOPT_NOSIGNAL, 1);

    mOutput.reset(new LLBufferArray);
    setopt(CURLOPT_WRITEFUNCTION, (void*)&curlWriteCallback);
    setopt(CURLOPT_WRITEDATA, (void*)this);

    setopt(CURLOPT_READFUNCTION, (void*)&curlReadCallback);
    setopt(CURLOPT_READDATA, (void*)this);

    setopt(CURLOPT_HEADERFUNCTION, (void*)&curlHeaderCallback);
    setopt(CURLOPT_HEADERDATA, (void*)this);

    setErrorBuffer();
    setCA();

    setopt(CURLOPT_SSL_VERIFYPEER, LLCurl::getSSLVerify());
    setopt(CURLOPT_SSL_VERIFYHOST, LLCurl::getSSLVerify()? 2 : 0);
    setopt(CURLOPT_TIMEOUT, CURL_REQUEST_TIMEOUT);

    setoptString(CURLOPT_URL, url);

    mResponder = responder;

    if (!post)
    {
        slist_append("Connection: keep-alive");
        slist_append("Keep-alive: 300");
        // Accept and other headers
        for (std::vector<std::string>::const_iterator iter = headers.begin();
                iter != headers.end(); ++iter)
        {
            slist_append((*iter).c_str());
        }
    }
}
コード例 #17
0
ファイル: header.c プロジェクト: Eppo791906066/gtk-gnutella
/**
 * Append line of text to given header field.
 * A private copy of the data is made.
 */
static void
hfield_append(header_field_t *h, const char *text)
{
	header_field_check(h);

	if (!h->lines) {
		h->lines = slist_new();
	}
	slist_append(h->lines, h_strdup(text));
}
コード例 #18
0
SList slist_concat(SList list1, SList list2, size_t size)
{
  SList new_list = slist_create();
  SList aux_list1 = list1;
  SList aux_list2 = list2;

  while(aux_list1 != slist_empty())
  {
    new_list = slist_append(new_list, slist_data(aux_list1), size);
    aux_list1 = slist_next(aux_list1);
  }

  while(aux_list2 != slist_empty())
  {
    new_list = slist_append(new_list, slist_data(aux_list2), size);
    aux_list2 = slist_next(aux_list2);
  }

  return new_list;
}
コード例 #19
0
ファイル: ioq_linux.c プロジェクト: dlbeer/libdlb
static int mod_enqueue_nolock(struct ioq *q, struct ioq_fd *f)
{
	int need_wakeup = 0;

	if (!(f->flags & IOQ_FLAG_MOD_LIST)) {
		need_wakeup = slist_is_empty(&q->mod_list);
		f->flags |= IOQ_FLAG_MOD_LIST;
		slist_append(&q->mod_list, &f->mod_list);
	}

	return need_wakeup;
}
コード例 #20
0
ファイル: slist.cpp プロジェクト: jmgunn87/lp3
slist* slist_copy(slist* list)
{
  int i=1;
  slist* ret=0;
  slist_elem* sle=0;

  if(!list)return 0;
  
  ret=new_slist();
  sle=list->_head;
  for(;sle&&i<list->_size;sle=sle->_next,++i)
    slist_append(list,(void*)sle->_data);
  return ret;
}
コード例 #21
0
slist slist_ssort(slist lista)
{
  slist listaNueva = slist_create();
  slist aux = slist_create();

  int i,j, lonLista;

  lonLista = slist_length(lista);

  for(i = 0; i < lonLista; i++)
    aux = slist_append(aux, slist_elem(lista, i));

  slist aux2 = aux;
  int posMenor = 0;
  int menor = slist_data(aux);

  for(j = 0; j < lonLista; j++)
  {
    posMenor = 0;
    menor = slist_data(aux);
    for(i = 0 ; aux != slist_empty(); aux = slist_next(aux), i++)
    {
      if(slist_data(aux) < menor)
      {
        posMenor = i;
        menor = slist_data(aux);
      }
    }
    aux = aux2;

    listaNueva = slist_append(listaNueva, menor);
    aux = slist_remove(aux, posMenor);
    aux2 = aux;
  }

  return listaNueva;
}
コード例 #22
0
ファイル: bnf_constructs.cpp プロジェクト: jmgunn87/clrgen
/******************************************
 * CLOSURE() algorithm                    *
 * ---------------------------------------*
 * The closure will take an index, shift  *
 * its position to the right(increment)   *
 * I will clarify this function later!    *
 ******************************************/
void bnf_closure(bnf_grammar* bnf,
                 bnf_index* i,
                 cset* closure)
{
  int j=1;  
  int sym=0;
  int next_right=0;
  bnf_index bi;

  next_right=bnf->items[i->item][i->product][i->product_part];

  /*no more products to be seen here*/
  if(next_right<0||next_right>=bnf->start_of_actions||
     IS_TERM(bnf,next_right)||!bnf||!i||!closure)
    return;

  /* now take the shifted symbols index */
  ++i->product_part;
  sym=PART_SYMBOL(bnf,i);
  --i->product_part;
    
  /*recurse through each product and add with lookaheads*/
  for(;j<=bnf->items[next_right][0][1];++j)
  {
    /*now attach lookaheads*/
    bi.item=next_right;
    bi.product=j;
    bi.product_part=0;
    sym>0?
      bi.lookaheads=bnf_get_first_set(bnf,sym):
      bi.lookaheads=i->lookaheads;

    /********************************************************
     * try and add to the closure, if not augment its       *
     * generated lookaheads to the existing item in the set *
     ********************************************************/
    if(cset_is_member(closure,(void*)&bi))
      if(!add_lookaheads_to_item(closure,&bi))
        break;
      else
        bnf_closure(bnf,new_bnf_index(bi.item,bi.product,bi.product_part,bi.lookaheads),closure);
    else
    {
      slist_append(closure->members,new_bnf_index(bi.item,bi.product,bi.product_part,bi.lookaheads));
      bnf_closure(bnf,(bnf_index*)closure->members->_tail->_data,closure);
    }
      
  }
}
コード例 #23
0
ファイル: test-slist.c プロジェクト: vdt/libcore
void test_slist_append_to_existing(void)
{
    unsigned long *val;
    unsigned long old_size;

    old_size = slist_size(test_slist);
    val = make_ulong_ptr(7777);
    assert_true(slist_append(test_slist, val) == 0);

    /* Verify */
    val = NULL;
    val = slist_index(test_slist, (slist_size(test_slist) - 1));
    assert_ulong_equal(7777, *val);
    assert_true((old_size + 1) == slist_size(test_slist));
}
コード例 #24
0
ファイル: llcurl.cpp プロジェクト: Boy/rainbow
void LLCurl::Easy::prepRequest(const std::string& url, ResponderPtr responder, bool post)
{
	resetState();
	
	if (post) setoptString(CURLOPT_ENCODING, "");

//	setopt(CURLOPT_VERBOSE, 1); // usefull for debugging
	setopt(CURLOPT_NOSIGNAL, 1);

	mOutput.reset(new LLBufferArray);
	setopt(CURLOPT_WRITEFUNCTION, (void*)&curlWriteCallback);
	setopt(CURLOPT_WRITEDATA, (void*)this);

	setopt(CURLOPT_READFUNCTION, (void*)&curlReadCallback);
	setopt(CURLOPT_READDATA, (void*)this);
	
	setopt(CURLOPT_HEADERFUNCTION, (void*)&curlHeaderCallback);
	setopt(CURLOPT_HEADERDATA, (void*)this);

	setErrorBuffer();
	setCA();

	setopt(CURLOPT_SSL_VERIFYPEER, true);
	setopt(CURLOPT_TIMEOUT, CURL_REQUEST_TIMEOUT);

	setoptString(CURLOPT_URL, url);

	mResponder = responder;

	if (!post)
	{
		slist_append("Connection: keep-alive");
		slist_append("Keep-alive: 300");
	}
	// *FIX: should have ACCEPT headers
}
コード例 #25
0
ファイル: test-slist.c プロジェクト: vdt/libcore
void slist_setup_ints(void)
{
    unsigned long i, *val;

    test_slist = slist_create();

    assert_true(test_slist != NULL);
    assert_true(slist_is_empty(test_slist));

    for(i = 0; i < 1000; i++) {
        val = make_ulong_ptr(i);
        if(val != NULL) {
            slist_append(test_slist, val);
        }
    }
}
コード例 #26
0
ファイル: search.c プロジェクト: Longdengyu/gtk-gnutella
void
search_gui_add_record(search_t *sch, record_t *rc, enum gui_color color)
{
	static const struct result_data zero_data;
	struct result_data *data;

	record_check(rc);

	WALLOC(data);
	*data = zero_data;
	data->color = color;
	data->record = rc;
	data->sh = sch->search_handle;
	search_gui_ref_record(rc);

	slist_append(sch->queue, data);
}
コード例 #27
0
ファイル: configs.c プロジェクト: m1nuz/neon-core
int
load_config(const char *filepath) {
    SDL_RWops *fp = SDL_RWFromFile(filepath, "r");

    if (!fp) {
        LOG_ERROR("Can't open file %s\n", filepath);
        return -1;
    }

    char buffer[256];

    while (!rweof(fp)) {
        memset(buffer, 0, sizeof(buffer));
        rwgets(buffer, sizeof(buffer), fp);

        if (buffer[0] == '#')
            continue;

        char *ptr;
        char *p = strtok_r(buffer, " \r\n", &ptr);

        if (p) {
            struct ConfigItem *item = malloc(sizeof(struct ConfigItem));

            strncpy(item->key, p, MAX_CONFIGS_STR_KEY_SIZE);
            item->hash = pjw_hash(p);

            p = strtok_r(NULL, " \r\n", &ptr);

            if (isint(p)) {
                VARIANT_SET_INT(item->var, atoi(p));
            } else if (isfloat(p)) {
                VARIANT_SET_FLOAT(item->var, atof(p));
            } else {
                VARIANT_SET_STRING(item->var, p);
            }

            // TODO: check dublicate
            slist_append(configs, &item);
        }
    }

    SDL_RWclose(fp);

    return 0;
}
コード例 #28
0
/*
 * Function obex_object_getnextheader()
 *
 * Return the next header in the rx-queue
 *
 */
int obex_object_getnextheader(obex_t *self, obex_object_t *object, uint8_t *hi,
				obex_headerdata_t *hv, uint32_t *hv_size)
{
	uint32_t *bq4;
	struct obex_header_element *h;

	DEBUG(4, "\n");

	/* No more headers */
	if (object->rx_headerq == NULL)
		return 0;

	/* New headers are appended at the end of the list while receiving, so
	   we pull them from the front.
	   Since we cannot free the mem used just yet just put the header in
	   another list so we can free it when the object is deleted. */

	h = object->rx_headerq->data;
	object->rx_headerq = slist_remove(object->rx_headerq, h);
	object->rx_headerq_rm = slist_append(object->rx_headerq_rm, h);

	*hi = h->hi;
	*hv_size= h->length;

	switch (h->hi & OBEX_HI_MASK) {
		case OBEX_BYTE_STREAM:
			hv->bs = &h->buf->data[0];
			break;

		case OBEX_UNICODE:
			hv->bs = &h->buf->data[0];
			break;

		case OBEX_INT:
			bq4 = (uint32_t*) h->buf->data;
			hv->bq4 = ntohl(*bq4);
			break;

		case OBEX_BYTE:
			hv->bq1 = h->buf->data[0];
			break;
	}

	return 1;
}
コード例 #29
0
slist slist_intersec(slist l1, slist l2)
{
  slist listaNueva = slist_create();
  slist l2Aux = l2;
  for( ; l1 != slist_empty(); l1 = slist_next(l1))
  {
    for( ; l2 != slist_empty(); l2 = slist_next(l2))
    {
      if( slist_data(l1) == slist_data(l2))
      {
        if(slist_contain(listaNueva, slist_data(l1)) == FALSE)
          listaNueva = slist_append(listaNueva, slist_data(l1));
      }
    }
    l2 = l2Aux;
  }
  return listaNueva;
}
コード例 #30
0
int pm_addstring(pm_t *pm, unsigned char *c, size_t n) {

	if(pm == NULL || c == NULL) {
		return -1;
	}

	int i;
	pm_state_t* currentState = pm->zerostate;
	pm_state_t* nextState;

	for(i=0; i < n; i++) {

		if((nextState = pm_goto_get(currentState, c[i])) != NULL) {
			currentState = nextState;

		} else {

			pm_state_t* newState = (pm_state_t*)malloc(sizeof(pm_state_t));
			if(newState == NULL) {
				perror("Failed to allocate memory\n");
				exit(-1);
			}

			printf("Allocating state %d\n", pm->newstate);
			if(init_state(pm, newState, (currentState->depth) + 1) == -1) {
				return -1;
			}

			if(pm_goto_set(currentState, c[i], newState) == -1) {
				return -1;
			}

			currentState = newState;
		}
	}

	if(contains(currentState->output, c) == 0) {

		slist_append(currentState->output, c);

	} 

	return 0;
}