コード例 #1
0
ファイル: filter.cpp プロジェクト: fourks/Openspy-Core
char *findfirstoperator(char *filter) {
	int len = strlen(filter);
	char *firstEquals;
	char *nextSpace;
	firstEquals = find_first(filter,'=',len);
	nextSpace = find_first(filter,' ',len);	
	return firstEquals>nextSpace?firstEquals:nextSpace;
}
コード例 #2
0
ファイル: rte_hash.c プロジェクト: carriercomm/dpdkv7
static inline int32_t
__rte_hash_add_key_with_hash(const struct rte_hash *h, 
				const void *key, hash_sig_t sig)
{
	hash_sig_t *sig_bucket;
	uint8_t *key_bucket;
	uint32_t bucket_index, i;
	int32_t pos;

	/* Get the hash signature and bucket index */
	sig |= h->sig_msb;
	bucket_index = sig & h->bucket_bitmask;
	sig_bucket = get_sig_tbl_bucket(h, bucket_index);
	key_bucket = get_key_tbl_bucket(h, bucket_index);

	/* Check if key is already present in the hash */
	for (i = 0; i < h->bucket_entries; i++) {
		if ((sig == sig_bucket[i]) &&
		    likely(memcmp(key, get_key_from_bucket(h, key_bucket, i),
				  h->key_len) == 0)) {
			return bucket_index * h->bucket_entries + i;
		}
	}

	/* Check if any free slot within the bucket to add the new key */
	pos = find_first(NULL_SIGNATURE, sig_bucket, h->bucket_entries);

	if (unlikely(pos < 0))
		return -ENOSPC;

	/* Add the new key to the bucket */
	sig_bucket[pos] = sig;
	rte_memcpy(get_key_from_bucket(h, key_bucket, pos), key, h->key_len);
	return bucket_index * h->bucket_entries + pos;
}
コード例 #3
0
ファイル: header.hpp プロジェクト: 3Hren/cocaine-core
boost::optional<To>
convert_first(const std::vector<header_t>& headers, From&& from) {
    if(auto v = find_first(headers, from)) {
        return boost::make_optional(unpack<To>(v->value()));
    }
    return boost::none;
}
コード例 #4
0
ファイル: StaticList.hpp プロジェクト: novalabs/core-mw
 Item*
 find_first(
     Predicate pred_func
 ) const
 {
     return find_first(reinterpret_cast<StaticList::Predicate>(pred_func));
 }
コード例 #5
0
ファイル: cntr_tcl.cpp プロジェクト: mdmitr/surfit
boolvec * cntr_read(const char * filename, const char * cntrname,
	       int col1, int col2, int col3,
	       const char* delimiter, int skip_lines, int grow_by)
{
	boolvec * res = create_boolvec();
	const char * fname = find_first(filename);

	while (fname) {

		d_cntr * contour = _cntr_read(fname, cntrname,
			col1, col2, col3, skip_lines,
			grow_by, delimiter);

		if (contour != NULL) {
			surfit_cntrs->push_back(contour);
			res->push_back(true);
			
		} else
			res->push_back(false);

		fname = find_next();
	}

	find_close();
	return res;
};
コード例 #6
0
ファイル: area_tcl.cpp プロジェクト: mdmitr/surfit
boolvec * area_load(const char * filename, const char * areaname)
{
    boolvec * res = create_boolvec();
    const char * fname = find_first(filename);

    while (fname != NULL) {
        d_area * area = _area_load(fname, areaname);
        if (area) {
            surfit_areas->push_back(area);
            res->push_back(true);
        } else {
            res->push_back(false);
            fname = find_next();
            continue;
        }
        if (areaname == NULL)
        {
            char * name = get_name(fname);
            area->setName( name );
            sstuff_free_char(name);
        }

        fname = find_next();
    }

    find_close();
    return res;
};
コード例 #7
0
ファイル: jade.newick.hpp プロジェクト: jade-cheng/ohana
 ///
 /// \return The node with the specified name.
 ///
 pointer_type find_name(
         char const * const name) ///< The name of the node to find.
 {
     return find_first([name](pointer_type node) -> bool
     {
         return node->_name == name;
     });
 }
コード例 #8
0
ファイル: jade.newick.hpp プロジェクト: jade-cheng/ohana
 ///
 /// \return The node with the specified id.
 ///
 pointer_type find_id(
         const int id) ///< The id of the node to find.
 {
     return find_first([id](pointer_type node) -> bool
     {
         return node->_id == id;
     });
 }
コード例 #9
0
ファイル: StaticList.hpp プロジェクト: novalabs/core-mw
 Item*
 find_first(
     Matches         match_func,
     const Features* featuresp
 ) const
 {
     return find_first(reinterpret_cast<StaticList::Matches>(match_func),
                       reinterpret_cast<const void*>(featuresp));
 }
コード例 #10
0
ファイル: ft_strinside.c プロジェクト: ntrancha/libft
char        *ft_strinside(char *str, char start, char end)
{
    int     first;
    int     last;
    char    *inside;

    last = find_last(str, start);
    first = find_first(str, last, end);
    inside = ft_strsub(str, last + 1, first - last - 1);
    return (inside);
}
コード例 #11
0
ファイル: pool_queue.c プロジェクト: ccli8/uvisor
uvisor_pool_slot_t uvisor_pool_queue_find_first(uvisor_pool_queue_t * pool_queue,
                                                TQueryFN_Ptr query_fn, void * context)
{
    uvisor_pool_slot_t slot;
    uvisor_pool_t * pool = UVISOR_AUTO_NS_ALIAS(pool_queue->pool);

    uvisor_spin_lock(&pool->spinlock);
    slot = find_first(pool_queue, query_fn, context);
    uvisor_spin_unlock(&pool->spinlock);

    return slot;
}
コード例 #12
0
ファイル: buttons.cpp プロジェクト: nbingham1/Blaze
void buttonshdl::release(int button, double real_current_time, double game_current_time)
{
	array<int>::iterator k = find_first(pressed.ref(), button);
	if (k != pressed.end())
	{
		k.pop();

		map<int, preference>::iterator i = control.find(button);
		if (i != control.end())
			i->value(vec3f(0.0f, -1.0f, 0.0f), real_current_time, game_current_time);
	}
}
コード例 #13
0
ファイル: area_io_tcl.cpp プロジェクト: mdmitr/surfit
boolvec * area_load_shp(const char * filename, const char * areaname) 
{
	boolvec * res = create_boolvec();
	const char * fname = find_first(filename);

	while (fname) {
		res->push_back(_area_load_shp(fname, areaname));
		fname = find_next();	
	}
	find_close();
	return res;
};
コード例 #14
0
ファイル: buttons.cpp プロジェクト: nbingham1/Blaze
void buttonshdl::press(int button, double real_current_time, double game_current_time)
{
	array<int>::iterator k = find_first(pressed.ref(), button);
	if (k == pressed.end())
	{
		pressed.push_back(button);

		map<int, preference>::iterator i = control.find(button);
		if (i != control.end())
			i->value(vec3f(1.0f, 1.0f, 0.0f), real_current_time, game_current_time);
	}
}
コード例 #15
0
ファイル: fat.c プロジェクト: ArakniD/dynawa
/**
 * Find number of entries for specific filename
 * 
 * \param match Filename to count
 * \return Number of matching directory entries
 * 
 */
int num_direntries(char *match)
{
    int res, max = 0;
    fatffdata_t ff; /** \todo ! no good with this static alloc, dynamic is also crap, see if other solution can be used. */

    res = find_first(match,&ff);
    while (res != -1)
    {
        res = find_next(&ff);
        max++;
    }
    return max; 
}
コード例 #16
0
int main()
{
	char s[5] = "hello";
	

	printf("%d", find_first(s, 'e'));

	replace_first(s, 5, 'l', 'v');


	getchar();
	return 0;
}
コード例 #17
0
ファイル: PartitionShell.cpp プロジェクト: chrismullins/cgma
CubitSense PartitionShell::find_sense( const PartitionSurface* surf ) const
{
  PartitionCoSurf* cos = find_first( surf );
  if( ! cos )
    return CUBIT_UNKNOWN;
  
  CubitSense result = cos->sense();
  while( (cos = find_next( cos )) )
    if( cos->sense() != result )
      return CUBIT_UNKNOWN;
  
  return result;
}
コード例 #18
0
ファイル: halloc.c プロジェクト: zhengruohuang/toddler
void *halloc()
{
    int e;
    int b;
    int found = 0;
    
    int prev_entry;
    unsigned long addr;
    void *result = NULL;
    
    kthread_mutex_lock(&heap_mutex);
    
    // Find the first avail entry
    for (e = 0; e < BITMAP_ENTRY_COUNT; e++) {
        if (entry_avail(e)) {
            found = 1;
            break;
        }
    }
    
    if (!found) {
        goto done;
    }
    
    // Find and set the first avail bit
    b = find_first(e, 0);
    bit_set(e, b);
    
    // Resize the heap
    prev_entry = cur_last_bitmap_entry;
    if (e > cur_last_bitmap_entry) {
        cur_last_bitmap_entry = e;
    }
    
    if (!resize_heap()) {
        bit_clear(e, b);
        cur_last_bitmap_entry = prev_entry;
        
        goto done;
    }
    
    // Calculate the final address
    addr = heap_start + HALLOC_CHUNK_SIZE * (BITS_PER_ENTRY * e + b);
    result = (void *)addr;
    
done:
    atomic_membar();
    kthread_mutex_unlock(&heap_mutex);
    
    return result;
}
コード例 #19
0
 vector<int> searchRange(vector<int> &A, int target) {
     // write your code here
     int length = A.size();
     if(length == 0)
         return vector<int>(2, -1);
     int start = -1, end = -1;
     start = find_first(A, target);
     if(start != -1)
         end = find_last(A, target);
     vector<int> result;
     result.push_back(start);
     result.push_back(end);
     return result;
 }
コード例 #20
0
ファイル: area_io_tcl.cpp プロジェクト: mdmitr/surfit
boolvec * area_load_bln(const char * filename, const char * areaname) 
{
	boolvec * res = create_boolvec();
	const char * fname = find_first(filename);

	while (fname) {
		d_area * area = _area_load_bln(fname, areaname);
		if (area)
			surfit_areas->push_back(area);
		res->push_back( area != NULL );
		fname = find_next();	
	}
	find_close();
	return res;
};
コード例 #21
0
ファイル: pool_queue.c プロジェクト: ccli8/uvisor
uvisor_pool_slot_t uvisor_pool_queue_try_find_first(uvisor_pool_queue_t * pool_queue,
                                                    TQueryFN_Ptr query_fn, void * context)
{
    uvisor_pool_slot_t slot;
    uvisor_pool_t * pool = UVISOR_AUTO_NS_ALIAS(pool_queue->pool);

    bool locked = uvisor_spin_trylock(&pool->spinlock);
    if (!locked) {
        /* We didn't get the lock. */
        return UVISOR_POOL_SLOT_INVALID;
    }
    slot = find_first(pool_queue, query_fn, context);
    uvisor_spin_unlock(&pool->spinlock);

    return slot;
}
コード例 #22
0
ファイル: buffreader.cpp プロジェクト: chc/gameserver_v8
uint8_t *BufferReadNTS(uint8_t **buffer, uint32_t *len) {
	uint8_t *retbuff;
	uint32_t readlen;
	uint8_t *nullbyte = (uint8_t *)find_first((char *)*buffer,0,*len);
	if(nullbyte == NULL) { //we didn't find a null byte so just stop
		return NULL;
	}
	readlen = nullbyte - *buffer;
	retbuff = (uint8_t *)malloc(readlen+1);
	if(retbuff == NULL) return NULL;
	memset(retbuff,0,readlen+1);
	BufferReadData(buffer,len,retbuff,readlen);
	*buffer += sizeof(uint8_t); //skip the null byte
	*len -= sizeof(uint8_t);
	return retbuff;
}
コード例 #23
0
ファイル: foldline.c プロジェクト: wurzelstumpf/cproglang
int main()
{
    int c;                 /* character */
    int len;               /* current line length */
    int tos;               /* index to last tab or space */

    tos = -1;              /* no tabs or spaces read so far */
    len = 0;               /* set index to first character */

    while ((c = getchar()) != EOF)
    {
        if (c == '\n')              /* end of line */
        {
            print_line(len);
            len = 0;
            tos = -1;
        }
        else if (len == FOLD)        /* buffer full and next char not a newline */
        {
            if (tos < 0)             /* no tabs or spaces in line */
            {
                print_line(FOLD);
                buffer[0] = c;                 /* add char to next line */
                len = 1;                       /* set for next char */
                tos = (is_white(c)) ? 0 : -1;  /* is it a white space char */
            }
            else
            {
                print_line(tos);
                shift_left(tos + 1);   /* from first non white space */
                len = FOLD - tos -1;
                buffer[len] = c;
                tos = find_first(len);
                ++len;
            }
        }
        else
        {
            buffer[len] = c;
            if (is_white(c))
                tos = len;
            ++len;
        }
    }
}
コード例 #24
0
ファイル: cntr_tcl.cpp プロジェクト: mdmitr/surfit
boolvec * cntr_load(const char * filename, const char * cntrname) 
{
	boolvec * res = create_boolvec();
	const char * fname = find_first(filename);

	while (fname) {
		d_cntr * contour = _cntr_load(fname, cntrname);
		if (contour) {
			surfit_cntrs->push_back(contour);
			res->push_back(true);
		} else
			res->push_back(false);

		fname = find_next();
	}

	find_close();
	return res;
};
コード例 #25
0
ファイル: cmex.c プロジェクト: AMFIRNAS/wso2-gridlabd
void cmex_object_list(int nlhs, mxArray *plhs[], /**< entlist */
					  int nrhs, const mxArray *prhs[] ) /**< () */
{
	OBJECT *obj;
	char criteria[1024]="(undefined)";
	FINDPGM *search = NULL;
	char *fields[] = {"name","class","parent","flags","location","service","rank","clock","handle"};
	FINDLIST *list = NULL;
	if (nrhs>0 && mxGetString(prhs[0],criteria,sizeof(criteria))!=0)
		output_error("gl('list',type='object'): unable to read search criteria (arg 2)");
	else if (nrhs>0 && (search=find_mkpgm(criteria))==NULL)
		output_error("gl('list',type='object'): unable to run search '%s'",criteria);
	else if (search==NULL && (list=find_objects(NULL,NULL))==NULL)
		output_error("gl('list',type='object'): unable to obtain default list");
	else if (list==NULL && (list=find_runpgm(NULL,search))==NULL)
		output_error("gl('list',type='object'): unable search failed");
	else if ((plhs[0] = mxCreateStructMatrix(list->hit_count,1,sizeof(fields)/sizeof(fields[0]),fields))==NULL)
		output_error("gl('list',type='object'): unable to allocate memory for result list");
	else
	{
		unsigned int n;
		for (n=0, obj=find_first(list); obj!=NULL; n++, obj=find_next(list,obj))
		{
			char tmp[1024];
			mxArray *data;
			double *pDouble;
			unsigned int *pInt;
			mxSetFieldByNumber(plhs[0], n, 0, mxCreateString(object_name(obj)));
			mxSetFieldByNumber(plhs[0], n, 1, mxCreateString(obj->oclass->name));
			mxSetFieldByNumber(plhs[0], n, 2, mxCreateString(obj->parent?object_name(obj->parent):NONE));
			mxSetFieldByNumber(plhs[0], n, 3, mxCreateString(convert_from_set(tmp,sizeof(tmp),&(obj->flags),object_flag_property())?tmp:ERROR));
			pDouble = mxGetPr(data=mxCreateDoubleMatrix(1,2,mxREAL)); pDouble[0] = obj->longitude; pDouble[1] = obj->latitude;
			mxSetFieldByNumber(plhs[0], n, 4, data);
			pDouble = mxGetPr(data=mxCreateDoubleMatrix(1,2,mxREAL)); pDouble[0] = (double)obj->in_svc/TS_SECOND; pDouble[1] = (double)obj->out_svc/TS_SECOND;
			mxSetFieldByNumber(plhs[0], n, 5, data);
			pInt = (unsigned int*)mxGetPr(data=mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL)); pInt[0] = obj->rank;
			mxSetFieldByNumber(plhs[0], n, 6, data);
			pDouble = mxGetPr(data=mxCreateDoubleMatrix(1,1,mxREAL)); pDouble[0] = (double)obj->clock/TS_SECOND; 
			mxSetFieldByNumber(plhs[0], n, 7, data);
			mxSetFieldByNumber(plhs[0], n, 8, make_handle(MH_OBJECT,obj));
		}
	}
}
コード例 #26
0
ファイル: textbox.c プロジェクト: 0mp/freebsd
static long
tabize(MY_OBJ * obj, long val, long *first_pos)
{
    long fpos;
    long i, count, begin_line;
    char *buftab;

    if (!dialog_vars.tab_correct)
	return val;

    fpos = ftell_obj(obj);

    lseek_set(obj, fpos - obj->fd_bytes_read);

    /* Allocate space for read buffer */
    buftab = xalloc((size_t) val + 1);

    if ((read(obj->fd, buftab, (size_t) val)) == -1)
	dlg_exiterr("Error reading file in tabize().");

    begin_line = count = 0;
    if (first_pos != 0)
	*first_pos = 0;

    for (i = 0; i < val; i++) {
	if ((first_pos != 0) && (count >= val)) {
	    *first_pos = find_first(obj, buftab, i);
	    break;
	}
	if (buftab[i] == TAB)
	    count += dialog_state.tab_len
		- ((count - begin_line) % dialog_state.tab_len);
	else if (buftab[i] == '\n') {
	    count++;
	    begin_line = count;
	} else
	    count++;
    }

    lseek_set(obj, fpos);
    free(buftab);
    return count;
}
コード例 #27
0
ファイル: tardiffmerge.c プロジェクト: maksverver/tardiff
/* Order the list of input files so each next file applies to the previous: */
static bool order_input(struct File **files)
{
    struct File *cur, *succ;

    /* Determine first file */
    cur = find_first(*files);
    if (cur == NULL) return false;
    *files = move_to_front(*files, cur);

    /* Order remaining files */
    while (cur->next)
    {
        succ = find_digest(cur->next, cur->diff.digest2);
        if (succ == NULL) return false;
        cur->next = move_to_front(cur->next, succ);
        cur = cur->next;
    }

    return true;
}
コード例 #28
0
ファイル: random_circuit.cpp プロジェクト: chastell/cirkit
void create_random_gate( gate& g, unsigned lines, bool negative, std::default_random_engine& generator )
{
  std::uniform_int_distribution<unsigned> dist( 0u, lines - 1u );
  std::uniform_int_distribution<unsigned> bdist( 0u, 1u );

  auto controls = random_bitset( lines, generator );
  auto target   = dist( generator );

  g.set_type( toffoli_tag() );
  g.add_target( target );
  auto pos = controls.find_first();
  while ( pos != controls.npos )
  {
    if ( pos != target )
    {
      g.add_control( make_var( pos, negative ? ( bdist( generator ) == 1u ) : true ) );
    }
    pos = controls.find_next( pos );
  }
}
コード例 #29
0
ファイル: buttons.cpp プロジェクト: nbingham1/Blaze
void buttonshdl::set(int button, bool value, double real_current_time, double game_current_time)
{
	array<int>::iterator k = find_first(pressed.ref(), button);
	if (!value && k != pressed.end())
	{
		k.pop();

		map<int, preference>::iterator i = control.find(button);
		if (i != control.end())
			i->value(vec3f(0.0f, -1.0f, 0.0f), real_current_time, game_current_time);
	}
	else if (value && k == pressed.end())
	{
		pressed.push_back(button);

		map<int, preference>::iterator i = control.find(button);
		if (i != control.end())
			i->value(vec3f(1.0f, 1.0f, 0.0f), real_current_time, game_current_time);
	}
}
コード例 #30
0
ファイル: area_tcl.cpp プロジェクト: mdmitr/surfit
boolvec * area_read(const char * filename, const char * areaname,
                    int col1, int col2,
                    const char* delimiter, int skip_lines, int grow_by)
{

    boolvec * res = create_boolvec();
    const char * fname = find_first(filename);

    while (fname != NULL) {

        d_area * area = _area_read(fname, areaname,
                                   col1, col2, skip_lines,
                                   grow_by, delimiter);

        if (area != NULL)
            surfit_areas->push_back(area);
        else {
            writelog(LOG_WARNING,"failed to read area from file %s", fname);
            res->push_back(false);
            fname = find_next();
            continue;
        }

        if (areaname == NULL)
        {
            char * name = get_name(fname);
            area->setName( name );
            sstuff_free_char(name);
        }

        res->push_back(true);
        fname = find_next();

    }

    find_close();
    return res;

};