Beispiel #1
0
/*
  Extrancs raw point correspondence locations from a set of features

  @param features array of features from which to extract points and match
    points; each of these is assumed to have a match of type mtype
  @param n number of features
  @param mtype match type; if FEATURE_MDL_MATCH correspondences are assumed
    to be between each feature's img_pt field and it's match's mdl_pt field,
    otherwise, correspondences are assumed to be between img_pt and img_pt
  @param pts output as an array of raw point locations from features
  @param mpts output as an array of raw point locations from features' matches
*/
static void extract_corresp_pts( struct feature** features, int n, int mtype,
				 CvPoint2D64f** pts, CvPoint2D64f** mpts )
{
  struct feature* match;
  CvPoint2D64f* _pts, * _mpts;
  int i;

  _pts = ( CvPoint2D64f *)calloc( n, sizeof( CvPoint2D64f ) );
  _mpts = ( CvPoint2D64f *)calloc( n, sizeof( CvPoint2D64f ) );

  if( mtype == FEATURE_MDL_MATCH )
    for( i = 0; i < n; i++ )
      {
	match = get_match( features[i], mtype );
	if( ! match )
	  fatal_error( "feature does not have match of type %d, %s line %d",
		       mtype, __FILE__, __LINE__ );
	_pts[i] = features[i]->img_pt;
	_mpts[i] = match->mdl_pt;
      }

  else
    for( i = 0; i < n; i++ )
      {
	match = get_match( features[i], mtype );
	if( ! match )
	  fatal_error( "feature does not have match of type %d, %s line %d",
		       mtype, __FILE__, __LINE__ );
	_pts[i] = features[i]->img_pt;
	_mpts[i] = match->img_pt;
      }

  *pts = _pts;
  *mpts = _mpts;
}
Beispiel #2
0
int main()
{
    struct match *info1, *info2, *info3;

    init_heap();

    info1 = get_match(20151018, "Baseball", "Cubs", "Mets", 1, 4);

    print_info(info1);

    dump_heap();

    del_match(info1);

    info1 = get_match(20151018, "Football", "Ravens", "49ers", 20, 25);

    info2 = get_match(20151019, "Baseball", "Royals", "Blue Jays", 8, 1);

    info3 = get_match(20151019, "Football", "Giants", "Eagles", 7, 27);

    dump_heap();

    del_match(info2);

    dump_heap();
    return 0;
}
Beispiel #3
0
/*
  For a given model and error function, finds a consensus from a set of
  feature correspondences.

  @param features set of pointers to features; every feature is assumed to
    have a match of type mtype
  @param n number of features in features
  @param mtype determines the match field of each feature against which to
    measure error; if this is FEATURE_MDL_MATCH, correspondences are assumed
    to be between the feature's img_pt field and the match's mdl_pt field;
    otherwise matches are assumed to be between img_pt and img_pt
  @param M model for which a consensus set is being found
  @param err_fn error function used to measure distance from M
  @param err_tol correspondences within this distance of M are added to the
    consensus set
  @param consensus output as an array of pointers to features in the
    consensus set

  @return Returns the number of points in the consensus set
*/
static int find_consensus( struct feature** features, int n, int mtype,
			   CvMat* M, ransac_err_fn err_fn, double err_tol,
			   struct feature*** consensus )
{
  struct feature** _consensus;
  struct feature* match;
  CvPoint2D64f pt, mpt;
  double err;
  int i, in = 0;

  int cnt6=0;
  
  _consensus = (struct feature **)calloc( n, sizeof( struct feature* ) );

  if( mtype == FEATURE_MDL_MATCH )
    for( i = 0; i < n; i++ )
      {
	match = get_match( features[i], mtype );
	if( ! match )
	  fatal_error( "feature does not have match of type %d, %s line %d",
		       mtype, __FILE__, __LINE__ );
	pt = features[i]->img_pt;
	mpt = match->mdl_pt;
	err = err_fn( pt, mpt, M );
	if( err <= err_tol )
	  _consensus[in++] = features[i];
      }

  else
    for( i = 0; i < n; i++ )
      {
	match = get_match( features[i], mtype );
	if( ! match )
	  fatal_error( "feature does not have match of type %d, %s line %d",
		       mtype, __FILE__, __LINE__ );
	pt = features[i]->img_pt;
	mpt = match->img_pt;
	err = err_fn( pt, mpt, M );
	if( err <= err_tol ){
	  _consensus[in++] = features[i];

	  cnt6++;
	}
      }
  *consensus = _consensus;

  fprintf( stderr, "n: %d cnt6: %d\n", n, cnt6 );
  return in;
}
Beispiel #4
0
void mapped_compile(char* line){

  regex_t regst;
  regmatch_t match[3];

  char *reg = "[a-z0-9-]*";
    
  if(regcomp(&regst,reg,REG_EXTENDED)){
    printf("Failed to compile...\n");
    return;
  }

  if(!regexec(&regst,line,3,match,0)){

    char *test,*_start,*_end;

    test = get_match(line,match[0].rm_so,match[0].rm_eo);
      
    _start = strtok(test,"-");
    _end   = strtok(NULL,"-");

    start = strtol(_start,NULL,16);
    end   = strtol(_end,NULL,16);
      
  }

  regfree(&regst);
    
}
Beispiel #5
0
/*
 * (see ActionEnqueue#to_s)
 */
static VALUE
match_to_s( VALUE self ) {
  char match_str[ 1024 ];

  match_to_string( get_match( self ), match_str, sizeof ( match_str ) );
  return rb_str_new2( match_str );
}
static void solve(sym_t *mname, int level, int pos) {
    match_t *m;
    
    if (!mname)
        return;

    m = get_match(mname->name);
    if (!m) { // round robin
        return;
    }

    if (!m->level) {
        m->level = level;
        m->pos = pos;
    }

    if (m->c1.comp && m->c2.comp) {
        //printf("%s: comp%d comp%d\n", m->name, m->c1.comp, m->c2.comp);
        return;
    }
    if (m->c1.comp) {
        solve(m->c2.match, level+1, pos);
        //printf("%s: comp%d match=%s.%d\n", m->name, m->c1.comp, m->c2.match, m->c2.pos);
        return;
    }
    if (m->c2.comp) {
        solve(m->c1.match, level+1, pos);
        //printf("%s: match=%s.%d comp%d\n", m->name, m->c1.match, m->c1.pos, m->c2.comp);
        return;
    }
    solve(m->c1.match, level+1, pos);
    solve(m->c2.match, level+1, pos);
    //printf("%s: match=%s.%d match=%s.%d\n", m->name, m->c1.match, m->c1.pos, m->c2.match, m->c2.pos);
}
Beispiel #7
0
/*
 * Creates a {Match} instance from packet_in's data, the method accepts an
 * additional list of symbols to wildcard set and ignore while matching flow entries.
 *
 * @overload match_from(message, *options)
 *
 *   @example
 *     def packet_in datapath_id, message
 *       send_flow_mod(
 *         datapath_id,
 *         :match => Match.from( message, :dl_type, :nw_proto ),
 *         :actions => Trema::ActionOutput.new( 2 )
 *       )
 *     end
 *
 *   @param [PacketIn] message
 *     the {PacketIn}'s message content.
 *
 *   @param [optional, list] options
 *     If supplied a comma-separated list of symbol ids indicating fields to be wildcarded.
 *
 *     [:in_port]
 *       the physical port number to wildcard.
 *
 *     [:dl_src]
 *       the source Ethernet address to wildcard.
 *
 *     [:dl_dst]
 *       the destination Ethernet address to wildcard.
 *
 *     [:dl_vlan]
 *       the IEEE 802.1q virtual VLAN tag to wildcard.
 *
 *     [:dl_vlan_pcp]
 *       the IEEE 802.1q priority code point to wildcard.
 *
 *     [:dl_type]
 *       the Ethernet protocol type to wildcard.
 *
 *     [:nw_tos]
 *       the IP ToS /DSCP field to wildcard.
 *
 *     [:nw_proto]
 *       the IP protocol type to wildcard.
 *
 *     [:nw_src]
 *       the IPv4 source address to wildcard.
 *
 *     [:nw_dst]
 *       the IPv4 destination address to wildcard.
 *
 *     [:tp_src]
 *       the source TCP/UDP port number to wildcard.
 *
 *     [:tp_dst]
 *       the destination TCP/UDP port number to wildcard.
 *
 * @return [Match] self
 *   the modified or exact match from packet depending on whether the options
 *   argument supplied or not.
 */
static VALUE
match_from( int argc, VALUE *argv, VALUE self ) {
  VALUE message, obj, wildcard_id, options;
  struct ofp_match *match = NULL;
  packet_in *packet = NULL;
  uint32_t wildcards = 0;

  if ( rb_scan_args( argc, argv, "1*", &message, &options ) >= 1 ) {
    obj = rb_funcall( self, rb_intern( "new" ), 0 );
    match = get_match( obj );
    Data_Get_Struct( message, packet_in, packet );
    int i;
    for ( i = 0; i < RARRAY_LEN( options ); i++ ) {
      wildcard_id = SYM2ID( RARRAY_PTR( options )[ i ] );
      if ( rb_intern( "in_port" ) == wildcard_id ) {
        wildcards |= OFPFW_IN_PORT;
      }
      if ( rb_intern( "dl_src" ) == wildcard_id ) {
        wildcards |= OFPFW_DL_SRC;
      }
      if ( rb_intern( "dl_dst" ) == wildcard_id ) {
        wildcards |= OFPFW_DL_DST;
      }
      if ( rb_intern( "dl_vlan" ) == wildcard_id ) {
        wildcards |= OFPFW_DL_VLAN;
      }
      if ( rb_intern( "dl_vlan_pcp" ) == wildcard_id ) {
        wildcards |= OFPFW_DL_VLAN_PCP;
      }
      if ( rb_intern( "dl_type" ) == wildcard_id ) {
        wildcards |= OFPFW_DL_TYPE;
      }
      if ( rb_intern( "nw_tos" ) == wildcard_id ) {
        wildcards |= OFPFW_NW_TOS;
      }
      if ( rb_intern( "nw_proto" ) == wildcard_id ) {
        wildcards |= OFPFW_NW_PROTO;
      }
      if ( rb_intern( "nw_src" ) == wildcard_id ) {
        wildcards |= OFPFW_NW_SRC_ALL;
      }
      if ( rb_intern( "nw_dst" ) == wildcard_id ) {
        wildcards |= OFPFW_NW_DST_ALL;
      }
      if ( rb_intern( "tp_src" ) == wildcard_id ) {
        wildcards |= OFPFW_TP_SRC;
      }
      if ( rb_intern( "tp_dst" ) == wildcard_id ) {
        wildcards |= OFPFW_TP_DST;
      }
    }
    set_match_from_packet( match, packet->in_port, wildcards, packet->data );
  }
  else {
    rb_raise( rb_eArgError, "Message is a mandatory option" );
  }
  return obj;
}
Beispiel #8
0
/*
For a given model and error function, finds a consensus from a set of
feature correspondences.

@param features set of pointers to features; every feature is assumed to
	have a match of type mtype
@param n number of features in features
@param mtype determines the match field of each feature against which to
	measure error; if this is FEATURE_MDL_MATCH, correspondences are assumed
	to be between the feature's img_pt field and the match's mdl_pt field;
	otherwise matches are assumed to be between img_pt and img_pt
@param M model for which a consensus set is being found
@param err_fn error function used to measure distance from M
@param err_tol correspondences within this distance of M are added to the
	consensus set
@param consensus output as an array of pointers to features in the
	consensus set

@return Returns the number of points in the consensus set
*/
static int find_consensus( struct feature** features, int n, int mtype,
						   CvMat* M, ransac_err_fn err_fn, double err_tol,
						   struct feature*** consensus )
{
    struct feature** _consensus;//一致集
    struct feature* match;//每个特征点对应的匹配点
    CvPoint2D64f pt, mpt;//pt:当前特征点的坐标,mpt:当前特征点的匹配点的坐标
    double err;//变换误差
	int i, in = 0;

    _consensus = calloc( n, sizeof( struct feature* ) );//给一致集分配空间

    //匹配类型是FEATURE_MDL_MATCH,匹配点的坐标是mdl_pt域
	if( mtype == FEATURE_MDL_MATCH )
		for( i = 0; i < n; i++ )
		{
            //根据给定的匹配类型,返回输入特征点的匹配点
			match = get_match( features[i], mtype );
			if( ! match )
				fatal_error( "feature does not have match of type %d, %s line %d",
							mtype, __FILE__, __LINE__ );
            pt = features[i]->img_pt;//特征点的坐标
            mpt = match->mdl_pt;//对应匹配点的坐标
            err = err_fn( pt, mpt, M );//计算"pt经M变换后的点"和mpt之间的距离的平方,即变换误差
            if( err <= err_tol )//若变换误差小于容错度,将其加入一致集
				_consensus[in++] = features[i];
		}
    //匹配类型不是FEATURE_MDL_MATCH,匹配点的坐标是img_pt域
	else
		for( i = 0; i < n; i++ )
		{
            //根据给定的匹配类型,返回输入特征点的匹配点
			match = get_match( features[i], mtype );
			if( ! match )
				fatal_error( "feature does not have match of type %d, %s line %d",
							mtype, __FILE__, __LINE__ );
            pt = features[i]->img_pt;//特征点的坐标
            mpt = match->img_pt;//对应匹配点的坐标
            err = err_fn( pt, mpt, M );//计算"pt经M变换后的点"和mpt之间的距离的平方,即变换误差
            if( err <= err_tol )//若变换误差小于容错度,将其加入一致集
				_consensus[in++] = features[i];
		}
	*consensus = _consensus;
    return in;//返回一致集中元素个数
}
/**********************************************************************
 * classify_blob
 *
 * Classify the this blob if it is not already recorded in the match
 * table. Attempt to recognize this blob as a character.  The recognition
 * rating (probability) for this blob will be stored as a part of the
 * blob.  This value will also be returned to the caller.
 **********************************************************************/
CHOICES classify_blob(TBLOB *pblob,
                      TBLOB *blob,
                      TBLOB *nblob,
                      TEXTROW *row,
                      int fx,
                      const char *string,
                      C_COL color,
                      STATE *this_state,
                      STATE *best_state,
                      INT32 pass,
                      INT32 blob_index) {
  CHOICES rating;
  INT32 old_index;

  chars_classified++;            /* Global value */
  if (blob_skip)
    return (NIL);

#ifndef GRAPHICS_DISABLED
  if (display_all_blobs)
    display_blob(blob, color); 
#endif
  rating = get_match (blob);
  if (rating == NIL) {
    if (pass) {
      old_index = blob_index;
                                 //?cast to int*
      blob_type = compare_states (best_state, this_state, (int *) &blob_index);
      blob_answer = word_answer[blob_index];
      if (blob_answer < '!')
        fprintf (matcher_fp,
          "Bad compare states: best state=0x%x%x, this=0x%x%x, bits="
          INT32FORMAT ", index=" INT32FORMAT ", outdex="
          INT32FORMAT ", word=%s\n", best_state->part1,
          best_state->part2, this_state->part1, this_state->part2,
          bits_in_states, old_index, blob_index, word_answer);
    }
    else
      blob_type = 0;
    rating = /*(*blob_matchers [fx]) */ (CHOICES) call_matcher (pblob, blob,
      nblob, NULL,
      row);
    put_match(blob, rating); 
  }

#ifndef GRAPHICS_DISABLED
  if (display_ratings && string)
    print_choices(string, rating); 

  if (blob_pause)
    window_wait(blob_window); 
#endif

  return (rating);
}
Beispiel #10
0
static VALUE
match_nw( VALUE self, uint8_t which ) {
  struct ofp_match *match;
  uint32_t nw_addr;
  uint32_t masklen;

  match = get_match( self );
  if ( which ) {
    nw_addr = match->nw_src;
    masklen = ( match->wildcards & OFPFW_NW_SRC_MASK ) >> OFPFW_NW_SRC_SHIFT;
  } else {
Beispiel #11
0
static VALUE
match_dl( VALUE self, uint8_t which ) {
  struct ofp_match *match;
  uint8_t *dl_addr;

  match = get_match( self );
  if ( which ) {
    dl_addr = match->dl_src;
  } else {
    dl_addr = match->dl_dst;
  }
  return rb_funcall( rb_eval_string( "Trema::Mac" ), rb_intern( "new" ), 1, ULL2NUM( mac_to_uint64( dl_addr ) ) );
}
Beispiel #12
0
/*
Extract raw point correspondence locations from a set of features

@param features array of features from which to extract points and match
	points; each of these is assumed to have a match of type mtype
@param n number of features
@param mtype match type; if FEATURE_MDL_MATCH correspondences are assumed
	to be between each feature's img_pt field and it's match's mdl_pt field,
	otherwise, correspondences are assumed to be between img_pt and img_pt
@param pts output as an array of raw point locations from features
@param mpts output as an array of raw point locations from features' matches
*/
static void extract_corresp_pts( struct feature** features, int n, int mtype,
								 CvPoint2D64f** pts, CvPoint2D64f** mpts )
{
    struct feature* match;//每个特征点对应的匹配点
	CvPoint2D64f* _pts, * _mpts;
	int i;

    _pts = calloc( n, sizeof( CvPoint2D64f ) );//特征点的坐标数组
    _mpts = calloc( n, sizeof( CvPoint2D64f ) );//对应匹配点的坐标数组

    //匹配类型是FEATURE_MDL_MATCH,匹配点的坐标是mdl_pt域
	if( mtype == FEATURE_MDL_MATCH )
		for( i = 0; i < n; i++ )
		{
            //根据给定的匹配类型,返回输入特征点的匹配点
			match = get_match( features[i], mtype );
			if( ! match )
				fatal_error( "feature does not have match of type %d, %s line %d",
							mtype, __FILE__, __LINE__ );
            _pts[i] = features[i]->img_pt;//特征点的坐标
            _mpts[i] = match->mdl_pt;//对应匹配点的坐标
		}
    //匹配类型不是FEATURE_MDL_MATCH,匹配点的坐标是img_pt域
	else
		for( i = 0; i < n; i++ )
		{
            //根据给定的匹配类型,返回输入特征点的匹配点
			match = get_match( features[i], mtype );
			if( ! match )
				fatal_error( "feature does not have match of type %d, %s line %d",
							mtype, __FILE__, __LINE__ );
            _pts[i] = features[i]->img_pt;//特征点的坐标
            _mpts[i] = match->img_pt;//对应匹配点的坐标
		}

		*pts = _pts;
		*mpts = _mpts;
}
Beispiel #13
0
/*找到所有具有mtype类型匹配点的特征点,将他们的指针存储在matched数组中,
并初始化matched数组中每个特征点的feature_data域为ransac_data类型的数据指针
参数:
features:特征点数组
n:特征点个数
mtype:匹配类型
matched:输出参数,含有mtype类型匹配点的特征点的指针数组
返回值:matched数组中特征点的个数
*/
static int get_matched_features(struct feature* features, int n, int mtype,
struct feature*** matched)
{
	struct feature** _matched;		//输出数组,具有mtype类型匹配点的特征点指针数组  
	struct ransac_data* rdata;		//ransac_data类型数据指针  
	int i, m = 0;
	_matched = calloc(n, sizeof(struct feature*));
	for (i = 0; i < n; i++)		//遍历输入的特征点数组  
		if (get_match(features + i, mtype))		//找第i个特征点的mtype类型匹配点,若能正确找到表明此特征点有mtype类型的匹配点,则将其放入_matched数组  
		{
		rdata = malloc(sizeof(struct ransac_data));		//为ransac_data结构分配空间  
		memset(rdata, 0, sizeof(struct ransac_data));		//清零 
		rdata->orig_feat_data = features[i].feature_data;		//保存第i个特征点的feature_data域之前的值  
		_matched[m] = features + i;		//放到_matched数组 
		_matched[m]->feature_data = rdata;		//其feature_data域赋值为ransac_data类型数据的指针  
		m++;		//_matched数组中元素个数 
		}
	*matched = _matched;		//输出参数赋值  
	return m;		//返回值,元素个数  
}
Beispiel #14
0
/*
  Finds all features with a match of a specified type and stores pointers
  to them in an array.  Additionally initializes each matched feature's
  feature_data field with a ransac_data structure.

  @param features array of features
  @param n number of features in features
  @param mtype match type, one of FEATURE_{FWD,BCK,MDL}_MATCH
  @param matched output as an array of pointers to features with a match of
    the specified type

  @return Returns the number of features output in matched.
*/
static int get_matched_features( struct feature* features, int n, int mtype,
				 struct feature*** matched )
{
  struct feature** _matched;
  struct ransac_data* rdata;
  int i, m = 0;

  _matched = ( struct feature** )calloc( n, sizeof( struct feature* ) );
  for( i = 0; i < n; i++ )
    if( get_match( features + i, mtype ) )
      {
    rdata = ( struct ransac_data*)malloc( sizeof( struct ransac_data ) );
	memset( rdata, 0, sizeof( struct ransac_data ) );
	rdata->orig_feat_data = features[i].feature_data;
	_matched[m] = features + i;
	_matched[m]->feature_data = rdata;
	m++;
      }
  *matched = _matched;
  return m;
}
Beispiel #15
0
z_status zp_parser::test_white_space(zp_mode mode)
{
	z_status status=test_cset(*cset_white_space);
	if (status==zs_matched)
	{
		ctext match;
		size_t len;
		get_match(match,len);

		if(mode.create)
		{
			/*
			zp_text* item=new zp_text("ws");
			item->set_text(match,len);
			_ctx_current->_obj->add_child(item);
			*/
			ZT("adding whitespace");
		}
	}
	return status;
}
Beispiel #16
0
inline void solve() {
    std::sort(p+1, p+p_n+1), p[p_n+1].x = p[1].x+L;
    for(int i = 1; i <= p_n; ++i) {
        info[i] = Data2(p[i+1].x-p[i].x, info[i-1].cnt+(p[i].type==1?-1:1), i);
        //debug("%d\n", info[i].cnt);
    }
    std::sort(info+1, info+p_n+1);
    for(int i = 1; i <= p_n; ++i)                    
        sum += 1ll*info[i].len*(info[i].cnt-info[1].cnt);
    ans = sum, cut = info[1].id, cnt = info[1].len;
    //debug("%lld\n", sum);
    for(int i = 2; i <= p_n; ++i) {
        sum += (2*cnt-L)*(info[i].cnt-info[i-1].cnt);
        //debug("%lld\n", sum);
        if(sum < ans) ans = sum, cut = info[i].id;
        cnt += info[i].len;
    }
    get_match(nex(cut));
    std::cout << ans << std::endl;
    for(int i = 1; i <= n; ++i)
        printf("%d%c", match[i], i==n?'\n':' ');
}
Beispiel #17
0
/*
 * @return [Number] the value of attribute dl_vlan_pcp.
 */
static VALUE
match_dl_vlan_pcp( VALUE self ) {
  return UINT2NUM( ( get_match( self ) )->dl_vlan_pcp );
}
Beispiel #18
0
/*
 * @return [Number] the value of attribute in_port.
 */
static VALUE
match_in_port( VALUE self ) {
  return UINT2NUM( ( get_match( self ) )->in_port );
}
Beispiel #19
0
int
exec_which(int argc, char **argv)
{
	struct pkgdb *db = NULL;
	struct pkgdb_it *it = NULL;
	struct pkg *pkg = NULL;
	char pathabs[MAXPATHLEN];
	char *p, *path, *match;
	int ret = EPKG_OK, retcode = EX_SOFTWARE;
	int ch;
	int res, pathlen;
	bool orig = false;
	bool glob = false;
	bool search = false;
	bool search_s = false;

	while ((ch = getopt(argc, argv, "qgop")) != -1) {
		switch (ch) {
		case 'q':
			quiet = true;
			break;
		case 'g':
			glob = true;
			break;
		case 'o':
			orig = true;
			break;
		case 'p':
			search_s = true;
			break;
		default:
			usage_which();
			return (EX_USAGE);
		}
	}

	argc -= optind;
	argv += optind;

	if (argc < 1) {
		usage_which();
		return (EX_USAGE);
	}

	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
		return (EX_IOERR);
	}

	if (pkgdb_obtain_lock(db, PKGDB_LOCK_READONLY, 0, 0) != EPKG_OK) {
		pkgdb_close(db);
		warnx("Cannot get a read lock on a database, it is locked by another process");
		return (EX_TEMPFAIL);
	}

	if (search_s) {
		if ((path = getenv("PATH")) == NULL) {
			printf("$PATH is not set, falling back to non-search behaviour\n");
			search_s = false;
		} else {
			pathlen = strlen(path) + 1;
		}
	}

	while (argc >= 1) {
		retcode = EX_SOFTWARE;
		if (search_s) {
			if ((argv[0][0] == '.') || (argv[0][0] == '/')) {
				search = false;
			} else {
				search = true;

				if (strlen(argv[0]) >= FILENAME_MAX) {
					retcode = EX_USAGE;
					goto cleanup;
				}

				p = malloc(pathlen);
				if (p == NULL) {
					retcode = EX_OSERR;
					goto cleanup;
				}
				strlcpy(p, path, pathlen);

				match = NULL;
				res = get_match(&match, p, argv[0]);
				free(p);

				if (res == (EX_USAGE)) {
					printf("%s was not found in PATH, falling back to non-search behaviour\n", argv[0]);
					search = false;
				} else if (res == (EX_OSERR)) {
					retcode = EX_OSERR;
					goto cleanup;
				} else {
					absolutepath(match, pathabs, sizeof(pathabs));
					free(match);
				}
			}
		}

		if (!glob && !search)
			absolutepath(argv[0], pathabs, sizeof(pathabs));
		else if (!search) {
			if (strlcpy(pathabs, argv[0], sizeof(pathabs)) >= sizeof(pathabs))
				retcode = EX_USAGE;
				goto cleanup;
		}


		if ((it = pkgdb_query_which(db, pathabs, glob)) == NULL) {
			retcode = EX_IOERR;
			goto cleanup;
		}

		pkg = NULL;
		while ((ret = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
			retcode = EX_OK;
			if (quiet && orig)
				pkg_printf("%o\n", pkg);
			else if (quiet && !orig)
				pkg_printf("%n-%v\n", pkg, pkg);
			else if (!quiet && orig)
				pkg_printf("%S was installed by package %o\n", pathabs, pkg);
			else if (!quiet && !orig)
				pkg_printf("%S was installed by package %n-%v\n", pathabs, pkg, pkg);
		}

		if (retcode != EX_OK && !quiet)
			printf("%s was not found in the database\n", pathabs);

		pkg_free(pkg);
		pkgdb_it_free(it);

		argc--;
		argv++;

	}

	cleanup:
		pkgdb_release_lock(db, PKGDB_LOCK_READONLY);
		pkgdb_close(db);

	return (retcode);
}
Beispiel #20
0
/*
 * Compare context of {Match} self with {Match} other.
 *
 * @example
 *   def packet_in datapath_id, message
 *     match = Match.new( :dl_type => 0x0800, :nw_src => "192.168.0.1" )
 *     if match.compare( ExactMatch.from( message ) )
 *       info "Received packet from 192.168.0.1"
 *     end
 *   end
 *
 * @return [Boolean] true if the {Match} match
 */
static VALUE
match_compare( VALUE self, VALUE other ) {
  return compare_match( get_match( self ), get_match( other ) ) ? Qtrue : Qfalse;
}
Beispiel #21
0
/*
 * The wildcard field expressed as a 32-bit bitmap,
 *
 * @return [Number] the value of attribute wildcards.
 */
static VALUE
match_wildcards( VALUE self ) {
  return UINT2NUM( ( get_match( self ) )->wildcards );
}
Beispiel #22
0
/*
 * Replaces context of {Match} self with {Match} other.
 *
 * @return [Match] self
 *   the modified object instance.
 */
static VALUE
match_replace( VALUE self, VALUE other ) {
  memcpy( get_match( self ), get_match( other ), sizeof ( struct ofp_match ) );
  return self;
}
Beispiel #23
0
void print_hits(SESA sesa, struct HitTable *hits, int wm_length) {
  struct HitEntry *end = hits->pScores + hits->nScores;
  struct HitEntry *hit = hits->pScores;
  int seq, last_seq;

  qsort((void*)hits->pScores, hits->nScores, sizeof(struct HitEntry), compare_hits);

  last_seq = -1;

  for (hit = hits->pScores; hit < end; hit++) {
    seq = sesa->seq[hit->position];
    printf("%3i: %10s   %5i   %s   %7.2f\n", seq, sesa->seqnames[seq], sesa->pos[hit->position], get_match(sesa, hit->position, wm_length), hit->score);
  } 
  
}
Beispiel #24
0
int
exec_which(int argc, char **argv)
{
	struct pkgdb	*db = NULL;
	struct pkgdb_it	*it = NULL;
	struct pkg	*pkg = NULL;
	char		 pathabs[MAXPATHLEN];
	char		*p, *path, *match, *savedpath;
	int		 ret = EPKG_OK, retcode = EX_SOFTWARE;
	int		 ch, i;
	int		 res, pathlen = 0;
	bool		 orig = false;
	bool		 glob = false;
	bool		 search = false;
	bool		 search_s = false;
	charlist	 patterns;

	struct option longopts[] = {
		{ "glob",		no_argument,	NULL,	'g' },
		{ "origin",		no_argument,	NULL,	'o' },
		{ "path-search",	no_argument,	NULL,	'p' },
		{ "quiet",		no_argument,	NULL,	'q' },
		{ NULL,			0,		NULL,	0   },
	};

	path = NULL;

	while ((ch = getopt_long(argc, argv, "+gopq", longopts, NULL)) != -1) {
		switch (ch) {
		case 'g':
			glob = true;
			break;
		case 'o':
			orig = true;
			break;
		case 'p':
			search_s = true;
			break;
		case 'q':
			quiet = true;
			break;
		default:
			usage_which();
			return (EX_USAGE);
		}
	}

	argc -= optind;
	argv += optind;

	if (argc < 1) {
		usage_which();
		return (EX_USAGE);
	}

	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
		return (EX_IOERR);
	}

	if (pkgdb_obtain_lock(db, PKGDB_LOCK_READONLY) != EPKG_OK) {
		pkgdb_close(db);
		warnx("Cannot get a read lock on a database, it is locked by another process");
		return (EX_TEMPFAIL);
	}

	if (search_s) {
		if ((path = getenv("PATH")) == NULL) {
			printf("$PATH is not set, falling back to non-search behaviour\n");
			search_s = false;
		} else {
			pathlen = strlen(path) + 1;
		}
	}

	while (argc >= 1) {
		kv_init(patterns);
		retcode = EX_SOFTWARE;
		if (search_s) {
			if ((argv[0][0] == '.') || (argv[0][0] == '/')) {
				search = false;
			} else {
				search = true;

				if (strlen(argv[0]) >= FILENAME_MAX) {
					retcode = EX_USAGE;
					goto cleanup;
				}

				p = malloc(pathlen);
				if (p == NULL) {
					retcode = EX_OSERR;
					goto cleanup;
				}
				strlcpy(p, path, pathlen);

				match = NULL;
				savedpath=p;
				for (;;) {
					res = get_match(&match, &p, argv[0]);
					if (p == NULL)
						break;

					if (res == (EX_USAGE)) {
						printf("%s was not found in PATH, falling back to non-search behaviour\n", argv[0]);
						search = false;
					} else if (res == (EX_OSERR)) {
						retcode = EX_OSERR;
						free(savedpath);
						goto cleanup;
					} else {
						pkg_absolutepath(match, pathabs, sizeof(pathabs));
						/* ensure not not append twice an entry if PATH is messy */
						if (already_in_list(&patterns, pathabs))
							continue;
						kv_push(char *, patterns, strdup(pathabs));
						free(match);
					}
				}
				free(savedpath);
			}
		}

		if (!glob && !search) {
			pkg_absolutepath(argv[0], pathabs, sizeof(pathabs));
			kv_push(char *, patterns, strdup(pathabs));
		} else if (!search) {
			if (strlcpy(pathabs, argv[0], sizeof(pathabs)) >= sizeof(pathabs)) {
				retcode = EX_USAGE;
				goto cleanup;
                        }
		}


		for (i = 0; i < kv_size(patterns); i++) {
			if ((it = pkgdb_query_which(db, kv_A(patterns, i), glob)) == NULL) {
				retcode = EX_IOERR;
				goto cleanup;
			}

			pkg = NULL;
			while ((ret = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
				retcode = EX_OK;
				if (quiet && orig)
					pkg_printf("%o\n", pkg);
				else if (quiet && !orig)
					pkg_printf("%n-%v\n", pkg, pkg);
				else if (!quiet && orig)
					pkg_printf("%S was installed by package %o\n", kv_A(patterns, i), pkg);
				else if (!quiet && !orig)
					pkg_printf("%S was installed by package %n-%v\n", kv_A(patterns, i), pkg, pkg);
			}
			if (retcode != EX_OK && !quiet)
				printf("%s was not found in the database\n", kv_A(patterns, i));

			pkg_free(pkg);
			pkgdb_it_free(it);

		}
		kv_destroy(patterns);

		argc--;
		argv++;

	}

	cleanup:
		pkgdb_release_lock(db, PKGDB_LOCK_READONLY);
		pkgdb_close(db);

	return (retcode);
}
Beispiel #25
0
/*
 * @return [Number] the value of attribute dl_type.
 */
static VALUE
match_dl_type( VALUE self ) {
  return UINT2NUM( ( get_match( self ) )->dl_type );
}
Beispiel #26
0
/*
 * An IPv4 source address in its numeric representation.
 *
 * @return [Number] the value of attribute nw_src.
 */
static VALUE
match_nw_src( VALUE self ) {
  return UINT2NUM( ( get_match( self ) )->nw_src );
}
Beispiel #27
0
/*
 * @return [Number] the value of attribute nw_proto.
 */
static VALUE
match_nw_proto( VALUE self ) {
  return UINT2NUM( ( get_match( self ) )->nw_proto );
}
Beispiel #28
0
std::string BAMUtils::to_string() {
	std::ostringstream strm(std::ostringstream::app);
	strm << get_name(); //0
	strm << "\t";
	strm << get_strand(); //1

	strm << "\t";
	strm << get_t_start(); //2

	strm << "\t";
	strm << get_t_length(); //3

	strm << "\t";
	strm << get_q_length();//4

	strm << "\t";
	strm << get_match();//5
	strm << "\t";
	strm << get_percent_id();//6
	strm << "\t";
	strm << get_q_error();//7
	strm << "\t";

	strm << get_homo_errors();//8
	strm << "\t";
	strm << get_mismatch_errors();//9
	strm << "\t";
	strm << get_indel_errors();//10
	strm << "\t";

	strm << get_qdna();//12
	strm << "\t";
	strm << get_matcha();//13
	strm << "\t";
	strm << get_tdna();//14
	strm << "\t";
	strm << get_rname();//15
	strm << "\t";

	if (num_slop >= 0) {
		strm << num_slop;
		
	}else {
		strm << 0;//16
	}
	strm << "\t";
	
	std::vector<std::string> q_score_vec;
	split(q_scores, ',', q_score_vec);
	for (std::vector<std::string>::size_type i = 0; i < q_score_vec.size(); i++) {
		//strm << phred_lens[i];
		strm << get_phred_len((strtol(q_score_vec[i].c_str(),NULL, 10)));
		strm << "\t";
	}

	strm << get_full_q_length();
	strm << "\t";
	
	return strm.str();
	
}
Beispiel #29
0
/*
 * @return [Number] the value of attribute tp_dst.
 */
static VALUE
match_tp_dst( VALUE self ) {
  return UINT2NUM( ( get_match( self ) )->tp_dst );
}
Beispiel #30
0
static int editor_input(struct commands *commands, struct mbuf *mb, char key,
			struct re_printf *pf, bool *del, bool is_long)
{
	int err = 0;

	switch (key) {

	case KEYCODE_ESC:
		*del = true;
		return re_hprintf(pf, "\nCancel\n");

	case KEYCODE_NONE:
	case KEYCODE_REL:
		break;

	case '\n':
		*del = true;
		return re_hprintf(pf, "\n");

	case '\b':
	case KEYCODE_DEL:
		if (mb->pos > 0) {
			err |= re_hprintf(pf, "\b ");
			mb->pos = mb->end = (mb->pos - 1);
		}
		break;

	case '\t':
		if (is_long) {
			const struct cmd *cmd = NULL;
			size_t n;

			err = re_hprintf(pf,
					 "TAB completion for \"%b\":\n",
					 mb->buf, mb->end);
			if (err)
				return err;

			/* Find all long commands that matches the N
			 * first characters of the input string.
			 *
			 * If the number of matches is exactly one,
			 * we can regard it as TAB completion.
			 */

			err = cmd_print_all(pf, commands, true, false,
					    (char *)mb->buf, mb->end);
			if (err)
				return err;

			n = get_match(commands, &cmd,
				      (char *)mb->buf, mb->end);
			if (n == 1 && cmd) {

				mb->pos = 0;
				mbuf_write_str(mb, cmd->name);
			}
			else if (n == 0) {
				err = re_hprintf(pf, "(none)\n");
			}
		}
		else {
			err = mbuf_write_u8(mb, key);
		}
		break;

	default:
		err = mbuf_write_u8(mb, key);
		break;
	}

	if (is_long) {
		err |= re_hprintf(pf, "\r/%b",
				  mb->buf, mb->end);
	}
	else
		err |= re_hprintf(pf, "\r> %32b", mb->buf, mb->end);

	return err;
}